Merge pull request #2495 from woocommerce/PCP-3493-validation-on-classic-checkout-page-automatically-triggered-when-google-pay-is-enabled-rc2

Fix Google Pay button on non-checkout pages (#3493)
This commit is contained in:
Emili Castells 2024-08-07 15:16:31 +02:00 committed by GitHub
commit f96293542a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -292,24 +292,33 @@ class GooglepayButton {
onButtonClick() {
this.log( 'onButtonClick', this.context );
this.contextHandler.validateForm().then(
() => {
window.ppcpFundingSource = 'googlepay';
const initiatePaymentRequest = () => {
window.ppcpFundingSource = 'googlepay';
const paymentDataRequest = this.paymentDataRequest();
const paymentDataRequest = this.paymentDataRequest();
this.log(
'onButtonClick: paymentDataRequest',
paymentDataRequest,
this.context
);
this.log(
'onButtonClick: paymentDataRequest',
paymentDataRequest,
this.context
);
this.paymentsClient.loadPaymentData( paymentDataRequest );
},
() => {
console.error( '[GooglePayButton] Form validation failed.' );
}
);
this.paymentsClient.loadPaymentData( paymentDataRequest );
};
if ( 'function' === typeof this.contextHandler.validateForm ) {
// During regular checkout, validate the checkout form before initiating the payment.
this.contextHandler
.validateForm()
.then( initiatePaymentRequest, () => {
console.error(
'[GooglePayButton] Form validation failed.'
);
} );
} else {
// This is the flow on product page, cart, and other non-checkout pages.
initiatePaymentRequest();
}
}
paymentDataRequest() {