From 3dd7db6e5aef5ea5ae63dcf077fd2446ed8381cb Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Tue, 2 Jul 2024 10:27:26 +0200 Subject: [PATCH] NTR: PISHPS-300: add trustly payment (#780) Co-authored-by: Vitalij Mik --- src/Handler/Method/TrustlyPayment.php | 15 +++++ src/Resources/config/services/handlers.xml | 7 ++ src/Service/PaymentMethodService.php | 2 + .../checkout/checkout-success.cy.js | 1 + .../storefront/payment-methods/trustly.cy.js | 43 ++++++++++++ .../Payments/TrustlyOrderBuilderTest.php | 67 +++++++++++++++++++ .../Service/PaymentMethodServiceTest.php | 2 + 7 files changed, 137 insertions(+) create mode 100644 src/Handler/Method/TrustlyPayment.php create mode 100644 tests/Cypress/cypress/e2e/storefront/payment-methods/trustly.cy.js create mode 100644 tests/PHPUnit/Service/MollieApi/Builder/Payments/TrustlyOrderBuilderTest.php diff --git a/src/Handler/Method/TrustlyPayment.php b/src/Handler/Method/TrustlyPayment.php new file mode 100644 index 000000000..8c8be6517 --- /dev/null +++ b/src/Handler/Method/TrustlyPayment.php @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index ddd40e95b..b6b71c8db 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -29,6 +29,7 @@ use Kiener\MolliePayments\Handler\Method\PosPayment; use Kiener\MolliePayments\Handler\Method\Przelewy24Payment; use Kiener\MolliePayments\Handler\Method\SofortPayment; +use Kiener\MolliePayments\Handler\Method\TrustlyPayment; use Kiener\MolliePayments\Handler\Method\TwintPayment; use Kiener\MolliePayments\Handler\Method\VoucherPayment; use Kiener\MolliePayments\MolliePayments; @@ -446,6 +447,7 @@ public function getPaymentHandlers(): array BancomatPayment::class, MyBankPayment::class, AlmaPayment::class, + TrustlyPayment::class, // IngHomePayPayment::class, // not allowed anymore // DirectDebitPayment::class, // only allowed when updating subsriptions, aka => not allowed anymore ]; diff --git a/tests/Cypress/cypress/e2e/storefront/checkout/checkout-success.cy.js b/tests/Cypress/cypress/e2e/storefront/checkout/checkout-success.cy.js index 9281088e7..69262419f 100644 --- a/tests/Cypress/cypress/e2e/storefront/checkout/checkout-success.cy.js +++ b/tests/Cypress/cypress/e2e/storefront/checkout/checkout-success.cy.js @@ -58,6 +58,7 @@ const payments = [ {caseId: 'C4127', key: 'belfius', name: 'Belfius', sanity: false}, {caseId: 'C4121', key: 'giftcard', name: 'Gift cards', sanity: false}, {caseId: 'C4143', key: 'voucher', name: 'Voucher', sanity: false}, + {caseId: 'C3362894', key: 'trustly', name: 'Trustly', sanity: false}, // unfortunately address and product prices need to match, so we cannot do in3 automatically for now // {caseId: '', key: 'in3', name: 'in3'}, ]; diff --git a/tests/Cypress/cypress/e2e/storefront/payment-methods/trustly.cy.js b/tests/Cypress/cypress/e2e/storefront/payment-methods/trustly.cy.js new file mode 100644 index 000000000..7389173da --- /dev/null +++ b/tests/Cypress/cypress/e2e/storefront/payment-methods/trustly.cy.js @@ -0,0 +1,43 @@ +import Devices from "Services/utils/Devices"; +import Session from "Services/utils/Session" +// ------------------------------------------------------ +import PaymentAction from "Actions/storefront/checkout/PaymentAction"; +import DummyBasketScenario from "Scenarios/DummyBasketScenario"; +// ------------------------------------------------------ + + +const devices = new Devices(); +const session = new Session(); + +const paymentAction = new PaymentAction(); +const scenarioDummyBasket = new DummyBasketScenario(1); + +const device = devices.getFirstDevice(); + + +describe('Trustly', () => { + + context(devices.getDescription(device), () => { + + before(function () { + devices.setDevice(device); + }) + + beforeEach(() => { + session.resetBrowserSession(); + devices.setDevice(device); + }); + + it('C3362895: Trustly is existing in checkout', () => { + + scenarioDummyBasket.execute(); + + paymentAction.switchPaymentMethod('Trustly'); + + // payment would only work using currency CHF which cannot be done at the moment + }) + + }) + +}) + diff --git a/tests/PHPUnit/Service/MollieApi/Builder/Payments/TrustlyOrderBuilderTest.php b/tests/PHPUnit/Service/MollieApi/Builder/Payments/TrustlyOrderBuilderTest.php new file mode 100644 index 000000000..a5384acbc --- /dev/null +++ b/tests/PHPUnit/Service/MollieApi/Builder/Payments/TrustlyOrderBuilderTest.php @@ -0,0 +1,67 @@ +router->method('generate')->willReturn($redirectWebhookUrl); + + $this->paymentHandler = new TrustlyPayment( + $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..0d50277a4 100644 --- a/tests/PHPUnit/Service/PaymentMethodServiceTest.php +++ b/tests/PHPUnit/Service/PaymentMethodServiceTest.php @@ -27,6 +27,7 @@ use Kiener\MolliePayments\Handler\Method\PosPayment; use Kiener\MolliePayments\Handler\Method\Przelewy24Payment; use Kiener\MolliePayments\Handler\Method\SofortPayment; +use Kiener\MolliePayments\Handler\Method\TrustlyPayment; use Kiener\MolliePayments\Handler\Method\TwintPayment; use Kiener\MolliePayments\Handler\Method\VoucherPayment; use Kiener\MolliePayments\Repository\Media\MediaRepositoryInterface; @@ -136,6 +137,7 @@ public function testSupportedMethods(): void BancomatPayment::class, MyBankPayment::class, AlmaPayment::class, + TrustlyPayment::class, ]; $handlers = $this->paymentMethodService->getPaymentHandlers();