From dcf232ec091037d62fc3be6bcfeaf1b6ccfa22f7 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Mon, 9 Sep 2024 11:09:39 +0200 Subject: [PATCH] NTR: PISHPW-231: Add satispay payment --- Components/Constants/PaymentMethod.php | 1 + .../PaymentMethodsInstaller.php | 1 + Services/Mollie/Payments/PaymentFactory.php | 3 + .../Mollie/Payments/Requests/Satispay.php | 25 ++++ .../Installer/PaymentMethodsInstallerTest.php | 1 + .../Mollie/Payments/Requests/SatispayTest.php | 138 ++++++++++++++++++ 6 files changed, 169 insertions(+) create mode 100644 Services/Mollie/Payments/Requests/Satispay.php create mode 100644 Tests/PHPUnit/Services/Mollie/Payments/Requests/SatispayTest.php diff --git a/Components/Constants/PaymentMethod.php b/Components/Constants/PaymentMethod.php index 735eb4b7..30a6e8da 100644 --- a/Components/Constants/PaymentMethod.php +++ b/Components/Constants/PaymentMethod.php @@ -35,4 +35,5 @@ class PaymentMethod const BLIK = "blik"; const RIVERTY = "riverty"; const PAYCONIQ = "payconiq"; + const SATISPAY = "satispay"; } diff --git a/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php b/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php index 62ba2578..914ebb4c 100644 --- a/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php +++ b/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php @@ -125,6 +125,7 @@ public static function getSupportedPaymentMethods() PaymentMethod::KLARNA_ONE, PaymentMethod::RIVERTY, PaymentMethod::PAYCONIQ, + PaymentMethod::SATISPAY, ]; } diff --git a/Services/Mollie/Payments/PaymentFactory.php b/Services/Mollie/Payments/PaymentFactory.php index db0d50e4..ee9fd25a 100644 --- a/Services/Mollie/Payments/PaymentFactory.php +++ b/Services/Mollie/Payments/PaymentFactory.php @@ -26,6 +26,7 @@ use MollieShopware\Services\Mollie\Payments\Requests\Paysafecard; use MollieShopware\Services\Mollie\Payments\Requests\Przelewy24; use MollieShopware\Services\Mollie\Payments\Requests\Riverty; +use MollieShopware\Services\Mollie\Payments\Requests\Satispay; use MollieShopware\Services\Mollie\Payments\Requests\SepaDirectDebit; use MollieShopware\Services\Mollie\Payments\Requests\SliceIt; use MollieShopware\Services\Mollie\Payments\Requests\Sofort; @@ -123,6 +124,8 @@ public function createByPaymentName($paymentMethod) case PaymentMethod::PAYCONIQ: return new PayConiq(); + case PaymentMethod::SATISPAY: + return new Satispay(); } throw new \Exception('Payment handler not found for: ' . $paymentMethod); diff --git a/Services/Mollie/Payments/Requests/Satispay.php b/Services/Mollie/Payments/Requests/Satispay.php new file mode 100644 index 00000000..abf7d81c --- /dev/null +++ b/Services/Mollie/Payments/Requests/Satispay.php @@ -0,0 +1,25 @@ +assertEquals($expected, PaymentMethodsInstaller::getSupportedPaymentMethods()); diff --git a/Tests/PHPUnit/Services/Mollie/Payments/Requests/SatispayTest.php b/Tests/PHPUnit/Services/Mollie/Payments/Requests/SatispayTest.php new file mode 100644 index 00000000..50980e7c --- /dev/null +++ b/Tests/PHPUnit/Services/Mollie/Payments/Requests/SatispayTest.php @@ -0,0 +1,138 @@ +payment = new Satispay(); + + $this->addressInvoice = $this->getAddressFixture1(); + $this->addressShipping = $this->getAddressFixture2(); + $this->lineItem = $this->getLineItemFixture(); + + $this->payment->setPayment( + new Payment( + 'UUID-123', + 'Payment UUID-123', + '20004', + $this->addressInvoice, + $this->addressShipping, + 49.98, + [$this->lineItem], + 'CHF', + 'de_DE', + 'https://local/redirect', + 'https://local/notify' + ) + ); + } + + /** + * This test verifies that the Payments-API request + * for our payment is correct. + * Please note, Twint does not work with the payments API + * so this is just an empty array + */ + public function testPaymentsAPI() + { + $expected = [ + 'method' => PaymentMethod::SATISPAY, + 'amount' => [ + 'currency' => 'CHF', + 'value' => '49.98', + ], + 'description' => 'Payment UUID-123', + 'redirectUrl' => 'https://local/redirect', + 'webhookUrl' => 'https://local/notify', + 'locale' => 'de_DE', + ]; + + $requestBody = $this->payment->buildBodyPaymentsAPI(); + + $this->assertEquals($expected, $requestBody); + } + + /** + * This test verifies that the Orders-API request + * for our payment is correct. + */ + public function testOrdersAPI() + { + $expected = [ + 'method' => PaymentMethod::SATISPAY, + 'amount' => [ + 'currency' => 'CHF', + 'value' => '49.98', + ], + 'redirectUrl' => 'https://local/redirect', + 'webhookUrl' => 'https://local/notify', + 'locale' => 'de_DE', + 'orderNumber' => '20004', + 'payment' => [ + 'webhookUrl' => 'https://local/notify', + ], + 'billingAddress' => $this->getExpectedAddressStructure($this->addressInvoice), + 'shippingAddress' => $this->getExpectedAddressStructure($this->addressShipping), + 'lines' => [ + $this->getExpectedLineItemStructure($this->lineItem), + ], + 'metadata' => [], + ]; + + $requestBody = $this->payment->buildBodyOrdersAPI(); + + $this->assertSame($expected, $requestBody); + } + + /** + * This test verifies that we can set a custom expiration date + * for our Orders API request. + */ + public function testExpirationDate() + { + $dueInDays = 5; + $expectedDueDate = date('Y-m-d', strtotime(' + ' . $dueInDays . ' day')); + + $this->payment->setExpirationDays($dueInDays); + $request = $this->payment->buildBodyOrdersAPI(); + + $this->assertEquals($expectedDueDate, $request['expiresAt']); + } +}