@@ -34,7 +34,10 @@ import { STATUS } from '../../../../../data/checkout/constants';
34
34
import { useStoreEvents } from '../../../hooks/use-store-events' ;
35
35
import { useCheckoutNotices } from '../../../hooks/use-checkout-notices' ;
36
36
import { CheckoutState } from '../../../../../data/checkout/default-state' ;
37
- import { getPaymentMethods } from '../../../../../blocks-registry/payment-methods/registry' ;
37
+ import {
38
+ getExpressPaymentMethods ,
39
+ getPaymentMethods ,
40
+ } from '../../../../../blocks-registry/payment-methods/registry' ;
38
41
39
42
type CheckoutEventsContextType = {
40
43
// Submits the checkout and begins processing.
@@ -77,19 +80,32 @@ export const CheckoutEventsProvider = ( {
77
80
redirectUrl : string ;
78
81
} ) : JSX . Element => {
79
82
const paymentMethods = getPaymentMethods ( ) ;
83
+ const expressPaymentMethods = getExpressPaymentMethods ( ) ;
80
84
81
85
// Go into useState as once this is set it won't change.
82
86
const [ isEditor ] = useState ( ! ! wpDataSelect ( 'core/editor' ) ) ;
83
87
84
- const { __internalInitializePaymentStore } =
88
+ const { __internalUpdateAvailablePaymentMethods } =
85
89
useDispatch ( PAYMENT_STORE_KEY ) ;
86
90
91
+ // Update the payment method store when paymentMethods or expressPaymentMethods changes.
92
+ // Ensure this happens in the editor even if paymentMethods is empty. This won't happen instantly when the objects
93
+ // are updated, but on the next re-render.
87
94
useEffect ( ( ) => {
88
- if ( ! isEditor && Object . keys ( paymentMethods ) . length === 0 ) {
95
+ if (
96
+ ! isEditor &&
97
+ Object . keys ( paymentMethods ) . length === 0 &&
98
+ Object . keys ( expressPaymentMethods ) . length === 0
99
+ ) {
89
100
return ;
90
101
}
91
102
__internalUpdateAvailablePaymentMethods ( ) ;
92
- } , [ isEditor , paymentMethods , __internalInitializePaymentStore ] ) ;
103
+ } , [
104
+ isEditor ,
105
+ paymentMethods ,
106
+ expressPaymentMethods ,
107
+ __internalUpdateAvailablePaymentMethods ,
108
+ ] ) ;
93
109
94
110
const checkoutActions = useDispatch ( CHECKOUT_STORE_KEY ) ;
95
111
const checkoutState : CheckoutState = useSelect ( ( select ) =>
0 commit comments