From 128f9a626abdf27b73be5168a60c206174cda11d Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Mon, 11 Mar 2024 16:48:57 +0800 Subject: [PATCH 1/2] Able to set service version --- src/PaymentMethods/PaymentFacade.php | 7 +++++++ src/PaymentMethods/PaymentMethod.php | 10 ++++++++++ tests/Buckaroo/Payments/AfterpayTest.php | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/PaymentMethods/PaymentFacade.php b/src/PaymentMethods/PaymentFacade.php index 584472ac..a74b2636 100644 --- a/src/PaymentMethods/PaymentFacade.php +++ b/src/PaymentMethods/PaymentFacade.php @@ -168,6 +168,13 @@ public function __call(?string $name, array $arguments) { if (method_exists($this->paymentMethod, $name)) { + if($name === 'setServiceVersion') + { + $this->paymentMethod->setServiceVersion($arguments[0]); + + return $this; + } + $this->paymentMethod->setPayload((new PayloadService($arguments[0] ?? []))->toArray()); return $this->paymentMethod->$name(); diff --git a/src/PaymentMethods/PaymentMethod.php b/src/PaymentMethods/PaymentMethod.php index 3041656c..0a1cf3a8 100644 --- a/src/PaymentMethods/PaymentMethod.php +++ b/src/PaymentMethods/PaymentMethod.php @@ -171,6 +171,16 @@ public function serviceVersion(): int return $this->serviceVersion; } + /** + * @return PaymentInterface + */ + public function setServiceVersion(int $serviceVersion): PaymentInterface + { + $this->serviceVersion = $serviceVersion; + + return $this; + } + /** * @param bool|null $isManually * @return $this diff --git a/tests/Buckaroo/Payments/AfterpayTest.php b/tests/Buckaroo/Payments/AfterpayTest.php index a92d30d0..bec23abd 100644 --- a/tests/Buckaroo/Payments/AfterpayTest.php +++ b/tests/Buckaroo/Payments/AfterpayTest.php @@ -31,7 +31,7 @@ class AfterpayTest extends BuckarooTestCase */ public function it_creates_a_afterpay_payment() { - $response = $this->buckaroo->method('afterpay')->pay($this->getPaymentPayload()); + $response = $this->buckaroo->method('afterpay')->setServiceVersion(3)->pay($this->getPaymentPayload()); $this->assertTrue($response->isSuccess()); } From c3c3130605e7ea0e9090f242d3879e38503a62ed Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Tue, 12 Mar 2024 14:34:12 +0800 Subject: [PATCH 2/2] Fix style --- src/PaymentMethods/PaymentFacade.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/PaymentMethods/PaymentFacade.php b/src/PaymentMethods/PaymentFacade.php index a74b2636..76d65d68 100644 --- a/src/PaymentMethods/PaymentFacade.php +++ b/src/PaymentMethods/PaymentFacade.php @@ -166,10 +166,8 @@ public function paymentMethod(): PaymentMethod */ public function __call(?string $name, array $arguments) { - if (method_exists($this->paymentMethod, $name)) - { - if($name === 'setServiceVersion') - { + if (method_exists($this->paymentMethod, $name)) { + if($name === 'setServiceVersion') { $this->paymentMethod->setServiceVersion($arguments[0]); return $this;