Check if the booking error happens due to disabled charge creation

This commit is contained in:
Vesa Luusua 2019-05-23 13:58:37 +03:00
parent 200ca602e1
commit db11a921ad
3 changed files with 34 additions and 0 deletions

View file

@ -16,6 +16,7 @@ import {
isTransactionInitiateListingNotFoundError,
isTransactionInitiateMissingStripeAccountError,
isTransactionInitiateBookingTimeNotAvailableError,
isTransactionChargeDisabledError,
isTransactionZeroPaymentError,
transactionInitiateOrderStripeErrors,
} from '../../util/errors';
@ -304,6 +305,7 @@ export class CheckoutPageComponent extends Component {
);
const isAmountTooLowError = isTransactionInitiateAmountTooLowError(initiateOrderError);
const isChargeDisabledError = isTransactionChargeDisabledError(initiateOrderError);
const isBookingTimeNotAvailableError = isTransactionInitiateBookingTimeNotAvailableError(
initiateOrderError
);
@ -323,6 +325,12 @@ export class CheckoutPageComponent extends Component {
<FormattedMessage id="CheckoutPage.bookingTimeNotAvailableMessage" />
</p>
);
} else if (!listingNotFound && isChargeDisabledError) {
initiateOrderErrorMessage = (
<p className={css.orderError}>
<FormattedMessage id="CheckoutPage.chargeDisabledMessage" />
</p>
);
} else if (!listingNotFound && stripeErrors && stripeErrors.length > 0) {
// NOTE: Error messages from Stripes are not part of translations.
// By default they are in English.

View file

@ -79,6 +79,7 @@
"BookingPanel.perUnit": "per unit",
"BookingPanel.subTitleClosedListing": "Sorry, this listing has been closed.",
"CheckoutPage.bookingTimeNotAvailableMessage": "Unfortunately, the requested time is already booked.",
"CheckoutPage.chargeDisabledMessage": "This provider's payout information is incomplete so this listing cannot be booked. Please contact the administrator.",
"CheckoutPage.errorlistingLinkText": "the sauna page",
"CheckoutPage.goToLandingPage": "Go to homepage",
"CheckoutPage.hostedBy": "Hosted by {name}",

View file

@ -140,6 +140,31 @@ export const isTransactionInitiateAmountTooLowError = error => {
return isZeroPayment || tooLowAmount;
};
/**
* Check if the given API error (from `sdk.transaction.initiate()`) is
* due to the transaction charge creation disabled by Stripe.
*/
export const isTransactionChargeDisabledError = error => {
const chargeCreationDisabled = errorAPIErrors(error).some(apiError => {
const isPaymentFailedError =
apiError.status === 402 && apiError.code === ERROR_CODE_PAYMENT_FAILED;
let isChargeCreationDisabled = false;
try {
const msg = apiError.meta.stripeMessage;
isChargeCreationDisabled =
msg.startsWith('Your account cannot currently make charges.') ||
msg.match(/verification.disabled_reason/);
} catch (e) {
// Ignore
}
return isPaymentFailedError && isChargeCreationDisabled;
});
return chargeCreationDisabled;
};
/**
* Check if the given API error (from `sdk.transaction.initiate()`) is
* due to other error in Stripe.