From 680b2d1df681edda5ef9b80c9d24cb307af6769b Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 15 May 2024 09:17:57 +0200 Subject: [PATCH] NTR: PISHPS-281 MyBank payment fix #739 --- src/Handler/Method/MyBankPayment.php | 32 +++++++++ src/Resources/config/services/handlers.xml | 7 ++ src/Service/PaymentMethodService.php | 2 + .../Payments/MyBankOrderBuilderTest.php | 67 +++++++++++++++++++ .../Service/PaymentMethodServiceTest.php | 2 + 5 files changed, 110 insertions(+) create mode 100644 src/Handler/Method/MyBankPayment.php create mode 100644 tests/PHPUnit/Service/MollieApi/Builder/Payments/MyBankOrderBuilderTest.php diff --git a/src/Handler/Method/MyBankPayment.php b/src/Handler/Method/MyBankPayment.php new file mode 100644 index 000000000..92cf0b3a2 --- /dev/null +++ b/src/Handler/Method/MyBankPayment.php @@ -0,0 +1,32 @@ + $orderData + * @param OrderEntity $orderEntity + * @param SalesChannelContext $salesChannelContext + * @param CustomerEntity $customer + * @return array + */ + public function processPaymentMethodSpecificParameters(array $orderData, OrderEntity $orderEntity, SalesChannelContext $salesChannelContext, CustomerEntity $customer): array + { + return $orderData; + } +} diff --git a/src/Resources/config/services/handlers.xml b/src/Resources/config/services/handlers.xml index dd3e77fea..dcf54e0ff 100644 --- a/src/Resources/config/services/handlers.xml +++ b/src/Resources/config/services/handlers.xml @@ -204,6 +204,13 @@ + + + + + + + diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index ee11f6733..c6b429c66 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -22,6 +22,7 @@ use Kiener\MolliePayments\Handler\Method\KlarnaPayLaterPayment; use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment; use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment; +use Kiener\MolliePayments\Handler\Method\MyBankPayment; use Kiener\MolliePayments\Handler\Method\PayPalPayment; use Kiener\MolliePayments\Handler\Method\PaySafeCardPayment; use Kiener\MolliePayments\Handler\Method\PosPayment; @@ -443,6 +444,7 @@ public function getPaymentHandlers(): array TwintPayment::class, BlikPayment::class, BancomatPayment::class, + MyBankPayment::class, // IngHomePayPayment::class, // not allowed anymore // DirectDebitPayment::class, // only allowed when updating subsriptions, aka => not allowed anymore ]; diff --git a/tests/PHPUnit/Service/MollieApi/Builder/Payments/MyBankOrderBuilderTest.php b/tests/PHPUnit/Service/MollieApi/Builder/Payments/MyBankOrderBuilderTest.php new file mode 100644 index 000000000..dcb2e3524 --- /dev/null +++ b/tests/PHPUnit/Service/MollieApi/Builder/Payments/MyBankOrderBuilderTest.php @@ -0,0 +1,67 @@ +router->method('generate')->willReturn($redirectWebhookUrl); + $paymentMethod = PaymentMethod::MYBANK; + + $this->paymentHandler = new KlarnaOnePayment( + $this->loggerService, + new FakeContainer() + ); + + $transactionId = Uuid::randomHex(); + $amountTotal = 27.0; + $taxStatus = CartPrice::TAX_STATE_GROSS; + $currencyISO = 'EUR'; + + $currency = new CurrencyEntity(); + $currency->setId(Uuid::randomHex()); + $currency->setIsoCode($currencyISO); + + $orderNumber = 'foo number'; + $lineItems = $this->getDummyLineItems(); + + $order = $this->getOrderEntity($amountTotal, $taxStatus, $currencyISO, $lineItems, $orderNumber); + + $actual = $this->builder->buildOrderPayload($order, $transactionId, $paymentMethod, $this->salesChannelContext, $this->paymentHandler, []); + + $expectedOrderLifeTime = (new DateTime())->setTimezone(new DateTimeZone('UTC')) + ->modify(sprintf('+%d day', $this->expiresAt)) + ->format('Y-m-d'); + + $expected = [ + 'amount' => (new MollieOrderPriceBuilder())->build($amountTotal, $currencyISO), + 'locale' => $this->localeCode, + 'method' => $paymentMethod, + 'orderNumber' => $orderNumber, + 'payment' => ['webhookUrl' => $redirectWebhookUrl], + 'redirectUrl' => $redirectWebhookUrl, + 'webhookUrl' => $redirectWebhookUrl, + 'lines' => $this->getExpectedLineItems($taxStatus, $lineItems, $currency), + 'billingAddress' => $this->getExpectedTestAddress($this->address, $this->email), + 'shippingAddress' => $this->getExpectedTestAddress($this->address, $this->email), + 'expiresAt' => $expectedOrderLifeTime + ]; + + self::assertSame($expected, $actual); + } +} diff --git a/tests/PHPUnit/Service/PaymentMethodServiceTest.php b/tests/PHPUnit/Service/PaymentMethodServiceTest.php index 84a932984..0bcbf9dc8 100644 --- a/tests/PHPUnit/Service/PaymentMethodServiceTest.php +++ b/tests/PHPUnit/Service/PaymentMethodServiceTest.php @@ -20,6 +20,7 @@ use Kiener\MolliePayments\Handler\Method\KlarnaPayLaterPayment; use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment; use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment; +use Kiener\MolliePayments\Handler\Method\MyBankPayment; use Kiener\MolliePayments\Handler\Method\PayPalPayment; use Kiener\MolliePayments\Handler\Method\PaySafeCardPayment; use Kiener\MolliePayments\Handler\Method\PosPayment; @@ -133,6 +134,7 @@ public function testSupportedMethods(): void TwintPayment::class, BlikPayment::class, BancomatPayment::class, + MyBankPayment::class, ]; $handlers = $this->paymentMethodService->getPaymentHandlers();