Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).catch((err) => {
if (options.onError) {
options.onError(err);
}
});
});
}
hosted_payment_session_id = uniqueID();
logger.track({
comp: 'hostedpayment',
// risk_correlation_id: 'TODO',
api_integration_type: 'PAYPALSDK',
product_identifier: 'PAYPAL_FOR_MARKETPLACES',
[FPTI_KEY.STATE]: 'CARD_PAYMENT_FORM',
[FPTI_KEY.TRANSITION]: 'collect_card_info',
hosted_payment_textboxes_shown: Object.keys(hostedFieldsCreateOptions.fields).join(':'),
hosted_payment_session_cre_dt: (new Date()).toString(),
hosted_payment_session_cre_ts_epoch: Date.now().toString(),
[ FPTI_KEY.CONTEXT_TYPE ]: 'hosted_session_id',
[ FPTI_KEY.CONTEXT_ID ]: hosted_payment_session_id
});
logger.flush();
return hostedFieldsInstance;
});
}
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,
}).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;
});
});
getPageRenderTime().then(pageRenderTime => {
const logger = getLogger();
const fundingSources = Array.prototype.slice.call(document.querySelectorAll(`[${ ATTRIBUTE.FUNDING_SOURCE }]`)).map(el => {
return el.getAttribute(ATTRIBUTE.CARD) || el.getAttribute(ATTRIBUTE.FUNDING_SOURCE);
}).filter(source => {
return source && source !== FUNDING.CARD;
});
let layout = BUTTON_LAYOUT.HORIZONTAL;
if (xprops.style && xprops.style.layout) {
layout = xprops.style.layout;
}
logger.track({
[FPTI_KEY.STATE]: FPTI_STATE.BUTTON,
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.BUTTON_LOAD,
[FPTI_KEY.BUTTON_TYPE]: FPTI_BUTTON_TYPE.IFRAME,
[FPTI_KEY.FUNDING_LIST]: fundingSources.join(':'),
[FPTI_KEY.FUNDING_COUNT]: fundingSources.length.toString(),
[FPTI_KEY.PAGE_LOAD_TIME]: pageRenderTime ? pageRenderTime.toString() : '',
[FPTI_KEY.BUTTON_LAYOUT]: layout
});
logger.flush();
});
}).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;
});
}
logTreatment({ treatment, payload }) {
logger.track({
[FPTI_KEY.STATE]: FPTI_STATE.PXP,
[FPTI_KEY.TRANSITION]: FPTI_TRANSITION.PXP,
[FPTI_KEY.EXPERIMENT_NAME]: name,
[FPTI_KEY.TREATMENT_NAME]: treatment,
...payload
});
logger.flush();
},