From 6ca1c5884c8fe257404a586fc5c4a94d813b4ef9 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Tue, 23 Jun 2026 10:53:06 -0300 Subject: [PATCH 1/2] Improve PayPal front end error messages --- paypal/js/frontend.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/paypal/js/frontend.js b/paypal/js/frontend.js index 13371c0a8a..beda09cd59 100644 --- a/paypal/js/frontend.js +++ b/paypal/js/frontend.js @@ -1568,7 +1568,11 @@ } if ( 'string' === typeof err ) { - return parsePayPalErrorString( err ) || err; + const parsed = parsePayPalErrorString( err ); + if ( parsed ) { + return parsed; + } + return mapPayPalErrorCode( err ) || err; } // PayPal SDK sometimes nests the payload under `err.data` or `err.response`. @@ -1581,12 +1585,33 @@ } if ( err.message ) { - return parsePayPalErrorString( err.message ) || err.message; + const parsed = parsePayPalErrorString( err.message ); + if ( parsed ) { + return parsed; + } + return mapPayPalErrorCode( err.message ) || err.message; } return fallback; } + /** + * Map PayPal error codes to user-friendly messages. + * + * @param {string} code The PayPal error code (e.g. INVALID_CVV). + * @return {string} The user-friendly message, or empty string if not mapped. + */ + function mapPayPalErrorCode( code ) { + const codeMap = { + 'INVALID_CVV': 'Please enter a valid CVV code.', + 'INVALID_CARD_NUMBER': 'Please enter a valid card number.', + 'INVALID_EXPIRY': 'Please enter a valid expiry date.', + }; + + const upperCode = code.toUpperCase(); + return codeMap[ upperCode ] || ''; + } + /** * Extract the first `description` from a PayPal `details` array. * From 5584cca134bdf2c9fb51b86bfa87c3195ec7495d Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Tue, 23 Jun 2026 11:39:40 -0300 Subject: [PATCH 2/2] Remove unnecessary quotes --- paypal/js/frontend.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paypal/js/frontend.js b/paypal/js/frontend.js index beda09cd59..479b74be4d 100644 --- a/paypal/js/frontend.js +++ b/paypal/js/frontend.js @@ -1603,9 +1603,9 @@ */ function mapPayPalErrorCode( code ) { const codeMap = { - 'INVALID_CVV': 'Please enter a valid CVV code.', - 'INVALID_CARD_NUMBER': 'Please enter a valid card number.', - 'INVALID_EXPIRY': 'Please enter a valid expiry date.', + INVALID_CVV: 'Please enter a valid CVV code.', + INVALID_CARD_NUMBER: 'Please enter a valid card number.', + INVALID_EXPIRY: 'Please enter a valid expiry date.', }; const upperCode = code.toUpperCase();