From 5d912c7716e6b98876742b3795373ec0ca11fc3d Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Wed, 28 Feb 2018 09:36:32 +0200 Subject: [PATCH 1/3] Add error code --- src/util/types.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/types.js b/src/util/types.js index 046b8600..438b5b93 100644 --- a/src/util/types.js +++ b/src/util/types.js @@ -394,6 +394,7 @@ export const ERROR_CODE_UPLOAD_OVER_LIMIT = 'request-upload-over-limit'; export const ERROR_CODE_VALIDATION_INVALID_PARAMS = 'validation-invalid-params'; export const ERROR_CODE_NOT_FOUND = 'not-found'; export const ERROR_CODE_FORBIDDEN = 'forbidden'; +export const ERROR_CODE_MISSING_STRIPE_ACCOUNT = 'transaction-missing-stripe-account'; const ERROR_CODES = [ ERROR_CODE_TRANSACTION_LISTING_NOT_FOUND, @@ -409,6 +410,7 @@ const ERROR_CODES = [ ERROR_CODE_VALIDATION_INVALID_PARAMS, ERROR_CODE_NOT_FOUND, ERROR_CODE_FORBIDDEN, + ERROR_CODE_MISSING_STRIPE_ACCOUNT, ]; // API error From 33deabeec255656139b88caec2a1bc9595265179 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Wed, 28 Feb 2018 09:55:06 +0200 Subject: [PATCH 2/3] Add error helper for missing Stripe account error --- src/util/errors.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/errors.js b/src/util/errors.js index b14bccc1..fbeacc8f 100644 --- a/src/util/errors.js +++ b/src/util/errors.js @@ -20,6 +20,7 @@ import { ERROR_CODE_EMAIL_NOT_VERIFIED, ERROR_CODE_TOO_MANY_VERIFICATION_REQUESTS, ERROR_CODE_UPLOAD_OVER_LIMIT, + ERROR_CODE_MISSING_STRIPE_ACCOUNT, } from './types'; const errorAPIErrors = error => { @@ -101,6 +102,14 @@ export const isPasswordRecoveryEmailNotVerifiedError = error => export const isTransactionInitiateListingNotFoundError = error => hasErrorWithCode(error, ERROR_CODE_TRANSACTION_LISTING_NOT_FOUND); +/** + * Check if the given API error (from `sdk.transaction.initiate()` or + * `sdk.transaction.initiateSpeculative()`) is due to missign Stripe + * connection from the listing author. + */ +export const isTransactionInitiateMissingStripeAccountError = error => + hasErrorWithCode(error, ERROR_CODE_MISSING_STRIPE_ACCOUNT); + /** * Check if the given API error (from `sdk.transaction.initiate()`) is * due to the transaction total amount being too low for Stripe. From 4f91b2aa9e2b4eb62eb242141b15f46d7b322665 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Wed, 28 Feb 2018 09:55:47 +0200 Subject: [PATCH 3/3] Handle speculation errors properly in checkout - Hide form if speculation failed - Add specific error message for missing author Stripe account - Add generic error message for other speculation errors --- src/containers/CheckoutPage/CheckoutPage.js | 20 +++++++++++++++++++- src/translations/en.json | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/containers/CheckoutPage/CheckoutPage.js b/src/containers/CheckoutPage/CheckoutPage.js index 9d369754..c2e5a26d 100644 --- a/src/containers/CheckoutPage/CheckoutPage.js +++ b/src/containers/CheckoutPage/CheckoutPage.js @@ -13,6 +13,7 @@ import { createSlug } from '../../util/urlHelpers'; import { isTransactionInitiateAmountTooLowError, isTransactionInitiateListingNotFoundError, + isTransactionInitiateMissingStripeAccountError, } from '../../util/errors'; import { AvatarMedium, @@ -225,7 +226,8 @@ export class CheckoutPageComponent extends Component { currentUser && hasRequiredData && !listingNotFound && - !initiateOrderError + !initiateOrderError && + !speculateTransactionError ); const listingTitle = currentListing.attributes.title; @@ -270,6 +272,21 @@ export class CheckoutPageComponent extends Component {

) : null; + let speculateErrorMessage = null; + + if (isTransactionInitiateMissingStripeAccountError(speculateTransactionError)) { + speculateErrorMessage = ( +

+ +

+ ); + } else if (speculateTransactionError) { + speculateErrorMessage = ( +

+ +

+ ); + } const topbar = (
@@ -343,6 +360,7 @@ export class CheckoutPageComponent extends Component {
{initiateOrderErrorMessage} {listingNotFoundErrorMessage} + {speculateErrorMessage} {showPaymentForm ? (