From 4cd762aaa04a03ea3ea63d1b7c4d10752a9d3e38 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 25 Aug 2020 21:15:49 +0100 Subject: [PATCH 1/3] Fix for payment method being required@ --- .../PaymentIntents/AuthorizeRequest.php | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Message/PaymentIntents/AuthorizeRequest.php b/src/Message/PaymentIntents/AuthorizeRequest.php index 4a0ec8ad..f7eeb592 100644 --- a/src/Message/PaymentIntents/AuthorizeRequest.php +++ b/src/Message/PaymentIntents/AuthorizeRequest.php @@ -328,6 +328,55 @@ public function getOffSession() { return $this->getParameter('off_session'); } + + /** + * Set the capture method, accepts automatic or manual + * + * @param string $value + * + * @return AbstractRequest provides a fluent interface. + */ + public function setCaptureMethod($value) + { + if($value == null) { + $value = 'automatic'; + } + + return $this->setParameter('capture_method', $value); + } + + + /** + * @return mixed + */ + public function getCaptureMethod() + { + return $this->getParameter('capture_method'); + } + + /** + * Set the confirmation method, accepts automatic or manual + * + * @param string $value + * + * @return AbstractRequest provides a fluent interface. + */ + public function setConfirmationMethod($value) + { + if($value == null) { + $value = 'automatic'; + } + return $this->setParameter('confirmation_method', $value); + } + + + /** + * @return mixed + */ + public function getConfirmationMethod() + { + return $this->getParameter('confirmation_method'); + } /** * @inheritdoc @@ -377,9 +426,6 @@ public function getData() 'type' => 'card', 'card' => ['token' => $this->getToken()], ]; - } else { - // one of cardReference, token, or card is required - $this->validate('paymentMethod'); } if ($this->getCustomerReference()) { @@ -392,8 +438,8 @@ public function getData() $data['off_session'] = $this->getOffSession() ? 'true' : 'false'; - $data['confirmation_method'] = 'manual'; - $data['capture_method'] = 'manual'; + $data['confirmation_method'] = $this->getConfirmationMethod(); + $data['capture_method'] = $this->getCaptureMethod(); $data['confirm'] = $this->getConfirm() ? 'true' : 'false'; From a09855b6f5ef7e62993d24b9f946ba26830224f7 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 25 Aug 2020 22:09:34 +0100 Subject: [PATCH 2/3] Updated docblocks --- src/Message/PaymentIntents/AuthorizeRequest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Message/PaymentIntents/AuthorizeRequest.php b/src/Message/PaymentIntents/AuthorizeRequest.php index f7eeb592..cf840809 100644 --- a/src/Message/PaymentIntents/AuthorizeRequest.php +++ b/src/Message/PaymentIntents/AuthorizeRequest.php @@ -338,7 +338,7 @@ public function getOffSession() */ public function setCaptureMethod($value) { - if($value == null) { + if ($value == null) { $value = 'automatic'; } @@ -347,6 +347,8 @@ public function setCaptureMethod($value) /** + * Get the capture_method parameter. + * * @return mixed */ public function getCaptureMethod() @@ -363,14 +365,17 @@ public function getCaptureMethod() */ public function setConfirmationMethod($value) { - if($value == null) { + if ($value == null) { $value = 'automatic'; } + return $this->setParameter('confirmation_method', $value); } /** + * Get the confrimation_method parameter. + * * @return mixed */ public function getConfirmationMethod() From 291420f3bb2454e8cb6b3f07393e3560cd14ac46 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 25 Aug 2020 22:31:55 +0100 Subject: [PATCH 3/3] Update tests --- src/Message/PaymentIntents/AuthorizeRequest.php | 8 ++------ tests/Message/PaymentIntents/AuthorizeRequestTest.php | 6 ++++-- tests/Message/PaymentIntents/PurchaseRequestTest.php | 6 ++++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Message/PaymentIntents/AuthorizeRequest.php b/src/Message/PaymentIntents/AuthorizeRequest.php index cf840809..5529253b 100644 --- a/src/Message/PaymentIntents/AuthorizeRequest.php +++ b/src/Message/PaymentIntents/AuthorizeRequest.php @@ -338,9 +338,7 @@ public function getOffSession() */ public function setCaptureMethod($value) { - if ($value == null) { - $value = 'automatic'; - } + $value = ($value === null) ? 'automatic' : $value; return $this->setParameter('capture_method', $value); } @@ -365,9 +363,7 @@ public function getCaptureMethod() */ public function setConfirmationMethod($value) { - if ($value == null) { - $value = 'automatic'; - } + $value = ($value === null) ? 'automatic' : $value; return $this->setParameter('confirmation_method', $value); } diff --git a/tests/Message/PaymentIntents/AuthorizeRequestTest.php b/tests/Message/PaymentIntents/AuthorizeRequestTest.php index 5081eb01..32174735 100644 --- a/tests/Message/PaymentIntents/AuthorizeRequestTest.php +++ b/tests/Message/PaymentIntents/AuthorizeRequestTest.php @@ -28,6 +28,8 @@ public function setUp() 'setup_future_usage' => 'off_session', 'off_session' => false, 'confirm' => true, + 'capture_method' => null, + 'confirmation_method' => null ) ); } @@ -39,8 +41,8 @@ public function testGetData() $this->assertSame(1200, $data['amount']); $this->assertSame('usd', $data['currency']); $this->assertSame('Order #42', $data['description']); - $this->assertSame('manual', $data['capture_method']); - $this->assertSame('manual', $data['confirmation_method']); + $this->assertSame('automatic', $data['capture_method']); + $this->assertSame('automatic', $data['confirmation_method']); $this->assertSame('pm_valid_payment_method', $data['payment_method']); $this->assertSame(array('foo' => 'bar'), $data['metadata']); $this->assertSame(100, $data['application_fee']); diff --git a/tests/Message/PaymentIntents/PurchaseRequestTest.php b/tests/Message/PaymentIntents/PurchaseRequestTest.php index 09af7fae..41c5a30c 100644 --- a/tests/Message/PaymentIntents/PurchaseRequestTest.php +++ b/tests/Message/PaymentIntents/PurchaseRequestTest.php @@ -23,7 +23,9 @@ public function setUp() 'metadata' => array( 'foo' => 'bar', ), - 'applicationFee' => '1.00' + 'applicationFee' => '1.00', + 'capture_method' => null, + 'confirmation_method' => null ) ); } @@ -36,7 +38,7 @@ public function testGetData() $this->assertSame('usd', $data['currency']); $this->assertSame('Order #42', $data['description']); $this->assertSame('automatic', $data['capture_method']); - $this->assertSame('manual', $data['confirmation_method']); + $this->assertSame('automatic', $data['confirmation_method']); $this->assertSame('pm_valid_payment_method', $data['payment_method']); $this->assertSame(array('foo' => 'bar'), $data['metadata']); $this->assertSame(100, $data['application_fee']);