From a41249f5e0ed6bd33584ed0ecdea0be74cf6ca3b Mon Sep 17 00:00:00 2001 From: Alex Florisca Date: Mon, 9 Jan 2023 12:08:56 +0000 Subject: [PATCH] Set payment status to FAILED or SUCCESS when the storeAPI fetch returns --- .../context/providers/cart-checkout/checkout-processor.ts | 5 +++++ assets/js/data/payment/selectors.ts | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/js/base/context/providers/cart-checkout/checkout-processor.ts b/assets/js/base/context/providers/cart-checkout/checkout-processor.ts index 7b819f3afc4..885410fd8f6 100644 --- a/assets/js/base/context/providers/cart-checkout/checkout-processor.ts +++ b/assets/js/base/context/providers/cart-checkout/checkout-processor.ts @@ -106,6 +106,9 @@ const CheckoutProcessor = () => { }; }, [] ); + const { __internalSetPaymentFailed, __internalSetPaymentSuccess } = + useDispatch( PAYMENT_STORE_KEY ); + const paymentMethods = getPaymentMethods(); const expressPaymentMethods = getExpressPaymentMethods(); const currentBillingAddress = useRef( billingAddress ); @@ -256,6 +259,7 @@ const CheckoutProcessor = () => { if ( ! response.ok ) { throw response; } + __internalSetPaymentSuccess(); return response.json(); } ) .then( ( responseJson: CheckoutResponseSuccess ) => { @@ -263,6 +267,7 @@ const CheckoutProcessor = () => { setIsProcessingOrder( false ); } ) .catch( ( errorResponse: ApiResponse< CheckoutResponseError > ) => { + __internalSetPaymentFailed(); processCheckoutResponseHeaders( errorResponse?.headers ); try { // This attempts to parse a JSON error response where the status code was 4xx/5xx. diff --git a/assets/js/data/payment/selectors.ts b/assets/js/data/payment/selectors.ts index f3eb6edc285..00377b76161 100644 --- a/assets/js/data/payment/selectors.ts +++ b/assets/js/data/payment/selectors.ts @@ -47,7 +47,6 @@ export const isPaymentReady = ( state: PaymentState ) => export const isPaymentFinished = ( state: PaymentState ) => { return ( state.status === PAYMENT_STATUS.SUCCESS || - state.status === PAYMENT_STATUS.ERROR || state.status === PAYMENT_STATUS.FAILED ); };