-
Notifications
You must be signed in to change notification settings - Fork 219
Revise checkout payment statuses to avoid data loss on error #5350
Conversation
Size Change: +20 B (0%) Total Size: 840 kB
ℹ️ View Unchanged
|
[ savedTokenKey ]: token.toString(), | ||
isSavedToken: true, | ||
} ); | ||
removeNotice( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was previously handled in the context provider via useEffect, but because we want the token and method ID it seemed best to move it all to the onClick handler.
@@ -79,10 +80,10 @@ const ExpressPaymentMethods = () => { | |||
( errorMessage ) => { | |||
setPaymentStatus().error( errorMessage ); | |||
setExpressPaymentError( errorMessage ); | |||
setActivePaymentMethod( previousActivePaymentMethod.current ); | |||
if ( previousPaymentMethodData.current.isSavedToken ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code appears to have been added as a workaround for started/pristine data resetting. Saved methods should not be using STARTED
so I've removed it.
}; | ||
setActivePaymentMethod: ( | ||
paymentMethod: string, | ||
paymentMethodData?: ObjectType | EmptyObjectType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data can now be set at the same time as setting an active payment method. This removes the need to use STARTED status to set data.
type: STATUS.SUCCESS, | ||
paymentMethodData, | ||
} as const ), | ||
started: ( { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can no longer dispatch started
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's dispatched as statusOnly
now like pristine. That's all express methods need. The data addition was added for saved payment methods - with the new setActivePaymentMethod
method that's no longer a requirement. They can stay pristine.
assets/js/base/context/providers/cart-checkout/payment-methods/reducer.ts
Outdated
Show resolved
Hide resolved
if ( | ||
! activePaymentMethod && | ||
paymentMethod.is_default && | ||
activeSavedToken === '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we were handling defaults here. I moved it to context with the other default setter.
…/reducer.ts Co-authored-by: Seghir Nadir <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests and works very well!
…erce#5350) * Clarify docs for STARTED * Clarify docs for setActivePaymentMethod * Remove useActivePaymentMethod hook (this held state for active methods and tokens) * Update type defs * Enhance setActivePaymentMethod action to accept method data * SET_ACTIVE_PAYMENT_METHOD action * Add setActivePaymentMethod dispatcher and make "started" status only * Update setActivePaymentMethod usage in express methods * Set radio control defaults * Consolodate tokens and methods * Update assets/js/base/context/providers/cart-checkout/payment-methods/reducer.ts Co-authored-by: Seghir Nadir <[email protected]> * Spacing * Split saved cards tests from regular, since saved cards are checked by default Co-authored-by: Seghir Nadir <[email protected]>
Issue reported here as as well 4580573-zen. |
…erce#5350) * Clarify docs for STARTED * Clarify docs for setActivePaymentMethod * Remove useActivePaymentMethod hook (this held state for active methods and tokens) * Update type defs * Enhance setActivePaymentMethod action to accept method data * SET_ACTIVE_PAYMENT_METHOD action * Add setActivePaymentMethod dispatcher and make "started" status only * Update setActivePaymentMethod usage in express methods * Set radio control defaults * Consolodate tokens and methods * Update assets/js/base/context/providers/cart-checkout/payment-methods/reducer.ts Co-authored-by: Seghir Nadir <[email protected]> * Spacing * Split saved cards tests from regular, since saved cards are checked by default Co-authored-by: Seghir Nadir <[email protected]>
We're seeing errors and inconsistencies with payment method data being lost when errors cause a status change (to pristine) on checkout. On reviewing this, we've also noticed some discrepancies with how statuses (in particular the
STARTED
status) are used in a non-documented way. It's also confusing how some data is stored in the context provider, some in hooks, and yet it all needs to be kept in sync (currently with useEffect calls).To solve this, I've taken the following approach:
useActivePaymentMethod
hook which had methods to set active method, and active token. This has been replaced with data in the context provider.setActivePaymentMethod
now accepts payment method data. By consolidating it within this function, saved methods no longer need to use theSTARTED
status to store data.setActiveToken
.useEffect
hook to avoid conflicts.Fixes #5296
Closes #5318 in favor of this.
Testing
Please smoke test the following:
Also, test the case from #5296.
Changelog