Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix charge disabled error #1098

Merged
merged 2 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ way to update this template, but currently, we follow a pattern:

## Upcoming version 2019-XX-XX

- [fix] missing provider information (like SSN in US), might cause payment to fail on
`CheckoutPage`. This improves related error message.
[#10967](https://github.com/sharetribe/flex-template-web/pull/1097)
- [fix] Menu needs to wait for mounting to calculate dimensions properly.
[#1096](https://github.com/sharetribe/flex-template-web/pull/1096)
- [fix] Renamed Component.example.css files to ComponentExample.css to fix bug introduced in one of
Expand Down
8 changes: 8 additions & 0 deletions src/containers/CheckoutPage/CheckoutPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isTransactionInitiateListingNotFoundError,
isTransactionInitiateMissingStripeAccountError,
isTransactionInitiateBookingTimeNotAvailableError,
isTransactionChargeDisabledError,
isTransactionZeroPaymentError,
transactionInitiateOrderStripeErrors,
} from '../../util/errors';
Expand Down Expand Up @@ -304,6 +305,7 @@ export class CheckoutPageComponent extends Component {
);

const isAmountTooLowError = isTransactionInitiateAmountTooLowError(initiateOrderError);
const isChargeDisabledError = isTransactionChargeDisabledError(initiateOrderError);
const isBookingTimeNotAvailableError = isTransactionInitiateBookingTimeNotAvailableError(
initiateOrderError
);
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
25 changes: 25 additions & 0 deletions src/util/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down