Show button in PayPal gateway if Google Pay gateway is disabled

This commit is contained in:
Emili Castells Guasch 2024-07-17 16:39:53 +02:00
parent 39ffbaa6e7
commit e547d7e097
3 changed files with 23 additions and 9 deletions

View file

@ -63,8 +63,9 @@ class GooglepayButton {
.then( ( response ) => { .then( ( response ) => {
if ( response.result ) { if ( response.result ) {
if ( if (
this.context === 'checkout' || ( this.context === 'checkout' ||
this.context === 'pay-now' this.context === 'pay-now' ) &&
this.buttonConfig.is_wc_gateway_enabled === '1'
) { ) {
const wrapper = document.getElementById( const wrapper = document.getElementById(
'ppc-button-ppcp-googlepay' 'ppc-button-ppcp-googlepay'

View file

@ -15,6 +15,7 @@ use WC_Countries;
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface; use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait; use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint; use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
use WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Session\SessionHandler; use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
@ -424,19 +425,23 @@ class Button implements ButtonInterface {
$is_enabled = $this->settings->has( 'googlepay_button_enabled' ) && $this->settings->get( 'googlepay_button_enabled' ); $is_enabled = $this->settings->has( 'googlepay_button_enabled' ) && $this->settings->get( 'googlepay_button_enabled' );
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$is_wc_gateway_enabled = isset( $available_gateways[ GooglePayGateway::ID ] );
return array( return array(
'environment' => $this->environment->current_environment_is( Environment::SANDBOX ) ? 'TEST' : 'PRODUCTION', 'environment' => $this->environment->current_environment_is( Environment::SANDBOX ) ? 'TEST' : 'PRODUCTION',
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, 'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
'is_enabled' => $is_enabled, 'is_enabled' => $is_enabled,
'sdk_url' => $this->sdk_url, 'is_wc_gateway_enabled' => $is_wc_gateway_enabled,
'button' => array( 'sdk_url' => $this->sdk_url,
'button' => array(
'wrapper' => '#ppc-button-googlepay-container', 'wrapper' => '#ppc-button-googlepay-container',
'style' => $this->button_styles_for_context( 'cart' ), // For now use cart. Pass the context if necessary. 'style' => $this->button_styles_for_context( 'cart' ), // For now use cart. Pass the context if necessary.
'mini_cart_wrapper' => '#ppc-button-googlepay-container-minicart', 'mini_cart_wrapper' => '#ppc-button-googlepay-container-minicart',
'mini_cart_style' => $this->button_styles_for_context( 'mini-cart' ), 'mini_cart_style' => $this->button_styles_for_context( 'mini-cart' ),
), ),
'shipping' => $shipping, 'shipping' => $shipping,
'ajax' => array( 'ajax' => array(
'update_payment_data' => array( 'update_payment_data' => array(
'endpoint' => \WC_AJAX::get_endpoint( UpdatePaymentDataEndpoint::ENDPOINT ), 'endpoint' => \WC_AJAX::get_endpoint( UpdatePaymentDataEndpoint::ENDPOINT ),
'nonce' => wp_create_nonce( UpdatePaymentDataEndpoint::nonce() ), 'nonce' => wp_create_nonce( UpdatePaymentDataEndpoint::nonce() ),

View file

@ -96,6 +96,14 @@ class GooglePayGateway extends WC_Payment_Gateway {
$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; $this->session_handler = $session_handler;
add_action(
'woocommerce_update_options_payment_gateways_' . $this->id,
array(
$this,
'process_admin_options',
)
);
} }
/** /**