mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add Basic Checkout Validation and Early Checkout Validation to Card Fields
This commit is contained in:
parent
425b7b4a31
commit
a37594643a
3 changed files with 46 additions and 17 deletions
|
@ -40,11 +40,6 @@ const bootstrap = () => {
|
|||
);
|
||||
const spinner = new Spinner();
|
||||
|
||||
let creditCardRenderer = new HostedFieldsRenderer(PayPalCommerceGateway, errorHandler, spinner);
|
||||
if (typeof paypal.CardFields !== 'undefined') {
|
||||
creditCardRenderer = new CardFieldsRenderer(PayPalCommerceGateway, errorHandler, spinner);
|
||||
}
|
||||
|
||||
const formSaver = new FormSaver(
|
||||
PayPalCommerceGateway.ajax.save_checkout_form.endpoint,
|
||||
PayPalCommerceGateway.ajax.save_checkout_form.nonce,
|
||||
|
@ -73,13 +68,7 @@ const bootstrap = () => {
|
|||
&& document.querySelector(PayPalCommerceGateway.messages.wrapper);
|
||||
}
|
||||
|
||||
const onSmartButtonClick = async (data, actions) => {
|
||||
window.ppcpFundingSource = data.fundingSource;
|
||||
const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input');
|
||||
requiredFields.each((i, input) => {
|
||||
jQuery(input).trigger('validate');
|
||||
});
|
||||
|
||||
const doBasicCheckoutValidation = () => {
|
||||
if (PayPalCommerceGateway.basic_checkout_validation_enabled) {
|
||||
// A quick fix to get the errors about empty form fields before attempting PayPal order,
|
||||
// it should solve #513 for most of the users, but it is not a proper solution.
|
||||
|
@ -117,9 +106,26 @@ const bootstrap = () => {
|
|||
errorHandler.message(PayPalCommerceGateway.labels.error.required.generic);
|
||||
}
|
||||
|
||||
return actions.reject();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const onCardFieldsBeforeSubmit = () => {
|
||||
return doBasicCheckoutValidation();
|
||||
};
|
||||
|
||||
const onSmartButtonClick = async (data, actions) => {
|
||||
window.ppcpFundingSource = data.fundingSource;
|
||||
const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input');
|
||||
requiredFields.each((i, input) => {
|
||||
jQuery(input).trigger('validate');
|
||||
});
|
||||
|
||||
if (!doBasicCheckoutValidation()) {
|
||||
return actions.reject();
|
||||
}
|
||||
|
||||
const form = document.querySelector(checkoutFormSelector);
|
||||
if (form) {
|
||||
|
@ -149,6 +155,12 @@ const bootstrap = () => {
|
|||
jQuery(document).trigger('ppcp-smart-buttons-init', this);
|
||||
buttonsSpinner.unblock();
|
||||
};
|
||||
|
||||
let creditCardRenderer = new HostedFieldsRenderer(PayPalCommerceGateway, errorHandler, spinner);
|
||||
if (typeof paypal.CardFields !== 'undefined') {
|
||||
creditCardRenderer = new CardFieldsRenderer(PayPalCommerceGateway, errorHandler, spinner, onCardFieldsBeforeSubmit);
|
||||
}
|
||||
|
||||
const renderer = new Renderer(creditCardRenderer, PayPalCommerceGateway, onSmartButtonClick, onSmartButtonsInit);
|
||||
const messageRenderer = new MessageRenderer(PayPalCommerceGateway.messages);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue