Пример #1
0
 /**
  * @test
  * @expectedException \Accesto\Component\Payum\PayU\Exception\PayUException
  */
 public function shouldThrowExceptionAfterFailure()
 {
     $createResponse = new \stdClass();
     $createResponse->status = new \stdClass();
     $createResponse->status->statusCode = 'Error';
     $createResponse->orderId = 1;
     $createResponse->redirectUri = 'example.com';
     $action = $this->setupSetPayUAction($createResponse);
     $t = new Token();
     $t->setGatewayName('payu');
     $t->setDetails(new \ArrayObject());
     $request = new SetPayU($t);
     $request->setModel(new ArrayObject());
     $action->execute($request);
 }
 /**
  * @test
  */
 public function shouldExecuteAuthorizeRequest()
 {
     $request = Request::create('/');
     $request->query->set('foo', 'fooVal');
     $token = new Token();
     $token->setGatewayName('theGateway');
     $token->setAfterUrl('http://example.com/theAfterUrl');
     $httpRequestVerifierMock = $this->getMock(HttpRequestVerifierInterface::class);
     $httpRequestVerifierMock->expects($this->once())->method('verify')->with($this->identicalTo($request))->will($this->returnValue($token));
     $httpRequestVerifierMock->expects($this->once())->method('invalidate')->with($this->identicalTo($token));
     $gatewayMock = $this->getMock(GatewayInterface::class);
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf(Authorize::class));
     $registryMock = $this->getMock(RegistryInterface::class);
     $registryMock->expects($this->once())->method('getGateway')->with('theGateway')->will($this->returnValue($gatewayMock));
     $payum = new Payum($registryMock, $httpRequestVerifierMock, $this->getMock(GenericTokenFactoryInterface::class), $this->getMock(StorageInterface::class));
     $container = new Container();
     $container->set('payum', $payum);
     $controller = new AuthorizeController();
     $controller->setContainer($container);
     $response = $controller->doAction($request);
     $this->assertInstanceOf(RedirectResponse::class, $response);
     $this->assertEquals('http://example.com/theAfterUrl', $response->getTargetUrl());
 }
 /**
  * @test
  */
 public function shouldExecuteCaptureRequest()
 {
     $request = Request::create('/');
     $request->query->set('foo', 'fooVal');
     $token = new Token();
     $token->setGatewayName('theGateway');
     $token->setAfterUrl('http://example.com/theAfterUrl');
     $tokenVerifierMock = $this->getMock('Payum\\Core\\Security\\HttpRequestVerifierInterface');
     $tokenVerifierMock->expects($this->once())->method('verify')->with($this->identicalTo($request))->will($this->returnValue($token));
     $tokenVerifierMock->expects($this->once())->method('invalidate')->with($this->identicalTo($token));
     $gatewayMock = $this->getMock('Payum\\Core\\GatewayInterface');
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\Capture'));
     $registryMock = $this->getMock('Payum\\Core\\Registry\\RegistryInterface');
     $registryMock->expects($this->once())->method('getGateway')->with('theGateway')->will($this->returnValue($gatewayMock));
     $container = new Container();
     $container->set('payum', $registryMock);
     $container->set('payum.security.http_request_verifier', $tokenVerifierMock);
     $controller = new CaptureController();
     $controller->setContainer($container);
     $response = $controller->doAction($request);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
     $this->assertEquals('http://example.com/theAfterUrl', $response->getTargetUrl());
 }
Пример #4
0
 /**
  * @test
  */
 public function shouldGeneratePushUriIfNotSet()
 {
     $config = new Config();
     $config->termsUri = 'theTermsUri';
     $token = new Token();
     $token->setTargetUrl('theTargetUrl');
     $token->setGatewayName('theGatewayName');
     $token->setDetails($identity = new Identity('id', 'class'));
     $notifyToken = new Token();
     $notifyToken->setTargetUrl('theNotifyUrl');
     $tokenFactory = $this->getMock(GenericTokenFactoryInterface::class);
     $tokenFactory->expects($this->once())->method('createNotifyToken')->with('theGatewayName', $this->identicalTo($identity))->will($this->returnValue($notifyToken));
     $action = new AuthorizeAction('aTemplate');
     $action->setGateway($this->createGatewayMock());
     $action->setApi($config);
     $action->setGenericTokenFactory($tokenFactory);
     $authorize = new Authorize($token);
     $authorize->setModel(['location' => 'aLocation', 'merchant' => ['confirmation_uri' => 'theConfirmationUri', 'checkout_uri' => 'theCheckoutUri', 'terms_uri' => 'theTermsUri']]);
     $action->execute($authorize);
 }
 /**
  * @test
  */
 public function shouldNotAddNotifyUrlIfTokenFactoryNotSet()
 {
     $details = new \ArrayObject(array());
     $captureToken = new Token();
     $captureToken->setGatewayName('theGatewayName');
     $captureToken->setDetails($details);
     $action = new AuthorizeAction();
     $action->setGateway($this->createGatewayMock());
     $request = new Authorize($captureToken);
     $request->setModel($details);
     $action->execute($request);
     $this->assertArrayNotHasKey('PAYMENTREQUEST_0_NOTIFYURL', $details);
 }
 /**
  * @test
  */
 public function shouldSetResponseStringDataToDetails()
 {
     $details = new \ArrayObject(['card' => array('cvv' => 123), 'clientIp' => '']);
     $responseMock = $this->getMock(OmnipayAbstractResponse::class, [], [], '', false);
     $responseMock->expects($this->any())->method('getData')->willReturn('someData');
     $requestMock = $this->getMock(OmnipayRequestInterface::class);
     $requestMock->expects($this->any())->method('send')->will($this->returnValue($responseMock));
     $omnipayGateway = $this->getMock(OffsiteGateway::class);
     $omnipayGateway->expects($this->once())->method('purchase')->willReturn($requestMock);
     $captureToken = new Token();
     $captureToken->setTargetUrl('theCaptureUrl');
     $captureToken->setDetails($identity = new Identity('theId', new \stdClass()));
     $captureToken->setGatewayName('theGatewayName');
     $notifyToken = new Token();
     $notifyToken->setTargetUrl('theNotifyUrl');
     $tokenFactoryMock = $this->getMock(GenericTokenFactoryInterface::class);
     $tokenFactoryMock->expects($this->once())->method('createNotifyToken')->with('theGatewayName', $this->identicalTo($identity))->willReturn($notifyToken);
     $request = new Capture($captureToken);
     $request->setModel($details);
     $action = new OffsiteCaptureAction();
     $action->setApi($omnipayGateway);
     $action->setGateway($this->createGatewayMock());
     $action->setGenericTokenFactory($tokenFactoryMock);
     $action->execute($request);
     $details = (array) $details;
     $this->assertArrayHasKey('_data', $details);
     $this->assertEquals('someData', $details['_data']);
 }
Пример #7
0
 /**
  * @test
  */
 public function shouldAllowGetPreviouslySetGatewayName()
 {
     $token = new Token();
     $token->setGatewayName('theName');
     $this->assertSame('theName', $token->getGatewayName());
 }