Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 }) : 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;
});
}
}).then(orderID => {
getLogger()
.info('button_approve')
.track({
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.CHECKOUT_AUTHORIZE,
[FPTI_KEY.TOKEN]: orderID
}).flush();
const data = { orderID, payerID, paymentID, billingToken, subscriptionID, facilitatorAccessToken };
const actions = buildXApproveActions({ orderID, paymentID, payerID, intent, restart, subscriptionID, facilitatorAccessToken, buyerAccessToken, partnerAttributionID, forceRestAPI });
return onApprove(data, actions).catch(err => {
return ZalgoPromise.try(() => {
return onError(err);
}).then(() => {
throw err;
});
});
});
});
return createOrder().then(orderID => {
getLogger()
.info('button_shipping_change')
.track({
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.CHECKOUT_SHIPPING_CHANGE,
[FPTI_KEY.TOKEN]: orderID
}).flush();
return onShippingChange(buildXOnShippingChangeData(data), buildXShippingChangeActions({ orderID, facilitatorAccessToken, buyerAccessToken, actions, partnerAttributionID }));
});
};
}).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;
});
}
return createOrder().then(orderID => {
getLogger()
.info('button_cancel')
.track({
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.CHECKOUT_CANCEL,
[FPTI_KEY.TOKEN]: orderID
}).flush();
return onCancel(buildXOnCancelData({ orderID }), buildXOnCancelActions());
}).catch(err => {
return onError(err);
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 => {
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;
});
}