Merge branch 'trunk' into pcp-697-separate-gateway

This commit is contained in:
Alex P 2022-07-26 15:28:27 +03:00
commit e55e2d9c81
5 changed files with 59 additions and 12 deletions

View file

@ -1,6 +1,6 @@
*** Changelog *** *** Changelog ***
= 1.9.1 - TBD = = 1.9.1 - 2022-07-25 =
* Fix - ITEM_TOTAL_MISMATCH error when checking out with multiple products #721 * Fix - ITEM_TOTAL_MISMATCH error when checking out with multiple products #721
* Fix - Unable to purchase a product with Credit card button in pay for order page #718 * Fix - Unable to purchase a product with Credit card button in pay for order page #718
* Fix - Pay Later messaging only displayed when smart button is active on the same page #283 * Fix - Pay Later messaging only displayed when smart button is active on the same page #283

View file

@ -40,9 +40,36 @@ const bootstrap = () => {
requiredFields.each((i, input) => { requiredFields.each((i, input) => {
jQuery(input).trigger('validate'); jQuery(input).trigger('validate');
}); });
if (jQuery('form.woocommerce-checkout .validate-required.woocommerce-invalid:visible').length) { const invalidFields = Array.from(jQuery('form.woocommerce-checkout .validate-required.woocommerce-invalid:visible'));
if (invalidFields.length) {
const billingFieldsContainer = document.querySelector('.woocommerce-billing-fields');
const shippingFieldsContainer = document.querySelector('.woocommerce-shipping-fields');
const nameMessageMap = PayPalCommerceGateway.labels.error.required.elements;
const messages = invalidFields.map(el => {
const name = el.querySelector('[name]')?.getAttribute('name');
if (name && name in nameMessageMap) {
return nameMessageMap[name];
}
let label = el.querySelector('label').textContent
.replaceAll('*', '')
.trim();
if (billingFieldsContainer?.contains(el)) {
label = PayPalCommerceGateway.labels.billing_field.replace('%s', label);
}
if (shippingFieldsContainer?.contains(el)) {
label = PayPalCommerceGateway.labels.shipping_field.replace('%s', label);
}
return PayPalCommerceGateway.labels.error.required.field
.replace('%s', `<strong>${label}</strong>`)
}).filter(s => s.length > 2);
errorHandler.clear(); errorHandler.clear();
errorHandler.message(PayPalCommerceGateway.labels.error.js_validation); if (messages.length) {
messages.forEach(s => errorHandler.message(s));
} else {
errorHandler.message(PayPalCommerceGateway.labels.error.required.generic);
}
return actions.reject(); return actions.reject();
} }
@ -85,7 +112,7 @@ const bootstrap = () => {
PayPalCommerceGateway, PayPalCommerceGateway,
renderer, renderer,
messageRenderer, messageRenderer,
); );w
singleProductBootstrap.init(); singleProductBootstrap.init();
} }

View file

@ -876,16 +876,31 @@ class SmartButton implements SmartButtonInterface {
), ),
'messages' => $this->message_values(), 'messages' => $this->message_values(),
'labels' => array( 'labels' => array(
'error' => array( 'error' => array(
'generic' => __( 'generic' => __(
'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' => array(
'Required form fields are not filled or invalid.', 'generic' => __(
'woocommerce-paypal-payments' 'Required form fields are not filled.',
'woocommerce-paypal-payments'
),
// phpcs:ignore WordPress.WP.I18n
'field' => __( '%s is a required field.', 'woocommerce' ),
'elements' => array( // Map <form element name> => text for error messages.
'terms' => __(
'Please read and accept the terms and conditions to proceed with your order.',
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'woocommerce'
),
),
), ),
), ),
// phpcs:ignore WordPress.WP.I18n
'billing_field' => _x( 'Billing %s', 'checkout-validation', 'woocommerce' ),
// phpcs:ignore WordPress.WP.I18n
'shipping_field' => _x( 'Shipping %s', 'checkout-validation', 'woocommerce' ),
), ),
'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,
'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ), 'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ),

View file

@ -22,7 +22,7 @@ use WC_Product_Variation;
class PayUponInvoiceHelper { class PayUponInvoiceHelper {
/** /**
* Ensures date is valid and at least 18 years back. * Ensures date is valid, at least 18 years back and not older than 100 years.
* *
* @param string $date The date. * @param string $date The date.
* @param string $format The date format. * @param string $format The date format.
@ -43,6 +43,10 @@ class PayUponInvoiceHelper {
return false; return false;
} }
if ( $date_time < strtotime( '-100 years', time() ) ) {
return false;
}
return true; return true;
} }

View file

@ -26,6 +26,7 @@ class PayUponInvoiceHelperTest extends TestCase
['1942-02-31', false], ['1942-02-31', false],
['01-01-1942', false], ['01-01-1942', false],
['1942-01-01', true], ['1942-01-01', true],
['0001-01-01', false],
]; ];
} }