Handle empty acdc fields

This commit is contained in:
Alex P 2023-05-09 12:01:26 +03:00
parent af5d33dc78
commit 729251495f
No known key found for this signature in database
GPG key ID: 54487A734A204D71
2 changed files with 21 additions and 1 deletions

View file

@ -10,6 +10,7 @@ class CreditCardRenderer {
this.spinner = spinner; this.spinner = spinner;
this.cardValid = false; this.cardValid = false;
this.formValid = false; this.formValid = false;
this.emptyFields = new Set(['number', 'cvv', 'expirationDate']);
this.currentHostedFieldsInstance = null; this.currentHostedFieldsInstance = null;
} }
@ -138,6 +139,12 @@ class CreditCardRenderer {
this.formValid = formValid; this.formValid = formValid;
}); });
hostedFields.on('empty', (event) => {
this.emptyFields.add(event.emittedBy);
});
hostedFields.on('notEmpty', (event) => {
this.emptyFields.delete(event.emittedBy);
});
show(buttonSelector); show(buttonSelector);
@ -249,7 +256,16 @@ class CreditCardRenderer {
}); });
} else { } else {
this.spinner.unblock(); this.spinner.unblock();
const message = ! this.cardValid ? this.defaultConfig.hosted_fields.labels.card_not_supported : this.defaultConfig.hosted_fields.labels.fields_not_valid;
let message = this.defaultConfig.labels.error.generic;
if (this.emptyFields.size > 0) {
message = this.defaultConfig.hosted_fields.labels.fields_empty;
} else if (!this.cardValid) {
message = this.defaultConfig.hosted_fields.labels.card_not_supported;
} else if (!this.formValid) {
message = this.defaultConfig.hosted_fields.labels.fields_not_valid;
}
this.errorHandler.message(message); this.errorHandler.message(message);
} }
} }

View file

@ -893,6 +893,10 @@ class SmartButton implements SmartButtonInterface {
'credit_card_number' => '', 'credit_card_number' => '',
'cvv' => '', 'cvv' => '',
'mm_yy' => __( 'MM/YY', 'woocommerce-paypal-payments' ), 'mm_yy' => __( 'MM/YY', 'woocommerce-paypal-payments' ),
'fields_empty' => __(
'Card payment details are missing. Please fill in all required fields.',
'woocommerce-paypal-payments'
),
'fields_not_valid' => __( 'fields_not_valid' => __(
'Unfortunately, your credit card details are not valid.', 'Unfortunately, your credit card details are not valid.',
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'