diff --git a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php index 6db9de464..be1b05da5 100644 --- a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php +++ b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php @@ -185,18 +185,6 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo 2 ); - add_filter( - 'woocommerce_paypal_payments_allowed_refund_payment_methods', - function( array $payment_methods ) use ( $c ): array { - $local_payment_methods = $c->get( 'ppcp-local-apms.payment-methods' ); - foreach ( $local_payment_methods as $payment_method ) { - $payment_methods[] = $payment_method['id']; - } - - return $payment_methods; - } - ); - return true; } diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index c235e0d4b..d9822f9ba 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -520,17 +520,10 @@ return array( $container->get( 'api.endpoint.order' ), $container->get( 'api.endpoint.payments' ), $container->get( 'wcgateway.helper.refund-fees-updater' ), - $container->get( 'wcgateway.allowed_refund_payment_methods' ), $container->get( 'api.prefix' ), $container->get( 'woocommerce.logger.woocommerce' ) ); }, - 'wcgateway.allowed_refund_payment_methods' => static function ( ContainerInterface $container ): array { - return apply_filters( - 'woocommerce_paypal_payments_allowed_refund_payment_methods', - array( PayPalGateway::ID, CreditCardGateway::ID, CardButtonGateway::ID, PayUponInvoiceGateway::ID, GooglePayGateway::ID, ApplePayGateway::ID ) - ); - }, 'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor { $order_endpoint = $container->get( 'api.endpoint.order' ); $payments_endpoint = $container->get( 'api.endpoint.payments' ); @@ -1933,8 +1926,7 @@ return array( $container->get( 'wcgateway.url' ), $container->get( 'ppcp.asset-version' ), $container->get( 'api.endpoint.order' ), - $container->get( 'wcgateway.processor.refunds' ), - $container->get( 'wcgateway.allowed_refund_payment_methods' ) + $container->get( 'wcgateway.processor.refunds' ) ); }, 'wcgateway.void-button.endpoint' => function( ContainerInterface $container ) : VoidOrderEndpoint { diff --git a/modules/ppcp-wc-gateway/src/Assets/VoidButtonAssets.php b/modules/ppcp-wc-gateway/src/Assets/VoidButtonAssets.php index 9a2435449..285ac7fb2 100644 --- a/modules/ppcp-wc-gateway/src/Assets/VoidButtonAssets.php +++ b/modules/ppcp-wc-gateway/src/Assets/VoidButtonAssets.php @@ -51,13 +51,6 @@ class VoidButtonAssets { */ private $refund_processor; - /** - * The methods that can be refunded. - * - * @var array - */ - private $allowed_refund_payment_methods; - /** * VoidButtonAssets constructor. * @@ -65,20 +58,17 @@ class VoidButtonAssets { * @param string $version The assets version. * @param OrderEndpoint $order_endpoint The order endpoint. * @param RefundProcessor $refund_processor The Refund Processor. - * @param array $allowed_refund_payment_methods The methods that can be refunded. */ public function __construct( string $module_url, string $version, OrderEndpoint $order_endpoint, - RefundProcessor $refund_processor, - array $allowed_refund_payment_methods + RefundProcessor $refund_processor ) { - $this->module_url = $module_url; - $this->version = $version; - $this->order_endpoint = $order_endpoint; - $this->refund_processor = $refund_processor; - $this->allowed_refund_payment_methods = $allowed_refund_payment_methods; + $this->module_url = $module_url; + $this->version = $version; + $this->order_endpoint = $order_endpoint; + $this->refund_processor = $refund_processor; } /** @@ -103,7 +93,8 @@ class VoidButtonAssets { return false; } - if ( ! in_array( $theorder->get_payment_method(), $this->allowed_refund_payment_methods, true ) ) { + $payment_gateways = WC()->payment_gateways()->payment_gateways(); + if ( ! isset( $payment_gateways[ $theorder->get_payment_method() ] ) || ! $payment_gateways[ $theorder->get_payment_method() ]->supports( 'refunds' ) ) { return false; } diff --git a/modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php b/modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php index 523fcf00e..c890e7542 100644 --- a/modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php +++ b/modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php @@ -72,20 +72,12 @@ class RefundProcessor { */ private $refund_fees_updater; - /** - * The methods that can be refunded. - * - * @var array - */ - private $allowed_refund_payment_methods; - /** * RefundProcessor constructor. * * @param OrderEndpoint $order_endpoint The order endpoint. * @param PaymentsEndpoint $payments_endpoint The payments endpoint. * @param RefundFeesUpdater $refund_fees_updater The refund fees updater. - * @param array $allowed_refund_payment_methods The methods that can be refunded. * @param string $prefix The prefix. * @param LoggerInterface $logger The logger. */ @@ -93,17 +85,15 @@ class RefundProcessor { OrderEndpoint $order_endpoint, PaymentsEndpoint $payments_endpoint, RefundFeesUpdater $refund_fees_updater, - array $allowed_refund_payment_methods, string $prefix, LoggerInterface $logger ) { - $this->order_endpoint = $order_endpoint; - $this->payments_endpoint = $payments_endpoint; - $this->refund_fees_updater = $refund_fees_updater; - $this->allowed_refund_payment_methods = $allowed_refund_payment_methods; - $this->prefix = $prefix; - $this->logger = $logger; + $this->order_endpoint = $order_endpoint; + $this->payments_endpoint = $payments_endpoint; + $this->refund_fees_updater = $refund_fees_updater; + $this->prefix = $prefix; + $this->logger = $logger; } /** @@ -119,7 +109,8 @@ class RefundProcessor { */ public function process( WC_Order $wc_order, float $amount = null, string $reason = '' ) : bool { try { - if ( ! in_array( $wc_order->get_payment_method(), $this->allowed_refund_payment_methods, true ) ) { + $payment_gateways = WC()->payment_gateways()->payment_gateways(); + if ( ! isset( $payment_gateways[ $wc_order->get_payment_method() ] ) || ! $payment_gateways[ $wc_order->get_payment_method() ]->supports( 'refunds' ) ) { return true; }