Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* @flow */

export * from "./overlay";
82 changes: 82 additions & 0 deletions src/ui/overlay/paypal-on-approve-processing-overlay/overlay.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* @flow */
/** @jsx node */

import { animate, noop } 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 "../paypal-app-switch/style";

type OverlayProps = {|
buttonSessionID: string,
close: () => ZalgoPromise<void>,
focus: () => ZalgoPromise<void>,
|};

export function PayPalOnApproveOverlay({
buttonSessionID,
}: OverlayProps): ElementNode {
const uid = `paypal-onapprove-overlay-${buttonSessionID}`;
const overlayIframeName = `__paypal_checkout_sandbox_${uid}__`;
const nonce = "";
function closeOverlay(e) {
e.preventDefault();
e.stopPropagation();
const overlay = document.getElementsByName(uid)?.[0];

animate(overlay, "hide-container", noop);

if (overlay) {
// the delay is to allow the animation time to run
setTimeout(() => {
overlay.remove();
}, 300);
}
}

const setupShowAnimation = () => (el) => {
animate(el, "show-container", noop);
};

return (
<div
id={uid}
name={uid}
onRender={setupShowAnimation()}
class="paypal-checkout-sandbox"
>
<style nonce={nonce}>{getSandboxStyle({ uid })}</style>
<iframe
title="PayPal Checkout On Approve Overlay"
name={overlayIframeName}
scrolling="no"
class="paypal-checkout-sandbox-iframe"
>
<html>
<body>
<div
dir="auto"
id={uid}
class="paypal-overlay-context-popup paypal-checkout-overlay"
>
<a
href="#"
class="paypal-checkout-close"
onClick={closeOverlay}
aria-label="close"
role="button"
/>
<div class="paypal-checkout-modal">
<div class="paypal-checkout-logo" dir="ltr">
<PayPalRebrandLogo logoColor={LOGO_COLOR.WHITE} />
</div>
</div>
<style nonce={nonce}>{getContainerStyle({ uid })}</style>
</div>
</body>
</html>
</iframe>
</div>
);
}
33 changes: 33 additions & 0 deletions src/zoid/buttons/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

import { containerTemplate } from "./container";
import { PrerenderedButtons } from "./prerender";
import {

Check failure on line 97 in src/zoid/buttons/component.jsx

View workflow job for this annotation

GitHub Actions / main

There should be at least one empty line between import groups
applePaySession,
determineFlow,
isSupportedNativeBrowser,
Expand All @@ -105,6 +105,7 @@
sendPostRobotMessageToButtonIframe,
isEagerOrderCreationEnabled,
} from "./util";
import { PayPalOnApproveOverlay } from "../../ui/overlay/paypal-on-approve-processing-overlay";

Check failure on line 108 in src/zoid/buttons/component.jsx

View workflow job for this annotation

GitHub Actions / main

`../../ui/overlay/paypal-on-approve-processing-overlay` import should occur before import of `./container`

export type ButtonsComponent = ZoidComponent<
ButtonProps,
Expand Down Expand Up @@ -348,6 +349,38 @@
},
},

showOnApproveOverlay: {
type: "function",
queryParam: false,
value:
({ props: { buttonSessionID } }) =>
() => {
const overlay = (
<PayPalOnApproveOverlay
buttonSessionID={buttonSessionID}
/>
).render(dom({ doc: document }));

document.body?.appendChild(overlay);
},
},

hideOnApproveOverlay: {
type: "function",
queryParam: false,
value:
({ props: { buttonSessionID } }) =>
() => {
const overlay = document.getElementsByName(
`paypal-onapprove-overlay-${buttonSessionID}`
)?.[0];

if (overlay) {
overlay.remove();
}
},
},

redirect: {
type: "function",
sendToChild: true,
Expand Down
Loading