Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const connectNative = () : NativeConnection => {
const socket = nativeSocket;
if (!socket) {
throw new Error(`Native socket connection not established`);
}
const setNativeProps = once(() => {
return getSDKProps().then(sdkProps => {
getLogger().info(`native_message_setprops`).flush();
return socket.send(SOCKET_MESSAGE.SET_PROPS, sdkProps);
}).then(() => {
getLogger().info(`native_response_setprops`).track({
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.NATIVE_APP_SWITCH_ACK
}).flush();
});
});
const closeNative = once(() => {
getLogger().info(`native_message_close`).flush();
return socket.send(SOCKET_MESSAGE.CLOSE).then(() => {
getLogger().info(`native_response_close`).flush();
return close();
});
function normalizeCheckoutProps(props : Object) : { env : string, payment : Function, onAuthorize : Function, onCancel : Function } {
let payment = props.payment;
let onAuthorize = once(props.onAuthorize);
let onCancel = once(props.onCancel || noop);
return { env: config.env, payment, onAuthorize, onCancel };
}
watchForUnload() {
const unloadWindowListener = addEventListener(window, 'unload', once(() => {
this.component.log(`navigate_away`);
this.destroy(new Error(`Window navigated away`));
}));
this.clean.register(unloadWindowListener.cancel);
}
if (useDirectAppSwitch()) {
popupWin = attemptPopupAppSwitch(nativeUrl);
} else {
popupWin = openBlankPopup();
}
clean.register(() => {
if (popupWin && !isWindowClosed(popupWin)) {
popupWin.close();
}
});
return popupWin;
};
const detectAppSwitch = once(() => {
getLogger().info(`native_detect_app_switch`).track({
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.NATIVE_DETECT_APP_SWITCH
}).flush();
return connectNative().setProps();
});
const detectWebSwitch = once((fallbackWin : ?CrossDomainWindowType) => {
getLogger().info(`native_detect_web_switch`).track({
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.NATIVE_DETECT_WEB_SWITCH
}).flush();
return fallbackToWebCheckout(fallbackWin);
});
const initDirectAppSwitch = (popupWin : ?CrossDomainWindowType) => {
var listenerOptions = {
handler: options.handler,
handleError: options.errorHandler || function (err) {
throw err;
},
window: win,
domain: domain || WILDCARD,
name: name
};
var requestListener = addRequestListener({ name: name, win: win, domain: domain }, listenerOptions);
if (options.once) {
var _handler = listenerOptions.handler;
listenerOptions.handler = onceFunction(function listenOnce() {
requestListener.cancel();
return _handler.apply(this, arguments);
});
}
if (listenerOptions.window && options.errorOnClose) {
var interval = safeInterval(function () {
if (win && (typeof win === 'undefined' ? 'undefined' : _typeof(win)) === 'object' && isWindowClosed(win)) {
interval.cancel();
listenerOptions.handleError(new Error('Post message target window is closed'));
}
}, 50);
}
return {
cancel: function cancel() {
ParentComponent.prototype.watchForUnload = function watchForUnload() {
var _this13 = this;
var unloadWindowListener = addEventListener(window, 'unload', once(function () {
_this13.component.log('navigate_away');
_this13.destroy();
}));
this.clean.register('destroyUnloadWindowListener', unloadWindowListener.cancel);
};
watchForUnload() {
let unloadWindowListener = addEventListener(window, 'unload', once(() => {
this.component.log(`navigate_away`);
this.destroy();
}));
this.clean.register('destroyUnloadWindowListener', unloadWindowListener.cancel);
}
}
const userAgent = window.navigator.userAgent;
if (userAgent && eligibilityResults.hasOwnProperty(userAgent)) {
return eligibilityResults[userAgent];
}
const result = isBrowserEligible();
eligibilityResults[userAgent] = result;
return result;
}
export const checkRecognizedBrowser = once((state : string) => {
const { browser } = getBrowser();
if (!browser) {
const { name, version, mobile, android, ios } = getBowser();
const logger = getLogger();
logger.info(`unrecognized_browser_${ state }`, { name, version, mobile, android, ios });
logger.flush();
}
});
let approved = false;
const onApprove = ({ orderID, payerID, paymentID, billingToken }) => {
approved = true;
const actions = {
restart,
...buildApproveActions(orderID, fundingSource, restart)
};
return window.xprops.onApprove({ orderID, payerID, paymentID, billingToken }, actions).catch(err => {
return window.xprops.onError(err);
});
};
const onCancel = once(() => {
return ZalgoPromise.try(() => {
if (approved) {
return false;
}
return validationPromise;
}).then(valid => {
if (!valid) {
return;
}
return createOrder().then(orderID => {
return window.xprops.onCancel({ orderID });
}).catch(err => {