mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Use gateway supports to check if refunds are allowed
This commit is contained in:
parent
19fea3c81e
commit
cfe61421f3
4 changed files with 15 additions and 53 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,7 +85,6 @@ class RefundProcessor {
|
|||
OrderEndpoint $order_endpoint,
|
||||
PaymentsEndpoint $payments_endpoint,
|
||||
RefundFeesUpdater $refund_fees_updater,
|
||||
array $allowed_refund_payment_methods,
|
||||
string $prefix,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
|
@ -101,7 +92,6 @@ class RefundProcessor {
|
|||
$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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue