From 08ac59ed6d09cf084dfe4e7b245508e48fbef198 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Tue, 2 Jul 2024 09:40:03 +0200 Subject: [PATCH] NTR: PISHPS-288: add riverty --- src/Handler/Method/RivertyPayment.php | 16 +++++ src/Resources/config/services/handlers.xml | 6 ++ src/Service/PaymentMethodService.php | 2 + .../Payments/RivertyOrderBuilderTest.php | 67 +++++++++++++++++++ .../Service/PaymentMethodServiceTest.php | 2 + 5 files changed, 93 insertions(+) create mode 100644 src/Handler/Method/RivertyPayment.php create mode 100644 tests/PHPUnit/Service/MollieApi/Builder/Payments/RivertyOrderBuilderTest.php diff --git a/src/Handler/Method/RivertyPayment.php b/src/Handler/Method/RivertyPayment.php new file mode 100644 index 000000000..7aaf77ac4 --- /dev/null +++ b/src/Handler/Method/RivertyPayment.php @@ -0,0 +1,16 @@ + + + + + + + diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index ddd40e95b..0b11482c4 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -28,6 +28,7 @@ use Kiener\MolliePayments\Handler\Method\PaySafeCardPayment; use Kiener\MolliePayments\Handler\Method\PosPayment; use Kiener\MolliePayments\Handler\Method\Przelewy24Payment; +use Kiener\MolliePayments\Handler\Method\RivertyPayment; use Kiener\MolliePayments\Handler\Method\SofortPayment; use Kiener\MolliePayments\Handler\Method\TwintPayment; use Kiener\MolliePayments\Handler\Method\VoucherPayment; @@ -446,6 +447,7 @@ public function getPaymentHandlers(): array BancomatPayment::class, MyBankPayment::class, AlmaPayment::class, + RivertyPayment::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/RivertyOrderBuilderTest.php b/tests/PHPUnit/Service/MollieApi/Builder/Payments/RivertyOrderBuilderTest.php new file mode 100644 index 000000000..ea29a0b4d --- /dev/null +++ b/tests/PHPUnit/Service/MollieApi/Builder/Payments/RivertyOrderBuilderTest.php @@ -0,0 +1,67 @@ +router->method('generate')->willReturn($redirectWebhookUrl); + + $this->paymentHandler = new RivertyPayment( + $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, $this->paymentHandler::PAYMENT_METHOD_NAME, $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' => $this->paymentHandler::PAYMENT_METHOD_NAME, + '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 9fd939294..2bb7c455c 100644 --- a/tests/PHPUnit/Service/PaymentMethodServiceTest.php +++ b/tests/PHPUnit/Service/PaymentMethodServiceTest.php @@ -26,6 +26,7 @@ use Kiener\MolliePayments\Handler\Method\PaySafeCardPayment; use Kiener\MolliePayments\Handler\Method\PosPayment; use Kiener\MolliePayments\Handler\Method\Przelewy24Payment; +use Kiener\MolliePayments\Handler\Method\RivertyPayment; use Kiener\MolliePayments\Handler\Method\SofortPayment; use Kiener\MolliePayments\Handler\Method\TwintPayment; use Kiener\MolliePayments\Handler\Method\VoucherPayment; @@ -136,6 +137,7 @@ public function testSupportedMethods(): void BancomatPayment::class, MyBankPayment::class, AlmaPayment::class, + RivertyPayment::class ]; $handlers = $this->paymentMethodService->getPaymentHandlers();