From c2fd9b83cc846bbfa6c5621c5da3264054631763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20M=C3=BCller?= Date: Thu, 19 Dec 2024 21:22:44 +0100 Subject: [PATCH] PAYOSWXP-158: Hide PayPal v1 if v2 is active --- .../PaypalPaymentMethodFilter.php | 24 +++++++++++++++++++ .../payment_method_filter.xml | 7 ++++++ .../checkout/offcanvas-cart.html.twig | 2 +- .../page/checkout/address/index.html.twig | 2 +- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Components/PaymentFilter/PaypalPaymentMethodFilter.php diff --git a/src/Components/PaymentFilter/PaypalPaymentMethodFilter.php b/src/Components/PaymentFilter/PaypalPaymentMethodFilter.php new file mode 100644 index 00000000..2338d223 --- /dev/null +++ b/src/Components/PaymentFilter/PaypalPaymentMethodFilter.php @@ -0,0 +1,24 @@ +get(PayonePaypal::UUID); + $paypalV2 = $methodCollection->get(PayonePaypalV2::UUID); + + if ($paypalV1 instanceof PaymentMethodEntity && $paypalV2 instanceof PaymentMethodEntity) { + throw new PaymentMethodNotAllowedException('PayPal: PayPal v1 is not allowed if v2 is active.'); + } + } +} diff --git a/src/DependencyInjection/payment_method_filter.xml b/src/DependencyInjection/payment_method_filter.xml index 341b0eef..43214f46 100644 --- a/src/DependencyInjection/payment_method_filter.xml +++ b/src/DependencyInjection/payment_method_filter.xml @@ -179,6 +179,13 @@ + + PayonePayment\PaymentHandler\PayonePaypalPaymentHandler + + + diff --git a/src/Resources/views/storefront/component/checkout/offcanvas-cart.html.twig b/src/Resources/views/storefront/component/checkout/offcanvas-cart.html.twig index c2df875e..06677088 100644 --- a/src/Resources/views/storefront/component/checkout/offcanvas-cart.html.twig +++ b/src/Resources/views/storefront/component/checkout/offcanvas-cart.html.twig @@ -4,7 +4,7 @@ {{ parent() }} {% if not context.customer and page.cart.price.totalPrice > 0 %} - {% if constant('PayonePayment\\PaymentMethod\\PayonePaypalExpress::UUID') in activePayonePaymentMethodIds %} + {% if constant('PayonePayment\\PaymentMethod\\PayonePaypalExpress::UUID') in activePayonePaymentMethodIds and constant('PayonePayment\\PaymentMethod\\PayonePaypalV2Express::UUID') not in activePayonePaymentMethodIds %} {% block utilities_offcanvas_payone_paypal_express_button %}
{% sw_include '@PayonePayment/storefront/component/checkout/paypal-button.html.twig' %} diff --git a/src/Resources/views/storefront/page/checkout/address/index.html.twig b/src/Resources/views/storefront/page/checkout/address/index.html.twig index e864c1d3..d0ced74c 100644 --- a/src/Resources/views/storefront/page/checkout/address/index.html.twig +++ b/src/Resources/views/storefront/page/checkout/address/index.html.twig @@ -4,7 +4,7 @@ {{ parent() }} {% if not context.customer and page.cart.price.totalPrice > 0 %} - {% if constant('PayonePayment\\PaymentMethod\\PayonePaypalExpress::UUID') in activePayonePaymentMethodIds %} + {% if constant('PayonePayment\\PaymentMethod\\PayonePaypalExpress::UUID') in activePayonePaymentMethodIds and constant('PayonePayment\\PaymentMethod\\PayonePaypalV2Express::UUID') not in activePayonePaymentMethodIds %} {% block page_checkout_address_payone_paypal_express_button %}