Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Set payment status to FAILED or SUCCESS when the storeAPI fetch returns
Browse files Browse the repository at this point in the history
  • Loading branch information
alexflorisca committed Jan 9, 2023
1 parent 08ff29a commit a41249f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const CheckoutProcessor = () => {
};
}, [] );

const { __internalSetPaymentFailed, __internalSetPaymentSuccess } =
useDispatch( PAYMENT_STORE_KEY );

const paymentMethods = getPaymentMethods();
const expressPaymentMethods = getExpressPaymentMethods();
const currentBillingAddress = useRef( billingAddress );
Expand Down Expand Up @@ -256,13 +259,15 @@ const CheckoutProcessor = () => {
if ( ! response.ok ) {
throw response;
}
__internalSetPaymentSuccess();
return response.json();
} )
.then( ( responseJson: CheckoutResponseSuccess ) => {
__internalProcessCheckoutResponse( responseJson );
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.
Expand Down
1 change: 0 additions & 1 deletion assets/js/data/payment/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
Expand Down

0 comments on commit a41249f

Please sign in to comment.