Skip to content

Commit

Permalink
Fixed possible race condition on the WooPay opt-in (#10399)
Browse files Browse the repository at this point in the history
Co-authored-by: Miguel Gasca <[email protected]>
  • Loading branch information
leonardola and mgascam authored Feb 20, 2025
1 parent 0e656e7 commit 94dd750
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-woopay-opt-in-race-condition
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fixed WooPay opt-in race condition
29 changes: 23 additions & 6 deletions client/components/woopay/save-user/checkout-page-save-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,34 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
isBlocksCheckout,
] );

useEffect( () => {
if (
! getConfig( 'forceNetworkSavedCards' ) ||
! isWCPayWithNewTokenChosen ||
isRegisteredUser
) {
// Clicking the place order button sets the extension data in backend. If user changes the payment method
// due to an error, we need to clear the extension data in backend.
if ( isBlocksCheckout && userDataSent ) {
sendExtensionData( true );
}
clearValidationError( errorId );
}
}, [
clearValidationError,
errorId,
isBlocksCheckout,
isRegisteredUser,
isWCPayWithNewTokenChosen,
sendExtensionData,
userDataSent,
] );

if (
! getConfig( 'forceNetworkSavedCards' ) ||
! isWCPayWithNewTokenChosen ||
isRegisteredUser
) {
// Clicking the place order button sets the extension data in backend. If user changes the payment method
// due to an error, we need to clear the extension data in backend.
if ( isBlocksCheckout && userDataSent ) {
sendExtensionData( true );
}
clearValidationError( errorId );
return null;
}

Expand Down

0 comments on commit 94dd750

Please sign in to comment.