diff --git a/assets/js/data/checkout/test/reducer.ts b/assets/js/data/checkout/test/reducer.ts index 127fde0a649..97930369891 100644 --- a/assets/js/data/checkout/test/reducer.ts +++ b/assets/js/data/checkout/test/reducer.ts @@ -26,7 +26,6 @@ describe.only( 'Checkout Store Reducer', () => { const expectedState = { ...defaultState, redirectUrl: 'https://example.com', - status: STATUS.IDLE, }; expect( @@ -97,12 +96,15 @@ describe.only( 'Checkout Store Reducer', () => { } ); it( 'should handle SET_HAS_ERROR when status is anything else', () => { - const initialState = { ...defaultState, status: STATUS.PRISTINE }; + const initialState = { + ...defaultState, + status: STATUS.AFTER_PROCESSING, + }; const expectedState = { ...defaultState, hasError: false, - status: STATUS.IDLE, + status: STATUS.AFTER_PROCESSING, }; expect( @@ -135,7 +137,6 @@ describe.only( 'Checkout Store Reducer', () => { it( 'should handle INCREMENT_CALCULATING', () => { const expectedState = { ...defaultState, - status: STATUS.IDLE, calculatingCount: 1, }; @@ -152,7 +153,6 @@ describe.only( 'Checkout Store Reducer', () => { const expectedState = { ...defaultState, - status: STATUS.IDLE, calculatingCount: 0, }; @@ -164,7 +164,6 @@ describe.only( 'Checkout Store Reducer', () => { it( 'should handle SET_CUSTOMER_ID', () => { const expectedState = { ...defaultState, - status: STATUS.IDLE, customerId: 1, }; @@ -176,7 +175,6 @@ describe.only( 'Checkout Store Reducer', () => { it( 'should handle SET_USE_SHIPPING_AS_BILLING', () => { const expectedState = { ...defaultState, - status: STATUS.IDLE, useShippingAsBilling: false, }; @@ -191,7 +189,6 @@ describe.only( 'Checkout Store Reducer', () => { it( 'should handle SET_SHOULD_CREATE_ACCOUNT', () => { const expectedState = { ...defaultState, - status: STATUS.IDLE, shouldCreateAccount: true, }; @@ -206,7 +203,6 @@ describe.only( 'Checkout Store Reducer', () => { it( 'should handle SET_ORDER_NOTES', () => { const expectedState = { ...defaultState, - status: STATUS.IDLE, orderNotes: 'test', }; @@ -221,7 +217,6 @@ describe.only( 'Checkout Store Reducer', () => { }; const expectedState = { ...defaultState, - status: STATUS.IDLE, extensionData: mockExtensionData, }; diff --git a/assets/js/data/payment/thunks.ts b/assets/js/data/payment/thunks.ts index 0b142271d81..3fd7bb57d5f 100644 --- a/assets/js/data/payment/thunks.ts +++ b/assets/js/data/payment/thunks.ts @@ -121,7 +121,7 @@ export const __internalEmitPaymentProcessingEvent: emitProcessingEventType = ( const { setBillingAddress, setShippingAddress } = registry.dispatch( CART_STORE_KEY ); - if ( successResponse ) { + if ( successResponse && ! errorResponse ) { const { paymentMethodData } = successResponse?.meta || {}; if ( billingAddress && isBillingAddress( billingAddress ) ) { @@ -135,6 +135,23 @@ export const __internalEmitPaymentProcessingEvent: emitProcessingEventType = ( } dispatch.__internalSetPaymentMethodData( paymentMethodData ); dispatch.__internalSetPaymentReady(); + } else if ( errorResponse && isFailResponse( errorResponse ) ) { + if ( errorResponse.message && errorResponse.message.length ) { + createErrorNotice( errorResponse.message, { + id: 'wc-payment-error', + isDismissible: false, + context: + errorResponse?.messageContext || + noticeContexts.PAYMENTS, + } ); + } + + const { paymentMethodData } = errorResponse?.meta || {}; + if ( billingAddress && isBillingAddress( billingAddress ) ) { + setBillingAddress( billingAddress ); + } + dispatch.__internalSetPaymentError(); + dispatch.__internalSetPaymentMethodData( paymentMethodData ); } else if ( errorResponse ) { if ( errorResponse.message && errorResponse.message.length ) { createErrorNotice( errorResponse.message, {