@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.
@@ -1,6 +1,6 @@
1
- import { c as ie, a as ce, f as V, d as he, C as A, I as re, g as ue, S as R, b as Z, e as w, A as me, P as pe, E as fe, l as ge, h as ye, i as be, j as Ee, k as Se, F as Fe, m as ve, n as Ce } from "./shared.js";
2
- import { o as vt, p as Ct, q as Mt, r as Nt, s as Pt, t as At, u as wt, v as kt } from "./shared.js";
3
- const v = {
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
- }, G = {
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
- }, Me = /^\s*at (?:(.+?) ?\()?((?:file|https?|chrome-extension|webpack-internal):\/\/.+?):(\d+):(\d+)\)?\s*$/, Ne = /^([^@]+)@((?:file|https?|chrome-extension|webpack-internal):\/\/[^\s:]+):(\d+):(\d+)$/, Pe = /^(?:([^@]+)@)?((?:file|https?):\/\/[^\s:]+):(\d+):(\d+)$/, q = (n) => {
24
- if (!n)
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 = n.split(`
26
+ const e = [], t = i.split(`
27
27
  `);
28
28
  for (const s of t) {
29
- const i = s.trim();
30
- if (!i)
29
+ const a = s.trim();
30
+ if (!a)
31
31
  continue;
32
- let a = Me.exec(i);
33
- if (a) {
32
+ let n = Ie.exec(a);
33
+ if (n) {
34
34
  e.push({
35
- function: a[1] || "(anonymous)",
36
- filename: a[2],
37
- lineno: parseInt(a[3], 10),
38
- colno: parseInt(a[4], 10)
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
- a = Ne.exec(i) ?? Pe.exec(i), a && e.push({
43
- function: a[1] || "(anonymous)",
44
- filename: a[2],
45
- lineno: parseInt(a[3], 10),
46
- colno: parseInt(a[4], 10)
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
- }, Ae = "@odus/telemetry", we = "0.0.1";
51
- let O, x, Y;
52
- const ke = () => {
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 n = navigator.userAgent;
55
+ const i = navigator.userAgent;
56
56
  let e, t, s;
57
- n.includes("Firefox/") ? (e = "Firefox", t = n.match(/Firefox\/([\d.]+)/)?.[1]) : n.includes("Edg/") ? (e = "Edge", t = n.match(/Edg\/([\d.]+)/)?.[1]) : n.includes("Chrome/") ? (e = "Chrome", t = n.match(/Chrome\/([\d.]+)/)?.[1]) : n.includes("Safari/") && (e = "Safari", t = n.match(/Version\/([\d.]+)/)?.[1]), n.includes("Windows") ? s = "Windows" : n.includes("Mac OS") ? s = "macOS" : n.includes("Linux") ? s = "Linux" : n.includes("Android") ? s = "Android" : (n.includes("iPhone") || n.includes("iPad")) && (s = "iOS");
58
- const i = /Mobi|Android|iPhone|iPad/i.test(n) || void 0;
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: i ?? !1,
63
+ mobile: a ?? !1,
64
64
  language: navigator.language,
65
65
  viewportWidth: String(window.innerWidth),
66
66
  viewportHeight: String(window.innerHeight),
67
- userAgent: n
67
+ userAgent: i
68
68
  };
69
- }, Ie = () => typeof window > "u" ? {} : { url: window.location.href }, De = (n) => {
70
- O = void 0, Y = void 0, x = n.sessionTracking?.session ? { id: n.sessionTracking.session.id } : void 0;
71
- }, Te = (n) => {
72
- O = n;
73
- }, Le = () => {
74
- O = void 0;
75
- }, _e = (n) => {
76
- x = n;
77
- }, Be = (n) => {
78
- Y = n;
79
- }, Oe = () => x?.id, xe = (n) => ({
80
- sdk: { name: Ae, version: we },
81
- app: n.app,
82
- user: O,
83
- session: x,
84
- page: Ie(),
85
- browser: ke(),
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
- }), Ue = 30, Ve = 250, Re = 6e4;
88
- let k = [], P = null, W = 0, T = null, L = null;
89
- const He = (n) => {
90
- if (P)
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 = n.batching?.sendTimeout ?? Ve;
93
- P = setTimeout(() => {
94
- U(n);
92
+ const e = i.batching?.sendTimeout ?? qe;
93
+ w = setTimeout(() => {
94
+ R(i);
95
95
  }, e);
96
- }, ze = (n, e) => {
96
+ }, Ge = (i, e) => {
97
97
  const t = {
98
- meta: xe(e)
98
+ meta: je(e)
99
99
  };
100
- for (const s of n)
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
- }, je = (n, e, t = !1) => {
117
- const s = JSON.stringify(n), i = Oe(), a = {
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 (i && (a["x-faro-session-id"] = i), t && typeof navigator < "u" && navigator.sendBeacon) {
121
- const d = new Blob([s], { type: "application/json" });
122
- navigator.sendBeacon(e, d);
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 < Re;
125
+ const r = s.length < We;
126
126
  fetch(e, {
127
127
  method: "POST",
128
- headers: a,
128
+ headers: n,
129
129
  body: s,
130
130
  keepalive: r
131
- }).then((d) => {
132
- if (d.status === 429) {
133
- const l = d.headers.get("Retry-After"), u = l ? parseInt(l, 10) * 1e3 : 3e4;
134
- W = Date.now() + u;
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
- }, U = (n, e = !1) => {
139
- if (P && (clearTimeout(P), P = null), k.length === 0)
138
+ }, R = (i, e = !1) => {
139
+ if (w && (clearTimeout(w), w = null), A.length === 0)
140
140
  return;
141
- if (Date.now() < W) {
142
- k = [];
141
+ if (Date.now() < G) {
142
+ A = [];
143
143
  return;
144
144
  }
145
- const t = k;
146
- k = [];
145
+ const t = A;
146
+ A = [];
147
147
  try {
148
- let s = ze(t, n);
149
- if (n.beforeSend) {
150
- const i = n.beforeSend(s);
151
- if (!i)
148
+ let s = Ge(t, i);
149
+ if (i.beforeSend) {
150
+ const a = i.beforeSend(s);
151
+ if (!a)
152
152
  return;
153
- s = i;
153
+ s = a;
154
154
  }
155
- je(s, n.url, e);
155
+ Ze(s, i.url, e);
156
156
  } catch {
157
157
  }
158
- }, M = (n, e) => {
159
- k.push(n);
160
- const t = e.batching?.itemLimit ?? Ue;
161
- if (k.length >= t) {
162
- U(e);
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
- He(e);
166
- }, Ke = (n) => {
167
- if (k = [], W = 0, P && (clearTimeout(P), P = null), typeof document > "u")
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 = () => U(n, !0);
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
- }, X = () => (/* @__PURE__ */ new Date()).toISOString();
175
- let Q = null, J = null;
176
- const qe = (n) => {
177
- typeof window > "u" || (Q = (e) => {
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
- M({
179
+ N({
180
180
  type: "exception",
181
181
  payload: {
182
182
  type: t.name,
183
183
  value: t.message,
184
- timestamp: X(),
184
+ timestamp: Q(),
185
185
  stacktrace: t.stack ? { frames: q(t.stack) } : void 0
186
186
  }
187
- }, n);
188
- }, J = (e) => {
187
+ }, i);
188
+ }, te = (e) => {
189
189
  const t = e.reason, s = t instanceof Error ? t : new Error(String(t));
190
- M({
190
+ N({
191
191
  type: "exception",
192
192
  payload: {
193
193
  type: s.name,
194
194
  value: s.message,
195
- timestamp: X(),
195
+ timestamp: Q(),
196
196
  stacktrace: s.stack ? { frames: q(s.stack) } : void 0,
197
197
  context: { source: "unhandledrejection" }
198
198
  }
199
- }, n);
200
- }, window.addEventListener("error", Q), window.addEventListener("unhandledrejection", J));
201
- }, ee = "odus_telemetry_session_id", H = () => {
202
- const n = new Uint8Array(16);
203
- return crypto.getRandomValues(n), Array.from(n, (e) => e.toString(16).padStart(2, "0")).join("");
204
- }, $e = (n) => {
205
- if (n)
206
- return n;
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 H();
208
+ return z();
209
209
  try {
210
- const e = sessionStorage.getItem(ee);
210
+ const e = sessionStorage.getItem(se);
211
211
  if (e)
212
212
  return e;
213
- const t = H();
214
- return sessionStorage.setItem(ee, t), t;
213
+ const t = z();
214
+ return sessionStorage.setItem(se, t), t;
215
215
  } catch {
216
- return H();
216
+ return z();
217
217
  }
218
- }, Ye = (n) => {
219
- if (!n.sessionTracking?.enabled)
218
+ }, et = (i) => {
219
+ if (!i.sessionTracking?.enabled)
220
220
  return;
221
- const e = $e(n.sessionTracking.session?.id);
222
- _e({ id: e });
223
- }, z = () => (/* @__PURE__ */ new Date()).toISOString(), j = (n, e) => {
224
- if (typeof PerformanceObserver > "u" || !PerformanceObserver.supportedEntryTypes?.includes(n))
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 i of s.getEntries())
228
- e(i);
229
- }).observe({ type: n, buffered: !0 });
230
- }, We = (n) => {
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
- M({
234
+ N({
235
235
  type: "measurement",
236
236
  payload: {
237
237
  type: "web-vitals",
238
238
  values: { lcp: t.startTime },
239
- timestamp: z()
239
+ timestamp: $()
240
240
  }
241
- }, n);
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, M({
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: z()
251
+ timestamp: $()
252
252
  }
253
- }, n));
253
+ }, i));
254
254
  }), j("event", (t) => {
255
255
  const s = t;
256
- s.duration > 0 && M({
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: z()
261
+ timestamp: $()
262
262
  }
263
- }, n);
263
+ }, i);
264
264
  });
265
- }, B = {
265
+ }, _ = {
266
266
  INFO: "info",
267
267
  WARN: "warn",
268
268
  ERROR: "error"
269
- }, _ = () => (/* @__PURE__ */ new Date()).toISOString(), Ze = (n) => {
270
- De(n), Ke(n);
271
- const e = n.instrumentations ?? {
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 && Ye(n), e.errors !== !1 && qe(n), e.webVitals !== !1 && We(n), {
276
+ return e.session !== !1 && et(i), e.errors !== !1 && Xe(i), e.webVitals !== !1 && tt(i), {
277
277
  pushError(t, s) {
278
- M({
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
- }, n);
287
+ }, i);
288
288
  },
289
289
  pushEvent(t, s) {
290
- M({
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
- }, n);
297
+ }, i);
298
298
  },
299
299
  pushMeasurement(t) {
300
- M({
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
- }, n);
308
+ }, i);
309
309
  },
310
310
  pushLog(t, s) {
311
- M({
311
+ N({
312
312
  type: "log",
313
313
  payload: {
314
314
  message: t.join(" "),
315
- level: s?.level ?? B.INFO,
316
- timestamp: _(),
315
+ level: s?.level ?? _.INFO,
316
+ timestamp: V(),
317
317
  context: s?.context
318
318
  }
319
- }, n);
319
+ }, i);
320
320
  },
321
321
  setUser(t) {
322
- Te(t);
322
+ Re(t);
323
323
  },
324
324
  resetUser() {
325
- Le();
325
+ Ue();
326
326
  },
327
327
  setView(t) {
328
- Be(t);
328
+ ze(t);
329
329
  },
330
330
  flush() {
331
- U(n);
331
+ R(i);
332
332
  }
333
333
  };
334
- }, Ge = (n) => n === "test" ? "https://sandbox-analytics.odus.com/collect" : "https://analytics.odus.com/collect", Xe = () => {
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 n = window.location.hostname;
338
- return n === "localhost" || n === "127.0.0.1" || n === "0.0.0.0" || n === "::1" || n === "[::1]" || n.endsWith(".localhost");
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 F = null;
341
- const Qe = (n) => {
342
- if (F)
343
- return F;
344
- if (Xe())
340
+ let E = null;
341
+ const at = (i) => {
342
+ if (E)
343
+ return E;
344
+ if (it())
345
345
  return null;
346
- const e = Ge(n.environment);
347
- return F = Ze({
346
+ const e = nt(i.environment);
347
+ return E = st({
348
348
  url: e,
349
349
  app: {
350
350
  name: "odus-checkout",
351
- environment: n.environment === "test" ? "sandbox" : "production"
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: n.sessionId
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((a) => {
372
- s.searchParams.has(a) && s.searchParams.set(a, "[REDACTED]");
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
- }), F;
379
- }, Je = (n, e) => {
380
- F && F.pushError(n, { context: e });
381
- }, C = (n, e) => {
382
- F && F.pushEvent(n, e);
383
- }, te = (n, e, t, s) => {
384
- F && F.pushMeasurement({
385
- type: n,
386
- values: { [n]: e },
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
- }, Et = (n, e = "info", t) => {
393
- if (!F) return;
392
+ }, Dt = (i, e = "info", t) => {
393
+ if (!E) return;
394
394
  const s = {
395
- info: B.INFO,
396
- warn: B.WARN,
397
- error: B.ERROR
395
+ info: _.INFO,
396
+ warn: _.WARN,
397
+ error: _.ERROR
398
398
  };
399
- F.pushLog([n], {
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
- function K(n) {
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: n.additionalPaymentMethods || {},
408
- styles: n.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: n.layout?.grouped,
419
- actionButton: n.layout?.actionButton || {
610
+ grouped: i.layout?.grouped,
611
+ actionButton: i.layout?.actionButton || {
420
612
  translationKey: null
421
613
  },
422
- phoneNumber: n.layout?.phoneNumber ? {
423
- enabled: n.layout.phoneNumber.enabled,
424
- label: n.layout.phoneNumber.label,
425
- defaultCountry: n.layout.phoneNumber.defaultCountry,
426
- allowedCountries: n.layout.phoneNumber.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: n.layout?.billingFields?.street?.enabled ?? !1,
431
- label: n.layout?.billingFields?.street?.label
622
+ enabled: i.layout?.billingFields?.street?.enabled ?? !1,
623
+ label: i.layout?.billingFields?.street?.label
432
624
  },
433
625
  city: {
434
- enabled: n.layout?.billingFields?.city?.enabled ?? !1,
435
- label: n.layout?.billingFields?.city?.label
626
+ enabled: i.layout?.billingFields?.city?.enabled ?? !1,
627
+ label: i.layout?.billingFields?.city?.label
436
628
  },
437
629
  state: {
438
- enabled: n.layout?.billingFields?.state?.enabled ?? !1,
439
- label: n.layout?.billingFields?.state?.label,
440
- options: n.layout?.billingFields?.state?.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: n.layout?.billingFields?.zipCode?.enabled ?? !1,
444
- label: n.layout?.billingFields?.zipCode?.label
635
+ enabled: i.layout?.billingFields?.zipCode?.enabled ?? !1,
636
+ label: i.layout?.billingFields?.zipCode?.label
445
637
  },
446
638
  firstName: {
447
- enabled: n.layout?.billingFields?.firstName?.enabled ?? !1,
448
- label: n.layout?.billingFields?.firstName?.label
639
+ enabled: i.layout?.billingFields?.firstName?.enabled ?? !1,
640
+ label: i.layout?.billingFields?.firstName?.label
449
641
  },
450
642
  lastName: {
451
- enabled: n.layout?.billingFields?.lastName?.enabled ?? !1,
452
- label: n.layout?.billingFields?.lastName?.label
643
+ enabled: i.layout?.billingFields?.lastName?.enabled ?? !1,
644
+ label: i.layout?.billingFields?.lastName?.label
453
645
  },
454
646
  country: {
455
- enabled: n.layout?.billingFields?.country?.enabled ?? !1,
456
- label: n.layout?.billingFields?.country?.label,
457
- options: n.layout?.billingFields?.country?.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: n.layout?.shippingFields ? {
652
+ shippingFields: i.layout?.shippingFields ? {
461
653
  street: {
462
- enabled: n.layout.shippingFields.street?.enabled ?? !1,
463
- label: n.layout.shippingFields.street?.label
654
+ enabled: i.layout.shippingFields.street?.enabled ?? !1,
655
+ label: i.layout.shippingFields.street?.label
464
656
  },
465
657
  firstName: {
466
- enabled: n.layout.shippingFields.firstName?.enabled ?? !1,
467
- label: n.layout.shippingFields.firstName?.label
658
+ enabled: i.layout.shippingFields.firstName?.enabled ?? !1,
659
+ label: i.layout.shippingFields.firstName?.label
468
660
  },
469
661
  lastName: {
470
- enabled: n.layout.shippingFields.lastName?.enabled ?? !1,
471
- label: n.layout.shippingFields.lastName?.label
662
+ enabled: i.layout.shippingFields.lastName?.enabled ?? !1,
663
+ label: i.layout.shippingFields.lastName?.label
472
664
  },
473
665
  city: {
474
- enabled: n.layout.shippingFields.city?.enabled ?? !1,
475
- label: n.layout.shippingFields.city?.label
666
+ enabled: i.layout.shippingFields.city?.enabled ?? !1,
667
+ label: i.layout.shippingFields.city?.label
476
668
  },
477
669
  state: {
478
- enabled: n.layout.shippingFields.state?.enabled ?? !1,
479
- label: n.layout.shippingFields.state?.label,
480
- options: n.layout.shippingFields.state?.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: n.layout.shippingFields.zipCode?.enabled ?? !1,
484
- label: n.layout.shippingFields.zipCode?.label
675
+ enabled: i.layout.shippingFields.zipCode?.enabled ?? !1,
676
+ label: i.layout.shippingFields.zipCode?.label
485
677
  },
486
678
  country: {
487
- enabled: n.layout.shippingFields.country?.enabled ?? !1,
488
- label: n.layout.shippingFields.country?.label,
489
- options: n.layout.shippingFields.country?.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: n.additionalPaymentMethods ? {
495
- applePay: n.additionalPaymentMethods.applePay ? {
496
- displayName: n.additionalPaymentMethods.applePay.displayName,
497
- requiredBillingContactFields: n.additionalPaymentMethods.applePay.requiredBillingContactFields,
498
- requiredShippingContactFields: n.additionalPaymentMethods.applePay.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 et({
505
- appearance: n
696
+ function ot({
697
+ appearance: i
506
698
  }) {
507
- const e = ie({
699
+ const e = de({
508
700
  checkoutProfile: void 0,
509
701
  isLoading: !0,
510
702
  error: null
511
703
  });
512
- if (n) {
513
- const s = K(n);
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: (i) => {
524
- const a = K(i);
715
+ updateProfile: (a) => {
716
+ const n = K(a);
525
717
  e.setState({
526
- checkoutProfile: a,
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 i = K(s);
765
+ const a = K(s);
574
766
  e.setState({
575
- checkoutProfile: i,
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 tt = () => {
585
- const n = ce(), e = ie({
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, f, m, h) => {
794
+ }), t = (o, g, m, u) => {
603
795
  if (o === "cardCvv")
604
- return n.cardCvv(f, m);
605
- if (o === "phoneNumber" && h)
606
- return n.phoneNumber(f, h);
607
- const p = n[o];
608
- return p?.(f);
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 f = {};
611
- return Object.keys(o).forEach((h) => {
612
- const p = o[h];
613
- if (p === void 0) return;
614
- let c;
615
- h === "cardCvv" ? c = t(h, p, o.cardNumber) : h === "phoneNumber" ? c = t(
616
- h,
617
- p,
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
- ) : c = t(h, p), c && (f[h] = c);
812
+ ) : h = t(u, f), h && (g[u] = h);
621
813
  }), [
622
814
  "billingAddress",
623
815
  "shippingAddress"
624
- ].forEach((h) => {
625
- const p = o[h];
626
- if (p && typeof p == "object") {
627
- const c = {};
628
- Object.keys(p).forEach(
629
- (b) => {
630
- const g = p[b];
631
- if (g === void 0) return;
632
- const S = n[b];
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 N = S(g);
635
- N && (c[b] = N);
826
+ const M = S(v);
827
+ M && (h[y] = M);
636
828
  }
637
829
  }
638
- ), Object.keys(c).length > 0 && (f[h] = c);
830
+ ), Object.keys(h).length > 0 && (g[u] = h);
639
831
  }
640
- }), f;
641
- }, i = (o) => {
642
- const f = s(o);
643
- return Object.keys(f).length === 0;
644
- }, a = "billingAddress.", r = "shippingAddress.", d = (o) => o.startsWith(a) ? {
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(a.length)
838
+ field: o.slice(n.length)
647
839
  } : o.startsWith(r) ? {
648
840
  parent: "shippingAddress",
649
841
  field: o.slice(r.length)
650
- } : null, l = (o, f, m, h) => {
651
- const p = { ...o };
652
- if (h)
653
- p[f] = {
654
- ...p[f],
655
- [m]: h
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 c = {
659
- ...p[f]
850
+ const h = {
851
+ ...f[g]
660
852
  };
661
- delete c[m], Object.keys(c).length === 0 ? delete p[f] : p[f] = c;
853
+ delete h[m], Object.keys(h).length === 0 ? delete f[g] : f[g] = h;
662
854
  }
663
- return p;
664
- }, u = (o, f) => {
855
+ return f;
856
+ }, c = (o, g) => {
665
857
  const m = e.getState();
666
- let h = f;
667
- const p = d(o);
668
- if (!p && o in V)
858
+ let u = g;
859
+ const f = l(o);
860
+ if (!f && o in U)
669
861
  if (o === "cardCvv") {
670
- const S = he(m.formData.cardNumber) === "amex" ? 4 : 3;
671
- h = V.cardCvv(f, S);
862
+ const S = fe(m.formData.cardNumber) === "amex" ? 4 : 3;
863
+ u = U.cardCvv(g, S);
672
864
  } else
673
- h = V[o](f);
674
- let c;
675
- if (p) {
676
- const { parent: g, field: S } = p;
677
- c = {
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
- [g]: {
680
- ...m.formData[g] ?? {},
681
- [S]: h
871
+ [v]: {
872
+ ...m.formData[v] ?? {},
873
+ [S]: u
682
874
  }
683
875
  };
684
876
  } else
685
- c = {
877
+ h = {
686
878
  ...m.formData,
687
- [o]: h
879
+ [o]: u
688
880
  };
689
- let b = { ...m.errors };
690
- if (o === "phoneCountryCode" && c.phoneNumber) {
691
- const g = t(
881
+ let y = { ...m.errors };
882
+ if (o === "phoneCountryCode" && h.phoneNumber) {
883
+ const v = t(
692
884
  "phoneNumber",
693
- c.phoneNumber,
885
+ h.phoneNumber,
694
886
  void 0,
695
- h
887
+ u
696
888
  );
697
- g ? b.phoneNumber = g : delete b.phoneNumber;
889
+ v ? y.phoneNumber = v : delete y.phoneNumber;
698
890
  }
699
891
  if (m.touched[o])
700
- if (p) {
701
- const { parent: g, field: S } = p, N = n[S], D = N ? N(
702
- h
892
+ if (f) {
893
+ const { parent: v, field: S } = f, M = i[S], x = M ? M(
894
+ u
703
895
  ) : void 0;
704
- b = l(b, g, S, D);
896
+ y = d(y, v, S, x);
705
897
  } else {
706
- let g;
707
- o === "cardCvv" ? g = t(o, h, c.cardNumber) : o === "phoneNumber" ? g = t(
898
+ let v;
899
+ o === "cardCvv" ? v = t(o, u, h.cardNumber) : o === "phoneNumber" ? v = t(
708
900
  o,
709
- h,
901
+ u,
710
902
  void 0,
711
- c.phoneCountryCode
712
- ) : g = t(o, h), g ? b[o] = g : delete b[o];
903
+ h.phoneCountryCode
904
+ ) : v = t(o, u), v ? y[o] = v : delete y[o];
713
905
  }
714
906
  e.setState({
715
- formData: c,
716
- errors: b,
717
- isValid: i(c)
907
+ formData: h,
908
+ errors: y,
909
+ isValid: a(h)
718
910
  });
719
- }, E = (o, f) => {
720
- const m = e.getState(), h = d(o);
721
- if (h) {
722
- const { parent: g, field: S } = h, N = {
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
- [g]: {
725
- ...m.formData[g] ?? {},
726
- [S]: f
916
+ [v]: {
917
+ ...m.formData[v] ?? {},
918
+ [S]: g
727
919
  }
728
- }, D = n[S], le = D ? D(f) : void 0, de = l(m.errors, g, S, le);
920
+ }, x = i[S], ue = x ? x(g) : void 0, me = d(m.errors, v, S, ue);
729
921
  e.setState({
730
- formData: N,
922
+ formData: M,
731
923
  touched: {
732
924
  ...m.touched,
733
925
  [o]: !0
734
926
  },
735
- errors: de,
736
- isValid: i(N)
927
+ errors: me,
928
+ isValid: a(M)
737
929
  });
738
930
  return;
739
931
  }
740
- const p = {
932
+ const f = {
741
933
  ...m.touched,
742
934
  [o]: !0
743
935
  };
744
- let c;
745
- o === "cardCvv" ? c = t(o, f, m.formData.cardNumber) : o === "phoneNumber" ? c = t(
936
+ let h;
937
+ o === "cardCvv" ? h = t(o, g, m.formData.cardNumber) : o === "phoneNumber" ? h = t(
746
938
  o,
747
- f,
939
+ g,
748
940
  void 0,
749
941
  m.formData.phoneCountryCode
750
- ) : c = t(o, f);
751
- const b = { ...m.errors };
752
- c ? b[o] = c : delete b[o], e.setState({
753
- touched: p,
754
- errors: b
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
- }, y = (o) => {
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: i(m)
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: u,
770
- handleBlur: E,
771
- setFormData: y,
961
+ handleChange: c,
962
+ handleBlur: p,
963
+ setFormData: b,
772
964
  reset: e.resetState.bind(e)
773
965
  };
774
- };
775
- function $(n) {
776
- if (!n) return !1;
777
- const { billingFields: e, shippingFields: t } = n, s = e && Object.values(e).some((a) => a?.enabled), i = t && Object.values(t).some((a) => a?.enabled);
778
- return !!(s || i);
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
- class se extends A {
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: i, values: a, errors: r, touched: d } = e;
998
+ const { title: t, checkoutProfile: s, fieldsConfig: a, values: n, errors: r, touched: l } = e;
793
999
  if (this.grouped) {
794
- const l = document.createElement("h3");
795
- l.className = "address-section-title", l.textContent = t, l.style.color = s.styles.textColor, l.style.fontFamily = `"${s.styles.fontFamily}", sans-serif`, l.style.fontSize = `${s.styles.fontSize}px`, l.style.fontWeight = "normal", this.getElement().appendChild(l);
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, i, a, r, d);
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, i, a) {
800
- const r = (d) => d ? `${e}px` : "0px";
801
- return `${r(t)} ${r(s)} ${r(i)} ${r(a)}`;
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, i, a) {
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
- i,
810
- a
1015
+ a,
1016
+ n
811
1017
  );
812
1018
  return;
813
1019
  }
814
- const r = e.styles.borderRadius, d = {
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
- }, l = [];
819
- t.street?.enabled && l.push({ kind: "street" });
820
- const u = [];
821
- t.firstName?.enabled && u.push("firstName"), t.lastName?.enabled && u.push("lastName"), u.length > 0 && l.push({ kind: "name", fields: u }), t.country?.enabled && l.push({ kind: "country" });
822
- const E = [];
823
- t.city?.enabled && E.push("city"), t.zipCode?.enabled && E.push("zipCode"), E.length > 0 && l.push({ kind: "cityZip", fields: E }), t.state?.enabled && l.push({ kind: "state" });
824
- const y = l.length;
825
- l.forEach((o, f) => {
826
- const m = f === 0, h = f === y - 1, p = (c, b) => ({
827
- ...d,
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 && c,
831
- m && b,
832
- h && b,
833
- h && c
1036
+ m && h,
1037
+ m && y,
1038
+ u && y,
1039
+ u && h
834
1040
  )
835
1041
  });
836
1042
  if (o.kind === "street") {
837
- const c = this.createRow(["full"]), b = this.createInput(
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
- p(!0, !0),
1048
+ n.street,
1049
+ f(!0, !0),
844
1050
  "street-address"
845
1051
  );
846
- this.inputs.set("street", b), c.appendChild(b.getElement()), this.fieldsContainer.appendChild(c);
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 c = this.createRow(o.fields.map(() => "half")), b = o.fields.length === 1;
1056
+ const h = this.createRow(o.fields.map(() => "half")), y = o.fields.length === 1;
851
1057
  if (o.fields.includes("firstName")) {
852
- const g = b || o.fields[o.fields.length - 1] === "firstName", S = this.createInput(
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
- p(!0, g),
1063
+ n.firstName,
1064
+ f(!0, v),
859
1065
  "given-name"
860
1066
  );
861
- this.inputs.set("firstName", S), c.appendChild(S.getElement());
1067
+ this.inputs.set("firstName", S), h.appendChild(S.getElement());
862
1068
  }
863
1069
  if (o.fields.includes("lastName")) {
864
- const g = b || o.fields[0] === "lastName", S = this.createInput(
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
- p(g, !0),
1075
+ n.lastName,
1076
+ f(v, !0),
871
1077
  "family-name"
872
1078
  );
873
- this.inputs.set("lastName", S), c.appendChild(S.getElement());
1079
+ this.inputs.set("lastName", S), h.appendChild(S.getElement());
874
1080
  }
875
- this.fieldsContainer.appendChild(c);
1081
+ this.fieldsContainer.appendChild(h);
876
1082
  return;
877
1083
  }
878
1084
  if (o.kind === "country") {
879
- const c = this.createRow(["full"]), b = this.createCountrySelect(
1085
+ const h = this.createRow(["full"]), y = this.createCountrySelect(
880
1086
  s.country,
881
- i.country,
882
1087
  a.country,
883
- p(!0, !0),
1088
+ n.country,
1089
+ f(!0, !0),
884
1090
  t.country?.options,
885
1091
  t.country?.label
886
1092
  );
887
- this.inputs.set("country", b), c.appendChild(b.getElement()), this.fieldsContainer.appendChild(c);
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 c = this.createRow(o.fields.map(() => "half")), b = o.fields.length === 1;
1097
+ const h = this.createRow(o.fields.map(() => "half")), y = o.fields.length === 1;
892
1098
  if (o.fields.includes("city")) {
893
- const g = b || o.fields[o.fields.length - 1] === "city", S = this.createInput(
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
- p(!0, g),
1104
+ n.city,
1105
+ f(!0, v),
900
1106
  "address-level2"
901
1107
  );
902
- this.inputs.set("city", S), c.appendChild(S.getElement());
1108
+ this.inputs.set("city", S), h.appendChild(S.getElement());
903
1109
  }
904
1110
  if (o.fields.includes("zipCode")) {
905
- const g = b || o.fields[0] === "zipCode", S = this.createInput(
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
- p(g, !0),
1116
+ n.zipCode,
1117
+ f(v, !0),
912
1118
  "postal-code"
913
1119
  );
914
- this.inputs.set("zipCode", S), c.appendChild(S.getElement());
1120
+ this.inputs.set("zipCode", S), h.appendChild(S.getElement());
915
1121
  }
916
- this.fieldsContainer.appendChild(c);
1122
+ this.fieldsContainer.appendChild(h);
917
1123
  return;
918
1124
  }
919
1125
  if (o.kind === "state") {
920
- const c = this.createRow(["full"]);
1126
+ const h = this.createRow(["full"]);
921
1127
  if (this.stateOptions = t.state?.options, t.state?.options && t.state.options.length > 0) {
922
- const g = this.createStateSelect(
1128
+ const v = this.createStateSelect(
923
1129
  s.state,
924
- i.state,
925
1130
  a.state,
926
- p(!0, !0),
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", g), c.appendChild(g.getElement());
1137
+ this.inputs.set("state", v), h.appendChild(v.getElement());
932
1138
  } else {
933
- const g = this.createInput(
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
- p(!0, !0),
1144
+ n.state,
1145
+ f(!0, !0),
940
1146
  "address-level1"
941
1147
  );
942
- this.inputs.set("state", g), c.appendChild(g.getElement());
1148
+ this.inputs.set("state", v), h.appendChild(v.getElement());
943
1149
  }
944
- this.fieldsContainer.appendChild(c);
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, i, a, r, d) {
953
- const l = `${this.type}Address.${e}`, u = new re({
954
- name: l,
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 E = `address.placeholder.${e}`, y = this.translationFunc(E);
962
- return y !== E ? y : t;
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: d,
967
- onChange: (E) => {
968
- u.setError(!1);
969
- const y = new Event("input", { bubbles: !0 });
970
- Object.defineProperty(y, "target", {
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: l,
974
- value: E.target.value
1179
+ name: d,
1180
+ value: p.target.value
975
1181
  }
976
- }), this.onChange(y);
1182
+ }), this.onChange(b);
977
1183
  }
978
1184
  });
979
- return u.addEventListener("blur", (E) => {
980
- const y = new Event("blur", { bubbles: !0 });
981
- Object.defineProperty(y, "target", {
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: l,
985
- value: E.target.value
1190
+ name: d,
1191
+ value: p.target.value
986
1192
  }
987
- }), this.onBlur(y);
988
- }), u;
1193
+ }), this.onBlur(b);
1194
+ }), c;
989
1195
  }
990
- createCountrySelect(e, t, s, i, a, r) {
991
- const d = `${this.type}Address.country`, l = ue(a, this.locale), u = new R({
992
- name: d,
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: i,
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: l,
1207
+ options: d,
1002
1208
  autocomplete: "country",
1003
- onChange: (E) => {
1004
- u.setError(!1);
1005
- const y = E.target.value;
1006
- this.updateStateOptionsForCountry(y);
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: d,
1012
- value: y
1217
+ name: l,
1218
+ value: b
1013
1219
  }
1014
1220
  }), this.onChange(o);
1015
1221
  }
1016
1222
  });
1017
- return u.addEventListener("blur", (E) => {
1018
- const y = new Event("blur", { bubbles: !0 });
1019
- Object.defineProperty(y, "target", {
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: d,
1023
- value: E.target.value
1228
+ name: l,
1229
+ value: p.target.value
1024
1230
  }
1025
- }), this.onBlur(y);
1026
- }), u;
1231
+ }), this.onBlur(b);
1232
+ }), c;
1027
1233
  }
1028
1234
  updateStateOptionsForCountry(e) {
1029
1235
  const t = this.inputs.get("state");
1030
- if (!(t instanceof R)) return;
1031
- const s = e === "CA" ? "CA" : "US", i = Z(this.stateOptions, s), a = s === "CA" ? this.translationFunc("address.chooseProvince") : this.translationFunc("address.chooseState");
1032
- t.setOptions(i, a);
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, i, a, r, d) {
1035
- const l = `${this.type}Address.state`, u = r === "CA" ? "CA" : "US", E = Z(a, u), y = u === "CA" ? this.translationFunc("address.chooseProvince") : this.translationFunc("address.chooseState"), o = new R({
1036
- name: l,
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: i,
1040
- placeholder: y,
1041
- ...!this.grouped && { label: d ?? y },
1245
+ styles: a,
1246
+ placeholder: b,
1247
+ ...!this.grouped && { label: l ?? b },
1042
1248
  value: e,
1043
- options: E,
1249
+ options: p,
1044
1250
  autocomplete: "address-level1",
1045
- onChange: (f) => {
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: l,
1052
- value: f.target.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", (f) => {
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: l,
1063
- value: f.target.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, i, a) {
1069
- const r = e.styles.borderRadius, d = {
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
- }, l = (u, E, y) => {
1075
- if (!t[u]?.enabled) return;
1076
- const o = t[u]?.label ?? this.translationFunc(E), f = this.createRow(["full"]), m = this.createInput(
1077
- u,
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[u],
1080
- i[u],
1081
- a[u],
1082
- d,
1083
- y
1285
+ s[c],
1286
+ a[c],
1287
+ n[c],
1288
+ l,
1289
+ b
1084
1290
  );
1085
- this.inputs.set(u, m), f.appendChild(m.getElement()), this.fieldsContainer.appendChild(f);
1291
+ this.inputs.set(c, m), g.appendChild(m.getElement()), this.fieldsContainer.appendChild(g);
1086
1292
  };
1087
- if (l("firstName", "address.firstName", "given-name"), l("lastName", "address.lastName", "family-name"), l("street", "address.addressLine1", "street-address"), l("city", "address.townCity", "address-level2"), t.country?.enabled) {
1088
- const u = t.country?.label ?? this.translationFunc("address.chooseCountry"), E = this.createRow(["full"]), y = this.createCountrySelect(
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
- d,
1297
+ n.country,
1298
+ l,
1093
1299
  t.country?.options,
1094
- u
1300
+ c
1095
1301
  );
1096
- this.inputs.set("country", y), E.appendChild(y.getElement()), this.fieldsContainer.appendChild(E);
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 u = this.createRow(["full"]), E = t.state?.options && t.state.options.length > 0, y = t.state?.label ?? this.translationFunc("address.chooseState");
1101
- if (E) {
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
- d,
1311
+ n.state,
1312
+ l,
1107
1313
  t.state?.options,
1108
1314
  s.country,
1109
- y
1315
+ b
1110
1316
  );
1111
- this.inputs.set("state", o), u.appendChild(o.getElement());
1317
+ this.inputs.set("state", o), c.appendChild(o.getElement());
1112
1318
  } else {
1113
1319
  const o = this.createInput(
1114
1320
  "state",
1115
- y,
1321
+ b,
1116
1322
  s.state,
1117
- i.state,
1118
1323
  a.state,
1119
- d,
1324
+ n.state,
1325
+ l,
1120
1326
  "address-level1"
1121
1327
  );
1122
- this.inputs.set("state", o), u.appendChild(o.getElement());
1328
+ this.inputs.set("state", o), c.appendChild(o.getElement());
1123
1329
  }
1124
- this.fieldsContainer.appendChild(u);
1330
+ this.fieldsContainer.appendChild(c);
1125
1331
  }
1126
- l("zipCode", "address.postalCode", "postal-code");
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 d = a.getElement().querySelector("input") || a.getElement().querySelector("select"), l = a.getValue();
1161
- !(document.activeElement === d) && !(t === "" && l !== "") && this.setValue(e, t);
1359
+ const n = a.getElement().querySelector("input") || a.getElement().querySelector("select");
1360
+ document.activeElement !== n && a.setError(t, s);
1162
1361
  }
1163
- const r = !!(i && s);
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((i) => {
1373
+ Object.keys(e).forEach((a) => {
1168
1374
  this.updateField(
1169
- i,
1170
- e[i],
1171
- t[i],
1172
- !!s[i]
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 st {
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: i,
1188
- errorMsg: a,
1398
+ onBlur: a,
1399
+ errorMsg: n,
1189
1400
  checkoutProfile: r,
1190
- translationFunc: d,
1191
- autocomplete: l = "cc-name"
1401
+ translationFunc: l,
1402
+ autocomplete: d = "cc-name",
1403
+ isVgsMode: c = !1
1192
1404
  } = e;
1193
- this.input = new re({
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: d("cardholderNameLabel"),
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: r.styles.textColor,
1201
- borderRadius: `${r.styles.borderRadius}px`,
1202
- fontSize: r.styles.fontSize,
1203
- fontFamily: r.styles.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: d("cardholderNamePlaceholder"),
1206
- value: t,
1435
+ placeholder: r("cardholderNamePlaceholder"),
1436
+ value: e,
1207
1437
  autocomplete: l,
1208
- onChange: (u) => {
1209
- const y = u.target.value, o = y.replace(/[^a-zA-Z\s\-'.]/g, "");
1210
- y !== o && this.input.setValue(o), this.input.setError(!1), this.trim(), s(u);
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", (u) => {
1213
- i(u);
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.getValue();
1463
+ return this.isVgsMode ? "" : this.input?.getValue() ?? "";
1218
1464
  }
1219
1465
  setValue(e) {
1220
- return this.input.setValue(e), this;
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
- const s = this.input.getElement().querySelector("input");
1228
- return document.activeElement !== s && this.input.setError(e, t), this;
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.input.appendTo(e), this;
1482
+ return e.appendChild(this.getElement()), this;
1235
1483
  }
1236
1484
  focus() {
1237
- this.input.focus();
1485
+ this.isVgsMode || this.input?.focus();
1238
1486
  }
1239
1487
  }
1240
- class oe extends A {
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 = w.createDiv(["skeleton-field"]), t = w.createDiv([
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 = w.createDiv([
1503
+ const e = k.createDiv([
1256
1504
  "payment-separator_container"
1257
- ]), t = w.createDiv(["payment-separator__line"]), s = w.createDiv([
1505
+ ]), t = k.createDiv(["payment-separator__line"]), s = k.createDiv([
1258
1506
  "skeleton",
1259
1507
  "skeleton-separator-text"
1260
- ]), i = w.createDiv(["payment-separator__line"]);
1261
- return e.appendChild(t), e.appendChild(s), e.appendChild(i), e;
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 nt extends A {
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 i = this.getElement(), a = document.createElement("span");
1269
- a.className = "payment-separator__line";
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 d = document.createElement("span");
1273
- d.className = "payment-separator__line", i.appendChild(a), i.appendChild(r), i.appendChild(d);
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 at extends A {
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: i,
1285
- onApplePaySubmit: a,
1532
+ onPaypalSubmit: a,
1533
+ onApplePaySubmit: n,
1286
1534
  supportedPaymentMethods: r,
1287
- translationFunc: d,
1288
- paymentId: l,
1289
- checkoutKey: u,
1290
- checkoutDetails: E,
1291
- environment: y,
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 f = Object.entries(
1550
+ const g = Object.entries(
1303
1551
  t.additionalPaymentMethods
1304
- ).filter(([m, h]) => {
1305
- const p = h.enabled, c = r ? r[m] === !0 : !0, b = !h.countries || o && h.countries.includes(o);
1306
- return p && c && b;
1307
- }).sort((m, h) => m[1].order - h[1].order);
1308
- if (f.length === 0) {
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 f)
1560
+ for (const [m] of g)
1313
1561
  switch (m) {
1314
1562
  case "paypal": {
1315
- if (i) {
1316
- const h = new pe({
1563
+ if (a) {
1564
+ const u = new Se({
1317
1565
  checkoutProfile: t,
1318
1566
  formData: s,
1319
- onSubmit: i
1567
+ onSubmit: a
1320
1568
  });
1321
- this.paymentMethods.set("paypal", h), h.appendTo(this.getElement());
1569
+ this.paymentMethods.set("paypal", u), u.appendTo(this.getElement());
1322
1570
  }
1323
1571
  break;
1324
1572
  }
1325
1573
  case "applePay": {
1326
- if (a && l && u) {
1327
- const h = t.appearance?.additionalPaymentMethods?.applePay, p = new me({
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: a,
1331
- paymentId: l,
1332
- checkoutKey: u,
1333
- checkoutDetails: E,
1334
- environment: y,
1335
- displayName: h?.displayName,
1336
- requiredBillingContactFields: h?.requiredBillingContactFields,
1337
- requiredShippingContactFields: h?.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", p), p.appendTo(this.getElement());
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 nt({
1356
- translationFunc: d,
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 oe(), this.getElement().appendChild(this.skeleton.getElement());
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 it = 17;
1374
- class rt extends A {
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 === it ? "100vmax" : `${this.styles.borderRadius}px`, e.style.fontSize = `${this.styles.fontSize}px`, e.style.fontFamily = `${this.styles.fontFamily}, sans-serif`;
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 ot {
1644
+ class bt {
1397
1645
  button;
1398
1646
  constructor(e) {
1399
- const { disabled: t, checkoutProfile: s, translationFunc: i } = e;
1400
- this.button = new rt({
1401
- text: i(
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 lt {
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
- (i) => i.enabled
1718
+ (a) => a.enabled
1466
1719
  ))
1467
1720
  return;
1468
- this.paymentMethods = new at({
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 (i) {
1485
- throw console.error("Error creating payment methods:", i), i;
1737
+ } catch (a) {
1738
+ throw console.error("Error creating payment methods:", a), a;
1486
1739
  }
1487
1740
  }
1488
- createEmailField(e, t, s, i) {
1741
+ createEmailField(e, t, s, a) {
1489
1742
  try {
1490
- const a = e.layout.billingFields && Object.values(e.layout.billingFields).some(
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 fe({
1748
+ this.emailField = new Ee({
1496
1749
  value: t.email,
1497
1750
  onChange: this.onChange,
1498
1751
  onBlur: this.onBlur,
1499
- onTab: a ? void 0 : () => this.focusManager.focusField(
1752
+ onTab: n ? void 0 : () => this.focusManager.focusField(
1500
1753
  e.layout.phoneNumber?.enabled ? "phoneNumber" : "cardNumber"
1501
1754
  ),
1502
- error: !!(s.email && i.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 (a) {
1508
- throw console.error("Error creating email field:", a), a;
1760
+ } catch (n) {
1761
+ throw console.error("Error creating email field:", n), n;
1509
1762
  }
1510
1763
  }
1511
- createPhoneNumberField(e, t, s, i) {
1512
- const a = document.createElement("div");
1513
- this.phonePlaceholder = a, this.formElement.appendChild(a), ge().then(({ PhoneNumberField: r }) => {
1514
- a.isConnected && (this.phoneNumberField = new r({
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 && i.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), a.replaceWith(this.phoneNumberField.getElement()), this.phonePlaceholder = void 0);
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), a.remove(), this.phonePlaceholder = void 0;
1781
+ console.error("Error creating phone number field:", r), n.remove(), this.phonePlaceholder = void 0;
1529
1782
  });
1530
1783
  }
1531
- createCardSection(e, t, s, i) {
1784
+ setCheckoutDetailsLoaded(e) {
1785
+ this.isCheckoutDetailsLoaded = e;
1786
+ }
1787
+ createCardSection(e, t, s, a) {
1532
1788
  try {
1533
- this.cardSection = new ye({
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: !!i.cardNumber,
1797
+ cardNumberTouched: !!a.cardNumber,
1538
1798
  cardCvv: t.cardCvv,
1539
1799
  cardCvvError: s.cardCvv,
1540
- cardCvvTouched: !!i.cardCvv,
1800
+ cardCvvTouched: !!a.cardCvv,
1541
1801
  cardExpiry: t.cardExpiry,
1542
1802
  cardExpiryError: s.cardExpiry,
1543
- cardExpiryTouched: !!i.cardExpiry,
1803
+ cardExpiryTouched: !!a.cardExpiry,
1544
1804
  onChange: this.onChange,
1545
1805
  onBlur: this.onBlur,
1546
1806
  onCardBrandChange: () => {
1547
1807
  if (t.cardCvv) {
1548
- const l = new Event("blur", { bubbles: !0 });
1549
- Object.defineProperty(l, "target", {
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(l);
1812
+ }), this.onBlur(n);
1553
1813
  }
1554
1814
  },
1555
- translationFunc: this.translationFunc
1556
- });
1557
- const a = this.cardSection.getElement().querySelector('input[name="cardExpiry"]');
1558
- a && (this.cardExpiryFocusHandler = () => this.onFieldFocus("cardExpiry"), a.addEventListener("focus", this.cardExpiryFocusHandler));
1559
- const r = this.cardSection.getElement().querySelector('input[name="cardNumber"]');
1560
- r && (this.cardNumberFocusHandler = () => this.onFieldFocus("cardNumber"), r.addEventListener("focus", this.cardNumberFocusHandler));
1561
- const d = this.cardSection.getElement().querySelector('input[name="cardCvv"]');
1562
- d && (this.cardCvvFocusHandler = () => this.onFieldFocus("cardCvv"), d.addEventListener("focus", this.cardCvvFocusHandler)), this.focusManager.registerField("cardNumber", {
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 (a) {
1570
- throw console.error("Error creating card section:", a), a;
1839
+ } catch (n) {
1840
+ throw console.error("Error creating card section:", n), n;
1571
1841
  }
1572
1842
  }
1573
- createCardholderSection(e, t, s, i) {
1843
+ createCardholderSection(e, t, s, a) {
1574
1844
  try {
1575
- this.cardholderSection = new st({
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 && i.name),
1853
+ error: !!(s.name && a.name),
1580
1854
  errorMsg: s.name,
1581
1855
  checkoutProfile: e,
1582
- translationFunc: this.translationFunc
1583
- });
1584
- const a = this.cardholderSection.getElement().querySelector('input[name="name"]');
1585
- a && (this.nameFocusHandler = () => this.onFieldFocus("name"), a.addEventListener("focus", this.nameFocusHandler)), this.focusManager.registerField("name", this.cardholderSection), this.formElement.appendChild(this.cardholderSection.getElement());
1586
- } catch (a) {
1587
- throw console.error("Error creating cardholder section:", a), a;
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, i) {
1867
+ createBillingAddressSection(e, t, s, a) {
1591
1868
  try {
1592
- const a = e.layout.billingFields;
1593
- if (!a || !Object.values(a).some(
1594
- (l) => l?.enabled
1869
+ const n = e.layout.billingFields;
1870
+ if (!n || !Object.values(n).some(
1871
+ (d) => d?.enabled
1595
1872
  )) return;
1596
- const d = {
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 se({
1882
+ this.billingAddressSection = new re({
1606
1883
  type: "billing",
1607
1884
  title: this.translationFunc("address.billingTitle"),
1608
1885
  checkoutProfile: e,
1609
- fieldsConfig: a,
1610
- values: t.billingAddress ?? d,
1886
+ fieldsConfig: n,
1887
+ values: t.billingAddress ?? l,
1611
1888
  errors: s.billingAddress ?? {},
1612
- touched: i.billingAddress ?? {},
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 (a) {
1620
- throw console.error("Error creating billing address section:", a), a;
1896
+ } catch (n) {
1897
+ throw console.error("Error creating billing address section:", n), n;
1621
1898
  }
1622
1899
  }
1623
- createShippingAddressSection(e, t, s, i) {
1900
+ createShippingAddressSection(e, t, s, a) {
1624
1901
  try {
1625
- const a = e.layout.shippingFields;
1626
- if (!a || !Object.values(a).some(
1627
- (l) => l?.enabled
1902
+ const n = e.layout.shippingFields;
1903
+ if (!n || !Object.values(n).some(
1904
+ (d) => d?.enabled
1628
1905
  )) return;
1629
- const d = {
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 se({
1915
+ this.shippingAddressSection = new re({
1639
1916
  type: "shipping",
1640
1917
  title: this.translationFunc("address.shippingTitle"),
1641
1918
  checkoutProfile: e,
1642
- fieldsConfig: a,
1643
- values: t.shippingAddress ?? d,
1919
+ fieldsConfig: n,
1920
+ values: t.shippingAddress ?? l,
1644
1921
  errors: s.shippingAddress ?? {},
1645
- touched: i.shippingAddress ?? {},
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 (a) {
1653
- throw console.error("Error creating shipping address section:", a), a;
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 ot({
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, i, a, r, d, l, u) {
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(i, a, r), this.cardSection.updateCardExpiry(
1679
- d,
1955
+ ), this.cardSection.updateCardCvv(a, n, r), this.cardSection.updateCardExpiry(
1680
1956
  l,
1681
- u
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 dt {
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: i } = t, a = s;
1752
- this.formManager.handleChange(a, i), this.localTouchedFields.has(a) || (this.localTouchedFields.add(a), this.formManager.handleBlur(a, i));
1753
- const { formData: r, errors: d, touched: l } = this.formManager.getFormState();
1754
- this.focusManager.handleStateUpdate(r, d, l);
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: i } = t, a = s;
1758
- this.localTouchedFields.add(a), this.formManager.handleBlur(a, i), setTimeout(() => {
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: d, touched: l } = this.formManager.getFormState();
1762
- l[a] || this.focusManager.handleStateUpdate(r, d, l);
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 ct {
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 } = be({
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
- (c) => c !== "billingAddress" && c !== "shippingAddress"
1822
- ).length > 0, i = e.errors.billingAddress, a = i && typeof i == "object" ? Object.keys(i).length > 0 : !1, r = e.errors.shippingAddress, d = r && typeof r == "object" ? Object.keys(r).length > 0 : !1, l = s || a || d, E = $(
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: f, shippingFields: m } = t.checkoutProfile?.layout ?? {}, h = (c, b) => !c || Object.entries(c).every(
1825
- ([g, S]) => !S?.enabled || !!b?.[g]?.trim()
1826
- ), p = !!e.formData.email && o && E && !!e.formData.cardNumber && !!e.formData.cardCvv && !!e.formData.cardExpiry && h(f, e.formData.billingAddress) && h(m, e.formData.shippingAddress);
1827
- return l || !p || this.isSubmitting;
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 ht extends A {
2202
+ class Ct extends P {
1840
2203
  titleElement;
1841
2204
  constructor(e = {}) {
1842
2205
  super("div", ["blur-bg"]);
1843
- const t = w.createDiv(["loader"]);
1844
- this.titleElement = new A("h3", ["title"]), this.titleElement.setText(e.text || ""), this.appendChild(t), this.appendChild(this.titleElement);
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 ne = {
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
- }, ae = (n, e) => {
2221
+ }, le = (i, e) => {
1859
2222
  const t = {}, s = `${e}.`;
1860
- return Object.keys(n).forEach((i) => {
1861
- if (i.startsWith(s)) {
1862
- const a = i.slice(s.length);
1863
- t[a] = n[i];
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 ut {
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 ?? ne,
2264
+ e.formData.billingAddress ?? oe,
1902
2265
  e.errors.billingAddress ?? {},
1903
- ae(e.touched, "billingAddress")
2266
+ le(e.touched, "billingAddress")
1904
2267
  ), this.componentManager.updateShippingAddressSection(
1905
- e.formData.shippingAddress ?? ne,
2268
+ e.formData.shippingAddress ?? oe,
1906
2269
  e.errors.shippingAddress ?? {},
1907
- ae(e.touched, "shippingAddress")
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 oe(), this.formElement.appendChild(this.formSkeleton.getElement())) : this.hideSkeleton();
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 ht({ text: e }), this.formElement.appendChild(this.spinner.getElement());
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 Ee({ message: e }), this.formElement.insertBefore(
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 I = (n) => ({
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
- ...n
2310
+ ...i
1948
2311
  });
1949
- class mt extends A {
2312
+ class Mt extends P {
1950
2313
  options;
1951
- formManager = tt();
2314
+ formManager = lt();
1952
2315
  checkoutProfile;
1953
- translation = Se();
1954
- focusManager = new Fe();
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 = et({
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 lt({
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
- }), this.uiManager = new ut({
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 ct({
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 dt({
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: I(
2386
+ billingAddress: D(
2018
2387
  e.initialValues.billingAddress
2019
2388
  )
2020
2389
  },
2021
2390
  ...e.initialValues.shippingAddress && {
2022
- shippingAddress: I(
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: I(t.billingAddress)
2408
+ billingAddress: D(t.billingAddress)
2040
2409
  },
2041
2410
  ...t?.shippingAddress && {
2042
- shippingAddress: I(t.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: I()
2435
+ billingAddress: D()
2060
2436
  }), e.checkoutProfile.layout.shippingFields && this.formManager.getFormState().formData.shippingAddress === void 0 && this.formManager.setFormData({
2061
- shippingAddress: I()
2437
+ shippingAddress: D()
2062
2438
  });
2063
- const { formData: t, errors: s, touched: i } = this._getFormStateData(), a = $(
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
- i
2455
+ a
2080
2456
  );
2081
2457
  } catch (r) {
2082
2458
  console.error("Failed to create email field:", r);
2083
2459
  }
2084
- if (a) {
2460
+ if (n) {
2085
2461
  try {
2086
2462
  this.componentManager.createBillingAddressSection(
2087
2463
  e.checkoutProfile,
2088
2464
  t,
2089
2465
  s,
2090
- i
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
- i
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
- i
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
- i
2498
+ a
2123
2499
  );
2124
2500
  } catch (r) {
2125
2501
  console.error("Failed to create card section:", r);
2126
2502
  }
2127
- if (!a)
2503
+ if (!n)
2128
2504
  try {
2129
2505
  this.componentManager.createCardholderSection(
2130
2506
  e.checkoutProfile,
2131
2507
  t,
2132
2508
  s,
2133
- i
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(), i = s.billingAddress ?? s.shippingAddress;
2164
- if (!i) return;
2165
- const a = i.firstName?.trim() ?? "", r = i.lastName?.trim() ?? "", d = [a, r].filter(Boolean).join(" ");
2166
- d && this.formManager.setFormData({ name: d });
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, i = t && Object.values(t).some((d) => d?.enabled), a = s && Object.values(s).some((d) => d?.enabled), { formData: r } = this._getFormStateData();
2177
- !i && a && r.shippingAddress ? this.formManager.setFormData({
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
- }) : !a && i && r.billingAddress && this.formManager.setFormData({
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(), await this.options.onSubmit({
2187
- formData: this.formManager.getFormState().formData
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, i) {
2240
- this.options.paymentId = e, this.options.checkoutKey = t, this.options.supportedPaymentMethods = s, this.options.checkoutDetails = i, this.componentManager.removePaymentMethods(), this.componentManager.updateSupportedPaymentMethods(
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
- i
2246
- );
2247
- const a = this.checkoutProfile.getState();
2248
- if (a.checkoutProfile) {
2249
- const { formData: r } = this._getFormStateData();
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
- a.checkoutProfile,
2252
- r,
2665
+ r.checkoutProfile,
2666
+ l,
2253
2667
  !0
2254
2668
  );
2255
2669
  }
2256
2670
  }
2257
2671
  }
2258
- class pt {
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 mt({
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, i) {
2309
- this.options.paymentId = e, this.options.checkoutKey = t, this.options.checkoutDetails = i, this.form && this.form.associatePayment(
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
- i
2728
+ a,
2729
+ n
2314
2730
  );
2315
2731
  }
2316
2732
  }
2317
- class ft {
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 gt = "en";
2340
- class yt {
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(), Qe({
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(v.CHECKOUT_INITIALIZED, {
2767
+ }), F(C.CHECKOUT_INITIALIZED, {
2352
2768
  environment: this.config.environment
2353
- }), this.apiService = new ve(
2769
+ }), this.apiService = new Ae(
2354
2770
  this.config.apiKey,
2355
2771
  this.config.environment
2356
- ), this.stateManager = new ft({
2772
+ ), this.stateManager = new wt({
2357
2773
  mounted: !1,
2358
2774
  form: null
2359
- }), this.formManager = new pt(
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 || gt,
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(v.CHECKOUT_MOUNTED, {
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(v.CHECKOUT_UNMOUNTED);
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(v.PAYMENT_SUBMIT_STARTED, {
2842
+ F(C.PAYMENT_SUBMIT_STARTED, {
2427
2843
  payment_id: this.paymentState.paymentId,
2428
2844
  payment_method: s
2429
2845
  });
2430
- const i = performance.now();
2846
+ const a = performance.now();
2431
2847
  try {
2432
- const a = await this.apiService.authorizePayment({
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() - i;
2439
- te(
2440
- G.PAYMENT_AUTHORIZATION_TIME,
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(v.PAYMENT_SUBMIT_SUCCESS, {
2864
+ ), F(C.PAYMENT_SUBMIT_SUCCESS, {
2449
2865
  payment_id: this.paymentState.paymentId,
2450
2866
  payment_method: s
2451
- }), this.handlePaymentResponse(a);
2452
- } catch (a) {
2453
- const r = performance.now() - i;
2454
- te(
2455
- G.PAYMENT_AUTHORIZATION_TIME,
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(v.PAYMENT_SUBMIT_FAILED, {
2879
+ ), F(C.PAYMENT_SUBMIT_FAILED, {
2464
2880
  payment_id: this.paymentState.paymentId,
2465
2881
  payment_method: s,
2466
- error_message: a.details?.message ?? "Unknown error"
2467
- }), this.handleAuthorizationError(a);
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(v.PAYMENT_AUTHORIZED, {
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(v.PAYMENT_FAILED, {
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(v.PAYMENT_ACTION_REQUIRED, {
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 Ce({
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
- (a) => typeof a == "string"
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 i = s.supportedPaymentMethods.reduce(
2542
- (a, r) => (a[r] = !0, a),
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
- i,
2549
- this.paymentState.checkoutDetails
2550
- ), C(v.PAYMENT_ASSOCIATED, {
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(v.PAYMENT_ASSOCIATION_FAILED, {
2973
+ throw F(C.PAYMENT_ASSOCIATION_FAILED, {
2557
2974
  payment_id: e,
2558
2975
  error_message: s instanceof Error ? s.message : "Unknown error"
2559
- }), Je(
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 = yt);
2983
+ typeof globalThis < "u" && (globalThis.OdusCheckout = kt);
2567
2984
  export {
2568
- yt as OdusCheckout,
2569
- vt as deLocale,
2570
- Ct as enLocale,
2571
- Mt as esLocale,
2572
- Nt as frLocale,
2573
- Pt as itLocale,
2574
- At as plLocale,
2575
- wt as ptLocale,
2576
- Je as pushError,
2577
- C as pushEvent,
2578
- Et as pushLog,
2579
- te as pushMeasurement,
2580
- kt as trLocale
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
  };