Add some validations to GooglePay scripts

This commit is contained in:
Pedro Silva 2023-10-19 15:12:31 +01:00
parent 5d406ea612
commit 567a7a2065
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
3 changed files with 11 additions and 2 deletions

View file

@ -422,7 +422,7 @@ class ApplePayButton implements ButtonInterface {
}
$applepay_request_data_object->order_data( $context );
$this->update_posted_data( $applepay_request_data_object );
if ( $context == 'product' ) {
if ( $context === 'product' ) {
$cart_item_key = $this->prepare_cart( $applepay_request_data_object );
$cart = WC()->cart;
$address = $applepay_request_data_object->shipping_address();

View file

@ -16,7 +16,9 @@ import GooglepayManager from "./GooglepayManager";
};
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
manager.reinit();
if (manager) {
manager.reinit();
}
});
document.addEventListener(

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Googlepay;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
use WooCommerce\PayPalCommerce\Googlepay\Helper\AvailabilityNotice;
@ -86,6 +87,12 @@ class GooglepayModule implements ModuleInterface {
add_action(
'wp_enqueue_scripts',
static function () use ( $c, $button ) {
$smart_button = $c->get( 'button.smart-button' );
assert( $smart_button instanceof SmartButtonInterface );
$page_has_block = has_block( 'woocommerce/checkout' ) || has_block( 'woocommerce/cart' );
if ( ! $smart_button->should_load_ppcp_script() && ! $page_has_block ) {
return;
}
$button->enqueue();
}
);