Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* @flow */
import { getLogger } from 'paypal-braintree-web-client/src';
import { getParent, getTop } from 'cross-domain-utils/src';
import { patchMethod } from 'belter/src';
import { Checkout } from '../checkout';
const parent = getParent(window);
const top = getTop(window);
if (top && parent) {
let canRenderTop = (top === parent);
if (!canRenderTop) {
Checkout.canRenderTo(top).then(result => {
canRenderTop = result;
});
patchMethod(Checkout, 'renderTo', ({ args: [ win, props, el ], original, context }) => {
if (!canRenderTop) {
win = getParent(window);
}
return original.call(context, win, props, el);
checkout.openContainer().then(() => {
checkout.event.triggerOnce(CONSTANTS.EVENTS.CLOSE);
checkout.showContainer();
});
// $FlowFixMe
Button.xprops.payment().then(token => {
window.top.location = extendUrl(config.checkoutUrl, { token });
}).catch(err => {
checkout.error(err);
});
};
}
const parent = getParent(window);
const top = getTop(window);
if (top && parent) {
let canRenderTop = (top === parent);
if (!canRenderTop) {
Checkout.canRenderTo(top).then(result => {
canRenderTop = result;
});
patchMethod(Checkout, 'renderTo', ({ args: [ win, props, el ], original, context }) => {
if (!canRenderTop) {
win = getParent(window);
}
return original.call(context, win, props, el);
ChildComponent.prototype.getWindowByRef = function getWindowByRef(ref) {
var type = ref.type;
var result = void 0;
if (type === WINDOW_REFERENCES.OPENER) {
result = getOpener(window);
} else if (type === WINDOW_REFERENCES.TOP) {
result = getTop(window);
} else if (type === WINDOW_REFERENCES.PARENT) {
// $FlowFixMe
var distance = ref.distance;
if (distance) {
result = getNthParentFromTop(window, distance);
} else {
result = getParent(window);
}
}
if (type === WINDOW_REFERENCES.GLOBAL) {
// $FlowFixMe
var uid = ref.uid;
function setupCheckout({ components } : { components : Components }) : ZalgoPromise {
const { Checkout } = components;
checkoutOpen = false;
const [ parent, top ] = [ getParent(window), getTop(window) ];
const tasks = {};
if (top && parent && parent !== top) {
tasks.canRenderTo = Checkout.canRenderTo(top).then(result => {
canRenderTop = result;
});
}
return ZalgoPromise.hash(tasks).then(noop);
}
function getRenderWindow() : Object {
const top = getTop(window);
if (canRenderTop && top) {
return top;
} else if (getParent()) {
return getParent();
} else {
return window;
}
}
function getRenderWindow() : Object {
const top = getTop(window);
if (canRenderTop && top) {
return top;
} else {
return window.xprops.getParent();
}
}
export function setupCheckout() : ZalgoPromise {
checkoutOpen = false;
const [ parent, top ] = [ getParent(window), getTop(window) ];
const tasks = {};
if (top && parent && parent !== top) {
tasks.canRenderTo = window.paypal.Checkout.canRenderTo(top).then(result => {
canRenderTop = result;
});
}
return ZalgoPromise.hash(tasks).then(noop);
}