diff --git a/src/containers/PayoutDetailsForm/PayoutDetailsForm.js b/src/containers/PayoutDetailsForm/PayoutDetailsForm.js index a10e6509..c1ad34e4 100644 --- a/src/containers/PayoutDetailsForm/PayoutDetailsForm.js +++ b/src/containers/PayoutDetailsForm/PayoutDetailsForm.js @@ -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 ? ( -
- -
- ) : null; + + let error = null; + + if (isStripeInvalidPostalCode(createStripeAccountError)) { + error = ( +
+ +
+ ); + } else if (createStripeAccountError) { + error = ( +
+ +
+ ); + } return (
diff --git a/src/translations/en.json b/src/translations/en.json index 160ced5c..72e439a8 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -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", diff --git a/src/util/errors.js b/src/util/errors.js index a17ce45a..ba773105 100644 --- a/src/util/errors.js +++ b/src/util/errors.js @@ -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