diff --git a/src/Components/MollieLimits/Service/MollieLimitsRemover.php b/src/Components/MollieAvailability/Service/MolliePaymentMethodAvailabilityRemover.php similarity index 87% rename from src/Components/MollieLimits/Service/MollieLimitsRemover.php rename to src/Components/MollieAvailability/Service/MolliePaymentMethodAvailabilityRemover.php index 622dcc4e2..d7b92de59 100644 --- a/src/Components/MollieLimits/Service/MollieLimitsRemover.php +++ b/src/Components/MollieAvailability/Service/MolliePaymentMethodAvailabilityRemover.php @@ -1,6 +1,6 @@ isAllowedRoute()) { return $originalData; } + $billingAddress = null; + $countryIsoCode = null; if ($this->isCartRoute()) { try { @@ -77,8 +79,13 @@ public function removePaymentMethods(PaymentMethodRouteResponse $originalData, S } $price = $cart->getPrice()->getTotalPrice(); + $customer = $context->getCustomer(); + if ($customer !== null) { + $billingAddress = $customer->getDefaultBillingAddress(); + } } + if ($this->isOrderRoute()) { try { $order = $this->getOrder($context->getContext()); @@ -90,15 +97,27 @@ public function removePaymentMethods(PaymentMethodRouteResponse $originalData, S } $price = $order->getAmountTotal(); + + $billingAddress = $order->getBillingAddress(); } if (!isset($price)) { return $originalData; } + if ($billingAddress !== null) { + $billingCountry = $billingAddress->getCountry(); + if ($billingCountry !== null) { + $countryIsoCode = $billingCountry->getIso(); + } + } + + + $availableMolliePayments = $this->paymentMethodsProvider->getActivePaymentMethodsForAmount( $price, $context->getCurrency()->getIsoCode(), + (string) $countryIsoCode, [ $context->getSalesChannel()->getId(), ] diff --git a/src/Handler/Method/BlikPayment.php b/src/Handler/Method/BlikPayment.php new file mode 100644 index 000000000..f4914474d --- /dev/null +++ b/src/Handler/Method/BlikPayment.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/app/administration/src/snippet/de-DE.json b/src/Resources/app/administration/src/snippet/de-DE.json index 76b59f784..b3674920d 100644 --- a/src/Resources/app/administration/src/snippet/de-DE.json +++ b/src/Resources/app/administration/src/snippet/de-DE.json @@ -76,7 +76,7 @@ "failed": "Die Zahlungsarten konnten nicht aktualisiert werden." }, "mollieLimits": { - "link": "Öffne Mollie Zahlungs Limits" + "link": "Zeige Mollie-Verfügbarkeitregeln für Zahlungsmethoden" } }, "rounding": { diff --git a/src/Resources/app/administration/src/snippet/en-GB.json b/src/Resources/app/administration/src/snippet/en-GB.json index c8901c310..6652b6198 100644 --- a/src/Resources/app/administration/src/snippet/en-GB.json +++ b/src/Resources/app/administration/src/snippet/en-GB.json @@ -76,7 +76,7 @@ "failed": "The payment methods couldn't be updated." }, "mollieLimits": { - "link": "Open Mollie Payment Limits" + "link": "Show mollie availability rules for payment methods" } }, "rounding": { diff --git a/src/Resources/app/administration/src/snippet/nl-NL.json b/src/Resources/app/administration/src/snippet/nl-NL.json index b3f8b10c0..a37ce42c5 100644 --- a/src/Resources/app/administration/src/snippet/nl-NL.json +++ b/src/Resources/app/administration/src/snippet/nl-NL.json @@ -76,7 +76,7 @@ "failed": "De betaalmethoden konden niet worden geupdated." }, "mollieLimits": { - "link": "Open betalingslimieten van Mollie" + "link": "Toon Mollie-beschikbaarheidsregels voor betaalmethoden" } }, "rounding": { diff --git a/src/Resources/config/config.xml b/src/Resources/config/config.xml index d06a1063e..2184638f7 100644 --- a/src/Resources/config/config.xml +++ b/src/Resources/config/config.xml @@ -165,12 +165,12 @@ useMolliePaymentMethodLimits false - - - - Automatically hides payment methods in the checkout based on the limits of Mollie. For instance, if you can only accept credit card payments up to 500 euros, the checkout for a cart of 600 euros will not display credit card as a payment method. - Blendet automatisch Zahlungsart im Checkout basierend auf den Limits von Mollie aus. Wenn Sie beispielsweise nur Kreditkartenzahlungen bis zu 500 Euro akzeptieren können, wird an der Kasse für einen Warenkorb von 600 Euro keine Kreditkarte als Zahlungsarte angezeigt. - Verbergt automatisch betaalmethoden in de checkout op basis van Mollie's limieten. Als je bijvoorbeeld alleen creditcardbetalingen tot 500 euro kan accepteren, wordt bij een winkelwagen van 600 euro geen creditcard weergegeven als betaalmethode bij het afrekenen. + + + + Automatically hides payment methods in the checkout based on the availability rules for payment methods. Only active payment methods from your mollie dashboard will be shown. If the payment method has a cart limit, currency restriction or billing address restriction, it will be hidden during checkout. + Blendet automatisch Zahlungsart im Checkout basierend auf Verfügbarkeitsregeln von Mollie. Es werden nur die aktiven Zahlungsarten aus dem Mollie Dashboard angezeigt. Wenn die Zahlungsart eine Einschränkung auf den Warenkorbwert, Währung oder Rechnungsadresse hat, wird diese auch ausgeblendet. + Automatische betalingsmethode wordt verborgen tijdens het afrekenen op basis van beschikbaarheidsregels van Mollie. Alleen actieve betalingsmethoden uit het Mollie-dashboard worden weergegeven. Als de betalingsmethode beperkingen heeft op de winkelwagenwaarde, valuta of factuuradres, wordt deze ook verborgen. formatOrderNumber diff --git a/src/Resources/config/services/handlers.xml b/src/Resources/config/services/handlers.xml index 0cb06f79d..5ffa6d2d6 100644 --- a/src/Resources/config/services/handlers.xml +++ b/src/Resources/config/services/handlers.xml @@ -183,5 +183,13 @@ + + + + + + + + diff --git a/src/Resources/config/services/payment.xml b/src/Resources/config/services/payment.xml index bbdd973fe..7233d5e38 100644 --- a/src/Resources/config/services/payment.xml +++ b/src/Resources/config/services/payment.xml @@ -17,7 +17,8 @@ - + + diff --git a/src/Service/Payment/Provider/ActivePaymentMethodsProvider.php b/src/Service/Payment/Provider/ActivePaymentMethodsProvider.php index aacbf2358..bb49496b8 100644 --- a/src/Service/Payment/Provider/ActivePaymentMethodsProvider.php +++ b/src/Service/Payment/Provider/ActivePaymentMethodsProvider.php @@ -48,10 +48,11 @@ public function __construct(MollieApiFactory $mollieApiFactory, MollieOrderPrice * * @param float $price * @param string $currency + * @param string $billingCountryCode * @param array $salesChannelIDs * @return Method[] */ - public function getActivePaymentMethodsForAmount(float $price, string $currency, array $salesChannelIDs): array + public function getActivePaymentMethodsForAmount(float $price, string $currency, string $billingCountryCode, array $salesChannelIDs): array { if ($price < 0.01) { return []; @@ -61,9 +62,13 @@ public function getActivePaymentMethodsForAmount(float $price, string $currency, 'amount' => [ 'value' => $this->priceFormatter->formatValue($price), 'currency' => strtoupper($currency), - ] + ], ]; + if (mb_strlen($billingCountryCode) > 0) { + $params['billingCountry'] = $billingCountryCode; + } + return $this->getActivePaymentMethods($params, $salesChannelIDs); } diff --git a/src/Service/Payment/Provider/ActivePaymentMethodsProviderInterface.php b/src/Service/Payment/Provider/ActivePaymentMethodsProviderInterface.php index b22230074..90d6f831c 100644 --- a/src/Service/Payment/Provider/ActivePaymentMethodsProviderInterface.php +++ b/src/Service/Payment/Provider/ActivePaymentMethodsProviderInterface.php @@ -9,10 +9,11 @@ interface ActivePaymentMethodsProviderInterface { /** - * @param float $price - * @param string $currency + * @param float $price + * @param string $currency + * @param string $billingCountryCode * @param array $salesChannelIDs * @return array */ - public function getActivePaymentMethodsForAmount(float $price, string $currency, array $salesChannelIDs): array; + public function getActivePaymentMethodsForAmount(float $price, string $currency, string $billingCountryCode, array $salesChannelIDs): array; } diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index 8a746a0f0..5d9c1e85d 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -8,6 +8,7 @@ use Kiener\MolliePayments\Handler\Method\BankTransferPayment; use Kiener\MolliePayments\Handler\Method\BelfiusPayment; use Kiener\MolliePayments\Handler\Method\BilliePayment; +use Kiener\MolliePayments\Handler\Method\BlikPayment; use Kiener\MolliePayments\Handler\Method\CreditCardPayment; use Kiener\MolliePayments\Handler\Method\EpsPayment; use Kiener\MolliePayments\Handler\Method\GiftCardPayment; @@ -417,6 +418,7 @@ public function getPaymentHandlers(): array In3Payment::class, PosPayment::class, TwintPayment::class, + BlikPayment::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/payment-methods/blik.cy.js b/tests/Cypress/cypress/e2e/storefront/payment-methods/blik.cy.js new file mode 100644 index 000000000..1d28a1a0b --- /dev/null +++ b/tests/Cypress/cypress/e2e/storefront/payment-methods/blik.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('Blik payment method', () => { + + context(devices.getDescription(device), () => { + + before(function () { + devices.setDevice(device); + }) + + beforeEach(() => { + session.resetBrowserSession(); + devices.setDevice(device); + }); + + it('Blik is existing in checkout', () => { + + scenarioDummyBasket.execute(); + + paymentAction.switchPaymentMethod('Blik'); + + // payment would only work using currency CHF which cannot be done at the moment + }) + + }) + +}) + diff --git a/tests/PHPUnit/Service/MollieApi/Builder/Payments/BlikOrderBuilderTest.php b/tests/PHPUnit/Service/MollieApi/Builder/Payments/BlikOrderBuilderTest.php new file mode 100644 index 000000000..6b03838bd --- /dev/null +++ b/tests/PHPUnit/Service/MollieApi/Builder/Payments/BlikOrderBuilderTest.php @@ -0,0 +1,68 @@ +router->method('generate')->willReturn($redirectWebhookUrl); + + + $this->paymentHandler = new BlikPayment( + $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/MollieApi/Builder/Payments/TwintOrderBuilderTest.php b/tests/PHPUnit/Service/MollieApi/Builder/Payments/TwintOrderBuilderTest.php index ed85d1c6a..96d713682 100644 --- a/tests/PHPUnit/Service/MollieApi/Builder/Payments/TwintOrderBuilderTest.php +++ b/tests/PHPUnit/Service/MollieApi/Builder/Payments/TwintOrderBuilderTest.php @@ -21,9 +21,8 @@ public function testOrderBuild(): void { $redirectWebhookUrl = 'https://foo'; $this->router->method('generate')->willReturn($redirectWebhookUrl); - $paymentMethod = TwintPayment::PAYMENT_METHOD_NAME; - $this->paymentHandler = new KlarnaPayLaterPayment( + $this->paymentHandler = new TwintPayment( $this->loggerService, new FakeContainer() ); @@ -42,7 +41,7 @@ public function testOrderBuild(): void $order = $this->getOrderEntity($amountTotal, $taxStatus, $currencyISO, $lineItems, $orderNumber); - $actual = $this->builder->buildOrderPayload($order, $transactionId, $paymentMethod, $this->salesChannelContext, $this->paymentHandler, []); + $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)) @@ -51,7 +50,7 @@ public function testOrderBuild(): void $expected = [ 'amount' => (new MollieOrderPriceBuilder())->build($amountTotal, $currencyISO), 'locale' => $this->localeCode, - 'method' => $paymentMethod, + 'method' => $this->paymentHandler::PAYMENT_METHOD_NAME, 'orderNumber' => $orderNumber, 'payment' => ['webhookUrl' => $redirectWebhookUrl], 'redirectUrl' => $redirectWebhookUrl, diff --git a/tests/PHPUnit/Service/PaymentMethodServiceTest.php b/tests/PHPUnit/Service/PaymentMethodServiceTest.php index 4dbd0061c..8c01d69a5 100644 --- a/tests/PHPUnit/Service/PaymentMethodServiceTest.php +++ b/tests/PHPUnit/Service/PaymentMethodServiceTest.php @@ -7,6 +7,7 @@ use Kiener\MolliePayments\Handler\Method\BankTransferPayment; use Kiener\MolliePayments\Handler\Method\BelfiusPayment; use Kiener\MolliePayments\Handler\Method\BilliePayment; +use Kiener\MolliePayments\Handler\Method\BlikPayment; use Kiener\MolliePayments\Handler\Method\CreditCardPayment; use Kiener\MolliePayments\Handler\Method\EpsPayment; use Kiener\MolliePayments\Handler\Method\GiftCardPayment; @@ -127,6 +128,7 @@ public function testSupportedMethods(): void In3Payment::class, PosPayment::class, TwintPayment::class, + BlikPayment::class, ]; $handlers = $this->paymentMethodService->getPaymentHandlers();