|
3 | 3 | */ |
4 | 4 | import type { CheckoutResponse } from '@woocommerce/types'; |
5 | 5 | import { store as noticesStore } from '@wordpress/notices'; |
| 6 | +import { dispatch as wpDispatch, select as wpSelect } from '@wordpress/data'; |
6 | 7 |
|
7 | 8 | /** |
8 | 9 | * Internal dependencies |
9 | 10 | */ |
| 11 | +import { STORE_KEY as PAYMENT_STORE_KEY } from '../payment/constants'; |
10 | 12 | import { removeNoticesByStatus } from '../../utils/notices'; |
11 | 13 | import { |
12 | 14 | getPaymentResultFromCheckoutResponse, |
@@ -40,7 +42,11 @@ export const __internalProcessCheckoutResponse = ( |
40 | 42 | } ) => { |
41 | 43 | const paymentResult = getPaymentResultFromCheckoutResponse( response ); |
42 | 44 | dispatch.__internalSetRedirectUrl( paymentResult?.redirectUrl || '' ); |
43 | | - dispatch.__internalSetPaymentResult( paymentResult ); |
| 45 | + // The local `dispatch` here is bound to the actions of the data store. We need to use the global dispatch here |
| 46 | + // to dispatch an action on a different store. |
| 47 | + wpDispatch( PAYMENT_STORE_KEY ).__internalSetPaymentResult( |
| 48 | + paymentResult |
| 49 | + ); |
44 | 50 | dispatch.__internalSetAfterProcessing(); |
45 | 51 | }; |
46 | 52 | }; |
@@ -90,15 +96,16 @@ export const __internalEmitAfterProcessingEvents: emitAfterProcessingEventsType |
90 | 96 | ( { observers, notices } ) => { |
91 | 97 | return ( { select, dispatch, registry } ) => { |
92 | 98 | const { createErrorNotice } = registry.dispatch( noticesStore ); |
93 | | - const state = select.getCheckoutState(); |
| 99 | + const checkoutState = select.getCheckoutState(); |
94 | 100 | const data = { |
95 | | - redirectUrl: state.redirectUrl, |
96 | | - orderId: state.orderId, |
97 | | - customerId: state.customerId, |
98 | | - orderNotes: state.orderNotes, |
99 | | - processingResponse: state.paymentResult, |
| 101 | + redirectUrl: checkoutState.redirectUrl, |
| 102 | + orderId: checkoutState.orderId, |
| 103 | + customerId: checkoutState.customerId, |
| 104 | + orderNotes: checkoutState.orderNotes, |
| 105 | + processingResponse: |
| 106 | + wpSelect( PAYMENT_STORE_KEY ).getPaymentResult(), |
100 | 107 | }; |
101 | | - if ( state.hasError ) { |
| 108 | + if ( checkoutState.hasError ) { |
102 | 109 | // allow payment methods or other things to customize the error |
103 | 110 | // with a fallback if nothing customizes it. |
104 | 111 | emitEventWithAbort( |
|
0 commit comments