Skip to content

Commit

Permalink
Fix: throw error message instead of the error object when submitting …
Browse files Browse the repository at this point in the history
…an donation made with Stripe Element gateway (#7399)
  • Loading branch information
glaubersilva authored and kjohnson committed Aug 21, 2024
1 parent 8aff186 commit d82d281
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {Elements, PaymentElement, useElements, useStripe} from '@stripe/react-stripe-js';
import {applyFilters} from '@wordpress/hooks';
import type {Gateway, GatewaySettings} from '@givewp/forms/types';
import {__, sprintf} from '@wordpress/i18n';

let stripePromise = null;
let stripePaymentMethod = null;
Expand Down Expand Up @@ -123,7 +124,21 @@ const stripePaymentElementGateway: StripeGateway = {
const {error: submitError} = await this.elements.submit();

if (submitError) {
throw new Error(submitError);
let errorMessage = __('Invalid Payment Data.', 'give');

if (typeof submitError === 'string') {
errorMessage = sprintf(__('Invalid Payment Data. Error Details: %s', 'give'), submitError);
}

if (submitError.hasOwnProperty('code') && submitError.hasOwnProperty('message')) {
errorMessage = sprintf(
__('Invalid Payment Data. Error Details: %s (code: %s)', 'give'),
submitError.message,
submitError.code
);
}

throw new Error(errorMessage);
}

return {
Expand Down

0 comments on commit d82d281

Please sign in to comment.