Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return body.id;
}
throw new Error(`Order Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
});
}
const PROXY_REST = `proxy_rest`;
const parentWin = getAncestor();
on(PROXY_REST, { domain: getPayPalDomain() }, ({ data }) => {
proxyRest = data;
});
if (parentWin && isPayPalDomain() && !isSameDomain(parentWin)) {
send(parentWin, PROXY_REST, { createAccessToken, createOrder })
.catch(() => {
// pass
});
}
onApprove() {
send(window.top.frames[0], 'onApprove');
},
onShippingChange() {
send(window.top.frames[0], 'onShippingChange');
}
delegate(context : $Values, target : CrossDomainWindowType) {
this.component.log(`delegate`);
const props = {};
for (const propName of this.component.getPropNames()) {
if (this.component.getPropDefinition(propName).allowDelegate) {
props[propName] = this.props[propName];
}
}
const overridesPromise = send(target, `${ POST_MESSAGE.DELEGATE }_${ this.component.name }`, {
context,
props,
overrides: {
event: this.event,
close: () => this.close(),
onError: (err) => this.onError(err)
}
}).then(({ data }) => {
this.clean.register(data.destroy);
return data.overrides;
}).catch(err => {
throw new Error(`Unable to delegate rendering. Possibly the component is not loaded in the target window.\n\n${ stringifyError(err) }`);
});
Component.prototype.canRenderTo = function canRenderTo(win) {
return send(win, POST_MESSAGE.ALLOW_DELEGATE + '_' + this.name).then(function (_ref3) {
var data = _ref3.data;
return data;
})['catch'](function () {
return false;
});
};
delegate(context : $Values, target : CrossDomainWindowType) {
this.component.log(`delegate`);
let props = {};
for (let propName of this.component.getPropNames()) {
if (this.component.getProp(propName).allowDelegate) {
props[propName] = this.props[propName];
}
}
let delegate = send(target, `${ POST_MESSAGE.DELEGATE }_${ this.component.name }`, {
context,
props,
overrides: {
userClose: () => this.userClose(),
error: (err) => this.error(err),
on: (eventName, handler) => this.on(eventName, handler)
}
}).then(({ data }) => {
this.clean.register(data.destroy);
return data;
}).catch(err => {
throw new Error(`Unable to delegate rendering. Possibly the component is not loaded in the target window.\n\n${ stringifyError(err) }`);
});
canRenderTo(win : CrossDomainWindowType) : ZalgoPromise {
return send(win, `${ POST_MESSAGE.ALLOW_DELEGATE }_${ this.name }`).then(({ data }) => {
return data;
}).catch(() => {
return false;
});
}
canRenderTo(win : CrossDomainWindowType) : ZalgoPromise {
return send(win, `${ POST_MESSAGE.ALLOW_DELEGATE }_${ this.name }`).then(({ data }) => {
return data;
}).catch(() => {
return false;
});
}
export function proxyMethod(name : string, win : ?CrossDomainWindowType, originalMethod : Function) : Function {
if (win && getDomain() === getPayPalDomain() && !isSameDomain(win)) {
if (win) {
send(win, `proxy_${ name }`, { originalMethod }).catch(noop);
}
return originalMethod;
}
let methods = [];
on(`proxy_${ name }`, { domain: getPayPalDomain() }, ({ data }) => {
methods.push(data.originalMethod);
});
return function postMessageProxy() : mixed {
methods = methods.filter(method => !isWindowClosed(method.source));
if (methods.length) {