Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return orderIdFunction().then((orderId) => {
logger.track({
[ FPTI_KEY.STATE ]: 'CARD_PAYMENT_FORM',
[ FPTI_KEY.TRANSITION ]: 'process_receive_order',
hosted_payment_session_id,
[ FPTI_KEY.CONTEXT_TYPE ]: 'Cart-ID',
[ FPTI_KEY.CONTEXT_ID ]: orderId
});
logger.flush();
return hostedFieldsInstance.tokenize({
...options,
orderId
}).catch((err) => {
if (!(err.details && err.details.find && err.details.find(detail => detail.issue === 'CONTINGENCY'))) {
return ZalgoPromise.reject(err);
}
const url = `${ err.links.find(link => link.rel === '3ds-contingency-resolution').href }`;
return contingencyFlow.start(url);
}).then((payload) => {
// does contingency flow give a payload?
logger.track({
}).then(({ body }) : string => {
if (!body || !body.id) {
throw new Error(`Order Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
}
getLogger().track({
[FPTI_KEY.STATE]: fptiState,
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.CREATE_ORDER,
[FPTI_KEY.CONTEXT_TYPE]: FPTI_CONTEXT_TYPE.ORDER_ID,
[FPTI_KEY.TOKEN]: body.id,
[FPTI_KEY.CONTEXT_ID]: body.id
});
return body.id;
});
}
getLogger().addTrackingBuilder(() => {
const orderID = getOrderID();
const buttonSessionID = getButtonSessionID();
return {
[FPTI_KEY.CONTEXT_TYPE]: orderID ? FPTI_CONTEXT_TYPE.ORDER_ID : FPTI_CONTEXT_TYPE.BUTTON_SESSION_ID,
[FPTI_KEY.CONTEXT_ID]: orderID ? orderID : buttonSessionID,
[FPTI_KEY.BUTTON_SESSION_UID]: buttonSessionID,
[FPTI_KEY.TOKEN]: orderID,
[FPTI_KEY.REFERER]: getRefererDomain()
};
});
}
}).then(body => {
const paymentID = body && body.id;
if (!paymentID) {
throw new Error(`Payment Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
}
getLogger().track({
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.CREATE_PAYMENT,
[FPTI_KEY.CONTEXT_TYPE]: FPTI_CONTEXT_TYPE.PAYMENT_ID,
[FPTI_KEY.TOKEN]: paymentID,
[FPTI_KEY.CONTEXT_ID]: paymentID
});
return body;
});
}
}).then(orderID => {
if (!orderID || typeof orderID !== 'string') {
throw new Error(`Expected an order id to be passed`);
}
if (orderID.indexOf('PAY-') === 0 || orderID.indexOf('PAYID-') === 0) {
throw new Error(`Do not pass PAY-XXX or PAYID-XXX directly into createOrder. Pass the EC-XXX token instead`);
}
const duration = Date.now() - startTime;
getLogger().track({
[FPTI_KEY.STATE]: FPTI_STATE.BUTTON,
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.RECEIVE_ORDER,
[FPTI_KEY.CONTEXT_TYPE]: FPTI_CONTEXT_TYPE.ORDER_ID,
[FPTI_KEY.CONTEXT_ID]: orderID,
[FPTI_KEY.TOKEN]: orderID,
[FPTI_KEY.BUTTON_SESSION_UID]: buttonSessionID,
[FPTI_KEY.RESPONSE_DURATION]: duration.toString()
}).flush();
return orderID;
});
});
}).then((body) : string => {
const orderID = body && body.id;
if (!orderID) {
throw new Error(`Order Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
}
getLogger().track({
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.CREATE_ORDER,
[FPTI_KEY.CONTEXT_TYPE]: FPTI_CONTEXT_TYPE.ORDER_ID,
[FPTI_KEY.TOKEN]: orderID,
[FPTI_KEY.CONTEXT_ID]: orderID
});
return orderID;
});
}
logger.addTrackingBuilder(() => {
const { lang, country } = locale;
return {
[FPTI_KEY.STATE]: FPTI_STATE.BUTTON,
[FPTI_KEY.CONTEXT_TYPE]: FPTI_CONTEXT_TYPE.BUTTON_SESSION_ID,
[FPTI_KEY.CONTEXT_ID]: buttonSessionID,
[FPTI_KEY.STATE]: FPTI_STATE.BUTTON,
[FPTI_KEY.FEED]: FPTI_FEED.PAYMENTS_SDK,
[FPTI_KEY.DATA_SOURCE]: FPTI_DATA_SOURCE.PAYMENTS_SDK,
[FPTI_KEY.CLIENT_ID]: clientID,
[FPTI_KEY.SELLER_ID]: merchantID[0],
[FPTI_KEY.BUTTON_SESSION_UID]: buttonSessionID,
[FPTI_KEY.SESSION_UID]: sessionID,
[FPTI_KEY.REFERER]: window.location.host,
[FPTI_KEY.MERCHANT_DOMAIN]: merchantDomain,
[FPTI_KEY.LOCALE]: `${ lang }_${ country }`,
[FPTI_KEY.INTEGRATION_IDENTIFIER]: clientID,
[FPTI_KEY.PARTNER_ATTRIBUTION_ID]: partnerAttributionID,
[FPTI_KEY.SDK_NAME]: FPTI_SDK_NAME.PAYMENTS_SDK,
[FPTI_KEY.SDK_VERSION]: version,
[FPTI_KEY.USER_AGENT]: window.navigator && window.navigator.userAgent,
[FPTI_KEY.USER_ACTION]: commit ? FPTI_USER_ACTION.COMMIT : FPTI_USER_ACTION.CONTINUE,
return (...args) => {
if (props.locale && props.locale.lang === 'en' && props.locale.country === 'US') {
const isBlackButtonEnabled = state.cardButtonExperiment.isEnabled();
state.cardButtonExperiment.logStart({
[ FPTI_KEY.CONTEXT_ID ]: props.buttonSessionID,
[ FPTI_KEY.CONTEXT_TYPE ]: FPTI_KEY.BUTTON_SESSION_UID,
[ FPTI_KEY.EXPERIMENT_NAME ]: 'inline_blk_btn',
[ FPTI_KEY.TREATMENT_NAME ]: isBlackButtonEnabled ? 'inline_blk_btn_test' : 'inline_blk_btn_control'
});
}
if (value) {
return value(...args);
}
};
}