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( 'wc-subscriptions.helper' ),
$container->get( 'api.factory.paypal-checkout-url' ), $container->get( 'api.factory.paypal-checkout-url' ),
$container->get( 'wcgateway.processor.refunds' ), $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_Order;
use WC_Payment_Gateway; use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException; use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\WcGateway\Exception\GatewayGenericException; use WooCommerce\PayPalCommerce\WcGateway\Exception\GatewayGenericException;
use WooCommerce\PayPalCommerce\WcGateway\Exception\PayPalOrderMissingException; use WooCommerce\PayPalCommerce\WcGateway\Exception\PayPalOrderMissingException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\Messages; use WooCommerce\PayPalCommerce\WcGateway\Gateway\Messages;
@ -65,21 +66,30 @@ class GooglePayGateway extends WC_Payment_Gateway {
*/ */
protected $transaction_url_provider; protected $transaction_url_provider;
/**
* The Session Handler.
*
* @var SessionHandler
*/
protected $session_handler;
/** /**
* GooglePayGateway constructor. * GooglePayGateway constructor.
* *
* @param OrderProcessor $order_processor The Order Processor. * @param OrderProcessor $order_processor The Order Processor.
* @param SubscriptionHelper $subscription_helper The subscription helper. * @param SubscriptionHelper $subscription_helper The subscription helper.
* @param callable(string):string $paypal_checkout_url_factory The function return the PayPal checkout URL for the given order ID. * @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 RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order. * @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param SessionHandler $session_handler The Session Handler.
*/ */
public function __construct( public function __construct(
OrderProcessor $order_processor, OrderProcessor $order_processor,
SubscriptionHelper $subscription_helper, SubscriptionHelper $subscription_helper,
callable $paypal_checkout_url_factory, callable $paypal_checkout_url_factory,
RefundProcessor $refund_processor, RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider TransactionUrlProvider $transaction_url_provider,
SessionHandler $session_handler
) { ) {
$this->id = self::ID; $this->id = self::ID;
@ -91,11 +101,12 @@ class GooglePayGateway extends WC_Payment_Gateway {
$this->init_form_fields(); $this->init_form_fields();
$this->init_settings(); $this->init_settings();
$this->order_processor = $order_processor; $this->order_processor = $order_processor;
$this->subscription_helper = $subscription_helper; $this->subscription_helper = $subscription_helper;
$this->paypal_checkout_url_factory = $paypal_checkout_url_factory; $this->paypal_checkout_url_factory = $paypal_checkout_url_factory;
$this->refund_processor = $refund_processor; $this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider; $this->transaction_url_provider = $transaction_url_provider;
$this->session_handler = $session_handler;
} }
/** /**

View file

@ -106,6 +106,12 @@ class DisableGateways {
return $methods; 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 ] ); return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] );
} }