diff --git a/modules/ppcp-googlepay/services.php b/modules/ppcp-googlepay/services.php index a566630e6..ae86d129b 100644 --- a/modules/ppcp-googlepay/services.php +++ b/modules/ppcp-googlepay/services.php @@ -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' ) ); }, ); diff --git a/modules/ppcp-googlepay/src/GooglePayGateway.php b/modules/ppcp-googlepay/src/GooglePayGateway.php index 89c5f88a5..144d5da9e 100644 --- a/modules/ppcp-googlepay/src/GooglePayGateway.php +++ b/modules/ppcp-googlepay/src/GooglePayGateway.php @@ -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,21 +66,30 @@ class GooglePayGateway extends WC_Payment_Gateway { */ protected $transaction_url_provider; + /** + * The Session Handler. + * + * @var SessionHandler + */ + protected $session_handler; + /** * GooglePayGateway constructor. * - * @param OrderProcessor $order_processor The Order Processor. - * @param SubscriptionHelper $subscription_helper The subscription helper. + * @param OrderProcessor $order_processor The Order Processor. + * @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 RefundProcessor $refund_processor The Refund Processor. - * @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order. + * @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; @@ -91,11 +101,12 @@ class GooglePayGateway extends WC_Payment_Gateway { $this->init_form_fields(); $this->init_settings(); - $this->order_processor = $order_processor; - $this->subscription_helper = $subscription_helper; + $this->order_processor = $order_processor; + $this->subscription_helper = $subscription_helper; $this->paypal_checkout_url_factory = $paypal_checkout_url_factory; - $this->refund_processor = $refund_processor; - $this->transaction_url_provider = $transaction_url_provider; + $this->refund_processor = $refund_processor; + $this->transaction_url_provider = $transaction_url_provider; + $this->session_handler = $session_handler; } /** diff --git a/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php b/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php index de07ecfef..a55fe621c 100644 --- a/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php +++ b/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php @@ -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 ] ); }