@zonos/elements 1.0.16 → 1.0.17-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{cart-e27fd17c.js → cart-108bc407.js} +8 -1
- package/dist/cjs/cart-108bc407.js.map +1 -0
- package/dist/cjs/zonos-address_2.cjs.entry.js +1 -1
- package/dist/cjs/zonos-banner_2.cjs.entry.js +1 -1
- package/dist/cjs/zonos-cart-items_10.cjs.entry.js +5 -3
- package/dist/cjs/zonos-cart-items_10.cjs.entry.js.map +1 -1
- package/dist/cjs/zonos-checkout.cjs.entry.js +6 -2
- package/dist/cjs/zonos-checkout.cjs.entry.js.map +1 -1
- package/dist/cjs/zonos-controller.cjs.entry.js +1 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.js +3 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-cart-items/zonos-cart-items.js.map +1 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +1 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js.map +1 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +5 -1
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js.map +1 -1
- package/dist/collection/components/store/checkout/cart.js +6 -0
- package/dist/collection/components/store/checkout/cart.js.map +1 -1
- package/dist/collection/components/store/checkout/stripe.js +2 -0
- package/dist/collection/components/store/checkout/stripe.js.map +1 -1
- package/dist/collection/environment.js +9 -1
- package/dist/collection/environment.js.map +1 -1
- package/dist/collection/scripts/loadStripe.js +3 -3
- package/dist/collection/scripts/loadStripe.js.map +1 -1
- package/dist/collection/scripts/stripe.js +6 -6
- package/dist/collection/scripts/stripe.js.map +1 -1
- package/dist/collection/scripts/zonos.js +2 -2
- package/dist/collection/scripts/zonos.js.map +1 -1
- package/dist/collection/types/generated/graphql.customer.types.js +5 -0
- package/dist/collection/types/generated/graphql.customer.types.js.map +1 -1
- package/dist/components/stripe.js +8 -1
- package/dist/components/stripe.js.map +1 -1
- package/dist/components/zonos-cart-items2.js +3 -1
- package/dist/components/zonos-cart-items2.js.map +1 -1
- package/dist/components/zonos-checkout-finish2.js +1 -1
- package/dist/components/zonos-checkout-finish2.js.map +1 -1
- package/dist/components/zonos-checkout.js +5 -1
- package/dist/components/zonos-checkout.js.map +1 -1
- package/dist/esm/{cart-36c33342.js → cart-2f83e048.js} +8 -1
- package/dist/esm/cart-2f83e048.js.map +1 -0
- package/dist/esm/zonos-address_2.entry.js +1 -1
- package/dist/esm/zonos-banner_2.entry.js +1 -1
- package/dist/esm/zonos-cart-items_10.entry.js +5 -3
- package/dist/esm/zonos-cart-items_10.entry.js.map +1 -1
- package/dist/esm/zonos-checkout.entry.js +6 -2
- package/dist/esm/zonos-checkout.entry.js.map +1 -1
- package/dist/esm/zonos-controller.entry.js +1 -1
- package/dist/esm-es5/cart-2f83e048.js +2 -0
- package/dist/esm-es5/cart-2f83e048.js.map +1 -0
- package/dist/esm-es5/zonos-address_2.entry.js +1 -1
- package/dist/esm-es5/zonos-banner_2.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_10.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_10.entry.js.map +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js.map +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- package/dist/scripts/loadStripe.js +118 -0
- package/dist/scripts/loadZonos.js +300 -0
- package/dist/scripts/stripe.js +126 -0
- package/dist/scripts/zonos.js +300 -0
- package/dist/types/components/store/checkout/cart.d.ts +14 -0
- package/dist/types/components/store/checkout/stripe.d.ts +1 -1
- package/dist/types/scripts/loadStripe.d.ts +1 -1
- package/dist/types/scripts/stripe.d.ts +2 -2
- package/dist/types/types/generated/graphql.customer.types.d.ts +48 -0
- package/dist/types/types/generated/graphql.customer.types.ts +50 -0
- package/dist/zonos-elements/{cart-36c33342.js → cart-2f83e048.js} +8 -1
- package/dist/zonos-elements/cart-2f83e048.js.map +1 -0
- package/dist/zonos-elements/cart-9780fa28.system.js +2 -0
- package/dist/zonos-elements/cart-9780fa28.system.js.map +1 -0
- package/dist/zonos-elements/zonos-address_2.entry.js +1 -1
- package/dist/zonos-elements/zonos-address_2.system.entry.js +1 -1
- package/dist/zonos-elements/zonos-banner_2.entry.js +1 -1
- package/dist/zonos-elements/zonos-banner_2.system.entry.js +1 -1
- package/dist/zonos-elements/zonos-cart-items_10.entry.js +5 -3
- package/dist/zonos-elements/zonos-cart-items_10.entry.js.map +1 -1
- package/dist/zonos-elements/zonos-cart-items_10.system.entry.js +1 -1
- package/dist/zonos-elements/zonos-cart-items_10.system.entry.js.map +1 -1
- package/dist/zonos-elements/zonos-checkout.entry.js +6 -2
- package/dist/zonos-elements/zonos-checkout.entry.js.map +1 -1
- package/dist/zonos-elements/zonos-checkout.system.entry.js +1 -1
- package/dist/zonos-elements/zonos-checkout.system.entry.js.map +1 -1
- package/dist/zonos-elements/zonos-controller.entry.js +1 -1
- package/dist/zonos-elements/zonos-controller.system.entry.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/cart-e27fd17c.js.map +0 -1
- package/dist/esm/cart-36c33342.js.map +0 -1
- package/dist/esm-es5/cart-36c33342.js +0 -2
- package/dist/esm-es5/cart-36c33342.js.map +0 -1
- package/dist/zonos-elements/cart-36c33342.js.map +0 -1
- package/dist/zonos-elements/cart-ecd9011b.system.js +0 -2
- package/dist/zonos-elements/cart-ecd9011b.system.js.map +0 -1
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const log = (message, type, ...additionalInfo) => {
|
|
4
|
+
// if type is error and debug is false, do not log
|
|
5
|
+
if (!window.Zonos.debug) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
switch (type) {
|
|
9
|
+
case 'warn':
|
|
10
|
+
// eslint-disable-next-line no-console
|
|
11
|
+
console.warn(message, ...additionalInfo);
|
|
12
|
+
break;
|
|
13
|
+
case 'info':
|
|
14
|
+
// eslint-disable-next-line no-console
|
|
15
|
+
console.info(message, ...additionalInfo);
|
|
16
|
+
break;
|
|
17
|
+
default:
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.groupCollapsed(message, ...additionalInfo);
|
|
20
|
+
// eslint-disable-next-line no-console
|
|
21
|
+
console.trace();
|
|
22
|
+
// eslint-disable-next-line no-console
|
|
23
|
+
console.groupEnd();
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const logError = (message, ...rest) => {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.error(message, ...rest);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/* eslint-disable no-console */
|
|
34
|
+
/** Loading stripe script extracted from stripe.js repository */
|
|
35
|
+
const V3_URL = 'https://js.stripe.com/v3';
|
|
36
|
+
const V3_URL_REGEX = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;
|
|
37
|
+
const EXISTING_SCRIPT_MESSAGE = 'loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used';
|
|
38
|
+
const zonosStripeFindScript = () => {
|
|
39
|
+
const scripts = document.querySelectorAll(`script[src^="${V3_URL}"]`);
|
|
40
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
41
|
+
const script = scripts[i];
|
|
42
|
+
if (!script) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (!V3_URL_REGEX.test(script.src)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
return script;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
let stripePromise$1 = null;
|
|
53
|
+
const injectScript = (params) => {
|
|
54
|
+
const queryString = params && !params.advancedFraudSignals ? '?advancedFraudSignals=false' : '';
|
|
55
|
+
const script = document.createElement('script');
|
|
56
|
+
script.src = `${V3_URL}${queryString}`;
|
|
57
|
+
const headBody = document.head || document.body;
|
|
58
|
+
if (!headBody) {
|
|
59
|
+
logError('Expected document.body not to be null. Stripe.js requires a <body> element.');
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
headBody.appendChild(script);
|
|
63
|
+
return script;
|
|
64
|
+
};
|
|
65
|
+
const zonosStripeLoadScript = (params) => {
|
|
66
|
+
// Ensure that we only attempt to load Stripe.js at most once
|
|
67
|
+
if (stripePromise$1 !== null) {
|
|
68
|
+
return stripePromise$1;
|
|
69
|
+
}
|
|
70
|
+
stripePromise$1 = new Promise((resolve, reject) => {
|
|
71
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
72
|
+
// Resolve to null when imported server side. This makes the module
|
|
73
|
+
// safe to import in an isomorphic code base.
|
|
74
|
+
resolve(null);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (window.Stripe && params) {
|
|
78
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
79
|
+
}
|
|
80
|
+
if (window.Stripe) {
|
|
81
|
+
resolve(window.Stripe);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
let script = zonosStripeFindScript();
|
|
86
|
+
if (script && params) {
|
|
87
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
88
|
+
}
|
|
89
|
+
else if (!script) {
|
|
90
|
+
script = injectScript(params);
|
|
91
|
+
}
|
|
92
|
+
script === null || script === void 0 ? void 0 : script.addEventListener('load', () => {
|
|
93
|
+
if (window.Stripe) {
|
|
94
|
+
resolve(window.Stripe);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
reject(new Error('Stripe.js not available'));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
script === null || script === void 0 ? void 0 : script.addEventListener('error', () => {
|
|
101
|
+
reject(new Error('Failed to load Stripe.js'));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
reject(error);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return stripePromise$1;
|
|
110
|
+
};
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
const registerWrapper = (stripe, startTime) => {
|
|
113
|
+
if (!stripe || !stripe._registerWrapper) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
stripe._registerWrapper({ name: 'stripe-js', startTime });
|
|
117
|
+
};
|
|
118
|
+
const initStripe = (maybeStripe, args, startTime) => {
|
|
119
|
+
if (maybeStripe === null) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const stripe = maybeStripe.apply(undefined, args);
|
|
123
|
+
registerWrapper(stripe, startTime);
|
|
124
|
+
return stripe;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// Execute our own script injection after a tick to give users time to do their
|
|
128
|
+
// own script injection.
|
|
129
|
+
const stripePromise = Promise.resolve().then(() => zonosStripeLoadScript(null));
|
|
130
|
+
let loadCalled = false;
|
|
131
|
+
stripePromise.catch((err) => {
|
|
132
|
+
if (!loadCalled) {
|
|
133
|
+
// eslint-disable-next-line no-console
|
|
134
|
+
console.warn(err);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const zonosLoadStripe = async (...args) => {
|
|
138
|
+
loadCalled = true;
|
|
139
|
+
const startTime = Date.now();
|
|
140
|
+
return stripePromise.then(maybeStripe => initStripe(maybeStripe, args, startTime));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
var _a;
|
|
144
|
+
const ZONOS_URL = "https://unpkg.com/@zonos/elements@1.0.17-alpha.1";
|
|
145
|
+
const INTER_FONT_URL = 'https://rsms.me';
|
|
146
|
+
const INTER_FONT_REGEX = /^https:\/\/rsms\.me\/inter\/inter\.css(.*)$/;
|
|
147
|
+
class Zonos {
|
|
148
|
+
}
|
|
149
|
+
_a = Zonos;
|
|
150
|
+
Zonos.doneInit = false;
|
|
151
|
+
// if query 'zonosDebug=1' param from url, debug mode is on
|
|
152
|
+
Zonos.debug = !!window.location.search.match(/\?.*(&*)zonosDebug=1/);
|
|
153
|
+
Zonos.init = async ({ appearance, checkoutSettings, currencyConverter, helloSettings, zonosApiKey, }) => {
|
|
154
|
+
if (Zonos.doneInit) {
|
|
155
|
+
// do nothing if zonos is already initializeds
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
log('====== ZONOS DEBUG MODE: on ======');
|
|
159
|
+
if (!zonosApiKey) {
|
|
160
|
+
logError('Missing Zonos API key');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
_a.zonosApiKey = zonosApiKey;
|
|
164
|
+
// eslint-disable-next-line no-console
|
|
165
|
+
log('init zonos');
|
|
166
|
+
// inject zonos cdn
|
|
167
|
+
Zonos.injectZonosCdn();
|
|
168
|
+
// inject css for zonos elements
|
|
169
|
+
Zonos.injectZonosCss();
|
|
170
|
+
// inject fonts for zonos elements
|
|
171
|
+
Zonos.injectFonts();
|
|
172
|
+
// init zonos controller
|
|
173
|
+
Zonos.injectController({
|
|
174
|
+
config: {
|
|
175
|
+
appearance,
|
|
176
|
+
checkoutSettings,
|
|
177
|
+
currencyConverter,
|
|
178
|
+
helloSettings,
|
|
179
|
+
},
|
|
180
|
+
zonosApiKey,
|
|
181
|
+
});
|
|
182
|
+
Zonos.doneInit = true;
|
|
183
|
+
};
|
|
184
|
+
Zonos.displayCurrency = () => {
|
|
185
|
+
const zonosHello = document.querySelector('zonos-hello');
|
|
186
|
+
if (zonosHello) {
|
|
187
|
+
void zonosHello.displayCurrency();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
Zonos.showNotification = (notification) => {
|
|
191
|
+
const zonosController = document.querySelector('zonos-controller');
|
|
192
|
+
void (zonosController === null || zonosController === void 0 ? void 0 : zonosController.showNotification(notification));
|
|
193
|
+
};
|
|
194
|
+
Zonos.injectController = ({ config, zonosApiKey, }) => {
|
|
195
|
+
if (document.querySelector('zonos-controller')) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const zonosController = document.createElement('zonos-controller');
|
|
199
|
+
zonosController.config = config;
|
|
200
|
+
zonosController.zonosApiKey = zonosApiKey;
|
|
201
|
+
zonosController.addEventListener('stripeInitEvent', async (event) => {
|
|
202
|
+
const { detail } = event;
|
|
203
|
+
log('loading Stripe');
|
|
204
|
+
const stripe = await zonosLoadStripe(detail.publishableKey);
|
|
205
|
+
if (!stripe) {
|
|
206
|
+
logError('API seems to be invalid or missing. Failed to load Stripe');
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
window.Zonos.stripe = stripe;
|
|
210
|
+
void zonosController.initCheckoutElement(stripe);
|
|
211
|
+
});
|
|
212
|
+
document.body.appendChild(zonosController);
|
|
213
|
+
// eslint-disable-next-line no-console
|
|
214
|
+
log('Zonos controller injected!');
|
|
215
|
+
};
|
|
216
|
+
Zonos.injectZonosCdn = () => {
|
|
217
|
+
const findScript = () => {
|
|
218
|
+
const scripts = document.querySelectorAll(`script[src^="${ZONOS_URL}/dist/zonos-elements"]`);
|
|
219
|
+
scripts.forEach(script => {
|
|
220
|
+
if (script.src.indexOf('zonos-elements.js')) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return false;
|
|
225
|
+
};
|
|
226
|
+
if (findScript()) ;
|
|
227
|
+
const headOrBody = document.head || document.body;
|
|
228
|
+
// init zonos elements when the zonosKey is valid
|
|
229
|
+
// inject esmodule cdn for zonos elements
|
|
230
|
+
const zonosEsmCdn = document.createElement('script');
|
|
231
|
+
zonosEsmCdn.type = 'module';
|
|
232
|
+
zonosEsmCdn.src = `${ZONOS_URL}/dist/zonos-elements/zonos-elements.esm.js`;
|
|
233
|
+
headOrBody.appendChild(zonosEsmCdn);
|
|
234
|
+
// inject non module cdn for zonos elements
|
|
235
|
+
const zonosCdn = document.createElement('script');
|
|
236
|
+
zonosCdn.noModule = true;
|
|
237
|
+
zonosCdn.src = `${ZONOS_URL}/dist/zonos-elements/zonos-elements.js`;
|
|
238
|
+
headOrBody.appendChild(zonosCdn);
|
|
239
|
+
// eslint-disable-next-line no-console
|
|
240
|
+
log('Zonos cdn script injected!');
|
|
241
|
+
};
|
|
242
|
+
Zonos.injectZonosCss = () => {
|
|
243
|
+
const findStyleLink = () => {
|
|
244
|
+
return !!document.querySelector(`link[rel="stylesheet"][href^="${ZONOS_URL}/dist/zonos-elements/zonos-elements.css"]`);
|
|
245
|
+
};
|
|
246
|
+
if (findStyleLink()) {
|
|
247
|
+
// eslint-disable-next-line no-console
|
|
248
|
+
log('Zonos style links already injected', 'warn');
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const headOrBody = document.head || document.body;
|
|
252
|
+
// inject css for zonos elements
|
|
253
|
+
const zonosCssPreconnect = document.createElement('link');
|
|
254
|
+
zonosCssPreconnect.rel = 'preconnect';
|
|
255
|
+
zonosCssPreconnect.href = `${ZONOS_URL}/`;
|
|
256
|
+
headOrBody.appendChild(zonosCssPreconnect);
|
|
257
|
+
// inject css for zonos elements
|
|
258
|
+
const zonosCss = document.createElement('link');
|
|
259
|
+
zonosCss.rel = 'stylesheet';
|
|
260
|
+
zonosCss.href = `${ZONOS_URL}/dist/zonos-elements/zonos-elements.css`;
|
|
261
|
+
headOrBody.appendChild(zonosCss);
|
|
262
|
+
// eslint-disable-next-line no-console
|
|
263
|
+
log('Zonos style css injected!');
|
|
264
|
+
};
|
|
265
|
+
Zonos.injectFonts = () => {
|
|
266
|
+
const findFont = () => {
|
|
267
|
+
const links = document.querySelectorAll(`link[rel="stylesheet"][href^="${INTER_FONT_URL}"]`);
|
|
268
|
+
for (let i = 0; i < links.length; i++) {
|
|
269
|
+
const link = links[i];
|
|
270
|
+
if (!link) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (INTER_FONT_REGEX.test(link.href)) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
return link;
|
|
277
|
+
}
|
|
278
|
+
return null;
|
|
279
|
+
};
|
|
280
|
+
if (findFont()) {
|
|
281
|
+
// eslint-disable-next-line no-console
|
|
282
|
+
log('Inter font already injected', 'warn');
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const headOrBody = document.head || document.body;
|
|
286
|
+
// inject css for zonos elements
|
|
287
|
+
const fontPreconnect = document.createElement('link');
|
|
288
|
+
fontPreconnect.rel = 'preconnect';
|
|
289
|
+
fontPreconnect.href = INTER_FONT_URL;
|
|
290
|
+
headOrBody.appendChild(fontPreconnect);
|
|
291
|
+
// inject css for zonos elements
|
|
292
|
+
const font = document.createElement('link');
|
|
293
|
+
font.rel = 'stylesheet';
|
|
294
|
+
font.href = `${INTER_FONT_URL}/inter/inter.css`;
|
|
295
|
+
headOrBody.appendChild(font);
|
|
296
|
+
// eslint-disable-next-line no-console
|
|
297
|
+
log('Zonos font injected!');
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
exports.Zonos = Zonos;
|
|
@@ -19,6 +19,13 @@ type CartStore = {
|
|
|
19
19
|
messages: string[];
|
|
20
20
|
title: string;
|
|
21
21
|
} | null;
|
|
22
|
+
exchangeRate: {
|
|
23
|
+
id: string;
|
|
24
|
+
rate: number;
|
|
25
|
+
sourceCurrencyCode: CurrencyCode;
|
|
26
|
+
targetCurrencyCode: CurrencyCode;
|
|
27
|
+
type: string;
|
|
28
|
+
} | null;
|
|
22
29
|
isSelectedShippingAboveDeminimis: boolean;
|
|
23
30
|
isSelectedShippingGuarantee: boolean;
|
|
24
31
|
items: CartItem[];
|
|
@@ -52,6 +59,13 @@ declare const cartStoreUpdateToErrorState: ({ messages, title, }: {
|
|
|
52
59
|
title: string;
|
|
53
60
|
}) => void;
|
|
54
61
|
type CartSubtotals = {
|
|
62
|
+
exchangeRate: {
|
|
63
|
+
id: string;
|
|
64
|
+
rate: number;
|
|
65
|
+
sourceCurrencyCode: CurrencyCode;
|
|
66
|
+
targetCurrencyCode: CurrencyCode;
|
|
67
|
+
type: string;
|
|
68
|
+
};
|
|
55
69
|
items: number;
|
|
56
70
|
landedCostTotal: number;
|
|
57
71
|
presentmentCurrencyCode: CurrencyCode;
|
|
@@ -37,7 +37,7 @@ declare const initStripeElements: (props?: {
|
|
|
37
37
|
declare const stripeStoreReset: () => void;
|
|
38
38
|
declare const stripeStorePrefetchLandedCost: () => Promise<void>;
|
|
39
39
|
declare const stripeStoreRetrievePayment: ({ clientSecret: _clientSecret, storybookForceStatus, }: {
|
|
40
|
-
clientSecret
|
|
40
|
+
clientSecret: string | null;
|
|
41
41
|
storybookForceStatus?: PaymentIntent.Status | undefined;
|
|
42
42
|
}) => Promise<{
|
|
43
43
|
error: boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type LoadStripe } from "./stripe";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const zonosLoadStripe: LoadStripe;
|
|
@@ -4,9 +4,9 @@ export interface LoadParams {
|
|
|
4
4
|
advancedFraudSignals: boolean;
|
|
5
5
|
}
|
|
6
6
|
export type LoadStripe = (...args: Parameters<StripeConstructor>) => Promise<Stripe | null>;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const zonosStripeFindScript: () => HTMLScriptElement | null;
|
|
8
8
|
export declare const injectScript: (params: null | LoadParams) => HTMLScriptElement | null;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const zonosStripeLoadScript: (params: null | LoadParams) => Promise<StripeConstructor | null>;
|
|
10
10
|
export declare const initStripe: (maybeStripe: StripeConstructor | null, args: [publishableKey: string, options?: import("@stripe/stripe-js").StripeConstructorOptions | undefined], startTime: number) => Stripe | null;
|
|
11
11
|
export declare const validateLoadParams: (params: {
|
|
12
12
|
advancedFraudSignals: boolean;
|
|
@@ -1687,6 +1687,12 @@ export declare const stripeSubscriptionStatus: {
|
|
|
1687
1687
|
readonly Unpaid: "UNPAID";
|
|
1688
1688
|
};
|
|
1689
1689
|
export type StripeSubscriptionStatus = (typeof stripeSubscriptionStatus)[keyof typeof stripeSubscriptionStatus];
|
|
1690
|
+
export declare const taxCalculationType: {
|
|
1691
|
+
readonly Cif: "CIF";
|
|
1692
|
+
readonly Custom: "CUSTOM";
|
|
1693
|
+
readonly Fob: "FOB";
|
|
1694
|
+
};
|
|
1695
|
+
export type TaxCalculationType = (typeof taxCalculationType)[keyof typeof taxCalculationType];
|
|
1690
1696
|
export declare const taxIdType: {
|
|
1691
1697
|
readonly Cnp: "CNP";
|
|
1692
1698
|
readonly Dan: "DAN";
|
|
@@ -1848,6 +1854,13 @@ export type CalculateLandedCostMutation = {
|
|
|
1848
1854
|
} | null;
|
|
1849
1855
|
subtotals: {
|
|
1850
1856
|
duties: number;
|
|
1857
|
+
exchangeRate: {
|
|
1858
|
+
id: string;
|
|
1859
|
+
rate: number;
|
|
1860
|
+
sourceCurrencyCode: CurrencyCode;
|
|
1861
|
+
targetCurrencyCode: CurrencyCode;
|
|
1862
|
+
type: ExchangeRateType;
|
|
1863
|
+
};
|
|
1851
1864
|
fees: number;
|
|
1852
1865
|
items: number;
|
|
1853
1866
|
landedCostTotal: number;
|
|
@@ -1934,6 +1947,13 @@ export type CheckoutPresentmentFragment = {
|
|
|
1934
1947
|
} | null;
|
|
1935
1948
|
subtotals: {
|
|
1936
1949
|
duties: number;
|
|
1950
|
+
exchangeRate: {
|
|
1951
|
+
id: string;
|
|
1952
|
+
rate: number;
|
|
1953
|
+
sourceCurrencyCode: CurrencyCode;
|
|
1954
|
+
targetCurrencyCode: CurrencyCode;
|
|
1955
|
+
type: ExchangeRateType;
|
|
1956
|
+
};
|
|
1937
1957
|
fees: number;
|
|
1938
1958
|
items: number;
|
|
1939
1959
|
landedCostTotal: number;
|
|
@@ -2007,6 +2027,13 @@ export type CheckoutSessionUpdateMutation = {
|
|
|
2007
2027
|
organizationId: string;
|
|
2008
2028
|
subtotals: {
|
|
2009
2029
|
duties: number;
|
|
2030
|
+
exchangeRate: {
|
|
2031
|
+
id: string;
|
|
2032
|
+
rate: number;
|
|
2033
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2034
|
+
targetCurrencyCode: CurrencyCode;
|
|
2035
|
+
type: ExchangeRateType;
|
|
2036
|
+
};
|
|
2010
2037
|
fees: number;
|
|
2011
2038
|
items: number;
|
|
2012
2039
|
landedCostTotal: number;
|
|
@@ -2043,6 +2070,13 @@ export type CheckoutSessionUpdateDetailsFragment = {
|
|
|
2043
2070
|
organizationId: string;
|
|
2044
2071
|
subtotals: {
|
|
2045
2072
|
duties: number;
|
|
2073
|
+
exchangeRate: {
|
|
2074
|
+
id: string;
|
|
2075
|
+
rate: number;
|
|
2076
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2077
|
+
targetCurrencyCode: CurrencyCode;
|
|
2078
|
+
type: ExchangeRateType;
|
|
2079
|
+
};
|
|
2046
2080
|
fees: number;
|
|
2047
2081
|
items: number;
|
|
2048
2082
|
landedCostTotal: number;
|
|
@@ -2098,6 +2132,13 @@ export type CheckoutSessionCreateMutation = {
|
|
|
2098
2132
|
organizationId: string;
|
|
2099
2133
|
subtotals: {
|
|
2100
2134
|
duties: number;
|
|
2135
|
+
exchangeRate: {
|
|
2136
|
+
id: string;
|
|
2137
|
+
rate: number;
|
|
2138
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2139
|
+
targetCurrencyCode: CurrencyCode;
|
|
2140
|
+
type: ExchangeRateType;
|
|
2141
|
+
};
|
|
2101
2142
|
fees: number;
|
|
2102
2143
|
items: number;
|
|
2103
2144
|
landedCostTotal: number;
|
|
@@ -2134,6 +2175,13 @@ export type CheckoutDetailsFragment = {
|
|
|
2134
2175
|
organizationId: string;
|
|
2135
2176
|
subtotals: {
|
|
2136
2177
|
duties: number;
|
|
2178
|
+
exchangeRate: {
|
|
2179
|
+
id: string;
|
|
2180
|
+
rate: number;
|
|
2181
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2182
|
+
targetCurrencyCode: CurrencyCode;
|
|
2183
|
+
type: ExchangeRateType;
|
|
2184
|
+
};
|
|
2137
2185
|
fees: number;
|
|
2138
2186
|
items: number;
|
|
2139
2187
|
landedCostTotal: number;
|
|
@@ -1946,6 +1946,14 @@ export const stripeSubscriptionStatus = {
|
|
|
1946
1946
|
|
|
1947
1947
|
export type StripeSubscriptionStatus =
|
|
1948
1948
|
(typeof stripeSubscriptionStatus)[keyof typeof stripeSubscriptionStatus];
|
|
1949
|
+
export const taxCalculationType = {
|
|
1950
|
+
Cif: 'CIF',
|
|
1951
|
+
Custom: 'CUSTOM',
|
|
1952
|
+
Fob: 'FOB',
|
|
1953
|
+
} as const;
|
|
1954
|
+
|
|
1955
|
+
export type TaxCalculationType =
|
|
1956
|
+
(typeof taxCalculationType)[keyof typeof taxCalculationType];
|
|
1949
1957
|
|
|
1950
1958
|
export const taxIdType = {
|
|
1951
1959
|
Cnp: 'CNP',
|
|
@@ -2132,6 +2140,13 @@ export type CalculateLandedCostMutation = {
|
|
|
2132
2140
|
} | null;
|
|
2133
2141
|
subtotals: {
|
|
2134
2142
|
duties: number;
|
|
2143
|
+
exchangeRate: {
|
|
2144
|
+
id: string;
|
|
2145
|
+
rate: number;
|
|
2146
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2147
|
+
targetCurrencyCode: CurrencyCode;
|
|
2148
|
+
type: ExchangeRateType;
|
|
2149
|
+
};
|
|
2135
2150
|
fees: number;
|
|
2136
2151
|
items: number;
|
|
2137
2152
|
landedCostTotal: number;
|
|
@@ -2204,6 +2219,13 @@ export type CheckoutPresentmentFragment = {
|
|
|
2204
2219
|
} | null;
|
|
2205
2220
|
subtotals: {
|
|
2206
2221
|
duties: number;
|
|
2222
|
+
exchangeRate: {
|
|
2223
|
+
id: string;
|
|
2224
|
+
rate: number;
|
|
2225
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2226
|
+
targetCurrencyCode: CurrencyCode;
|
|
2227
|
+
type: ExchangeRateType;
|
|
2228
|
+
};
|
|
2207
2229
|
fees: number;
|
|
2208
2230
|
items: number;
|
|
2209
2231
|
landedCostTotal: number;
|
|
@@ -2263,6 +2285,13 @@ export type CheckoutSessionUpdateMutation = {
|
|
|
2263
2285
|
organizationId: string;
|
|
2264
2286
|
subtotals: {
|
|
2265
2287
|
duties: number;
|
|
2288
|
+
exchangeRate: {
|
|
2289
|
+
id: string;
|
|
2290
|
+
rate: number;
|
|
2291
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2292
|
+
targetCurrencyCode: CurrencyCode;
|
|
2293
|
+
type: ExchangeRateType;
|
|
2294
|
+
};
|
|
2266
2295
|
fees: number;
|
|
2267
2296
|
items: number;
|
|
2268
2297
|
landedCostTotal: number;
|
|
@@ -2295,6 +2324,13 @@ export type CheckoutSessionUpdateDetailsFragment = {
|
|
|
2295
2324
|
organizationId: string;
|
|
2296
2325
|
subtotals: {
|
|
2297
2326
|
duties: number;
|
|
2327
|
+
exchangeRate: {
|
|
2328
|
+
id: string;
|
|
2329
|
+
rate: number;
|
|
2330
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2331
|
+
targetCurrencyCode: CurrencyCode;
|
|
2332
|
+
type: ExchangeRateType;
|
|
2333
|
+
};
|
|
2298
2334
|
fees: number;
|
|
2299
2335
|
items: number;
|
|
2300
2336
|
landedCostTotal: number;
|
|
@@ -2348,6 +2384,13 @@ export type CheckoutSessionCreateMutation = {
|
|
|
2348
2384
|
organizationId: string;
|
|
2349
2385
|
subtotals: {
|
|
2350
2386
|
duties: number;
|
|
2387
|
+
exchangeRate: {
|
|
2388
|
+
id: string;
|
|
2389
|
+
rate: number;
|
|
2390
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2391
|
+
targetCurrencyCode: CurrencyCode;
|
|
2392
|
+
type: ExchangeRateType;
|
|
2393
|
+
};
|
|
2351
2394
|
fees: number;
|
|
2352
2395
|
items: number;
|
|
2353
2396
|
landedCostTotal: number;
|
|
@@ -2380,6 +2423,13 @@ export type CheckoutDetailsFragment = {
|
|
|
2380
2423
|
organizationId: string;
|
|
2381
2424
|
subtotals: {
|
|
2382
2425
|
duties: number;
|
|
2426
|
+
exchangeRate: {
|
|
2427
|
+
id: string;
|
|
2428
|
+
rate: number;
|
|
2429
|
+
sourceCurrencyCode: CurrencyCode;
|
|
2430
|
+
targetCurrencyCode: CurrencyCode;
|
|
2431
|
+
type: ExchangeRateType;
|
|
2432
|
+
};
|
|
2383
2433
|
fees: number;
|
|
2384
2434
|
items: number;
|
|
2385
2435
|
landedCostTotal: number;
|
|
@@ -214,6 +214,7 @@ const stripeStorePrefetchLandedCost = async () => {
|
|
|
214
214
|
if (subtotals) {
|
|
215
215
|
// prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
|
|
216
216
|
cartStoreApplySubtotals({
|
|
217
|
+
exchangeRate: subtotals.exchangeRate,
|
|
217
218
|
items: subtotals.items,
|
|
218
219
|
landedCostTotal: 0,
|
|
219
220
|
presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
|
|
@@ -349,6 +350,7 @@ const stripeStoreInitCheckoutSession = async () => {
|
|
|
349
350
|
// update cart store with updated informations
|
|
350
351
|
cartStore.checkoutSessionId = result.id;
|
|
351
352
|
cartStoreApplySubtotals(Object.assign(Object.assign({}, result.subtotals), { landedCostTotal: 0, shipping: 0, total: result.subtotals.items }));
|
|
353
|
+
log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
|
|
352
354
|
log('done-init-checkout-session');
|
|
353
355
|
return true;
|
|
354
356
|
};
|
|
@@ -401,6 +403,7 @@ const { onChange, reset, state: cartStore, } = createStore(() => ({
|
|
|
401
403
|
currency: 'USD',
|
|
402
404
|
dutiesTaxFees: 0,
|
|
403
405
|
error: null,
|
|
406
|
+
exchangeRate: null,
|
|
404
407
|
isSelectedShippingAboveDeminimis: false,
|
|
405
408
|
isSelectedShippingGuarantee: false,
|
|
406
409
|
items: [],
|
|
@@ -453,6 +456,8 @@ const cartStoreUpdateToErrorState = ({ messages, title, }) => {
|
|
|
453
456
|
};
|
|
454
457
|
};
|
|
455
458
|
const cartStoreApplySubtotals = (subtotals) => {
|
|
459
|
+
// update exchange rate so we can use it to display cart items
|
|
460
|
+
cartStore.exchangeRate = subtotals.exchangeRate;
|
|
456
461
|
cartStore.dutiesTaxFees = subtotals.landedCostTotal;
|
|
457
462
|
cartStore.subtotal = subtotals.items;
|
|
458
463
|
cartStore.total = subtotals.total;
|
|
@@ -463,6 +468,7 @@ const cartStoreReCalculateTotal = async ({ currency, itemsAmount, landedCostId,
|
|
|
463
468
|
// update cart total right away if we have landed cost id to avoid order total flickering
|
|
464
469
|
const subtotals = cartStore.selectedLandedCost.subtotals;
|
|
465
470
|
cartStoreApplySubtotals(subtotals);
|
|
471
|
+
log('Exchange rate updated for cart items (landed cost subtotal)', 'info', cartStore.exchangeRate);
|
|
466
472
|
}
|
|
467
473
|
// update checkout session
|
|
468
474
|
if (!cartStore.checkoutSessionId) {
|
|
@@ -491,6 +497,7 @@ const cartStoreReCalculateTotal = async ({ currency, itemsAmount, landedCostId,
|
|
|
491
497
|
// This is when first open the checkout modal and we just want to get info from the old cart session.
|
|
492
498
|
// use subtotals from checkout session to update cart total
|
|
493
499
|
cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);
|
|
500
|
+
log('Exchange rate updated for cart items (checkout session update)', 'info', cartStore.exchangeRate);
|
|
494
501
|
}
|
|
495
502
|
return true;
|
|
496
503
|
};
|
|
@@ -588,4 +595,4 @@ const cartStorePreviousStep = () => {
|
|
|
588
595
|
|
|
589
596
|
export { cartStoreUpdateItems as a, cartStoreReset as b, cartStore as c, stripeStoreInitCheckoutSession as d, cartStoreUpdateToErrorState as e, stripeStorePrefetchLandedCost as f, cartStoreNextStep as g, stripeStoreConfirmPayment as h, initStripeElements as i, stripeStoreReset as j, cartStorePreviousStep as k, stripeStoreRetrievePayment as l, cartStoreUpdateSelectedShippingOption as m, cartStoreGetShippingTransitInfo as n, stripeStore as s };
|
|
590
597
|
|
|
591
|
-
//# sourceMappingURL=cart-
|
|
598
|
+
//# sourceMappingURL=cart-2f83e048.js.map
|