diff --git a/Action/PurchaseAction.php b/Action/PurchaseAction.php index 1601f9f..b0fae7a 100644 --- a/Action/PurchaseAction.php +++ b/Action/PurchaseAction.php @@ -78,7 +78,9 @@ public function execute($request) if ($details['CANCELURL']) { $cancelUrl = Url::createFromUrl($details['CANCELURL']); - $cancelUrl->setQuery(['cancelled' => 1]); + $query = $cancelUrl->getQuery(); + $query->modify(['cancelled' => 1]); + $cancelUrl->setQuery($query); $details['CANCELURL'] = (string) $cancelUrl; } diff --git a/Tests/Action/AutorizeActionTest.php b/Tests/Action/AutorizeActionTest.php index ebfc89e..48b8e8e 100644 --- a/Tests/Action/AutorizeActionTest.php +++ b/Tests/Action/AutorizeActionTest.php @@ -262,6 +262,42 @@ public function shouldSetTokenTargetUrlAsCancelUrlIfCapturePassedWithToken() $action->execute($request); } + /** + * @test + */ + public function shouldNotLooseExistingGetParamWhenSettingTargetUrlAsCancelUrl() + { + $testCase = $this; + + $cancelUrl = 'http://theCancelUrl/?existingGetParam=testValue'; + $expectedCancelUrl = $cancelUrl.'&cancelled=1'; + + $token = new Token(); + $token->setTargetUrl($cancelUrl); + $token->setDetails(array()); + + $gatewayMock = $this->createGatewayMock(); + + $gatewayMock + ->expects($this->at(1)) + ->method('execute') + ->with($this->isInstanceOf(SetExpressCheckout::class)) + ->will($this->returnCallback(function ($request) use ($testCase, $expectedCancelUrl) { + $model = $request->getModel(); + + $testCase->assertEquals($expectedCancelUrl, $model['CANCELURL']); + })) + ; + + $action = new AuthorizeAction(); + $action->setGateway($gatewayMock); + + $request = new Authorize($token); + $request->setModel(array()); + + $action->execute($request); + } + /** * @test */ diff --git a/Tests/Action/CaptureActionTest.php b/Tests/Action/CaptureActionTest.php index fe98959..639776b 100644 --- a/Tests/Action/CaptureActionTest.php +++ b/Tests/Action/CaptureActionTest.php @@ -261,6 +261,42 @@ public function shouldSetTokenTargetUrlAsCancelUrlIfCapturePassedWithToken() $action->execute($request); } + /** + * @test + */ + public function shouldNotLooseExistingGetParamWhenSettingTargetUrlAsCancelUrl() + { + $testCase = $this; + + $cancelUrl = 'http://theCancelUrl/?existingGetParam=testValue'; + $expectedCancelUrl = $cancelUrl.'&cancelled=1'; + + $token = new Token(); + $token->setTargetUrl($cancelUrl); + $token->setDetails(array()); + + $gatewayMock = $this->createGatewayMock(); + + $gatewayMock + ->expects($this->at(1)) + ->method('execute') + ->with($this->isInstanceOf(SetExpressCheckout::class)) + ->will($this->returnCallback(function ($request) use ($testCase, $expectedCancelUrl) { + $model = $request->getModel(); + + $testCase->assertEquals($expectedCancelUrl, $model['CANCELURL']); + })) + ; + + $action = new CaptureAction(); + $action->setGateway($gatewayMock); + + $request = new Capture($token); + $request->setModel(array()); + + $action->execute($request); + } + /** * @test */