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

Google Pay: Prevent field validation from being triggered on checkout page load (3493)
This commit is contained in:
Emili Castells 2024-07-30 17:06:44 +02:00 committed by GitHub
commit 9fbeaf56be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

View file

@ -4,7 +4,7 @@ import CheckoutActionHandler from '../../../../ppcp-button/resources/js/modules/
import FormValidator from '../../../../ppcp-button/resources/js/modules/Helper/FormValidator';
class CheckoutHandler extends BaseHandler {
transactionInfo() {
validateForm() {
return new Promise( async ( resolve, reject ) => {
try {
const spinner = new Spinner();
@ -23,7 +23,7 @@ class CheckoutHandler extends BaseHandler {
: null;
if ( ! formValidator ) {
resolve( super.transactionInfo() );
resolve();
return;
}
@ -42,7 +42,7 @@ class CheckoutHandler extends BaseHandler {
reject();
} else {
resolve( super.transactionInfo() );
resolve();
}
} );
} catch ( error ) {

View file

@ -292,17 +292,24 @@ class GooglepayButton {
onButtonClick() {
this.log( 'onButtonClick', this.context );
const paymentDataRequest = this.paymentDataRequest();
this.contextHandler.validateForm().then(
() => {
window.ppcpFundingSource = 'googlepay';
this.log(
'onButtonClick: paymentDataRequest',
paymentDataRequest,
this.context
const paymentDataRequest = this.paymentDataRequest();
this.log(
'onButtonClick: paymentDataRequest',
paymentDataRequest,
this.context
);
this.paymentsClient.loadPaymentData( paymentDataRequest );
},
() => {
console.error( '[GooglePayButton] Form validation failed.' );
}
);
window.ppcpFundingSource = 'googlepay'; // Do this on another place like on create order endpoint handler.
this.paymentsClient.loadPaymentData( paymentDataRequest );
}
paymentDataRequest() {