@odus/checkout 0.29.0 → 0.30.0-beta.0
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 +1222 -805
- package/dist/elements.es.js +2 -2
- package/dist/index.css +1 -1
- package/dist/package.json +2 -1
- package/dist/phone.js +1 -1
- package/dist/shared.js +4353 -1935
- package/package.json +2 -1
package/dist/checkout.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
1
|
+
import { l as pe, c as de, a as ge, f as U, d as fe, C as P, I as ce, g as ye, S as H, b as Z, H as be, V as J, e as k, A as ve, P as Se, E as Ee, h as Ce, i as Fe, j as Me, k as Ne, m as we, n as Pe, F as ke, o as Ae, p as De } from "./shared.js";
|
|
2
|
+
import { q as Tt, r as Lt, s as Vt, t as _t, u as Bt, v as Ot, w as Rt, x as Ut } from "./shared.js";
|
|
3
|
+
const C = {
|
|
4
4
|
// Checkout lifecycle events
|
|
5
5
|
CHECKOUT_INITIALIZED: "checkout.initialized",
|
|
6
6
|
CHECKOUT_MOUNTED: "checkout.mounted",
|
|
@@ -16,88 +16,88 @@ const v = {
|
|
|
16
16
|
PAYMENT_AUTHORIZED: "payment.authorized",
|
|
17
17
|
PAYMENT_FAILED: "payment.failed",
|
|
18
18
|
PAYMENT_ACTION_REQUIRED: "payment.action_required"
|
|
19
|
-
},
|
|
19
|
+
}, X = {
|
|
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
|
-
},
|
|
24
|
-
if (!
|
|
23
|
+
}, Ie = /^\s*at (?:(.+?) ?\()?((?:file|https?|chrome-extension|webpack-internal):\/\/.+?):(\d+):(\d+)\)?\s*$/, xe = /^([^@]+)@((?:file|https?|chrome-extension|webpack-internal):\/\/[^\s:]+):(\d+):(\d+)$/, Te = /^(?:([^@]+)@)?((?:file|https?):\/\/[^\s:]+):(\d+):(\d+)$/, q = (i) => {
|
|
24
|
+
if (!i)
|
|
25
25
|
return [];
|
|
26
|
-
const e = [], t =
|
|
26
|
+
const e = [], t = i.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 n = Ie.exec(a);
|
|
33
|
+
if (n) {
|
|
34
34
|
e.push({
|
|
35
|
-
function:
|
|
36
|
-
filename:
|
|
37
|
-
lineno: parseInt(
|
|
38
|
-
colno: parseInt(
|
|
35
|
+
function: n[1] || "(anonymous)",
|
|
36
|
+
filename: n[2],
|
|
37
|
+
lineno: parseInt(n[3], 10),
|
|
38
|
+
colno: parseInt(n[4], 10)
|
|
39
39
|
});
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
function:
|
|
44
|
-
filename:
|
|
45
|
-
lineno: parseInt(
|
|
46
|
-
colno: parseInt(
|
|
42
|
+
n = xe.exec(a) ?? Te.exec(a), n && e.push({
|
|
43
|
+
function: n[1] || "(anonymous)",
|
|
44
|
+
filename: n[2],
|
|
45
|
+
lineno: parseInt(n[3], 10),
|
|
46
|
+
colno: parseInt(n[4], 10)
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
return e;
|
|
50
|
-
},
|
|
51
|
-
let
|
|
52
|
-
const
|
|
50
|
+
}, Le = "@odus/telemetry", Ve = "0.0.1";
|
|
51
|
+
let B, O, Y;
|
|
52
|
+
const _e = () => {
|
|
53
53
|
if (typeof navigator > "u")
|
|
54
54
|
return {};
|
|
55
|
-
const
|
|
55
|
+
const i = navigator.userAgent;
|
|
56
56
|
let e, t, s;
|
|
57
|
-
|
|
58
|
-
const
|
|
57
|
+
i.includes("Firefox/") ? (e = "Firefox", t = i.match(/Firefox\/([\d.]+)/)?.[1]) : i.includes("Edg/") ? (e = "Edge", t = i.match(/Edg\/([\d.]+)/)?.[1]) : i.includes("Chrome/") ? (e = "Chrome", t = i.match(/Chrome\/([\d.]+)/)?.[1]) : i.includes("Safari/") && (e = "Safari", t = i.match(/Version\/([\d.]+)/)?.[1]), i.includes("Windows") ? s = "Windows" : i.includes("Mac OS") ? s = "macOS" : i.includes("Linux") ? s = "Linux" : i.includes("Android") ? s = "Android" : (i.includes("iPhone") || i.includes("iPad")) && (s = "iOS");
|
|
58
|
+
const a = /Mobi|Android|iPhone|iPad/i.test(i) || 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
|
-
userAgent:
|
|
67
|
+
userAgent: i
|
|
68
68
|
};
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
Y =
|
|
79
|
-
},
|
|
80
|
-
sdk: { name:
|
|
81
|
-
app:
|
|
82
|
-
user:
|
|
83
|
-
session:
|
|
84
|
-
page:
|
|
85
|
-
browser:
|
|
69
|
+
}, Be = () => typeof window > "u" ? {} : { url: window.location.href }, Oe = (i) => {
|
|
70
|
+
B = void 0, Y = void 0, O = i.sessionTracking?.session ? { id: i.sessionTracking.session.id } : void 0;
|
|
71
|
+
}, Re = (i) => {
|
|
72
|
+
B = i;
|
|
73
|
+
}, Ue = () => {
|
|
74
|
+
B = void 0;
|
|
75
|
+
}, He = (i) => {
|
|
76
|
+
O = i;
|
|
77
|
+
}, ze = (i) => {
|
|
78
|
+
Y = i;
|
|
79
|
+
}, $e = () => O?.id, je = (i) => ({
|
|
80
|
+
sdk: { name: Le, version: Ve },
|
|
81
|
+
app: i.app,
|
|
82
|
+
user: B,
|
|
83
|
+
session: O,
|
|
84
|
+
page: Be(),
|
|
85
|
+
browser: _e(),
|
|
86
86
|
view: Y
|
|
87
|
-
}),
|
|
88
|
-
let
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
87
|
+
}), Ke = 30, qe = 250, We = 6e4;
|
|
88
|
+
let A = [], w = null, G = 0, T = null, L = null;
|
|
89
|
+
const Ye = (i) => {
|
|
90
|
+
if (w)
|
|
91
91
|
return;
|
|
92
|
-
const e =
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
const e = i.batching?.sendTimeout ?? qe;
|
|
93
|
+
w = setTimeout(() => {
|
|
94
|
+
R(i);
|
|
95
95
|
}, e);
|
|
96
|
-
},
|
|
96
|
+
}, Ge = (i, e) => {
|
|
97
97
|
const t = {
|
|
98
|
-
meta:
|
|
98
|
+
meta: je(e)
|
|
99
99
|
};
|
|
100
|
-
for (const s of
|
|
100
|
+
for (const s of i)
|
|
101
101
|
switch (s.type) {
|
|
102
102
|
case "exception":
|
|
103
103
|
(t.exceptions ??= []).push(s.payload);
|
|
@@ -113,248 +113,248 @@ const He = (n) => {
|
|
|
113
113
|
break;
|
|
114
114
|
}
|
|
115
115
|
return t;
|
|
116
|
-
},
|
|
117
|
-
const s = JSON.stringify(
|
|
116
|
+
}, Ze = (i, e, t = !1) => {
|
|
117
|
+
const s = JSON.stringify(i), a = $e(), n = {
|
|
118
118
|
"Content-Type": "application/json"
|
|
119
119
|
};
|
|
120
|
-
if (
|
|
121
|
-
const
|
|
122
|
-
navigator.sendBeacon(e,
|
|
120
|
+
if (a && (n["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 < We;
|
|
126
126
|
fetch(e, {
|
|
127
127
|
method: "POST",
|
|
128
|
-
headers:
|
|
128
|
+
headers: n,
|
|
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"), c = d ? parseInt(d, 10) * 1e3 : 3e4;
|
|
134
|
+
G = Date.now() + c;
|
|
135
135
|
}
|
|
136
136
|
}).catch(() => {
|
|
137
137
|
});
|
|
138
|
-
},
|
|
139
|
-
if (
|
|
138
|
+
}, R = (i, e = !1) => {
|
|
139
|
+
if (w && (clearTimeout(w), w = null), A.length === 0)
|
|
140
140
|
return;
|
|
141
|
-
if (Date.now() <
|
|
142
|
-
|
|
141
|
+
if (Date.now() < G) {
|
|
142
|
+
A = [];
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
|
-
const t =
|
|
146
|
-
|
|
145
|
+
const t = A;
|
|
146
|
+
A = [];
|
|
147
147
|
try {
|
|
148
|
-
let s =
|
|
149
|
-
if (
|
|
150
|
-
const
|
|
151
|
-
if (!
|
|
148
|
+
let s = Ge(t, i);
|
|
149
|
+
if (i.beforeSend) {
|
|
150
|
+
const a = i.beforeSend(s);
|
|
151
|
+
if (!a)
|
|
152
152
|
return;
|
|
153
|
-
s =
|
|
153
|
+
s = a;
|
|
154
154
|
}
|
|
155
|
-
|
|
155
|
+
Ze(s, i.url, e);
|
|
156
156
|
} catch {
|
|
157
157
|
}
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
const t = e.batching?.itemLimit ??
|
|
161
|
-
if (
|
|
162
|
-
|
|
158
|
+
}, N = (i, e) => {
|
|
159
|
+
A.push(i);
|
|
160
|
+
const t = e.batching?.itemLimit ?? Ke;
|
|
161
|
+
if (A.length >= t) {
|
|
162
|
+
R(e);
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
},
|
|
167
|
-
if (
|
|
165
|
+
Ye(e);
|
|
166
|
+
}, Je = (i) => {
|
|
167
|
+
if (A = [], G = 0, w && (clearTimeout(w), w = null), typeof document > "u")
|
|
168
168
|
return;
|
|
169
169
|
T && document.removeEventListener("visibilitychange", T), L && window.removeEventListener("pagehide", L);
|
|
170
|
-
const e = () =>
|
|
170
|
+
const e = () => R(i, !0);
|
|
171
171
|
T = () => {
|
|
172
172
|
document.visibilityState === "hidden" && e();
|
|
173
173
|
}, L = e, document.addEventListener("visibilitychange", T), window.addEventListener("pagehide", L);
|
|
174
|
-
},
|
|
175
|
-
let
|
|
176
|
-
const
|
|
177
|
-
typeof window > "u" || (
|
|
174
|
+
}, Q = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
175
|
+
let ee = null, te = null;
|
|
176
|
+
const Xe = (i) => {
|
|
177
|
+
typeof window > "u" || (ee = (e) => {
|
|
178
178
|
const t = e.error instanceof Error ? e.error : new Error(e.message);
|
|
179
|
-
|
|
179
|
+
N({
|
|
180
180
|
type: "exception",
|
|
181
181
|
payload: {
|
|
182
182
|
type: t.name,
|
|
183
183
|
value: t.message,
|
|
184
|
-
timestamp:
|
|
184
|
+
timestamp: Q(),
|
|
185
185
|
stacktrace: t.stack ? { frames: q(t.stack) } : void 0
|
|
186
186
|
}
|
|
187
|
-
},
|
|
188
|
-
},
|
|
187
|
+
}, i);
|
|
188
|
+
}, te = (e) => {
|
|
189
189
|
const t = e.reason, s = t instanceof Error ? t : new Error(String(t));
|
|
190
|
-
|
|
190
|
+
N({
|
|
191
191
|
type: "exception",
|
|
192
192
|
payload: {
|
|
193
193
|
type: s.name,
|
|
194
194
|
value: s.message,
|
|
195
|
-
timestamp:
|
|
195
|
+
timestamp: Q(),
|
|
196
196
|
stacktrace: s.stack ? { frames: q(s.stack) } : void 0,
|
|
197
197
|
context: { source: "unhandledrejection" }
|
|
198
198
|
}
|
|
199
|
-
},
|
|
200
|
-
}, window.addEventListener("error",
|
|
201
|
-
},
|
|
202
|
-
const
|
|
203
|
-
return crypto.getRandomValues(
|
|
204
|
-
},
|
|
205
|
-
if (
|
|
206
|
-
return
|
|
199
|
+
}, i);
|
|
200
|
+
}, window.addEventListener("error", ee), window.addEventListener("unhandledrejection", te));
|
|
201
|
+
}, se = "odus_telemetry_session_id", z = () => {
|
|
202
|
+
const i = new Uint8Array(16);
|
|
203
|
+
return crypto.getRandomValues(i), Array.from(i, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
204
|
+
}, Qe = (i) => {
|
|
205
|
+
if (i)
|
|
206
|
+
return i;
|
|
207
207
|
if (typeof sessionStorage > "u")
|
|
208
|
-
return
|
|
208
|
+
return z();
|
|
209
209
|
try {
|
|
210
|
-
const e = sessionStorage.getItem(
|
|
210
|
+
const e = sessionStorage.getItem(se);
|
|
211
211
|
if (e)
|
|
212
212
|
return e;
|
|
213
|
-
const t =
|
|
214
|
-
return sessionStorage.setItem(
|
|
213
|
+
const t = z();
|
|
214
|
+
return sessionStorage.setItem(se, t), t;
|
|
215
215
|
} catch {
|
|
216
|
-
return
|
|
216
|
+
return z();
|
|
217
217
|
}
|
|
218
|
-
},
|
|
219
|
-
if (!
|
|
218
|
+
}, et = (i) => {
|
|
219
|
+
if (!i.sessionTracking?.enabled)
|
|
220
220
|
return;
|
|
221
|
-
const e =
|
|
222
|
-
|
|
223
|
-
},
|
|
224
|
-
if (typeof PerformanceObserver > "u" || !PerformanceObserver.supportedEntryTypes?.includes(
|
|
221
|
+
const e = Qe(i.sessionTracking.session?.id);
|
|
222
|
+
He({ id: e });
|
|
223
|
+
}, $ = () => (/* @__PURE__ */ new Date()).toISOString(), j = (i, e) => {
|
|
224
|
+
if (typeof PerformanceObserver > "u" || !PerformanceObserver.supportedEntryTypes?.includes(i))
|
|
225
225
|
return;
|
|
226
226
|
new PerformanceObserver((s) => {
|
|
227
|
-
for (const
|
|
228
|
-
e(
|
|
229
|
-
}).observe({ type:
|
|
230
|
-
},
|
|
227
|
+
for (const a of s.getEntries())
|
|
228
|
+
e(a);
|
|
229
|
+
}).observe({ type: i, buffered: !0 });
|
|
230
|
+
}, tt = (i) => {
|
|
231
231
|
if (typeof window > "u")
|
|
232
232
|
return;
|
|
233
233
|
j("largest-contentful-paint", (t) => {
|
|
234
|
-
|
|
234
|
+
N({
|
|
235
235
|
type: "measurement",
|
|
236
236
|
payload: {
|
|
237
237
|
type: "web-vitals",
|
|
238
238
|
values: { lcp: t.startTime },
|
|
239
|
-
timestamp:
|
|
239
|
+
timestamp: $()
|
|
240
240
|
}
|
|
241
|
-
},
|
|
241
|
+
}, i);
|
|
242
242
|
});
|
|
243
243
|
let e = 0;
|
|
244
244
|
j("layout-shift", (t) => {
|
|
245
245
|
const s = t;
|
|
246
|
-
s.hadRecentInput || (e += s.value,
|
|
246
|
+
s.hadRecentInput || (e += s.value, N({
|
|
247
247
|
type: "measurement",
|
|
248
248
|
payload: {
|
|
249
249
|
type: "web-vitals",
|
|
250
250
|
values: { cls: e },
|
|
251
|
-
timestamp:
|
|
251
|
+
timestamp: $()
|
|
252
252
|
}
|
|
253
|
-
},
|
|
253
|
+
}, i));
|
|
254
254
|
}), j("event", (t) => {
|
|
255
255
|
const s = t;
|
|
256
|
-
s.duration > 0 &&
|
|
256
|
+
s.duration > 0 && N({
|
|
257
257
|
type: "measurement",
|
|
258
258
|
payload: {
|
|
259
259
|
type: "web-vitals",
|
|
260
260
|
values: { inp: s.duration },
|
|
261
|
-
timestamp:
|
|
261
|
+
timestamp: $()
|
|
262
262
|
}
|
|
263
|
-
},
|
|
263
|
+
}, i);
|
|
264
264
|
});
|
|
265
|
-
},
|
|
265
|
+
}, _ = {
|
|
266
266
|
INFO: "info",
|
|
267
267
|
WARN: "warn",
|
|
268
268
|
ERROR: "error"
|
|
269
|
-
},
|
|
270
|
-
|
|
271
|
-
const e =
|
|
269
|
+
}, V = () => (/* @__PURE__ */ new Date()).toISOString(), st = (i) => {
|
|
270
|
+
Oe(i), Je(i);
|
|
271
|
+
const e = i.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 && et(i), e.errors !== !1 && Xe(i), e.webVitals !== !1 && tt(i), {
|
|
277
277
|
pushError(t, s) {
|
|
278
|
-
|
|
278
|
+
N({
|
|
279
279
|
type: "exception",
|
|
280
280
|
payload: {
|
|
281
281
|
type: t.name,
|
|
282
282
|
value: t.message,
|
|
283
|
-
timestamp:
|
|
283
|
+
timestamp: V(),
|
|
284
284
|
stacktrace: t.stack ? { frames: q(t.stack) } : void 0,
|
|
285
285
|
context: s?.context
|
|
286
286
|
}
|
|
287
|
-
},
|
|
287
|
+
}, i);
|
|
288
288
|
},
|
|
289
289
|
pushEvent(t, s) {
|
|
290
|
-
|
|
290
|
+
N({
|
|
291
291
|
type: "event",
|
|
292
292
|
payload: {
|
|
293
293
|
name: t,
|
|
294
|
-
timestamp:
|
|
294
|
+
timestamp: V(),
|
|
295
295
|
attributes: s
|
|
296
296
|
}
|
|
297
|
-
},
|
|
297
|
+
}, i);
|
|
298
298
|
},
|
|
299
299
|
pushMeasurement(t) {
|
|
300
|
-
|
|
300
|
+
N({
|
|
301
301
|
type: "measurement",
|
|
302
302
|
payload: {
|
|
303
303
|
type: t.type,
|
|
304
304
|
values: t.values,
|
|
305
|
-
timestamp:
|
|
305
|
+
timestamp: V(),
|
|
306
306
|
context: t.context
|
|
307
307
|
}
|
|
308
|
-
},
|
|
308
|
+
}, i);
|
|
309
309
|
},
|
|
310
310
|
pushLog(t, s) {
|
|
311
|
-
|
|
311
|
+
N({
|
|
312
312
|
type: "log",
|
|
313
313
|
payload: {
|
|
314
314
|
message: t.join(" "),
|
|
315
|
-
level: s?.level ??
|
|
316
|
-
timestamp:
|
|
315
|
+
level: s?.level ?? _.INFO,
|
|
316
|
+
timestamp: V(),
|
|
317
317
|
context: s?.context
|
|
318
318
|
}
|
|
319
|
-
},
|
|
319
|
+
}, i);
|
|
320
320
|
},
|
|
321
321
|
setUser(t) {
|
|
322
|
-
|
|
322
|
+
Re(t);
|
|
323
323
|
},
|
|
324
324
|
resetUser() {
|
|
325
|
-
|
|
325
|
+
Ue();
|
|
326
326
|
},
|
|
327
327
|
setView(t) {
|
|
328
|
-
|
|
328
|
+
ze(t);
|
|
329
329
|
},
|
|
330
330
|
flush() {
|
|
331
|
-
|
|
331
|
+
R(i);
|
|
332
332
|
}
|
|
333
333
|
};
|
|
334
|
-
},
|
|
334
|
+
}, nt = (i) => i === "test" ? "https://sandbox-analytics.odus.com/collect" : "https://analytics.odus.com/collect", it = () => {
|
|
335
335
|
if (typeof window > "u")
|
|
336
336
|
return !1;
|
|
337
|
-
const
|
|
338
|
-
return
|
|
337
|
+
const i = window.location.hostname;
|
|
338
|
+
return i === "localhost" || i === "127.0.0.1" || i === "0.0.0.0" || i === "::1" || i === "[::1]" || i.endsWith(".localhost");
|
|
339
339
|
};
|
|
340
|
-
let
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
343
|
-
return
|
|
344
|
-
if (
|
|
340
|
+
let E = null;
|
|
341
|
+
const at = (i) => {
|
|
342
|
+
if (E)
|
|
343
|
+
return E;
|
|
344
|
+
if (it())
|
|
345
345
|
return null;
|
|
346
|
-
const e =
|
|
347
|
-
return
|
|
346
|
+
const e = nt(i.environment);
|
|
347
|
+
return E = st({
|
|
348
348
|
url: e,
|
|
349
349
|
app: {
|
|
350
350
|
name: "odus-checkout",
|
|
351
|
-
environment:
|
|
351
|
+
environment: i.environment === "test" ? "sandbox" : "production"
|
|
352
352
|
},
|
|
353
353
|
isolate: !0,
|
|
354
354
|
sessionTracking: {
|
|
355
355
|
enabled: !0,
|
|
356
356
|
session: {
|
|
357
|
-
id:
|
|
357
|
+
id: i.sessionId
|
|
358
358
|
}
|
|
359
359
|
},
|
|
360
360
|
beforeSend: (t) => {
|
|
@@ -368,44 +368,236 @@ const Qe = (n) => {
|
|
|
368
368
|
"card",
|
|
369
369
|
"cvv",
|
|
370
370
|
"pan"
|
|
371
|
-
].forEach((
|
|
372
|
-
s.searchParams.has(
|
|
371
|
+
].forEach((n) => {
|
|
372
|
+
s.searchParams.has(n) && s.searchParams.set(n, "[REDACTED]");
|
|
373
373
|
}), t.meta.view.name = s.toString();
|
|
374
374
|
} catch {
|
|
375
375
|
}
|
|
376
376
|
return t;
|
|
377
377
|
}
|
|
378
|
-
}),
|
|
379
|
-
},
|
|
380
|
-
|
|
381
|
-
},
|
|
382
|
-
|
|
383
|
-
},
|
|
384
|
-
|
|
385
|
-
type:
|
|
386
|
-
values: { [
|
|
378
|
+
}), E;
|
|
379
|
+
}, rt = (i, e) => {
|
|
380
|
+
E && E.pushError(i, { context: e });
|
|
381
|
+
}, F = (i, e) => {
|
|
382
|
+
E && E.pushEvent(i, e);
|
|
383
|
+
}, ne = (i, e, t, s) => {
|
|
384
|
+
E && E.pushMeasurement({
|
|
385
|
+
type: i,
|
|
386
|
+
values: { [i]: e },
|
|
387
387
|
context: {
|
|
388
388
|
...t && { unit: t },
|
|
389
389
|
...s
|
|
390
390
|
}
|
|
391
391
|
});
|
|
392
|
-
},
|
|
393
|
-
if (!
|
|
392
|
+
}, Dt = (i, e = "info", t) => {
|
|
393
|
+
if (!E) return;
|
|
394
394
|
const s = {
|
|
395
|
-
info:
|
|
396
|
-
warn:
|
|
397
|
-
error:
|
|
395
|
+
info: _.INFO,
|
|
396
|
+
warn: _.WARN,
|
|
397
|
+
error: _.ERROR
|
|
398
398
|
};
|
|
399
|
-
|
|
399
|
+
E.pushLog([i], {
|
|
400
400
|
level: s[e],
|
|
401
401
|
context: t
|
|
402
402
|
});
|
|
403
|
+
}, ie = {
|
|
404
|
+
test: "tntwpdhfwng",
|
|
405
|
+
live: "TBD"
|
|
406
|
+
}, ae = {
|
|
407
|
+
test: "sandbox",
|
|
408
|
+
live: "live"
|
|
403
409
|
};
|
|
404
|
-
|
|
410
|
+
class I {
|
|
411
|
+
vgsForm = null;
|
|
412
|
+
fields = [];
|
|
413
|
+
readyResolve;
|
|
414
|
+
readyPromise;
|
|
415
|
+
environment;
|
|
416
|
+
constructor() {
|
|
417
|
+
this.readyPromise = new Promise((e) => {
|
|
418
|
+
this.readyResolve = e;
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
async init(e) {
|
|
422
|
+
return this.environment = e, await pe({
|
|
423
|
+
vaultId: ie[e],
|
|
424
|
+
environment: ae[e],
|
|
425
|
+
version: "3.2.2"
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
createForm(e, t) {
|
|
429
|
+
if (!this.environment)
|
|
430
|
+
throw new Error("VGS not initialized — call init() first");
|
|
431
|
+
return this.vgsForm = e.create(
|
|
432
|
+
ie[this.environment],
|
|
433
|
+
ae[this.environment],
|
|
434
|
+
t
|
|
435
|
+
), this.readyResolve?.(), this.vgsForm;
|
|
436
|
+
}
|
|
437
|
+
whenReady() {
|
|
438
|
+
return this.readyPromise;
|
|
439
|
+
}
|
|
440
|
+
mountCardFields(e, t, s, a) {
|
|
441
|
+
if (!this.vgsForm)
|
|
442
|
+
throw new Error("VGS form not initialized");
|
|
443
|
+
if (e.cardNumber) {
|
|
444
|
+
const n = this.vgsForm.cardNumberField(e.cardNumber, {
|
|
445
|
+
placeholder: s.cardNumber,
|
|
446
|
+
autoComplete: "cc-number",
|
|
447
|
+
validations: ["required", "validCardNumber"],
|
|
448
|
+
css: t
|
|
449
|
+
});
|
|
450
|
+
n.on("update", (r) => {
|
|
451
|
+
a && a(I.mapCardType(r.cardType));
|
|
452
|
+
}), this.fields.push(n);
|
|
453
|
+
}
|
|
454
|
+
if (e.cardExpiry) {
|
|
455
|
+
const n = this.vgsForm.cardExpirationDateField(
|
|
456
|
+
e.cardExpiry,
|
|
457
|
+
{
|
|
458
|
+
placeholder: s.cardExpiry,
|
|
459
|
+
autoComplete: "cc-exp",
|
|
460
|
+
validations: ["required", "validCardExpirationDate"],
|
|
461
|
+
css: t
|
|
462
|
+
}
|
|
463
|
+
);
|
|
464
|
+
this.fields.push(n);
|
|
465
|
+
}
|
|
466
|
+
if (e.cardCvv) {
|
|
467
|
+
const n = this.vgsForm.cardCVCField(e.cardCvv, {
|
|
468
|
+
placeholder: s.cardCvv,
|
|
469
|
+
autoComplete: "cc-csc",
|
|
470
|
+
validations: ["required", "validCardSecurityCode"],
|
|
471
|
+
css: t
|
|
472
|
+
});
|
|
473
|
+
this.fields.push(n);
|
|
474
|
+
}
|
|
475
|
+
if (e.cardholderName) {
|
|
476
|
+
const n = this.vgsForm.cardholderNameField(
|
|
477
|
+
e.cardholderName,
|
|
478
|
+
{
|
|
479
|
+
placeholder: s.cardholderName,
|
|
480
|
+
autoComplete: "cc-name",
|
|
481
|
+
validations: ["required"],
|
|
482
|
+
css: t
|
|
483
|
+
}
|
|
484
|
+
);
|
|
485
|
+
this.fields.push(n);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
waitForFieldsReady() {
|
|
489
|
+
return Promise.all(this.fields.map((e) => e.promise));
|
|
490
|
+
}
|
|
491
|
+
createCard(e) {
|
|
492
|
+
if (!this.vgsForm)
|
|
493
|
+
return Promise.reject(new Error("VGS form not initialized"));
|
|
494
|
+
const t = this.vgsForm;
|
|
495
|
+
return new Promise((s, a) => {
|
|
496
|
+
t.createCard(
|
|
497
|
+
{ auth: e },
|
|
498
|
+
(n, r) => {
|
|
499
|
+
if (r?.errors) {
|
|
500
|
+
a(r.errors);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const l = r?.data;
|
|
504
|
+
if (!l?.id) {
|
|
505
|
+
a(new Error("Card creation failed: no card ID returned"));
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (n === 303) {
|
|
509
|
+
this.patchCard(e, l.id).then(s).catch(a);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
s(I.extractCardResult(l));
|
|
513
|
+
},
|
|
514
|
+
(n) => {
|
|
515
|
+
a(n);
|
|
516
|
+
}
|
|
517
|
+
);
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
patchCard(e, t) {
|
|
521
|
+
if (!this.vgsForm || !this.environment)
|
|
522
|
+
return Promise.reject(new Error("VGS not initialized"));
|
|
523
|
+
const s = this.vgsForm;
|
|
524
|
+
return new Promise((a, n) => {
|
|
525
|
+
s.submit(
|
|
526
|
+
`/cards/${t}`,
|
|
527
|
+
{
|
|
528
|
+
method: "PATCH",
|
|
529
|
+
headers: {
|
|
530
|
+
Authorization: `Bearer ${e}`,
|
|
531
|
+
"Content-Type": "application/vnd.api+json"
|
|
532
|
+
},
|
|
533
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
534
|
+
data: (r) => ({
|
|
535
|
+
data: {
|
|
536
|
+
attributes: {
|
|
537
|
+
cvc: r.cvc,
|
|
538
|
+
exp_month: r["exp-date"].month,
|
|
539
|
+
exp_year: r["exp-date"].year
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
})
|
|
543
|
+
},
|
|
544
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
545
|
+
(r, l) => {
|
|
546
|
+
if (r >= 400 || l?.errors) {
|
|
547
|
+
n(l?.errors ?? new Error("Card update failed"));
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const d = l?.data;
|
|
551
|
+
if (!d?.id) {
|
|
552
|
+
n(new Error("Card update failed: no card ID returned"));
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
const c = I.extractCardResult(d), p = l.included?.find(
|
|
556
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
557
|
+
(b) => b.type === "card_updates"
|
|
558
|
+
);
|
|
559
|
+
p?.attributes?.updated_values?.length && (c.updatedValues = p.attributes.updated_values), a(c);
|
|
560
|
+
},
|
|
561
|
+
(r) => {
|
|
562
|
+
n(r);
|
|
563
|
+
}
|
|
564
|
+
);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
568
|
+
static extractCardResult(e) {
|
|
569
|
+
const t = e.attributes;
|
|
570
|
+
return {
|
|
571
|
+
cardId: e.id,
|
|
572
|
+
expMonth: String(t?.exp_month ?? ""),
|
|
573
|
+
cvc: String(t?.cvc ?? ""),
|
|
574
|
+
expYear: String(t?.exp_year ?? ""),
|
|
575
|
+
name: String(t?.cardholder?.name ?? "")
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
destroy() {
|
|
579
|
+
this.vgsForm = null, this.fields = [];
|
|
580
|
+
}
|
|
581
|
+
static mapCardType(e) {
|
|
582
|
+
return e ? {
|
|
583
|
+
visa: "visa",
|
|
584
|
+
mastercard: "mastercard",
|
|
585
|
+
"american-express": "amex",
|
|
586
|
+
amex: "amex",
|
|
587
|
+
"diners-club": "unknown",
|
|
588
|
+
discover: "discover",
|
|
589
|
+
jcb: "unknown",
|
|
590
|
+
unionpay: "unknown",
|
|
591
|
+
maestro: "unknown",
|
|
592
|
+
elo: "unknown"
|
|
593
|
+
}[e] ?? "unknown" : "unknown";
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function K(i) {
|
|
405
597
|
return {
|
|
406
598
|
name: "Custom Appearance",
|
|
407
|
-
additionalPaymentMethods:
|
|
408
|
-
styles:
|
|
599
|
+
additionalPaymentMethods: i.additionalPaymentMethods || {},
|
|
600
|
+
styles: i.styles || {
|
|
409
601
|
fontSize: 14,
|
|
410
602
|
textColor: "#000000",
|
|
411
603
|
buttonColor: "#0070f3",
|
|
@@ -415,102 +607,102 @@ function K(n) {
|
|
|
415
607
|
buttonFontSize: 16
|
|
416
608
|
},
|
|
417
609
|
layout: {
|
|
418
|
-
grouped:
|
|
419
|
-
actionButton:
|
|
610
|
+
grouped: i.layout?.grouped,
|
|
611
|
+
actionButton: i.layout?.actionButton || {
|
|
420
612
|
translationKey: null
|
|
421
613
|
},
|
|
422
|
-
phoneNumber:
|
|
423
|
-
enabled:
|
|
424
|
-
label:
|
|
425
|
-
defaultCountry:
|
|
426
|
-
allowedCountries:
|
|
614
|
+
phoneNumber: i.layout?.phoneNumber ? {
|
|
615
|
+
enabled: i.layout.phoneNumber.enabled,
|
|
616
|
+
label: i.layout.phoneNumber.label,
|
|
617
|
+
defaultCountry: i.layout.phoneNumber.defaultCountry,
|
|
618
|
+
allowedCountries: i.layout.phoneNumber.allowedCountries
|
|
427
619
|
} : void 0,
|
|
428
620
|
billingFields: {
|
|
429
621
|
street: {
|
|
430
|
-
enabled:
|
|
431
|
-
label:
|
|
622
|
+
enabled: i.layout?.billingFields?.street?.enabled ?? !1,
|
|
623
|
+
label: i.layout?.billingFields?.street?.label
|
|
432
624
|
},
|
|
433
625
|
city: {
|
|
434
|
-
enabled:
|
|
435
|
-
label:
|
|
626
|
+
enabled: i.layout?.billingFields?.city?.enabled ?? !1,
|
|
627
|
+
label: i.layout?.billingFields?.city?.label
|
|
436
628
|
},
|
|
437
629
|
state: {
|
|
438
|
-
enabled:
|
|
439
|
-
label:
|
|
440
|
-
options:
|
|
630
|
+
enabled: i.layout?.billingFields?.state?.enabled ?? !1,
|
|
631
|
+
label: i.layout?.billingFields?.state?.label,
|
|
632
|
+
options: i.layout?.billingFields?.state?.options
|
|
441
633
|
},
|
|
442
634
|
zipCode: {
|
|
443
|
-
enabled:
|
|
444
|
-
label:
|
|
635
|
+
enabled: i.layout?.billingFields?.zipCode?.enabled ?? !1,
|
|
636
|
+
label: i.layout?.billingFields?.zipCode?.label
|
|
445
637
|
},
|
|
446
638
|
firstName: {
|
|
447
|
-
enabled:
|
|
448
|
-
label:
|
|
639
|
+
enabled: i.layout?.billingFields?.firstName?.enabled ?? !1,
|
|
640
|
+
label: i.layout?.billingFields?.firstName?.label
|
|
449
641
|
},
|
|
450
642
|
lastName: {
|
|
451
|
-
enabled:
|
|
452
|
-
label:
|
|
643
|
+
enabled: i.layout?.billingFields?.lastName?.enabled ?? !1,
|
|
644
|
+
label: i.layout?.billingFields?.lastName?.label
|
|
453
645
|
},
|
|
454
646
|
country: {
|
|
455
|
-
enabled:
|
|
456
|
-
label:
|
|
457
|
-
options:
|
|
647
|
+
enabled: i.layout?.billingFields?.country?.enabled ?? !1,
|
|
648
|
+
label: i.layout?.billingFields?.country?.label,
|
|
649
|
+
options: i.layout?.billingFields?.country?.options
|
|
458
650
|
}
|
|
459
651
|
},
|
|
460
|
-
shippingFields:
|
|
652
|
+
shippingFields: i.layout?.shippingFields ? {
|
|
461
653
|
street: {
|
|
462
|
-
enabled:
|
|
463
|
-
label:
|
|
654
|
+
enabled: i.layout.shippingFields.street?.enabled ?? !1,
|
|
655
|
+
label: i.layout.shippingFields.street?.label
|
|
464
656
|
},
|
|
465
657
|
firstName: {
|
|
466
|
-
enabled:
|
|
467
|
-
label:
|
|
658
|
+
enabled: i.layout.shippingFields.firstName?.enabled ?? !1,
|
|
659
|
+
label: i.layout.shippingFields.firstName?.label
|
|
468
660
|
},
|
|
469
661
|
lastName: {
|
|
470
|
-
enabled:
|
|
471
|
-
label:
|
|
662
|
+
enabled: i.layout.shippingFields.lastName?.enabled ?? !1,
|
|
663
|
+
label: i.layout.shippingFields.lastName?.label
|
|
472
664
|
},
|
|
473
665
|
city: {
|
|
474
|
-
enabled:
|
|
475
|
-
label:
|
|
666
|
+
enabled: i.layout.shippingFields.city?.enabled ?? !1,
|
|
667
|
+
label: i.layout.shippingFields.city?.label
|
|
476
668
|
},
|
|
477
669
|
state: {
|
|
478
|
-
enabled:
|
|
479
|
-
label:
|
|
480
|
-
options:
|
|
670
|
+
enabled: i.layout.shippingFields.state?.enabled ?? !1,
|
|
671
|
+
label: i.layout.shippingFields.state?.label,
|
|
672
|
+
options: i.layout.shippingFields.state?.options
|
|
481
673
|
},
|
|
482
674
|
zipCode: {
|
|
483
|
-
enabled:
|
|
484
|
-
label:
|
|
675
|
+
enabled: i.layout.shippingFields.zipCode?.enabled ?? !1,
|
|
676
|
+
label: i.layout.shippingFields.zipCode?.label
|
|
485
677
|
},
|
|
486
678
|
country: {
|
|
487
|
-
enabled:
|
|
488
|
-
label:
|
|
489
|
-
options:
|
|
679
|
+
enabled: i.layout.shippingFields.country?.enabled ?? !1,
|
|
680
|
+
label: i.layout.shippingFields.country?.label,
|
|
681
|
+
options: i.layout.shippingFields.country?.options
|
|
490
682
|
}
|
|
491
683
|
} : void 0
|
|
492
684
|
},
|
|
493
685
|
appearance: {
|
|
494
|
-
additionalPaymentMethods:
|
|
495
|
-
applePay:
|
|
496
|
-
displayName:
|
|
497
|
-
requiredBillingContactFields:
|
|
498
|
-
requiredShippingContactFields:
|
|
686
|
+
additionalPaymentMethods: i.additionalPaymentMethods ? {
|
|
687
|
+
applePay: i.additionalPaymentMethods.applePay ? {
|
|
688
|
+
displayName: i.additionalPaymentMethods.applePay.displayName,
|
|
689
|
+
requiredBillingContactFields: i.additionalPaymentMethods.applePay.requiredBillingContactFields,
|
|
690
|
+
requiredShippingContactFields: i.additionalPaymentMethods.applePay.requiredShippingContactFields
|
|
499
691
|
} : void 0
|
|
500
692
|
} : void 0
|
|
501
693
|
}
|
|
502
694
|
};
|
|
503
695
|
}
|
|
504
|
-
function
|
|
505
|
-
appearance:
|
|
696
|
+
function ot({
|
|
697
|
+
appearance: i
|
|
506
698
|
}) {
|
|
507
|
-
const e =
|
|
699
|
+
const e = de({
|
|
508
700
|
checkoutProfile: void 0,
|
|
509
701
|
isLoading: !0,
|
|
510
702
|
error: null
|
|
511
703
|
});
|
|
512
|
-
if (
|
|
513
|
-
const s = K(
|
|
704
|
+
if (i) {
|
|
705
|
+
const s = K(i);
|
|
514
706
|
return Promise.resolve().then(() => {
|
|
515
707
|
e.setState({
|
|
516
708
|
checkoutProfile: s,
|
|
@@ -520,10 +712,10 @@ function et({
|
|
|
520
712
|
}), {
|
|
521
713
|
getState: e.getState.bind(e),
|
|
522
714
|
subscribe: e.subscribe.bind(e),
|
|
523
|
-
updateProfile: (
|
|
524
|
-
const
|
|
715
|
+
updateProfile: (a) => {
|
|
716
|
+
const n = K(a);
|
|
525
717
|
e.setState({
|
|
526
|
-
checkoutProfile:
|
|
718
|
+
checkoutProfile: n,
|
|
527
719
|
isLoading: !1,
|
|
528
720
|
error: null
|
|
529
721
|
});
|
|
@@ -570,9 +762,9 @@ function et({
|
|
|
570
762
|
getState: e.getState.bind(e),
|
|
571
763
|
subscribe: e.subscribe.bind(e),
|
|
572
764
|
updateProfile: (s) => {
|
|
573
|
-
const
|
|
765
|
+
const a = K(s);
|
|
574
766
|
e.setState({
|
|
575
|
-
checkoutProfile:
|
|
767
|
+
checkoutProfile: a,
|
|
576
768
|
isLoading: !1,
|
|
577
769
|
error: null
|
|
578
770
|
});
|
|
@@ -581,8 +773,8 @@ function et({
|
|
|
581
773
|
}
|
|
582
774
|
};
|
|
583
775
|
}
|
|
584
|
-
const
|
|
585
|
-
const
|
|
776
|
+
const lt = () => {
|
|
777
|
+
const i = ge(), e = de({
|
|
586
778
|
formData: {
|
|
587
779
|
name: "",
|
|
588
780
|
email: "",
|
|
@@ -599,185 +791,199 @@ const tt = () => {
|
|
|
599
791
|
cardCvv: !1
|
|
600
792
|
},
|
|
601
793
|
isValid: !1
|
|
602
|
-
}), t = (o,
|
|
794
|
+
}), t = (o, g, m, u) => {
|
|
603
795
|
if (o === "cardCvv")
|
|
604
|
-
return
|
|
605
|
-
if (o === "phoneNumber" &&
|
|
606
|
-
return
|
|
607
|
-
const
|
|
608
|
-
return
|
|
796
|
+
return i.cardCvv(g, m);
|
|
797
|
+
if (o === "phoneNumber" && u)
|
|
798
|
+
return i.phoneNumber(g, u);
|
|
799
|
+
const f = i[o];
|
|
800
|
+
return f?.(g);
|
|
609
801
|
}, s = (o) => {
|
|
610
|
-
const
|
|
611
|
-
return Object.keys(o).forEach((
|
|
612
|
-
const
|
|
613
|
-
if (
|
|
614
|
-
let
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
802
|
+
const g = {};
|
|
803
|
+
return Object.keys(o).forEach((u) => {
|
|
804
|
+
const f = o[u];
|
|
805
|
+
if (f === void 0) return;
|
|
806
|
+
let h;
|
|
807
|
+
u === "cardCvv" ? h = t(u, f, o.cardNumber) : u === "phoneNumber" ? h = t(
|
|
808
|
+
u,
|
|
809
|
+
f,
|
|
618
810
|
void 0,
|
|
619
811
|
o.phoneCountryCode
|
|
620
|
-
) :
|
|
812
|
+
) : h = t(u, f), h && (g[u] = h);
|
|
621
813
|
}), [
|
|
622
814
|
"billingAddress",
|
|
623
815
|
"shippingAddress"
|
|
624
|
-
].forEach((
|
|
625
|
-
const
|
|
626
|
-
if (
|
|
627
|
-
const
|
|
628
|
-
Object.keys(
|
|
629
|
-
(
|
|
630
|
-
const
|
|
631
|
-
if (
|
|
632
|
-
const S =
|
|
816
|
+
].forEach((u) => {
|
|
817
|
+
const f = o[u];
|
|
818
|
+
if (f && typeof f == "object") {
|
|
819
|
+
const h = {};
|
|
820
|
+
Object.keys(f).forEach(
|
|
821
|
+
(y) => {
|
|
822
|
+
const v = f[y];
|
|
823
|
+
if (v === void 0) return;
|
|
824
|
+
const S = i[y];
|
|
633
825
|
if (S) {
|
|
634
|
-
const
|
|
635
|
-
|
|
826
|
+
const M = S(v);
|
|
827
|
+
M && (h[y] = M);
|
|
636
828
|
}
|
|
637
829
|
}
|
|
638
|
-
), Object.keys(
|
|
830
|
+
), Object.keys(h).length > 0 && (g[u] = h);
|
|
639
831
|
}
|
|
640
|
-
}),
|
|
641
|
-
},
|
|
642
|
-
const
|
|
643
|
-
return Object.keys(
|
|
644
|
-
},
|
|
832
|
+
}), g;
|
|
833
|
+
}, a = (o) => {
|
|
834
|
+
const g = s(o);
|
|
835
|
+
return Object.keys(g).length === 0;
|
|
836
|
+
}, n = "billingAddress.", r = "shippingAddress.", l = (o) => o.startsWith(n) ? {
|
|
645
837
|
parent: "billingAddress",
|
|
646
|
-
field: o.slice(
|
|
838
|
+
field: o.slice(n.length)
|
|
647
839
|
} : o.startsWith(r) ? {
|
|
648
840
|
parent: "shippingAddress",
|
|
649
841
|
field: o.slice(r.length)
|
|
650
|
-
} : null,
|
|
651
|
-
const
|
|
652
|
-
if (
|
|
653
|
-
|
|
654
|
-
...
|
|
655
|
-
[m]:
|
|
842
|
+
} : null, d = (o, g, m, u) => {
|
|
843
|
+
const f = { ...o };
|
|
844
|
+
if (u)
|
|
845
|
+
f[g] = {
|
|
846
|
+
...f[g],
|
|
847
|
+
[m]: u
|
|
656
848
|
};
|
|
657
849
|
else {
|
|
658
|
-
const
|
|
659
|
-
...
|
|
850
|
+
const h = {
|
|
851
|
+
...f[g]
|
|
660
852
|
};
|
|
661
|
-
delete
|
|
853
|
+
delete h[m], Object.keys(h).length === 0 ? delete f[g] : f[g] = h;
|
|
662
854
|
}
|
|
663
|
-
return
|
|
664
|
-
},
|
|
855
|
+
return f;
|
|
856
|
+
}, c = (o, g) => {
|
|
665
857
|
const m = e.getState();
|
|
666
|
-
let
|
|
667
|
-
const
|
|
668
|
-
if (!
|
|
858
|
+
let u = g;
|
|
859
|
+
const f = l(o);
|
|
860
|
+
if (!f && o in U)
|
|
669
861
|
if (o === "cardCvv") {
|
|
670
|
-
const S =
|
|
671
|
-
|
|
862
|
+
const S = fe(m.formData.cardNumber) === "amex" ? 4 : 3;
|
|
863
|
+
u = U.cardCvv(g, S);
|
|
672
864
|
} else
|
|
673
|
-
|
|
674
|
-
let
|
|
675
|
-
if (
|
|
676
|
-
const { parent:
|
|
677
|
-
|
|
865
|
+
u = U[o](g);
|
|
866
|
+
let h;
|
|
867
|
+
if (f) {
|
|
868
|
+
const { parent: v, field: S } = f;
|
|
869
|
+
h = {
|
|
678
870
|
...m.formData,
|
|
679
|
-
[
|
|
680
|
-
...m.formData[
|
|
681
|
-
[S]:
|
|
871
|
+
[v]: {
|
|
872
|
+
...m.formData[v] ?? {},
|
|
873
|
+
[S]: u
|
|
682
874
|
}
|
|
683
875
|
};
|
|
684
876
|
} else
|
|
685
|
-
|
|
877
|
+
h = {
|
|
686
878
|
...m.formData,
|
|
687
|
-
[o]:
|
|
879
|
+
[o]: u
|
|
688
880
|
};
|
|
689
|
-
let
|
|
690
|
-
if (o === "phoneCountryCode" &&
|
|
691
|
-
const
|
|
881
|
+
let y = { ...m.errors };
|
|
882
|
+
if (o === "phoneCountryCode" && h.phoneNumber) {
|
|
883
|
+
const v = t(
|
|
692
884
|
"phoneNumber",
|
|
693
|
-
|
|
885
|
+
h.phoneNumber,
|
|
694
886
|
void 0,
|
|
695
|
-
|
|
887
|
+
u
|
|
696
888
|
);
|
|
697
|
-
|
|
889
|
+
v ? y.phoneNumber = v : delete y.phoneNumber;
|
|
698
890
|
}
|
|
699
891
|
if (m.touched[o])
|
|
700
|
-
if (
|
|
701
|
-
const { parent:
|
|
702
|
-
|
|
892
|
+
if (f) {
|
|
893
|
+
const { parent: v, field: S } = f, M = i[S], x = M ? M(
|
|
894
|
+
u
|
|
703
895
|
) : void 0;
|
|
704
|
-
|
|
896
|
+
y = d(y, v, S, x);
|
|
705
897
|
} else {
|
|
706
|
-
let
|
|
707
|
-
o === "cardCvv" ?
|
|
898
|
+
let v;
|
|
899
|
+
o === "cardCvv" ? v = t(o, u, h.cardNumber) : o === "phoneNumber" ? v = t(
|
|
708
900
|
o,
|
|
709
|
-
|
|
901
|
+
u,
|
|
710
902
|
void 0,
|
|
711
|
-
|
|
712
|
-
) :
|
|
903
|
+
h.phoneCountryCode
|
|
904
|
+
) : v = t(o, u), v ? y[o] = v : delete y[o];
|
|
713
905
|
}
|
|
714
906
|
e.setState({
|
|
715
|
-
formData:
|
|
716
|
-
errors:
|
|
717
|
-
isValid:
|
|
907
|
+
formData: h,
|
|
908
|
+
errors: y,
|
|
909
|
+
isValid: a(h)
|
|
718
910
|
});
|
|
719
|
-
},
|
|
720
|
-
const m = e.getState(),
|
|
721
|
-
if (
|
|
722
|
-
const { parent:
|
|
911
|
+
}, p = (o, g) => {
|
|
912
|
+
const m = e.getState(), u = l(o);
|
|
913
|
+
if (u) {
|
|
914
|
+
const { parent: v, field: S } = u, M = {
|
|
723
915
|
...m.formData,
|
|
724
|
-
[
|
|
725
|
-
...m.formData[
|
|
726
|
-
[S]:
|
|
916
|
+
[v]: {
|
|
917
|
+
...m.formData[v] ?? {},
|
|
918
|
+
[S]: g
|
|
727
919
|
}
|
|
728
|
-
},
|
|
920
|
+
}, x = i[S], ue = x ? x(g) : void 0, me = d(m.errors, v, S, ue);
|
|
729
921
|
e.setState({
|
|
730
|
-
formData:
|
|
922
|
+
formData: M,
|
|
731
923
|
touched: {
|
|
732
924
|
...m.touched,
|
|
733
925
|
[o]: !0
|
|
734
926
|
},
|
|
735
|
-
errors:
|
|
736
|
-
isValid:
|
|
927
|
+
errors: me,
|
|
928
|
+
isValid: a(M)
|
|
737
929
|
});
|
|
738
930
|
return;
|
|
739
931
|
}
|
|
740
|
-
const
|
|
932
|
+
const f = {
|
|
741
933
|
...m.touched,
|
|
742
934
|
[o]: !0
|
|
743
935
|
};
|
|
744
|
-
let
|
|
745
|
-
o === "cardCvv" ?
|
|
936
|
+
let h;
|
|
937
|
+
o === "cardCvv" ? h = t(o, g, m.formData.cardNumber) : o === "phoneNumber" ? h = t(
|
|
746
938
|
o,
|
|
747
|
-
|
|
939
|
+
g,
|
|
748
940
|
void 0,
|
|
749
941
|
m.formData.phoneCountryCode
|
|
750
|
-
) :
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
touched:
|
|
754
|
-
errors:
|
|
942
|
+
) : h = t(o, g);
|
|
943
|
+
const y = { ...m.errors };
|
|
944
|
+
h ? y[o] = h : delete y[o], e.setState({
|
|
945
|
+
touched: f,
|
|
946
|
+
errors: y
|
|
755
947
|
});
|
|
756
|
-
},
|
|
948
|
+
}, b = (o) => {
|
|
757
949
|
const m = {
|
|
758
950
|
...e.getState().formData,
|
|
759
951
|
...o
|
|
760
952
|
};
|
|
761
953
|
e.setState({
|
|
762
954
|
formData: m,
|
|
763
|
-
isValid:
|
|
955
|
+
isValid: a(m)
|
|
764
956
|
});
|
|
765
957
|
};
|
|
766
958
|
return {
|
|
767
959
|
getFormState: e.getState.bind(e),
|
|
768
960
|
subscribe: e.subscribe.bind(e),
|
|
769
|
-
handleChange:
|
|
770
|
-
handleBlur:
|
|
771
|
-
setFormData:
|
|
961
|
+
handleChange: c,
|
|
962
|
+
handleBlur: p,
|
|
963
|
+
setFormData: b,
|
|
772
964
|
reset: e.resetState.bind(e)
|
|
773
965
|
};
|
|
774
|
-
}
|
|
775
|
-
function
|
|
776
|
-
if (!
|
|
777
|
-
const
|
|
778
|
-
|
|
966
|
+
}, dt = "https://fonts.googleapis.com/css2", ct = /src:\s*url\(([^)]+\.woff2[^)]*)\)/, ht = /\/\*\s*latin\s*\*\/\s*@font-face\s*\{[^}]*src:\s*url\(([^)]+\.woff2[^)]*)\)[^}]*\}/;
|
|
967
|
+
async function ut(i) {
|
|
968
|
+
if (!i) return null;
|
|
969
|
+
const e = i.trim().replace(/\s+/g, "+"), t = `${dt}?family=${e}:wght@400;700&display=swap`;
|
|
970
|
+
try {
|
|
971
|
+
const s = await fetch(t);
|
|
972
|
+
if (!s.ok) return null;
|
|
973
|
+
const a = await s.text(), n = ht.exec(a);
|
|
974
|
+
if (n?.[1]) return n[1];
|
|
975
|
+
const r = ct.exec(a);
|
|
976
|
+
return r?.[1] ? r[1] : null;
|
|
977
|
+
} catch {
|
|
978
|
+
return null;
|
|
979
|
+
}
|
|
779
980
|
}
|
|
780
|
-
|
|
981
|
+
function W(i) {
|
|
982
|
+
if (!i) return !1;
|
|
983
|
+
const { billingFields: e, shippingFields: t } = i, s = e && Object.values(e).some((n) => n?.enabled), a = t && Object.values(t).some((n) => n?.enabled);
|
|
984
|
+
return !!(s || a);
|
|
985
|
+
}
|
|
986
|
+
class re extends P {
|
|
781
987
|
inputs = /* @__PURE__ */ new Map();
|
|
782
988
|
type;
|
|
783
989
|
onChange;
|
|
@@ -789,159 +995,159 @@ class se extends A {
|
|
|
789
995
|
grouped;
|
|
790
996
|
constructor(e) {
|
|
791
997
|
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:
|
|
998
|
+
const { title: t, checkoutProfile: s, fieldsConfig: a, values: n, errors: r, touched: l } = e;
|
|
793
999
|
if (this.grouped) {
|
|
794
|
-
const
|
|
795
|
-
|
|
1000
|
+
const d = document.createElement("h3");
|
|
1001
|
+
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
1002
|
}
|
|
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,
|
|
1003
|
+
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, n, r, l);
|
|
798
1004
|
}
|
|
799
|
-
borderRadius(e, t, s,
|
|
800
|
-
const r = (
|
|
801
|
-
return `${r(t)} ${r(s)} ${r(
|
|
1005
|
+
borderRadius(e, t, s, a, n) {
|
|
1006
|
+
const r = (l) => l ? `${e}px` : "0px";
|
|
1007
|
+
return `${r(t)} ${r(s)} ${r(a)} ${r(n)}`;
|
|
802
1008
|
}
|
|
803
|
-
createFields(e, t, s,
|
|
1009
|
+
createFields(e, t, s, a, n) {
|
|
804
1010
|
if (!this.grouped) {
|
|
805
1011
|
this.createUngroupedFields(
|
|
806
1012
|
e,
|
|
807
1013
|
t,
|
|
808
1014
|
s,
|
|
809
|
-
|
|
810
|
-
|
|
1015
|
+
a,
|
|
1016
|
+
n
|
|
811
1017
|
);
|
|
812
1018
|
return;
|
|
813
1019
|
}
|
|
814
|
-
const r = e.styles.borderRadius,
|
|
1020
|
+
const r = e.styles.borderRadius, l = {
|
|
815
1021
|
color: e.styles.textColor,
|
|
816
1022
|
fontSize: e.styles.fontSize,
|
|
817
1023
|
fontFamily: e.styles.fontFamily
|
|
818
|
-
},
|
|
819
|
-
t.street?.enabled &&
|
|
820
|
-
const
|
|
821
|
-
t.firstName?.enabled &&
|
|
822
|
-
const
|
|
823
|
-
t.city?.enabled &&
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
const m =
|
|
827
|
-
...
|
|
1024
|
+
}, d = [];
|
|
1025
|
+
t.street?.enabled && d.push({ kind: "street" });
|
|
1026
|
+
const c = [];
|
|
1027
|
+
t.firstName?.enabled && c.push("firstName"), t.lastName?.enabled && c.push("lastName"), c.length > 0 && d.push({ kind: "name", fields: c }), t.country?.enabled && d.push({ kind: "country" });
|
|
1028
|
+
const p = [];
|
|
1029
|
+
t.city?.enabled && p.push("city"), t.zipCode?.enabled && p.push("zipCode"), p.length > 0 && d.push({ kind: "cityZip", fields: p }), t.state?.enabled && d.push({ kind: "state" });
|
|
1030
|
+
const b = d.length;
|
|
1031
|
+
d.forEach((o, g) => {
|
|
1032
|
+
const m = g === 0, u = g === b - 1, f = (h, y) => ({
|
|
1033
|
+
...l,
|
|
828
1034
|
borderRadius: this.borderRadius(
|
|
829
1035
|
r,
|
|
830
|
-
m &&
|
|
831
|
-
m &&
|
|
832
|
-
|
|
833
|
-
|
|
1036
|
+
m && h,
|
|
1037
|
+
m && y,
|
|
1038
|
+
u && y,
|
|
1039
|
+
u && h
|
|
834
1040
|
)
|
|
835
1041
|
});
|
|
836
1042
|
if (o.kind === "street") {
|
|
837
|
-
const
|
|
1043
|
+
const h = this.createRow(["full"]), y = this.createInput(
|
|
838
1044
|
"street",
|
|
839
1045
|
t.street?.label ?? this.translationFunc("address.addressLine1"),
|
|
840
1046
|
s.street,
|
|
841
|
-
i.street,
|
|
842
1047
|
a.street,
|
|
843
|
-
|
|
1048
|
+
n.street,
|
|
1049
|
+
f(!0, !0),
|
|
844
1050
|
"street-address"
|
|
845
1051
|
);
|
|
846
|
-
this.inputs.set("street",
|
|
1052
|
+
this.inputs.set("street", y), h.appendChild(y.getElement()), this.fieldsContainer.appendChild(h);
|
|
847
1053
|
return;
|
|
848
1054
|
}
|
|
849
1055
|
if (o.kind === "name") {
|
|
850
|
-
const
|
|
1056
|
+
const h = this.createRow(o.fields.map(() => "half")), y = o.fields.length === 1;
|
|
851
1057
|
if (o.fields.includes("firstName")) {
|
|
852
|
-
const
|
|
1058
|
+
const v = y || o.fields[o.fields.length - 1] === "firstName", S = this.createInput(
|
|
853
1059
|
"firstName",
|
|
854
1060
|
t.firstName?.label ?? this.translationFunc("address.firstName"),
|
|
855
1061
|
s.firstName,
|
|
856
|
-
i.firstName,
|
|
857
1062
|
a.firstName,
|
|
858
|
-
|
|
1063
|
+
n.firstName,
|
|
1064
|
+
f(!0, v),
|
|
859
1065
|
"given-name"
|
|
860
1066
|
);
|
|
861
|
-
this.inputs.set("firstName", S),
|
|
1067
|
+
this.inputs.set("firstName", S), h.appendChild(S.getElement());
|
|
862
1068
|
}
|
|
863
1069
|
if (o.fields.includes("lastName")) {
|
|
864
|
-
const
|
|
1070
|
+
const v = y || o.fields[0] === "lastName", S = this.createInput(
|
|
865
1071
|
"lastName",
|
|
866
1072
|
t.lastName?.label ?? this.translationFunc("address.lastName"),
|
|
867
1073
|
s.lastName,
|
|
868
|
-
i.lastName,
|
|
869
1074
|
a.lastName,
|
|
870
|
-
|
|
1075
|
+
n.lastName,
|
|
1076
|
+
f(v, !0),
|
|
871
1077
|
"family-name"
|
|
872
1078
|
);
|
|
873
|
-
this.inputs.set("lastName", S),
|
|
1079
|
+
this.inputs.set("lastName", S), h.appendChild(S.getElement());
|
|
874
1080
|
}
|
|
875
|
-
this.fieldsContainer.appendChild(
|
|
1081
|
+
this.fieldsContainer.appendChild(h);
|
|
876
1082
|
return;
|
|
877
1083
|
}
|
|
878
1084
|
if (o.kind === "country") {
|
|
879
|
-
const
|
|
1085
|
+
const h = this.createRow(["full"]), y = this.createCountrySelect(
|
|
880
1086
|
s.country,
|
|
881
|
-
i.country,
|
|
882
1087
|
a.country,
|
|
883
|
-
|
|
1088
|
+
n.country,
|
|
1089
|
+
f(!0, !0),
|
|
884
1090
|
t.country?.options,
|
|
885
1091
|
t.country?.label
|
|
886
1092
|
);
|
|
887
|
-
this.inputs.set("country",
|
|
1093
|
+
this.inputs.set("country", y), h.appendChild(y.getElement()), this.fieldsContainer.appendChild(h);
|
|
888
1094
|
return;
|
|
889
1095
|
}
|
|
890
1096
|
if (o.kind === "cityZip") {
|
|
891
|
-
const
|
|
1097
|
+
const h = this.createRow(o.fields.map(() => "half")), y = o.fields.length === 1;
|
|
892
1098
|
if (o.fields.includes("city")) {
|
|
893
|
-
const
|
|
1099
|
+
const v = y || o.fields[o.fields.length - 1] === "city", S = this.createInput(
|
|
894
1100
|
"city",
|
|
895
1101
|
t.city?.label ?? this.translationFunc("address.townCity"),
|
|
896
1102
|
s.city,
|
|
897
|
-
i.city,
|
|
898
1103
|
a.city,
|
|
899
|
-
|
|
1104
|
+
n.city,
|
|
1105
|
+
f(!0, v),
|
|
900
1106
|
"address-level2"
|
|
901
1107
|
);
|
|
902
|
-
this.inputs.set("city", S),
|
|
1108
|
+
this.inputs.set("city", S), h.appendChild(S.getElement());
|
|
903
1109
|
}
|
|
904
1110
|
if (o.fields.includes("zipCode")) {
|
|
905
|
-
const
|
|
1111
|
+
const v = y || o.fields[0] === "zipCode", S = this.createInput(
|
|
906
1112
|
"zipCode",
|
|
907
1113
|
t.zipCode?.label ?? this.translationFunc("address.postalCode"),
|
|
908
1114
|
s.zipCode,
|
|
909
|
-
i.zipCode,
|
|
910
1115
|
a.zipCode,
|
|
911
|
-
|
|
1116
|
+
n.zipCode,
|
|
1117
|
+
f(v, !0),
|
|
912
1118
|
"postal-code"
|
|
913
1119
|
);
|
|
914
|
-
this.inputs.set("zipCode", S),
|
|
1120
|
+
this.inputs.set("zipCode", S), h.appendChild(S.getElement());
|
|
915
1121
|
}
|
|
916
|
-
this.fieldsContainer.appendChild(
|
|
1122
|
+
this.fieldsContainer.appendChild(h);
|
|
917
1123
|
return;
|
|
918
1124
|
}
|
|
919
1125
|
if (o.kind === "state") {
|
|
920
|
-
const
|
|
1126
|
+
const h = this.createRow(["full"]);
|
|
921
1127
|
if (this.stateOptions = t.state?.options, t.state?.options && t.state.options.length > 0) {
|
|
922
|
-
const
|
|
1128
|
+
const v = this.createStateSelect(
|
|
923
1129
|
s.state,
|
|
924
|
-
i.state,
|
|
925
1130
|
a.state,
|
|
926
|
-
|
|
1131
|
+
n.state,
|
|
1132
|
+
f(!0, !0),
|
|
927
1133
|
t.state?.options,
|
|
928
1134
|
s.country,
|
|
929
1135
|
t.state?.label
|
|
930
1136
|
);
|
|
931
|
-
this.inputs.set("state",
|
|
1137
|
+
this.inputs.set("state", v), h.appendChild(v.getElement());
|
|
932
1138
|
} else {
|
|
933
|
-
const
|
|
1139
|
+
const v = this.createInput(
|
|
934
1140
|
"state",
|
|
935
1141
|
t.state?.label ?? this.translationFunc("address.chooseState"),
|
|
936
1142
|
s.state,
|
|
937
|
-
i.state,
|
|
938
1143
|
a.state,
|
|
939
|
-
|
|
1144
|
+
n.state,
|
|
1145
|
+
f(!0, !0),
|
|
940
1146
|
"address-level1"
|
|
941
1147
|
);
|
|
942
|
-
this.inputs.set("state",
|
|
1148
|
+
this.inputs.set("state", v), h.appendChild(v.getElement());
|
|
943
1149
|
}
|
|
944
|
-
this.fieldsContainer.appendChild(
|
|
1150
|
+
this.fieldsContainer.appendChild(h);
|
|
945
1151
|
}
|
|
946
1152
|
});
|
|
947
1153
|
}
|
|
@@ -949,181 +1155,181 @@ class se extends A {
|
|
|
949
1155
|
const t = document.createElement("div");
|
|
950
1156
|
return t.className = `address-row address-row-${e.length === 1 ? "single" : "double"}`, t;
|
|
951
1157
|
}
|
|
952
|
-
createInput(e, t, s,
|
|
953
|
-
const
|
|
954
|
-
name:
|
|
1158
|
+
createInput(e, t, s, a, n, r, l) {
|
|
1159
|
+
const d = `${this.type}Address.${e}`, c = new ce({
|
|
1160
|
+
name: d,
|
|
955
1161
|
error: !1,
|
|
956
1162
|
errorMsg: void 0,
|
|
957
1163
|
styles: r,
|
|
958
1164
|
...this.grouped ? { placeholder: t } : {
|
|
959
1165
|
label: t,
|
|
960
1166
|
placeholder: (() => {
|
|
961
|
-
const
|
|
962
|
-
return
|
|
1167
|
+
const p = `address.placeholder.${e}`, b = this.translationFunc(p);
|
|
1168
|
+
return b !== p ? b : t;
|
|
963
1169
|
})()
|
|
964
1170
|
},
|
|
965
1171
|
value: s,
|
|
966
|
-
autocomplete:
|
|
967
|
-
onChange: (
|
|
968
|
-
|
|
969
|
-
const
|
|
970
|
-
Object.defineProperty(
|
|
1172
|
+
autocomplete: l,
|
|
1173
|
+
onChange: (p) => {
|
|
1174
|
+
c.setError(!1);
|
|
1175
|
+
const b = new Event("input", { bubbles: !0 });
|
|
1176
|
+
Object.defineProperty(b, "target", {
|
|
971
1177
|
writable: !1,
|
|
972
1178
|
value: {
|
|
973
|
-
name:
|
|
974
|
-
value:
|
|
1179
|
+
name: d,
|
|
1180
|
+
value: p.target.value
|
|
975
1181
|
}
|
|
976
|
-
}), this.onChange(
|
|
1182
|
+
}), this.onChange(b);
|
|
977
1183
|
}
|
|
978
1184
|
});
|
|
979
|
-
return
|
|
980
|
-
const
|
|
981
|
-
Object.defineProperty(
|
|
1185
|
+
return c.addEventListener("blur", (p) => {
|
|
1186
|
+
const b = new Event("blur", { bubbles: !0 });
|
|
1187
|
+
Object.defineProperty(b, "target", {
|
|
982
1188
|
writable: !1,
|
|
983
1189
|
value: {
|
|
984
|
-
name:
|
|
985
|
-
value:
|
|
1190
|
+
name: d,
|
|
1191
|
+
value: p.target.value
|
|
986
1192
|
}
|
|
987
|
-
}), this.onBlur(
|
|
988
|
-
}),
|
|
1193
|
+
}), this.onBlur(b);
|
|
1194
|
+
}), c;
|
|
989
1195
|
}
|
|
990
|
-
createCountrySelect(e, t, s,
|
|
991
|
-
const
|
|
992
|
-
name:
|
|
1196
|
+
createCountrySelect(e, t, s, a, n, r) {
|
|
1197
|
+
const l = `${this.type}Address.country`, d = ye(n, this.locale), c = new H({
|
|
1198
|
+
name: l,
|
|
993
1199
|
error: !1,
|
|
994
1200
|
errorMsg: void 0,
|
|
995
|
-
styles:
|
|
1201
|
+
styles: a,
|
|
996
1202
|
placeholder: this.translationFunc("address.chooseCountry"),
|
|
997
1203
|
...!this.grouped && {
|
|
998
1204
|
label: r ?? this.translationFunc("address.chooseCountry")
|
|
999
1205
|
},
|
|
1000
1206
|
value: e,
|
|
1001
|
-
options:
|
|
1207
|
+
options: d,
|
|
1002
1208
|
autocomplete: "country",
|
|
1003
|
-
onChange: (
|
|
1004
|
-
|
|
1005
|
-
const
|
|
1006
|
-
this.updateStateOptionsForCountry(
|
|
1209
|
+
onChange: (p) => {
|
|
1210
|
+
c.setError(!1);
|
|
1211
|
+
const b = p.target.value;
|
|
1212
|
+
this.updateStateOptionsForCountry(b);
|
|
1007
1213
|
const o = new Event("change", { bubbles: !0 });
|
|
1008
1214
|
Object.defineProperty(o, "target", {
|
|
1009
1215
|
writable: !1,
|
|
1010
1216
|
value: {
|
|
1011
|
-
name:
|
|
1012
|
-
value:
|
|
1217
|
+
name: l,
|
|
1218
|
+
value: b
|
|
1013
1219
|
}
|
|
1014
1220
|
}), this.onChange(o);
|
|
1015
1221
|
}
|
|
1016
1222
|
});
|
|
1017
|
-
return
|
|
1018
|
-
const
|
|
1019
|
-
Object.defineProperty(
|
|
1223
|
+
return c.addEventListener("blur", (p) => {
|
|
1224
|
+
const b = new Event("blur", { bubbles: !0 });
|
|
1225
|
+
Object.defineProperty(b, "target", {
|
|
1020
1226
|
writable: !1,
|
|
1021
1227
|
value: {
|
|
1022
|
-
name:
|
|
1023
|
-
value:
|
|
1228
|
+
name: l,
|
|
1229
|
+
value: p.target.value
|
|
1024
1230
|
}
|
|
1025
|
-
}), this.onBlur(
|
|
1026
|
-
}),
|
|
1231
|
+
}), this.onBlur(b);
|
|
1232
|
+
}), c;
|
|
1027
1233
|
}
|
|
1028
1234
|
updateStateOptionsForCountry(e) {
|
|
1029
1235
|
const t = this.inputs.get("state");
|
|
1030
|
-
if (!(t instanceof
|
|
1031
|
-
const s = e === "CA" ? "CA" : "US",
|
|
1032
|
-
t.setOptions(
|
|
1236
|
+
if (!(t instanceof H)) return;
|
|
1237
|
+
const s = e === "CA" ? "CA" : "US", a = Z(this.stateOptions, s), n = s === "CA" ? this.translationFunc("address.chooseProvince") : this.translationFunc("address.chooseState");
|
|
1238
|
+
t.setOptions(a, n);
|
|
1033
1239
|
}
|
|
1034
|
-
createStateSelect(e, t, s,
|
|
1035
|
-
const
|
|
1036
|
-
name:
|
|
1240
|
+
createStateSelect(e, t, s, a, n, r, l) {
|
|
1241
|
+
const d = `${this.type}Address.state`, c = r === "CA" ? "CA" : "US", p = Z(n, c), b = c === "CA" ? this.translationFunc("address.chooseProvince") : this.translationFunc("address.chooseState"), o = new H({
|
|
1242
|
+
name: d,
|
|
1037
1243
|
error: !1,
|
|
1038
1244
|
errorMsg: void 0,
|
|
1039
|
-
styles:
|
|
1040
|
-
placeholder:
|
|
1041
|
-
...!this.grouped && { label:
|
|
1245
|
+
styles: a,
|
|
1246
|
+
placeholder: b,
|
|
1247
|
+
...!this.grouped && { label: l ?? b },
|
|
1042
1248
|
value: e,
|
|
1043
|
-
options:
|
|
1249
|
+
options: p,
|
|
1044
1250
|
autocomplete: "address-level1",
|
|
1045
|
-
onChange: (
|
|
1251
|
+
onChange: (g) => {
|
|
1046
1252
|
o.setError(!1);
|
|
1047
1253
|
const m = new Event("change", { bubbles: !0 });
|
|
1048
1254
|
Object.defineProperty(m, "target", {
|
|
1049
1255
|
writable: !1,
|
|
1050
1256
|
value: {
|
|
1051
|
-
name:
|
|
1052
|
-
value:
|
|
1257
|
+
name: d,
|
|
1258
|
+
value: g.target.value
|
|
1053
1259
|
}
|
|
1054
1260
|
}), this.onChange(m);
|
|
1055
1261
|
}
|
|
1056
1262
|
});
|
|
1057
|
-
return o.addEventListener("blur", (
|
|
1263
|
+
return o.addEventListener("blur", (g) => {
|
|
1058
1264
|
const m = new Event("blur", { bubbles: !0 });
|
|
1059
1265
|
Object.defineProperty(m, "target", {
|
|
1060
1266
|
writable: !1,
|
|
1061
1267
|
value: {
|
|
1062
|
-
name:
|
|
1063
|
-
value:
|
|
1268
|
+
name: d,
|
|
1269
|
+
value: g.target.value
|
|
1064
1270
|
}
|
|
1065
1271
|
}), this.onBlur(m);
|
|
1066
1272
|
}), o;
|
|
1067
1273
|
}
|
|
1068
|
-
createUngroupedFields(e, t, s,
|
|
1069
|
-
const r = e.styles.borderRadius,
|
|
1274
|
+
createUngroupedFields(e, t, s, a, n) {
|
|
1275
|
+
const r = e.styles.borderRadius, l = {
|
|
1070
1276
|
color: e.styles.textColor,
|
|
1071
1277
|
fontSize: e.styles.fontSize,
|
|
1072
1278
|
fontFamily: e.styles.fontFamily,
|
|
1073
1279
|
borderRadius: `${r}px`
|
|
1074
|
-
},
|
|
1075
|
-
if (!t[
|
|
1076
|
-
const o = t[
|
|
1077
|
-
|
|
1280
|
+
}, d = (c, p, b) => {
|
|
1281
|
+
if (!t[c]?.enabled) return;
|
|
1282
|
+
const o = t[c]?.label ?? this.translationFunc(p), g = this.createRow(["full"]), m = this.createInput(
|
|
1283
|
+
c,
|
|
1078
1284
|
o,
|
|
1079
|
-
s[
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1285
|
+
s[c],
|
|
1286
|
+
a[c],
|
|
1287
|
+
n[c],
|
|
1288
|
+
l,
|
|
1289
|
+
b
|
|
1084
1290
|
);
|
|
1085
|
-
this.inputs.set(
|
|
1291
|
+
this.inputs.set(c, m), g.appendChild(m.getElement()), this.fieldsContainer.appendChild(g);
|
|
1086
1292
|
};
|
|
1087
|
-
if (
|
|
1088
|
-
const
|
|
1293
|
+
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) {
|
|
1294
|
+
const c = t.country?.label ?? this.translationFunc("address.chooseCountry"), p = this.createRow(["full"]), b = this.createCountrySelect(
|
|
1089
1295
|
s.country,
|
|
1090
|
-
i.country,
|
|
1091
1296
|
a.country,
|
|
1092
|
-
|
|
1297
|
+
n.country,
|
|
1298
|
+
l,
|
|
1093
1299
|
t.country?.options,
|
|
1094
|
-
|
|
1300
|
+
c
|
|
1095
1301
|
);
|
|
1096
|
-
this.inputs.set("country",
|
|
1302
|
+
this.inputs.set("country", b), p.appendChild(b.getElement()), this.fieldsContainer.appendChild(p);
|
|
1097
1303
|
}
|
|
1098
1304
|
if (t.state?.enabled) {
|
|
1099
1305
|
this.stateOptions = t.state?.options;
|
|
1100
|
-
const
|
|
1101
|
-
if (
|
|
1306
|
+
const c = this.createRow(["full"]), p = t.state?.options && t.state.options.length > 0, b = t.state?.label ?? this.translationFunc("address.chooseState");
|
|
1307
|
+
if (p) {
|
|
1102
1308
|
const o = this.createStateSelect(
|
|
1103
1309
|
s.state,
|
|
1104
|
-
i.state,
|
|
1105
1310
|
a.state,
|
|
1106
|
-
|
|
1311
|
+
n.state,
|
|
1312
|
+
l,
|
|
1107
1313
|
t.state?.options,
|
|
1108
1314
|
s.country,
|
|
1109
|
-
|
|
1315
|
+
b
|
|
1110
1316
|
);
|
|
1111
|
-
this.inputs.set("state", o),
|
|
1317
|
+
this.inputs.set("state", o), c.appendChild(o.getElement());
|
|
1112
1318
|
} else {
|
|
1113
1319
|
const o = this.createInput(
|
|
1114
1320
|
"state",
|
|
1115
|
-
|
|
1321
|
+
b,
|
|
1116
1322
|
s.state,
|
|
1117
|
-
i.state,
|
|
1118
1323
|
a.state,
|
|
1119
|
-
|
|
1324
|
+
n.state,
|
|
1325
|
+
l,
|
|
1120
1326
|
"address-level1"
|
|
1121
1327
|
);
|
|
1122
|
-
this.inputs.set("state", o),
|
|
1328
|
+
this.inputs.set("state", o), c.appendChild(o.getElement());
|
|
1123
1329
|
}
|
|
1124
|
-
this.fieldsContainer.appendChild(
|
|
1330
|
+
this.fieldsContainer.appendChild(c);
|
|
1125
1331
|
}
|
|
1126
|
-
|
|
1332
|
+
d("zipCode", "address.postalCode", "postal-code");
|
|
1127
1333
|
}
|
|
1128
1334
|
getValue(e) {
|
|
1129
1335
|
return this.inputs.get(e)?.getValue() ?? "";
|
|
@@ -1148,28 +1354,28 @@ class se extends A {
|
|
|
1148
1354
|
});
|
|
1149
1355
|
}
|
|
1150
1356
|
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
1357
|
const a = this.inputs.get(e);
|
|
1159
1358
|
if (a) {
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1359
|
+
const n = a.getElement().querySelector("input") || a.getElement().querySelector("select");
|
|
1360
|
+
document.activeElement !== n && a.setError(t, s);
|
|
1162
1361
|
}
|
|
1163
|
-
|
|
1362
|
+
}
|
|
1363
|
+
updateField(e, t, s, a) {
|
|
1364
|
+
const n = this.inputs.get(e);
|
|
1365
|
+
if (n) {
|
|
1366
|
+
const l = n.getElement().querySelector("input") || n.getElement().querySelector("select"), d = n.getValue();
|
|
1367
|
+
!(document.activeElement === l) && !(t === "" && d !== "") && this.setValue(e, t);
|
|
1368
|
+
}
|
|
1369
|
+
const r = !!(a && s);
|
|
1164
1370
|
this.setError(e, r, s);
|
|
1165
1371
|
}
|
|
1166
1372
|
updateAllFields(e, t, s) {
|
|
1167
|
-
Object.keys(e).forEach((
|
|
1373
|
+
Object.keys(e).forEach((a) => {
|
|
1168
1374
|
this.updateField(
|
|
1169
|
-
|
|
1170
|
-
e[
|
|
1171
|
-
t[
|
|
1172
|
-
!!s[
|
|
1375
|
+
a,
|
|
1376
|
+
e[a],
|
|
1377
|
+
t[a],
|
|
1378
|
+
!!s[a]
|
|
1173
1379
|
);
|
|
1174
1380
|
});
|
|
1175
1381
|
}
|
|
@@ -1178,66 +1384,108 @@ class se extends A {
|
|
|
1178
1384
|
e && e.focus();
|
|
1179
1385
|
}
|
|
1180
1386
|
}
|
|
1181
|
-
class
|
|
1182
|
-
input;
|
|
1387
|
+
class mt {
|
|
1388
|
+
input = null;
|
|
1389
|
+
isVgsMode;
|
|
1390
|
+
vgsWrapper = null;
|
|
1391
|
+
vgsContainer = null;
|
|
1392
|
+
vgsHelperText = null;
|
|
1393
|
+
wrapperElement;
|
|
1183
1394
|
constructor(e) {
|
|
1184
1395
|
const {
|
|
1185
1396
|
value: t,
|
|
1186
1397
|
onChange: s,
|
|
1187
|
-
onBlur:
|
|
1188
|
-
errorMsg:
|
|
1398
|
+
onBlur: a,
|
|
1399
|
+
errorMsg: n,
|
|
1189
1400
|
checkoutProfile: r,
|
|
1190
|
-
translationFunc:
|
|
1191
|
-
autocomplete:
|
|
1401
|
+
translationFunc: l,
|
|
1402
|
+
autocomplete: d = "cc-name",
|
|
1403
|
+
isVgsMode: c = !1
|
|
1192
1404
|
} = e;
|
|
1193
|
-
this.
|
|
1405
|
+
this.isVgsMode = c, this.wrapperElement = document.createElement("div"), c ? this.buildVgsLayout(r, l) : this.buildNativeLayout(
|
|
1406
|
+
t,
|
|
1407
|
+
s,
|
|
1408
|
+
a,
|
|
1409
|
+
n,
|
|
1410
|
+
r,
|
|
1411
|
+
l,
|
|
1412
|
+
d
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
buildVgsLayout(e, t) {
|
|
1416
|
+
const s = e.styles.borderRadius, a = document.createElement("div");
|
|
1417
|
+
a.style.marginBottom = "4px";
|
|
1418
|
+
const n = document.createElement("label");
|
|
1419
|
+
n.className = "input-label", n.textContent = t("cardholderNameLabel"), n.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, a.appendChild(n), this.wrapperElement.appendChild(a), this.vgsWrapper = document.createElement("div"), this.vgsWrapper.className = "vgs-wrap", this.vgsWrapper.style.position = "relative", this.vgsWrapper.style.borderRadius = `${s}px`, this.vgsWrapper.style.height = "38.5px", this.vgsWrapper.style.width = "100%", this.vgsWrapper.style.overflow = "hidden", this.vgsWrapper.style.background = "#fff", this.vgsWrapper.style.boxShadow = "none";
|
|
1420
|
+
const r = document.createElement("div");
|
|
1421
|
+
r.className = "vgs-field-skeleton", this.vgsWrapper.appendChild(r), this.vgsContainer = document.createElement("div"), this.vgsContainer.id = `vgs-cc-name-${Date.now()}`, this.vgsContainer.style.position = "relative", this.vgsContainer.style.zIndex = "1", this.vgsContainer.style.width = "100%", this.vgsContainer.style.height = "100%", this.vgsWrapper.appendChild(this.vgsContainer), this.wrapperElement.appendChild(this.vgsWrapper), this.vgsHelperText = new be({ visible: !1 }), this.wrapperElement.appendChild(this.vgsHelperText.getElement());
|
|
1422
|
+
}
|
|
1423
|
+
buildNativeLayout(e, t, s, a, n, r, l) {
|
|
1424
|
+
this.input = new ce({
|
|
1194
1425
|
name: "name",
|
|
1195
|
-
label:
|
|
1196
|
-
// Always hide error initially - we'll show it only on blur if needed
|
|
1426
|
+
label: r("cardholderNameLabel"),
|
|
1197
1427
|
error: !1,
|
|
1198
1428
|
errorMsg: a,
|
|
1199
1429
|
styles: {
|
|
1200
|
-
color:
|
|
1201
|
-
borderRadius: `${
|
|
1202
|
-
fontSize:
|
|
1203
|
-
fontFamily:
|
|
1430
|
+
color: n.styles.textColor,
|
|
1431
|
+
borderRadius: `${n.styles.borderRadius}px`,
|
|
1432
|
+
fontSize: n.styles.fontSize,
|
|
1433
|
+
fontFamily: n.styles.fontFamily
|
|
1204
1434
|
},
|
|
1205
|
-
placeholder:
|
|
1206
|
-
value:
|
|
1435
|
+
placeholder: r("cardholderNamePlaceholder"),
|
|
1436
|
+
value: e,
|
|
1207
1437
|
autocomplete: l,
|
|
1208
|
-
onChange: (
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1438
|
+
onChange: (d) => {
|
|
1439
|
+
const p = d.target.value, b = p.replace(/[^a-zA-Z\s\-'.]/g, "");
|
|
1440
|
+
p !== b && this.input?.setValue(b), this.input?.setError(!1), this.trim(), t(d);
|
|
1211
1441
|
}
|
|
1212
|
-
}), this.input.addEventListener("blur", (
|
|
1213
|
-
|
|
1214
|
-
});
|
|
1442
|
+
}), this.input.addEventListener("blur", (d) => {
|
|
1443
|
+
s(d);
|
|
1444
|
+
}), this.wrapperElement.appendChild(this.input.getElement());
|
|
1445
|
+
}
|
|
1446
|
+
getVgsContainerId() {
|
|
1447
|
+
return this.vgsContainer?.id;
|
|
1448
|
+
}
|
|
1449
|
+
handleVgsStateChange(e, t) {
|
|
1450
|
+
if (!this.isVgsMode || !this.vgsWrapper) return;
|
|
1451
|
+
const a = !!e[J.CARDHOLDER]?.isFocused;
|
|
1452
|
+
if (this.vgsWrapper.classList.toggle("vgs-wrap-focused", a), !t || !this.vgsHelperText) return;
|
|
1453
|
+
const n = t[J.CARDHOLDER];
|
|
1454
|
+
n ? (this.vgsHelperText.setText(n), this.vgsHelperText.toggleVisibility(!0)) : this.vgsHelperText.toggleVisibility(!1);
|
|
1455
|
+
}
|
|
1456
|
+
hideFakePlaceholder() {
|
|
1457
|
+
if (!this.vgsWrapper) return;
|
|
1458
|
+
this.vgsWrapper.style.boxShadow = "";
|
|
1459
|
+
const e = this.vgsWrapper.querySelector(".vgs-field-skeleton");
|
|
1460
|
+
e && e.remove();
|
|
1215
1461
|
}
|
|
1216
1462
|
getValue() {
|
|
1217
|
-
return this.input
|
|
1463
|
+
return this.isVgsMode ? "" : this.input?.getValue() ?? "";
|
|
1218
1464
|
}
|
|
1219
1465
|
setValue(e) {
|
|
1220
|
-
return this.input
|
|
1466
|
+
return this.isVgsMode || this.input?.setValue(e), this;
|
|
1221
1467
|
}
|
|
1222
1468
|
trim() {
|
|
1469
|
+
if (this.isVgsMode) return this;
|
|
1223
1470
|
const e = this.getValue().trimStart();
|
|
1224
1471
|
return this.setValue(e), this;
|
|
1225
1472
|
}
|
|
1226
1473
|
setError(e, t) {
|
|
1227
|
-
|
|
1228
|
-
|
|
1474
|
+
if (this.isVgsMode) return this;
|
|
1475
|
+
const s = this.input?.getElement().querySelector("input");
|
|
1476
|
+
return s && document.activeElement !== s && this.input?.setError(e, t), this;
|
|
1229
1477
|
}
|
|
1230
1478
|
getElement() {
|
|
1231
|
-
return this.input.getElement();
|
|
1479
|
+
return !this.isVgsMode && this.input ? this.input.getElement() : this.wrapperElement;
|
|
1232
1480
|
}
|
|
1233
1481
|
appendTo(e) {
|
|
1234
|
-
return this.
|
|
1482
|
+
return e.appendChild(this.getElement()), this;
|
|
1235
1483
|
}
|
|
1236
1484
|
focus() {
|
|
1237
|
-
this.input
|
|
1485
|
+
this.isVgsMode || this.input?.focus();
|
|
1238
1486
|
}
|
|
1239
1487
|
}
|
|
1240
|
-
class
|
|
1488
|
+
class he extends P {
|
|
1241
1489
|
constructor() {
|
|
1242
1490
|
super("div", ["skeleton-container"]), this.createSkeletonElements();
|
|
1243
1491
|
}
|
|
@@ -1245,35 +1493,35 @@ class oe extends A {
|
|
|
1245
1493
|
this.appendChild(this.createPaymentMethodSkeleton()), this.appendChild(this.createPaymentSeparatorSkeleton());
|
|
1246
1494
|
}
|
|
1247
1495
|
createPaymentMethodSkeleton() {
|
|
1248
|
-
const e =
|
|
1496
|
+
const e = k.createDiv(["skeleton-field"]), t = k.createDiv([
|
|
1249
1497
|
"skeleton",
|
|
1250
1498
|
"skeleton-payment-method"
|
|
1251
1499
|
]);
|
|
1252
1500
|
return e.appendChild(t), e;
|
|
1253
1501
|
}
|
|
1254
1502
|
createPaymentSeparatorSkeleton() {
|
|
1255
|
-
const e =
|
|
1503
|
+
const e = k.createDiv([
|
|
1256
1504
|
"payment-separator_container"
|
|
1257
|
-
]), t =
|
|
1505
|
+
]), t = k.createDiv(["payment-separator__line"]), s = k.createDiv([
|
|
1258
1506
|
"skeleton",
|
|
1259
1507
|
"skeleton-separator-text"
|
|
1260
|
-
]),
|
|
1261
|
-
return e.appendChild(t), e.appendChild(s), e.appendChild(
|
|
1508
|
+
]), a = k.createDiv(["payment-separator__line"]);
|
|
1509
|
+
return e.appendChild(t), e.appendChild(s), e.appendChild(a), e;
|
|
1262
1510
|
}
|
|
1263
1511
|
}
|
|
1264
|
-
class
|
|
1512
|
+
class pt extends P {
|
|
1265
1513
|
constructor(e) {
|
|
1266
1514
|
const { translationFunc: t, checkoutProfile: s } = e;
|
|
1267
1515
|
super("div", ["payment-separator"]);
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1516
|
+
const a = this.getElement(), n = document.createElement("span");
|
|
1517
|
+
n.className = "payment-separator__line";
|
|
1270
1518
|
const r = document.createElement("p");
|
|
1271
1519
|
r.textContent = t("pay-with-card"), r.className = "payment-separator__text", r.style.fontFamily = `${s.styles.fontFamily}, sans-serif`;
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1520
|
+
const l = document.createElement("span");
|
|
1521
|
+
l.className = "payment-separator__line", a.appendChild(n), a.appendChild(r), a.appendChild(l);
|
|
1274
1522
|
}
|
|
1275
1523
|
}
|
|
1276
|
-
class
|
|
1524
|
+
class gt extends P {
|
|
1277
1525
|
paymentMethods;
|
|
1278
1526
|
paymentSeparator;
|
|
1279
1527
|
skeleton;
|
|
@@ -1281,14 +1529,14 @@ class at extends A {
|
|
|
1281
1529
|
const {
|
|
1282
1530
|
checkoutProfile: t,
|
|
1283
1531
|
formData: s,
|
|
1284
|
-
onPaypalSubmit:
|
|
1285
|
-
onApplePaySubmit:
|
|
1532
|
+
onPaypalSubmit: a,
|
|
1533
|
+
onApplePaySubmit: n,
|
|
1286
1534
|
supportedPaymentMethods: r,
|
|
1287
|
-
translationFunc:
|
|
1288
|
-
paymentId:
|
|
1289
|
-
checkoutKey:
|
|
1290
|
-
checkoutDetails:
|
|
1291
|
-
environment:
|
|
1535
|
+
translationFunc: l,
|
|
1536
|
+
paymentId: d,
|
|
1537
|
+
checkoutKey: c,
|
|
1538
|
+
checkoutDetails: p,
|
|
1539
|
+
environment: b,
|
|
1292
1540
|
countryCode: o
|
|
1293
1541
|
} = e;
|
|
1294
1542
|
if (super("div", ["payment-methods"]), this.paymentMethods = /* @__PURE__ */ new Map(), !t?.additionalPaymentMethods) {
|
|
@@ -1299,44 +1547,44 @@ class at extends A {
|
|
|
1299
1547
|
this.renderSkeleton();
|
|
1300
1548
|
return;
|
|
1301
1549
|
}
|
|
1302
|
-
const
|
|
1550
|
+
const g = Object.entries(
|
|
1303
1551
|
t.additionalPaymentMethods
|
|
1304
|
-
).filter(([m,
|
|
1305
|
-
const
|
|
1306
|
-
return
|
|
1307
|
-
}).sort((m,
|
|
1308
|
-
if (
|
|
1552
|
+
).filter(([m, u]) => {
|
|
1553
|
+
const f = u.enabled, h = r ? r[m] === !0 : !0, y = !u.countries || o && u.countries.includes(o);
|
|
1554
|
+
return f && h && y;
|
|
1555
|
+
}).sort((m, u) => m[1].order - u[1].order);
|
|
1556
|
+
if (g.length === 0) {
|
|
1309
1557
|
this.getElement().style.display = "none";
|
|
1310
1558
|
return;
|
|
1311
1559
|
}
|
|
1312
|
-
for (const [m] of
|
|
1560
|
+
for (const [m] of g)
|
|
1313
1561
|
switch (m) {
|
|
1314
1562
|
case "paypal": {
|
|
1315
|
-
if (
|
|
1316
|
-
const
|
|
1563
|
+
if (a) {
|
|
1564
|
+
const u = new Se({
|
|
1317
1565
|
checkoutProfile: t,
|
|
1318
1566
|
formData: s,
|
|
1319
|
-
onSubmit:
|
|
1567
|
+
onSubmit: a
|
|
1320
1568
|
});
|
|
1321
|
-
this.paymentMethods.set("paypal",
|
|
1569
|
+
this.paymentMethods.set("paypal", u), u.appendTo(this.getElement());
|
|
1322
1570
|
}
|
|
1323
1571
|
break;
|
|
1324
1572
|
}
|
|
1325
1573
|
case "applePay": {
|
|
1326
|
-
if (
|
|
1327
|
-
const
|
|
1574
|
+
if (n && d && c) {
|
|
1575
|
+
const u = t.appearance?.additionalPaymentMethods?.applePay, f = new ve({
|
|
1328
1576
|
checkoutProfile: t,
|
|
1329
1577
|
formData: s,
|
|
1330
|
-
onSubmit:
|
|
1331
|
-
paymentId:
|
|
1332
|
-
checkoutKey:
|
|
1333
|
-
checkoutDetails:
|
|
1334
|
-
environment:
|
|
1335
|
-
displayName:
|
|
1336
|
-
requiredBillingContactFields:
|
|
1337
|
-
requiredShippingContactFields:
|
|
1578
|
+
onSubmit: n,
|
|
1579
|
+
paymentId: d,
|
|
1580
|
+
checkoutKey: c,
|
|
1581
|
+
checkoutDetails: p,
|
|
1582
|
+
environment: b,
|
|
1583
|
+
displayName: u?.displayName,
|
|
1584
|
+
requiredBillingContactFields: u?.requiredBillingContactFields,
|
|
1585
|
+
requiredShippingContactFields: u?.requiredShippingContactFields
|
|
1338
1586
|
});
|
|
1339
|
-
this.paymentMethods.set("applePay",
|
|
1587
|
+
this.paymentMethods.set("applePay", f), f.appendTo(this.getElement());
|
|
1340
1588
|
}
|
|
1341
1589
|
break;
|
|
1342
1590
|
}
|
|
@@ -1352,13 +1600,13 @@ class at extends A {
|
|
|
1352
1600
|
);
|
|
1353
1601
|
break;
|
|
1354
1602
|
}
|
|
1355
|
-
this.paymentMethods.size > 0 && (this.paymentSeparator = new
|
|
1356
|
-
translationFunc:
|
|
1603
|
+
this.paymentMethods.size > 0 && (this.paymentSeparator = new pt({
|
|
1604
|
+
translationFunc: l,
|
|
1357
1605
|
checkoutProfile: t
|
|
1358
1606
|
}), this.getElement().appendChild(this.paymentSeparator.getElement()));
|
|
1359
1607
|
}
|
|
1360
1608
|
renderSkeleton() {
|
|
1361
|
-
this.skeleton = new
|
|
1609
|
+
this.skeleton = new he(), this.getElement().appendChild(this.skeleton.getElement());
|
|
1362
1610
|
}
|
|
1363
1611
|
updateFormData(e) {
|
|
1364
1612
|
const t = this.paymentMethods.get("paypal");
|
|
@@ -1370,8 +1618,8 @@ class at extends A {
|
|
|
1370
1618
|
return this.paymentMethods.size > 0 && this.getElement().style.display !== "none";
|
|
1371
1619
|
}
|
|
1372
1620
|
}
|
|
1373
|
-
const
|
|
1374
|
-
class
|
|
1621
|
+
const ft = 17;
|
|
1622
|
+
class yt extends P {
|
|
1375
1623
|
styles;
|
|
1376
1624
|
isHovered = !1;
|
|
1377
1625
|
constructor(e) {
|
|
@@ -1381,7 +1629,7 @@ class rt extends A {
|
|
|
1381
1629
|
}
|
|
1382
1630
|
applyStyles() {
|
|
1383
1631
|
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 ===
|
|
1632
|
+
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 === ft ? "100vmax" : `${this.styles.borderRadius}px`, e.style.fontSize = `${this.styles.fontSize}px`, e.style.fontFamily = `${this.styles.fontFamily}, sans-serif`;
|
|
1385
1633
|
}
|
|
1386
1634
|
handleMouseEnter() {
|
|
1387
1635
|
this.isHovered = !0, this.applyStyles();
|
|
@@ -1393,12 +1641,12 @@ class rt extends A {
|
|
|
1393
1641
|
return this.getElement().disabled = e, e ? (this.addClass("disabled"), this.removeClass("valid")) : (this.removeClass("disabled"), this.addClass("valid")), this.applyStyles(), this;
|
|
1394
1642
|
}
|
|
1395
1643
|
}
|
|
1396
|
-
class
|
|
1644
|
+
class bt {
|
|
1397
1645
|
button;
|
|
1398
1646
|
constructor(e) {
|
|
1399
|
-
const { disabled: t, checkoutProfile: s, translationFunc:
|
|
1400
|
-
this.button = new
|
|
1401
|
-
text:
|
|
1647
|
+
const { disabled: t, checkoutProfile: s, translationFunc: a } = e;
|
|
1648
|
+
this.button = new yt({
|
|
1649
|
+
text: a(
|
|
1402
1650
|
`buttonTexts.${s?.layout.actionButton.translationKey}`
|
|
1403
1651
|
),
|
|
1404
1652
|
styles: {
|
|
@@ -1424,7 +1672,7 @@ class ot {
|
|
|
1424
1672
|
return this.button.appendTo(e), this;
|
|
1425
1673
|
}
|
|
1426
1674
|
}
|
|
1427
|
-
class
|
|
1675
|
+
class vt {
|
|
1428
1676
|
formElement;
|
|
1429
1677
|
focusManager;
|
|
1430
1678
|
translationFunc;
|
|
@@ -1439,6 +1687,8 @@ class lt {
|
|
|
1439
1687
|
checkoutKey;
|
|
1440
1688
|
checkoutDetails;
|
|
1441
1689
|
environment;
|
|
1690
|
+
vgsService;
|
|
1691
|
+
onVgsStateChange;
|
|
1442
1692
|
// Form components
|
|
1443
1693
|
emailField;
|
|
1444
1694
|
phoneNumberField;
|
|
@@ -1449,6 +1699,9 @@ class lt {
|
|
|
1449
1699
|
paymentMethods;
|
|
1450
1700
|
billingAddressSection;
|
|
1451
1701
|
shippingAddressSection;
|
|
1702
|
+
cardSectionSkeleton;
|
|
1703
|
+
cardholderSectionSkeleton;
|
|
1704
|
+
isCheckoutDetailsLoaded = !1;
|
|
1452
1705
|
// Event handler references
|
|
1453
1706
|
emailFocusHandler;
|
|
1454
1707
|
phoneNumberFocusHandler;
|
|
@@ -1457,15 +1710,15 @@ class lt {
|
|
|
1457
1710
|
cardCvvFocusHandler;
|
|
1458
1711
|
nameFocusHandler;
|
|
1459
1712
|
constructor(e) {
|
|
1460
|
-
this.formElement = e.formElement, this.focusManager = e.focusManager, this.translationFunc = e.translationFunc, this.locale = e.locale, this.onFieldFocus = e.onFieldFocus, this.onChange = e.onChange, this.onBlur = e.onBlur, this.onPaypalSubmit = e.onPaypalSubmit, this.onApplePaySubmit = e.onApplePaySubmit, this.supportedPaymentMethods = e.supportedPaymentMethods, this.paymentId = e.paymentId, this.checkoutKey = e.checkoutKey, this.checkoutDetails = e.checkoutDetails, this.environment = e.environment;
|
|
1713
|
+
this.formElement = e.formElement, this.focusManager = e.focusManager, this.translationFunc = e.translationFunc, this.locale = e.locale, this.onFieldFocus = e.onFieldFocus, this.onChange = e.onChange, this.onBlur = e.onBlur, this.onPaypalSubmit = e.onPaypalSubmit, this.onApplePaySubmit = e.onApplePaySubmit, this.supportedPaymentMethods = e.supportedPaymentMethods, this.paymentId = e.paymentId, this.checkoutKey = e.checkoutKey, this.checkoutDetails = e.checkoutDetails, this.environment = e.environment, this.vgsService = e.vgsService, this.onVgsStateChange = e.onVgsStateChange;
|
|
1461
1714
|
}
|
|
1462
1715
|
createPaymentMethods(e, t, s = !1) {
|
|
1463
1716
|
try {
|
|
1464
1717
|
if (!e?.additionalPaymentMethods || Object.keys(e.additionalPaymentMethods).length === 0 || !Object.values(e.additionalPaymentMethods).some(
|
|
1465
|
-
(
|
|
1718
|
+
(a) => a.enabled
|
|
1466
1719
|
))
|
|
1467
1720
|
return;
|
|
1468
|
-
this.paymentMethods = new
|
|
1721
|
+
this.paymentMethods = new gt({
|
|
1469
1722
|
checkoutProfile: e,
|
|
1470
1723
|
formData: t,
|
|
1471
1724
|
supportedPaymentMethods: this.supportedPaymentMethods,
|
|
@@ -1481,119 +1734,143 @@ class lt {
|
|
|
1481
1734
|
this.paymentMethods.getElement(),
|
|
1482
1735
|
this.formElement.firstChild
|
|
1483
1736
|
) : this.formElement.appendChild(this.paymentMethods.getElement());
|
|
1484
|
-
} catch (
|
|
1485
|
-
throw console.error("Error creating payment methods:",
|
|
1737
|
+
} catch (a) {
|
|
1738
|
+
throw console.error("Error creating payment methods:", a), a;
|
|
1486
1739
|
}
|
|
1487
1740
|
}
|
|
1488
|
-
createEmailField(e, t, s,
|
|
1741
|
+
createEmailField(e, t, s, a) {
|
|
1489
1742
|
try {
|
|
1490
|
-
const
|
|
1743
|
+
const n = e.layout.billingFields && Object.values(e.layout.billingFields).some(
|
|
1491
1744
|
(r) => r?.enabled
|
|
1492
1745
|
) || e.layout.shippingFields && Object.values(e.layout.shippingFields).some(
|
|
1493
1746
|
(r) => r?.enabled
|
|
1494
1747
|
);
|
|
1495
|
-
this.emailField = new
|
|
1748
|
+
this.emailField = new Ee({
|
|
1496
1749
|
value: t.email,
|
|
1497
1750
|
onChange: this.onChange,
|
|
1498
1751
|
onBlur: this.onBlur,
|
|
1499
|
-
onTab:
|
|
1752
|
+
onTab: n ? void 0 : () => this.focusManager.focusField(
|
|
1500
1753
|
e.layout.phoneNumber?.enabled ? "phoneNumber" : "cardNumber"
|
|
1501
1754
|
),
|
|
1502
|
-
error: !!(s.email &&
|
|
1755
|
+
error: !!(s.email && a.email),
|
|
1503
1756
|
errorMsg: s.email,
|
|
1504
1757
|
checkoutProfile: e,
|
|
1505
1758
|
translationFunc: this.translationFunc
|
|
1506
1759
|
}), 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:",
|
|
1760
|
+
} catch (n) {
|
|
1761
|
+
throw console.error("Error creating email field:", n), n;
|
|
1509
1762
|
}
|
|
1510
1763
|
}
|
|
1511
|
-
createPhoneNumberField(e, t, s,
|
|
1512
|
-
const
|
|
1513
|
-
this.phonePlaceholder =
|
|
1514
|
-
|
|
1764
|
+
createPhoneNumberField(e, t, s, a) {
|
|
1765
|
+
const n = document.createElement("div");
|
|
1766
|
+
this.phonePlaceholder = n, this.formElement.appendChild(n), Ce().then(({ PhoneNumberField: r }) => {
|
|
1767
|
+
n.isConnected && (this.phoneNumberField = new r({
|
|
1515
1768
|
value: t.phoneNumber ?? "",
|
|
1516
1769
|
onChange: this.onChange,
|
|
1517
1770
|
onBlur: this.onBlur,
|
|
1518
1771
|
onTab: () => this.focusManager.focusField("cardNumber"),
|
|
1519
|
-
error: !!(s.phoneNumber &&
|
|
1772
|
+
error: !!(s.phoneNumber && a.phoneNumber),
|
|
1520
1773
|
errorMsg: s.phoneNumber,
|
|
1521
1774
|
checkoutProfile: e,
|
|
1522
1775
|
translationFunc: this.translationFunc,
|
|
1523
1776
|
defaultCountry: e.layout.phoneNumber?.defaultCountry || "US",
|
|
1524
1777
|
allowedCountries: e.layout.phoneNumber?.allowedCountries,
|
|
1525
1778
|
locale: this.locale
|
|
1526
|
-
}), this.phoneNumberFocusHandler = () => this.onFieldFocus("phoneNumber"), this.phoneNumberField.getElement().addEventListener("focus", this.phoneNumberFocusHandler, !0), this.focusManager.registerField("phoneNumber", this.phoneNumberField),
|
|
1779
|
+
}), this.phoneNumberFocusHandler = () => this.onFieldFocus("phoneNumber"), this.phoneNumberField.getElement().addEventListener("focus", this.phoneNumberFocusHandler, !0), this.focusManager.registerField("phoneNumber", this.phoneNumberField), n.replaceWith(this.phoneNumberField.getElement()), this.phonePlaceholder = void 0);
|
|
1527
1780
|
}).catch((r) => {
|
|
1528
|
-
console.error("Error creating phone number field:", r),
|
|
1781
|
+
console.error("Error creating phone number field:", r), n.remove(), this.phonePlaceholder = void 0;
|
|
1529
1782
|
});
|
|
1530
1783
|
}
|
|
1531
|
-
|
|
1784
|
+
setCheckoutDetailsLoaded(e) {
|
|
1785
|
+
this.isCheckoutDetailsLoaded = e;
|
|
1786
|
+
}
|
|
1787
|
+
createCardSection(e, t, s, a) {
|
|
1532
1788
|
try {
|
|
1533
|
-
this.
|
|
1789
|
+
if (!this.isCheckoutDetailsLoaded) {
|
|
1790
|
+
this.cardSectionSkeleton = this.buildCardSkeleton(e), this.formElement.appendChild(this.cardSectionSkeleton);
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1793
|
+
if (this.cardSection = new Fe({
|
|
1534
1794
|
checkoutProfile: e,
|
|
1535
1795
|
cardNumber: t.cardNumber,
|
|
1536
1796
|
cardNumberError: s.cardNumber,
|
|
1537
|
-
cardNumberTouched: !!
|
|
1797
|
+
cardNumberTouched: !!a.cardNumber,
|
|
1538
1798
|
cardCvv: t.cardCvv,
|
|
1539
1799
|
cardCvvError: s.cardCvv,
|
|
1540
|
-
cardCvvTouched: !!
|
|
1800
|
+
cardCvvTouched: !!a.cardCvv,
|
|
1541
1801
|
cardExpiry: t.cardExpiry,
|
|
1542
1802
|
cardExpiryError: s.cardExpiry,
|
|
1543
|
-
cardExpiryTouched: !!
|
|
1803
|
+
cardExpiryTouched: !!a.cardExpiry,
|
|
1544
1804
|
onChange: this.onChange,
|
|
1545
1805
|
onBlur: this.onBlur,
|
|
1546
1806
|
onCardBrandChange: () => {
|
|
1547
1807
|
if (t.cardCvv) {
|
|
1548
|
-
const
|
|
1549
|
-
Object.defineProperty(
|
|
1808
|
+
const n = new Event("blur", { bubbles: !0 });
|
|
1809
|
+
Object.defineProperty(n, "target", {
|
|
1550
1810
|
writable: !1,
|
|
1551
1811
|
value: { name: "cardCvv", value: t.cardCvv }
|
|
1552
|
-
}), this.onBlur(
|
|
1812
|
+
}), this.onBlur(n);
|
|
1553
1813
|
}
|
|
1554
1814
|
},
|
|
1555
|
-
translationFunc: this.translationFunc
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1815
|
+
translationFunc: this.translationFunc,
|
|
1816
|
+
vgsService: this.vgsService,
|
|
1817
|
+
onVgsStateChange: this.onVgsStateChange
|
|
1818
|
+
}), !this.vgsService) {
|
|
1819
|
+
const n = this.cardSection.getElement().querySelector('input[name="cardExpiry"]');
|
|
1820
|
+
n && (this.cardExpiryFocusHandler = () => this.onFieldFocus("cardExpiry"), n.addEventListener(
|
|
1821
|
+
"focus",
|
|
1822
|
+
this.cardExpiryFocusHandler
|
|
1823
|
+
));
|
|
1824
|
+
const r = this.cardSection.getElement().querySelector('input[name="cardNumber"]');
|
|
1825
|
+
r && (this.cardNumberFocusHandler = () => this.onFieldFocus("cardNumber"), r.addEventListener(
|
|
1826
|
+
"focus",
|
|
1827
|
+
this.cardNumberFocusHandler
|
|
1828
|
+
));
|
|
1829
|
+
const l = this.cardSection.getElement().querySelector('input[name="cardCvv"]');
|
|
1830
|
+
l && (this.cardCvvFocusHandler = () => this.onFieldFocus("cardCvv"), l.addEventListener("focus", this.cardCvvFocusHandler));
|
|
1831
|
+
}
|
|
1832
|
+
this.focusManager.registerField("cardNumber", {
|
|
1563
1833
|
focus: () => this.cardSection?.focusField("cardNumber")
|
|
1564
1834
|
}), this.focusManager.registerField("cardExpiry", {
|
|
1565
1835
|
focus: () => this.cardSection?.focusField("cardExpiry")
|
|
1566
1836
|
}), this.focusManager.registerField("cardCvv", {
|
|
1567
1837
|
focus: () => this.cardSection?.focusField("cardCvv")
|
|
1568
1838
|
}), this.formElement.appendChild(this.cardSection.getElement());
|
|
1569
|
-
} catch (
|
|
1570
|
-
throw console.error("Error creating card section:",
|
|
1839
|
+
} catch (n) {
|
|
1840
|
+
throw console.error("Error creating card section:", n), n;
|
|
1571
1841
|
}
|
|
1572
1842
|
}
|
|
1573
|
-
createCardholderSection(e, t, s,
|
|
1843
|
+
createCardholderSection(e, t, s, a) {
|
|
1574
1844
|
try {
|
|
1575
|
-
this.
|
|
1845
|
+
if (!this.isCheckoutDetailsLoaded) {
|
|
1846
|
+
this.cardholderSectionSkeleton = this.buildCardholderSkeleton(e), this.formElement.appendChild(this.cardholderSectionSkeleton);
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
if (this.cardholderSection = new mt({
|
|
1576
1850
|
value: t.name,
|
|
1577
1851
|
onChange: this.onChange,
|
|
1578
1852
|
onBlur: this.onBlur,
|
|
1579
|
-
error: !!(s.name &&
|
|
1853
|
+
error: !!(s.name && a.name),
|
|
1580
1854
|
errorMsg: s.name,
|
|
1581
1855
|
checkoutProfile: e,
|
|
1582
|
-
translationFunc: this.translationFunc
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1856
|
+
translationFunc: this.translationFunc,
|
|
1857
|
+
isVgsMode: !!this.vgsService
|
|
1858
|
+
}), !this.vgsService) {
|
|
1859
|
+
const n = this.cardholderSection.getElement().querySelector('input[name="name"]');
|
|
1860
|
+
n && (this.nameFocusHandler = () => this.onFieldFocus("name"), n.addEventListener("focus", this.nameFocusHandler));
|
|
1861
|
+
}
|
|
1862
|
+
this.focusManager.registerField("name", this.cardholderSection), this.formElement.appendChild(this.cardholderSection.getElement());
|
|
1863
|
+
} catch (n) {
|
|
1864
|
+
throw console.error("Error creating cardholder section:", n), n;
|
|
1588
1865
|
}
|
|
1589
1866
|
}
|
|
1590
|
-
createBillingAddressSection(e, t, s,
|
|
1867
|
+
createBillingAddressSection(e, t, s, a) {
|
|
1591
1868
|
try {
|
|
1592
|
-
const
|
|
1593
|
-
if (!
|
|
1594
|
-
(
|
|
1869
|
+
const n = e.layout.billingFields;
|
|
1870
|
+
if (!n || !Object.values(n).some(
|
|
1871
|
+
(d) => d?.enabled
|
|
1595
1872
|
)) return;
|
|
1596
|
-
const
|
|
1873
|
+
const l = {
|
|
1597
1874
|
street: "",
|
|
1598
1875
|
firstName: "",
|
|
1599
1876
|
lastName: "",
|
|
@@ -1602,31 +1879,31 @@ class lt {
|
|
|
1602
1879
|
zipCode: "",
|
|
1603
1880
|
country: ""
|
|
1604
1881
|
};
|
|
1605
|
-
this.billingAddressSection = new
|
|
1882
|
+
this.billingAddressSection = new re({
|
|
1606
1883
|
type: "billing",
|
|
1607
1884
|
title: this.translationFunc("address.billingTitle"),
|
|
1608
1885
|
checkoutProfile: e,
|
|
1609
|
-
fieldsConfig:
|
|
1610
|
-
values: t.billingAddress ??
|
|
1886
|
+
fieldsConfig: n,
|
|
1887
|
+
values: t.billingAddress ?? l,
|
|
1611
1888
|
errors: s.billingAddress ?? {},
|
|
1612
|
-
touched:
|
|
1889
|
+
touched: a.billingAddress ?? {},
|
|
1613
1890
|
onChange: this.onChange,
|
|
1614
1891
|
onBlur: this.onBlur,
|
|
1615
1892
|
translationFunc: this.translationFunc,
|
|
1616
1893
|
locale: this.locale,
|
|
1617
1894
|
grouped: e.layout.grouped
|
|
1618
1895
|
}), this.formElement.appendChild(this.billingAddressSection.getElement());
|
|
1619
|
-
} catch (
|
|
1620
|
-
throw console.error("Error creating billing address section:",
|
|
1896
|
+
} catch (n) {
|
|
1897
|
+
throw console.error("Error creating billing address section:", n), n;
|
|
1621
1898
|
}
|
|
1622
1899
|
}
|
|
1623
|
-
createShippingAddressSection(e, t, s,
|
|
1900
|
+
createShippingAddressSection(e, t, s, a) {
|
|
1624
1901
|
try {
|
|
1625
|
-
const
|
|
1626
|
-
if (!
|
|
1627
|
-
(
|
|
1902
|
+
const n = e.layout.shippingFields;
|
|
1903
|
+
if (!n || !Object.values(n).some(
|
|
1904
|
+
(d) => d?.enabled
|
|
1628
1905
|
)) return;
|
|
1629
|
-
const
|
|
1906
|
+
const l = {
|
|
1630
1907
|
street: "",
|
|
1631
1908
|
firstName: "",
|
|
1632
1909
|
lastName: "",
|
|
@@ -1635,27 +1912,27 @@ class lt {
|
|
|
1635
1912
|
zipCode: "",
|
|
1636
1913
|
country: ""
|
|
1637
1914
|
};
|
|
1638
|
-
this.shippingAddressSection = new
|
|
1915
|
+
this.shippingAddressSection = new re({
|
|
1639
1916
|
type: "shipping",
|
|
1640
1917
|
title: this.translationFunc("address.shippingTitle"),
|
|
1641
1918
|
checkoutProfile: e,
|
|
1642
|
-
fieldsConfig:
|
|
1643
|
-
values: t.shippingAddress ??
|
|
1919
|
+
fieldsConfig: n,
|
|
1920
|
+
values: t.shippingAddress ?? l,
|
|
1644
1921
|
errors: s.shippingAddress ?? {},
|
|
1645
|
-
touched:
|
|
1922
|
+
touched: a.shippingAddress ?? {},
|
|
1646
1923
|
onChange: this.onChange,
|
|
1647
1924
|
onBlur: this.onBlur,
|
|
1648
1925
|
translationFunc: this.translationFunc,
|
|
1649
1926
|
locale: this.locale,
|
|
1650
1927
|
grouped: e.layout.grouped
|
|
1651
1928
|
}), this.formElement.appendChild(this.shippingAddressSection.getElement());
|
|
1652
|
-
} catch (
|
|
1653
|
-
throw console.error("Error creating shipping address section:",
|
|
1929
|
+
} catch (n) {
|
|
1930
|
+
throw console.error("Error creating shipping address section:", n), n;
|
|
1654
1931
|
}
|
|
1655
1932
|
}
|
|
1656
1933
|
createSubmitButton(e, t) {
|
|
1657
1934
|
try {
|
|
1658
|
-
this.submitButton = new
|
|
1935
|
+
this.submitButton = new bt({
|
|
1659
1936
|
disabled: t,
|
|
1660
1937
|
checkoutProfile: e,
|
|
1661
1938
|
translationFunc: this.translationFunc
|
|
@@ -1670,15 +1947,15 @@ class lt {
|
|
|
1670
1947
|
updatePhoneNumberField(e, t, s) {
|
|
1671
1948
|
this.phoneNumberField && (this.phoneNumberField.setValue(e), this.phoneNumberField.setError(t, s));
|
|
1672
1949
|
}
|
|
1673
|
-
updateCardSection(e, t, s,
|
|
1950
|
+
updateCardSection(e, t, s, a, n, r, l, d, c) {
|
|
1674
1951
|
this.cardSection && (this.cardSection.updateCardNumber(
|
|
1675
1952
|
e,
|
|
1676
1953
|
t,
|
|
1677
1954
|
s
|
|
1678
|
-
), this.cardSection.updateCardCvv(
|
|
1679
|
-
d,
|
|
1955
|
+
), this.cardSection.updateCardCvv(a, n, r), this.cardSection.updateCardExpiry(
|
|
1680
1956
|
l,
|
|
1681
|
-
|
|
1957
|
+
d,
|
|
1958
|
+
c
|
|
1682
1959
|
));
|
|
1683
1960
|
}
|
|
1684
1961
|
updateCardholderSection(e, t, s) {
|
|
@@ -1708,6 +1985,70 @@ class lt {
|
|
|
1708
1985
|
hasComponents() {
|
|
1709
1986
|
return !!this.emailField;
|
|
1710
1987
|
}
|
|
1988
|
+
setVgsService(e) {
|
|
1989
|
+
this.vgsService = e;
|
|
1990
|
+
}
|
|
1991
|
+
buildCardSkeleton(e) {
|
|
1992
|
+
const t = e.styles.borderRadius, s = document.createElement("div"), a = document.createElement("div");
|
|
1993
|
+
a.style.marginBottom = "4px";
|
|
1994
|
+
const n = document.createElement("label");
|
|
1995
|
+
n.className = "input-label", n.textContent = this.translationFunc("cardInformation"), n.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, a.appendChild(n), s.appendChild(a);
|
|
1996
|
+
const r = document.createElement("div");
|
|
1997
|
+
r.className = "vgs-card-group", r.style.borderRadius = `${t}px`, r.style.background = "#fff", r.style.display = "flex", r.style.flexDirection = "column", r.style.gap = "8px";
|
|
1998
|
+
const l = document.createElement("div");
|
|
1999
|
+
l.className = "card-number-row", l.style.position = "relative", l.style.height = "38.5px", l.style.overflow = "hidden", l.style.borderRadius = `${t}px`, l.appendChild(this.createSkeletonDiv()), r.appendChild(l);
|
|
2000
|
+
const d = document.createElement("div");
|
|
2001
|
+
d.style.display = "flex", d.style.gap = "8px";
|
|
2002
|
+
const c = document.createElement("div");
|
|
2003
|
+
c.style.position = "relative", c.style.flex = "1", c.style.height = "38.5px", c.style.overflow = "hidden", c.style.borderRadius = `${t}px`, c.appendChild(this.createSkeletonDiv()), d.appendChild(c);
|
|
2004
|
+
const p = document.createElement("div");
|
|
2005
|
+
return p.style.position = "relative", p.style.flex = "1", p.style.height = "38.5px", p.style.overflow = "hidden", p.style.borderRadius = `${t}px`, p.appendChild(this.createSkeletonDiv()), d.appendChild(p), r.appendChild(d), s.appendChild(r), s;
|
|
2006
|
+
}
|
|
2007
|
+
createSkeletonDiv() {
|
|
2008
|
+
const e = document.createElement("div");
|
|
2009
|
+
return e.className = "vgs-field-skeleton", e;
|
|
2010
|
+
}
|
|
2011
|
+
buildCardholderSkeleton(e) {
|
|
2012
|
+
const t = e.styles.borderRadius, s = document.createElement("div"), a = document.createElement("div");
|
|
2013
|
+
a.style.marginBottom = "4px";
|
|
2014
|
+
const n = document.createElement("label");
|
|
2015
|
+
n.className = "input-label", n.textContent = this.translationFunc("cardholderNameLabel"), n.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, a.appendChild(n), s.appendChild(a);
|
|
2016
|
+
const r = document.createElement("div");
|
|
2017
|
+
return r.style.position = "relative", r.style.borderRadius = `${t}px`, r.style.height = "38.5px", r.style.width = "100%", r.style.overflow = "hidden", r.style.background = "#fff", r.appendChild(this.createSkeletonDiv()), s.appendChild(r), s;
|
|
2018
|
+
}
|
|
2019
|
+
async mountVgsFields(e) {
|
|
2020
|
+
if (!this.vgsService || !this.cardSection) return;
|
|
2021
|
+
await this.vgsService.whenReady();
|
|
2022
|
+
const t = this.cardSection.getVgsContainerIds(), s = this.cardholderSection?.getVgsContainerId(), a = await ut(
|
|
2023
|
+
e.styles.fontFamily
|
|
2024
|
+
), n = this.cardSection.buildVgsFieldCss(
|
|
2025
|
+
e,
|
|
2026
|
+
a
|
|
2027
|
+
);
|
|
2028
|
+
this.vgsService.mountCardFields(
|
|
2029
|
+
{
|
|
2030
|
+
cardNumber: t.cardNumber ? `#${t.cardNumber}` : void 0,
|
|
2031
|
+
cardExpiry: t.cardExpiry ? `#${t.cardExpiry}` : void 0,
|
|
2032
|
+
cardCvv: t.cardCvv ? `#${t.cardCvv}` : void 0,
|
|
2033
|
+
cardholderName: s ? `#${s}` : void 0
|
|
2034
|
+
},
|
|
2035
|
+
n,
|
|
2036
|
+
{
|
|
2037
|
+
cardNumber: "1234 5678 9012 3456",
|
|
2038
|
+
cardExpiry: this.translationFunc("cardExpiry"),
|
|
2039
|
+
cardCvv: "CVV",
|
|
2040
|
+
cardholderName: this.translationFunc("cardholderNamePlaceholder")
|
|
2041
|
+
},
|
|
2042
|
+
(r) => this.cardSection?.updateVgsCardBrand(r)
|
|
2043
|
+
), this.vgsService.waitForFieldsReady().then(() => {
|
|
2044
|
+
requestAnimationFrame(() => {
|
|
2045
|
+
this.cardSection?.hideFakePlaceholders(), this.cardholderSection?.hideFakePlaceholder();
|
|
2046
|
+
});
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
handleVgsStateChange(e, t) {
|
|
2050
|
+
this.cardSection?.handleVgsStateChange(e, t), this.cardholderSection?.handleVgsStateChange(e, t);
|
|
2051
|
+
}
|
|
1711
2052
|
cleanup() {
|
|
1712
2053
|
if (this.emailField) {
|
|
1713
2054
|
const e = this.emailField.getElement().querySelector('input[name="email"]');
|
|
@@ -1717,7 +2058,7 @@ class lt {
|
|
|
1717
2058
|
const e = this.phoneNumberField.getElement().querySelector('input[name="phoneNumber"]');
|
|
1718
2059
|
e && this.phoneNumberFocusHandler && e.removeEventListener("focus", this.phoneNumberFocusHandler), this.phoneNumberField.getElement().remove(), this.phoneNumberField = void 0;
|
|
1719
2060
|
}
|
|
1720
|
-
if (this.cardSection) {
|
|
2061
|
+
if (this.cardSectionSkeleton && (this.cardSectionSkeleton.remove(), this.cardSectionSkeleton = void 0), this.cardSection) {
|
|
1721
2062
|
const e = this.cardSection.getElement().querySelector('input[name="cardExpiry"]');
|
|
1722
2063
|
e && this.cardExpiryFocusHandler && e.removeEventListener(
|
|
1723
2064
|
"focus",
|
|
@@ -1731,14 +2072,14 @@ class lt {
|
|
|
1731
2072
|
const s = this.cardSection.getElement().querySelector('input[name="cardCvv"]');
|
|
1732
2073
|
s && this.cardCvvFocusHandler && s.removeEventListener("focus", this.cardCvvFocusHandler), this.cardSection.getElement().remove(), this.cardSection = void 0;
|
|
1733
2074
|
}
|
|
1734
|
-
if (this.cardholderSection) {
|
|
2075
|
+
if (this.cardholderSectionSkeleton && (this.cardholderSectionSkeleton.remove(), this.cardholderSectionSkeleton = void 0), this.cardholderSection) {
|
|
1735
2076
|
const e = this.cardholderSection.getElement().querySelector('input[name="name"]');
|
|
1736
2077
|
e && this.nameFocusHandler && e.removeEventListener("focus", this.nameFocusHandler), this.cardholderSection.getElement().remove(), this.cardholderSection = void 0;
|
|
1737
2078
|
}
|
|
1738
2079
|
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
2080
|
}
|
|
1740
2081
|
}
|
|
1741
|
-
class
|
|
2082
|
+
class St {
|
|
1742
2083
|
formManager;
|
|
1743
2084
|
focusManager;
|
|
1744
2085
|
onFormSubmit;
|
|
@@ -1748,18 +2089,18 @@ class dt {
|
|
|
1748
2089
|
this.formManager = e.formManager, this.focusManager = e.focusManager, this.onFormSubmit = e.onFormSubmit, this.onUIUpdate = e.onUIUpdate;
|
|
1749
2090
|
}
|
|
1750
2091
|
handleChange = (e) => {
|
|
1751
|
-
const t = e.target, { name: s, value:
|
|
1752
|
-
this.formManager.handleChange(
|
|
1753
|
-
const { formData: r, errors:
|
|
1754
|
-
this.focusManager.handleStateUpdate(r,
|
|
2092
|
+
const t = e.target, { name: s, value: a } = t, n = s;
|
|
2093
|
+
this.formManager.handleChange(n, a), this.localTouchedFields.has(n) || (this.localTouchedFields.add(n), this.formManager.handleBlur(n, a));
|
|
2094
|
+
const { formData: r, errors: l, touched: d } = this.formManager.getFormState();
|
|
2095
|
+
this.focusManager.handleStateUpdate(r, l, d);
|
|
1755
2096
|
};
|
|
1756
2097
|
handleBlur = (e) => {
|
|
1757
|
-
const t = e.target, { name: s, value:
|
|
1758
|
-
this.localTouchedFields.add(
|
|
2098
|
+
const t = e.target, { name: s, value: a } = t, n = s;
|
|
2099
|
+
this.localTouchedFields.add(n), this.formManager.handleBlur(n, a), setTimeout(() => {
|
|
1759
2100
|
this.onUIUpdate();
|
|
1760
2101
|
}, 0);
|
|
1761
|
-
const { formData: r, errors:
|
|
1762
|
-
|
|
2102
|
+
const { formData: r, errors: l, touched: d } = this.formManager.getFormState();
|
|
2103
|
+
d[n] || this.focusManager.handleStateUpdate(r, l, d);
|
|
1763
2104
|
};
|
|
1764
2105
|
handleSubmit = async (e) => {
|
|
1765
2106
|
e.preventDefault(), await this.onFormSubmit(e);
|
|
@@ -1779,7 +2120,7 @@ class dt {
|
|
|
1779
2120
|
this.localTouchedFields.clear();
|
|
1780
2121
|
}
|
|
1781
2122
|
}
|
|
1782
|
-
class
|
|
2123
|
+
class Et {
|
|
1783
2124
|
formManager;
|
|
1784
2125
|
checkoutProfile;
|
|
1785
2126
|
formElement;
|
|
@@ -1789,6 +2130,8 @@ class ct {
|
|
|
1789
2130
|
onLoadingChange;
|
|
1790
2131
|
fontCleanup;
|
|
1791
2132
|
isSubmitting = !1;
|
|
2133
|
+
isVgsMode = !1;
|
|
2134
|
+
vgsFieldsState = {};
|
|
1792
2135
|
constructor(e) {
|
|
1793
2136
|
this.formManager = e.formManager, this.checkoutProfile = e.checkoutProfile, this.formElement = e.formElement, this.onUIUpdate = e.onUIUpdate, this.onProfileLoaded = e.onProfileLoaded, this.onError = e.onError, this.onLoadingChange = e.onLoadingChange;
|
|
1794
2137
|
}
|
|
@@ -1801,7 +2144,7 @@ class ct {
|
|
|
1801
2144
|
try {
|
|
1802
2145
|
if (e.checkoutProfile.styles?.fontFamily)
|
|
1803
2146
|
try {
|
|
1804
|
-
const { cleanup: t } =
|
|
2147
|
+
const { cleanup: t } = Me({
|
|
1805
2148
|
fontFamily: e.checkoutProfile.styles.fontFamily
|
|
1806
2149
|
});
|
|
1807
2150
|
this.fontCleanup = t, this.formElement.style.fontFamily = e.checkoutProfile.styles.fontFamily;
|
|
@@ -1818,17 +2161,37 @@ class ct {
|
|
|
1818
2161
|
};
|
|
1819
2162
|
isFormDisabled() {
|
|
1820
2163
|
const e = this.formManager.getFormState(), t = this.checkoutProfile.getState(), s = Object.keys(e.errors).filter(
|
|
1821
|
-
(
|
|
1822
|
-
).length > 0,
|
|
2164
|
+
(y) => y !== "billingAddress" && y !== "shippingAddress"
|
|
2165
|
+
).length > 0, a = e.errors.billingAddress, n = 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 || n || l, p = W(
|
|
1823
2166
|
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
|
-
|
|
2167
|
+
) ? !!(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: g, shippingFields: m } = t.checkoutProfile?.layout ?? {}, u = (y, v) => !y || Object.entries(y).every(
|
|
2168
|
+
([S, M]) => !M?.enabled || !!v?.[S]?.trim()
|
|
2169
|
+
), f = !this.isVgsMode || Object.values(this.vgsFieldsState).every(
|
|
2170
|
+
(y) => y?.isValid === !0
|
|
2171
|
+
), h = this.isVgsMode ? !!e.formData.email && o && f && u(g, e.formData.billingAddress) && u(m, e.formData.shippingAddress) : !!e.formData.email && o && p && !!e.formData.cardNumber && !!e.formData.cardCvv && !!e.formData.cardExpiry && u(g, e.formData.billingAddress) && u(m, e.formData.shippingAddress);
|
|
2172
|
+
return d || !h || this.isSubmitting;
|
|
1828
2173
|
}
|
|
1829
2174
|
setSubmitting(e) {
|
|
1830
2175
|
this.isSubmitting = e;
|
|
1831
2176
|
}
|
|
2177
|
+
setVgsMode(e) {
|
|
2178
|
+
this.isVgsMode = e;
|
|
2179
|
+
}
|
|
2180
|
+
updateVgsState(e) {
|
|
2181
|
+
this.vgsFieldsState = e;
|
|
2182
|
+
}
|
|
2183
|
+
getVgsFieldErrors(e) {
|
|
2184
|
+
const t = {};
|
|
2185
|
+
for (const [s, a] of Object.entries(this.vgsFieldsState)) {
|
|
2186
|
+
if (!a?.isTouched || a.isFocused || a.isValid)
|
|
2187
|
+
continue;
|
|
2188
|
+
const n = a.errors?.[0];
|
|
2189
|
+
if (!n) continue;
|
|
2190
|
+
const r = Ne(s, n.code);
|
|
2191
|
+
r && (t[s] = e(r));
|
|
2192
|
+
}
|
|
2193
|
+
return t;
|
|
2194
|
+
}
|
|
1832
2195
|
getSubmitting() {
|
|
1833
2196
|
return this.isSubmitting;
|
|
1834
2197
|
}
|
|
@@ -1836,18 +2199,18 @@ class ct {
|
|
|
1836
2199
|
this.fontCleanup && (this.fontCleanup(), this.fontCleanup = void 0);
|
|
1837
2200
|
}
|
|
1838
2201
|
}
|
|
1839
|
-
class
|
|
2202
|
+
class Ct extends P {
|
|
1840
2203
|
titleElement;
|
|
1841
2204
|
constructor(e = {}) {
|
|
1842
2205
|
super("div", ["blur-bg"]);
|
|
1843
|
-
const t =
|
|
1844
|
-
this.titleElement = new
|
|
2206
|
+
const t = k.createDiv(["loader"]);
|
|
2207
|
+
this.titleElement = new P("h3", ["title"]), this.titleElement.setText(e.text || ""), this.appendChild(t), this.appendChild(this.titleElement);
|
|
1845
2208
|
}
|
|
1846
2209
|
setText(e) {
|
|
1847
2210
|
return this.titleElement.setText(e), this;
|
|
1848
2211
|
}
|
|
1849
2212
|
}
|
|
1850
|
-
const
|
|
2213
|
+
const oe = {
|
|
1851
2214
|
street: "",
|
|
1852
2215
|
firstName: "",
|
|
1853
2216
|
lastName: "",
|
|
@@ -1855,16 +2218,16 @@ const ne = {
|
|
|
1855
2218
|
city: "",
|
|
1856
2219
|
zipCode: "",
|
|
1857
2220
|
country: ""
|
|
1858
|
-
},
|
|
2221
|
+
}, le = (i, e) => {
|
|
1859
2222
|
const t = {}, s = `${e}.`;
|
|
1860
|
-
return Object.keys(
|
|
1861
|
-
if (
|
|
1862
|
-
const
|
|
1863
|
-
t[
|
|
2223
|
+
return Object.keys(i).forEach((a) => {
|
|
2224
|
+
if (a.startsWith(s)) {
|
|
2225
|
+
const n = a.slice(s.length);
|
|
2226
|
+
t[n] = i[a];
|
|
1864
2227
|
}
|
|
1865
2228
|
}), t;
|
|
1866
2229
|
};
|
|
1867
|
-
class
|
|
2230
|
+
class Ft {
|
|
1868
2231
|
formElement;
|
|
1869
2232
|
componentManager;
|
|
1870
2233
|
onLoadingStateChange;
|
|
@@ -1898,13 +2261,13 @@ class ut {
|
|
|
1898
2261
|
!!(e.errors.name && e.touched.name),
|
|
1899
2262
|
e.errors.name
|
|
1900
2263
|
), this.componentManager.updateBillingAddressSection(
|
|
1901
|
-
e.formData.billingAddress ??
|
|
2264
|
+
e.formData.billingAddress ?? oe,
|
|
1902
2265
|
e.errors.billingAddress ?? {},
|
|
1903
|
-
|
|
2266
|
+
le(e.touched, "billingAddress")
|
|
1904
2267
|
), this.componentManager.updateShippingAddressSection(
|
|
1905
|
-
e.formData.shippingAddress ??
|
|
2268
|
+
e.formData.shippingAddress ?? oe,
|
|
1906
2269
|
e.errors.shippingAddress ?? {},
|
|
1907
|
-
|
|
2270
|
+
le(e.touched, "shippingAddress")
|
|
1908
2271
|
), this.componentManager.updateSubmitButton(t);
|
|
1909
2272
|
}
|
|
1910
2273
|
setLoadingState(e) {
|
|
@@ -1912,10 +2275,10 @@ class ut {
|
|
|
1912
2275
|
this.onLoadingStateChange(e);
|
|
1913
2276
|
return;
|
|
1914
2277
|
}
|
|
1915
|
-
e ? (this.hideSkeleton(), this.formSkeleton = new
|
|
2278
|
+
e ? (this.hideSkeleton(), this.formSkeleton = new he(), this.formElement.appendChild(this.formSkeleton.getElement())) : this.hideSkeleton();
|
|
1916
2279
|
}
|
|
1917
2280
|
showSpinner(e) {
|
|
1918
|
-
this.hideSpinner(), this.spinner = new
|
|
2281
|
+
this.hideSpinner(), this.spinner = new Ct({ text: e }), this.formElement.appendChild(this.spinner.getElement());
|
|
1919
2282
|
}
|
|
1920
2283
|
hideSpinner() {
|
|
1921
2284
|
this.spinner && (this.spinner.getElement().remove(), this.spinner = void 0);
|
|
@@ -1924,7 +2287,7 @@ class ut {
|
|
|
1924
2287
|
this.formSkeleton && (this.formSkeleton.getElement().remove(), this.formSkeleton = void 0);
|
|
1925
2288
|
}
|
|
1926
2289
|
setErrorMessage(e) {
|
|
1927
|
-
this.alert && (this.alert.getElement().remove(), this.alert = void 0), this.alert = new
|
|
2290
|
+
this.alert && (this.alert.getElement().remove(), this.alert = void 0), this.alert = new we({ message: e }), this.formElement.insertBefore(
|
|
1928
2291
|
this.alert.getElement(),
|
|
1929
2292
|
this.formElement.firstChild
|
|
1930
2293
|
);
|
|
@@ -1936,7 +2299,7 @@ class ut {
|
|
|
1936
2299
|
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
2300
|
}
|
|
1938
2301
|
}
|
|
1939
|
-
const
|
|
2302
|
+
const D = (i) => ({
|
|
1940
2303
|
street: "",
|
|
1941
2304
|
firstName: "",
|
|
1942
2305
|
lastName: "",
|
|
@@ -1944,23 +2307,27 @@ const I = (n) => ({
|
|
|
1944
2307
|
city: "",
|
|
1945
2308
|
zipCode: "",
|
|
1946
2309
|
country: "",
|
|
1947
|
-
...
|
|
2310
|
+
...i
|
|
1948
2311
|
});
|
|
1949
|
-
class
|
|
2312
|
+
class Mt extends P {
|
|
1950
2313
|
options;
|
|
1951
|
-
formManager =
|
|
2314
|
+
formManager = lt();
|
|
1952
2315
|
checkoutProfile;
|
|
1953
|
-
translation =
|
|
1954
|
-
focusManager = new
|
|
2316
|
+
translation = Pe();
|
|
2317
|
+
focusManager = new ke();
|
|
1955
2318
|
// Managers
|
|
1956
2319
|
componentManager;
|
|
1957
2320
|
eventHandler;
|
|
1958
2321
|
stateCoordinator;
|
|
1959
2322
|
uiManager;
|
|
2323
|
+
// VGS
|
|
2324
|
+
vgsService;
|
|
2325
|
+
vgsJwt;
|
|
2326
|
+
vgsCardResult;
|
|
1960
2327
|
constructor(e) {
|
|
1961
|
-
super("form", ["form-container"]), this.options = e, this.checkoutProfile =
|
|
2328
|
+
super("form", ["form-container"]), this.options = e, this.vgsJwt = e.vgsJwt, this.vgsJwt && (this.vgsService = new I()), this.checkoutProfile = ot({
|
|
1962
2329
|
appearance: e.appearance
|
|
1963
|
-
}), e.locale && this.translation.setLocale(e.locale), this.componentManager = new
|
|
2330
|
+
}), e.locale && this.translation.setLocale(e.locale), this.componentManager = new vt({
|
|
1964
2331
|
formElement: this.element,
|
|
1965
2332
|
focusManager: this.focusManager,
|
|
1966
2333
|
translationFunc: this.translation.t,
|
|
@@ -1974,12 +2341,14 @@ class mt extends A {
|
|
|
1974
2341
|
paymentId: e.paymentId,
|
|
1975
2342
|
checkoutKey: e.checkoutKey,
|
|
1976
2343
|
checkoutDetails: e.checkoutDetails,
|
|
1977
|
-
environment: e.environment
|
|
1978
|
-
|
|
2344
|
+
environment: e.environment,
|
|
2345
|
+
vgsService: this.vgsService,
|
|
2346
|
+
onVgsStateChange: (t) => this.handleVgsStateChange(t)
|
|
2347
|
+
}), this.uiManager = new Ft({
|
|
1979
2348
|
formElement: this.element,
|
|
1980
2349
|
componentManager: this.componentManager,
|
|
1981
2350
|
onLoadingStateChange: e.onLoadingStateChange
|
|
1982
|
-
}), this.stateCoordinator = new
|
|
2351
|
+
}), this.stateCoordinator = new Et({
|
|
1983
2352
|
formManager: this.formManager,
|
|
1984
2353
|
checkoutProfile: this.checkoutProfile,
|
|
1985
2354
|
componentManager: this.componentManager,
|
|
@@ -1989,7 +2358,7 @@ class mt extends A {
|
|
|
1989
2358
|
onError: (t) => this.uiManager.setErrorMessage(t),
|
|
1990
2359
|
onLoadingChange: (t) => this.uiManager.setLoadingState(t),
|
|
1991
2360
|
getInitialFormData: () => this._getFormStateData().formData
|
|
1992
|
-
}), this.eventHandler = new
|
|
2361
|
+
}), this.vgsService && this.stateCoordinator.setVgsMode(!0), this.eventHandler = new St({
|
|
1993
2362
|
formManager: this.formManager,
|
|
1994
2363
|
focusManager: this.focusManager,
|
|
1995
2364
|
onFormSubmit: async () => this.handleSubmit(),
|
|
@@ -2014,12 +2383,12 @@ class mt extends A {
|
|
|
2014
2383
|
},
|
|
2015
2384
|
...e.initialValues.name && { name: e.initialValues.name },
|
|
2016
2385
|
...e.initialValues.billingAddress && {
|
|
2017
|
-
billingAddress:
|
|
2386
|
+
billingAddress: D(
|
|
2018
2387
|
e.initialValues.billingAddress
|
|
2019
2388
|
)
|
|
2020
2389
|
},
|
|
2021
2390
|
...e.initialValues.shippingAddress && {
|
|
2022
|
-
shippingAddress:
|
|
2391
|
+
shippingAddress: D(
|
|
2023
2392
|
e.initialValues.shippingAddress
|
|
2024
2393
|
)
|
|
2025
2394
|
}
|
|
@@ -2036,10 +2405,10 @@ class mt extends A {
|
|
|
2036
2405
|
cardNumber: "",
|
|
2037
2406
|
cardCvv: "",
|
|
2038
2407
|
...t?.billingAddress && {
|
|
2039
|
-
billingAddress:
|
|
2408
|
+
billingAddress: D(t.billingAddress)
|
|
2040
2409
|
},
|
|
2041
2410
|
...t?.shippingAddress && {
|
|
2042
|
-
shippingAddress:
|
|
2411
|
+
shippingAddress: D(t.shippingAddress)
|
|
2043
2412
|
}
|
|
2044
2413
|
},
|
|
2045
2414
|
errors: e.errors || {},
|
|
@@ -2047,7 +2416,14 @@ class mt extends A {
|
|
|
2047
2416
|
};
|
|
2048
2417
|
}
|
|
2049
2418
|
initializeForm() {
|
|
2050
|
-
this.uiManager.setLoadingState(!0), this.options.errorMsg && this.uiManager.setErrorMessage(this.options.errorMsg)
|
|
2419
|
+
this.uiManager.setLoadingState(!0), this.options.errorMsg && this.uiManager.setErrorMessage(this.options.errorMsg), this.vgsService && this.vgsService.init(this.options.environment).then((e) => {
|
|
2420
|
+
this.vgsService?.createForm(
|
|
2421
|
+
e,
|
|
2422
|
+
(t) => this.handleVgsStateChange(t)
|
|
2423
|
+
);
|
|
2424
|
+
}).catch(() => {
|
|
2425
|
+
this.vgsService = void 0, this.vgsJwt = void 0;
|
|
2426
|
+
});
|
|
2051
2427
|
}
|
|
2052
2428
|
renderFormComponents() {
|
|
2053
2429
|
const e = this.checkoutProfile.getState();
|
|
@@ -2056,11 +2432,11 @@ class mt extends A {
|
|
|
2056
2432
|
return;
|
|
2057
2433
|
}
|
|
2058
2434
|
this.componentManager.hasComponents() && this.componentManager.cleanup(), e.checkoutProfile.layout.phoneNumber?.enabled && this.formManager.getFormState().formData.phoneNumber === void 0 && this.formManager.setFormData({ phoneNumber: "" }), e.checkoutProfile.layout.billingFields && this.formManager.getFormState().formData.billingAddress === void 0 && this.formManager.setFormData({
|
|
2059
|
-
billingAddress:
|
|
2435
|
+
billingAddress: D()
|
|
2060
2436
|
}), e.checkoutProfile.layout.shippingFields && this.formManager.getFormState().formData.shippingAddress === void 0 && this.formManager.setFormData({
|
|
2061
|
-
shippingAddress:
|
|
2437
|
+
shippingAddress: D()
|
|
2062
2438
|
});
|
|
2063
|
-
const { formData: t, errors: s, touched:
|
|
2439
|
+
const { formData: t, errors: s, touched: a } = this._getFormStateData(), n = W(
|
|
2064
2440
|
e.checkoutProfile.layout
|
|
2065
2441
|
);
|
|
2066
2442
|
try {
|
|
@@ -2076,18 +2452,18 @@ class mt extends A {
|
|
|
2076
2452
|
e.checkoutProfile,
|
|
2077
2453
|
t,
|
|
2078
2454
|
s,
|
|
2079
|
-
|
|
2455
|
+
a
|
|
2080
2456
|
);
|
|
2081
2457
|
} catch (r) {
|
|
2082
2458
|
console.error("Failed to create email field:", r);
|
|
2083
2459
|
}
|
|
2084
|
-
if (
|
|
2460
|
+
if (n) {
|
|
2085
2461
|
try {
|
|
2086
2462
|
this.componentManager.createBillingAddressSection(
|
|
2087
2463
|
e.checkoutProfile,
|
|
2088
2464
|
t,
|
|
2089
2465
|
s,
|
|
2090
|
-
|
|
2466
|
+
a
|
|
2091
2467
|
);
|
|
2092
2468
|
} catch (r) {
|
|
2093
2469
|
console.error("Failed to create billing address section:", r);
|
|
@@ -2097,7 +2473,7 @@ class mt extends A {
|
|
|
2097
2473
|
e.checkoutProfile,
|
|
2098
2474
|
t,
|
|
2099
2475
|
s,
|
|
2100
|
-
|
|
2476
|
+
a
|
|
2101
2477
|
);
|
|
2102
2478
|
} catch (r) {
|
|
2103
2479
|
console.error("Failed to create shipping address section:", r);
|
|
@@ -2109,7 +2485,7 @@ class mt extends A {
|
|
|
2109
2485
|
e.checkoutProfile,
|
|
2110
2486
|
t,
|
|
2111
2487
|
s,
|
|
2112
|
-
|
|
2488
|
+
a
|
|
2113
2489
|
);
|
|
2114
2490
|
} catch (r) {
|
|
2115
2491
|
console.error("Failed to create phone number field:", r);
|
|
@@ -2119,22 +2495,25 @@ class mt extends A {
|
|
|
2119
2495
|
e.checkoutProfile,
|
|
2120
2496
|
t,
|
|
2121
2497
|
s,
|
|
2122
|
-
|
|
2498
|
+
a
|
|
2123
2499
|
);
|
|
2124
2500
|
} catch (r) {
|
|
2125
2501
|
console.error("Failed to create card section:", r);
|
|
2126
2502
|
}
|
|
2127
|
-
if (!
|
|
2503
|
+
if (!n)
|
|
2128
2504
|
try {
|
|
2129
2505
|
this.componentManager.createCardholderSection(
|
|
2130
2506
|
e.checkoutProfile,
|
|
2131
2507
|
t,
|
|
2132
2508
|
s,
|
|
2133
|
-
|
|
2509
|
+
a
|
|
2134
2510
|
);
|
|
2135
2511
|
} catch (r) {
|
|
2136
2512
|
console.error("Failed to create cardholder section:", r);
|
|
2137
2513
|
}
|
|
2514
|
+
this.vgsService && this.componentManager.mountVgsFields(e.checkoutProfile).catch((r) => {
|
|
2515
|
+
console.error("Failed to mount VGS fields:", r);
|
|
2516
|
+
});
|
|
2138
2517
|
try {
|
|
2139
2518
|
this.componentManager.createSubmitButton(
|
|
2140
2519
|
e.checkoutProfile,
|
|
@@ -2157,13 +2536,13 @@ class mt extends A {
|
|
|
2157
2536
|
*/
|
|
2158
2537
|
inferCardholderName() {
|
|
2159
2538
|
const e = this.checkoutProfile.getState();
|
|
2160
|
-
if (!e.checkoutProfile ||
|
|
2539
|
+
if (!e.checkoutProfile || !W(
|
|
2161
2540
|
e.checkoutProfile.layout
|
|
2162
2541
|
)) return;
|
|
2163
|
-
const { formData: s } = this._getFormStateData(),
|
|
2164
|
-
if (!
|
|
2165
|
-
const
|
|
2166
|
-
|
|
2542
|
+
const { formData: s } = this._getFormStateData(), a = s.billingAddress ?? s.shippingAddress;
|
|
2543
|
+
if (!a) return;
|
|
2544
|
+
const n = a.firstName?.trim() ?? "", r = a.lastName?.trim() ?? "", l = [n, r].filter(Boolean).join(" ");
|
|
2545
|
+
l && this.formManager.setFormData({ name: l });
|
|
2167
2546
|
}
|
|
2168
2547
|
/**
|
|
2169
2548
|
* Infers address data based on field configuration.
|
|
@@ -2173,18 +2552,46 @@ class mt extends A {
|
|
|
2173
2552
|
inferAddresses() {
|
|
2174
2553
|
const e = this.checkoutProfile.getState();
|
|
2175
2554
|
if (!e.checkoutProfile) return;
|
|
2176
|
-
const { billingFields: t, shippingFields: s } = e.checkoutProfile.layout,
|
|
2177
|
-
!
|
|
2555
|
+
const { billingFields: t, shippingFields: s } = e.checkoutProfile.layout, a = t && Object.values(t).some((l) => l?.enabled), n = s && Object.values(s).some((l) => l?.enabled), { formData: r } = this._getFormStateData();
|
|
2556
|
+
!a && n && r.shippingAddress ? this.formManager.setFormData({
|
|
2178
2557
|
billingAddress: { ...r.shippingAddress }
|
|
2179
|
-
}) : !
|
|
2558
|
+
}) : !n && a && r.billingAddress && this.formManager.setFormData({
|
|
2180
2559
|
shippingAddress: { ...r.billingAddress }
|
|
2181
2560
|
});
|
|
2182
2561
|
}
|
|
2562
|
+
handleVgsStateChange(e) {
|
|
2563
|
+
this.stateCoordinator.updateVgsState(e);
|
|
2564
|
+
const t = this.stateCoordinator.getVgsFieldErrors(
|
|
2565
|
+
this.translation.t
|
|
2566
|
+
);
|
|
2567
|
+
this.componentManager.handleVgsStateChange(e, t), this.updateFormUI();
|
|
2568
|
+
}
|
|
2183
2569
|
async handleSubmit() {
|
|
2184
2570
|
if (!this.stateCoordinator.isFormDisabled())
|
|
2185
2571
|
try {
|
|
2186
|
-
this.stateCoordinator.setSubmitting(!0), this.updateFormUI(), this.options.onLoadingStateChange?.(!0), this.uiManager.showSpinner(this.translation.t("loading")), this.inferCardholderName(), this.inferAddresses(),
|
|
2187
|
-
|
|
2572
|
+
if (this.stateCoordinator.setSubmitting(!0), this.updateFormUI(), this.options.onLoadingStateChange?.(!0), this.uiManager.showSpinner(this.translation.t("loading")), this.inferCardholderName(), this.inferAddresses(), this.vgsService && this.vgsJwt)
|
|
2573
|
+
try {
|
|
2574
|
+
this.vgsCardResult = await this.vgsService.createCard(this.vgsJwt);
|
|
2575
|
+
} catch (t) {
|
|
2576
|
+
console.error("VGS card creation failed:", t), this.handleSubmitError(
|
|
2577
|
+
"Card processing failed. Please check your card details and try again."
|
|
2578
|
+
);
|
|
2579
|
+
return;
|
|
2580
|
+
}
|
|
2581
|
+
const e = this.formManager.getFormState().formData;
|
|
2582
|
+
await this.options.onSubmit({
|
|
2583
|
+
formData: this.vgsCardResult ? {
|
|
2584
|
+
...e,
|
|
2585
|
+
vgsCardData: {
|
|
2586
|
+
cardId: this.vgsCardResult.cardId,
|
|
2587
|
+
expMonth: this.vgsCardResult.expMonth,
|
|
2588
|
+
expYear: this.vgsCardResult.expYear,
|
|
2589
|
+
name: this.vgsCardResult.name,
|
|
2590
|
+
...this.vgsCardResult.updatedValues && {
|
|
2591
|
+
updatedValues: this.vgsCardResult.updatedValues
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
} : e
|
|
2188
2595
|
}), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
2189
2596
|
} catch {
|
|
2190
2597
|
this.handleSubmitError("Payment processing failed. Please try again.");
|
|
@@ -2228,7 +2635,7 @@ class mt extends A {
|
|
|
2228
2635
|
e.locale && this.translation.setLocale(e.locale), e.appearance && this.checkoutProfile.updateProfile(e.appearance), e.locale && (this.componentManager.cleanup(), this.renderFormComponents());
|
|
2229
2636
|
}
|
|
2230
2637
|
destroy() {
|
|
2231
|
-
this.stateCoordinator.cleanup(), this.eventHandler.clearTouchedFields(), this.getElement().removeEventListener(
|
|
2638
|
+
this.vgsService?.destroy(), this.stateCoordinator.cleanup(), this.eventHandler.clearTouchedFields(), this.getElement().removeEventListener(
|
|
2232
2639
|
"submit",
|
|
2233
2640
|
this.eventHandler.handleSubmit
|
|
2234
2641
|
), this.getElement().removeEventListener(
|
|
@@ -2236,26 +2643,33 @@ class mt extends A {
|
|
|
2236
2643
|
this.eventHandler.handleKeyDown
|
|
2237
2644
|
), this.componentManager.cleanup(), this.uiManager.cleanup(), this.getElement().remove();
|
|
2238
2645
|
}
|
|
2239
|
-
associatePayment(e, t, s,
|
|
2240
|
-
this.options.paymentId = e, this.options.checkoutKey = t, this.options.supportedPaymentMethods = s, this.options.checkoutDetails =
|
|
2646
|
+
associatePayment(e, t, s, a, n) {
|
|
2647
|
+
this.options.paymentId = e, this.options.checkoutKey = t, this.options.supportedPaymentMethods = s, this.options.checkoutDetails = a, this.componentManager.setCheckoutDetailsLoaded(!0), n && !this.vgsService && (this.vgsJwt = n, this.vgsService = new I(), this.componentManager.setVgsService(this.vgsService), this.stateCoordinator.setVgsMode(!0), this.vgsService.init(this.options.environment).then((l) => {
|
|
2648
|
+
this.vgsService?.createForm(
|
|
2649
|
+
l,
|
|
2650
|
+
(d) => this.handleVgsStateChange(d)
|
|
2651
|
+
), this.renderFormComponents();
|
|
2652
|
+
}).catch((l) => {
|
|
2653
|
+
console.error("Failed to load VGS Collect:", l), this.vgsService = void 0, this.vgsJwt = void 0, this.renderFormComponents();
|
|
2654
|
+
})), this.componentManager.removePaymentMethods(), this.componentManager.updateSupportedPaymentMethods(
|
|
2241
2655
|
s
|
|
2242
2656
|
), this.componentManager.updatePaymentDetails(
|
|
2243
2657
|
e,
|
|
2244
2658
|
t,
|
|
2245
|
-
|
|
2246
|
-
);
|
|
2247
|
-
const
|
|
2248
|
-
if (
|
|
2249
|
-
const { formData:
|
|
2659
|
+
a
|
|
2660
|
+
), !n && this.checkoutProfile.getState().checkoutProfile && this.renderFormComponents();
|
|
2661
|
+
const r = this.checkoutProfile.getState();
|
|
2662
|
+
if (r.checkoutProfile) {
|
|
2663
|
+
const { formData: l } = this._getFormStateData();
|
|
2250
2664
|
this.componentManager.createPaymentMethods(
|
|
2251
|
-
|
|
2252
|
-
|
|
2665
|
+
r.checkoutProfile,
|
|
2666
|
+
l,
|
|
2253
2667
|
!0
|
|
2254
2668
|
);
|
|
2255
2669
|
}
|
|
2256
2670
|
}
|
|
2257
2671
|
}
|
|
2258
|
-
class
|
|
2672
|
+
class Nt {
|
|
2259
2673
|
container = null;
|
|
2260
2674
|
options;
|
|
2261
2675
|
onSubmit;
|
|
@@ -2279,7 +2693,7 @@ class pt {
|
|
|
2279
2693
|
}
|
|
2280
2694
|
}
|
|
2281
2695
|
renderForm(e) {
|
|
2282
|
-
this.container && (this.form && (this.form.destroy(), this.form = null), this.form = new
|
|
2696
|
+
this.container && (this.form && (this.form.destroy(), this.form = null), this.form = new Mt({
|
|
2283
2697
|
apiKey: this.options.apiKey,
|
|
2284
2698
|
onSubmit: this.onSubmit,
|
|
2285
2699
|
locale: this.options.locale,
|
|
@@ -2291,7 +2705,8 @@ class pt {
|
|
|
2291
2705
|
paymentId: this.options.paymentId,
|
|
2292
2706
|
checkoutKey: this.options.checkoutKey,
|
|
2293
2707
|
checkoutDetails: this.options.checkoutDetails,
|
|
2294
|
-
initialValues: this.options.initialValues
|
|
2708
|
+
initialValues: this.options.initialValues,
|
|
2709
|
+
vgsJwt: this.options.vgsJwt
|
|
2295
2710
|
}));
|
|
2296
2711
|
}
|
|
2297
2712
|
unmount() {
|
|
@@ -2305,16 +2720,17 @@ class pt {
|
|
|
2305
2720
|
clearError() {
|
|
2306
2721
|
this.form && this.form.clearErrorMessage();
|
|
2307
2722
|
}
|
|
2308
|
-
async associatePayment(e, t, s,
|
|
2309
|
-
this.options.paymentId = e, this.options.checkoutKey = t, this.options.checkoutDetails =
|
|
2723
|
+
async associatePayment(e, t, s, a, n) {
|
|
2724
|
+
this.options.paymentId = e, this.options.checkoutKey = t, this.options.checkoutDetails = a, this.options.vgsJwt = n, this.form && this.form.associatePayment(
|
|
2310
2725
|
e,
|
|
2311
2726
|
t,
|
|
2312
2727
|
s,
|
|
2313
|
-
|
|
2728
|
+
a,
|
|
2729
|
+
n
|
|
2314
2730
|
);
|
|
2315
2731
|
}
|
|
2316
2732
|
}
|
|
2317
|
-
class
|
|
2733
|
+
class wt {
|
|
2318
2734
|
state;
|
|
2319
2735
|
listeners = /* @__PURE__ */ new Set();
|
|
2320
2736
|
constructor(e) {
|
|
@@ -2336,8 +2752,8 @@ class ft {
|
|
|
2336
2752
|
this.listeners.forEach((t) => t(e));
|
|
2337
2753
|
}
|
|
2338
2754
|
}
|
|
2339
|
-
const
|
|
2340
|
-
class
|
|
2755
|
+
const Pt = "en";
|
|
2756
|
+
class kt {
|
|
2341
2757
|
config;
|
|
2342
2758
|
paymentState;
|
|
2343
2759
|
apiService;
|
|
@@ -2345,18 +2761,18 @@ class yt {
|
|
|
2345
2761
|
stateManager;
|
|
2346
2762
|
sessionId;
|
|
2347
2763
|
constructor(e) {
|
|
2348
|
-
this.config = this.validateConfig(e), this.paymentState = {}, this.sessionId = crypto.randomUUID(),
|
|
2764
|
+
this.config = this.validateConfig(e), this.paymentState = {}, this.sessionId = crypto.randomUUID(), at({
|
|
2349
2765
|
environment: this.config.environment,
|
|
2350
2766
|
sessionId: this.sessionId
|
|
2351
|
-
}), C
|
|
2767
|
+
}), F(C.CHECKOUT_INITIALIZED, {
|
|
2352
2768
|
environment: this.config.environment
|
|
2353
|
-
}), this.apiService = new
|
|
2769
|
+
}), this.apiService = new Ae(
|
|
2354
2770
|
this.config.apiKey,
|
|
2355
2771
|
this.config.environment
|
|
2356
|
-
), this.stateManager = new
|
|
2772
|
+
), this.stateManager = new wt({
|
|
2357
2773
|
mounted: !1,
|
|
2358
2774
|
form: null
|
|
2359
|
-
}), this.formManager = new
|
|
2775
|
+
}), this.formManager = new Nt(
|
|
2360
2776
|
{
|
|
2361
2777
|
locale: this.config.locale,
|
|
2362
2778
|
apiKey: this.config.apiKey,
|
|
@@ -2378,7 +2794,7 @@ class yt {
|
|
|
2378
2794
|
apiKey: e.apiKey,
|
|
2379
2795
|
returnUrl: e.returnUrl,
|
|
2380
2796
|
environment: e.environment,
|
|
2381
|
-
locale: e.locale ||
|
|
2797
|
+
locale: e.locale || Pt,
|
|
2382
2798
|
disableErrorMessages: e.disableErrorMessages ?? !1,
|
|
2383
2799
|
manualActionHandling: e.manualActionHandling ?? !1,
|
|
2384
2800
|
appearance: e.appearance,
|
|
@@ -2399,7 +2815,7 @@ class yt {
|
|
|
2399
2815
|
return t.appendChild(s), this.stateManager.updateState({
|
|
2400
2816
|
form: s,
|
|
2401
2817
|
mounted: !0
|
|
2402
|
-
}), this.formManager.mount(s), C
|
|
2818
|
+
}), this.formManager.mount(s), F(C.CHECKOUT_MOUNTED, {
|
|
2403
2819
|
container_id: e
|
|
2404
2820
|
}), this;
|
|
2405
2821
|
}
|
|
@@ -2411,7 +2827,7 @@ class yt {
|
|
|
2411
2827
|
t && t.remove(), this.stateManager.updateState({
|
|
2412
2828
|
form: null,
|
|
2413
2829
|
mounted: !1
|
|
2414
|
-
}), C
|
|
2830
|
+
}), F(C.CHECKOUT_UNMOUNTED);
|
|
2415
2831
|
});
|
|
2416
2832
|
}
|
|
2417
2833
|
async handleSubmit({
|
|
@@ -2423,21 +2839,21 @@ class yt {
|
|
|
2423
2839
|
"Payment must be associated before submitting. Call associatePayment() first."
|
|
2424
2840
|
);
|
|
2425
2841
|
const s = this.getPaymentMethod(e, t);
|
|
2426
|
-
C
|
|
2842
|
+
F(C.PAYMENT_SUBMIT_STARTED, {
|
|
2427
2843
|
payment_id: this.paymentState.paymentId,
|
|
2428
2844
|
payment_method: s
|
|
2429
2845
|
});
|
|
2430
|
-
const
|
|
2846
|
+
const a = performance.now();
|
|
2431
2847
|
try {
|
|
2432
|
-
const
|
|
2848
|
+
const n = await this.apiService.authorizePayment({
|
|
2433
2849
|
checkoutKey: this.paymentState.checkoutKey,
|
|
2434
2850
|
formData: e || null,
|
|
2435
2851
|
paymentId: this.paymentState.paymentId,
|
|
2436
2852
|
returnUrl: this.config.returnUrl,
|
|
2437
2853
|
applePayData: t
|
|
2438
|
-
}), r = performance.now() -
|
|
2439
|
-
|
|
2440
|
-
|
|
2854
|
+
}), r = performance.now() - a;
|
|
2855
|
+
ne(
|
|
2856
|
+
X.PAYMENT_AUTHORIZATION_TIME,
|
|
2441
2857
|
r,
|
|
2442
2858
|
"ms",
|
|
2443
2859
|
{
|
|
@@ -2445,14 +2861,14 @@ class yt {
|
|
|
2445
2861
|
payment_method: s,
|
|
2446
2862
|
status: "success"
|
|
2447
2863
|
}
|
|
2448
|
-
), C
|
|
2864
|
+
), F(C.PAYMENT_SUBMIT_SUCCESS, {
|
|
2449
2865
|
payment_id: this.paymentState.paymentId,
|
|
2450
2866
|
payment_method: s
|
|
2451
|
-
}), this.handlePaymentResponse(
|
|
2452
|
-
} catch (
|
|
2453
|
-
const r = performance.now() -
|
|
2454
|
-
|
|
2455
|
-
|
|
2867
|
+
}), this.handlePaymentResponse(n);
|
|
2868
|
+
} catch (n) {
|
|
2869
|
+
const r = performance.now() - a;
|
|
2870
|
+
ne(
|
|
2871
|
+
X.PAYMENT_AUTHORIZATION_TIME,
|
|
2456
2872
|
r,
|
|
2457
2873
|
"ms",
|
|
2458
2874
|
{
|
|
@@ -2460,25 +2876,25 @@ class yt {
|
|
|
2460
2876
|
payment_method: s,
|
|
2461
2877
|
status: "failed"
|
|
2462
2878
|
}
|
|
2463
|
-
), C
|
|
2879
|
+
), F(C.PAYMENT_SUBMIT_FAILED, {
|
|
2464
2880
|
payment_id: this.paymentState.paymentId,
|
|
2465
2881
|
payment_method: s,
|
|
2466
|
-
error_message:
|
|
2467
|
-
}), this.handleAuthorizationError(
|
|
2882
|
+
error_message: n.details?.message ?? "Unknown error"
|
|
2883
|
+
}), this.handleAuthorizationError(n);
|
|
2468
2884
|
}
|
|
2469
2885
|
}
|
|
2470
2886
|
handlePaymentResponse(e) {
|
|
2471
|
-
if (e.latestTransaction.status === "authorized" && (C
|
|
2887
|
+
if (e.latestTransaction.status === "authorized" && (F(C.PAYMENT_AUTHORIZED, {
|
|
2472
2888
|
payment_id: this.paymentState.paymentId ?? "",
|
|
2473
2889
|
status: e.latestTransaction.status
|
|
2474
2890
|
}), this.config.callbacks.onPaymentSucceeded?.(
|
|
2475
2891
|
e.latestTransaction.status
|
|
2476
|
-
)), e.latestTransaction.status === "failed" && (C
|
|
2892
|
+
)), e.latestTransaction.status === "failed" && (F(C.PAYMENT_FAILED, {
|
|
2477
2893
|
payment_id: this.paymentState.paymentId ?? "",
|
|
2478
2894
|
status: e.latestTransaction.status
|
|
2479
2895
|
}), this.config.callbacks.onPaymentFailed?.(e.latestTransaction.status)), e.status === "requires_action") {
|
|
2480
2896
|
const { redirectUrl: t } = e.action;
|
|
2481
|
-
C
|
|
2897
|
+
F(C.PAYMENT_ACTION_REQUIRED, {
|
|
2482
2898
|
payment_id: this.paymentState.paymentId ?? "",
|
|
2483
2899
|
status: e.status
|
|
2484
2900
|
}), this.config.manualActionHandling ? this.config.callbacks.onActionRequired?.(t) : globalThis.location.href = t;
|
|
@@ -2518,7 +2934,7 @@ class yt {
|
|
|
2518
2934
|
throw new Error("paymentId and checkoutKey are required");
|
|
2519
2935
|
this.paymentState.paymentId = e, this.paymentState.checkoutKey = t;
|
|
2520
2936
|
try {
|
|
2521
|
-
const s = await
|
|
2937
|
+
const s = await De({
|
|
2522
2938
|
id: e,
|
|
2523
2939
|
checkoutKey: t,
|
|
2524
2940
|
environment: this.config.environment
|
|
@@ -2528,7 +2944,7 @@ class yt {
|
|
|
2528
2944
|
"Invalid response: supportedPaymentMethods must be an array"
|
|
2529
2945
|
);
|
|
2530
2946
|
if (!s.supportedPaymentMethods.every(
|
|
2531
|
-
(
|
|
2947
|
+
(n) => typeof n == "string"
|
|
2532
2948
|
))
|
|
2533
2949
|
throw new Error(
|
|
2534
2950
|
"Invalid response: all supportedPaymentMethods must be strings"
|
|
@@ -2538,44 +2954,45 @@ class yt {
|
|
|
2538
2954
|
currency: s.currency,
|
|
2539
2955
|
countryCode: s.countryCode
|
|
2540
2956
|
};
|
|
2541
|
-
const
|
|
2542
|
-
(
|
|
2957
|
+
const a = s.supportedPaymentMethods.reduce(
|
|
2958
|
+
(n, r) => (n[r] = !0, n),
|
|
2543
2959
|
{}
|
|
2544
2960
|
);
|
|
2545
2961
|
await this.formManager.associatePayment(
|
|
2546
2962
|
e,
|
|
2547
2963
|
t,
|
|
2548
|
-
|
|
2549
|
-
this.paymentState.checkoutDetails
|
|
2550
|
-
|
|
2964
|
+
a,
|
|
2965
|
+
this.paymentState.checkoutDetails,
|
|
2966
|
+
s.vgsJwt
|
|
2967
|
+
), F(C.PAYMENT_ASSOCIATED, {
|
|
2551
2968
|
payment_id: e,
|
|
2552
2969
|
currency: s.currency,
|
|
2553
2970
|
country_code: s.countryCode
|
|
2554
2971
|
});
|
|
2555
2972
|
} catch (s) {
|
|
2556
|
-
throw C
|
|
2973
|
+
throw F(C.PAYMENT_ASSOCIATION_FAILED, {
|
|
2557
2974
|
payment_id: e,
|
|
2558
2975
|
error_message: s instanceof Error ? s.message : "Unknown error"
|
|
2559
|
-
}),
|
|
2976
|
+
}), rt(
|
|
2560
2977
|
s instanceof Error ? s : new Error("Failed to associate payment"),
|
|
2561
2978
|
{ payment_id: e }
|
|
2562
2979
|
), s;
|
|
2563
2980
|
}
|
|
2564
2981
|
}
|
|
2565
2982
|
}
|
|
2566
|
-
typeof globalThis < "u" && (globalThis.OdusCheckout =
|
|
2983
|
+
typeof globalThis < "u" && (globalThis.OdusCheckout = kt);
|
|
2567
2984
|
export {
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2985
|
+
kt as OdusCheckout,
|
|
2986
|
+
Tt as deLocale,
|
|
2987
|
+
Lt as enLocale,
|
|
2988
|
+
Vt as esLocale,
|
|
2989
|
+
_t as frLocale,
|
|
2990
|
+
Bt as itLocale,
|
|
2991
|
+
Ot as plLocale,
|
|
2992
|
+
Rt as ptLocale,
|
|
2993
|
+
rt as pushError,
|
|
2994
|
+
F as pushEvent,
|
|
2995
|
+
Dt as pushLog,
|
|
2996
|
+
ne as pushMeasurement,
|
|
2997
|
+
Ut as trLocale
|
|
2581
2998
|
};
|