@@ -93,6 +93,14 @@ export const handlePlatformCheckoutEmailInput = async (
93
93
// Maybe we could make this a configurable option defined in PHP so it could be filtered by merchants.
94
94
const fullScreenModalBreakpoint = 768 ;
95
95
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
+
96
104
// Track the current state of the header. This default
97
105
// value should match the default state on the platform.
98
106
let iframeHeaderValue = true ;
@@ -485,48 +493,12 @@ export const handlePlatformCheckoutEmailInput = async (
485
493
} , 15000 ) ;
486
494
} ;
487
495
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 ) {
506
499
openLoginSessionIframe ( platformCheckoutEmailInput . value ) ;
507
500
}
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
- } ) ;
527
501
528
- platformCheckoutEmailInput . addEventListener ( 'input' , ( e ) => {
529
- if ( ! hasCheckedLoginSession ) {
530
502
return ;
531
503
}
532
504
@@ -631,4 +603,28 @@ export const handlePlatformCheckoutEmailInput = async (
631
603
// do nothing, only respond to expected actions.
632
604
}
633
605
} ) ;
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
+ }
634
630
} ;
0 commit comments