From f27dcb6d80478b9a6223935253df3fe789378b26 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 15 May 2024 14:53:53 +0200 Subject: [PATCH 1/2] NTR: PISHPS: Add alma payment (#746) Co-authored-by: Vitalij Mik --- src/Handler/Method/AlmaPayment.php | 32 +++++++++ src/Resources/config/services/handlers.xml | 8 +++ src/Service/PaymentMethodService.php | 2 + .../Builder/Payments/AlmaOrderBuilderTest.php | 67 +++++++++++++++++++ .../Service/PaymentMethodServiceTest.php | 2 + 5 files changed, 111 insertions(+) create mode 100644 src/Handler/Method/AlmaPayment.php create mode 100644 tests/PHPUnit/Service/MollieApi/Builder/Payments/AlmaOrderBuilderTest.php diff --git a/src/Handler/Method/AlmaPayment.php b/src/Handler/Method/AlmaPayment.php new file mode 100644 index 000000000..6dbc6d0aa --- /dev/null +++ b/src/Handler/Method/AlmaPayment.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..4c53f376f 100644 --- a/src/Resources/config/services/handlers.xml +++ b/src/Resources/config/services/handlers.xml @@ -204,6 +204,14 @@ + + + + + + + + diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index ee11f6733..6e610c85e 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -3,6 +3,7 @@ namespace Kiener\MolliePayments\Service; use Kiener\MolliePayments\Compatibility\VersionCompare; +use Kiener\MolliePayments\Handler\Method\AlmaPayment; use Kiener\MolliePayments\Handler\Method\ApplePayPayment; use Kiener\MolliePayments\Handler\Method\BancomatPayment; use Kiener\MolliePayments\Handler\Method\BanContactPayment; @@ -443,6 +444,7 @@ public function getPaymentHandlers(): array TwintPayment::class, BlikPayment::class, BancomatPayment::class, + AlmaPayment::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/AlmaOrderBuilderTest.php b/tests/PHPUnit/Service/MollieApi/Builder/Payments/AlmaOrderBuilderTest.php new file mode 100644 index 000000000..66ed11367 --- /dev/null +++ b/tests/PHPUnit/Service/MollieApi/Builder/Payments/AlmaOrderBuilderTest.php @@ -0,0 +1,67 @@ +router->method('generate')->willReturn($redirectWebhookUrl); + $paymentMethod = PaymentMethod::ALMA; + + $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..70b5a21e6 100644 --- a/tests/PHPUnit/Service/PaymentMethodServiceTest.php +++ b/tests/PHPUnit/Service/PaymentMethodServiceTest.php @@ -2,6 +2,7 @@ namespace Kiener\MolliePayments\Tests\Service; +use Kiener\MolliePayments\Handler\Method\AlmaPayment; use Kiener\MolliePayments\Handler\Method\ApplePayPayment; use Kiener\MolliePayments\Handler\Method\BancomatPayment; use Kiener\MolliePayments\Handler\Method\BanContactPayment; @@ -133,6 +134,7 @@ public function testSupportedMethods(): void TwintPayment::class, BlikPayment::class, BancomatPayment::class, + AlmaPayment::class, ]; $handlers = $this->paymentMethodService->getPaymentHandlers(); From b9e41ab8e8a5056689c39c78e1c99824829fe23f Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 15 May 2024 14:55:10 +0200 Subject: [PATCH 2/2] NTR: PISHPS-246: Compatiblity with AcrisPersistenCartCS (#748) Co-authored-by: Vitalij Mik --- src/Subscriber/SystemConfigSubscriber.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Subscriber/SystemConfigSubscriber.php b/src/Subscriber/SystemConfigSubscriber.php index 49352533e..00fb3597e 100644 --- a/src/Subscriber/SystemConfigSubscriber.php +++ b/src/Subscriber/SystemConfigSubscriber.php @@ -53,6 +53,10 @@ public static function getSubscribedEvents() public function onSystemConfigWritten(EntityWrittenEvent $event): void { foreach ($event->getPayloads() as $payload) { + if (! isset($payload['configurationKey'])) { + continue; + } + $this->checkSystemConfigChange( (string)$payload['configurationKey'], $payload['configurationValue'],