From c13df34a0b19a8e8e4c5877aea607c870dc80c27 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Thu, 21 Mar 2024 13:17:13 +0100 Subject: [PATCH] NTR: PISHPS-247: Klarna One payment (#727) Co-authored-by: Vitalij Mik --- src/Handler/Method/KlarnaOnePayment.php | 32 +++++++++ src/Resources/config/services/handlers.xml | 8 +++ src/Service/PaymentMethodService.php | 2 + .../Payments/KlarnaOneOrderBuilderTest.php | 67 +++++++++++++++++++ .../Service/PaymentMethodServiceTest.php | 2 + 5 files changed, 111 insertions(+) create mode 100644 src/Handler/Method/KlarnaOnePayment.php create mode 100644 tests/PHPUnit/Service/MollieApi/Builder/Payments/KlarnaOneOrderBuilderTest.php diff --git a/src/Handler/Method/KlarnaOnePayment.php b/src/Handler/Method/KlarnaOnePayment.php new file mode 100644 index 000000000..a0dcaf1ad --- /dev/null +++ b/src/Handler/Method/KlarnaOnePayment.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 5ffa6d2d6..68ff045d9 100644 --- a/src/Resources/config/services/handlers.xml +++ b/src/Resources/config/services/handlers.xml @@ -190,6 +190,14 @@ + + + + + + + + diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index 6e2fe5349..9ea8e9b8f 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -17,6 +17,7 @@ use Kiener\MolliePayments\Handler\Method\In3Payment; use Kiener\MolliePayments\Handler\Method\IngHomePayPayment; use Kiener\MolliePayments\Handler\Method\KbcPayment; +use Kiener\MolliePayments\Handler\Method\KlarnaOnePayment; use Kiener\MolliePayments\Handler\Method\KlarnaPayLaterPayment; use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment; use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment; @@ -430,6 +431,7 @@ public function getPaymentHandlers(): array KlarnaPayLaterPayment::class, KlarnaPayNowPayment::class, KlarnaSliceItPayment::class, + KlarnaOnePayment::class, PayPalPayment::class, PaySafeCardPayment::class, Przelewy24Payment::class, diff --git a/tests/PHPUnit/Service/MollieApi/Builder/Payments/KlarnaOneOrderBuilderTest.php b/tests/PHPUnit/Service/MollieApi/Builder/Payments/KlarnaOneOrderBuilderTest.php new file mode 100644 index 000000000..402f29313 --- /dev/null +++ b/tests/PHPUnit/Service/MollieApi/Builder/Payments/KlarnaOneOrderBuilderTest.php @@ -0,0 +1,67 @@ +router->method('generate')->willReturn($redirectWebhookUrl); + $paymentMethod = PaymentMethod::KLARNA_PAY_LATER; + + $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 8c01d69a5..f7796943f 100644 --- a/tests/PHPUnit/Service/PaymentMethodServiceTest.php +++ b/tests/PHPUnit/Service/PaymentMethodServiceTest.php @@ -15,6 +15,7 @@ use Kiener\MolliePayments\Handler\Method\iDealPayment; use Kiener\MolliePayments\Handler\Method\In3Payment; use Kiener\MolliePayments\Handler\Method\KbcPayment; +use Kiener\MolliePayments\Handler\Method\KlarnaOnePayment; use Kiener\MolliePayments\Handler\Method\KlarnaPayLaterPayment; use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment; use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment; @@ -120,6 +121,7 @@ public function testSupportedMethods(): void KlarnaPayLaterPayment::class, KlarnaPayNowPayment::class, KlarnaSliceItPayment::class, + KlarnaOnePayment::class, PayPalPayment::class, PaySafeCardPayment::class, Przelewy24Payment::class,