From 4ecac675d152f92d42a00bf57256148bf815700c Mon Sep 17 00:00:00 2001 From: Aimeos GmbH Date: Fri, 1 May 2020 12:28:15 +0200 Subject: [PATCH 1/4] Adds methods for required setting to do token based payments --- .../PaymentIntents/AuthorizeRequest.php | 55 ++++++++++++++++++- .../PaymentIntents/AuthorizeRequestTest.php | 4 ++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/Message/PaymentIntents/AuthorizeRequest.php b/src/Message/PaymentIntents/AuthorizeRequest.php index fe939d1e..65965058 100644 --- a/src/Message/PaymentIntents/AuthorizeRequest.php +++ b/src/Message/PaymentIntents/AuthorizeRequest.php @@ -110,10 +110,11 @@ class AuthorizeRequest extends AbstractRequest * Set the confirm parameter. * * @param $value + * @return AbstractRequest provides a fluent interface. */ public function setConfirm($value) { - $this->setParameter('confirm', $value); + return $this->setParameter('confirm', $value); } /** @@ -286,6 +287,48 @@ public function setReceiptEmail($email) return $this; } + /** + * Set the setup_future_usage parameter. + * + * @param $value + * @return AbstractRequest provides a fluent interface. + */ + public function setSetupFutureUsage($value) + { + return $this->setParameter('setup_future_usage', $value); + } + + /** + * Get the setup_future_usage parameter. + * + * @return mixed + */ + public function getSetupFutureUsage() + { + return $this->getParameter('setup_future_usage'); + } + + /** + * Set the setup_future_usage parameter. + * + * @param $value + * @return AbstractRequest provides a fluent interface. + */ + public function setOffSession($value) + { + return $this->setParameter('off_session', $value); + } + + /** + * Get the setup_future_usage parameter. + * + * @return mixed + */ + public function getOffSession() + { + return $this->getParameter('off_session'); + } + /** * @inheritdoc */ @@ -343,12 +386,20 @@ public function getData() $data['customer'] = $this->getCustomerReference(); } + if ($this->getSetupFutureUsage()) { + $data['setup_future_usage'] = $this->getSetupFutureUsage(); + } + + if ($this->getOffSession()) { + $data['off_session'] = $this->getOffSession() ? 'true' : 'false'; + } + $data['confirmation_method'] = 'manual'; $data['capture_method'] = 'manual'; $data['confirm'] = $this->getConfirm() ? 'true' : 'false'; - if ($this->getConfirm()) { + if ($this->getReturnUrl()) { $this->validate('returnUrl'); $data['return_url'] = $this->getReturnUrl(); } diff --git a/tests/Message/PaymentIntents/AuthorizeRequestTest.php b/tests/Message/PaymentIntents/AuthorizeRequestTest.php index 9e3b8858..7254e9eb 100644 --- a/tests/Message/PaymentIntents/AuthorizeRequestTest.php +++ b/tests/Message/PaymentIntents/AuthorizeRequestTest.php @@ -25,6 +25,8 @@ public function setUp() ), 'applicationFee' => '1.00', 'returnUrl' => 'complete-payment', + 'setup_future_usage' => 'off_session', + 'off_session' => true, 'confirm' => true, ) ); @@ -42,6 +44,8 @@ public function testGetData() $this->assertSame('pm_valid_payment_method', $data['payment_method']); $this->assertSame(array('foo' => 'bar'), $data['metadata']); $this->assertSame(100, $data['application_fee']); + $this->assertSame('off_session', $data['setup_future_usage']); + $this->assertSame(true, $data['off_session']); } /** From e64b511abef93b8cafb50183ffdd793e506bfd73 Mon Sep 17 00:00:00 2001 From: Aimeos GmbH Date: Fri, 1 May 2020 12:42:13 +0200 Subject: [PATCH 2/4] Fixes tests --- src/Message/PaymentIntents/AuthorizeRequest.php | 2 +- tests/Message/PaymentIntents/AuthorizeRequestTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/PaymentIntents/AuthorizeRequest.php b/src/Message/PaymentIntents/AuthorizeRequest.php index 65965058..7691135a 100644 --- a/src/Message/PaymentIntents/AuthorizeRequest.php +++ b/src/Message/PaymentIntents/AuthorizeRequest.php @@ -399,7 +399,7 @@ public function getData() $data['confirm'] = $this->getConfirm() ? 'true' : 'false'; - if ($this->getReturnUrl()) { + if ($this->getConfirm() && !$this->getOffSession()) { $this->validate('returnUrl'); $data['return_url'] = $this->getReturnUrl(); } diff --git a/tests/Message/PaymentIntents/AuthorizeRequestTest.php b/tests/Message/PaymentIntents/AuthorizeRequestTest.php index 7254e9eb..1826f55a 100644 --- a/tests/Message/PaymentIntents/AuthorizeRequestTest.php +++ b/tests/Message/PaymentIntents/AuthorizeRequestTest.php @@ -45,7 +45,7 @@ public function testGetData() $this->assertSame(array('foo' => 'bar'), $data['metadata']); $this->assertSame(100, $data['application_fee']); $this->assertSame('off_session', $data['setup_future_usage']); - $this->assertSame(true, $data['off_session']); + $this->assertSame('true', $data['off_session']); } /** From 4e7fe74c3fb5d5a54c8e1733022f5f4fc85f58b6 Mon Sep 17 00:00:00 2001 From: Aimeos GmbH Date: Fri, 1 May 2020 12:48:50 +0200 Subject: [PATCH 3/4] Don't enable off_session in tests so existing tests still succeed --- tests/Message/PaymentIntents/AuthorizeRequestTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Message/PaymentIntents/AuthorizeRequestTest.php b/tests/Message/PaymentIntents/AuthorizeRequestTest.php index 1826f55a..5081eb01 100644 --- a/tests/Message/PaymentIntents/AuthorizeRequestTest.php +++ b/tests/Message/PaymentIntents/AuthorizeRequestTest.php @@ -26,7 +26,7 @@ public function setUp() 'applicationFee' => '1.00', 'returnUrl' => 'complete-payment', 'setup_future_usage' => 'off_session', - 'off_session' => true, + 'off_session' => false, 'confirm' => true, ) ); @@ -45,7 +45,7 @@ public function testGetData() $this->assertSame(array('foo' => 'bar'), $data['metadata']); $this->assertSame(100, $data['application_fee']); $this->assertSame('off_session', $data['setup_future_usage']); - $this->assertSame('true', $data['off_session']); + $this->assertSame('false', $data['off_session']); } /** From a9c9399ded7ebcaec4390c3f1dae14269107bb65 Mon Sep 17 00:00:00 2001 From: Aimeos GmbH Date: Fri, 1 May 2020 12:53:20 +0200 Subject: [PATCH 4/4] Always add off_session parameter to request --- src/Message/PaymentIntents/AuthorizeRequest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Message/PaymentIntents/AuthorizeRequest.php b/src/Message/PaymentIntents/AuthorizeRequest.php index 7691135a..8cf9d541 100644 --- a/src/Message/PaymentIntents/AuthorizeRequest.php +++ b/src/Message/PaymentIntents/AuthorizeRequest.php @@ -390,9 +390,7 @@ public function getData() $data['setup_future_usage'] = $this->getSetupFutureUsage(); } - if ($this->getOffSession()) { - $data['off_session'] = $this->getOffSession() ? 'true' : 'false'; - } + $data['off_session'] = $this->getOffSession() ? 'true' : 'false'; $data['confirmation_method'] = 'manual'; $data['capture_method'] = 'manual';