@odus/checkout 0.29.0 → 0.29.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/checkout.es.js +767 -682
- package/dist/elements.es.js +12 -21
- package/dist/package.json +1 -1
- package/dist/phone.js +47 -37
- package/dist/shared.js +153 -156
- package/package.json +1 -1
package/dist/checkout.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { o as vt, p as
|
|
1
|
+
import { c as le, a as he, f as j, d as ue, C as w, I as de, g as me, S as _, b as Q, e as k, A as pe, P as fe, E as ge, l as ye, h as be, i as Ee, j as Se, k as Fe, F as Ce, m as ve, n as Me } from "./shared.js";
|
|
2
|
+
import { o as vt, p as Mt, q as Nt, r as Pt, s as At, t as wt, u as kt, v as It } from "./shared.js";
|
|
3
3
|
const v = {
|
|
4
4
|
// Checkout lifecycle events
|
|
5
5
|
CHECKOUT_INITIALIZED: "checkout.initialized",
|
|
@@ -16,86 +16,86 @@ const v = {
|
|
|
16
16
|
PAYMENT_AUTHORIZED: "payment.authorized",
|
|
17
17
|
PAYMENT_FAILED: "payment.failed",
|
|
18
18
|
PAYMENT_ACTION_REQUIRED: "payment.action_required"
|
|
19
|
-
},
|
|
19
|
+
}, J = {
|
|
20
20
|
PAYMENT_AUTHORIZATION_TIME: "payment.authorization_time",
|
|
21
21
|
CHECKOUT_LOAD_TIME: "checkout.load_time",
|
|
22
22
|
FORM_RENDER_TIME: "form.render_time"
|
|
23
|
-
},
|
|
23
|
+
}, Ne = /^\s*at (?:(.+?) ?\()?((?:file|https?|chrome-extension|webpack-internal):\/\/.+?):(\d+):(\d+)\)?\s*$/, Pe = /^([^@]+)@((?:file|https?|chrome-extension|webpack-internal):\/\/[^\s:]+):(\d+):(\d+)$/, Ae = /^(?:([^@]+)@)?((?:file|https?):\/\/[^\s:]+):(\d+):(\d+)$/, W = (n) => {
|
|
24
24
|
if (!n)
|
|
25
25
|
return [];
|
|
26
26
|
const e = [], t = n.split(`
|
|
27
27
|
`);
|
|
28
28
|
for (const s of t) {
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
29
|
+
const a = s.trim();
|
|
30
|
+
if (!a)
|
|
31
31
|
continue;
|
|
32
|
-
let
|
|
33
|
-
if (
|
|
32
|
+
let i = Ne.exec(a);
|
|
33
|
+
if (i) {
|
|
34
34
|
e.push({
|
|
35
|
-
function:
|
|
36
|
-
filename:
|
|
37
|
-
lineno: parseInt(
|
|
38
|
-
colno: parseInt(
|
|
35
|
+
function: i[1] || "(anonymous)",
|
|
36
|
+
filename: i[2],
|
|
37
|
+
lineno: parseInt(i[3], 10),
|
|
38
|
+
colno: parseInt(i[4], 10)
|
|
39
39
|
});
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
function:
|
|
44
|
-
filename:
|
|
45
|
-
lineno: parseInt(
|
|
46
|
-
colno: parseInt(
|
|
42
|
+
i = Pe.exec(a) ?? Ae.exec(a), i && e.push({
|
|
43
|
+
function: i[1] || "(anonymous)",
|
|
44
|
+
filename: i[2],
|
|
45
|
+
lineno: parseInt(i[3], 10),
|
|
46
|
+
colno: parseInt(i[4], 10)
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
return e;
|
|
50
|
-
},
|
|
51
|
-
let
|
|
52
|
-
const
|
|
50
|
+
}, we = "@odus/telemetry", ke = "0.0.1";
|
|
51
|
+
let V, H, G;
|
|
52
|
+
const Ie = () => {
|
|
53
53
|
if (typeof navigator > "u")
|
|
54
54
|
return {};
|
|
55
55
|
const n = navigator.userAgent;
|
|
56
56
|
let e, t, s;
|
|
57
57
|
n.includes("Firefox/") ? (e = "Firefox", t = n.match(/Firefox\/([\d.]+)/)?.[1]) : n.includes("Edg/") ? (e = "Edge", t = n.match(/Edg\/([\d.]+)/)?.[1]) : n.includes("Chrome/") ? (e = "Chrome", t = n.match(/Chrome\/([\d.]+)/)?.[1]) : n.includes("Safari/") && (e = "Safari", t = n.match(/Version\/([\d.]+)/)?.[1]), n.includes("Windows") ? s = "Windows" : n.includes("Mac OS") ? s = "macOS" : n.includes("Linux") ? s = "Linux" : n.includes("Android") ? s = "Android" : (n.includes("iPhone") || n.includes("iPad")) && (s = "iOS");
|
|
58
|
-
const
|
|
58
|
+
const a = /Mobi|Android|iPhone|iPad/i.test(n) || void 0;
|
|
59
59
|
return {
|
|
60
60
|
name: e,
|
|
61
61
|
version: t,
|
|
62
62
|
os: s,
|
|
63
|
-
mobile:
|
|
63
|
+
mobile: a ?? !1,
|
|
64
64
|
language: navigator.language,
|
|
65
65
|
viewportWidth: String(window.innerWidth),
|
|
66
66
|
viewportHeight: String(window.innerHeight),
|
|
67
67
|
userAgent: n
|
|
68
68
|
};
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
}, _e = (n) => {
|
|
76
|
-
x = n;
|
|
69
|
+
}, De = () => typeof window > "u" ? {} : { url: window.location.href }, Te = (n) => {
|
|
70
|
+
V = void 0, G = void 0, H = n.sessionTracking?.session ? { id: n.sessionTracking.session.id } : void 0;
|
|
71
|
+
}, Le = (n) => {
|
|
72
|
+
V = n;
|
|
73
|
+
}, _e = () => {
|
|
74
|
+
V = void 0;
|
|
77
75
|
}, Be = (n) => {
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
|
|
76
|
+
H = n;
|
|
77
|
+
}, Ue = (n) => {
|
|
78
|
+
G = n;
|
|
79
|
+
}, xe = () => H?.id, Oe = (n) => ({
|
|
80
|
+
sdk: { name: we, version: ke },
|
|
81
81
|
app: n.app,
|
|
82
|
-
user:
|
|
83
|
-
session:
|
|
84
|
-
page:
|
|
85
|
-
browser:
|
|
86
|
-
view:
|
|
87
|
-
}),
|
|
88
|
-
let
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
82
|
+
user: V,
|
|
83
|
+
session: H,
|
|
84
|
+
page: De(),
|
|
85
|
+
browser: Ie(),
|
|
86
|
+
view: G
|
|
87
|
+
}), Re = 30, Ve = 250, He = 6e4;
|
|
88
|
+
let I = [], A = null, X = 0, B = null, U = null;
|
|
89
|
+
const ze = (n) => {
|
|
90
|
+
if (A)
|
|
91
91
|
return;
|
|
92
92
|
const e = n.batching?.sendTimeout ?? Ve;
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
A = setTimeout(() => {
|
|
94
|
+
z(n);
|
|
95
95
|
}, e);
|
|
96
|
-
},
|
|
96
|
+
}, je = (n, e) => {
|
|
97
97
|
const t = {
|
|
98
|
-
meta:
|
|
98
|
+
meta: Oe(e)
|
|
99
99
|
};
|
|
100
100
|
for (const s of n)
|
|
101
101
|
switch (s.type) {
|
|
@@ -113,238 +113,238 @@ const He = (n) => {
|
|
|
113
113
|
break;
|
|
114
114
|
}
|
|
115
115
|
return t;
|
|
116
|
-
},
|
|
117
|
-
const s = JSON.stringify(n),
|
|
116
|
+
}, Ke = (n, e, t = !1) => {
|
|
117
|
+
const s = JSON.stringify(n), a = xe(), i = {
|
|
118
118
|
"Content-Type": "application/json"
|
|
119
119
|
};
|
|
120
|
-
if (
|
|
121
|
-
const
|
|
122
|
-
navigator.sendBeacon(e,
|
|
120
|
+
if (a && (i["x-faro-session-id"] = a), t && typeof navigator < "u" && navigator.sendBeacon) {
|
|
121
|
+
const l = new Blob([s], { type: "application/json" });
|
|
122
|
+
navigator.sendBeacon(e, l);
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
|
-
const r = s.length <
|
|
125
|
+
const r = s.length < He;
|
|
126
126
|
fetch(e, {
|
|
127
127
|
method: "POST",
|
|
128
|
-
headers:
|
|
128
|
+
headers: i,
|
|
129
129
|
body: s,
|
|
130
130
|
keepalive: r
|
|
131
|
-
}).then((
|
|
132
|
-
if (
|
|
133
|
-
const
|
|
134
|
-
|
|
131
|
+
}).then((l) => {
|
|
132
|
+
if (l.status === 429) {
|
|
133
|
+
const d = l.headers.get("Retry-After"), h = d ? parseInt(d, 10) * 1e3 : 3e4;
|
|
134
|
+
X = Date.now() + h;
|
|
135
135
|
}
|
|
136
136
|
}).catch(() => {
|
|
137
137
|
});
|
|
138
|
-
},
|
|
139
|
-
if (
|
|
138
|
+
}, z = (n, e = !1) => {
|
|
139
|
+
if (A && (clearTimeout(A), A = null), I.length === 0)
|
|
140
140
|
return;
|
|
141
|
-
if (Date.now() <
|
|
142
|
-
|
|
141
|
+
if (Date.now() < X) {
|
|
142
|
+
I = [];
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
|
-
const t =
|
|
146
|
-
|
|
145
|
+
const t = I;
|
|
146
|
+
I = [];
|
|
147
147
|
try {
|
|
148
|
-
let s =
|
|
148
|
+
let s = je(t, n);
|
|
149
149
|
if (n.beforeSend) {
|
|
150
|
-
const
|
|
151
|
-
if (!
|
|
150
|
+
const a = n.beforeSend(s);
|
|
151
|
+
if (!a)
|
|
152
152
|
return;
|
|
153
|
-
s =
|
|
153
|
+
s = a;
|
|
154
154
|
}
|
|
155
|
-
|
|
155
|
+
Ke(s, n.url, e);
|
|
156
156
|
} catch {
|
|
157
157
|
}
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
const t = e.batching?.itemLimit ??
|
|
161
|
-
if (
|
|
162
|
-
|
|
158
|
+
}, P = (n, e) => {
|
|
159
|
+
I.push(n);
|
|
160
|
+
const t = e.batching?.itemLimit ?? Re;
|
|
161
|
+
if (I.length >= t) {
|
|
162
|
+
z(e);
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
},
|
|
167
|
-
if (
|
|
165
|
+
ze(e);
|
|
166
|
+
}, qe = (n) => {
|
|
167
|
+
if (I = [], X = 0, A && (clearTimeout(A), A = null), typeof document > "u")
|
|
168
168
|
return;
|
|
169
|
-
|
|
170
|
-
const e = () =>
|
|
171
|
-
|
|
169
|
+
B && document.removeEventListener("visibilitychange", B), U && window.removeEventListener("pagehide", U);
|
|
170
|
+
const e = () => z(n, !0);
|
|
171
|
+
B = () => {
|
|
172
172
|
document.visibilityState === "hidden" && e();
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
let
|
|
176
|
-
const
|
|
177
|
-
typeof window > "u" || (
|
|
173
|
+
}, U = e, document.addEventListener("visibilitychange", B), window.addEventListener("pagehide", U);
|
|
174
|
+
}, ee = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
175
|
+
let te = null, se = null;
|
|
176
|
+
const $e = (n) => {
|
|
177
|
+
typeof window > "u" || (te = (e) => {
|
|
178
178
|
const t = e.error instanceof Error ? e.error : new Error(e.message);
|
|
179
|
-
|
|
179
|
+
P({
|
|
180
180
|
type: "exception",
|
|
181
181
|
payload: {
|
|
182
182
|
type: t.name,
|
|
183
183
|
value: t.message,
|
|
184
|
-
timestamp:
|
|
185
|
-
stacktrace: t.stack ? { frames:
|
|
184
|
+
timestamp: ee(),
|
|
185
|
+
stacktrace: t.stack ? { frames: W(t.stack) } : void 0
|
|
186
186
|
}
|
|
187
187
|
}, n);
|
|
188
|
-
},
|
|
188
|
+
}, se = (e) => {
|
|
189
189
|
const t = e.reason, s = t instanceof Error ? t : new Error(String(t));
|
|
190
|
-
|
|
190
|
+
P({
|
|
191
191
|
type: "exception",
|
|
192
192
|
payload: {
|
|
193
193
|
type: s.name,
|
|
194
194
|
value: s.message,
|
|
195
|
-
timestamp:
|
|
196
|
-
stacktrace: s.stack ? { frames:
|
|
195
|
+
timestamp: ee(),
|
|
196
|
+
stacktrace: s.stack ? { frames: W(s.stack) } : void 0,
|
|
197
197
|
context: { source: "unhandledrejection" }
|
|
198
198
|
}
|
|
199
199
|
}, n);
|
|
200
|
-
}, window.addEventListener("error",
|
|
201
|
-
},
|
|
200
|
+
}, window.addEventListener("error", te), window.addEventListener("unhandledrejection", se));
|
|
201
|
+
}, ne = "odus_telemetry_session_id", K = () => {
|
|
202
202
|
const n = new Uint8Array(16);
|
|
203
203
|
return crypto.getRandomValues(n), Array.from(n, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
204
|
-
},
|
|
204
|
+
}, Ye = (n) => {
|
|
205
205
|
if (n)
|
|
206
206
|
return n;
|
|
207
207
|
if (typeof sessionStorage > "u")
|
|
208
|
-
return
|
|
208
|
+
return K();
|
|
209
209
|
try {
|
|
210
|
-
const e = sessionStorage.getItem(
|
|
210
|
+
const e = sessionStorage.getItem(ne);
|
|
211
211
|
if (e)
|
|
212
212
|
return e;
|
|
213
|
-
const t =
|
|
214
|
-
return sessionStorage.setItem(
|
|
213
|
+
const t = K();
|
|
214
|
+
return sessionStorage.setItem(ne, t), t;
|
|
215
215
|
} catch {
|
|
216
|
-
return
|
|
216
|
+
return K();
|
|
217
217
|
}
|
|
218
|
-
},
|
|
218
|
+
}, We = (n) => {
|
|
219
219
|
if (!n.sessionTracking?.enabled)
|
|
220
220
|
return;
|
|
221
|
-
const e =
|
|
222
|
-
|
|
223
|
-
},
|
|
221
|
+
const e = Ye(n.sessionTracking.session?.id);
|
|
222
|
+
Be({ id: e });
|
|
223
|
+
}, q = () => (/* @__PURE__ */ new Date()).toISOString(), $ = (n, e) => {
|
|
224
224
|
if (typeof PerformanceObserver > "u" || !PerformanceObserver.supportedEntryTypes?.includes(n))
|
|
225
225
|
return;
|
|
226
226
|
new PerformanceObserver((s) => {
|
|
227
|
-
for (const
|
|
228
|
-
e(
|
|
227
|
+
for (const a of s.getEntries())
|
|
228
|
+
e(a);
|
|
229
229
|
}).observe({ type: n, buffered: !0 });
|
|
230
|
-
},
|
|
230
|
+
}, Ze = (n) => {
|
|
231
231
|
if (typeof window > "u")
|
|
232
232
|
return;
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
$("largest-contentful-paint", (t) => {
|
|
234
|
+
P({
|
|
235
235
|
type: "measurement",
|
|
236
236
|
payload: {
|
|
237
237
|
type: "web-vitals",
|
|
238
238
|
values: { lcp: t.startTime },
|
|
239
|
-
timestamp:
|
|
239
|
+
timestamp: q()
|
|
240
240
|
}
|
|
241
241
|
}, n);
|
|
242
242
|
});
|
|
243
243
|
let e = 0;
|
|
244
|
-
|
|
244
|
+
$("layout-shift", (t) => {
|
|
245
245
|
const s = t;
|
|
246
|
-
s.hadRecentInput || (e += s.value,
|
|
246
|
+
s.hadRecentInput || (e += s.value, P({
|
|
247
247
|
type: "measurement",
|
|
248
248
|
payload: {
|
|
249
249
|
type: "web-vitals",
|
|
250
250
|
values: { cls: e },
|
|
251
|
-
timestamp:
|
|
251
|
+
timestamp: q()
|
|
252
252
|
}
|
|
253
253
|
}, n));
|
|
254
|
-
}),
|
|
254
|
+
}), $("event", (t) => {
|
|
255
255
|
const s = t;
|
|
256
|
-
s.duration > 0 &&
|
|
256
|
+
s.duration > 0 && P({
|
|
257
257
|
type: "measurement",
|
|
258
258
|
payload: {
|
|
259
259
|
type: "web-vitals",
|
|
260
260
|
values: { inp: s.duration },
|
|
261
|
-
timestamp:
|
|
261
|
+
timestamp: q()
|
|
262
262
|
}
|
|
263
263
|
}, n);
|
|
264
264
|
});
|
|
265
|
-
},
|
|
265
|
+
}, R = {
|
|
266
266
|
INFO: "info",
|
|
267
267
|
WARN: "warn",
|
|
268
268
|
ERROR: "error"
|
|
269
|
-
},
|
|
270
|
-
|
|
269
|
+
}, x = () => (/* @__PURE__ */ new Date()).toISOString(), Ge = (n) => {
|
|
270
|
+
Te(n), qe(n);
|
|
271
271
|
const e = n.instrumentations ?? {
|
|
272
272
|
errors: !0,
|
|
273
273
|
webVitals: !0,
|
|
274
274
|
session: !0
|
|
275
275
|
};
|
|
276
|
-
return e.session !== !1 &&
|
|
276
|
+
return e.session !== !1 && We(n), e.errors !== !1 && $e(n), e.webVitals !== !1 && Ze(n), {
|
|
277
277
|
pushError(t, s) {
|
|
278
|
-
|
|
278
|
+
P({
|
|
279
279
|
type: "exception",
|
|
280
280
|
payload: {
|
|
281
281
|
type: t.name,
|
|
282
282
|
value: t.message,
|
|
283
|
-
timestamp:
|
|
284
|
-
stacktrace: t.stack ? { frames:
|
|
283
|
+
timestamp: x(),
|
|
284
|
+
stacktrace: t.stack ? { frames: W(t.stack) } : void 0,
|
|
285
285
|
context: s?.context
|
|
286
286
|
}
|
|
287
287
|
}, n);
|
|
288
288
|
},
|
|
289
289
|
pushEvent(t, s) {
|
|
290
|
-
|
|
290
|
+
P({
|
|
291
291
|
type: "event",
|
|
292
292
|
payload: {
|
|
293
293
|
name: t,
|
|
294
|
-
timestamp:
|
|
294
|
+
timestamp: x(),
|
|
295
295
|
attributes: s
|
|
296
296
|
}
|
|
297
297
|
}, n);
|
|
298
298
|
},
|
|
299
299
|
pushMeasurement(t) {
|
|
300
|
-
|
|
300
|
+
P({
|
|
301
301
|
type: "measurement",
|
|
302
302
|
payload: {
|
|
303
303
|
type: t.type,
|
|
304
304
|
values: t.values,
|
|
305
|
-
timestamp:
|
|
305
|
+
timestamp: x(),
|
|
306
306
|
context: t.context
|
|
307
307
|
}
|
|
308
308
|
}, n);
|
|
309
309
|
},
|
|
310
310
|
pushLog(t, s) {
|
|
311
|
-
|
|
311
|
+
P({
|
|
312
312
|
type: "log",
|
|
313
313
|
payload: {
|
|
314
314
|
message: t.join(" "),
|
|
315
|
-
level: s?.level ??
|
|
316
|
-
timestamp:
|
|
315
|
+
level: s?.level ?? R.INFO,
|
|
316
|
+
timestamp: x(),
|
|
317
317
|
context: s?.context
|
|
318
318
|
}
|
|
319
319
|
}, n);
|
|
320
320
|
},
|
|
321
321
|
setUser(t) {
|
|
322
|
-
|
|
322
|
+
Le(t);
|
|
323
323
|
},
|
|
324
324
|
resetUser() {
|
|
325
|
-
|
|
325
|
+
_e();
|
|
326
326
|
},
|
|
327
327
|
setView(t) {
|
|
328
|
-
|
|
328
|
+
Ue(t);
|
|
329
329
|
},
|
|
330
330
|
flush() {
|
|
331
|
-
|
|
331
|
+
z(n);
|
|
332
332
|
}
|
|
333
333
|
};
|
|
334
|
-
},
|
|
334
|
+
}, Xe = (n) => n === "test" ? "https://sandbox-analytics.odus.com/collect" : "https://analytics.odus.com/collect", Qe = () => {
|
|
335
335
|
if (typeof window > "u")
|
|
336
336
|
return !1;
|
|
337
337
|
const n = window.location.hostname;
|
|
338
338
|
return n === "localhost" || n === "127.0.0.1" || n === "0.0.0.0" || n === "::1" || n === "[::1]" || n.endsWith(".localhost");
|
|
339
339
|
};
|
|
340
340
|
let F = null;
|
|
341
|
-
const
|
|
341
|
+
const Je = (n) => {
|
|
342
342
|
if (F)
|
|
343
343
|
return F;
|
|
344
|
-
if (
|
|
344
|
+
if (Qe())
|
|
345
345
|
return null;
|
|
346
|
-
const e =
|
|
347
|
-
return F =
|
|
346
|
+
const e = Xe(n.environment);
|
|
347
|
+
return F = Ge({
|
|
348
348
|
url: e,
|
|
349
349
|
app: {
|
|
350
350
|
name: "odus-checkout",
|
|
@@ -368,19 +368,19 @@ const Qe = (n) => {
|
|
|
368
368
|
"card",
|
|
369
369
|
"cvv",
|
|
370
370
|
"pan"
|
|
371
|
-
].forEach((
|
|
372
|
-
s.searchParams.has(
|
|
371
|
+
].forEach((i) => {
|
|
372
|
+
s.searchParams.has(i) && s.searchParams.set(i, "[REDACTED]");
|
|
373
373
|
}), t.meta.view.name = s.toString();
|
|
374
374
|
} catch {
|
|
375
375
|
}
|
|
376
376
|
return t;
|
|
377
377
|
}
|
|
378
378
|
}), F;
|
|
379
|
-
},
|
|
379
|
+
}, et = (n, e) => {
|
|
380
380
|
F && F.pushError(n, { context: e });
|
|
381
|
-
},
|
|
381
|
+
}, M = (n, e) => {
|
|
382
382
|
F && F.pushEvent(n, e);
|
|
383
|
-
},
|
|
383
|
+
}, ae = (n, e, t, s) => {
|
|
384
384
|
F && F.pushMeasurement({
|
|
385
385
|
type: n,
|
|
386
386
|
values: { [n]: e },
|
|
@@ -389,19 +389,19 @@ const Qe = (n) => {
|
|
|
389
389
|
...s
|
|
390
390
|
}
|
|
391
391
|
});
|
|
392
|
-
},
|
|
392
|
+
}, St = (n, e = "info", t) => {
|
|
393
393
|
if (!F) return;
|
|
394
394
|
const s = {
|
|
395
|
-
info:
|
|
396
|
-
warn:
|
|
397
|
-
error:
|
|
395
|
+
info: R.INFO,
|
|
396
|
+
warn: R.WARN,
|
|
397
|
+
error: R.ERROR
|
|
398
398
|
};
|
|
399
399
|
F.pushLog([n], {
|
|
400
400
|
level: s[e],
|
|
401
401
|
context: t
|
|
402
402
|
});
|
|
403
403
|
};
|
|
404
|
-
function
|
|
404
|
+
function Y(n) {
|
|
405
405
|
return {
|
|
406
406
|
name: "Custom Appearance",
|
|
407
407
|
additionalPaymentMethods: n.additionalPaymentMethods || {},
|
|
@@ -437,7 +437,7 @@ function K(n) {
|
|
|
437
437
|
state: {
|
|
438
438
|
enabled: n.layout?.billingFields?.state?.enabled ?? !1,
|
|
439
439
|
label: n.layout?.billingFields?.state?.label,
|
|
440
|
-
|
|
440
|
+
hiddenForCountries: n.layout?.billingFields?.state?.hiddenForCountries
|
|
441
441
|
},
|
|
442
442
|
zipCode: {
|
|
443
443
|
enabled: n.layout?.billingFields?.zipCode?.enabled ?? !1,
|
|
@@ -477,7 +477,7 @@ function K(n) {
|
|
|
477
477
|
state: {
|
|
478
478
|
enabled: n.layout.shippingFields.state?.enabled ?? !1,
|
|
479
479
|
label: n.layout.shippingFields.state?.label,
|
|
480
|
-
|
|
480
|
+
hiddenForCountries: n.layout.shippingFields.state?.hiddenForCountries
|
|
481
481
|
},
|
|
482
482
|
zipCode: {
|
|
483
483
|
enabled: n.layout.shippingFields.zipCode?.enabled ?? !1,
|
|
@@ -501,16 +501,16 @@ function K(n) {
|
|
|
501
501
|
}
|
|
502
502
|
};
|
|
503
503
|
}
|
|
504
|
-
function
|
|
504
|
+
function tt({
|
|
505
505
|
appearance: n
|
|
506
506
|
}) {
|
|
507
|
-
const e =
|
|
507
|
+
const e = le({
|
|
508
508
|
checkoutProfile: void 0,
|
|
509
509
|
isLoading: !0,
|
|
510
510
|
error: null
|
|
511
511
|
});
|
|
512
512
|
if (n) {
|
|
513
|
-
const s =
|
|
513
|
+
const s = Y(n);
|
|
514
514
|
return Promise.resolve().then(() => {
|
|
515
515
|
e.setState({
|
|
516
516
|
checkoutProfile: s,
|
|
@@ -520,10 +520,10 @@ function et({
|
|
|
520
520
|
}), {
|
|
521
521
|
getState: e.getState.bind(e),
|
|
522
522
|
subscribe: e.subscribe.bind(e),
|
|
523
|
-
updateProfile: (
|
|
524
|
-
const
|
|
523
|
+
updateProfile: (a) => {
|
|
524
|
+
const i = Y(a);
|
|
525
525
|
e.setState({
|
|
526
|
-
checkoutProfile:
|
|
526
|
+
checkoutProfile: i,
|
|
527
527
|
isLoading: !1,
|
|
528
528
|
error: null
|
|
529
529
|
});
|
|
@@ -570,9 +570,9 @@ function et({
|
|
|
570
570
|
getState: e.getState.bind(e),
|
|
571
571
|
subscribe: e.subscribe.bind(e),
|
|
572
572
|
updateProfile: (s) => {
|
|
573
|
-
const
|
|
573
|
+
const a = Y(s);
|
|
574
574
|
e.setState({
|
|
575
|
-
checkoutProfile:
|
|
575
|
+
checkoutProfile: a,
|
|
576
576
|
isLoading: !1,
|
|
577
577
|
error: null
|
|
578
578
|
});
|
|
@@ -581,8 +581,8 @@ function et({
|
|
|
581
581
|
}
|
|
582
582
|
};
|
|
583
583
|
}
|
|
584
|
-
const
|
|
585
|
-
const n =
|
|
584
|
+
const st = () => {
|
|
585
|
+
const n = he(), e = le({
|
|
586
586
|
formData: {
|
|
587
587
|
name: "",
|
|
588
588
|
email: "",
|
|
@@ -599,185 +599,204 @@ const tt = () => {
|
|
|
599
599
|
cardCvv: !1
|
|
600
600
|
},
|
|
601
601
|
isValid: !1
|
|
602
|
-
}), t = (o,
|
|
602
|
+
}), t = (o, u, g, m) => {
|
|
603
603
|
if (o === "cardCvv")
|
|
604
|
-
return n.cardCvv(
|
|
605
|
-
if (o === "phoneNumber" &&
|
|
606
|
-
return n.phoneNumber(
|
|
604
|
+
return n.cardCvv(u, g);
|
|
605
|
+
if (o === "phoneNumber" && m)
|
|
606
|
+
return n.phoneNumber(u, m);
|
|
607
607
|
const p = n[o];
|
|
608
|
-
return p?.(
|
|
608
|
+
return p?.(u);
|
|
609
609
|
}, s = (o) => {
|
|
610
|
-
const
|
|
611
|
-
return Object.keys(o).forEach((
|
|
612
|
-
const p = o[
|
|
610
|
+
const u = {};
|
|
611
|
+
return Object.keys(o).forEach((m) => {
|
|
612
|
+
const p = o[m];
|
|
613
613
|
if (p === void 0) return;
|
|
614
614
|
let c;
|
|
615
|
-
|
|
616
|
-
|
|
615
|
+
m === "cardCvv" ? c = t(m, p, o.cardNumber) : m === "phoneNumber" ? c = t(
|
|
616
|
+
m,
|
|
617
617
|
p,
|
|
618
618
|
void 0,
|
|
619
619
|
o.phoneCountryCode
|
|
620
|
-
) : c = t(
|
|
620
|
+
) : c = t(m, p), c && (u[m] = c);
|
|
621
621
|
}), [
|
|
622
622
|
"billingAddress",
|
|
623
623
|
"shippingAddress"
|
|
624
|
-
].forEach((
|
|
625
|
-
const p = o[
|
|
624
|
+
].forEach((m) => {
|
|
625
|
+
const p = o[m];
|
|
626
626
|
if (p && typeof p == "object") {
|
|
627
627
|
const c = {};
|
|
628
628
|
Object.keys(p).forEach(
|
|
629
|
-
(
|
|
630
|
-
const
|
|
631
|
-
if (
|
|
632
|
-
const
|
|
633
|
-
if (
|
|
634
|
-
const
|
|
635
|
-
|
|
629
|
+
(f) => {
|
|
630
|
+
const y = p[f];
|
|
631
|
+
if (y === void 0) return;
|
|
632
|
+
const b = n[f];
|
|
633
|
+
if (b) {
|
|
634
|
+
const C = f === "state" ? n.state(y, p.country) : b(
|
|
635
|
+
y
|
|
636
|
+
);
|
|
637
|
+
C && (c[f] = C);
|
|
636
638
|
}
|
|
637
639
|
}
|
|
638
|
-
), Object.keys(c).length > 0 && (
|
|
640
|
+
), Object.keys(c).length > 0 && (u[m] = c);
|
|
639
641
|
}
|
|
640
|
-
}),
|
|
641
|
-
},
|
|
642
|
-
const
|
|
643
|
-
return Object.keys(
|
|
644
|
-
},
|
|
642
|
+
}), u;
|
|
643
|
+
}, a = (o) => {
|
|
644
|
+
const u = s(o);
|
|
645
|
+
return Object.keys(u).length === 0;
|
|
646
|
+
}, i = "billingAddress.", r = "shippingAddress.", l = (o) => o.startsWith(i) ? {
|
|
645
647
|
parent: "billingAddress",
|
|
646
|
-
field: o.slice(
|
|
648
|
+
field: o.slice(i.length)
|
|
647
649
|
} : o.startsWith(r) ? {
|
|
648
650
|
parent: "shippingAddress",
|
|
649
651
|
field: o.slice(r.length)
|
|
650
|
-
} : null,
|
|
652
|
+
} : null, d = (o, u, g, m) => {
|
|
651
653
|
const p = { ...o };
|
|
652
|
-
if (
|
|
653
|
-
p[
|
|
654
|
-
...p[
|
|
655
|
-
[
|
|
654
|
+
if (m)
|
|
655
|
+
p[u] = {
|
|
656
|
+
...p[u],
|
|
657
|
+
[g]: m
|
|
656
658
|
};
|
|
657
659
|
else {
|
|
658
660
|
const c = {
|
|
659
|
-
...p[
|
|
661
|
+
...p[u]
|
|
660
662
|
};
|
|
661
|
-
delete c[
|
|
663
|
+
delete c[g], Object.keys(c).length === 0 ? delete p[u] : p[u] = c;
|
|
662
664
|
}
|
|
663
665
|
return p;
|
|
664
|
-
},
|
|
665
|
-
const
|
|
666
|
-
let
|
|
667
|
-
const p =
|
|
668
|
-
if (!p && o in
|
|
666
|
+
}, h = (o, u) => {
|
|
667
|
+
const g = e.getState();
|
|
668
|
+
let m = u;
|
|
669
|
+
const p = l(o);
|
|
670
|
+
if (!p && o in j)
|
|
669
671
|
if (o === "cardCvv") {
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
+
const b = ue(g.formData.cardNumber) === "amex" ? 4 : 3;
|
|
673
|
+
m = j.cardCvv(u, b);
|
|
672
674
|
} else
|
|
673
|
-
|
|
675
|
+
m = j[o](u);
|
|
674
676
|
let c;
|
|
675
677
|
if (p) {
|
|
676
|
-
const { parent:
|
|
678
|
+
const { parent: y, field: b } = p;
|
|
677
679
|
c = {
|
|
678
|
-
...
|
|
679
|
-
[
|
|
680
|
-
...
|
|
681
|
-
[
|
|
680
|
+
...g.formData,
|
|
681
|
+
[y]: {
|
|
682
|
+
...g.formData[y] ?? {},
|
|
683
|
+
[b]: m
|
|
682
684
|
}
|
|
683
685
|
};
|
|
684
686
|
} else
|
|
685
687
|
c = {
|
|
686
|
-
...
|
|
687
|
-
[o]:
|
|
688
|
+
...g.formData,
|
|
689
|
+
[o]: m
|
|
688
690
|
};
|
|
689
|
-
let
|
|
691
|
+
let f = { ...g.errors };
|
|
690
692
|
if (o === "phoneCountryCode" && c.phoneNumber) {
|
|
691
|
-
const
|
|
693
|
+
const y = t(
|
|
692
694
|
"phoneNumber",
|
|
693
695
|
c.phoneNumber,
|
|
694
696
|
void 0,
|
|
695
|
-
|
|
697
|
+
m
|
|
696
698
|
);
|
|
697
|
-
|
|
699
|
+
y ? f.phoneNumber = y : delete f.phoneNumber;
|
|
698
700
|
}
|
|
699
|
-
if (
|
|
701
|
+
if (g.touched[o])
|
|
700
702
|
if (p) {
|
|
701
|
-
const { parent:
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
703
|
+
const { parent: y, field: b } = p, C = c[y];
|
|
704
|
+
let N;
|
|
705
|
+
if (b === "state")
|
|
706
|
+
N = n.state(m, C?.country);
|
|
707
|
+
else {
|
|
708
|
+
const T = n[b];
|
|
709
|
+
N = T ? T(
|
|
710
|
+
m
|
|
711
|
+
) : void 0;
|
|
712
|
+
}
|
|
713
|
+
f = d(f, y, b, N);
|
|
705
714
|
} else {
|
|
706
|
-
let
|
|
707
|
-
o === "cardCvv" ?
|
|
715
|
+
let y;
|
|
716
|
+
o === "cardCvv" ? y = t(o, m, c.cardNumber) : o === "phoneNumber" ? y = t(
|
|
708
717
|
o,
|
|
709
|
-
|
|
718
|
+
m,
|
|
710
719
|
void 0,
|
|
711
720
|
c.phoneCountryCode
|
|
712
|
-
) :
|
|
721
|
+
) : y = t(o, m), y ? f[o] = y : delete f[o];
|
|
713
722
|
}
|
|
714
723
|
e.setState({
|
|
715
724
|
formData: c,
|
|
716
|
-
errors:
|
|
717
|
-
isValid:
|
|
725
|
+
errors: f,
|
|
726
|
+
isValid: a(c)
|
|
718
727
|
});
|
|
719
|
-
}, E = (o,
|
|
720
|
-
const
|
|
721
|
-
if (
|
|
722
|
-
const { parent:
|
|
723
|
-
...
|
|
724
|
-
[
|
|
725
|
-
...
|
|
726
|
-
[
|
|
728
|
+
}, E = (o, u) => {
|
|
729
|
+
const g = e.getState(), m = l(o);
|
|
730
|
+
if (m) {
|
|
731
|
+
const { parent: y, field: b } = m, C = {
|
|
732
|
+
...g.formData,
|
|
733
|
+
[y]: {
|
|
734
|
+
...g.formData[y] ?? {},
|
|
735
|
+
[b]: u
|
|
727
736
|
}
|
|
728
|
-
}
|
|
737
|
+
};
|
|
738
|
+
let N;
|
|
739
|
+
if (b === "state") {
|
|
740
|
+
const L = C[y];
|
|
741
|
+
N = n.state(u, L?.country);
|
|
742
|
+
} else {
|
|
743
|
+
const L = n[b];
|
|
744
|
+
N = L ? L(u) : void 0;
|
|
745
|
+
}
|
|
746
|
+
const T = d(g.errors, y, b, N);
|
|
729
747
|
e.setState({
|
|
730
|
-
formData:
|
|
748
|
+
formData: C,
|
|
731
749
|
touched: {
|
|
732
|
-
...
|
|
750
|
+
...g.touched,
|
|
733
751
|
[o]: !0
|
|
734
752
|
},
|
|
735
|
-
errors:
|
|
736
|
-
isValid:
|
|
753
|
+
errors: T,
|
|
754
|
+
isValid: a(C)
|
|
737
755
|
});
|
|
738
756
|
return;
|
|
739
757
|
}
|
|
740
758
|
const p = {
|
|
741
|
-
...
|
|
759
|
+
...g.touched,
|
|
742
760
|
[o]: !0
|
|
743
761
|
};
|
|
744
762
|
let c;
|
|
745
|
-
o === "cardCvv" ? c = t(o,
|
|
763
|
+
o === "cardCvv" ? c = t(o, u, g.formData.cardNumber) : o === "phoneNumber" ? c = t(
|
|
746
764
|
o,
|
|
747
|
-
|
|
765
|
+
u,
|
|
748
766
|
void 0,
|
|
749
|
-
|
|
750
|
-
) : c = t(o,
|
|
751
|
-
const
|
|
752
|
-
c ?
|
|
767
|
+
g.formData.phoneCountryCode
|
|
768
|
+
) : c = t(o, u);
|
|
769
|
+
const f = { ...g.errors };
|
|
770
|
+
c ? f[o] = c : delete f[o], e.setState({
|
|
753
771
|
touched: p,
|
|
754
|
-
errors:
|
|
772
|
+
errors: f
|
|
755
773
|
});
|
|
756
|
-
},
|
|
757
|
-
const
|
|
774
|
+
}, S = (o) => {
|
|
775
|
+
const g = {
|
|
758
776
|
...e.getState().formData,
|
|
759
777
|
...o
|
|
760
778
|
};
|
|
761
779
|
e.setState({
|
|
762
|
-
formData:
|
|
763
|
-
isValid:
|
|
780
|
+
formData: g,
|
|
781
|
+
isValid: a(g)
|
|
764
782
|
});
|
|
765
783
|
};
|
|
766
784
|
return {
|
|
767
785
|
getFormState: e.getState.bind(e),
|
|
768
786
|
subscribe: e.subscribe.bind(e),
|
|
769
|
-
handleChange:
|
|
787
|
+
handleChange: h,
|
|
770
788
|
handleBlur: E,
|
|
771
|
-
setFormData:
|
|
789
|
+
setFormData: S,
|
|
772
790
|
reset: e.resetState.bind(e)
|
|
773
791
|
};
|
|
774
792
|
};
|
|
775
|
-
function
|
|
793
|
+
function Z(n) {
|
|
776
794
|
if (!n) return !1;
|
|
777
|
-
const { billingFields: e, shippingFields: t } = n, s = e && Object.values(e).some((
|
|
778
|
-
return !!(s ||
|
|
795
|
+
const { billingFields: e, shippingFields: t } = n, s = e && Object.values(e).some((i) => i?.enabled), a = t && Object.values(t).some((i) => i?.enabled);
|
|
796
|
+
return !!(s || a);
|
|
779
797
|
}
|
|
780
|
-
|
|
798
|
+
const O = /* @__PURE__ */ new Set(["US", "CA"]);
|
|
799
|
+
class ie extends w {
|
|
781
800
|
inputs = /* @__PURE__ */ new Map();
|
|
782
801
|
type;
|
|
783
802
|
onChange;
|
|
@@ -785,161 +804,165 @@ class se extends A {
|
|
|
785
804
|
fieldsContainer;
|
|
786
805
|
translationFunc;
|
|
787
806
|
locale;
|
|
788
|
-
stateOptions;
|
|
789
807
|
grouped;
|
|
808
|
+
currentCountry = "";
|
|
809
|
+
stateRow = null;
|
|
810
|
+
stateFieldConfig;
|
|
811
|
+
stateStyles;
|
|
790
812
|
constructor(e) {
|
|
791
813
|
super("div", ["address-section"]), this.type = e.type, this.onChange = e.onChange, this.onBlur = e.onBlur, this.translationFunc = e.translationFunc, this.locale = e.locale, this.grouped = e.grouped ?? !0;
|
|
792
|
-
const { title: t, checkoutProfile: s, fieldsConfig:
|
|
814
|
+
const { title: t, checkoutProfile: s, fieldsConfig: a, values: i, errors: r, touched: l } = e;
|
|
793
815
|
if (this.grouped) {
|
|
794
|
-
const
|
|
795
|
-
|
|
816
|
+
const d = document.createElement("h3");
|
|
817
|
+
d.className = "address-section-title", d.textContent = t, d.style.color = s.styles.textColor, d.style.fontFamily = `"${s.styles.fontFamily}", sans-serif`, d.style.fontSize = `${s.styles.fontSize}px`, d.style.fontWeight = "normal", this.getElement().appendChild(d);
|
|
796
818
|
}
|
|
797
|
-
this.fieldsContainer = document.createElement("div"), this.fieldsContainer.className = "address-fields", this.grouped || this.fieldsContainer.classList.add("address-fields--ungrouped"), this.getElement().appendChild(this.fieldsContainer), this.createFields(s,
|
|
819
|
+
this.fieldsContainer = document.createElement("div"), this.fieldsContainer.className = "address-fields", this.grouped || this.fieldsContainer.classList.add("address-fields--ungrouped"), this.getElement().appendChild(this.fieldsContainer), this.createFields(s, a, i, r, l);
|
|
798
820
|
}
|
|
799
|
-
borderRadius(e, t, s,
|
|
800
|
-
const r = (
|
|
801
|
-
return `${r(t)} ${r(s)} ${r(
|
|
821
|
+
borderRadius(e, t, s, a, i) {
|
|
822
|
+
const r = (l) => l ? `${e}px` : "0px";
|
|
823
|
+
return `${r(t)} ${r(s)} ${r(a)} ${r(i)}`;
|
|
802
824
|
}
|
|
803
|
-
createFields(e, t, s,
|
|
825
|
+
createFields(e, t, s, a, i) {
|
|
804
826
|
if (!this.grouped) {
|
|
805
827
|
this.createUngroupedFields(
|
|
806
828
|
e,
|
|
807
829
|
t,
|
|
808
830
|
s,
|
|
809
|
-
|
|
810
|
-
|
|
831
|
+
a,
|
|
832
|
+
i
|
|
811
833
|
);
|
|
812
834
|
return;
|
|
813
835
|
}
|
|
814
|
-
const r = e.styles.borderRadius,
|
|
836
|
+
const r = e.styles.borderRadius, l = {
|
|
815
837
|
color: e.styles.textColor,
|
|
816
838
|
fontSize: e.styles.fontSize,
|
|
817
839
|
fontFamily: e.styles.fontFamily
|
|
818
|
-
},
|
|
819
|
-
t.street?.enabled &&
|
|
820
|
-
const
|
|
821
|
-
t.firstName?.enabled &&
|
|
840
|
+
}, d = [];
|
|
841
|
+
t.street?.enabled && d.push({ kind: "street" });
|
|
842
|
+
const h = [];
|
|
843
|
+
t.firstName?.enabled && h.push("firstName"), t.lastName?.enabled && h.push("lastName"), h.length > 0 && d.push({ kind: "name", fields: h }), t.country?.enabled && d.push({ kind: "country" });
|
|
822
844
|
const E = [];
|
|
823
|
-
t.city?.enabled && E.push("city"), t.zipCode?.enabled && E.push("zipCode"), E.length > 0 &&
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
const
|
|
827
|
-
...
|
|
845
|
+
t.city?.enabled && E.push("city"), t.zipCode?.enabled && E.push("zipCode"), E.length > 0 && d.push({ kind: "cityZip", fields: E }), t.state?.enabled && d.push({ kind: "state" });
|
|
846
|
+
const S = d.length;
|
|
847
|
+
d.forEach((o, u) => {
|
|
848
|
+
const g = u === 0, m = u === S - 1, p = (c, f) => ({
|
|
849
|
+
...l,
|
|
828
850
|
borderRadius: this.borderRadius(
|
|
829
851
|
r,
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
852
|
+
g && c,
|
|
853
|
+
g && f,
|
|
854
|
+
m && f,
|
|
855
|
+
m && c
|
|
834
856
|
)
|
|
835
857
|
});
|
|
836
858
|
if (o.kind === "street") {
|
|
837
|
-
const c = this.createRow(["full"]),
|
|
859
|
+
const c = this.createRow(["full"]), f = this.createInput(
|
|
838
860
|
"street",
|
|
839
861
|
t.street?.label ?? this.translationFunc("address.addressLine1"),
|
|
840
862
|
s.street,
|
|
841
|
-
i.street,
|
|
842
863
|
a.street,
|
|
864
|
+
i.street,
|
|
843
865
|
p(!0, !0),
|
|
844
866
|
"street-address"
|
|
845
867
|
);
|
|
846
|
-
this.inputs.set("street",
|
|
868
|
+
this.inputs.set("street", f), c.appendChild(f.getElement()), this.fieldsContainer.appendChild(c);
|
|
847
869
|
return;
|
|
848
870
|
}
|
|
849
871
|
if (o.kind === "name") {
|
|
850
|
-
const c = this.createRow(o.fields.map(() => "half")),
|
|
872
|
+
const c = this.createRow(o.fields.map(() => "half")), f = o.fields.length === 1;
|
|
851
873
|
if (o.fields.includes("firstName")) {
|
|
852
|
-
const
|
|
874
|
+
const y = f || o.fields[o.fields.length - 1] === "firstName", b = this.createInput(
|
|
853
875
|
"firstName",
|
|
854
876
|
t.firstName?.label ?? this.translationFunc("address.firstName"),
|
|
855
877
|
s.firstName,
|
|
856
|
-
i.firstName,
|
|
857
878
|
a.firstName,
|
|
858
|
-
|
|
879
|
+
i.firstName,
|
|
880
|
+
p(!0, y),
|
|
859
881
|
"given-name"
|
|
860
882
|
);
|
|
861
|
-
this.inputs.set("firstName",
|
|
883
|
+
this.inputs.set("firstName", b), c.appendChild(b.getElement());
|
|
862
884
|
}
|
|
863
885
|
if (o.fields.includes("lastName")) {
|
|
864
|
-
const
|
|
886
|
+
const y = f || o.fields[0] === "lastName", b = this.createInput(
|
|
865
887
|
"lastName",
|
|
866
888
|
t.lastName?.label ?? this.translationFunc("address.lastName"),
|
|
867
889
|
s.lastName,
|
|
868
|
-
i.lastName,
|
|
869
890
|
a.lastName,
|
|
870
|
-
|
|
891
|
+
i.lastName,
|
|
892
|
+
p(y, !0),
|
|
871
893
|
"family-name"
|
|
872
894
|
);
|
|
873
|
-
this.inputs.set("lastName",
|
|
895
|
+
this.inputs.set("lastName", b), c.appendChild(b.getElement());
|
|
874
896
|
}
|
|
875
897
|
this.fieldsContainer.appendChild(c);
|
|
876
898
|
return;
|
|
877
899
|
}
|
|
878
900
|
if (o.kind === "country") {
|
|
879
|
-
const c = this.createRow(["full"]),
|
|
901
|
+
const c = this.createRow(["full"]), f = this.createCountrySelect(
|
|
880
902
|
s.country,
|
|
881
|
-
i.country,
|
|
882
903
|
a.country,
|
|
904
|
+
i.country,
|
|
883
905
|
p(!0, !0),
|
|
884
906
|
t.country?.options,
|
|
885
907
|
t.country?.label
|
|
886
908
|
);
|
|
887
|
-
this.inputs.set("country",
|
|
909
|
+
this.inputs.set("country", f), c.appendChild(f.getElement()), this.fieldsContainer.appendChild(c);
|
|
888
910
|
return;
|
|
889
911
|
}
|
|
890
912
|
if (o.kind === "cityZip") {
|
|
891
|
-
const c = this.createRow(o.fields.map(() => "half")),
|
|
913
|
+
const c = this.createRow(o.fields.map(() => "half")), f = o.fields.length === 1;
|
|
892
914
|
if (o.fields.includes("city")) {
|
|
893
|
-
const
|
|
915
|
+
const y = f || o.fields[o.fields.length - 1] === "city", b = this.createInput(
|
|
894
916
|
"city",
|
|
895
917
|
t.city?.label ?? this.translationFunc("address.townCity"),
|
|
896
918
|
s.city,
|
|
897
|
-
i.city,
|
|
898
919
|
a.city,
|
|
899
|
-
|
|
920
|
+
i.city,
|
|
921
|
+
p(!0, y),
|
|
900
922
|
"address-level2"
|
|
901
923
|
);
|
|
902
|
-
this.inputs.set("city",
|
|
924
|
+
this.inputs.set("city", b), c.appendChild(b.getElement());
|
|
903
925
|
}
|
|
904
926
|
if (o.fields.includes("zipCode")) {
|
|
905
|
-
const
|
|
927
|
+
const y = f || o.fields[0] === "zipCode", b = this.createInput(
|
|
906
928
|
"zipCode",
|
|
907
929
|
t.zipCode?.label ?? this.translationFunc("address.postalCode"),
|
|
908
930
|
s.zipCode,
|
|
909
|
-
i.zipCode,
|
|
910
931
|
a.zipCode,
|
|
911
|
-
|
|
932
|
+
i.zipCode,
|
|
933
|
+
p(y, !0),
|
|
912
934
|
"postal-code"
|
|
913
935
|
);
|
|
914
|
-
this.inputs.set("zipCode",
|
|
936
|
+
this.inputs.set("zipCode", b), c.appendChild(b.getElement());
|
|
915
937
|
}
|
|
916
938
|
this.fieldsContainer.appendChild(c);
|
|
917
939
|
return;
|
|
918
940
|
}
|
|
919
941
|
if (o.kind === "state") {
|
|
920
942
|
const c = this.createRow(["full"]);
|
|
921
|
-
if (this.
|
|
922
|
-
|
|
943
|
+
if (this.stateFieldConfig = t.state, this.stateRow = c, this.stateStyles = p(!0, !0), this.currentCountry = s.country, t.state?.hiddenForCountries?.includes(
|
|
944
|
+
s.country
|
|
945
|
+
) && (c.style.display = "none"), O.has(s.country)) {
|
|
946
|
+
const b = this.createStateSelect(
|
|
923
947
|
s.state,
|
|
924
|
-
i.state,
|
|
925
948
|
a.state,
|
|
926
|
-
|
|
927
|
-
|
|
949
|
+
i.state,
|
|
950
|
+
this.stateStyles,
|
|
928
951
|
s.country,
|
|
929
952
|
t.state?.label
|
|
930
953
|
);
|
|
931
|
-
this.inputs.set("state",
|
|
954
|
+
this.inputs.set("state", b), c.appendChild(b.getElement());
|
|
932
955
|
} else {
|
|
933
|
-
const
|
|
956
|
+
const b = this.createInput(
|
|
934
957
|
"state",
|
|
935
|
-
t.state?.label ?? this.translationFunc("address.
|
|
958
|
+
t.state?.label ?? this.translationFunc("address.state"),
|
|
936
959
|
s.state,
|
|
937
|
-
i.state,
|
|
938
960
|
a.state,
|
|
939
|
-
|
|
961
|
+
i.state,
|
|
962
|
+
this.stateStyles,
|
|
940
963
|
"address-level1"
|
|
941
964
|
);
|
|
942
|
-
this.inputs.set("state",
|
|
965
|
+
this.inputs.set("state", b), c.appendChild(b.getElement());
|
|
943
966
|
}
|
|
944
967
|
this.fieldsContainer.appendChild(c);
|
|
945
968
|
}
|
|
@@ -949,181 +972,239 @@ class se extends A {
|
|
|
949
972
|
const t = document.createElement("div");
|
|
950
973
|
return t.className = `address-row address-row-${e.length === 1 ? "single" : "double"}`, t;
|
|
951
974
|
}
|
|
952
|
-
createInput(e, t, s,
|
|
953
|
-
const
|
|
954
|
-
name:
|
|
975
|
+
createInput(e, t, s, a, i, r, l) {
|
|
976
|
+
const d = `${this.type}Address.${e}`, h = new de({
|
|
977
|
+
name: d,
|
|
955
978
|
error: !1,
|
|
956
979
|
errorMsg: void 0,
|
|
957
980
|
styles: r,
|
|
958
981
|
...this.grouped ? { placeholder: t } : {
|
|
959
982
|
label: t,
|
|
960
983
|
placeholder: (() => {
|
|
961
|
-
const E = `address.placeholder.${e}`,
|
|
962
|
-
return
|
|
984
|
+
const E = `address.placeholder.${e}`, S = this.translationFunc(E);
|
|
985
|
+
return S !== E ? S : t;
|
|
963
986
|
})()
|
|
964
987
|
},
|
|
965
988
|
value: s,
|
|
966
|
-
autocomplete:
|
|
989
|
+
autocomplete: l,
|
|
967
990
|
onChange: (E) => {
|
|
968
|
-
|
|
969
|
-
const
|
|
970
|
-
Object.defineProperty(
|
|
991
|
+
h.setError(!1);
|
|
992
|
+
const S = new Event("input", { bubbles: !0 });
|
|
993
|
+
Object.defineProperty(S, "target", {
|
|
971
994
|
writable: !1,
|
|
972
995
|
value: {
|
|
973
|
-
name:
|
|
996
|
+
name: d,
|
|
974
997
|
value: E.target.value
|
|
975
998
|
}
|
|
976
|
-
}), this.onChange(
|
|
999
|
+
}), this.onChange(S);
|
|
977
1000
|
}
|
|
978
1001
|
});
|
|
979
|
-
return
|
|
980
|
-
const
|
|
981
|
-
Object.defineProperty(
|
|
1002
|
+
return h.addEventListener("blur", (E) => {
|
|
1003
|
+
const S = new Event("blur", { bubbles: !0 });
|
|
1004
|
+
Object.defineProperty(S, "target", {
|
|
982
1005
|
writable: !1,
|
|
983
1006
|
value: {
|
|
984
|
-
name:
|
|
1007
|
+
name: d,
|
|
985
1008
|
value: E.target.value
|
|
986
1009
|
}
|
|
987
|
-
}), this.onBlur(
|
|
988
|
-
}),
|
|
1010
|
+
}), this.onBlur(S);
|
|
1011
|
+
}), h;
|
|
989
1012
|
}
|
|
990
|
-
createCountrySelect(e, t, s,
|
|
991
|
-
const
|
|
992
|
-
name:
|
|
1013
|
+
createCountrySelect(e, t, s, a, i, r) {
|
|
1014
|
+
const l = `${this.type}Address.country`, d = me(i, this.locale), h = new _({
|
|
1015
|
+
name: l,
|
|
993
1016
|
error: !1,
|
|
994
1017
|
errorMsg: void 0,
|
|
995
|
-
styles:
|
|
1018
|
+
styles: a,
|
|
996
1019
|
placeholder: this.translationFunc("address.chooseCountry"),
|
|
997
1020
|
...!this.grouped && {
|
|
998
1021
|
label: r ?? this.translationFunc("address.chooseCountry")
|
|
999
1022
|
},
|
|
1000
1023
|
value: e,
|
|
1001
|
-
options:
|
|
1024
|
+
options: d,
|
|
1002
1025
|
autocomplete: "country",
|
|
1003
1026
|
onChange: (E) => {
|
|
1004
|
-
|
|
1005
|
-
const
|
|
1006
|
-
this.updateStateOptionsForCountry(y);
|
|
1007
|
-
const o = new Event("change", { bubbles: !0 });
|
|
1027
|
+
h.setError(!1);
|
|
1028
|
+
const S = E.target.value, o = new Event("change", { bubbles: !0 });
|
|
1008
1029
|
Object.defineProperty(o, "target", {
|
|
1009
1030
|
writable: !1,
|
|
1010
1031
|
value: {
|
|
1011
|
-
name:
|
|
1012
|
-
value:
|
|
1032
|
+
name: l,
|
|
1033
|
+
value: S
|
|
1013
1034
|
}
|
|
1014
|
-
}), this.onChange(o);
|
|
1035
|
+
}), this.onChange(o), this.handleCountryChange(S);
|
|
1015
1036
|
}
|
|
1016
1037
|
});
|
|
1017
|
-
return
|
|
1018
|
-
const
|
|
1019
|
-
Object.defineProperty(
|
|
1038
|
+
return h.addEventListener("blur", (E) => {
|
|
1039
|
+
const S = new Event("blur", { bubbles: !0 });
|
|
1040
|
+
Object.defineProperty(S, "target", {
|
|
1020
1041
|
writable: !1,
|
|
1021
1042
|
value: {
|
|
1022
|
-
name:
|
|
1043
|
+
name: l,
|
|
1023
1044
|
value: E.target.value
|
|
1024
1045
|
}
|
|
1025
|
-
}), this.onBlur(
|
|
1026
|
-
}),
|
|
1046
|
+
}), this.onBlur(S);
|
|
1047
|
+
}), h;
|
|
1048
|
+
}
|
|
1049
|
+
handleCountryChange(e) {
|
|
1050
|
+
const t = this.currentCountry;
|
|
1051
|
+
if (this.currentCountry = e, !this.stateRow || !this.stateFieldConfig?.enabled) return;
|
|
1052
|
+
const s = this.stateFieldConfig.hiddenForCountries?.includes(t), a = this.stateFieldConfig.hiddenForCountries?.includes(e);
|
|
1053
|
+
if (a && !s) {
|
|
1054
|
+
this.stateRow.style.display = "none", this.clearStateValue();
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
if (!a && s && (this.stateRow.style.display = ""), a) return;
|
|
1058
|
+
const i = this.inputs.get("state") instanceof _, r = O.has(e);
|
|
1059
|
+
if (i && r) {
|
|
1060
|
+
const l = this.inputs.get("state");
|
|
1061
|
+
if (l instanceof _) {
|
|
1062
|
+
const d = e === "CA" ? "CA" : "US", h = Q(d), E = d === "CA" ? this.translationFunc("address.chooseProvince") : this.translationFunc("address.chooseState");
|
|
1063
|
+
l.setOptions(h, E);
|
|
1064
|
+
}
|
|
1065
|
+
this.clearStateValue();
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
if (i !== r) {
|
|
1069
|
+
this.rebuildStateField(e), this.clearStateValue();
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
!i && !r && t !== e && this.clearStateValue();
|
|
1027
1073
|
}
|
|
1028
|
-
|
|
1074
|
+
rebuildStateField(e) {
|
|
1075
|
+
if (!this.stateRow || !this.stateStyles) return;
|
|
1029
1076
|
const t = this.inputs.get("state");
|
|
1030
|
-
if (
|
|
1031
|
-
|
|
1032
|
-
|
|
1077
|
+
if (t && (t.getElement().remove(), this.inputs.delete("state")), O.has(e)) {
|
|
1078
|
+
const a = this.createStateSelect(
|
|
1079
|
+
"",
|
|
1080
|
+
void 0,
|
|
1081
|
+
void 0,
|
|
1082
|
+
this.stateStyles,
|
|
1083
|
+
e,
|
|
1084
|
+
this.stateFieldConfig?.label
|
|
1085
|
+
);
|
|
1086
|
+
this.inputs.set("state", a), this.stateRow.appendChild(a.getElement());
|
|
1087
|
+
} else {
|
|
1088
|
+
const a = this.createInput(
|
|
1089
|
+
"state",
|
|
1090
|
+
this.stateFieldConfig?.label ?? this.translationFunc("address.state"),
|
|
1091
|
+
"",
|
|
1092
|
+
void 0,
|
|
1093
|
+
void 0,
|
|
1094
|
+
this.stateStyles,
|
|
1095
|
+
"address-level1"
|
|
1096
|
+
);
|
|
1097
|
+
this.inputs.set("state", a), this.stateRow.appendChild(a.getElement());
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
clearStateValue() {
|
|
1101
|
+
const e = this.inputs.get("state");
|
|
1102
|
+
e && e.setValue("");
|
|
1103
|
+
const t = `${this.type}Address.state`, s = new CustomEvent("input", {
|
|
1104
|
+
bubbles: !0,
|
|
1105
|
+
detail: { programmatic: !0 }
|
|
1106
|
+
});
|
|
1107
|
+
Object.defineProperty(s, "target", {
|
|
1108
|
+
writable: !1,
|
|
1109
|
+
value: { name: t, value: "" }
|
|
1110
|
+
}), this.onChange(s);
|
|
1033
1111
|
}
|
|
1034
|
-
createStateSelect(e, t, s,
|
|
1035
|
-
const l = `${this.type}Address.state`,
|
|
1112
|
+
createStateSelect(e, t, s, a, i, r) {
|
|
1113
|
+
const l = `${this.type}Address.state`, d = i === "CA" ? "CA" : "US", h = Q(d), E = d === "CA" ? this.translationFunc("address.chooseProvince") : this.translationFunc("address.chooseState"), S = new _({
|
|
1036
1114
|
name: l,
|
|
1037
1115
|
error: !1,
|
|
1038
1116
|
errorMsg: void 0,
|
|
1039
|
-
styles:
|
|
1040
|
-
placeholder:
|
|
1041
|
-
...!this.grouped && { label:
|
|
1117
|
+
styles: a,
|
|
1118
|
+
placeholder: E,
|
|
1119
|
+
...!this.grouped && { label: r ?? E },
|
|
1042
1120
|
value: e,
|
|
1043
|
-
options:
|
|
1121
|
+
options: h,
|
|
1044
1122
|
autocomplete: "address-level1",
|
|
1045
|
-
onChange: (
|
|
1046
|
-
|
|
1047
|
-
const
|
|
1048
|
-
Object.defineProperty(
|
|
1123
|
+
onChange: (o) => {
|
|
1124
|
+
S.setError(!1);
|
|
1125
|
+
const u = new Event("change", { bubbles: !0 });
|
|
1126
|
+
Object.defineProperty(u, "target", {
|
|
1049
1127
|
writable: !1,
|
|
1050
1128
|
value: {
|
|
1051
1129
|
name: l,
|
|
1052
|
-
value:
|
|
1130
|
+
value: o.target.value
|
|
1053
1131
|
}
|
|
1054
|
-
}), this.onChange(
|
|
1132
|
+
}), this.onChange(u);
|
|
1055
1133
|
}
|
|
1056
1134
|
});
|
|
1057
|
-
return
|
|
1058
|
-
const
|
|
1059
|
-
Object.defineProperty(
|
|
1135
|
+
return S.addEventListener("blur", (o) => {
|
|
1136
|
+
const u = new Event("blur", { bubbles: !0 });
|
|
1137
|
+
Object.defineProperty(u, "target", {
|
|
1060
1138
|
writable: !1,
|
|
1061
1139
|
value: {
|
|
1062
1140
|
name: l,
|
|
1063
|
-
value:
|
|
1141
|
+
value: o.target.value
|
|
1064
1142
|
}
|
|
1065
|
-
}), this.onBlur(
|
|
1066
|
-
}),
|
|
1143
|
+
}), this.onBlur(u);
|
|
1144
|
+
}), S;
|
|
1067
1145
|
}
|
|
1068
|
-
createUngroupedFields(e, t, s,
|
|
1069
|
-
const r = e.styles.borderRadius,
|
|
1146
|
+
createUngroupedFields(e, t, s, a, i) {
|
|
1147
|
+
const r = e.styles.borderRadius, l = {
|
|
1070
1148
|
color: e.styles.textColor,
|
|
1071
1149
|
fontSize: e.styles.fontSize,
|
|
1072
1150
|
fontFamily: e.styles.fontFamily,
|
|
1073
1151
|
borderRadius: `${r}px`
|
|
1074
|
-
},
|
|
1075
|
-
if (!t[
|
|
1076
|
-
const o = t[
|
|
1077
|
-
|
|
1152
|
+
}, d = (h, E, S) => {
|
|
1153
|
+
if (!t[h]?.enabled) return;
|
|
1154
|
+
const o = t[h]?.label ?? this.translationFunc(E), u = this.createRow(["full"]), g = this.createInput(
|
|
1155
|
+
h,
|
|
1078
1156
|
o,
|
|
1079
|
-
s[
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1157
|
+
s[h],
|
|
1158
|
+
a[h],
|
|
1159
|
+
i[h],
|
|
1160
|
+
l,
|
|
1161
|
+
S
|
|
1084
1162
|
);
|
|
1085
|
-
this.inputs.set(
|
|
1163
|
+
this.inputs.set(h, g), u.appendChild(g.getElement()), this.fieldsContainer.appendChild(u);
|
|
1086
1164
|
};
|
|
1087
|
-
if (
|
|
1088
|
-
const
|
|
1165
|
+
if (d("firstName", "address.firstName", "given-name"), d("lastName", "address.lastName", "family-name"), d("street", "address.addressLine1", "street-address"), d("city", "address.townCity", "address-level2"), t.country?.enabled) {
|
|
1166
|
+
const h = t.country?.label ?? this.translationFunc("address.chooseCountry"), E = this.createRow(["full"]), S = this.createCountrySelect(
|
|
1089
1167
|
s.country,
|
|
1090
|
-
i.country,
|
|
1091
1168
|
a.country,
|
|
1092
|
-
|
|
1169
|
+
i.country,
|
|
1170
|
+
l,
|
|
1093
1171
|
t.country?.options,
|
|
1094
|
-
|
|
1172
|
+
h
|
|
1095
1173
|
);
|
|
1096
|
-
this.inputs.set("country",
|
|
1174
|
+
this.inputs.set("country", S), E.appendChild(S.getElement()), this.fieldsContainer.appendChild(E);
|
|
1097
1175
|
}
|
|
1098
1176
|
if (t.state?.enabled) {
|
|
1099
|
-
this.
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
1177
|
+
this.stateFieldConfig = t.state;
|
|
1178
|
+
const h = this.createRow(["full"]);
|
|
1179
|
+
this.stateRow = h, this.stateStyles = l, this.currentCountry = s.country, t.state?.hiddenForCountries?.includes(
|
|
1180
|
+
s.country
|
|
1181
|
+
) && (h.style.display = "none");
|
|
1182
|
+
const S = O.has(s.country), o = t.state?.label ?? this.translationFunc("address.state");
|
|
1183
|
+
if (S) {
|
|
1184
|
+
const u = this.createStateSelect(
|
|
1103
1185
|
s.state,
|
|
1104
|
-
i.state,
|
|
1105
1186
|
a.state,
|
|
1106
|
-
|
|
1107
|
-
|
|
1187
|
+
i.state,
|
|
1188
|
+
l,
|
|
1108
1189
|
s.country,
|
|
1109
|
-
|
|
1190
|
+
o
|
|
1110
1191
|
);
|
|
1111
|
-
this.inputs.set("state",
|
|
1192
|
+
this.inputs.set("state", u), h.appendChild(u.getElement());
|
|
1112
1193
|
} else {
|
|
1113
|
-
const
|
|
1194
|
+
const u = this.createInput(
|
|
1114
1195
|
"state",
|
|
1115
|
-
|
|
1196
|
+
o,
|
|
1116
1197
|
s.state,
|
|
1117
|
-
i.state,
|
|
1118
1198
|
a.state,
|
|
1119
|
-
|
|
1199
|
+
i.state,
|
|
1200
|
+
l,
|
|
1120
1201
|
"address-level1"
|
|
1121
1202
|
);
|
|
1122
|
-
this.inputs.set("state",
|
|
1203
|
+
this.inputs.set("state", u), h.appendChild(u.getElement());
|
|
1123
1204
|
}
|
|
1124
|
-
this.fieldsContainer.appendChild(
|
|
1205
|
+
this.fieldsContainer.appendChild(h);
|
|
1125
1206
|
}
|
|
1126
|
-
|
|
1207
|
+
d("zipCode", "address.postalCode", "postal-code");
|
|
1127
1208
|
}
|
|
1128
1209
|
getValue(e) {
|
|
1129
1210
|
return this.inputs.get(e)?.getValue() ?? "";
|
|
@@ -1148,28 +1229,27 @@ class se extends A {
|
|
|
1148
1229
|
});
|
|
1149
1230
|
}
|
|
1150
1231
|
setError(e, t, s) {
|
|
1151
|
-
const i = this.inputs.get(e);
|
|
1152
|
-
if (i) {
|
|
1153
|
-
const a = i.getElement().querySelector("input") || i.getElement().querySelector("select");
|
|
1154
|
-
document.activeElement !== a && i.setError(t, s);
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
updateField(e, t, s, i) {
|
|
1158
1232
|
const a = this.inputs.get(e);
|
|
1159
1233
|
if (a) {
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1234
|
+
const i = a.getElement().querySelector("input") || a.getElement().querySelector("select");
|
|
1235
|
+
document.activeElement !== i && a.setError(t, s);
|
|
1162
1236
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1237
|
+
}
|
|
1238
|
+
updateField(e, t, s, a) {
|
|
1239
|
+
const i = this.inputs.get(e);
|
|
1240
|
+
if (!i) return;
|
|
1241
|
+
const r = i.getElement().querySelector("input") || i.getElement().querySelector("select"), l = i.getValue();
|
|
1242
|
+
!(document.activeElement === r) && !(t === "" && l !== "") && this.setValue(e, t);
|
|
1243
|
+
const E = !!(a && s);
|
|
1244
|
+
this.setError(e, E, s);
|
|
1165
1245
|
}
|
|
1166
1246
|
updateAllFields(e, t, s) {
|
|
1167
|
-
Object.keys(e).forEach((
|
|
1247
|
+
Object.keys(e).forEach((a) => {
|
|
1168
1248
|
this.updateField(
|
|
1169
|
-
|
|
1170
|
-
e[
|
|
1171
|
-
t[
|
|
1172
|
-
!!s[
|
|
1249
|
+
a,
|
|
1250
|
+
e[a],
|
|
1251
|
+
t[a],
|
|
1252
|
+
!!s[a]
|
|
1173
1253
|
);
|
|
1174
1254
|
});
|
|
1175
1255
|
}
|
|
@@ -1178,39 +1258,39 @@ class se extends A {
|
|
|
1178
1258
|
e && e.focus();
|
|
1179
1259
|
}
|
|
1180
1260
|
}
|
|
1181
|
-
class
|
|
1261
|
+
class nt {
|
|
1182
1262
|
input;
|
|
1183
1263
|
constructor(e) {
|
|
1184
1264
|
const {
|
|
1185
1265
|
value: t,
|
|
1186
1266
|
onChange: s,
|
|
1187
|
-
onBlur:
|
|
1188
|
-
errorMsg:
|
|
1267
|
+
onBlur: a,
|
|
1268
|
+
errorMsg: i,
|
|
1189
1269
|
checkoutProfile: r,
|
|
1190
|
-
translationFunc:
|
|
1191
|
-
autocomplete:
|
|
1270
|
+
translationFunc: l,
|
|
1271
|
+
autocomplete: d = "cc-name"
|
|
1192
1272
|
} = e;
|
|
1193
|
-
this.input = new
|
|
1273
|
+
this.input = new de({
|
|
1194
1274
|
name: "name",
|
|
1195
|
-
label:
|
|
1275
|
+
label: l("cardholderNameLabel"),
|
|
1196
1276
|
// Always hide error initially - we'll show it only on blur if needed
|
|
1197
1277
|
error: !1,
|
|
1198
|
-
errorMsg:
|
|
1278
|
+
errorMsg: i,
|
|
1199
1279
|
styles: {
|
|
1200
1280
|
color: r.styles.textColor,
|
|
1201
1281
|
borderRadius: `${r.styles.borderRadius}px`,
|
|
1202
1282
|
fontSize: r.styles.fontSize,
|
|
1203
1283
|
fontFamily: r.styles.fontFamily
|
|
1204
1284
|
},
|
|
1205
|
-
placeholder:
|
|
1285
|
+
placeholder: l("cardholderNamePlaceholder"),
|
|
1206
1286
|
value: t,
|
|
1207
|
-
autocomplete:
|
|
1208
|
-
onChange: (
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1287
|
+
autocomplete: d,
|
|
1288
|
+
onChange: (h) => {
|
|
1289
|
+
const S = h.target.value, o = S.replace(/[^a-zA-Z\s\-'.]/g, "");
|
|
1290
|
+
S !== o && this.input.setValue(o), this.input.setError(!1), this.trim(), s(h);
|
|
1211
1291
|
}
|
|
1212
|
-
}), this.input.addEventListener("blur", (
|
|
1213
|
-
|
|
1292
|
+
}), this.input.addEventListener("blur", (h) => {
|
|
1293
|
+
a(h);
|
|
1214
1294
|
});
|
|
1215
1295
|
}
|
|
1216
1296
|
getValue() {
|
|
@@ -1237,7 +1317,7 @@ class st {
|
|
|
1237
1317
|
this.input.focus();
|
|
1238
1318
|
}
|
|
1239
1319
|
}
|
|
1240
|
-
class
|
|
1320
|
+
class ce extends w {
|
|
1241
1321
|
constructor() {
|
|
1242
1322
|
super("div", ["skeleton-container"]), this.createSkeletonElements();
|
|
1243
1323
|
}
|
|
@@ -1245,35 +1325,35 @@ class oe extends A {
|
|
|
1245
1325
|
this.appendChild(this.createPaymentMethodSkeleton()), this.appendChild(this.createPaymentSeparatorSkeleton());
|
|
1246
1326
|
}
|
|
1247
1327
|
createPaymentMethodSkeleton() {
|
|
1248
|
-
const e =
|
|
1328
|
+
const e = k.createDiv(["skeleton-field"]), t = k.createDiv([
|
|
1249
1329
|
"skeleton",
|
|
1250
1330
|
"skeleton-payment-method"
|
|
1251
1331
|
]);
|
|
1252
1332
|
return e.appendChild(t), e;
|
|
1253
1333
|
}
|
|
1254
1334
|
createPaymentSeparatorSkeleton() {
|
|
1255
|
-
const e =
|
|
1335
|
+
const e = k.createDiv([
|
|
1256
1336
|
"payment-separator_container"
|
|
1257
|
-
]), t =
|
|
1337
|
+
]), t = k.createDiv(["payment-separator__line"]), s = k.createDiv([
|
|
1258
1338
|
"skeleton",
|
|
1259
1339
|
"skeleton-separator-text"
|
|
1260
|
-
]),
|
|
1261
|
-
return e.appendChild(t), e.appendChild(s), e.appendChild(
|
|
1340
|
+
]), a = k.createDiv(["payment-separator__line"]);
|
|
1341
|
+
return e.appendChild(t), e.appendChild(s), e.appendChild(a), e;
|
|
1262
1342
|
}
|
|
1263
1343
|
}
|
|
1264
|
-
class
|
|
1344
|
+
class at extends w {
|
|
1265
1345
|
constructor(e) {
|
|
1266
1346
|
const { translationFunc: t, checkoutProfile: s } = e;
|
|
1267
1347
|
super("div", ["payment-separator"]);
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1348
|
+
const a = this.getElement(), i = document.createElement("span");
|
|
1349
|
+
i.className = "payment-separator__line";
|
|
1270
1350
|
const r = document.createElement("p");
|
|
1271
1351
|
r.textContent = t("pay-with-card"), r.className = "payment-separator__text", r.style.fontFamily = `${s.styles.fontFamily}, sans-serif`;
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1352
|
+
const l = document.createElement("span");
|
|
1353
|
+
l.className = "payment-separator__line", a.appendChild(i), a.appendChild(r), a.appendChild(l);
|
|
1274
1354
|
}
|
|
1275
1355
|
}
|
|
1276
|
-
class
|
|
1356
|
+
class it extends w {
|
|
1277
1357
|
paymentMethods;
|
|
1278
1358
|
paymentSeparator;
|
|
1279
1359
|
skeleton;
|
|
@@ -1281,14 +1361,14 @@ class at extends A {
|
|
|
1281
1361
|
const {
|
|
1282
1362
|
checkoutProfile: t,
|
|
1283
1363
|
formData: s,
|
|
1284
|
-
onPaypalSubmit:
|
|
1285
|
-
onApplePaySubmit:
|
|
1364
|
+
onPaypalSubmit: a,
|
|
1365
|
+
onApplePaySubmit: i,
|
|
1286
1366
|
supportedPaymentMethods: r,
|
|
1287
|
-
translationFunc:
|
|
1288
|
-
paymentId:
|
|
1289
|
-
checkoutKey:
|
|
1367
|
+
translationFunc: l,
|
|
1368
|
+
paymentId: d,
|
|
1369
|
+
checkoutKey: h,
|
|
1290
1370
|
checkoutDetails: E,
|
|
1291
|
-
environment:
|
|
1371
|
+
environment: S,
|
|
1292
1372
|
countryCode: o
|
|
1293
1373
|
} = e;
|
|
1294
1374
|
if (super("div", ["payment-methods"]), this.paymentMethods = /* @__PURE__ */ new Map(), !t?.additionalPaymentMethods) {
|
|
@@ -1299,42 +1379,42 @@ class at extends A {
|
|
|
1299
1379
|
this.renderSkeleton();
|
|
1300
1380
|
return;
|
|
1301
1381
|
}
|
|
1302
|
-
const
|
|
1382
|
+
const u = Object.entries(
|
|
1303
1383
|
t.additionalPaymentMethods
|
|
1304
|
-
).filter(([
|
|
1305
|
-
const p =
|
|
1306
|
-
return p && c &&
|
|
1307
|
-
}).sort((
|
|
1308
|
-
if (
|
|
1384
|
+
).filter(([g, m]) => {
|
|
1385
|
+
const p = m.enabled, c = r ? r[g] === !0 : !0, f = !m.countries || o && m.countries.includes(o);
|
|
1386
|
+
return p && c && f;
|
|
1387
|
+
}).sort((g, m) => g[1].order - m[1].order);
|
|
1388
|
+
if (u.length === 0) {
|
|
1309
1389
|
this.getElement().style.display = "none";
|
|
1310
1390
|
return;
|
|
1311
1391
|
}
|
|
1312
|
-
for (const [
|
|
1313
|
-
switch (
|
|
1392
|
+
for (const [g] of u)
|
|
1393
|
+
switch (g) {
|
|
1314
1394
|
case "paypal": {
|
|
1315
|
-
if (
|
|
1316
|
-
const
|
|
1395
|
+
if (a) {
|
|
1396
|
+
const m = new fe({
|
|
1317
1397
|
checkoutProfile: t,
|
|
1318
1398
|
formData: s,
|
|
1319
|
-
onSubmit:
|
|
1399
|
+
onSubmit: a
|
|
1320
1400
|
});
|
|
1321
|
-
this.paymentMethods.set("paypal",
|
|
1401
|
+
this.paymentMethods.set("paypal", m), m.appendTo(this.getElement());
|
|
1322
1402
|
}
|
|
1323
1403
|
break;
|
|
1324
1404
|
}
|
|
1325
1405
|
case "applePay": {
|
|
1326
|
-
if (
|
|
1327
|
-
const
|
|
1406
|
+
if (i && d && h) {
|
|
1407
|
+
const m = t.appearance?.additionalPaymentMethods?.applePay, p = new pe({
|
|
1328
1408
|
checkoutProfile: t,
|
|
1329
1409
|
formData: s,
|
|
1330
|
-
onSubmit:
|
|
1331
|
-
paymentId:
|
|
1332
|
-
checkoutKey:
|
|
1410
|
+
onSubmit: i,
|
|
1411
|
+
paymentId: d,
|
|
1412
|
+
checkoutKey: h,
|
|
1333
1413
|
checkoutDetails: E,
|
|
1334
|
-
environment:
|
|
1335
|
-
displayName:
|
|
1336
|
-
requiredBillingContactFields:
|
|
1337
|
-
requiredShippingContactFields:
|
|
1414
|
+
environment: S,
|
|
1415
|
+
displayName: m?.displayName,
|
|
1416
|
+
requiredBillingContactFields: m?.requiredBillingContactFields,
|
|
1417
|
+
requiredShippingContactFields: m?.requiredShippingContactFields
|
|
1338
1418
|
});
|
|
1339
1419
|
this.paymentMethods.set("applePay", p), p.appendTo(this.getElement());
|
|
1340
1420
|
}
|
|
@@ -1348,17 +1428,17 @@ class at extends A {
|
|
|
1348
1428
|
// break;
|
|
1349
1429
|
default:
|
|
1350
1430
|
console.warn(
|
|
1351
|
-
`[PaymentMethods] Unsupported payment method: ${
|
|
1431
|
+
`[PaymentMethods] Unsupported payment method: ${g}`
|
|
1352
1432
|
);
|
|
1353
1433
|
break;
|
|
1354
1434
|
}
|
|
1355
|
-
this.paymentMethods.size > 0 && (this.paymentSeparator = new
|
|
1356
|
-
translationFunc:
|
|
1435
|
+
this.paymentMethods.size > 0 && (this.paymentSeparator = new at({
|
|
1436
|
+
translationFunc: l,
|
|
1357
1437
|
checkoutProfile: t
|
|
1358
1438
|
}), this.getElement().appendChild(this.paymentSeparator.getElement()));
|
|
1359
1439
|
}
|
|
1360
1440
|
renderSkeleton() {
|
|
1361
|
-
this.skeleton = new
|
|
1441
|
+
this.skeleton = new ce(), this.getElement().appendChild(this.skeleton.getElement());
|
|
1362
1442
|
}
|
|
1363
1443
|
updateFormData(e) {
|
|
1364
1444
|
const t = this.paymentMethods.get("paypal");
|
|
@@ -1370,8 +1450,8 @@ class at extends A {
|
|
|
1370
1450
|
return this.paymentMethods.size > 0 && this.getElement().style.display !== "none";
|
|
1371
1451
|
}
|
|
1372
1452
|
}
|
|
1373
|
-
const
|
|
1374
|
-
class
|
|
1453
|
+
const rt = 17;
|
|
1454
|
+
class ot extends w {
|
|
1375
1455
|
styles;
|
|
1376
1456
|
isHovered = !1;
|
|
1377
1457
|
constructor(e) {
|
|
@@ -1381,7 +1461,7 @@ class rt extends A {
|
|
|
1381
1461
|
}
|
|
1382
1462
|
applyStyles() {
|
|
1383
1463
|
const e = this.getElement();
|
|
1384
|
-
e.style.backgroundColor = this.isHovered ? `color-mix(in srgb, ${this.styles.backgroundColor} 80%, transparent)` : this.styles.backgroundColor, e.disabled ? (e.style.color = "rgb(150, 150, 150)", e.style.backgroundColor = "rgb(200, 200, 200)") : e.style.color = this.styles.color, e.style.borderRadius = this.styles.borderRadius ===
|
|
1464
|
+
e.style.backgroundColor = this.isHovered ? `color-mix(in srgb, ${this.styles.backgroundColor} 80%, transparent)` : this.styles.backgroundColor, e.disabled ? (e.style.color = "rgb(150, 150, 150)", e.style.backgroundColor = "rgb(200, 200, 200)") : e.style.color = this.styles.color, e.style.borderRadius = this.styles.borderRadius === rt ? "100vmax" : `${this.styles.borderRadius}px`, e.style.fontSize = `${this.styles.fontSize}px`, e.style.fontFamily = `${this.styles.fontFamily}, sans-serif`;
|
|
1385
1465
|
}
|
|
1386
1466
|
handleMouseEnter() {
|
|
1387
1467
|
this.isHovered = !0, this.applyStyles();
|
|
@@ -1393,12 +1473,12 @@ class rt extends A {
|
|
|
1393
1473
|
return this.getElement().disabled = e, e ? (this.addClass("disabled"), this.removeClass("valid")) : (this.removeClass("disabled"), this.addClass("valid")), this.applyStyles(), this;
|
|
1394
1474
|
}
|
|
1395
1475
|
}
|
|
1396
|
-
class
|
|
1476
|
+
class lt {
|
|
1397
1477
|
button;
|
|
1398
1478
|
constructor(e) {
|
|
1399
|
-
const { disabled: t, checkoutProfile: s, translationFunc:
|
|
1400
|
-
this.button = new
|
|
1401
|
-
text:
|
|
1479
|
+
const { disabled: t, checkoutProfile: s, translationFunc: a } = e;
|
|
1480
|
+
this.button = new ot({
|
|
1481
|
+
text: a(
|
|
1402
1482
|
`buttonTexts.${s?.layout.actionButton.translationKey}`
|
|
1403
1483
|
),
|
|
1404
1484
|
styles: {
|
|
@@ -1424,7 +1504,7 @@ class ot {
|
|
|
1424
1504
|
return this.button.appendTo(e), this;
|
|
1425
1505
|
}
|
|
1426
1506
|
}
|
|
1427
|
-
class
|
|
1507
|
+
class dt {
|
|
1428
1508
|
formElement;
|
|
1429
1509
|
focusManager;
|
|
1430
1510
|
translationFunc;
|
|
@@ -1462,10 +1542,10 @@ class lt {
|
|
|
1462
1542
|
createPaymentMethods(e, t, s = !1) {
|
|
1463
1543
|
try {
|
|
1464
1544
|
if (!e?.additionalPaymentMethods || Object.keys(e.additionalPaymentMethods).length === 0 || !Object.values(e.additionalPaymentMethods).some(
|
|
1465
|
-
(
|
|
1545
|
+
(a) => a.enabled
|
|
1466
1546
|
))
|
|
1467
1547
|
return;
|
|
1468
|
-
this.paymentMethods = new
|
|
1548
|
+
this.paymentMethods = new it({
|
|
1469
1549
|
checkoutProfile: e,
|
|
1470
1550
|
formData: t,
|
|
1471
1551
|
supportedPaymentMethods: this.supportedPaymentMethods,
|
|
@@ -1481,119 +1561,119 @@ class lt {
|
|
|
1481
1561
|
this.paymentMethods.getElement(),
|
|
1482
1562
|
this.formElement.firstChild
|
|
1483
1563
|
) : this.formElement.appendChild(this.paymentMethods.getElement());
|
|
1484
|
-
} catch (
|
|
1485
|
-
throw console.error("Error creating payment methods:",
|
|
1564
|
+
} catch (a) {
|
|
1565
|
+
throw console.error("Error creating payment methods:", a), a;
|
|
1486
1566
|
}
|
|
1487
1567
|
}
|
|
1488
|
-
createEmailField(e, t, s,
|
|
1568
|
+
createEmailField(e, t, s, a) {
|
|
1489
1569
|
try {
|
|
1490
|
-
const
|
|
1570
|
+
const i = e.layout.billingFields && Object.values(e.layout.billingFields).some(
|
|
1491
1571
|
(r) => r?.enabled
|
|
1492
1572
|
) || e.layout.shippingFields && Object.values(e.layout.shippingFields).some(
|
|
1493
1573
|
(r) => r?.enabled
|
|
1494
1574
|
);
|
|
1495
|
-
this.emailField = new
|
|
1575
|
+
this.emailField = new ge({
|
|
1496
1576
|
value: t.email,
|
|
1497
1577
|
onChange: this.onChange,
|
|
1498
1578
|
onBlur: this.onBlur,
|
|
1499
|
-
onTab:
|
|
1579
|
+
onTab: i ? void 0 : () => this.focusManager.focusField(
|
|
1500
1580
|
e.layout.phoneNumber?.enabled ? "phoneNumber" : "cardNumber"
|
|
1501
1581
|
),
|
|
1502
|
-
error: !!(s.email &&
|
|
1582
|
+
error: !!(s.email && a.email),
|
|
1503
1583
|
errorMsg: s.email,
|
|
1504
1584
|
checkoutProfile: e,
|
|
1505
1585
|
translationFunc: this.translationFunc
|
|
1506
1586
|
}), this.emailFocusHandler = () => this.onFieldFocus("email"), this.emailField.getElement().addEventListener("focus", this.emailFocusHandler, !0), this.focusManager.registerField("email", this.emailField), this.formElement.appendChild(this.emailField.getElement());
|
|
1507
|
-
} catch (
|
|
1508
|
-
throw console.error("Error creating email field:",
|
|
1587
|
+
} catch (i) {
|
|
1588
|
+
throw console.error("Error creating email field:", i), i;
|
|
1509
1589
|
}
|
|
1510
1590
|
}
|
|
1511
|
-
createPhoneNumberField(e, t, s,
|
|
1512
|
-
const
|
|
1513
|
-
this.phonePlaceholder =
|
|
1514
|
-
|
|
1591
|
+
createPhoneNumberField(e, t, s, a) {
|
|
1592
|
+
const i = document.createElement("div");
|
|
1593
|
+
this.phonePlaceholder = i, this.formElement.appendChild(i), ye().then(({ PhoneNumberField: r }) => {
|
|
1594
|
+
i.isConnected && (this.phoneNumberField = new r({
|
|
1515
1595
|
value: t.phoneNumber ?? "",
|
|
1516
1596
|
onChange: this.onChange,
|
|
1517
1597
|
onBlur: this.onBlur,
|
|
1518
1598
|
onTab: () => this.focusManager.focusField("cardNumber"),
|
|
1519
|
-
error: !!(s.phoneNumber &&
|
|
1599
|
+
error: !!(s.phoneNumber && a.phoneNumber),
|
|
1520
1600
|
errorMsg: s.phoneNumber,
|
|
1521
1601
|
checkoutProfile: e,
|
|
1522
1602
|
translationFunc: this.translationFunc,
|
|
1523
1603
|
defaultCountry: e.layout.phoneNumber?.defaultCountry || "US",
|
|
1524
1604
|
allowedCountries: e.layout.phoneNumber?.allowedCountries,
|
|
1525
1605
|
locale: this.locale
|
|
1526
|
-
}), this.phoneNumberFocusHandler = () => this.onFieldFocus("phoneNumber"), this.phoneNumberField.getElement().addEventListener("focus", this.phoneNumberFocusHandler, !0), this.focusManager.registerField("phoneNumber", this.phoneNumberField),
|
|
1606
|
+
}), this.phoneNumberFocusHandler = () => this.onFieldFocus("phoneNumber"), this.phoneNumberField.getElement().addEventListener("focus", this.phoneNumberFocusHandler, !0), this.focusManager.registerField("phoneNumber", this.phoneNumberField), i.replaceWith(this.phoneNumberField.getElement()), this.phonePlaceholder = void 0);
|
|
1527
1607
|
}).catch((r) => {
|
|
1528
|
-
console.error("Error creating phone number field:", r),
|
|
1608
|
+
console.error("Error creating phone number field:", r), i.remove(), this.phonePlaceholder = void 0;
|
|
1529
1609
|
});
|
|
1530
1610
|
}
|
|
1531
|
-
createCardSection(e, t, s,
|
|
1611
|
+
createCardSection(e, t, s, a) {
|
|
1532
1612
|
try {
|
|
1533
|
-
this.cardSection = new
|
|
1613
|
+
this.cardSection = new be({
|
|
1534
1614
|
checkoutProfile: e,
|
|
1535
1615
|
cardNumber: t.cardNumber,
|
|
1536
1616
|
cardNumberError: s.cardNumber,
|
|
1537
|
-
cardNumberTouched: !!
|
|
1617
|
+
cardNumberTouched: !!a.cardNumber,
|
|
1538
1618
|
cardCvv: t.cardCvv,
|
|
1539
1619
|
cardCvvError: s.cardCvv,
|
|
1540
|
-
cardCvvTouched: !!
|
|
1620
|
+
cardCvvTouched: !!a.cardCvv,
|
|
1541
1621
|
cardExpiry: t.cardExpiry,
|
|
1542
1622
|
cardExpiryError: s.cardExpiry,
|
|
1543
|
-
cardExpiryTouched: !!
|
|
1623
|
+
cardExpiryTouched: !!a.cardExpiry,
|
|
1544
1624
|
onChange: this.onChange,
|
|
1545
1625
|
onBlur: this.onBlur,
|
|
1546
1626
|
onCardBrandChange: () => {
|
|
1547
1627
|
if (t.cardCvv) {
|
|
1548
|
-
const
|
|
1549
|
-
Object.defineProperty(
|
|
1628
|
+
const d = new Event("blur", { bubbles: !0 });
|
|
1629
|
+
Object.defineProperty(d, "target", {
|
|
1550
1630
|
writable: !1,
|
|
1551
1631
|
value: { name: "cardCvv", value: t.cardCvv }
|
|
1552
|
-
}), this.onBlur(
|
|
1632
|
+
}), this.onBlur(d);
|
|
1553
1633
|
}
|
|
1554
1634
|
},
|
|
1555
1635
|
translationFunc: this.translationFunc
|
|
1556
1636
|
});
|
|
1557
|
-
const
|
|
1558
|
-
|
|
1637
|
+
const i = this.cardSection.getElement().querySelector('input[name="cardExpiry"]');
|
|
1638
|
+
i && (this.cardExpiryFocusHandler = () => this.onFieldFocus("cardExpiry"), i.addEventListener("focus", this.cardExpiryFocusHandler));
|
|
1559
1639
|
const r = this.cardSection.getElement().querySelector('input[name="cardNumber"]');
|
|
1560
1640
|
r && (this.cardNumberFocusHandler = () => this.onFieldFocus("cardNumber"), r.addEventListener("focus", this.cardNumberFocusHandler));
|
|
1561
|
-
const
|
|
1562
|
-
|
|
1641
|
+
const l = this.cardSection.getElement().querySelector('input[name="cardCvv"]');
|
|
1642
|
+
l && (this.cardCvvFocusHandler = () => this.onFieldFocus("cardCvv"), l.addEventListener("focus", this.cardCvvFocusHandler)), this.focusManager.registerField("cardNumber", {
|
|
1563
1643
|
focus: () => this.cardSection?.focusField("cardNumber")
|
|
1564
1644
|
}), this.focusManager.registerField("cardExpiry", {
|
|
1565
1645
|
focus: () => this.cardSection?.focusField("cardExpiry")
|
|
1566
1646
|
}), this.focusManager.registerField("cardCvv", {
|
|
1567
1647
|
focus: () => this.cardSection?.focusField("cardCvv")
|
|
1568
1648
|
}), this.formElement.appendChild(this.cardSection.getElement());
|
|
1569
|
-
} catch (
|
|
1570
|
-
throw console.error("Error creating card section:",
|
|
1649
|
+
} catch (i) {
|
|
1650
|
+
throw console.error("Error creating card section:", i), i;
|
|
1571
1651
|
}
|
|
1572
1652
|
}
|
|
1573
|
-
createCardholderSection(e, t, s,
|
|
1653
|
+
createCardholderSection(e, t, s, a) {
|
|
1574
1654
|
try {
|
|
1575
|
-
this.cardholderSection = new
|
|
1655
|
+
this.cardholderSection = new nt({
|
|
1576
1656
|
value: t.name,
|
|
1577
1657
|
onChange: this.onChange,
|
|
1578
1658
|
onBlur: this.onBlur,
|
|
1579
|
-
error: !!(s.name &&
|
|
1659
|
+
error: !!(s.name && a.name),
|
|
1580
1660
|
errorMsg: s.name,
|
|
1581
1661
|
checkoutProfile: e,
|
|
1582
1662
|
translationFunc: this.translationFunc
|
|
1583
1663
|
});
|
|
1584
|
-
const
|
|
1585
|
-
|
|
1586
|
-
} catch (
|
|
1587
|
-
throw console.error("Error creating cardholder section:",
|
|
1664
|
+
const i = this.cardholderSection.getElement().querySelector('input[name="name"]');
|
|
1665
|
+
i && (this.nameFocusHandler = () => this.onFieldFocus("name"), i.addEventListener("focus", this.nameFocusHandler)), this.focusManager.registerField("name", this.cardholderSection), this.formElement.appendChild(this.cardholderSection.getElement());
|
|
1666
|
+
} catch (i) {
|
|
1667
|
+
throw console.error("Error creating cardholder section:", i), i;
|
|
1588
1668
|
}
|
|
1589
1669
|
}
|
|
1590
|
-
createBillingAddressSection(e, t, s,
|
|
1670
|
+
createBillingAddressSection(e, t, s, a) {
|
|
1591
1671
|
try {
|
|
1592
|
-
const
|
|
1593
|
-
if (!
|
|
1594
|
-
(
|
|
1672
|
+
const i = e.layout.billingFields;
|
|
1673
|
+
if (!i || !Object.values(i).some(
|
|
1674
|
+
(d) => d?.enabled
|
|
1595
1675
|
)) return;
|
|
1596
|
-
const
|
|
1676
|
+
const l = {
|
|
1597
1677
|
street: "",
|
|
1598
1678
|
firstName: "",
|
|
1599
1679
|
lastName: "",
|
|
@@ -1602,31 +1682,31 @@ class lt {
|
|
|
1602
1682
|
zipCode: "",
|
|
1603
1683
|
country: ""
|
|
1604
1684
|
};
|
|
1605
|
-
this.billingAddressSection = new
|
|
1685
|
+
this.billingAddressSection = new ie({
|
|
1606
1686
|
type: "billing",
|
|
1607
1687
|
title: this.translationFunc("address.billingTitle"),
|
|
1608
1688
|
checkoutProfile: e,
|
|
1609
|
-
fieldsConfig:
|
|
1610
|
-
values: t.billingAddress ??
|
|
1689
|
+
fieldsConfig: i,
|
|
1690
|
+
values: t.billingAddress ?? l,
|
|
1611
1691
|
errors: s.billingAddress ?? {},
|
|
1612
|
-
touched:
|
|
1692
|
+
touched: a.billingAddress ?? {},
|
|
1613
1693
|
onChange: this.onChange,
|
|
1614
1694
|
onBlur: this.onBlur,
|
|
1615
1695
|
translationFunc: this.translationFunc,
|
|
1616
1696
|
locale: this.locale,
|
|
1617
1697
|
grouped: e.layout.grouped
|
|
1618
1698
|
}), this.formElement.appendChild(this.billingAddressSection.getElement());
|
|
1619
|
-
} catch (
|
|
1620
|
-
throw console.error("Error creating billing address section:",
|
|
1699
|
+
} catch (i) {
|
|
1700
|
+
throw console.error("Error creating billing address section:", i), i;
|
|
1621
1701
|
}
|
|
1622
1702
|
}
|
|
1623
|
-
createShippingAddressSection(e, t, s,
|
|
1703
|
+
createShippingAddressSection(e, t, s, a) {
|
|
1624
1704
|
try {
|
|
1625
|
-
const
|
|
1626
|
-
if (!
|
|
1627
|
-
(
|
|
1705
|
+
const i = e.layout.shippingFields;
|
|
1706
|
+
if (!i || !Object.values(i).some(
|
|
1707
|
+
(d) => d?.enabled
|
|
1628
1708
|
)) return;
|
|
1629
|
-
const
|
|
1709
|
+
const l = {
|
|
1630
1710
|
street: "",
|
|
1631
1711
|
firstName: "",
|
|
1632
1712
|
lastName: "",
|
|
@@ -1635,27 +1715,27 @@ class lt {
|
|
|
1635
1715
|
zipCode: "",
|
|
1636
1716
|
country: ""
|
|
1637
1717
|
};
|
|
1638
|
-
this.shippingAddressSection = new
|
|
1718
|
+
this.shippingAddressSection = new ie({
|
|
1639
1719
|
type: "shipping",
|
|
1640
1720
|
title: this.translationFunc("address.shippingTitle"),
|
|
1641
1721
|
checkoutProfile: e,
|
|
1642
|
-
fieldsConfig:
|
|
1643
|
-
values: t.shippingAddress ??
|
|
1722
|
+
fieldsConfig: i,
|
|
1723
|
+
values: t.shippingAddress ?? l,
|
|
1644
1724
|
errors: s.shippingAddress ?? {},
|
|
1645
|
-
touched:
|
|
1725
|
+
touched: a.shippingAddress ?? {},
|
|
1646
1726
|
onChange: this.onChange,
|
|
1647
1727
|
onBlur: this.onBlur,
|
|
1648
1728
|
translationFunc: this.translationFunc,
|
|
1649
1729
|
locale: this.locale,
|
|
1650
1730
|
grouped: e.layout.grouped
|
|
1651
1731
|
}), this.formElement.appendChild(this.shippingAddressSection.getElement());
|
|
1652
|
-
} catch (
|
|
1653
|
-
throw console.error("Error creating shipping address section:",
|
|
1732
|
+
} catch (i) {
|
|
1733
|
+
throw console.error("Error creating shipping address section:", i), i;
|
|
1654
1734
|
}
|
|
1655
1735
|
}
|
|
1656
1736
|
createSubmitButton(e, t) {
|
|
1657
1737
|
try {
|
|
1658
|
-
this.submitButton = new
|
|
1738
|
+
this.submitButton = new lt({
|
|
1659
1739
|
disabled: t,
|
|
1660
1740
|
checkoutProfile: e,
|
|
1661
1741
|
translationFunc: this.translationFunc
|
|
@@ -1670,15 +1750,15 @@ class lt {
|
|
|
1670
1750
|
updatePhoneNumberField(e, t, s) {
|
|
1671
1751
|
this.phoneNumberField && (this.phoneNumberField.setValue(e), this.phoneNumberField.setError(t, s));
|
|
1672
1752
|
}
|
|
1673
|
-
updateCardSection(e, t, s,
|
|
1753
|
+
updateCardSection(e, t, s, a, i, r, l, d, h) {
|
|
1674
1754
|
this.cardSection && (this.cardSection.updateCardNumber(
|
|
1675
1755
|
e,
|
|
1676
1756
|
t,
|
|
1677
1757
|
s
|
|
1678
|
-
), this.cardSection.updateCardCvv(
|
|
1679
|
-
d,
|
|
1758
|
+
), this.cardSection.updateCardCvv(a, i, r), this.cardSection.updateCardExpiry(
|
|
1680
1759
|
l,
|
|
1681
|
-
|
|
1760
|
+
d,
|
|
1761
|
+
h
|
|
1682
1762
|
));
|
|
1683
1763
|
}
|
|
1684
1764
|
updateCardholderSection(e, t, s) {
|
|
@@ -1738,7 +1818,7 @@ class lt {
|
|
|
1738
1818
|
this.billingAddressSection && (this.billingAddressSection.getElement().remove(), this.billingAddressSection = void 0), this.shippingAddressSection && (this.shippingAddressSection.getElement().remove(), this.shippingAddressSection = void 0), this.submitButton && (this.submitButton.getElement().remove(), this.submitButton = void 0), this.paymentMethods && (this.paymentMethods.getElement().remove(), this.paymentMethods = void 0);
|
|
1739
1819
|
}
|
|
1740
1820
|
}
|
|
1741
|
-
class
|
|
1821
|
+
class ct {
|
|
1742
1822
|
formManager;
|
|
1743
1823
|
focusManager;
|
|
1744
1824
|
onFormSubmit;
|
|
@@ -1748,18 +1828,18 @@ class dt {
|
|
|
1748
1828
|
this.formManager = e.formManager, this.focusManager = e.focusManager, this.onFormSubmit = e.onFormSubmit, this.onUIUpdate = e.onUIUpdate;
|
|
1749
1829
|
}
|
|
1750
1830
|
handleChange = (e) => {
|
|
1751
|
-
const t = e.target, { name: s, value:
|
|
1752
|
-
this.formManager.handleChange(a, i)
|
|
1753
|
-
const { formData:
|
|
1754
|
-
this.focusManager.handleStateUpdate(
|
|
1831
|
+
const t = e.target, { name: s, value: a } = t, i = s;
|
|
1832
|
+
this.formManager.handleChange(i, a), e instanceof CustomEvent && e.detail?.programmatic ? this.localTouchedFields.delete(i) : this.localTouchedFields.has(i) || (this.localTouchedFields.add(i), this.formManager.handleBlur(i, a));
|
|
1833
|
+
const { formData: l, errors: d, touched: h } = this.formManager.getFormState();
|
|
1834
|
+
this.focusManager.handleStateUpdate(l, d, h);
|
|
1755
1835
|
};
|
|
1756
1836
|
handleBlur = (e) => {
|
|
1757
|
-
const t = e.target, { name: s, value:
|
|
1758
|
-
this.localTouchedFields.add(
|
|
1837
|
+
const t = e.target, { name: s, value: a } = t, i = s;
|
|
1838
|
+
this.localTouchedFields.add(i), this.formManager.handleBlur(i, a), setTimeout(() => {
|
|
1759
1839
|
this.onUIUpdate();
|
|
1760
1840
|
}, 0);
|
|
1761
|
-
const { formData: r, errors:
|
|
1762
|
-
|
|
1841
|
+
const { formData: r, errors: l, touched: d } = this.formManager.getFormState();
|
|
1842
|
+
d[i] || this.focusManager.handleStateUpdate(r, l, d);
|
|
1763
1843
|
};
|
|
1764
1844
|
handleSubmit = async (e) => {
|
|
1765
1845
|
e.preventDefault(), await this.onFormSubmit(e);
|
|
@@ -1779,7 +1859,7 @@ class dt {
|
|
|
1779
1859
|
this.localTouchedFields.clear();
|
|
1780
1860
|
}
|
|
1781
1861
|
}
|
|
1782
|
-
class
|
|
1862
|
+
class ht {
|
|
1783
1863
|
formManager;
|
|
1784
1864
|
checkoutProfile;
|
|
1785
1865
|
formElement;
|
|
@@ -1801,7 +1881,7 @@ class ct {
|
|
|
1801
1881
|
try {
|
|
1802
1882
|
if (e.checkoutProfile.styles?.fontFamily)
|
|
1803
1883
|
try {
|
|
1804
|
-
const { cleanup: t } =
|
|
1884
|
+
const { cleanup: t } = Ee({
|
|
1805
1885
|
fontFamily: e.checkoutProfile.styles.fontFamily
|
|
1806
1886
|
});
|
|
1807
1887
|
this.fontCleanup = t, this.formElement.style.fontFamily = e.checkoutProfile.styles.fontFamily;
|
|
@@ -1818,13 +1898,15 @@ class ct {
|
|
|
1818
1898
|
};
|
|
1819
1899
|
isFormDisabled() {
|
|
1820
1900
|
const e = this.formManager.getFormState(), t = this.checkoutProfile.getState(), s = Object.keys(e.errors).filter(
|
|
1821
|
-
(
|
|
1822
|
-
).length > 0,
|
|
1901
|
+
(f) => f !== "billingAddress" && f !== "shippingAddress"
|
|
1902
|
+
).length > 0, a = e.errors.billingAddress, i = a && typeof a == "object" ? Object.keys(a).length > 0 : !1, r = e.errors.shippingAddress, l = r && typeof r == "object" ? Object.keys(r).length > 0 : !1, d = s || i || l, E = Z(
|
|
1823
1903
|
t.checkoutProfile?.layout
|
|
1824
|
-
) ? !!(e.formData.billingAddress?.firstName || e.formData.billingAddress?.lastName || e.formData.shippingAddress?.firstName || e.formData.shippingAddress?.lastName) : !!e.formData.name, o = t.checkoutProfile?.layout.phoneNumber?.enabled ?? !1 ? !!e.formData.phoneNumber : !0, { billingFields:
|
|
1825
|
-
(
|
|
1826
|
-
|
|
1827
|
-
|
|
1904
|
+
) ? !!(e.formData.billingAddress?.firstName || e.formData.billingAddress?.lastName || e.formData.shippingAddress?.firstName || e.formData.shippingAddress?.lastName) : !!e.formData.name, o = t.checkoutProfile?.layout.phoneNumber?.enabled ?? !1 ? !!e.formData.phoneNumber : !0, { billingFields: u, shippingFields: g } = t.checkoutProfile?.layout ?? {}, m = /* @__PURE__ */ new Set(["US", "CA"]), p = (f, y) => {
|
|
1905
|
+
if (!f) return !0;
|
|
1906
|
+
const b = y?.country ?? "";
|
|
1907
|
+
return Object.entries(f).every(([C, N]) => !N?.enabled || C === "state" && (!m.has(b) || N.hiddenForCountries?.includes(b)) ? !0 : !!y?.[C]?.trim());
|
|
1908
|
+
}, c = !!e.formData.email && o && E && !!e.formData.cardNumber && !!e.formData.cardCvv && !!e.formData.cardExpiry && p(u, e.formData.billingAddress) && p(g, e.formData.shippingAddress);
|
|
1909
|
+
return d || !c || this.isSubmitting;
|
|
1828
1910
|
}
|
|
1829
1911
|
setSubmitting(e) {
|
|
1830
1912
|
this.isSubmitting = e;
|
|
@@ -1836,18 +1918,18 @@ class ct {
|
|
|
1836
1918
|
this.fontCleanup && (this.fontCleanup(), this.fontCleanup = void 0);
|
|
1837
1919
|
}
|
|
1838
1920
|
}
|
|
1839
|
-
class
|
|
1921
|
+
class ut extends w {
|
|
1840
1922
|
titleElement;
|
|
1841
1923
|
constructor(e = {}) {
|
|
1842
1924
|
super("div", ["blur-bg"]);
|
|
1843
|
-
const t =
|
|
1844
|
-
this.titleElement = new
|
|
1925
|
+
const t = k.createDiv(["loader"]);
|
|
1926
|
+
this.titleElement = new w("h3", ["title"]), this.titleElement.setText(e.text || ""), this.appendChild(t), this.appendChild(this.titleElement);
|
|
1845
1927
|
}
|
|
1846
1928
|
setText(e) {
|
|
1847
1929
|
return this.titleElement.setText(e), this;
|
|
1848
1930
|
}
|
|
1849
1931
|
}
|
|
1850
|
-
const
|
|
1932
|
+
const re = {
|
|
1851
1933
|
street: "",
|
|
1852
1934
|
firstName: "",
|
|
1853
1935
|
lastName: "",
|
|
@@ -1855,16 +1937,16 @@ const ne = {
|
|
|
1855
1937
|
city: "",
|
|
1856
1938
|
zipCode: "",
|
|
1857
1939
|
country: ""
|
|
1858
|
-
},
|
|
1940
|
+
}, oe = (n, e) => {
|
|
1859
1941
|
const t = {}, s = `${e}.`;
|
|
1860
|
-
return Object.keys(n).forEach((
|
|
1861
|
-
if (
|
|
1862
|
-
const
|
|
1863
|
-
t[
|
|
1942
|
+
return Object.keys(n).forEach((a) => {
|
|
1943
|
+
if (a.startsWith(s)) {
|
|
1944
|
+
const i = a.slice(s.length);
|
|
1945
|
+
t[i] = n[a];
|
|
1864
1946
|
}
|
|
1865
1947
|
}), t;
|
|
1866
1948
|
};
|
|
1867
|
-
class
|
|
1949
|
+
class mt {
|
|
1868
1950
|
formElement;
|
|
1869
1951
|
componentManager;
|
|
1870
1952
|
onLoadingStateChange;
|
|
@@ -1898,13 +1980,13 @@ class ut {
|
|
|
1898
1980
|
!!(e.errors.name && e.touched.name),
|
|
1899
1981
|
e.errors.name
|
|
1900
1982
|
), this.componentManager.updateBillingAddressSection(
|
|
1901
|
-
e.formData.billingAddress ??
|
|
1983
|
+
e.formData.billingAddress ?? re,
|
|
1902
1984
|
e.errors.billingAddress ?? {},
|
|
1903
|
-
|
|
1985
|
+
oe(e.touched, "billingAddress")
|
|
1904
1986
|
), this.componentManager.updateShippingAddressSection(
|
|
1905
|
-
e.formData.shippingAddress ??
|
|
1987
|
+
e.formData.shippingAddress ?? re,
|
|
1906
1988
|
e.errors.shippingAddress ?? {},
|
|
1907
|
-
|
|
1989
|
+
oe(e.touched, "shippingAddress")
|
|
1908
1990
|
), this.componentManager.updateSubmitButton(t);
|
|
1909
1991
|
}
|
|
1910
1992
|
setLoadingState(e) {
|
|
@@ -1912,10 +1994,10 @@ class ut {
|
|
|
1912
1994
|
this.onLoadingStateChange(e);
|
|
1913
1995
|
return;
|
|
1914
1996
|
}
|
|
1915
|
-
e ? (this.hideSkeleton(), this.formSkeleton = new
|
|
1997
|
+
e ? (this.hideSkeleton(), this.formSkeleton = new ce(), this.formElement.appendChild(this.formSkeleton.getElement())) : this.hideSkeleton();
|
|
1916
1998
|
}
|
|
1917
1999
|
showSpinner(e) {
|
|
1918
|
-
this.hideSpinner(), this.spinner = new
|
|
2000
|
+
this.hideSpinner(), this.spinner = new ut({ text: e }), this.formElement.appendChild(this.spinner.getElement());
|
|
1919
2001
|
}
|
|
1920
2002
|
hideSpinner() {
|
|
1921
2003
|
this.spinner && (this.spinner.getElement().remove(), this.spinner = void 0);
|
|
@@ -1924,7 +2006,7 @@ class ut {
|
|
|
1924
2006
|
this.formSkeleton && (this.formSkeleton.getElement().remove(), this.formSkeleton = void 0);
|
|
1925
2007
|
}
|
|
1926
2008
|
setErrorMessage(e) {
|
|
1927
|
-
this.alert && (this.alert.getElement().remove(), this.alert = void 0), this.alert = new
|
|
2009
|
+
this.alert && (this.alert.getElement().remove(), this.alert = void 0), this.alert = new Se({ message: e }), this.formElement.insertBefore(
|
|
1928
2010
|
this.alert.getElement(),
|
|
1929
2011
|
this.formElement.firstChild
|
|
1930
2012
|
);
|
|
@@ -1936,7 +2018,7 @@ class ut {
|
|
|
1936
2018
|
this.spinner && (this.spinner.getElement().remove(), this.spinner = void 0), this.formSkeleton && (this.formSkeleton.getElement().remove(), this.formSkeleton = void 0), this.alert && (this.alert.getElement().remove(), this.alert = void 0);
|
|
1937
2019
|
}
|
|
1938
2020
|
}
|
|
1939
|
-
const
|
|
2021
|
+
const D = (n) => ({
|
|
1940
2022
|
street: "",
|
|
1941
2023
|
firstName: "",
|
|
1942
2024
|
lastName: "",
|
|
@@ -1946,21 +2028,21 @@ const I = (n) => ({
|
|
|
1946
2028
|
country: "",
|
|
1947
2029
|
...n
|
|
1948
2030
|
});
|
|
1949
|
-
class
|
|
2031
|
+
class pt extends w {
|
|
1950
2032
|
options;
|
|
1951
|
-
formManager =
|
|
2033
|
+
formManager = st();
|
|
1952
2034
|
checkoutProfile;
|
|
1953
|
-
translation =
|
|
1954
|
-
focusManager = new
|
|
2035
|
+
translation = Fe();
|
|
2036
|
+
focusManager = new Ce();
|
|
1955
2037
|
// Managers
|
|
1956
2038
|
componentManager;
|
|
1957
2039
|
eventHandler;
|
|
1958
2040
|
stateCoordinator;
|
|
1959
2041
|
uiManager;
|
|
1960
2042
|
constructor(e) {
|
|
1961
|
-
super("form", ["form-container"]), this.options = e, this.checkoutProfile =
|
|
2043
|
+
super("form", ["form-container"]), this.options = e, this.checkoutProfile = tt({
|
|
1962
2044
|
appearance: e.appearance
|
|
1963
|
-
}), e.locale && this.translation.setLocale(e.locale), this.componentManager = new
|
|
2045
|
+
}), e.locale && this.translation.setLocale(e.locale), this.componentManager = new dt({
|
|
1964
2046
|
formElement: this.element,
|
|
1965
2047
|
focusManager: this.focusManager,
|
|
1966
2048
|
translationFunc: this.translation.t,
|
|
@@ -1975,11 +2057,11 @@ class mt extends A {
|
|
|
1975
2057
|
checkoutKey: e.checkoutKey,
|
|
1976
2058
|
checkoutDetails: e.checkoutDetails,
|
|
1977
2059
|
environment: e.environment
|
|
1978
|
-
}), this.uiManager = new
|
|
2060
|
+
}), this.uiManager = new mt({
|
|
1979
2061
|
formElement: this.element,
|
|
1980
2062
|
componentManager: this.componentManager,
|
|
1981
2063
|
onLoadingStateChange: e.onLoadingStateChange
|
|
1982
|
-
}), this.stateCoordinator = new
|
|
2064
|
+
}), this.stateCoordinator = new ht({
|
|
1983
2065
|
formManager: this.formManager,
|
|
1984
2066
|
checkoutProfile: this.checkoutProfile,
|
|
1985
2067
|
componentManager: this.componentManager,
|
|
@@ -1989,7 +2071,7 @@ class mt extends A {
|
|
|
1989
2071
|
onError: (t) => this.uiManager.setErrorMessage(t),
|
|
1990
2072
|
onLoadingChange: (t) => this.uiManager.setLoadingState(t),
|
|
1991
2073
|
getInitialFormData: () => this._getFormStateData().formData
|
|
1992
|
-
}), this.eventHandler = new
|
|
2074
|
+
}), this.eventHandler = new ct({
|
|
1993
2075
|
formManager: this.formManager,
|
|
1994
2076
|
focusManager: this.focusManager,
|
|
1995
2077
|
onFormSubmit: async () => this.handleSubmit(),
|
|
@@ -2014,12 +2096,12 @@ class mt extends A {
|
|
|
2014
2096
|
},
|
|
2015
2097
|
...e.initialValues.name && { name: e.initialValues.name },
|
|
2016
2098
|
...e.initialValues.billingAddress && {
|
|
2017
|
-
billingAddress:
|
|
2099
|
+
billingAddress: D(
|
|
2018
2100
|
e.initialValues.billingAddress
|
|
2019
2101
|
)
|
|
2020
2102
|
},
|
|
2021
2103
|
...e.initialValues.shippingAddress && {
|
|
2022
|
-
shippingAddress:
|
|
2104
|
+
shippingAddress: D(
|
|
2023
2105
|
e.initialValues.shippingAddress
|
|
2024
2106
|
)
|
|
2025
2107
|
}
|
|
@@ -2036,10 +2118,10 @@ class mt extends A {
|
|
|
2036
2118
|
cardNumber: "",
|
|
2037
2119
|
cardCvv: "",
|
|
2038
2120
|
...t?.billingAddress && {
|
|
2039
|
-
billingAddress:
|
|
2121
|
+
billingAddress: D(t.billingAddress)
|
|
2040
2122
|
},
|
|
2041
2123
|
...t?.shippingAddress && {
|
|
2042
|
-
shippingAddress:
|
|
2124
|
+
shippingAddress: D(t.shippingAddress)
|
|
2043
2125
|
}
|
|
2044
2126
|
},
|
|
2045
2127
|
errors: e.errors || {},
|
|
@@ -2055,12 +2137,15 @@ class mt extends A {
|
|
|
2055
2137
|
this.uiManager.setErrorMessage("Failed to load checkout configuration");
|
|
2056
2138
|
return;
|
|
2057
2139
|
}
|
|
2058
|
-
this.componentManager.hasComponents() && this.componentManager.cleanup(), e.checkoutProfile.layout.phoneNumber?.enabled && this.formManager.getFormState().formData.phoneNumber === void 0 && this.formManager.setFormData({
|
|
2059
|
-
|
|
2140
|
+
this.componentManager.hasComponents() && this.componentManager.cleanup(), e.checkoutProfile.layout.phoneNumber?.enabled && this.formManager.getFormState().formData.phoneNumber === void 0 && this.formManager.setFormData({
|
|
2141
|
+
phoneNumber: "",
|
|
2142
|
+
phoneCountryCode: e.checkoutProfile.layout.phoneNumber.defaultCountry?.toUpperCase() || "US"
|
|
2143
|
+
}), e.checkoutProfile.layout.billingFields && this.formManager.getFormState().formData.billingAddress === void 0 && this.formManager.setFormData({
|
|
2144
|
+
billingAddress: D()
|
|
2060
2145
|
}), e.checkoutProfile.layout.shippingFields && this.formManager.getFormState().formData.shippingAddress === void 0 && this.formManager.setFormData({
|
|
2061
|
-
shippingAddress:
|
|
2146
|
+
shippingAddress: D()
|
|
2062
2147
|
});
|
|
2063
|
-
const { formData: t, errors: s, touched:
|
|
2148
|
+
const { formData: t, errors: s, touched: a } = this._getFormStateData(), i = Z(
|
|
2064
2149
|
e.checkoutProfile.layout
|
|
2065
2150
|
);
|
|
2066
2151
|
try {
|
|
@@ -2076,18 +2161,18 @@ class mt extends A {
|
|
|
2076
2161
|
e.checkoutProfile,
|
|
2077
2162
|
t,
|
|
2078
2163
|
s,
|
|
2079
|
-
|
|
2164
|
+
a
|
|
2080
2165
|
);
|
|
2081
2166
|
} catch (r) {
|
|
2082
2167
|
console.error("Failed to create email field:", r);
|
|
2083
2168
|
}
|
|
2084
|
-
if (
|
|
2169
|
+
if (i) {
|
|
2085
2170
|
try {
|
|
2086
2171
|
this.componentManager.createBillingAddressSection(
|
|
2087
2172
|
e.checkoutProfile,
|
|
2088
2173
|
t,
|
|
2089
2174
|
s,
|
|
2090
|
-
|
|
2175
|
+
a
|
|
2091
2176
|
);
|
|
2092
2177
|
} catch (r) {
|
|
2093
2178
|
console.error("Failed to create billing address section:", r);
|
|
@@ -2097,7 +2182,7 @@ class mt extends A {
|
|
|
2097
2182
|
e.checkoutProfile,
|
|
2098
2183
|
t,
|
|
2099
2184
|
s,
|
|
2100
|
-
|
|
2185
|
+
a
|
|
2101
2186
|
);
|
|
2102
2187
|
} catch (r) {
|
|
2103
2188
|
console.error("Failed to create shipping address section:", r);
|
|
@@ -2109,7 +2194,7 @@ class mt extends A {
|
|
|
2109
2194
|
e.checkoutProfile,
|
|
2110
2195
|
t,
|
|
2111
2196
|
s,
|
|
2112
|
-
|
|
2197
|
+
a
|
|
2113
2198
|
);
|
|
2114
2199
|
} catch (r) {
|
|
2115
2200
|
console.error("Failed to create phone number field:", r);
|
|
@@ -2119,18 +2204,18 @@ class mt extends A {
|
|
|
2119
2204
|
e.checkoutProfile,
|
|
2120
2205
|
t,
|
|
2121
2206
|
s,
|
|
2122
|
-
|
|
2207
|
+
a
|
|
2123
2208
|
);
|
|
2124
2209
|
} catch (r) {
|
|
2125
2210
|
console.error("Failed to create card section:", r);
|
|
2126
2211
|
}
|
|
2127
|
-
if (!
|
|
2212
|
+
if (!i)
|
|
2128
2213
|
try {
|
|
2129
2214
|
this.componentManager.createCardholderSection(
|
|
2130
2215
|
e.checkoutProfile,
|
|
2131
2216
|
t,
|
|
2132
2217
|
s,
|
|
2133
|
-
|
|
2218
|
+
a
|
|
2134
2219
|
);
|
|
2135
2220
|
} catch (r) {
|
|
2136
2221
|
console.error("Failed to create cardholder section:", r);
|
|
@@ -2157,13 +2242,13 @@ class mt extends A {
|
|
|
2157
2242
|
*/
|
|
2158
2243
|
inferCardholderName() {
|
|
2159
2244
|
const e = this.checkoutProfile.getState();
|
|
2160
|
-
if (!e.checkoutProfile ||
|
|
2245
|
+
if (!e.checkoutProfile || !Z(
|
|
2161
2246
|
e.checkoutProfile.layout
|
|
2162
2247
|
)) return;
|
|
2163
|
-
const { formData: s } = this._getFormStateData(),
|
|
2164
|
-
if (!
|
|
2165
|
-
const
|
|
2166
|
-
|
|
2248
|
+
const { formData: s } = this._getFormStateData(), a = s.billingAddress ?? s.shippingAddress;
|
|
2249
|
+
if (!a) return;
|
|
2250
|
+
const i = a.firstName?.trim() ?? "", r = a.lastName?.trim() ?? "", l = [i, r].filter(Boolean).join(" ");
|
|
2251
|
+
l && this.formManager.setFormData({ name: l });
|
|
2167
2252
|
}
|
|
2168
2253
|
/**
|
|
2169
2254
|
* Infers address data based on field configuration.
|
|
@@ -2173,10 +2258,10 @@ class mt extends A {
|
|
|
2173
2258
|
inferAddresses() {
|
|
2174
2259
|
const e = this.checkoutProfile.getState();
|
|
2175
2260
|
if (!e.checkoutProfile) return;
|
|
2176
|
-
const { billingFields: t, shippingFields: s } = e.checkoutProfile.layout,
|
|
2177
|
-
!
|
|
2261
|
+
const { billingFields: t, shippingFields: s } = e.checkoutProfile.layout, a = t && Object.values(t).some((l) => l?.enabled), i = s && Object.values(s).some((l) => l?.enabled), { formData: r } = this._getFormStateData();
|
|
2262
|
+
!a && i && r.shippingAddress ? this.formManager.setFormData({
|
|
2178
2263
|
billingAddress: { ...r.shippingAddress }
|
|
2179
|
-
}) : !
|
|
2264
|
+
}) : !i && a && r.billingAddress && this.formManager.setFormData({
|
|
2180
2265
|
shippingAddress: { ...r.billingAddress }
|
|
2181
2266
|
});
|
|
2182
2267
|
}
|
|
@@ -2236,26 +2321,26 @@ class mt extends A {
|
|
|
2236
2321
|
this.eventHandler.handleKeyDown
|
|
2237
2322
|
), this.componentManager.cleanup(), this.uiManager.cleanup(), this.getElement().remove();
|
|
2238
2323
|
}
|
|
2239
|
-
associatePayment(e, t, s,
|
|
2240
|
-
this.options.paymentId = e, this.options.checkoutKey = t, this.options.supportedPaymentMethods = s, this.options.checkoutDetails =
|
|
2324
|
+
associatePayment(e, t, s, a) {
|
|
2325
|
+
this.options.paymentId = e, this.options.checkoutKey = t, this.options.supportedPaymentMethods = s, this.options.checkoutDetails = a, this.componentManager.removePaymentMethods(), this.componentManager.updateSupportedPaymentMethods(
|
|
2241
2326
|
s
|
|
2242
2327
|
), this.componentManager.updatePaymentDetails(
|
|
2243
2328
|
e,
|
|
2244
2329
|
t,
|
|
2245
|
-
|
|
2330
|
+
a
|
|
2246
2331
|
);
|
|
2247
|
-
const
|
|
2248
|
-
if (
|
|
2332
|
+
const i = this.checkoutProfile.getState();
|
|
2333
|
+
if (i.checkoutProfile) {
|
|
2249
2334
|
const { formData: r } = this._getFormStateData();
|
|
2250
2335
|
this.componentManager.createPaymentMethods(
|
|
2251
|
-
|
|
2336
|
+
i.checkoutProfile,
|
|
2252
2337
|
r,
|
|
2253
2338
|
!0
|
|
2254
2339
|
);
|
|
2255
2340
|
}
|
|
2256
2341
|
}
|
|
2257
2342
|
}
|
|
2258
|
-
class
|
|
2343
|
+
class ft {
|
|
2259
2344
|
container = null;
|
|
2260
2345
|
options;
|
|
2261
2346
|
onSubmit;
|
|
@@ -2279,7 +2364,7 @@ class pt {
|
|
|
2279
2364
|
}
|
|
2280
2365
|
}
|
|
2281
2366
|
renderForm(e) {
|
|
2282
|
-
this.container && (this.form && (this.form.destroy(), this.form = null), this.form = new
|
|
2367
|
+
this.container && (this.form && (this.form.destroy(), this.form = null), this.form = new pt({
|
|
2283
2368
|
apiKey: this.options.apiKey,
|
|
2284
2369
|
onSubmit: this.onSubmit,
|
|
2285
2370
|
locale: this.options.locale,
|
|
@@ -2305,16 +2390,16 @@ class pt {
|
|
|
2305
2390
|
clearError() {
|
|
2306
2391
|
this.form && this.form.clearErrorMessage();
|
|
2307
2392
|
}
|
|
2308
|
-
async associatePayment(e, t, s,
|
|
2309
|
-
this.options.paymentId = e, this.options.checkoutKey = t, this.options.checkoutDetails =
|
|
2393
|
+
async associatePayment(e, t, s, a) {
|
|
2394
|
+
this.options.paymentId = e, this.options.checkoutKey = t, this.options.checkoutDetails = a, this.form && this.form.associatePayment(
|
|
2310
2395
|
e,
|
|
2311
2396
|
t,
|
|
2312
2397
|
s,
|
|
2313
|
-
|
|
2398
|
+
a
|
|
2314
2399
|
);
|
|
2315
2400
|
}
|
|
2316
2401
|
}
|
|
2317
|
-
class
|
|
2402
|
+
class gt {
|
|
2318
2403
|
state;
|
|
2319
2404
|
listeners = /* @__PURE__ */ new Set();
|
|
2320
2405
|
constructor(e) {
|
|
@@ -2336,8 +2421,8 @@ class ft {
|
|
|
2336
2421
|
this.listeners.forEach((t) => t(e));
|
|
2337
2422
|
}
|
|
2338
2423
|
}
|
|
2339
|
-
const
|
|
2340
|
-
class
|
|
2424
|
+
const yt = "en";
|
|
2425
|
+
class bt {
|
|
2341
2426
|
config;
|
|
2342
2427
|
paymentState;
|
|
2343
2428
|
apiService;
|
|
@@ -2345,18 +2430,18 @@ class yt {
|
|
|
2345
2430
|
stateManager;
|
|
2346
2431
|
sessionId;
|
|
2347
2432
|
constructor(e) {
|
|
2348
|
-
this.config = this.validateConfig(e), this.paymentState = {}, this.sessionId = crypto.randomUUID(),
|
|
2433
|
+
this.config = this.validateConfig(e), this.paymentState = {}, this.sessionId = crypto.randomUUID(), Je({
|
|
2349
2434
|
environment: this.config.environment,
|
|
2350
2435
|
sessionId: this.sessionId
|
|
2351
|
-
}),
|
|
2436
|
+
}), M(v.CHECKOUT_INITIALIZED, {
|
|
2352
2437
|
environment: this.config.environment
|
|
2353
2438
|
}), this.apiService = new ve(
|
|
2354
2439
|
this.config.apiKey,
|
|
2355
2440
|
this.config.environment
|
|
2356
|
-
), this.stateManager = new
|
|
2441
|
+
), this.stateManager = new gt({
|
|
2357
2442
|
mounted: !1,
|
|
2358
2443
|
form: null
|
|
2359
|
-
}), this.formManager = new
|
|
2444
|
+
}), this.formManager = new ft(
|
|
2360
2445
|
{
|
|
2361
2446
|
locale: this.config.locale,
|
|
2362
2447
|
apiKey: this.config.apiKey,
|
|
@@ -2378,7 +2463,7 @@ class yt {
|
|
|
2378
2463
|
apiKey: e.apiKey,
|
|
2379
2464
|
returnUrl: e.returnUrl,
|
|
2380
2465
|
environment: e.environment,
|
|
2381
|
-
locale: e.locale ||
|
|
2466
|
+
locale: e.locale || yt,
|
|
2382
2467
|
disableErrorMessages: e.disableErrorMessages ?? !1,
|
|
2383
2468
|
manualActionHandling: e.manualActionHandling ?? !1,
|
|
2384
2469
|
appearance: e.appearance,
|
|
@@ -2399,7 +2484,7 @@ class yt {
|
|
|
2399
2484
|
return t.appendChild(s), this.stateManager.updateState({
|
|
2400
2485
|
form: s,
|
|
2401
2486
|
mounted: !0
|
|
2402
|
-
}), this.formManager.mount(s),
|
|
2487
|
+
}), this.formManager.mount(s), M(v.CHECKOUT_MOUNTED, {
|
|
2403
2488
|
container_id: e
|
|
2404
2489
|
}), this;
|
|
2405
2490
|
}
|
|
@@ -2411,7 +2496,7 @@ class yt {
|
|
|
2411
2496
|
t && t.remove(), this.stateManager.updateState({
|
|
2412
2497
|
form: null,
|
|
2413
2498
|
mounted: !1
|
|
2414
|
-
}),
|
|
2499
|
+
}), M(v.CHECKOUT_UNMOUNTED);
|
|
2415
2500
|
});
|
|
2416
2501
|
}
|
|
2417
2502
|
async handleSubmit({
|
|
@@ -2423,21 +2508,21 @@ class yt {
|
|
|
2423
2508
|
"Payment must be associated before submitting. Call associatePayment() first."
|
|
2424
2509
|
);
|
|
2425
2510
|
const s = this.getPaymentMethod(e, t);
|
|
2426
|
-
|
|
2511
|
+
M(v.PAYMENT_SUBMIT_STARTED, {
|
|
2427
2512
|
payment_id: this.paymentState.paymentId,
|
|
2428
2513
|
payment_method: s
|
|
2429
2514
|
});
|
|
2430
|
-
const
|
|
2515
|
+
const a = performance.now();
|
|
2431
2516
|
try {
|
|
2432
|
-
const
|
|
2517
|
+
const i = await this.apiService.authorizePayment({
|
|
2433
2518
|
checkoutKey: this.paymentState.checkoutKey,
|
|
2434
2519
|
formData: e || null,
|
|
2435
2520
|
paymentId: this.paymentState.paymentId,
|
|
2436
2521
|
returnUrl: this.config.returnUrl,
|
|
2437
2522
|
applePayData: t
|
|
2438
|
-
}), r = performance.now() -
|
|
2439
|
-
|
|
2440
|
-
|
|
2523
|
+
}), r = performance.now() - a;
|
|
2524
|
+
ae(
|
|
2525
|
+
J.PAYMENT_AUTHORIZATION_TIME,
|
|
2441
2526
|
r,
|
|
2442
2527
|
"ms",
|
|
2443
2528
|
{
|
|
@@ -2445,14 +2530,14 @@ class yt {
|
|
|
2445
2530
|
payment_method: s,
|
|
2446
2531
|
status: "success"
|
|
2447
2532
|
}
|
|
2448
|
-
),
|
|
2533
|
+
), M(v.PAYMENT_SUBMIT_SUCCESS, {
|
|
2449
2534
|
payment_id: this.paymentState.paymentId,
|
|
2450
2535
|
payment_method: s
|
|
2451
|
-
}), this.handlePaymentResponse(
|
|
2452
|
-
} catch (
|
|
2453
|
-
const r = performance.now() -
|
|
2454
|
-
|
|
2455
|
-
|
|
2536
|
+
}), this.handlePaymentResponse(i);
|
|
2537
|
+
} catch (i) {
|
|
2538
|
+
const r = performance.now() - a;
|
|
2539
|
+
ae(
|
|
2540
|
+
J.PAYMENT_AUTHORIZATION_TIME,
|
|
2456
2541
|
r,
|
|
2457
2542
|
"ms",
|
|
2458
2543
|
{
|
|
@@ -2460,25 +2545,25 @@ class yt {
|
|
|
2460
2545
|
payment_method: s,
|
|
2461
2546
|
status: "failed"
|
|
2462
2547
|
}
|
|
2463
|
-
),
|
|
2548
|
+
), M(v.PAYMENT_SUBMIT_FAILED, {
|
|
2464
2549
|
payment_id: this.paymentState.paymentId,
|
|
2465
2550
|
payment_method: s,
|
|
2466
|
-
error_message:
|
|
2467
|
-
}), this.handleAuthorizationError(
|
|
2551
|
+
error_message: i.details?.message ?? "Unknown error"
|
|
2552
|
+
}), this.handleAuthorizationError(i);
|
|
2468
2553
|
}
|
|
2469
2554
|
}
|
|
2470
2555
|
handlePaymentResponse(e) {
|
|
2471
|
-
if (e.latestTransaction.status === "authorized" && (
|
|
2556
|
+
if (e.latestTransaction.status === "authorized" && (M(v.PAYMENT_AUTHORIZED, {
|
|
2472
2557
|
payment_id: this.paymentState.paymentId ?? "",
|
|
2473
2558
|
status: e.latestTransaction.status
|
|
2474
2559
|
}), this.config.callbacks.onPaymentSucceeded?.(
|
|
2475
2560
|
e.latestTransaction.status
|
|
2476
|
-
)), e.latestTransaction.status === "failed" && (
|
|
2561
|
+
)), e.latestTransaction.status === "failed" && (M(v.PAYMENT_FAILED, {
|
|
2477
2562
|
payment_id: this.paymentState.paymentId ?? "",
|
|
2478
2563
|
status: e.latestTransaction.status
|
|
2479
2564
|
}), this.config.callbacks.onPaymentFailed?.(e.latestTransaction.status)), e.status === "requires_action") {
|
|
2480
2565
|
const { redirectUrl: t } = e.action;
|
|
2481
|
-
|
|
2566
|
+
M(v.PAYMENT_ACTION_REQUIRED, {
|
|
2482
2567
|
payment_id: this.paymentState.paymentId ?? "",
|
|
2483
2568
|
status: e.status
|
|
2484
2569
|
}), this.config.manualActionHandling ? this.config.callbacks.onActionRequired?.(t) : globalThis.location.href = t;
|
|
@@ -2518,7 +2603,7 @@ class yt {
|
|
|
2518
2603
|
throw new Error("paymentId and checkoutKey are required");
|
|
2519
2604
|
this.paymentState.paymentId = e, this.paymentState.checkoutKey = t;
|
|
2520
2605
|
try {
|
|
2521
|
-
const s = await
|
|
2606
|
+
const s = await Me({
|
|
2522
2607
|
id: e,
|
|
2523
2608
|
checkoutKey: t,
|
|
2524
2609
|
environment: this.config.environment
|
|
@@ -2528,7 +2613,7 @@ class yt {
|
|
|
2528
2613
|
"Invalid response: supportedPaymentMethods must be an array"
|
|
2529
2614
|
);
|
|
2530
2615
|
if (!s.supportedPaymentMethods.every(
|
|
2531
|
-
(
|
|
2616
|
+
(i) => typeof i == "string"
|
|
2532
2617
|
))
|
|
2533
2618
|
throw new Error(
|
|
2534
2619
|
"Invalid response: all supportedPaymentMethods must be strings"
|
|
@@ -2538,44 +2623,44 @@ class yt {
|
|
|
2538
2623
|
currency: s.currency,
|
|
2539
2624
|
countryCode: s.countryCode
|
|
2540
2625
|
};
|
|
2541
|
-
const
|
|
2542
|
-
(
|
|
2626
|
+
const a = s.supportedPaymentMethods.reduce(
|
|
2627
|
+
(i, r) => (i[r] = !0, i),
|
|
2543
2628
|
{}
|
|
2544
2629
|
);
|
|
2545
2630
|
await this.formManager.associatePayment(
|
|
2546
2631
|
e,
|
|
2547
2632
|
t,
|
|
2548
|
-
|
|
2633
|
+
a,
|
|
2549
2634
|
this.paymentState.checkoutDetails
|
|
2550
|
-
),
|
|
2635
|
+
), M(v.PAYMENT_ASSOCIATED, {
|
|
2551
2636
|
payment_id: e,
|
|
2552
2637
|
currency: s.currency,
|
|
2553
2638
|
country_code: s.countryCode
|
|
2554
2639
|
});
|
|
2555
2640
|
} catch (s) {
|
|
2556
|
-
throw
|
|
2641
|
+
throw M(v.PAYMENT_ASSOCIATION_FAILED, {
|
|
2557
2642
|
payment_id: e,
|
|
2558
2643
|
error_message: s instanceof Error ? s.message : "Unknown error"
|
|
2559
|
-
}),
|
|
2644
|
+
}), et(
|
|
2560
2645
|
s instanceof Error ? s : new Error("Failed to associate payment"),
|
|
2561
2646
|
{ payment_id: e }
|
|
2562
2647
|
), s;
|
|
2563
2648
|
}
|
|
2564
2649
|
}
|
|
2565
2650
|
}
|
|
2566
|
-
typeof globalThis < "u" && (globalThis.OdusCheckout =
|
|
2651
|
+
typeof globalThis < "u" && (globalThis.OdusCheckout = bt);
|
|
2567
2652
|
export {
|
|
2568
|
-
|
|
2653
|
+
bt as OdusCheckout,
|
|
2569
2654
|
vt as deLocale,
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2655
|
+
Mt as enLocale,
|
|
2656
|
+
Nt as esLocale,
|
|
2657
|
+
Pt as frLocale,
|
|
2658
|
+
At as itLocale,
|
|
2659
|
+
wt as plLocale,
|
|
2660
|
+
kt as ptLocale,
|
|
2661
|
+
et as pushError,
|
|
2662
|
+
M as pushEvent,
|
|
2663
|
+
St as pushLog,
|
|
2664
|
+
ae as pushMeasurement,
|
|
2665
|
+
It as trLocale
|
|
2581
2666
|
};
|