Skip to content

Commit

Permalink
feat: handle ajax error response in js
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk committed Nov 13, 2023
1 parent e4a2086 commit 838eb05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions assets/src/js/frontend/paypal-commerce/AdvancedCardFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,21 @@ class AdvancedCardFields extends PaymentMethod {
const errorStringByGroup = {};
const errors = [];

if ( ! Object.values( error ).length ) {
Give.form.fn.resetDonationButton( this.jQueryForm );
throw window.givePayPalCommerce.genericDonorErrorMessage;
}
if (! error ) {
errors.push({message: window.givePayPalCommerce.genericDonorErrorMessage});
Give.form.fn.resetDonationButton(this.jQueryForm);
Give.form.fn.addErrorsAndResetDonationButton(this.jQueryForm, Give.form.fn.getErrorHTML(errors));
return;

} else if (typeof error === 'string') {
errors.push({message: error});
Give.form.fn.resetDonationButton(this.jQueryForm);
Give.form.fn.addErrorsAndResetDonationButton(
this.jQueryForm,
Give.form.fn.getErrorHTML(errors)
);
return;
}

// Group credit card error notices.
error.details.forEach( detail => {
Expand Down
2 changes: 1 addition & 1 deletion assets/src/js/frontend/paypal-commerce/SmartButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class SmartButtons extends PaymentMethod {

this.displayErrorMessage( responseJson.data.error, true );

errorDetail = responseJson.data.error.details[ 0 ];
errorDetail = responseJson.data.error?.details?.[0];
if ( errorDetail && errorDetail.issue === 'INSTRUMENT_DECLINED' ) {
// Recoverable state, see: "Handle Funding Failures"
// https://developer.paypal.com/docs/checkout/integration-features/funding-failure/
Expand Down

0 comments on commit 838eb05

Please sign in to comment.