mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Detect invalid postal code error in Stripe account creation
This commit is contained in:
parent
51576fa1e2
commit
9e98466661
3 changed files with 34 additions and 5 deletions
|
|
@ -15,6 +15,7 @@ import {
|
|||
TextInputField,
|
||||
} from '../../components';
|
||||
import * as validators from '../../util/validators';
|
||||
import { isStripeInvalidPostalCode } from '../../util/errors';
|
||||
|
||||
import css from './PayoutDetailsForm.css';
|
||||
|
||||
|
|
@ -191,11 +192,22 @@ const PayoutDetailsFormComponent = props => {
|
|||
const submitReady = false;
|
||||
const submitInProgress = submitting || inProgress;
|
||||
const submitDisabled = pristine || invalid || disabled || submitInProgress;
|
||||
const error = createStripeAccountError ? (
|
||||
<div className={css.error}>
|
||||
<FormattedMessage id="PayoutDetailsForm.createStripeAccountFailed" />
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
let error = null;
|
||||
|
||||
if (isStripeInvalidPostalCode(createStripeAccountError)) {
|
||||
error = (
|
||||
<div className={css.error}>
|
||||
<FormattedMessage id="PayoutDetailsForm.createStripeAccountFailedInvalidPostalCode" />
|
||||
</div>
|
||||
);
|
||||
} else if (createStripeAccountError) {
|
||||
error = (
|
||||
<div className={css.error}>
|
||||
<FormattedMessage id="PayoutDetailsForm.createStripeAccountFailed" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Form className={classes} onSubmit={handleSubmit}>
|
||||
|
|
|
|||
|
|
@ -395,6 +395,7 @@
|
|||
"PayoutDetailsForm.countryPlaceholder": "Select your country…",
|
||||
"PayoutDetailsForm.countryRequired": "This field is required",
|
||||
"PayoutDetailsForm.createStripeAccountFailed": "Whoops, something went wrong. Please try again.",
|
||||
"PayoutDetailsForm.createStripeAccountFailedInvalidPostalCode": "Whoops, check that the selected country and postal code are correct and try again.",
|
||||
"PayoutDetailsForm.firstNameLabel": "First name",
|
||||
"PayoutDetailsForm.firstNamePlaceholder": "John",
|
||||
"PayoutDetailsForm.firstNameRequired": "This field is required",
|
||||
|
|
|
|||
|
|
@ -157,6 +157,22 @@ export const isChangeEmailWrongPassword = error => error && error.status === 403
|
|||
*/
|
||||
export const isChangePasswordWrongPassword = error => error && error.status === 403;
|
||||
|
||||
|
||||
/**
|
||||
* Check if the given API error (from
|
||||
* 'sdk.currentUser.createStripeAccount(payoutDetails)') is due to
|
||||
* invalid postal code in the given country.
|
||||
*/
|
||||
export const isStripeInvalidPostalCode = error => {
|
||||
const msgRe = /^Invalid [A-Z]{2} postal code$/;
|
||||
return errorAPIErrors(error).some(apiError => {
|
||||
// Stripe doesn't seem to give an error code for this specific
|
||||
// case, so we have to recognize it from the message.
|
||||
const msg = apiError.meta && apiError.meta.stripe_message ? apiError.meta.stripe_message : '';
|
||||
return msgRe.test(msg);
|
||||
});
|
||||
};
|
||||
|
||||
export const storableError = error => {
|
||||
const { name, message, status, statusText } = error;
|
||||
// Status, statusText, and data.errors are (possibly) added to the error object by SDK
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue