Return payment method if it exist

This commit is contained in:
Emili Castells Guasch 2024-07-16 16:00:11 +02:00
parent e70891d359
commit 895cd5c4c1
3 changed files with 28 additions and 10 deletions

View file

@ -944,7 +944,8 @@ return array(
$container->get( 'wc-subscriptions.helper' ),
$container->get( 'api.factory.paypal-checkout-url' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'session.handler' )
);
},
);

View file

@ -13,6 +13,7 @@ use Exception;
use WC_Order;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\WcGateway\Exception\GatewayGenericException;
use WooCommerce\PayPalCommerce\WcGateway\Exception\PayPalOrderMissingException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\Messages;
@ -65,6 +66,13 @@ class GooglePayGateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The Session Handler.
*
* @var SessionHandler
*/
protected $session_handler;
/**
* GooglePayGateway constructor.
*
@ -73,13 +81,15 @@ class GooglePayGateway extends WC_Payment_Gateway {
* @param callable(string):string $paypal_checkout_url_factory The function return the PayPal checkout URL for the given order ID.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param SessionHandler $session_handler The Session Handler.
*/
public function __construct(
OrderProcessor $order_processor,
SubscriptionHelper $subscription_helper,
callable $paypal_checkout_url_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
SessionHandler $session_handler
) {
$this->id = self::ID;
@ -96,6 +106,7 @@ class GooglePayGateway extends WC_Payment_Gateway {
$this->paypal_checkout_url_factory = $paypal_checkout_url_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->session_handler = $session_handler;
}
/**

View file

@ -106,6 +106,12 @@ class DisableGateways {
return $methods;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$payment_method = wc_clean( wp_unslash( $_POST['payment_method'] ?? '' ) );
if ( $payment_method && is_string( $payment_method ) ) {
return array( $payment_method => $methods[ $payment_method ] );
}
return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] );
}