From a67906e6c6afee41b5a621262b5dd9d29e32cbfc Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 19 Jun 2024 10:01:06 +0200 Subject: [PATCH] NTR: add blik fix #411 (#417) Co-authored-by: Vitalij Mik --- Components/Constants/PaymentMethod.php | 1 + .../PaymentMethodsInstaller.php | 1 + Services/Mollie/Payments/PaymentFactory.php | 4 + Services/Mollie/Payments/Requests/Blik.php | 25 +++ .../storefront/checkout/checkout-full.cy.js | 2 +- .../Constants/PaymentMethodTypeTest.php | 1 + .../Installer/PaymentMethodsInstallerTest.php | 1 + .../Mollie/Payments/Requests/BlikTest.php | 143 ++++++++++++++++++ 8 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 Services/Mollie/Payments/Requests/Blik.php create mode 100644 Tests/PHPUnit/Services/Mollie/Payments/Requests/BlikTest.php diff --git a/Components/Constants/PaymentMethod.php b/Components/Constants/PaymentMethod.php index 999bed84..8dd85871 100644 --- a/Components/Constants/PaymentMethod.php +++ b/Components/Constants/PaymentMethod.php @@ -30,4 +30,5 @@ class PaymentMethod const IN3 = "in3"; const TWINT = "twint"; const BANCOMAT_PAY = "bancomatpay"; + const BLIK = "blik"; } diff --git a/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php b/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php index d358f083..0829072b 100644 --- a/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php +++ b/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php @@ -121,6 +121,7 @@ public static function getSupportedPaymentMethods() PaymentMethod::IN3, PaymentMethod::TWINT, PaymentMethod::BANCOMAT_PAY, + PaymentMethod::BLIK, ]; } diff --git a/Services/Mollie/Payments/PaymentFactory.php b/Services/Mollie/Payments/PaymentFactory.php index 1f8a142c..3c7dda48 100644 --- a/Services/Mollie/Payments/PaymentFactory.php +++ b/Services/Mollie/Payments/PaymentFactory.php @@ -10,6 +10,7 @@ use MollieShopware\Services\Mollie\Payments\Requests\BankTransfer; use MollieShopware\Services\Mollie\Payments\Requests\Belfius; use MollieShopware\Services\Mollie\Payments\Requests\Billie; +use MollieShopware\Services\Mollie\Payments\Requests\Blik; use MollieShopware\Services\Mollie\Payments\Requests\CreditCard; use MollieShopware\Services\Mollie\Payments\Requests\EPS; use MollieShopware\Services\Mollie\Payments\Requests\Giftcard; @@ -107,6 +108,9 @@ public function createByPaymentName($paymentMethod) case PaymentMethod::BANCOMAT_PAY: return new BancomatPay(); + + case PaymentMethod::BLIK: + return new Blik(); } throw new \Exception('Payment handler not found for: ' . $paymentMethod); diff --git a/Services/Mollie/Payments/Requests/Blik.php b/Services/Mollie/Payments/Requests/Blik.php new file mode 100644 index 00000000..d9744f59 --- /dev/null +++ b/Services/Mollie/Payments/Requests/Blik.php @@ -0,0 +1,25 @@ + { cy.contains('Vielen Dank für Ihre Bestellung'); // also verify that our address is correctly visible - cy.get('.billing--panel').contains('Max Mustermann'); + cy.get('.billing--panel').should('be.visible').contains('Max Mustermann'); }) }) diff --git a/Tests/PHPUnit/Components/Constants/PaymentMethodTypeTest.php b/Tests/PHPUnit/Components/Constants/PaymentMethodTypeTest.php index 6acafd4d..d3d359b4 100644 --- a/Tests/PHPUnit/Components/Constants/PaymentMethodTypeTest.php +++ b/Tests/PHPUnit/Components/Constants/PaymentMethodTypeTest.php @@ -76,6 +76,7 @@ public function getPaymentMethods() [true, PaymentMethod::KBC], [true, PaymentMethod::TWINT], [true, PaymentMethod::BANCOMAT_PAY], + [true, PaymentMethod::BLIK], ]; } diff --git a/Tests/PHPUnit/Components/Installer/PaymentMethodsInstallerTest.php b/Tests/PHPUnit/Components/Installer/PaymentMethodsInstallerTest.php index 0be34116..e2b18895 100644 --- a/Tests/PHPUnit/Components/Installer/PaymentMethodsInstallerTest.php +++ b/Tests/PHPUnit/Components/Installer/PaymentMethodsInstallerTest.php @@ -53,6 +53,7 @@ public function testSupportedPaymentMethods() PaymentMethod::IN3, PaymentMethod::TWINT, PaymentMethod::BANCOMAT_PAY, + PaymentMethod::BLIK ]; $this->assertEquals($expected, PaymentMethodsInstaller::getSupportedPaymentMethods()); diff --git a/Tests/PHPUnit/Services/Mollie/Payments/Requests/BlikTest.php b/Tests/PHPUnit/Services/Mollie/Payments/Requests/BlikTest.php new file mode 100644 index 00000000..ad18b8f2 --- /dev/null +++ b/Tests/PHPUnit/Services/Mollie/Payments/Requests/BlikTest.php @@ -0,0 +1,143 @@ +payment = new Blik(); + $this->methodName = PaymentMethod::BLIK; + $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' => $this->methodName, + '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' => $this->methodName, + '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']); + } +}