Skip to content

Commit 3d9589d

Browse files
authored
fixed bug that would not allow customers using firefox to be redirect to WooPay (#5112)
1 parent 74790b4 commit 3d9589d

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Fixed bug that would not allow customers using firefox to log in to WooPay sometimes

client/checkout/platform-checkout/email-input-iframe.js

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ export const handlePlatformCheckoutEmailInput = async (
9393
// Maybe we could make this a configurable option defined in PHP so it could be filtered by merchants.
9494
const fullScreenModalBreakpoint = 768;
9595

96+
//Checks if customer has clicked the back button to prevent auto redirect
97+
const searchParams = new URLSearchParams( window.location.search );
98+
const customerClickedBackButton =
99+
( 'undefined' !== typeof performance &&
100+
'back_forward' ===
101+
performance.getEntriesByType( 'navigation' )[ 0 ].type ) ||
102+
'true' === searchParams.get( 'skip_platform_checkout' );
103+
96104
// Track the current state of the header. This default
97105
// value should match the default state on the platform.
98106
let iframeHeaderValue = true;
@@ -485,48 +493,12 @@ export const handlePlatformCheckoutEmailInput = async (
485493
}, 15000 );
486494
};
487495

488-
// Prevent show platform checkout iframe if the page comes from
489-
// the back button on platform checkout itself.
490-
window.addEventListener( 'pageshow', function ( event ) {
491-
// Detect browser back button.
492-
const historyTraversal =
493-
event.persisted ||
494-
( 'undefined' !== typeof performance &&
495-
'back_forward' ===
496-
performance.getEntriesByType( 'navigation' )[ 0 ].type );
497-
498-
const searchParams = new URLSearchParams( window.location.search );
499-
500-
if (
501-
! historyTraversal &&
502-
'true' !== searchParams.get( 'skip_platform_checkout' )
503-
) {
504-
// Check if user already has a WooPay login session.
505-
if ( ! hasCheckedLoginSession ) {
496+
platformCheckoutEmailInput.addEventListener( 'input', ( e ) => {
497+
if ( ! hasCheckedLoginSession && ! customerClickedBackButton ) {
498+
if ( customerClickedBackButton ) {
506499
openLoginSessionIframe( platformCheckoutEmailInput.value );
507500
}
508-
} else {
509-
wcpayTracks.recordUserEvent(
510-
wcpayTracks.events.PLATFORM_CHECKOUT_SKIPPED
511-
);
512-
513-
searchParams.delete( 'skip_platform_checkout' );
514-
515-
let { pathname } = window.location;
516-
517-
if ( '' !== searchParams.toString() ) {
518-
pathname += '?' + searchParams.toString();
519-
}
520-
521-
history.replaceState( null, null, pathname );
522-
523-
// Safari needs to close iframe with this.
524-
closeIframe( false );
525-
}
526-
} );
527501

528-
platformCheckoutEmailInput.addEventListener( 'input', ( e ) => {
529-
if ( ! hasCheckedLoginSession ) {
530502
return;
531503
}
532504

@@ -631,4 +603,28 @@ export const handlePlatformCheckoutEmailInput = async (
631603
// do nothing, only respond to expected actions.
632604
}
633605
} );
606+
607+
if ( ! customerClickedBackButton ) {
608+
// Check if user already has a WooPay login session.
609+
if ( ! hasCheckedLoginSession ) {
610+
openLoginSessionIframe( platformCheckoutEmailInput.value );
611+
}
612+
} else {
613+
wcpayTracks.recordUserEvent(
614+
wcpayTracks.events.PLATFORM_CHECKOUT_SKIPPED
615+
);
616+
617+
searchParams.delete( 'skip_platform_checkout' );
618+
619+
let { pathname } = window.location;
620+
621+
if ( '' !== searchParams.toString() ) {
622+
pathname += '?' + searchParams.toString();
623+
}
624+
625+
history.replaceState( null, null, pathname );
626+
627+
// Safari needs to close iframe with this.
628+
closeIframe( false );
629+
}
634630
};

0 commit comments

Comments
 (0)