/** * @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); }
/** * @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); }
/** * @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 shouldAddNotifyUrlIfTokenFactorySetAndCaptureTokenPassed() { $details = new \ArrayObject(array('foo' => 'fooVal')); $captureToken = new Token(); $captureToken->setGatewayName('theGatewayName'); $captureToken->setDetails($details); $notifyToken = new Token(); $notifyToken->setTargetUrl('theNotifyUrl'); $tokenFactoryMock = $this->getMock(GenericTokenFactoryInterface::class); $tokenFactoryMock->expects($this->once())->method('createNotifyToken')->with('theGatewayName', $this->identicalTo($details))->will($this->returnValue($notifyToken)); $action = new AuthorizeAction(); $action->setGateway($this->createGatewayMock()); $action->setGenericTokenFactory($tokenFactoryMock); $request = new Authorize($captureToken); $request->setModel($details); $action->execute($request); $this->assertArrayHasKey('PAYMENTREQUEST_0_NOTIFYURL', $details); $this->assertEquals('theNotifyUrl', $details['PAYMENTREQUEST_0_NOTIFYURL']); $this->assertArrayHasKey('foo', $details); $this->assertEquals('fooVal', $details['foo']); }
/** * @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); }
/** * @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']); }
/** * @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); }
/** * @test */ public function shouldAllowGetPreviouslySetTargetUrl() { $token = new Token(); $token->setTargetUrl('theUrl'); $this->assertSame('theUrl', $token->getTargetUrl()); }