-
Notifications
You must be signed in to change notification settings - Fork 58
Refactor Fastlane email submission state management in Classic Checkout (5095) #3637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Dinamiko
merged 4 commits into
develop
from
PCP-5095-fastlane-email-lookup-fails-on-classic-checkout-when-email-is-pre-populated-from-session-v2
Oct 8, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e556108
✨ Add Fastlane session restoring post payment failure (Block Checkout)
danieldudzic 3a20cb4
✨ Add Fastlane session restoring post payment failure (Classic Checkout)
danieldudzic 499835f
🔄 Axo: Refactor email submission with centralized ButtonStateManager …
danieldudzic 67881e9
✨ Add Fastlane error param via filter to checkout error redirects
danieldudzic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
modules/ppcp-axo-block/resources/js/hooks/useSessionRestoration.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { useEffect, useRef } from '@wordpress/element'; | ||
| import { useDispatch } from '@wordpress/data'; | ||
| import { setIsEmailLookupCompleted, STORE_NAME } from '../stores/axoStore'; | ||
| import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug'; | ||
|
|
||
| /** | ||
| * Hook to restore Fastlane session after payment failures using triggerAuthenticationFlow | ||
| * Only runs when ppcp_fastlane_error=1 URL parameter is present | ||
| * @param {Object} fastlaneSdk - The Fastlane SDK instance | ||
| */ | ||
| const useSessionRestoration = ( fastlaneSdk ) => { | ||
| const { setShippingAddress, setCardDetails, setIsGuest } = | ||
| useDispatch( STORE_NAME ); | ||
| const hasProcessed = useRef( false ); | ||
|
|
||
| useEffect( () => { | ||
| if ( ! fastlaneSdk || hasProcessed.current ) { | ||
| return; | ||
| } | ||
|
|
||
| const urlParams = new URLSearchParams( window.location.search ); | ||
| const hasErrorParam = urlParams.get( 'ppcp_fastlane_error' ) === '1'; | ||
|
|
||
| if ( ! hasErrorParam ) { | ||
| return; | ||
| } | ||
|
|
||
| // Remove the error parameter from URL | ||
| urlParams.delete( 'ppcp_fastlane_error' ); | ||
| const newUrl = new URL( window.location ); | ||
| newUrl.search = urlParams.toString(); | ||
| window.history.replaceState( {}, '', newUrl ); | ||
|
|
||
| hasProcessed.current = true; | ||
|
|
||
| const restoreSession = async () => { | ||
| try { | ||
| const emailInput = document.getElementById( 'email' ); | ||
|
|
||
| if ( emailInput?.value ) { | ||
| const lookupResult = | ||
| await fastlaneSdk.identity.lookupCustomerByEmail( | ||
| emailInput.value | ||
| ); | ||
|
|
||
| wp.data.dispatch( STORE_NAME ).setIsEmailSubmitted( true ); | ||
|
|
||
| if ( lookupResult?.customerContextId ) { | ||
| const customerContextId = | ||
| lookupResult.customerContextId; | ||
|
|
||
| const authenticatedCustomerResult = | ||
| await fastlaneSdk.identity.triggerAuthenticationFlow( | ||
| customerContextId | ||
| ); | ||
|
|
||
| if ( | ||
| authenticatedCustomerResult?.authenticationState === | ||
| 'succeeded' | ||
| ) { | ||
| const { profileData } = authenticatedCustomerResult; | ||
| setIsGuest( false ); | ||
|
|
||
| if ( profileData?.shippingAddress ) { | ||
| setShippingAddress( | ||
| profileData.shippingAddress | ||
| ); | ||
| } | ||
|
|
||
| if ( profileData?.card ) { | ||
| setCardDetails( profileData.card ); | ||
| } | ||
|
|
||
| setIsEmailLookupCompleted( true ); | ||
| } | ||
| } | ||
| } | ||
| } catch ( error ) { | ||
| log( 'Failed to restore Fastlane session', 'warn' ); | ||
| } | ||
| }; | ||
|
|
||
| restoreSession(); | ||
| }, [ fastlaneSdk, setShippingAddress, setCardDetails, setIsGuest ] ); | ||
| }; | ||
|
|
||
| export default useSessionRestoration; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.