コード例 #1
0
 /**
  * @test
  */
 public function shouldReturnExpectedTokenIfAllCheckPassedOnVerify()
 {
     $_SERVER['REQUEST_URI'] = 'http://target.com/foo';
     $expectedToken = new Token();
     $expectedToken->setHash('theHash');
     $expectedToken->setTargetUrl('http://target.com/foo');
     $storageMock = $this->createStorageMock();
     $storageMock->expects($this->once())->method('find')->with('theHash')->will($this->returnValue($expectedToken));
     $verifier = new HttpRequestVerifier($storageMock);
     $actualToken = $verifier->verify(array('payum_token' => 'theHash'));
     $this->assertSame($expectedToken, $actualToken);
 }
コード例 #2
0
    /**
     * @test
     */
    public function shouldExecuteRefundRequestWithoutAfterUrl()
    {
        $request = Request::create('/');
        $request->query->set('foo', 'fooVal');

        $token = new Token;
        $token->setPaymentName('thePayment');
        $token->setAfterUrl(null);

        $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))
        ;

        $paymentMock = $this->getMock('Payum\Core\PaymentInterface');
        $paymentMock
            ->expects($this->once())
            ->method('execute')
            ->with($this->isInstanceOf('Payum\Core\Request\Refund'))
        ;

        $registryMock = $this->getMock('Payum\Core\Registry\RegistryInterface');
        $registryMock
            ->expects($this->once())
            ->method('getPayment')
            ->with('thePayment')
            ->will($this->returnValue($paymentMock))
        ;

        $container = new Container;
        $container->set('payum', $registryMock);
        $container->set('payum.security.http_request_verifier', $tokenVerifierMock);

        $controller = new RefundController;
        $controller->setContainer($container);

        $response = $controller->doAction($request);

        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
        $this->assertEquals(204, $response->getStatusCode());
    }
コード例 #3
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);
 }
コード例 #4
0
 /**
  * @test
  */
 public function shouldSetTokenTargetUrlAsCancelUrlIfCapturePassedWithToken()
 {
     $testCase = $this;
     $expectedCancelUrl = 'theCancelUrl';
     $token = new Token();
     $token->setTargetUrl($expectedCancelUrl);
     $token->setDetails(array());
     $paymentMock = $this->createPaymentMock();
     $paymentMock->expects($this->at(0))->method('execute')->with($this->isInstanceOf('Eki\\Payum\\Nganluong\\Request\\Api\\SetExpressCheckout'))->will($this->returnCallback(function ($request) use($testCase, $expectedCancelUrl) {
         $model = $request->getModel();
         $testCase->assertEquals($expectedCancelUrl, $model['cancel_url']);
     }));
     $action = new CaptureAction();
     $action->setPayment($paymentMock);
     $request = new Capture($token);
     $request->setModel(array());
     $action->execute($request);
 }
コード例 #5
0
 /**
  * @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());
 }
コード例 #6
0
 /**
  * @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());
 }
コード例 #7
0
ファイル: AuthorizeActionTest.php プロジェクト: eamador/Payum
 /**
  * @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);
 }
コード例 #8
0
 /**
  * @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);
 }
コード例 #9
0
 /**
  * @test
  */
 public function shouldNotMatchUriIfTokenSetToRequestAttribute()
 {
     $expectedToken = new Token();
     $expectedToken->setHash('theHash');
     $expectedToken->setTargetUrl('http://target.com/bar');
     $storageMock = $this->createStorageMock();
     $storageMock->expects($this->never())->method('findModelById');
     $request = Request::create('http://target.com/foo');
     $request->query->set('payum_token', $expectedToken);
     $verifier = new HttpRequestVerifier($storageMock);
     $actualToken = $verifier->verify($request);
     $this->assertSame($expectedToken, $actualToken);
 }
コード例 #10
0
 /**
  * @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']);
 }
コード例 #11
0
ファイル: TokenFactoryTest.php プロジェクト: payum/core
 /**
  * @test
  */
 public function shouldCreateTokenForBaseUrlWithPath()
 {
     $token = new Token();
     $token->setHash('aHash');
     $tokenStorageMock = $this->createStorageMock();
     $tokenStorageMock->expects($this->once())->method('create')->will($this->returnValue($token));
     $tokenStorageMock->expects($this->once())->method('update')->with($this->identicalTo($token));
     $gatewayName = 'theGatewayName';
     $identity = new Identity('anId', 'stdClass');
     $storageRegistryMock = $this->createStorageRegistryMock();
     $storageRegistryMock->expects($this->never())->method('getStorage');
     $factory = new TokenFactory($tokenStorageMock, $storageRegistryMock, 'http://example.com/aBase/path');
     $actualToken = $factory->createToken($gatewayName, $identity, 'theTargetPath', ['target' => 'val']);
     $this->assertEquals('http://example.com/aBase/path/theTargetPath?payum_token=aHash&target=val', $actualToken->getTargetUrl());
 }
コード例 #12
0
 /**
  * @test
  */
 public function shouldAllowCreateRefundToken()
 {
     $gatewayName = 'theGatewayName';
     $model = new \stdClass();
     $refundPath = 'theRefundPath';
     $afterPath = 'theAfterPath';
     $afterUrl = 'theAfterUrl';
     $afterParameters = array('after' => 'val');
     $afterToken = new Token();
     $afterToken->setTargetUrl($afterUrl);
     $refundToken = new Token();
     $tokenFactoryMock = $this->createTokenFactoryMock();
     $tokenFactoryMock->expects($this->at(0))->method('createToken')->with($gatewayName, $this->identicalTo($model), $afterPath, $afterParameters, null, array())->willReturn($afterToken);
     $tokenFactoryMock->expects($this->at(1))->method('createToken')->with($gatewayName, $this->identicalTo($model), $refundPath, array(), $afterUrl, array())->willReturn($refundToken);
     $factory = new GenericTokenFactory($tokenFactoryMock, array('refund' => $refundPath));
     $actualToken = $factory->createRefundToken($gatewayName, $model, $afterPath, $afterParameters);
     $this->assertSame($refundToken, $actualToken);
 }
コード例 #13
0
ファイル: TokenTest.php プロジェクト: stan5621/eduwind
 /**
  * @test
  */
 public function shouldAllowGetIdentificatorPreviouslySetAsDetails()
 {
     $expectedIdentificator = new Identificator('anId', 'stdClass');
     $token = new Token();
     $token->setDetails($expectedIdentificator);
     $this->assertSame($expectedIdentificator, $token->getDetails());
 }