From e1778b01aa7fef3fe0ac93809c54b85d5137ee3b Mon Sep 17 00:00:00 2001 From: Guilherme Pressutto Date: Thu, 31 Oct 2024 11:31:02 -0300 Subject: [PATCH] Register Expresss Checkout block only when enabled in the settings (#9646) --- .../fix-express-checkout-block-registering | 4 ++++ client/checkout/blocks/index.js | 20 ++++++++++--------- includes/class-wc-payment-gateway-wcpay.php | 9 +++++++++ includes/class-wc-payments-checkout.php | 1 + 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 changelog/fix-express-checkout-block-registering diff --git a/changelog/fix-express-checkout-block-registering b/changelog/fix-express-checkout-block-registering new file mode 100644 index 00000000000..790b8a27a45 --- /dev/null +++ b/changelog/fix-express-checkout-block-registering @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Register Expresss Checkout block only when enabled in the settings diff --git a/client/checkout/blocks/index.js b/client/checkout/blocks/index.js index 12017a03129..924afccde1f 100644 --- a/client/checkout/blocks/index.js +++ b/client/checkout/blocks/index.js @@ -157,15 +157,17 @@ if ( getUPEConfig( 'isWooPayEnabled' ) ) { } } -if ( getUPEConfig( 'isTokenizedCartPrbEnabled' ) ) { - registerExpressPaymentMethod( - tokenizedCartPaymentRequestPaymentMethod( api ) - ); -} else if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) { - registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) ); - registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) ); -} else { - registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) ); +if ( getUPEConfig( 'isPaymentRequestEnabled' ) ) { + if ( getUPEConfig( 'isTokenizedCartPrbEnabled' ) ) { + registerExpressPaymentMethod( + tokenizedCartPaymentRequestPaymentMethod( api ) + ); + } else if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) { + registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) ); + registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) ); + } else { + registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) ); + } } window.addEventListener( 'load', () => { enqueueFraudScripts( getUPEConfig( 'fraudServices' ) ); diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index d1fe2b1cca6..2a60d9b64e2 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -894,6 +894,15 @@ public function is_saved_cards_enabled() { return 'yes' === $this->get_option( 'saved_cards' ); } + /** + * Checks if the setting to show the payment request buttons is enabled. + * + * @return bool Whether the setting to show the payment request buttons is enabled or not. + */ + public function is_payment_request_enabled() { + return 'yes' === $this->get_option( 'payment_request' ); + } + /** * Check if account is eligible for card present. * diff --git a/includes/class-wc-payments-checkout.php b/includes/class-wc-payments-checkout.php index 79e6e119267..0b1cc59d9cf 100644 --- a/includes/class-wc-payments-checkout.php +++ b/includes/class-wc-payments-checkout.php @@ -193,6 +193,7 @@ public function get_payment_fields_js_config() { 'isPreview' => is_preview(), 'isSavedCardsEnabled' => $this->gateway->is_saved_cards_enabled(), 'isExpressCheckoutElementEnabled' => WC_Payments_Features::is_stripe_ece_enabled(), + 'isPaymentRequestEnabled' => $this->gateway->is_payment_request_enabled(), 'isTokenizedCartPrbEnabled' => WC_Payments_Features::is_tokenized_cart_prb_enabled(), 'isWooPayEnabled' => $this->woopay_util->should_enable_woopay( $this->gateway ) && $this->woopay_util->should_enable_woopay_on_cart_or_checkout(), 'isWoopayExpressCheckoutEnabled' => $this->woopay_util->is_woopay_express_checkout_enabled(),