From 4e1eb5a7c55d4149bb504951351d1bca588f0110 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Tue, 18 Jun 2024 13:50:17 +0200 Subject: [PATCH] NTR: add bancomat --- Components/Constants/PaymentMethod.php | 1 + .../PaymentMethodsInstaller.php | 1 + Services/Mollie/Payments/PaymentFactory.php | 4 + .../Mollie/Payments/Requests/BancomatPay.php | 25 ++++ .../Constants/PaymentMethodTypeTest.php | 1 + .../Installer/PaymentMethodsInstallerTest.php | 1 + .../Payments/Requests/BancomatPayTest.php | 136 ++++++++++++++++++ 7 files changed, 169 insertions(+) create mode 100644 Services/Mollie/Payments/Requests/BancomatPay.php create mode 100644 Tests/PHPUnit/Services/Mollie/Payments/Requests/BancomatPayTest.php diff --git a/Components/Constants/PaymentMethod.php b/Components/Constants/PaymentMethod.php index 83c9e15d..999bed84 100644 --- a/Components/Constants/PaymentMethod.php +++ b/Components/Constants/PaymentMethod.php @@ -29,4 +29,5 @@ class PaymentMethod const VOUCHERS = "voucher"; const IN3 = "in3"; const TWINT = "twint"; + const BANCOMAT_PAY = "bancomatpay"; } diff --git a/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php b/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php index 6f395516..d358f083 100644 --- a/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php +++ b/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php @@ -120,6 +120,7 @@ public static function getSupportedPaymentMethods() PaymentMethod::VOUCHERS, PaymentMethod::IN3, PaymentMethod::TWINT, + PaymentMethod::BANCOMAT_PAY, ]; } diff --git a/Services/Mollie/Payments/PaymentFactory.php b/Services/Mollie/Payments/PaymentFactory.php index b63c3600..1f8a142c 100644 --- a/Services/Mollie/Payments/PaymentFactory.php +++ b/Services/Mollie/Payments/PaymentFactory.php @@ -5,6 +5,7 @@ use MollieShopware\Components\Constants\PaymentMethod; use MollieShopware\Services\Mollie\Payments\Models\Payment; use MollieShopware\Services\Mollie\Payments\Requests\ApplePay; +use MollieShopware\Services\Mollie\Payments\Requests\BancomatPay; use MollieShopware\Services\Mollie\Payments\Requests\Bancontact; use MollieShopware\Services\Mollie\Payments\Requests\BankTransfer; use MollieShopware\Services\Mollie\Payments\Requests\Belfius; @@ -103,6 +104,9 @@ public function createByPaymentName($paymentMethod) case PaymentMethod::TWINT: return new Twint(); + + case PaymentMethod::BANCOMAT_PAY: + return new BancomatPay(); } throw new \Exception('Payment handler not found for: ' . $paymentMethod); diff --git a/Services/Mollie/Payments/Requests/BancomatPay.php b/Services/Mollie/Payments/Requests/BancomatPay.php new file mode 100644 index 00000000..5b63beed --- /dev/null +++ b/Services/Mollie/Payments/Requests/BancomatPay.php @@ -0,0 +1,25 @@ +assertEquals($expected, PaymentMethodsInstaller::getSupportedPaymentMethods()); diff --git a/Tests/PHPUnit/Services/Mollie/Payments/Requests/BancomatPayTest.php b/Tests/PHPUnit/Services/Mollie/Payments/Requests/BancomatPayTest.php new file mode 100644 index 00000000..19f1bb7b --- /dev/null +++ b/Tests/PHPUnit/Services/Mollie/Payments/Requests/BancomatPayTest.php @@ -0,0 +1,136 @@ +payment = new BancomatPay(); + + $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], + 'EUR', + 'de_DE', + 'https://local/redirect', + 'https://local/notify' + ) + ); + } + + /** + * This test verifies that the Payments-API request + * for our payment is correct. + */ + public function testPaymentsAPI() + { + $expected = [ + 'method' => PaymentMethod::BANCOMAT_PAY, + 'amount' => [ + 'currency' => 'EUR', + '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::BANCOMAT_PAY, + 'amount' => [ + 'currency' => 'EUR', + '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']); + } +}