-
Notifications
You must be signed in to change notification settings - Fork 576
Add PayPal App Switch Overlay #2484
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
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfc0bc2
add overlay foldeers
nikrom17 dfa93b3
add app switch overlay
nikrom17 8be1c03
remove logs and unused vars
nikrom17 db1adf3
remove unneeded overlay styles and add remove animation
nikrom17 d5b1759
add tests
nikrom17 33a1246
fix lint errors
nikrom17 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 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
This file contains 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
File renamed without changes.
This file contains 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,150 @@ | ||
/* @flow */ | ||
/** @jsx node */ | ||
|
||
import { | ||
isIos, | ||
isIpadOs, | ||
isFirefox, | ||
animate, | ||
noop, | ||
supportsPopups, | ||
} from "@krakenjs/belter/src"; | ||
import { node, type ElementNode } from "@krakenjs/jsx-pragmatic/src"; | ||
import { LOGO_COLOR, PayPalRebrandLogo } from "@paypal/sdk-logos/src"; | ||
import { type ZalgoPromise } from "@krakenjs/zalgo-promise/src"; | ||
|
||
import { getContainerStyle, getSandboxStyle } from "./style"; | ||
|
||
type OverlayProps = {| | ||
buttonSessionID: string, | ||
close: () => ZalgoPromise<void>, | ||
focus: () => ZalgoPromise<void>, | ||
|}; | ||
|
||
export function PayPalAppSwitchOverlay({ | ||
close, | ||
focus, | ||
buttonSessionID, | ||
}: OverlayProps): ElementNode { | ||
const uid = `paypal-overlay-${buttonSessionID}`; | ||
const overlayIframeName = `__paypal_checkout_sandbox_${uid}__`; | ||
|
||
function closeCheckout(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
close(); | ||
// const body = document.getElementsByTagName("body")?.[0]; | ||
const overlay = document.getElementsByName(uid)?.[0]; | ||
|
||
if (overlay) { | ||
overlay.remove(); | ||
} | ||
} | ||
|
||
function displayFocusWarning() { | ||
const overlayIframe: ?HTMLIFrameElement = | ||
// $FlowFixMe | ||
document.getElementsByName(overlayIframeName)?.[0]; | ||
const iframeDocument = overlayIframe?.contentWindow.document; | ||
const warningElement = iframeDocument?.getElementsByClassName( | ||
"paypal-checkout-focus-warning" | ||
)?.[0]; | ||
|
||
if (!warningElement) { | ||
return; | ||
} | ||
warningElement.innerText = `Still can't see it? Select "Window" in your toolbar to find "Log in to your PayPal account"`; | ||
} | ||
|
||
function focusCheckout(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
if (!supportsPopups()) { | ||
return; | ||
} | ||
|
||
if (isIos() || isIpadOs()) { | ||
// Note: alerts block the event loop until they are closed. | ||
// eslint-disable-next-line no-alert | ||
window.alert("Please switch tabs to reactivate the PayPal window"); | ||
} else if (isFirefox()) { | ||
displayFocusWarning(); | ||
} | ||
focus(); | ||
} | ||
|
||
const setupAnimations = (name) => { | ||
return (el) => { | ||
animate(el, `show-${name}`, noop); | ||
}; | ||
}; | ||
|
||
const nonce = ""; | ||
const context = "popup"; | ||
const content = { | ||
windowMessage: "To finish, go back to the PayPal app.", | ||
continueMessage: "Return to PayPal", | ||
}; | ||
|
||
return ( | ||
<div | ||
id={uid} | ||
name={uid} | ||
onRender={setupAnimations("container")} | ||
class="paypal-checkout-sandbox" | ||
> | ||
<style nonce={nonce}>{getSandboxStyle({ uid })}</style> | ||
<iframe | ||
title="PayPal Checkout Overlay" | ||
name={overlayIframeName} | ||
scrolling="no" | ||
class="paypal-checkout-sandbox-iframe" | ||
> | ||
<html> | ||
<body> | ||
<div | ||
dir="auto" | ||
id={uid} | ||
onClick={focusCheckout} | ||
class={`paypal-overlay-context-${context} paypal-checkout-overlay`} | ||
> | ||
<a | ||
href="#" | ||
class="paypal-checkout-close" | ||
onClick={closeCheckout} | ||
aria-label="close" | ||
role="button" | ||
/> | ||
<div class="paypal-checkout-modal"> | ||
<div class="paypal-checkout-logo" dir="ltr"> | ||
<PayPalRebrandLogo logoColor={LOGO_COLOR.WHITE} /> | ||
</div> | ||
{content.windowMessage && ( | ||
<div class="paypal-checkout-message"> | ||
{content.windowMessage} | ||
</div> | ||
)} | ||
<div class="paypal-checkout-focus-warning" /> | ||
{content.continueMessage && ( | ||
<div class="paypal-checkout-continue"> | ||
{/* This handler should be guarded with e.stopPropagation. | ||
This will stop the event from bubbling up to the overlay click handler | ||
and causing unexpected behavior. */} | ||
<a onClick={focusCheckout} href="#"> | ||
{content.continueMessage} | ||
</a> | ||
</div> | ||
)} | ||
<div class="paypal-checkout-loader"> | ||
<div class="paypal-spinner" /> | ||
</div> | ||
</div> | ||
<style nonce={nonce}>{getContainerStyle({ uid })}</style> | ||
</div> | ||
</body> | ||
</html> | ||
</iframe> | ||
</div> | ||
); | ||
} |
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.
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.
we also need to accept the universal link to render the continue link to app.
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.
I've added that logic in the focus function in
setupOverlays
I can update the focus function to take the args
props.redirect
&url.href
and callprops.redirect(url.href)
from inside the overlay componentThere 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.
https://github.paypal.com/Checkout-R/smartcomponentnodeweb/pull/930/files#diff-5706d68d378768a97412d3ee5d456d81d91fee49a759dd73ce9d6fef2da324e3R322
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.
@ravishekhar , I attempted a solution that took the url as an argument and ran into issues running the karma tests with the redirect call now being a part of
overlay.jsx
With the Karma framework, there is no way to mock
location.href
orlocation.redirect
. When the redirect is called, the karma test runner is interrupted and the tests fail.