@revolut/checkout
Version:
RevolutCheckout.js as npm module
35 lines (34 loc) • 1.27 kB
JavaScript
import { MODE, URLS } from './constants';
import { getVersionedUrl, loadScript } from './utils';
var loadedVersion = null;
var pendingTimestamp = null;
export function RevolutPaymentsVersionLoader(mode) {
if (mode === void 0) { mode = RevolutPaymentsVersionLoader.mode; }
if (typeof loadedVersion === 'string') {
return Promise.resolve(loadedVersion);
}
pendingTimestamp = pendingTimestamp !== null && pendingTimestamp !== void 0 ? pendingTimestamp : Date.now();
return loadScript({
src: getVersionedUrl(URLS[mode].version, "" + pendingTimestamp),
id: 'revolut-pay-version',
name: 'RevolutPayVersion',
})
.then(function () {
pendingTimestamp = null;
if (typeof loadedVersion !== 'string' || !loadedVersion) {
loadedVersion =
'__REV_PAY_VERSION__' in window &&
typeof __REV_PAY_VERSION__ === 'string'
? __REV_PAY_VERSION__
: '';
delete window.__REV_PAY_VERSION__;
}
return loadedVersion;
})
.catch(function () {
pendingTimestamp = null;
loadedVersion = '';
return loadedVersion;
});
}
RevolutPaymentsVersionLoader.mode = MODE.PRODUCTION;