Skip to content

Commit

Permalink
PAYOSWXP-158: Hide PayPal v1 if v2 is active
Browse files Browse the repository at this point in the history
  • Loading branch information
momocode-de committed Dec 19, 2024
1 parent ca924bf commit c2fd9b8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/Components/PaymentFilter/PaypalPaymentMethodFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace PayonePayment\Components\PaymentFilter;

use PayonePayment\Components\PaymentFilter\Exception\PaymentMethodNotAllowedException;
use PayonePayment\PaymentMethod\PayonePaypal;
use PayonePayment\PaymentMethod\PayonePaypalV2;
use Shopware\Core\Checkout\Payment\PaymentMethodCollection;
use Shopware\Core\Checkout\Payment\PaymentMethodEntity;

class PaypalPaymentMethodFilter extends DefaultPaymentFilterService
{
protected function additionalChecks(PaymentMethodCollection $methodCollection, PaymentFilterContext $filterContext): void
{
$paypalV1 = $methodCollection->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.');
}
}
}
7 changes: 7 additions & 0 deletions src/DependencyInjection/payment_method_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@
<tag name="payone.payment_method.filter"/>
</service>

<service id="payone.payment_filter_method.paypal"
class="PayonePayment\Components\PaymentFilter\PaypalPaymentMethodFilter"
parent="PayonePayment\Components\PaymentFilter\DefaultPaymentFilterService">
<argument key="$paymentHandlerClass">PayonePayment\PaymentHandler\PayonePaypalPaymentHandler</argument>
<tag name="payone.payment_method.filter"/>
</service>

<service id="payone.payment_filter_method.paypal_express"
class="PayonePayment\Components\PaymentFilter\DefaultPaymentFilterService"
parent="PayonePayment\Components\PaymentFilter\DefaultPaymentFilterService">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<div class="text-center mt-3">
{% sw_include '@PayonePayment/storefront/component/checkout/paypal-button.html.twig' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<div class="row">
<div class="col-5 pb-2">
Expand Down

0 comments on commit c2fd9b8

Please sign in to comment.