Add basic input validation before opening PayPal popup

This commit is contained in:
Alex P 2022-06-03 10:50:54 +03:00
parent 77230fefa8
commit 993e109c49
2 changed files with 17 additions and 0 deletions

View file

@ -31,6 +31,19 @@ const bootstrap = () => {
const onSmartButtonClick = (data, actions) => { const onSmartButtonClick = (data, actions) => {
window.ppcpFundingSource = data.fundingSource; window.ppcpFundingSource = data.fundingSource;
// TODO: quick fix to get the error about empty form before attempting PayPal order
// it should solve #513 for most of the users, but proper solution should be implemented later.
const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input');
requiredFields.each((i, input) => {
jQuery(input).trigger('validate');
});
if (jQuery('form.woocommerce-checkout .woocommerce-invalid').length) {
errorHandler.clear();
errorHandler.message(PayPalCommerceGateway.labels.error.js_validation);
return actions.reject();
}
const form = document.querySelector('form.woocommerce-checkout'); const form = document.querySelector('form.woocommerce-checkout');
if (form) { if (form) {
jQuery('#ppcp-funding-source-form-input').remove(); jQuery('#ppcp-funding-source-form-input').remove();

View file

@ -843,6 +843,10 @@ class SmartButton implements SmartButtonInterface {
'Something went wrong. Please try again or choose another payment source.', 'Something went wrong. Please try again or choose another payment source.',
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
), ),
'js_validation' => __(
'Required form fields are not filled or invalid.',
'woocommerce-paypal-payments'
),
), ),
), ),
'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0, 'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,