From 63ba2e2198f2feb7b73accfa0a65d61217caf490 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 18 Mar 2024 15:44:54 +0100 Subject: [PATCH 1/2] refactor: validator package bundle size improvements (#8402) --- changelog/refactor-validator-bundle-size | 4 ++++ .../express-button/use-express-checkout-product-handler.js | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelog/refactor-validator-bundle-size diff --git a/changelog/refactor-validator-bundle-size b/changelog/refactor-validator-bundle-size new file mode 100644 index 00000000000..43880deceb1 --- /dev/null +++ b/changelog/refactor-validator-bundle-size @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +refactor: validator package bundle size improvements diff --git a/client/checkout/woopay/express-button/use-express-checkout-product-handler.js b/client/checkout/woopay/express-button/use-express-checkout-product-handler.js index 2b8bdb607ea..357ed4bccd6 100644 --- a/client/checkout/woopay/express-button/use-express-checkout-product-handler.js +++ b/client/checkout/woopay/express-button/use-express-checkout-product-handler.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import validator from 'validator'; +import isEmail from 'validator/lib/isEmail'; import { __ } from '@wordpress/i18n'; const useExpressCheckoutProductHandler = ( api ) => { @@ -49,7 +49,7 @@ const useExpressCheckoutProductHandler = ( api ) => { if ( ! data.wc_gc_giftcard_to_multiple .split( ',' ) - .every( ( email ) => validator.isEmail( email.trim() ) ) + .every( ( email ) => isEmail( email.trim() ) ) ) { alert( __( @@ -62,7 +62,7 @@ const useExpressCheckoutProductHandler = ( api ) => { } if ( data.hasOwnProperty( 'wc_gc_giftcard_to' ) ) { - if ( ! validator.isEmail( data.wc_gc_giftcard_to ) ) { + if ( ! isEmail( data.wc_gc_giftcard_to ) ) { alert( __( 'Please type only valid emails', From f15c223ec7a664e4d10ddc11f55f753b941f2f4a Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 18 Mar 2024 18:21:25 +0100 Subject: [PATCH 2/2] fix: error handling when saved card and amount too large (#8411) Co-authored-by: Guilherme Pressutto --- changelog/payment-utils-when-amount-too-large | 4 ++++ includes/class-wc-payments-utils.php | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 changelog/payment-utils-when-amount-too-large diff --git a/changelog/payment-utils-when-amount-too-large b/changelog/payment-utils-when-amount-too-large new file mode 100644 index 00000000000..8328ed54fad --- /dev/null +++ b/changelog/payment-utils-when-amount-too-large @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +fix: better error message when saved card and amount too large diff --git a/includes/class-wc-payments-utils.php b/includes/class-wc-payments-utils.php index 092e7b8b976..8f56863e34f 100644 --- a/includes/class-wc-payments-utils.php +++ b/includes/class-wc-payments-utils.php @@ -572,6 +572,8 @@ public static function get_filtered_error_message( Exception $e ) { ), wp_strip_all_tags( html_entity_decode( $price ) ) ); + } elseif ( $e instanceof API_Exception && 'amount_too_large' === $e->get_error_code() ) { + $error_message = $e->getMessage(); } elseif ( $e instanceof API_Exception && 'wcpay_bad_request' === $e->get_error_code() ) { $error_message = __( 'We\'re not able to process this request. Please refresh the page and try again.', 'woocommerce-payments' ); } elseif ( $e instanceof API_Exception && ! empty( $e->get_error_type() ) && 'card_error' !== $e->get_error_type() ) {