From 597228ce1246c562fd54e98f0ab9c82468e9f2c6 Mon Sep 17 00:00:00 2001 From: Julien Hoarau Date: Wed, 20 May 2026 17:48:21 +0200 Subject: [PATCH 1/3] PRE-3224 feat: Add Wero payment method --- config/services.yaml | 20 ++++++++ config/services/client.xml | 9 ++++ config/services/gateway.xml | 8 ++++ config/twig_hooks/admin.yaml | 6 +++ config/twig_hooks/shop.yaml | 3 ++ public/assets/wero/logo.svg | 41 ++++++++++++++++ .../CapturePaymentRequestCommandProvider.php | 4 ++ .../NotifyPaymentRequestCommandProvider.php | 4 ++ .../StatusPaymentRequestCommandProvider.php | 4 ++ src/Creator/PayPlugPaymentDataCreator.php | 2 + .../Type/WeroGatewayConfigurationType.php | 25 ++++++++++ src/Gateway/WeroGatewayFactory.php | 14 ++++++ .../RefundPaymentGeneratedHandler.php | 2 + .../Provider/CaptureHttpResponseProvider.php | 4 ++ ...dRefundPaymentMethodsProviderDecorator.php | 15 ++++++ .../WeroPaymentMethodsResolverDecorator.php | 48 +++++++++++++++++++ src/Validator/PaymentMethodValidator.php | 9 ++++ templates/shop/integrated/index.html.twig | 2 +- templates/shop/select_payment/_wero.html.twig | 7 +++ translations/messages.en.yml | 1 + translations/messages.fr.yml | 1 + translations/messages.it.yml | 1 + translations/validators.en.yml | 8 ++++ translations/validators.fr.yml | 8 ++++ translations/validators.it.yml | 8 ++++ 25 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 public/assets/wero/logo.svg create mode 100644 src/Gateway/Form/Type/WeroGatewayConfigurationType.php create mode 100644 src/Gateway/WeroGatewayFactory.php create mode 100644 src/Provider/WeroSupportedRefundPaymentMethodsProviderDecorator.php create mode 100644 src/Resolver/WeroPaymentMethodsResolverDecorator.php create mode 100644 templates/shop/select_payment/_wero.html.twig diff --git a/config/services.yaml b/config/services.yaml index 116676f0..7db6a5fe 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -139,6 +139,26 @@ services: - name: sylius.payment_request.provider.http_response gateway_factory: !php/const PayPlug\SyliusPayPlugPlugin\Gateway\ScalapayGatewayFactory::FACTORY_NAME + ## Wero Payplug Gateway ## + payplug_sylius_payplug_plugin.command_provider.payplug_wero: + class: Sylius\Bundle\PaymentBundle\CommandProvider\ActionsCommandProvider + arguments: + - !tagged_locator + tag: payplug_sylius_payplug_plugin.command_provider.payplug_wero + index_by: 'action' + tags: + - name: sylius.payment_request.command_provider + gateway_factory: !php/const PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory::FACTORY_NAME + payplug_sylius_payplug_plugin.provider.order_pay.http_response.payplug_wero: + class: Sylius\Bundle\PaymentBundle\Provider\ActionsHttpResponseProvider + arguments: + - !tagged_locator + tag: payplug_sylius_payplug_plugin.http_response_provider.payplug_wero + index_by: action + tags: + - name: sylius.payment_request.provider.http_response + gateway_factory: !php/const PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory::FACTORY_NAME + ## Apple Pay Payplug Gateway ## payplug_sylius_payplug_plugin.command_provider.payplug_apple_pay: diff --git a/config/services/client.xml b/config/services/client.xml index 22917bdf..3f2d3391 100644 --- a/config/services/client.xml +++ b/config/services/client.xml @@ -62,5 +62,14 @@ method="create"/> payplug_scalapay + + + + payplug_wero + diff --git a/config/services/gateway.xml b/config/services/gateway.xml index dd174517..475c0a26 100644 --- a/config/services/gateway.xml +++ b/config/services/gateway.xml @@ -55,5 +55,13 @@ + + + + PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory + + diff --git a/config/twig_hooks/admin.yaml b/config/twig_hooks/admin.yaml index ba1e2403..ebd1c960 100644 --- a/config/twig_hooks/admin.yaml +++ b/config/twig_hooks/admin.yaml @@ -33,6 +33,9 @@ sylius_twig_hooks: 'sylius_admin.payment_method.create.content.form.sections.gateway_configuration.payplug_scalapay': &scalapayGateway live_checkbox: *liveCheckbox + 'sylius_admin.payment_method.create.content.form.sections.gateway_configuration.payplug_wero': &weroGateway + live_checkbox: *liveCheckbox + 'sylius_admin.payment_method.update.content.form.sections.gateway_configuration.payplug': <<: *payplugGateway renew_oauth: &renewOAuth @@ -53,3 +56,6 @@ sylius_twig_hooks: 'sylius_admin.payment_method.update.content.form.sections.gateway_configuration.payplug_scalapay': <<: *scalapayGateway renew_oauth: *renewOAuth + 'sylius_admin.payment_method.update.content.form.sections.gateway_configuration.payplug_wero': + <<: *weroGateway + renew_oauth: *renewOAuth diff --git a/config/twig_hooks/shop.yaml b/config/twig_hooks/shop.yaml index 5ffe2826..36252bfd 100644 --- a/config/twig_hooks/shop.yaml +++ b/config/twig_hooks/shop.yaml @@ -47,3 +47,6 @@ sylius_twig_hooks: 'sylius_shop.shared.form.select_payment.payment.choice.details#payplug_scalapay': scalapay: template: '@PayPlugSyliusPayPlugPlugin/shop/select_payment/_scalapay.html.twig' + 'sylius_shop.shared.form.select_payment.payment.choice.details#payplug_wero': + wero: + template: '@PayPlugSyliusPayPlugPlugin/shop/select_payment/_wero.html.twig' diff --git a/public/assets/wero/logo.svg b/public/assets/wero/logo.svg new file mode 100644 index 00000000..a1b9d520 --- /dev/null +++ b/public/assets/wero/logo.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Command/Provider/CapturePaymentRequestCommandProvider.php b/src/Command/Provider/CapturePaymentRequestCommandProvider.php index 8d0be621..bb507e7e 100644 --- a/src/Command/Provider/CapturePaymentRequestCommandProvider.php +++ b/src/Command/Provider/CapturePaymentRequestCommandProvider.php @@ -35,6 +35,10 @@ 'payplug_sylius_payplug_plugin.command_provider.payplug_scalapay', ['action' => PaymentRequestInterface::ACTION_CAPTURE], )] +#[AutoconfigureTag( + 'payplug_sylius_payplug_plugin.command_provider.payplug_wero', + ['action' => PaymentRequestInterface::ACTION_CAPTURE], +)] final class CapturePaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface { public function supports(PaymentRequestInterface $paymentRequest): bool diff --git a/src/Command/Provider/NotifyPaymentRequestCommandProvider.php b/src/Command/Provider/NotifyPaymentRequestCommandProvider.php index 55f16fb8..4ef91b6a 100644 --- a/src/Command/Provider/NotifyPaymentRequestCommandProvider.php +++ b/src/Command/Provider/NotifyPaymentRequestCommandProvider.php @@ -33,6 +33,10 @@ 'payplug_sylius_payplug_plugin.command_provider.payplug_scalapay', ['action' => PaymentRequestInterface::ACTION_NOTIFY], )] +#[AutoconfigureTag( + 'payplug_sylius_payplug_plugin.command_provider.payplug_wero', + ['action' => PaymentRequestInterface::ACTION_NOTIFY], +)] final class NotifyPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface { public function supports(PaymentRequestInterface $paymentRequest): bool diff --git a/src/Command/Provider/StatusPaymentRequestCommandProvider.php b/src/Command/Provider/StatusPaymentRequestCommandProvider.php index a0475641..37676e9b 100644 --- a/src/Command/Provider/StatusPaymentRequestCommandProvider.php +++ b/src/Command/Provider/StatusPaymentRequestCommandProvider.php @@ -34,6 +34,10 @@ 'payplug_sylius_payplug_plugin.command_provider.payplug_scalapay', ['action' => PaymentRequestInterface::ACTION_STATUS], )] +#[AutoconfigureTag( + 'payplug_sylius_payplug_plugin.command_provider.payplug_wero', + ['action' => PaymentRequestInterface::ACTION_STATUS], +)] final class StatusPaymentRequestCommandProvider implements PaymentRequestCommandProviderInterface { public function __construct(private RequestStack $requestStack) diff --git a/src/Creator/PayPlugPaymentDataCreator.php b/src/Creator/PayPlugPaymentDataCreator.php index 89d882c0..9b437e68 100644 --- a/src/Creator/PayPlugPaymentDataCreator.php +++ b/src/Creator/PayPlugPaymentDataCreator.php @@ -20,6 +20,7 @@ use PayPlug\SyliusPayPlugPlugin\Gateway\OneyGatewayFactory; use PayPlug\SyliusPayPlugPlugin\Gateway\PayPlugGatewayFactory; use PayPlug\SyliusPayPlugPlugin\Gateway\ScalapayGatewayFactory; +use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory; use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -355,6 +356,7 @@ private function addPaymentMethodFieldToDetails(ArrayObject $details, string $ga ApplePayGatewayFactory::FACTORY_NAME => ApplePayGatewayFactory::PAYMENT_METHOD_APPLE_PAY, AmericanExpressGatewayFactory::FACTORY_NAME => AmericanExpressGatewayFactory::PAYMENT_METHOD_AMERICAN_EXPRESS, ScalapayGatewayFactory::FACTORY_NAME => ScalapayGatewayFactory::PAYMENT_METHOD_SCALAPAY, + WeroGatewayFactory::FACTORY_NAME => WeroGatewayFactory::PAYMENT_METHOD_WERO, ]; // match function is only supported by php 8. so can not use it here. foreach ($paymentMethods as $name => $method) { diff --git a/src/Gateway/Form/Type/WeroGatewayConfigurationType.php b/src/Gateway/Form/Type/WeroGatewayConfigurationType.php new file mode 100644 index 00000000..39d1a035 --- /dev/null +++ b/src/Gateway/Form/Type/WeroGatewayConfigurationType.php @@ -0,0 +1,25 @@ + 'payplug_wero', + 'label' => 'payplug_sylius_payplug_plugin.ui.wero_gateway_label', + 'priority' => 90, + ], +)] +final class WeroGatewayConfigurationType extends AbstractGatewayConfigurationType +{ + protected string $gatewayFactoryTitle = WeroGatewayFactory::FACTORY_TITLE; + + protected string $gatewayFactoryName = WeroGatewayFactory::FACTORY_NAME; + + protected string $gatewayBaseCurrencyCode = WeroGatewayFactory::BASE_CURRENCY_CODE; +} diff --git a/src/Gateway/WeroGatewayFactory.php b/src/Gateway/WeroGatewayFactory.php new file mode 100644 index 00000000..aaa3f536 --- /dev/null +++ b/src/Gateway/WeroGatewayFactory.php @@ -0,0 +1,14 @@ + PaymentRequestInterface::ACTION_CAPTURE], )] +#[AutoconfigureTag( + 'payplug_sylius_payplug_plugin.http_response_provider.payplug_wero', + ['action' => PaymentRequestInterface::ACTION_CAPTURE], +)] class CaptureHttpResponseProvider implements HttpResponseProviderInterface { public function supports(RequestConfiguration $requestConfiguration, PaymentRequestInterface $paymentRequest): bool diff --git a/src/Provider/WeroSupportedRefundPaymentMethodsProviderDecorator.php b/src/Provider/WeroSupportedRefundPaymentMethodsProviderDecorator.php new file mode 100644 index 00000000..82870068 --- /dev/null +++ b/src/Provider/WeroSupportedRefundPaymentMethodsProviderDecorator.php @@ -0,0 +1,15 @@ +decorated->getSupportedMethods($subject); + + /** @var OrderInterface $order */ + $order = $subject->getOrder(); + $billingCountryCode = $order->getBillingAddress()?->getCountryCode(); + + return $this->supportedMethodsProvider->provide( + $supportedMethods, + WeroGatewayFactory::FACTORY_NAME, + $subject->getAmount() ?? 0, + $billingCountryCode, + ); + } + + public function supports(BasePaymentInterface $subject): bool + { + return $this->decorated->supports($subject); + } +} diff --git a/src/Validator/PaymentMethodValidator.php b/src/Validator/PaymentMethodValidator.php index 34b826e2..bcc918a6 100644 --- a/src/Validator/PaymentMethodValidator.php +++ b/src/Validator/PaymentMethodValidator.php @@ -12,6 +12,7 @@ use PayPlug\SyliusPayPlugPlugin\Gateway\OneyGatewayFactory; use PayPlug\SyliusPayPlugPlugin\Gateway\PayPlugGatewayFactory; use PayPlug\SyliusPayPlugPlugin\Gateway\ScalapayGatewayFactory; +use PayPlug\SyliusPayPlugPlugin\Gateway\WeroGatewayFactory; use PayPlug\SyliusPayPlugPlugin\Gateway\Validator\Constraints\IsCanSavePaymentMethod; use PayPlug\SyliusPayPlugPlugin\Gateway\Validator\Constraints\IsOneyEnabled; use PayPlug\SyliusPayPlugPlugin\Gateway\Validator\Constraints\PayplugPermission; @@ -48,6 +49,7 @@ public function process(PaymentMethodInterface $paymentMethod): void AmericanExpressGatewayFactory::FACTORY_NAME => $this->processAmex($paymentMethod), ApplePayGatewayFactory::FACTORY_NAME => $this->processApplePay($paymentMethod), ScalapayGatewayFactory::FACTORY_NAME => $this->processScalapay($paymentMethod), + WeroGatewayFactory::FACTORY_NAME => $this->processWero($paymentMethod), default => throw new \InvalidArgumentException('Unsupported payment method'), }; @@ -113,4 +115,11 @@ private function processScalapay(PaymentMethodInterface $paymentMethod): Constra return $this->validator->validate($paymentMethod, $constraintList, self::VALIDATION_GROUPS); } + + private function processWero(PaymentMethodInterface $paymentMethod): ConstraintViolationListInterface + { + $constraintList = [new IsCanSavePaymentMethod()]; + + return $this->validator->validate($paymentMethod, $constraintList, self::VALIDATION_GROUPS); + } } diff --git a/templates/shop/integrated/index.html.twig b/templates/shop/integrated/index.html.twig index 61a4b1d2..fcc71d2d 100644 --- a/templates/shop/integrated/index.html.twig +++ b/templates/shop/integrated/index.html.twig @@ -3,7 +3,7 @@ {% set initRouteParam = initRouteParam|merge({'orderToken': order.tokenValue}) %} {% endif %} - + +