@odus/checkout 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checkout.es.js +1623 -2521
- package/dist/elements.es.js +1318 -1750
- package/dist/index.css +2 -1
- package/dist/package.json +1 -1
- package/dist/phone.js +10957 -3446
- package/dist/shared.js +7075 -7412
- package/package.json +1 -1
package/dist/checkout.es.js
CHANGED
|
@@ -1,2525 +1,1627 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function I(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
styles: o.styles || {
|
|
8
|
-
fontSize: 14,
|
|
9
|
-
textColor: "#000000",
|
|
10
|
-
buttonColor: "#0070f3",
|
|
11
|
-
borderRadius: 4,
|
|
12
|
-
fontFamily: "system-ui",
|
|
13
|
-
buttonTextColor: "#ffffff",
|
|
14
|
-
buttonFontSize: 16
|
|
15
|
-
},
|
|
16
|
-
layout: {
|
|
17
|
-
grouped: o.layout?.grouped,
|
|
18
|
-
actionButton: o.layout?.actionButton || {
|
|
19
|
-
translationKey: null
|
|
20
|
-
},
|
|
21
|
-
phoneNumber: o.layout?.phoneNumber ? {
|
|
22
|
-
enabled: o.layout.phoneNumber.enabled,
|
|
23
|
-
label: o.layout.phoneNumber.label,
|
|
24
|
-
defaultCountry: o.layout.phoneNumber.defaultCountry,
|
|
25
|
-
allowedCountries: o.layout.phoneNumber.allowedCountries
|
|
26
|
-
} : void 0,
|
|
27
|
-
billingFields: {
|
|
28
|
-
street: {
|
|
29
|
-
enabled: o.layout?.billingFields?.street?.enabled ?? !1,
|
|
30
|
-
label: o.layout?.billingFields?.street?.label,
|
|
31
|
-
maxLength: o.layout?.billingFields?.street?.maxLength
|
|
32
|
-
},
|
|
33
|
-
city: {
|
|
34
|
-
enabled: o.layout?.billingFields?.city?.enabled ?? !1,
|
|
35
|
-
label: o.layout?.billingFields?.city?.label
|
|
36
|
-
},
|
|
37
|
-
state: {
|
|
38
|
-
enabled: o.layout?.billingFields?.state?.enabled ?? !1,
|
|
39
|
-
label: o.layout?.billingFields?.state?.label,
|
|
40
|
-
hiddenForCountries: o.layout?.billingFields?.state?.hiddenForCountries
|
|
41
|
-
},
|
|
42
|
-
zipCode: {
|
|
43
|
-
enabled: o.layout?.billingFields?.zipCode?.enabled ?? !1,
|
|
44
|
-
label: o.layout?.billingFields?.zipCode?.label
|
|
45
|
-
},
|
|
46
|
-
firstName: {
|
|
47
|
-
enabled: o.layout?.billingFields?.firstName?.enabled ?? !1,
|
|
48
|
-
label: o.layout?.billingFields?.firstName?.label
|
|
49
|
-
},
|
|
50
|
-
lastName: {
|
|
51
|
-
enabled: o.layout?.billingFields?.lastName?.enabled ?? !1,
|
|
52
|
-
label: o.layout?.billingFields?.lastName?.label
|
|
53
|
-
},
|
|
54
|
-
country: {
|
|
55
|
-
enabled: o.layout?.billingFields?.country?.enabled ?? !1,
|
|
56
|
-
label: o.layout?.billingFields?.country?.label,
|
|
57
|
-
options: o.layout?.billingFields?.country?.options
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
shippingFields: o.layout?.shippingFields ? {
|
|
61
|
-
street: {
|
|
62
|
-
enabled: o.layout.shippingFields.street?.enabled ?? !1,
|
|
63
|
-
label: o.layout.shippingFields.street?.label,
|
|
64
|
-
maxLength: o.layout.shippingFields.street?.maxLength
|
|
65
|
-
},
|
|
66
|
-
firstName: {
|
|
67
|
-
enabled: o.layout.shippingFields.firstName?.enabled ?? !1,
|
|
68
|
-
label: o.layout.shippingFields.firstName?.label
|
|
69
|
-
},
|
|
70
|
-
lastName: {
|
|
71
|
-
enabled: o.layout.shippingFields.lastName?.enabled ?? !1,
|
|
72
|
-
label: o.layout.shippingFields.lastName?.label
|
|
73
|
-
},
|
|
74
|
-
city: {
|
|
75
|
-
enabled: o.layout.shippingFields.city?.enabled ?? !1,
|
|
76
|
-
label: o.layout.shippingFields.city?.label
|
|
77
|
-
},
|
|
78
|
-
state: {
|
|
79
|
-
enabled: o.layout.shippingFields.state?.enabled ?? !1,
|
|
80
|
-
label: o.layout.shippingFields.state?.label,
|
|
81
|
-
hiddenForCountries: o.layout.shippingFields.state?.hiddenForCountries
|
|
82
|
-
},
|
|
83
|
-
zipCode: {
|
|
84
|
-
enabled: o.layout.shippingFields.zipCode?.enabled ?? !1,
|
|
85
|
-
label: o.layout.shippingFields.zipCode?.label
|
|
86
|
-
},
|
|
87
|
-
country: {
|
|
88
|
-
enabled: o.layout.shippingFields.country?.enabled ?? !1,
|
|
89
|
-
label: o.layout.shippingFields.country?.label,
|
|
90
|
-
options: o.layout.shippingFields.country?.options
|
|
91
|
-
}
|
|
92
|
-
} : void 0
|
|
93
|
-
},
|
|
94
|
-
appearance: {
|
|
95
|
-
additionalPaymentMethods: o.additionalPaymentMethods ? {
|
|
96
|
-
applePay: o.additionalPaymentMethods.applePay ? {
|
|
97
|
-
displayName: o.additionalPaymentMethods.applePay.displayName,
|
|
98
|
-
requiredBillingContactFields: o.additionalPaymentMethods.applePay.requiredBillingContactFields,
|
|
99
|
-
requiredShippingContactFields: o.additionalPaymentMethods.applePay.requiredShippingContactFields
|
|
100
|
-
} : void 0
|
|
101
|
-
} : void 0
|
|
102
|
-
}
|
|
103
|
-
};
|
|
1
|
+
import { A as e, B as t, D as n, E as r, F as i, G as a, H as o, I as s, K as c, L as l, M as u, O as d, R as f, S as p, T as m, U as h, V as g, W as _, _ as v, a as y, b, c as x, d as ee, f as S, i as C, j as te, k as w, l as T, m as E, n as D, o as O, p as k, q as ne, r as re, s as A, t as j, v as M, w as N, x as P, y as F } from "./shared.js";
|
|
2
|
+
//#region libs/checkout/src/utils/helpers/hasAddressConfiguration.util.ts
|
|
3
|
+
function I(e) {
|
|
4
|
+
if (!e) return !1;
|
|
5
|
+
let { billingFields: t, shippingFields: n } = e, r = t && Object.values(t).some((e) => e?.enabled), i = n && Object.values(n).some((e) => e?.enabled);
|
|
6
|
+
return !!(r || i);
|
|
104
7
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
checkoutProfile: void 0,
|
|
110
|
-
isLoading: !0,
|
|
111
|
-
error: null
|
|
112
|
-
});
|
|
113
|
-
if (o) {
|
|
114
|
-
const s = I(o);
|
|
115
|
-
return Promise.resolve().then(() => {
|
|
116
|
-
e.setState({
|
|
117
|
-
checkoutProfile: s,
|
|
118
|
-
isLoading: !1,
|
|
119
|
-
error: null
|
|
120
|
-
});
|
|
121
|
-
}), {
|
|
122
|
-
getState: e.getState.bind(e),
|
|
123
|
-
subscribe: e.subscribe.bind(e),
|
|
124
|
-
updateProfile: (a) => {
|
|
125
|
-
const i = I(a);
|
|
126
|
-
e.setState({
|
|
127
|
-
checkoutProfile: i,
|
|
128
|
-
isLoading: !1,
|
|
129
|
-
error: null
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
reload: async () => {
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const t = {
|
|
137
|
-
name: "Default Profile",
|
|
138
|
-
additionalPaymentMethods: {},
|
|
139
|
-
styles: {
|
|
140
|
-
fontSize: 14,
|
|
141
|
-
textColor: "#000000",
|
|
142
|
-
buttonColor: "#0070f3",
|
|
143
|
-
borderRadius: 4,
|
|
144
|
-
fontFamily: "system-ui",
|
|
145
|
-
buttonTextColor: "#ffffff",
|
|
146
|
-
buttonFontSize: 16
|
|
147
|
-
},
|
|
148
|
-
layout: {
|
|
149
|
-
actionButton: {
|
|
150
|
-
translationKey: null
|
|
151
|
-
},
|
|
152
|
-
billingFields: {
|
|
153
|
-
street: { enabled: !1 },
|
|
154
|
-
city: { enabled: !1 },
|
|
155
|
-
state: { enabled: !1 },
|
|
156
|
-
zipCode: { enabled: !1 },
|
|
157
|
-
firstName: { enabled: !1 },
|
|
158
|
-
lastName: { enabled: !1 },
|
|
159
|
-
country: { enabled: !1 }
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
appearance: {}
|
|
163
|
-
};
|
|
164
|
-
return Promise.resolve().then(() => {
|
|
165
|
-
e.setState({
|
|
166
|
-
checkoutProfile: t,
|
|
167
|
-
isLoading: !1,
|
|
168
|
-
error: null
|
|
169
|
-
});
|
|
170
|
-
}), {
|
|
171
|
-
getState: e.getState.bind(e),
|
|
172
|
-
subscribe: e.subscribe.bind(e),
|
|
173
|
-
updateProfile: (s) => {
|
|
174
|
-
const a = I(s);
|
|
175
|
-
e.setState({
|
|
176
|
-
checkoutProfile: a,
|
|
177
|
-
isLoading: !1,
|
|
178
|
-
error: null
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
reload: async () => {
|
|
182
|
-
}
|
|
183
|
-
};
|
|
8
|
+
function L(e) {
|
|
9
|
+
if (!e) return !1;
|
|
10
|
+
let { billingFields: t, shippingFields: n } = e, r = t?.firstName?.enabled && t?.lastName?.enabled, i = n?.firstName?.enabled && n?.lastName?.enabled;
|
|
11
|
+
return !!(r || i);
|
|
184
12
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region libs/checkout/src/components/checkout/form/AddressSection.ts
|
|
15
|
+
var R = new Set(["US", "CA"]), z = class extends v {
|
|
16
|
+
inputs = /* @__PURE__ */ new Map();
|
|
17
|
+
type;
|
|
18
|
+
onChange;
|
|
19
|
+
onBlur;
|
|
20
|
+
fieldsContainer;
|
|
21
|
+
translationFunc;
|
|
22
|
+
locale;
|
|
23
|
+
grouped;
|
|
24
|
+
currentCountry = "";
|
|
25
|
+
stateRow = null;
|
|
26
|
+
stateFieldConfig;
|
|
27
|
+
stateStyles;
|
|
28
|
+
constructor(e) {
|
|
29
|
+
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;
|
|
30
|
+
let { title: t, checkoutProfile: n, fieldsConfig: r, values: i, errors: a, touched: o } = e;
|
|
31
|
+
if (this.grouped) {
|
|
32
|
+
let e = document.createElement("h3");
|
|
33
|
+
e.className = "address-section-title", e.textContent = t, e.style.color = n.styles.textColor, e.style.fontFamily = `"${n.styles.fontFamily}", sans-serif`, e.style.fontSize = `${n.styles.fontSize}px`, e.style.fontWeight = "normal", this.getElement().appendChild(e);
|
|
34
|
+
}
|
|
35
|
+
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(n, r, i, a, o);
|
|
36
|
+
}
|
|
37
|
+
borderRadius(e, t, n, r, i) {
|
|
38
|
+
let a = (t) => t ? `${e}px` : "0px";
|
|
39
|
+
return `${a(t)} ${a(n)} ${a(r)} ${a(i)}`;
|
|
40
|
+
}
|
|
41
|
+
createFields(e, t, n, r, i) {
|
|
42
|
+
if (!this.grouped) {
|
|
43
|
+
this.createUngroupedFields(e, t, n, r, i);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let a = e.styles.borderRadius, o = {
|
|
47
|
+
color: e.styles.textColor,
|
|
48
|
+
fontSize: e.styles.fontSize,
|
|
49
|
+
fontFamily: e.styles.fontFamily
|
|
50
|
+
}, s = [];
|
|
51
|
+
t.street?.enabled && s.push({ kind: "street" });
|
|
52
|
+
let c = [];
|
|
53
|
+
t.firstName?.enabled && c.push("firstName"), t.lastName?.enabled && c.push("lastName"), c.length > 0 && s.push({
|
|
54
|
+
kind: "name",
|
|
55
|
+
fields: c
|
|
56
|
+
}), t.country?.enabled && s.push({ kind: "country" });
|
|
57
|
+
let l = [];
|
|
58
|
+
t.city?.enabled && l.push("city"), t.zipCode?.enabled && l.push("zipCode"), l.length > 0 && s.push({
|
|
59
|
+
kind: "cityZip",
|
|
60
|
+
fields: l
|
|
61
|
+
}), t.state?.enabled && s.push({ kind: "state" });
|
|
62
|
+
let u = s.length;
|
|
63
|
+
s.forEach((e, s) => {
|
|
64
|
+
let c = s === 0, l = s === u - 1, d = (e, t) => ({
|
|
65
|
+
...o,
|
|
66
|
+
borderRadius: this.borderRadius(a, c && e, c && t, l && t, l && e)
|
|
67
|
+
});
|
|
68
|
+
if (e.kind === "street") {
|
|
69
|
+
let e = this.createRow(["full"]), a = this.createInput("street", t.street?.label ?? this.translationFunc("address.addressLine1"), n.street, r.street, i.street, d(!0, !0), "street-address", t.street?.maxLength);
|
|
70
|
+
this.inputs.set("street", a), e.appendChild(a.getElement()), this.fieldsContainer.appendChild(e);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (e.kind === "name") {
|
|
74
|
+
let a = this.createRow(e.fields.map(() => "half")), o = e.fields.length === 1;
|
|
75
|
+
if (e.fields.includes("firstName")) {
|
|
76
|
+
let s = o || e.fields[e.fields.length - 1] === "firstName", c = this.createInput("firstName", t.firstName?.label ?? this.translationFunc("address.firstName"), n.firstName, r.firstName, i.firstName, d(!0, s), "given-name");
|
|
77
|
+
this.inputs.set("firstName", c), a.appendChild(c.getElement());
|
|
78
|
+
}
|
|
79
|
+
if (e.fields.includes("lastName")) {
|
|
80
|
+
let s = o || e.fields[0] === "lastName", c = this.createInput("lastName", t.lastName?.label ?? this.translationFunc("address.lastName"), n.lastName, r.lastName, i.lastName, d(s, !0), "family-name");
|
|
81
|
+
this.inputs.set("lastName", c), a.appendChild(c.getElement());
|
|
82
|
+
}
|
|
83
|
+
this.fieldsContainer.appendChild(a);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (e.kind === "country") {
|
|
87
|
+
let e = this.createRow(["full"]), a = this.createCountrySelect(n.country, r.country, i.country, d(!0, !0), t.country?.options, t.country?.label);
|
|
88
|
+
this.inputs.set("country", a), e.appendChild(a.getElement()), this.fieldsContainer.appendChild(e);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (e.kind === "cityZip") {
|
|
92
|
+
let a = this.createRow(e.fields.map(() => "half")), o = e.fields.length === 1;
|
|
93
|
+
if (e.fields.includes("city")) {
|
|
94
|
+
let s = o || e.fields[e.fields.length - 1] === "city", c = this.createInput("city", t.city?.label ?? this.translationFunc("address.townCity"), n.city, r.city, i.city, d(!0, s), "address-level2");
|
|
95
|
+
this.inputs.set("city", c), a.appendChild(c.getElement());
|
|
96
|
+
}
|
|
97
|
+
if (e.fields.includes("zipCode")) {
|
|
98
|
+
let s = o || e.fields[0] === "zipCode", c = this.createInput("zipCode", t.zipCode?.label ?? this.translationFunc("address.postalCode"), n.zipCode, r.zipCode, i.zipCode, d(s, !0), "postal-code");
|
|
99
|
+
this.inputs.set("zipCode", c), a.appendChild(c.getElement());
|
|
100
|
+
}
|
|
101
|
+
this.fieldsContainer.appendChild(a);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (e.kind === "state") {
|
|
105
|
+
let e = this.createRow(["full"]);
|
|
106
|
+
if (this.stateFieldConfig = t.state, this.stateRow = e, this.stateStyles = d(!0, !0), this.currentCountry = n.country, t.state?.hiddenForCountries?.includes(n.country) && (e.style.display = "none"), R.has(n.country)) {
|
|
107
|
+
let a = this.createStateSelect(n.state, r.state, i.state, this.stateStyles, n.country, t.state?.label);
|
|
108
|
+
this.inputs.set("state", a), e.appendChild(a.getElement());
|
|
109
|
+
} else {
|
|
110
|
+
let a = this.createInput("state", t.state?.label ?? this.translationFunc("address.state"), n.state, r.state, i.state, this.stateStyles, "address-level1");
|
|
111
|
+
this.inputs.set("state", a), e.appendChild(a.getElement());
|
|
112
|
+
}
|
|
113
|
+
this.fieldsContainer.appendChild(e);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
createRow(e) {
|
|
118
|
+
let t = document.createElement("div");
|
|
119
|
+
return t.className = `address-row address-row-${e.length === 1 ? "single" : "double"}`, t;
|
|
120
|
+
}
|
|
121
|
+
createInput(e, t, n, r, i, a, o, s) {
|
|
122
|
+
let c = `${this.type}Address.${e}`, l = new T({
|
|
123
|
+
name: c,
|
|
124
|
+
error: !1,
|
|
125
|
+
errorMsg: void 0,
|
|
126
|
+
styles: a,
|
|
127
|
+
maxLength: s,
|
|
128
|
+
...this.grouped ? { placeholder: t } : {
|
|
129
|
+
label: t,
|
|
130
|
+
placeholder: (() => {
|
|
131
|
+
let n = `address.placeholder.${e}`, r = this.translationFunc(n);
|
|
132
|
+
return r === n ? t : r;
|
|
133
|
+
})()
|
|
134
|
+
},
|
|
135
|
+
value: n,
|
|
136
|
+
autocomplete: o,
|
|
137
|
+
onChange: (e) => {
|
|
138
|
+
let t = e.target.value;
|
|
139
|
+
if (s && t.length >= s) {
|
|
140
|
+
let e = this.translationFunc("validation.maxLengthExceeded");
|
|
141
|
+
l.setError(!0, e.replace("{{max}}", String(s)));
|
|
142
|
+
} else l.setError(!1);
|
|
143
|
+
this.onChange(b({
|
|
144
|
+
type: "input",
|
|
145
|
+
target: {
|
|
146
|
+
name: c,
|
|
147
|
+
value: t
|
|
148
|
+
}
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return l.addEventListener("blur", (e) => {
|
|
153
|
+
this.onBlur(b({
|
|
154
|
+
type: "blur",
|
|
155
|
+
target: {
|
|
156
|
+
name: c,
|
|
157
|
+
value: e.target.value
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
}), l;
|
|
161
|
+
}
|
|
162
|
+
createCountrySelect(e, t, n, r, i, a) {
|
|
163
|
+
let o = `${this.type}Address.country`, s = E(i, this.locale), c = new x({
|
|
164
|
+
name: o,
|
|
165
|
+
error: !1,
|
|
166
|
+
errorMsg: void 0,
|
|
167
|
+
styles: r,
|
|
168
|
+
placeholder: this.translationFunc("address.chooseCountry"),
|
|
169
|
+
...!this.grouped && { label: a ?? this.translationFunc("address.chooseCountry") },
|
|
170
|
+
value: e,
|
|
171
|
+
options: s,
|
|
172
|
+
autocomplete: "country",
|
|
173
|
+
onChange: (e) => {
|
|
174
|
+
c.setError(!1);
|
|
175
|
+
let t = e.target.value;
|
|
176
|
+
this.onChange(b({
|
|
177
|
+
type: "change",
|
|
178
|
+
target: {
|
|
179
|
+
name: o,
|
|
180
|
+
value: t
|
|
181
|
+
}
|
|
182
|
+
})), this.handleCountryChange(t);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return c.addEventListener("blur", (e) => {
|
|
186
|
+
this.onBlur(b({
|
|
187
|
+
type: "blur",
|
|
188
|
+
target: {
|
|
189
|
+
name: o,
|
|
190
|
+
value: e.target.value
|
|
191
|
+
}
|
|
192
|
+
}));
|
|
193
|
+
}), c;
|
|
194
|
+
}
|
|
195
|
+
handleCountryChange(e) {
|
|
196
|
+
let t = this.currentCountry;
|
|
197
|
+
if (this.currentCountry = e, !this.stateRow || !this.stateFieldConfig?.enabled) return;
|
|
198
|
+
let n = this.stateFieldConfig.hiddenForCountries?.includes(t), r = this.stateFieldConfig.hiddenForCountries?.includes(e);
|
|
199
|
+
if (r && !n) {
|
|
200
|
+
this.stateRow.style.display = "none", this.clearStateValue();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (!r && n && (this.stateRow.style.display = ""), r) return;
|
|
204
|
+
let i = this.inputs.get("state") instanceof x, a = R.has(e);
|
|
205
|
+
if (i && a) {
|
|
206
|
+
let t = this.inputs.get("state");
|
|
207
|
+
if (t instanceof x) {
|
|
208
|
+
let n = e === "CA" ? "CA" : "US", r = k(n), i = n === "CA" ? this.translationFunc("address.chooseProvince") : this.translationFunc("address.chooseState");
|
|
209
|
+
t.setOptions(r, i);
|
|
210
|
+
}
|
|
211
|
+
this.clearStateValue();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (i !== a) {
|
|
215
|
+
this.rebuildStateField(e), this.clearStateValue();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
!i && !a && t !== e && this.clearStateValue();
|
|
219
|
+
}
|
|
220
|
+
rebuildStateField(e) {
|
|
221
|
+
if (!this.stateRow || !this.stateStyles) return;
|
|
222
|
+
let t = this.inputs.get("state");
|
|
223
|
+
if (t && (t.getElement().remove(), this.inputs.delete("state")), R.has(e)) {
|
|
224
|
+
let t = this.createStateSelect("", void 0, void 0, this.stateStyles, e, this.stateFieldConfig?.label);
|
|
225
|
+
this.inputs.set("state", t), this.stateRow.appendChild(t.getElement());
|
|
226
|
+
} else {
|
|
227
|
+
let e = this.createInput("state", this.stateFieldConfig?.label ?? this.translationFunc("address.state"), "", void 0, void 0, this.stateStyles, "address-level1");
|
|
228
|
+
this.inputs.set("state", e), this.stateRow.appendChild(e.getElement());
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
clearStateValue() {
|
|
232
|
+
let e = this.inputs.get("state");
|
|
233
|
+
e && e.setValue("");
|
|
234
|
+
let t = `${this.type}Address.state`;
|
|
235
|
+
this.onChange(b({
|
|
236
|
+
type: "input",
|
|
237
|
+
target: {
|
|
238
|
+
name: t,
|
|
239
|
+
value: ""
|
|
240
|
+
},
|
|
241
|
+
detail: { programmatic: !0 }
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
createStateSelect(e, t, n, r, i, a) {
|
|
245
|
+
let o = `${this.type}Address.state`, s = i === "CA" ? "CA" : "US", c = k(s), l = s === "CA" ? this.translationFunc("address.chooseProvince") : this.translationFunc("address.chooseState"), u = new x({
|
|
246
|
+
name: o,
|
|
247
|
+
error: !1,
|
|
248
|
+
errorMsg: void 0,
|
|
249
|
+
styles: r,
|
|
250
|
+
placeholder: l,
|
|
251
|
+
...!this.grouped && { label: a ?? l },
|
|
252
|
+
value: e,
|
|
253
|
+
options: c,
|
|
254
|
+
autocomplete: "address-level1",
|
|
255
|
+
onChange: (e) => {
|
|
256
|
+
u.setError(!1), this.onChange(b({
|
|
257
|
+
type: "change",
|
|
258
|
+
target: {
|
|
259
|
+
name: o,
|
|
260
|
+
value: e.target.value
|
|
261
|
+
}
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return u.addEventListener("blur", (e) => {
|
|
266
|
+
this.onBlur(b({
|
|
267
|
+
type: "blur",
|
|
268
|
+
target: {
|
|
269
|
+
name: o,
|
|
270
|
+
value: e.target.value
|
|
271
|
+
}
|
|
272
|
+
}));
|
|
273
|
+
}), u;
|
|
274
|
+
}
|
|
275
|
+
createUngroupedFields(e, t, n, r, i) {
|
|
276
|
+
let a = e.styles.borderRadius, o = {
|
|
277
|
+
color: e.styles.textColor,
|
|
278
|
+
fontSize: e.styles.fontSize,
|
|
279
|
+
fontFamily: e.styles.fontFamily,
|
|
280
|
+
borderRadius: `${a}px`
|
|
281
|
+
}, s = (e, a, s, c) => {
|
|
282
|
+
if (!t[e]?.enabled) return;
|
|
283
|
+
let l = t[e]?.label ?? this.translationFunc(a), u = this.createRow(["full"]), d = this.createInput(e, l, n[e], r[e], i[e], o, s, c);
|
|
284
|
+
this.inputs.set(e, d), u.appendChild(d.getElement()), this.fieldsContainer.appendChild(u);
|
|
285
|
+
};
|
|
286
|
+
if (s("firstName", "address.firstName", "given-name"), s("lastName", "address.lastName", "family-name"), s("street", "address.addressLine1", "street-address", t.street?.maxLength), s("city", "address.townCity", "address-level2"), t.country?.enabled) {
|
|
287
|
+
let e = t.country?.label ?? this.translationFunc("address.chooseCountry"), a = this.createRow(["full"]), s = this.createCountrySelect(n.country, r.country, i.country, o, t.country?.options, e);
|
|
288
|
+
this.inputs.set("country", s), a.appendChild(s.getElement()), this.fieldsContainer.appendChild(a);
|
|
289
|
+
}
|
|
290
|
+
if (t.state?.enabled) {
|
|
291
|
+
this.stateFieldConfig = t.state;
|
|
292
|
+
let e = this.createRow(["full"]);
|
|
293
|
+
this.stateRow = e, this.stateStyles = o, this.currentCountry = n.country, t.state?.hiddenForCountries?.includes(n.country) && (e.style.display = "none");
|
|
294
|
+
let a = R.has(n.country), s = t.state?.label ?? this.translationFunc("address.state");
|
|
295
|
+
if (a) {
|
|
296
|
+
let t = this.createStateSelect(n.state, r.state, i.state, o, n.country, s);
|
|
297
|
+
this.inputs.set("state", t), e.appendChild(t.getElement());
|
|
298
|
+
} else {
|
|
299
|
+
let t = this.createInput("state", s, n.state, r.state, i.state, o, "address-level1");
|
|
300
|
+
this.inputs.set("state", t), e.appendChild(t.getElement());
|
|
301
|
+
}
|
|
302
|
+
this.fieldsContainer.appendChild(e);
|
|
303
|
+
}
|
|
304
|
+
s("zipCode", "address.postalCode", "postal-code");
|
|
305
|
+
}
|
|
306
|
+
getValue(e) {
|
|
307
|
+
return this.inputs.get(e)?.getValue() ?? "";
|
|
308
|
+
}
|
|
309
|
+
getValues() {
|
|
310
|
+
return {
|
|
311
|
+
street: this.getValue("street"),
|
|
312
|
+
firstName: this.getValue("firstName"),
|
|
313
|
+
lastName: this.getValue("lastName"),
|
|
314
|
+
state: this.getValue("state"),
|
|
315
|
+
city: this.getValue("city"),
|
|
316
|
+
zipCode: this.getValue("zipCode"),
|
|
317
|
+
country: this.getValue("country")
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
setValue(e, t) {
|
|
321
|
+
this.inputs.get(e)?.setValue(t);
|
|
322
|
+
}
|
|
323
|
+
setValues(e) {
|
|
324
|
+
Object.entries(e).forEach(([e, t]) => {
|
|
325
|
+
t !== void 0 && this.setValue(e, t);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
setError(e, t, n) {
|
|
329
|
+
let r = this.inputs.get(e);
|
|
330
|
+
if (r) {
|
|
331
|
+
let e = r.getElement().querySelector("input") || r.getElement().querySelector("select");
|
|
332
|
+
document.activeElement !== e && r.setError(t, n);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
updateField(e, t, n, r) {
|
|
336
|
+
let i = this.inputs.get(e);
|
|
337
|
+
if (!i) return;
|
|
338
|
+
let a = i.getElement().querySelector("input") || i.getElement().querySelector("select"), o = i.getValue();
|
|
339
|
+
document.activeElement !== a && !(t === "" && o !== "") && this.setValue(e, t);
|
|
340
|
+
let s = !!(r && n);
|
|
341
|
+
this.setError(e, s, n);
|
|
342
|
+
}
|
|
343
|
+
updateAllFields(e, t, n) {
|
|
344
|
+
Object.keys(e).forEach((r) => {
|
|
345
|
+
this.updateField(r, e[r], t[r], !!n[r]);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
focus() {
|
|
349
|
+
let e = this.inputs.values().next().value;
|
|
350
|
+
e && e.focus();
|
|
351
|
+
}
|
|
352
|
+
}, B = class {
|
|
353
|
+
input = null;
|
|
354
|
+
isVgsMode;
|
|
355
|
+
vgsWrapper = null;
|
|
356
|
+
vgsContainer = null;
|
|
357
|
+
vgsHelperText = null;
|
|
358
|
+
wrapperElement;
|
|
359
|
+
_vgsFieldsReady = !1;
|
|
360
|
+
_fieldHeight = "38.5px";
|
|
361
|
+
_borderRadius = 0;
|
|
362
|
+
constructor(e) {
|
|
363
|
+
let { value: t, onChange: n, onBlur: r, errorMsg: i, checkoutProfile: a, translationFunc: o, autocomplete: s = "cc-name", isVgsMode: c = !1 } = e;
|
|
364
|
+
this.isVgsMode = c, this.wrapperElement = document.createElement("div"), c ? this.buildVgsLayout(a, o) : this.buildNativeLayout(t, n, r, i, a, o, s);
|
|
365
|
+
}
|
|
366
|
+
buildVgsLayout(e, t) {
|
|
367
|
+
let n = e.styles.borderRadius;
|
|
368
|
+
this._borderRadius = n;
|
|
369
|
+
let r = document.createElement("div");
|
|
370
|
+
r.style.marginBottom = "4px";
|
|
371
|
+
let i = document.createElement("label");
|
|
372
|
+
i.className = "input-label", i.textContent = t("cardholderNameLabel"), i.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, i.style.fontSize = `${e.styles.fontSize}px`, r.appendChild(i), this.wrapperElement.appendChild(r), this.vgsWrapper = document.createElement("div"), this.vgsWrapper.className = "vgs-wrap", this.vgsWrapper.style.position = "relative", this.vgsWrapper.style.borderRadius = `${n}px`, this.vgsWrapper.style.height = "38.5px", this.vgsWrapper.style.width = "100%", this.vgsWrapper.style.overflow = "hidden";
|
|
373
|
+
let a = document.createElement("div");
|
|
374
|
+
a.className = "vgs-field-skeleton", this.vgsWrapper.appendChild(a), 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 ee({ visible: !1 }), this.wrapperElement.appendChild(this.vgsHelperText.getElement());
|
|
375
|
+
}
|
|
376
|
+
buildNativeLayout(e, t, n, r, i, a, o) {
|
|
377
|
+
this.input = new T({
|
|
378
|
+
name: "name",
|
|
379
|
+
label: a("cardholderNameLabel"),
|
|
380
|
+
error: !1,
|
|
381
|
+
errorMsg: r,
|
|
382
|
+
styles: {
|
|
383
|
+
color: i.styles.textColor,
|
|
384
|
+
borderRadius: `${i.styles.borderRadius}px`,
|
|
385
|
+
fontSize: i.styles.fontSize,
|
|
386
|
+
fontFamily: i.styles.fontFamily
|
|
387
|
+
},
|
|
388
|
+
placeholder: a("cardholderNamePlaceholder"),
|
|
389
|
+
value: e,
|
|
390
|
+
autocomplete: o,
|
|
391
|
+
onChange: (e) => {
|
|
392
|
+
let n = e.target.value, r = n.replace(/[^a-zA-Z\s\-'.]/g, "");
|
|
393
|
+
n !== r && this.input?.setValue(r), this.input?.setError(!1), this.trim(), t(e);
|
|
394
|
+
}
|
|
395
|
+
}), this.input.addEventListener("blur", (e) => {
|
|
396
|
+
n(e);
|
|
397
|
+
}), this.wrapperElement.appendChild(this.input.getElement());
|
|
398
|
+
}
|
|
399
|
+
getVgsContainerId() {
|
|
400
|
+
return this.vgsContainer?.id;
|
|
401
|
+
}
|
|
402
|
+
handleVgsStateChange(e, t) {
|
|
403
|
+
if (!this.isVgsMode || !this.vgsWrapper) return;
|
|
404
|
+
let n = e[O.CARDHOLDER]?.isFocused;
|
|
405
|
+
if (this._vgsFieldsReady && (this.vgsWrapper.style.boxShadow = n ? "0 0 0 1px rgba(50, 151, 211, 0.7), 0 1px 1px 0 rgba(0, 0, 0, 0.07), 0 0 0 4px rgba(50, 151, 211, 0.3)" : "0 0 0 1px #e0e0e0, 0 2px 4px 0 rgba(0,0,0,0.07), 0 1px 1.5px 0 rgba(0,0,0,0.05)"), !t || !this.vgsHelperText) return;
|
|
406
|
+
let r = t[O.CARDHOLDER];
|
|
407
|
+
r ? (this.vgsHelperText.setText(r), this.vgsHelperText.toggleVisibility(!0)) : this.vgsHelperText.toggleVisibility(!1);
|
|
408
|
+
}
|
|
409
|
+
setFieldHeight(e) {
|
|
410
|
+
this._fieldHeight = e, this.vgsWrapper && (this.vgsWrapper.style.height = e);
|
|
411
|
+
}
|
|
412
|
+
setBorderRadius(e) {
|
|
413
|
+
this._borderRadius = e, this.vgsWrapper && (this.vgsWrapper.style.borderRadius = `${e}px`);
|
|
414
|
+
}
|
|
415
|
+
hideFakePlaceholder() {
|
|
416
|
+
if (!this.vgsWrapper) return;
|
|
417
|
+
this._vgsFieldsReady = !0, this.vgsWrapper.style.overflow = "visible", this.vgsWrapper.style.transition = "box-shadow 0.1s ease-in", this.vgsWrapper.style.boxShadow = "0 0 0 1px #e0e0e0, 0 2px 4px 0 rgba(0,0,0,0.07), 0 1px 1.5px 0 rgba(0,0,0,0.05)";
|
|
418
|
+
let e = this.vgsWrapper.querySelector(".vgs-field-skeleton");
|
|
419
|
+
e && e.remove(), this.vgsContainer?.querySelectorAll("iframe").forEach((e) => {
|
|
420
|
+
e.style.height = this._fieldHeight, e.style.borderRadius = `${this._borderRadius}px`;
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
getValue() {
|
|
424
|
+
return this.isVgsMode ? "" : this.input?.getValue() ?? "";
|
|
425
|
+
}
|
|
426
|
+
setValue(e) {
|
|
427
|
+
return this.isVgsMode || this.input?.setValue(e), this;
|
|
428
|
+
}
|
|
429
|
+
trim() {
|
|
430
|
+
if (this.isVgsMode) return this;
|
|
431
|
+
let e = this.getValue().trimStart();
|
|
432
|
+
return this.setValue(e), this;
|
|
433
|
+
}
|
|
434
|
+
setError(e, t) {
|
|
435
|
+
if (this.isVgsMode) return this;
|
|
436
|
+
let n = this.input?.getElement().querySelector("input");
|
|
437
|
+
return n && document.activeElement !== n && this.input?.setError(e, t), this;
|
|
438
|
+
}
|
|
439
|
+
getElement() {
|
|
440
|
+
return !this.isVgsMode && this.input ? this.input.getElement() : this.wrapperElement;
|
|
441
|
+
}
|
|
442
|
+
appendTo(e) {
|
|
443
|
+
return e.appendChild(this.getElement()), this;
|
|
444
|
+
}
|
|
445
|
+
focus() {
|
|
446
|
+
this.isVgsMode || this.input?.focus();
|
|
447
|
+
}
|
|
448
|
+
}, V = class extends v {
|
|
449
|
+
constructor() {
|
|
450
|
+
super("div", ["skeleton-container"]), this.createSkeletonElements();
|
|
451
|
+
}
|
|
452
|
+
createSkeletonElements() {
|
|
453
|
+
this.appendChild(this.createPaymentMethodSkeleton()), this.appendChild(this.createPaymentSeparatorSkeleton());
|
|
454
|
+
}
|
|
455
|
+
createPaymentMethodSkeleton() {
|
|
456
|
+
let e = S.createDiv(["skeleton-field"]), t = S.createDiv(["skeleton", "skeleton-payment-method"]);
|
|
457
|
+
return e.appendChild(t), e;
|
|
458
|
+
}
|
|
459
|
+
createPaymentSeparatorSkeleton() {
|
|
460
|
+
let e = S.createDiv(["payment-separator_container"]), t = S.createDiv(["payment-separator__line"]), n = S.createDiv(["skeleton", "skeleton-separator-text"]), r = S.createDiv(["payment-separator__line"]);
|
|
461
|
+
return e.appendChild(t), e.appendChild(n), e.appendChild(r), e;
|
|
462
|
+
}
|
|
463
|
+
}, H = class extends v {
|
|
464
|
+
constructor(e) {
|
|
465
|
+
let { translationFunc: t, checkoutProfile: n } = e;
|
|
466
|
+
super("div", ["payment-separator"]);
|
|
467
|
+
let r = this.getElement(), i = document.createElement("span");
|
|
468
|
+
i.className = "payment-separator__line";
|
|
469
|
+
let a = document.createElement("p");
|
|
470
|
+
a.textContent = t("pay-with-card"), a.className = "payment-separator__text", a.style.fontFamily = `${n.styles.fontFamily}, sans-serif`;
|
|
471
|
+
let o = document.createElement("span");
|
|
472
|
+
o.className = "payment-separator__line", r.appendChild(i), r.appendChild(a), r.appendChild(o);
|
|
473
|
+
}
|
|
474
|
+
}, U = class extends v {
|
|
475
|
+
paymentMethods;
|
|
476
|
+
paymentSeparator;
|
|
477
|
+
skeleton;
|
|
478
|
+
constructor(e) {
|
|
479
|
+
let { checkoutProfile: t, formData: n, onPaypalSubmit: r, onApplePaySubmit: i, supportedPaymentMethods: a, translationFunc: o, paymentId: s, checkoutKey: c, checkoutDetails: l, environment: u, countryCode: d } = e;
|
|
480
|
+
if (super("div", ["payment-methods"]), this.paymentMethods = /* @__PURE__ */ new Map(), !t?.additionalPaymentMethods) {
|
|
481
|
+
this.getElement().style.display = "none";
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (a === void 0) {
|
|
485
|
+
this.renderSkeleton();
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
let f = Object.entries(t.additionalPaymentMethods).filter(([e, t]) => {
|
|
489
|
+
let n = t.enabled, r = a ? a[e] === !0 : !0, i = !t.countries || d && t.countries.includes(d);
|
|
490
|
+
return n && r && i;
|
|
491
|
+
}).sort((e, t) => e[1].order - t[1].order);
|
|
492
|
+
if (f.length === 0) {
|
|
493
|
+
this.getElement().style.display = "none";
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
for (let [e] of f) switch (e) {
|
|
497
|
+
case "paypal":
|
|
498
|
+
if (r) {
|
|
499
|
+
let e = new D({
|
|
500
|
+
checkoutProfile: t,
|
|
501
|
+
formData: n,
|
|
502
|
+
onSubmit: r
|
|
503
|
+
});
|
|
504
|
+
this.paymentMethods.set("paypal", e), e.appendTo(this.getElement());
|
|
505
|
+
}
|
|
506
|
+
break;
|
|
507
|
+
case "applePay":
|
|
508
|
+
if (i && s && c) {
|
|
509
|
+
let e = t.appearance?.additionalPaymentMethods?.applePay, r = new re({
|
|
510
|
+
checkoutProfile: t,
|
|
511
|
+
formData: n,
|
|
512
|
+
onSubmit: i,
|
|
513
|
+
paymentId: s,
|
|
514
|
+
checkoutKey: c,
|
|
515
|
+
checkoutDetails: l,
|
|
516
|
+
environment: u,
|
|
517
|
+
displayName: e?.displayName,
|
|
518
|
+
requiredBillingContactFields: e?.requiredBillingContactFields,
|
|
519
|
+
requiredShippingContactFields: e?.requiredShippingContactFields
|
|
520
|
+
});
|
|
521
|
+
this.paymentMethods.set("applePay", r), r.appendTo(this.getElement());
|
|
522
|
+
}
|
|
523
|
+
break;
|
|
524
|
+
default:
|
|
525
|
+
console.warn(`[PaymentMethods] Unsupported payment method: ${e}`);
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
this.paymentMethods.size > 0 && (this.paymentSeparator = new H({
|
|
529
|
+
translationFunc: o,
|
|
530
|
+
checkoutProfile: t
|
|
531
|
+
}), this.getElement().appendChild(this.paymentSeparator.getElement()));
|
|
532
|
+
}
|
|
533
|
+
renderSkeleton() {
|
|
534
|
+
this.skeleton = new V(), this.getElement().appendChild(this.skeleton.getElement());
|
|
535
|
+
}
|
|
536
|
+
updateFormData(e) {
|
|
537
|
+
let t = this.paymentMethods.get("paypal");
|
|
538
|
+
t && t.updateFormData(e);
|
|
539
|
+
let n = this.paymentMethods.get("applePay");
|
|
540
|
+
return n && n.updateFormData(e), this;
|
|
541
|
+
}
|
|
542
|
+
hasVisiblePaymentMethods() {
|
|
543
|
+
return this.paymentMethods.size > 0 && this.getElement().style.display !== "none";
|
|
544
|
+
}
|
|
545
|
+
}, W = 17, G = class extends v {
|
|
546
|
+
styles;
|
|
547
|
+
isHovered = !1;
|
|
548
|
+
constructor(e) {
|
|
549
|
+
super("button", ["button"], { type: "submit" }), this.styles = e.styles, this.setText(e.text), this.getElement().disabled = e.disabled ?? !1, e.disabled ? this.addClass("disabled") : this.addClass("valid"), this.applyStyles(), this.addEventListener("mouseenter", () => this.handleMouseEnter()), this.addEventListener("mouseleave", () => this.handleMouseLeave());
|
|
550
|
+
}
|
|
551
|
+
applyStyles() {
|
|
552
|
+
let e = this.getElement();
|
|
553
|
+
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 === W ? "100vmax" : `${this.styles.borderRadius}px`, e.style.fontSize = `${this.styles.fontSize}px`, e.style.fontFamily = `${this.styles.fontFamily}, sans-serif`;
|
|
554
|
+
}
|
|
555
|
+
handleMouseEnter() {
|
|
556
|
+
this.isHovered = !0, this.applyStyles();
|
|
557
|
+
}
|
|
558
|
+
handleMouseLeave() {
|
|
559
|
+
this.isHovered = !1, this.applyStyles();
|
|
560
|
+
}
|
|
561
|
+
setDisabled(e) {
|
|
562
|
+
return this.getElement().disabled = e, e ? (this.addClass("disabled"), this.removeClass("valid")) : (this.removeClass("disabled"), this.addClass("valid")), this.applyStyles(), this;
|
|
563
|
+
}
|
|
564
|
+
}, K = class {
|
|
565
|
+
button;
|
|
566
|
+
constructor(e) {
|
|
567
|
+
let { disabled: t, checkoutProfile: n, translationFunc: r } = e;
|
|
568
|
+
this.button = new G({
|
|
569
|
+
text: r(`buttonTexts.${n?.layout.actionButton.translationKey}`),
|
|
570
|
+
styles: {
|
|
571
|
+
backgroundColor: n.styles.buttonColor,
|
|
572
|
+
color: n.styles.buttonTextColor,
|
|
573
|
+
fontFamily: n.styles.fontFamily,
|
|
574
|
+
borderRadius: n.styles.borderRadius,
|
|
575
|
+
fontSize: n.styles.buttonFontSize
|
|
576
|
+
},
|
|
577
|
+
disabled: t
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
getElement() {
|
|
581
|
+
return this.button.getElement();
|
|
582
|
+
}
|
|
583
|
+
setDisabled(e) {
|
|
584
|
+
return this.button.setDisabled(e), this;
|
|
585
|
+
}
|
|
586
|
+
addEventListener(e, t, n) {
|
|
587
|
+
return this.button.addEventListener(e, t, n), this;
|
|
588
|
+
}
|
|
589
|
+
appendTo(e) {
|
|
590
|
+
return this.button.appendTo(e), this;
|
|
591
|
+
}
|
|
592
|
+
}, q = class {
|
|
593
|
+
formElement;
|
|
594
|
+
focusManager;
|
|
595
|
+
translationFunc;
|
|
596
|
+
locale;
|
|
597
|
+
onFieldFocus;
|
|
598
|
+
onChange;
|
|
599
|
+
onBlur;
|
|
600
|
+
onPaypalSubmit;
|
|
601
|
+
onApplePaySubmit;
|
|
602
|
+
supportedPaymentMethods;
|
|
603
|
+
paymentId;
|
|
604
|
+
checkoutKey;
|
|
605
|
+
checkoutDetails;
|
|
606
|
+
environment;
|
|
607
|
+
vgsService;
|
|
608
|
+
onVgsStateChange;
|
|
609
|
+
emailField;
|
|
610
|
+
phoneNumberField;
|
|
611
|
+
phonePlaceholder;
|
|
612
|
+
cardSection;
|
|
613
|
+
cardholderSection;
|
|
614
|
+
submitButton;
|
|
615
|
+
paymentMethods;
|
|
616
|
+
billingAddressSection;
|
|
617
|
+
shippingAddressSection;
|
|
618
|
+
cardSectionSkeleton;
|
|
619
|
+
cardholderSectionSkeleton;
|
|
620
|
+
isCheckoutDetailsLoaded = !1;
|
|
621
|
+
emailFocusHandler;
|
|
622
|
+
phoneNumberFocusHandler;
|
|
623
|
+
cardExpiryFocusHandler;
|
|
624
|
+
cardNumberFocusHandler;
|
|
625
|
+
cardCvvFocusHandler;
|
|
626
|
+
nameFocusHandler;
|
|
627
|
+
constructor(e) {
|
|
628
|
+
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;
|
|
629
|
+
}
|
|
630
|
+
createPaymentMethods(e, t, n = !1) {
|
|
631
|
+
try {
|
|
632
|
+
if (!e?.additionalPaymentMethods || Object.keys(e.additionalPaymentMethods).length === 0 || !Object.values(e.additionalPaymentMethods).some((e) => e.enabled)) return;
|
|
633
|
+
this.paymentMethods = new U({
|
|
634
|
+
checkoutProfile: e,
|
|
635
|
+
formData: t,
|
|
636
|
+
supportedPaymentMethods: this.supportedPaymentMethods,
|
|
637
|
+
translationFunc: this.translationFunc,
|
|
638
|
+
onPaypalSubmit: this.onPaypalSubmit,
|
|
639
|
+
onApplePaySubmit: this.onApplePaySubmit,
|
|
640
|
+
paymentId: this.paymentId,
|
|
641
|
+
checkoutKey: this.checkoutKey,
|
|
642
|
+
checkoutDetails: this.checkoutDetails,
|
|
643
|
+
environment: this.environment,
|
|
644
|
+
countryCode: this.checkoutDetails?.countryCode
|
|
645
|
+
}), n ? this.formElement.insertBefore(this.paymentMethods.getElement(), this.formElement.firstChild) : this.formElement.appendChild(this.paymentMethods.getElement());
|
|
646
|
+
} catch (e) {
|
|
647
|
+
throw console.error("Error creating payment methods:", e), e;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
createEmailField(e, t, n, r) {
|
|
651
|
+
try {
|
|
652
|
+
let i = e.layout.billingFields && Object.values(e.layout.billingFields).some((e) => e?.enabled) || e.layout.shippingFields && Object.values(e.layout.shippingFields).some((e) => e?.enabled);
|
|
653
|
+
this.emailField = new C({
|
|
654
|
+
value: t.email,
|
|
655
|
+
onChange: this.onChange,
|
|
656
|
+
onBlur: this.onBlur,
|
|
657
|
+
onTab: i ? void 0 : () => this.focusManager.focusField(e.layout.phoneNumber?.enabled ? "phoneNumber" : "cardNumber"),
|
|
658
|
+
error: !!(n.email && r.email),
|
|
659
|
+
errorMsg: n.email,
|
|
660
|
+
checkoutProfile: e,
|
|
661
|
+
translationFunc: this.translationFunc
|
|
662
|
+
}), 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());
|
|
663
|
+
} catch (e) {
|
|
664
|
+
throw console.error("Error creating email field:", e), e;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
createPhoneNumberField(e, t, n, r) {
|
|
668
|
+
let i = document.createElement("div");
|
|
669
|
+
this.phonePlaceholder = i, this.formElement.appendChild(i), f().then(({ PhoneNumberField: a }) => {
|
|
670
|
+
i.isConnected && (this.phoneNumberField = new a({
|
|
671
|
+
value: t.phoneNumber ?? "",
|
|
672
|
+
onChange: this.onChange,
|
|
673
|
+
onBlur: this.onBlur,
|
|
674
|
+
onTab: () => this.focusManager.focusField("cardNumber"),
|
|
675
|
+
error: !!(n.phoneNumber && r.phoneNumber),
|
|
676
|
+
errorMsg: n.phoneNumber,
|
|
677
|
+
checkoutProfile: e,
|
|
678
|
+
translationFunc: this.translationFunc,
|
|
679
|
+
defaultCountry: e.layout.phoneNumber?.defaultCountry || "US",
|
|
680
|
+
allowedCountries: e.layout.phoneNumber?.allowedCountries,
|
|
681
|
+
locale: this.locale
|
|
682
|
+
}), this.phoneNumberFocusHandler = () => this.onFieldFocus("phoneNumber"), this.phoneNumberField.getElement().addEventListener("focus", this.phoneNumberFocusHandler, !0), this.focusManager.registerField("phoneNumber", this.phoneNumberField), i.replaceWith(this.phoneNumberField.getElement()), this.phonePlaceholder = void 0);
|
|
683
|
+
}).catch((e) => {
|
|
684
|
+
console.error("Error creating phone number field:", e), i.remove(), this.phonePlaceholder = void 0;
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
setCheckoutDetailsLoaded(e) {
|
|
688
|
+
this.isCheckoutDetailsLoaded = e;
|
|
689
|
+
}
|
|
690
|
+
createCardSection(e, t, n, r) {
|
|
691
|
+
try {
|
|
692
|
+
if (!this.isCheckoutDetailsLoaded) {
|
|
693
|
+
this.cardSectionSkeleton = this.buildCardSkeleton(e), this.formElement.appendChild(this.cardSectionSkeleton);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
if (this.cardSection = new y({
|
|
697
|
+
checkoutProfile: e,
|
|
698
|
+
cardNumber: t.cardNumber,
|
|
699
|
+
cardNumberError: n.cardNumber,
|
|
700
|
+
cardNumberTouched: !!r.cardNumber,
|
|
701
|
+
cardCvv: t.cardCvv,
|
|
702
|
+
cardCvvError: n.cardCvv,
|
|
703
|
+
cardCvvTouched: !!r.cardCvv,
|
|
704
|
+
cardExpiry: t.cardExpiry,
|
|
705
|
+
cardExpiryError: n.cardExpiry,
|
|
706
|
+
cardExpiryTouched: !!r.cardExpiry,
|
|
707
|
+
onChange: this.onChange,
|
|
708
|
+
onBlur: this.onBlur,
|
|
709
|
+
onCardBrandChange: () => {
|
|
710
|
+
t.cardCvv && this.onBlur(b({
|
|
711
|
+
type: "blur",
|
|
712
|
+
target: {
|
|
713
|
+
name: "cardCvv",
|
|
714
|
+
value: t.cardCvv
|
|
715
|
+
}
|
|
716
|
+
}));
|
|
717
|
+
},
|
|
718
|
+
translationFunc: this.translationFunc,
|
|
719
|
+
vgsService: this.vgsService,
|
|
720
|
+
onVgsStateChange: this.onVgsStateChange
|
|
721
|
+
}), this.vgsService) this.cardSection.setOnVgsAutoFocus((e) => {
|
|
722
|
+
this.onFieldFocus(e);
|
|
723
|
+
});
|
|
724
|
+
else {
|
|
725
|
+
let e = this.cardSection.getElement().querySelector("input[name=\"cardExpiry\"]");
|
|
726
|
+
e && (this.cardExpiryFocusHandler = () => this.onFieldFocus("cardExpiry"), e.addEventListener("focus", this.cardExpiryFocusHandler));
|
|
727
|
+
let t = this.cardSection.getElement().querySelector("input[name=\"cardNumber\"]");
|
|
728
|
+
t && (this.cardNumberFocusHandler = () => this.onFieldFocus("cardNumber"), t.addEventListener("focus", this.cardNumberFocusHandler));
|
|
729
|
+
let n = this.cardSection.getElement().querySelector("input[name=\"cardCvv\"]");
|
|
730
|
+
n && (this.cardCvvFocusHandler = () => this.onFieldFocus("cardCvv"), n.addEventListener("focus", this.cardCvvFocusHandler));
|
|
731
|
+
}
|
|
732
|
+
this.focusManager.registerField("cardNumber", { focus: () => this.cardSection?.focusField("cardNumber") }), this.focusManager.registerField("cardExpiry", { focus: () => this.cardSection?.focusField("cardExpiry") }), this.focusManager.registerField("cardCvv", { focus: () => this.cardSection?.focusField("cardCvv") }), this.formElement.appendChild(this.cardSection.getElement());
|
|
733
|
+
} catch (e) {
|
|
734
|
+
throw console.error("Error creating card section:", e), e;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
createCardholderSection(e, t, n, r) {
|
|
738
|
+
try {
|
|
739
|
+
if (!this.isCheckoutDetailsLoaded) {
|
|
740
|
+
this.cardholderSectionSkeleton = this.buildCardholderSkeleton(e), this.formElement.appendChild(this.cardholderSectionSkeleton);
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
if (this.cardholderSection = new B({
|
|
744
|
+
value: t.name,
|
|
745
|
+
onChange: this.onChange,
|
|
746
|
+
onBlur: this.onBlur,
|
|
747
|
+
error: !!(n.name && r.name),
|
|
748
|
+
errorMsg: n.name,
|
|
749
|
+
checkoutProfile: e,
|
|
750
|
+
translationFunc: this.translationFunc,
|
|
751
|
+
isVgsMode: !!this.vgsService
|
|
752
|
+
}), !this.vgsService) {
|
|
753
|
+
let e = this.cardholderSection.getElement().querySelector("input[name=\"name\"]");
|
|
754
|
+
e && (this.nameFocusHandler = () => this.onFieldFocus("name"), e.addEventListener("focus", this.nameFocusHandler));
|
|
755
|
+
}
|
|
756
|
+
this.focusManager.registerField("name", this.cardholderSection), this.formElement.appendChild(this.cardholderSection.getElement());
|
|
757
|
+
} catch (e) {
|
|
758
|
+
throw console.error("Error creating cardholder section:", e), e;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
createBillingAddressSection(e, t, n, r) {
|
|
762
|
+
try {
|
|
763
|
+
let i = e.layout.billingFields;
|
|
764
|
+
if (!i || !Object.values(i).some((e) => e?.enabled)) return;
|
|
765
|
+
let a = {
|
|
766
|
+
street: "",
|
|
767
|
+
firstName: "",
|
|
768
|
+
lastName: "",
|
|
769
|
+
state: "",
|
|
770
|
+
city: "",
|
|
771
|
+
zipCode: "",
|
|
772
|
+
country: ""
|
|
773
|
+
};
|
|
774
|
+
this.billingAddressSection = new z({
|
|
775
|
+
type: "billing",
|
|
776
|
+
title: this.translationFunc("address.billingTitle"),
|
|
777
|
+
checkoutProfile: e,
|
|
778
|
+
fieldsConfig: i,
|
|
779
|
+
values: t.billingAddress ?? a,
|
|
780
|
+
errors: n.billingAddress ?? {},
|
|
781
|
+
touched: r.billingAddress ?? {},
|
|
782
|
+
onChange: this.onChange,
|
|
783
|
+
onBlur: this.onBlur,
|
|
784
|
+
translationFunc: this.translationFunc,
|
|
785
|
+
locale: this.locale,
|
|
786
|
+
grouped: e.layout.grouped
|
|
787
|
+
}), this.formElement.appendChild(this.billingAddressSection.getElement());
|
|
788
|
+
} catch (e) {
|
|
789
|
+
throw console.error("Error creating billing address section:", e), e;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
createShippingAddressSection(e, t, n, r) {
|
|
793
|
+
try {
|
|
794
|
+
let i = e.layout.shippingFields;
|
|
795
|
+
if (!i || !Object.values(i).some((e) => e?.enabled)) return;
|
|
796
|
+
let a = {
|
|
797
|
+
street: "",
|
|
798
|
+
firstName: "",
|
|
799
|
+
lastName: "",
|
|
800
|
+
state: "",
|
|
801
|
+
city: "",
|
|
802
|
+
zipCode: "",
|
|
803
|
+
country: ""
|
|
804
|
+
};
|
|
805
|
+
this.shippingAddressSection = new z({
|
|
806
|
+
type: "shipping",
|
|
807
|
+
title: this.translationFunc("address.shippingTitle"),
|
|
808
|
+
checkoutProfile: e,
|
|
809
|
+
fieldsConfig: i,
|
|
810
|
+
values: t.shippingAddress ?? a,
|
|
811
|
+
errors: n.shippingAddress ?? {},
|
|
812
|
+
touched: r.shippingAddress ?? {},
|
|
813
|
+
onChange: this.onChange,
|
|
814
|
+
onBlur: this.onBlur,
|
|
815
|
+
translationFunc: this.translationFunc,
|
|
816
|
+
locale: this.locale,
|
|
817
|
+
grouped: e.layout.grouped
|
|
818
|
+
}), this.formElement.appendChild(this.shippingAddressSection.getElement());
|
|
819
|
+
} catch (e) {
|
|
820
|
+
throw console.error("Error creating shipping address section:", e), e;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
createSubmitButton(e, t) {
|
|
824
|
+
try {
|
|
825
|
+
this.submitButton = new K({
|
|
826
|
+
disabled: t,
|
|
827
|
+
checkoutProfile: e,
|
|
828
|
+
translationFunc: this.translationFunc
|
|
829
|
+
}), this.formElement.appendChild(this.submitButton.getElement());
|
|
830
|
+
} catch (e) {
|
|
831
|
+
throw console.error("Error creating submit button:", e), e;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
updateEmailField(e, t, n) {
|
|
835
|
+
this.emailField && (this.emailField.setValue(e), this.emailField.setError(t, n));
|
|
836
|
+
}
|
|
837
|
+
updatePhoneNumberField(e, t, n) {
|
|
838
|
+
this.phoneNumberField && (this.phoneNumberField.setValue(e), this.phoneNumberField.setError(t, n));
|
|
839
|
+
}
|
|
840
|
+
updateCardSection(e, t, n, r, i, a, o, s, c) {
|
|
841
|
+
this.cardSection && (this.cardSection.updateCardNumber(e, t, n), this.cardSection.updateCardCvv(r, i, a), this.cardSection.updateCardExpiry(o, s, c));
|
|
842
|
+
}
|
|
843
|
+
updateCardholderSection(e, t, n) {
|
|
844
|
+
this.cardholderSection && (this.cardholderSection.setValue(e), this.cardholderSection.setError(t, n));
|
|
845
|
+
}
|
|
846
|
+
updateBillingAddressSection(e, t, n) {
|
|
847
|
+
this.billingAddressSection && this.billingAddressSection.updateAllFields(e, t, n);
|
|
848
|
+
}
|
|
849
|
+
updateShippingAddressSection(e, t, n) {
|
|
850
|
+
this.shippingAddressSection && this.shippingAddressSection.updateAllFields(e, t, n);
|
|
851
|
+
}
|
|
852
|
+
updateSubmitButton(e) {
|
|
853
|
+
this.submitButton && this.submitButton.setDisabled(e);
|
|
854
|
+
}
|
|
855
|
+
updatePaymentMethods(e) {
|
|
856
|
+
this.paymentMethods && this.paymentMethods.updateFormData(e);
|
|
857
|
+
}
|
|
858
|
+
removePaymentMethods() {
|
|
859
|
+
this.paymentMethods &&= (this.paymentMethods.getElement().remove(), void 0);
|
|
860
|
+
}
|
|
861
|
+
updateSupportedPaymentMethods(e) {
|
|
862
|
+
this.supportedPaymentMethods = e;
|
|
863
|
+
}
|
|
864
|
+
updatePaymentDetails(e, t, n) {
|
|
865
|
+
this.paymentId = e, this.checkoutKey = t, this.checkoutDetails = n;
|
|
866
|
+
}
|
|
867
|
+
hasComponents() {
|
|
868
|
+
return !!this.emailField;
|
|
869
|
+
}
|
|
870
|
+
setVgsService(e) {
|
|
871
|
+
this.vgsService = e;
|
|
872
|
+
}
|
|
873
|
+
buildCardSkeleton(e) {
|
|
874
|
+
let t = e.styles.borderRadius, n = document.createElement("div"), r = document.createElement("div");
|
|
875
|
+
r.style.marginBottom = "4px";
|
|
876
|
+
let i = document.createElement("label");
|
|
877
|
+
i.className = "input-label", i.textContent = this.translationFunc("cardInformation"), i.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, r.appendChild(i), n.appendChild(r);
|
|
878
|
+
let a = document.createElement("div");
|
|
879
|
+
a.className = "vgs-card-group", a.style.borderRadius = `${t}px`, a.style.background = "#fff", a.style.display = "flex", a.style.flexDirection = "column", a.style.gap = "8px";
|
|
880
|
+
let o = document.createElement("div");
|
|
881
|
+
o.className = "card-number-row", o.style.position = "relative", o.style.height = "38.5px", o.style.overflow = "hidden", o.style.borderRadius = `${t}px`, o.appendChild(this.createSkeletonDiv()), a.appendChild(o);
|
|
882
|
+
let s = document.createElement("div");
|
|
883
|
+
s.style.display = "flex", s.style.gap = "8px";
|
|
884
|
+
let c = document.createElement("div");
|
|
885
|
+
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()), s.appendChild(c);
|
|
886
|
+
let l = document.createElement("div");
|
|
887
|
+
return l.style.position = "relative", l.style.flex = "1", l.style.height = "38.5px", l.style.overflow = "hidden", l.style.borderRadius = `${t}px`, l.appendChild(this.createSkeletonDiv()), s.appendChild(l), a.appendChild(s), n.appendChild(a), n;
|
|
888
|
+
}
|
|
889
|
+
createSkeletonDiv() {
|
|
890
|
+
let e = document.createElement("div");
|
|
891
|
+
return e.className = "vgs-field-skeleton", e;
|
|
892
|
+
}
|
|
893
|
+
buildCardholderSkeleton(e) {
|
|
894
|
+
let t = e.styles.borderRadius, n = document.createElement("div"), r = document.createElement("div");
|
|
895
|
+
r.style.marginBottom = "4px";
|
|
896
|
+
let i = document.createElement("label");
|
|
897
|
+
i.className = "input-label", i.textContent = this.translationFunc("cardholderNameLabel"), i.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, r.appendChild(i), n.appendChild(r);
|
|
898
|
+
let a = document.createElement("div");
|
|
899
|
+
return a.style.position = "relative", a.style.borderRadius = `${t}px`, a.style.height = "38.5px", a.style.width = "100%", a.style.overflow = "hidden", a.style.background = "#fff", a.appendChild(this.createSkeletonDiv()), n.appendChild(a), n;
|
|
900
|
+
}
|
|
901
|
+
async mountVgsFields(e) {
|
|
902
|
+
if (!this.vgsService || !this.cardSection) return;
|
|
903
|
+
await this.vgsService.whenReady();
|
|
904
|
+
let t = this.cardSection.getVgsContainerIds(), n = this.cardholderSection?.getVgsContainerId(), r = await F(e.styles.fontFamily), i = this.cardSection.buildVgsFieldCss(e, r);
|
|
905
|
+
if (this.cardholderSection && i.cardholderName) {
|
|
906
|
+
let e = i.cardholderName;
|
|
907
|
+
typeof e.height == "string" && this.cardholderSection.setFieldHeight(e.height);
|
|
908
|
+
let t = e["border-radius"];
|
|
909
|
+
typeof t == "string" && this.cardholderSection.setBorderRadius(parseFloat(t));
|
|
910
|
+
}
|
|
911
|
+
this.vgsService.mountCardFields({
|
|
912
|
+
cardNumber: t.cardNumber ? `#${t.cardNumber}` : void 0,
|
|
913
|
+
cardExpiry: t.cardExpiry ? `#${t.cardExpiry}` : void 0,
|
|
914
|
+
cardCvv: t.cardCvv ? `#${t.cardCvv}` : void 0,
|
|
915
|
+
cardholderName: n ? `#${n}` : void 0
|
|
916
|
+
}, i, {
|
|
917
|
+
cardNumber: "1234 5678 9012 3456",
|
|
918
|
+
cardExpiry: this.translationFunc("cardExpiry"),
|
|
919
|
+
cardCvv: "CVV",
|
|
920
|
+
cardholderName: this.translationFunc("cardholderNamePlaceholder")
|
|
921
|
+
}, (e) => this.cardSection?.updateVgsCardBrand(e)), this.vgsService.waitForFieldsReady().then(() => {
|
|
922
|
+
requestAnimationFrame(() => {
|
|
923
|
+
this.cardSection?.hideFakePlaceholders(), this.cardholderSection?.hideFakePlaceholder();
|
|
924
|
+
});
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
handleVgsStateChange(e, t) {
|
|
928
|
+
this.cardSection?.handleVgsStateChange(e, t), this.cardholderSection?.handleVgsStateChange(e, t);
|
|
929
|
+
}
|
|
930
|
+
cleanup() {
|
|
931
|
+
if (this.emailField) {
|
|
932
|
+
let e = this.emailField.getElement().querySelector("input[name=\"email\"]");
|
|
933
|
+
e && this.emailFocusHandler && e.removeEventListener("focus", this.emailFocusHandler), this.emailField.getElement().remove(), this.emailField = void 0;
|
|
934
|
+
}
|
|
935
|
+
if (this.phonePlaceholder &&= (this.phonePlaceholder.remove(), void 0), this.phoneNumberField) {
|
|
936
|
+
let e = this.phoneNumberField.getElement().querySelector("input[name=\"phoneNumber\"]");
|
|
937
|
+
e && this.phoneNumberFocusHandler && e.removeEventListener("focus", this.phoneNumberFocusHandler), this.phoneNumberField.getElement().remove(), this.phoneNumberField = void 0;
|
|
938
|
+
}
|
|
939
|
+
if (this.cardSectionSkeleton &&= (this.cardSectionSkeleton.remove(), void 0), this.cardSection) {
|
|
940
|
+
let e = this.cardSection.getElement().querySelector("input[name=\"cardExpiry\"]");
|
|
941
|
+
e && this.cardExpiryFocusHandler && e.removeEventListener("focus", this.cardExpiryFocusHandler);
|
|
942
|
+
let t = this.cardSection.getElement().querySelector("input[name=\"cardNumber\"]");
|
|
943
|
+
t && this.cardNumberFocusHandler && t.removeEventListener("focus", this.cardNumberFocusHandler);
|
|
944
|
+
let n = this.cardSection.getElement().querySelector("input[name=\"cardCvv\"]");
|
|
945
|
+
n && this.cardCvvFocusHandler && n.removeEventListener("focus", this.cardCvvFocusHandler), this.cardSection.getElement().remove(), this.cardSection = void 0;
|
|
946
|
+
}
|
|
947
|
+
if (this.cardholderSectionSkeleton &&= (this.cardholderSectionSkeleton.remove(), void 0), this.cardholderSection) {
|
|
948
|
+
let e = this.cardholderSection.getElement().querySelector("input[name=\"name\"]");
|
|
949
|
+
e && this.nameFocusHandler && e.removeEventListener("focus", this.nameFocusHandler), this.cardholderSection.getElement().remove(), this.cardholderSection = void 0;
|
|
950
|
+
}
|
|
951
|
+
this.billingAddressSection &&= (this.billingAddressSection.getElement().remove(), void 0), this.shippingAddressSection &&= (this.shippingAddressSection.getElement().remove(), void 0), this.submitButton &&= (this.submitButton.getElement().remove(), void 0), this.paymentMethods &&= (this.paymentMethods.getElement().remove(), void 0);
|
|
952
|
+
}
|
|
953
|
+
}, J = class {
|
|
954
|
+
formManager;
|
|
955
|
+
focusManager;
|
|
956
|
+
onFormSubmit;
|
|
957
|
+
onUIUpdate;
|
|
958
|
+
localTouchedFields = /* @__PURE__ */ new Set();
|
|
959
|
+
constructor(e) {
|
|
960
|
+
this.formManager = e.formManager, this.focusManager = e.focusManager, this.onFormSubmit = e.onFormSubmit, this.onUIUpdate = e.onUIUpdate;
|
|
961
|
+
}
|
|
962
|
+
handleChange = (e) => {
|
|
963
|
+
let { name: t, value: n } = e.target, r = t;
|
|
964
|
+
this.formManager.handleChange(r, n), e instanceof CustomEvent && e.detail?.programmatic ? this.localTouchedFields.delete(r) : this.localTouchedFields.has(r) || (this.localTouchedFields.add(r), this.formManager.handleBlur(r, n));
|
|
965
|
+
let { formData: i, errors: a, touched: o } = this.formManager.getFormState();
|
|
966
|
+
this.focusManager.handleStateUpdate(i, a, o);
|
|
967
|
+
};
|
|
968
|
+
handleBlur = (e) => {
|
|
969
|
+
let { name: t, value: n } = e.target, r = t;
|
|
970
|
+
this.localTouchedFields.add(r), this.formManager.handleBlur(r, n), setTimeout(() => {
|
|
971
|
+
this.onUIUpdate();
|
|
972
|
+
}, 0);
|
|
973
|
+
let { formData: i, errors: a, touched: o } = this.formManager.getFormState();
|
|
974
|
+
o[r] || this.focusManager.handleStateUpdate(i, a, o);
|
|
975
|
+
};
|
|
976
|
+
handleSubmit = async (e) => {
|
|
977
|
+
e.preventDefault(), await this.onFormSubmit(e);
|
|
978
|
+
};
|
|
979
|
+
handleKeyDown = (e) => {
|
|
980
|
+
e.key === "Enter" && (e.target instanceof HTMLTextAreaElement || (e.preventDefault(), this.handleSubmit(e)));
|
|
981
|
+
};
|
|
982
|
+
handleFieldFocus = (e) => {
|
|
983
|
+
this.focusManager.handleFieldFocus(e);
|
|
984
|
+
};
|
|
985
|
+
syncTouchedFields(e) {
|
|
986
|
+
Object.keys(e).forEach((t) => {
|
|
987
|
+
e[t] && this.localTouchedFields.add(t);
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
clearTouchedFields() {
|
|
991
|
+
this.localTouchedFields.clear();
|
|
992
|
+
}
|
|
993
|
+
}, Y = class {
|
|
994
|
+
formManager;
|
|
995
|
+
checkoutProfile;
|
|
996
|
+
formElement;
|
|
997
|
+
onUIUpdate;
|
|
998
|
+
onProfileLoaded;
|
|
999
|
+
onError;
|
|
1000
|
+
onLoadingChange;
|
|
1001
|
+
fontCleanup;
|
|
1002
|
+
isSubmitting = !1;
|
|
1003
|
+
isVgsMode = !1;
|
|
1004
|
+
vgsFieldsState = {};
|
|
1005
|
+
constructor(e) {
|
|
1006
|
+
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;
|
|
1007
|
+
}
|
|
1008
|
+
handleFormStateChange = () => {
|
|
1009
|
+
this.onUIUpdate();
|
|
1010
|
+
};
|
|
1011
|
+
handleProfileStateChange = (e) => {
|
|
1012
|
+
if (!e.isLoading) if (e.checkoutProfile) try {
|
|
1013
|
+
if (e.checkoutProfile.styles?.fontFamily) try {
|
|
1014
|
+
let { cleanup: t } = P({ fontFamily: e.checkoutProfile.styles.fontFamily });
|
|
1015
|
+
this.fontCleanup = t, this.formElement.style.fontFamily = e.checkoutProfile.styles.fontFamily;
|
|
1016
|
+
} catch (e) {
|
|
1017
|
+
console.error("Error loading Google Font:", e);
|
|
1018
|
+
}
|
|
1019
|
+
this.onProfileLoaded(), this.onLoadingChange(!1);
|
|
1020
|
+
} catch (t) {
|
|
1021
|
+
console.error("Error in profile state change:", t);
|
|
1022
|
+
let n = e.error || "Failed to load checkout profile data";
|
|
1023
|
+
this.onError(n), this.onLoadingChange(!1);
|
|
1024
|
+
}
|
|
1025
|
+
else e.error && (console.error("NO profile found", e.error), this.onError(e.error), this.onLoadingChange(!1));
|
|
1026
|
+
};
|
|
1027
|
+
isFormDisabled() {
|
|
1028
|
+
let e = this.formManager.getFormState(), t = this.checkoutProfile.getState(), n = Object.keys(e.errors).filter((e) => e !== "billingAddress" && e !== "shippingAddress").length > 0, r = e.errors.billingAddress, i = r && typeof r == "object" ? Object.keys(r).length > 0 : !1, a = e.errors.shippingAddress, o = a && typeof a == "object" ? Object.keys(a).length > 0 : !1, s = n || i || o, c = L(t.checkoutProfile?.layout) ? !!(e.formData.billingAddress?.firstName || e.formData.billingAddress?.lastName || e.formData.shippingAddress?.firstName || e.formData.shippingAddress?.lastName) : !!e.formData.name, l = t.checkoutProfile?.layout.phoneNumber?.enabled ?? !1 ? !!e.formData.phoneNumber : !0, { billingFields: u, shippingFields: d } = t.checkoutProfile?.layout ?? {}, f = new Set(["US", "CA"]), p = (e, t) => {
|
|
1029
|
+
if (!e) return !0;
|
|
1030
|
+
let n = t?.country ?? "";
|
|
1031
|
+
return Object.entries(e).every(([e, r]) => !r?.enabled || e === "state" && (!f.has(n) || r.hiddenForCountries?.includes(n)) ? !0 : !!t?.[e]?.trim());
|
|
1032
|
+
}, m = !this.isVgsMode || Object.values(this.vgsFieldsState).every((e) => e?.isValid === !0), h = this.isVgsMode ? !!e.formData.email && l && m && p(u, e.formData.billingAddress) && p(d, e.formData.shippingAddress) : !!e.formData.email && l && c && !!e.formData.cardNumber && !!e.formData.cardCvv && !!e.formData.cardExpiry && p(u, e.formData.billingAddress) && p(d, e.formData.shippingAddress);
|
|
1033
|
+
return s || !h || this.isSubmitting;
|
|
1034
|
+
}
|
|
1035
|
+
setSubmitting(e) {
|
|
1036
|
+
this.isSubmitting = e;
|
|
1037
|
+
}
|
|
1038
|
+
setVgsMode(e) {
|
|
1039
|
+
this.isVgsMode = e;
|
|
1040
|
+
}
|
|
1041
|
+
updateVgsState(e) {
|
|
1042
|
+
this.vgsFieldsState = e;
|
|
1043
|
+
}
|
|
1044
|
+
getVgsFieldErrors(e) {
|
|
1045
|
+
let t = {};
|
|
1046
|
+
for (let [n, r] of Object.entries(this.vgsFieldsState)) {
|
|
1047
|
+
if (!r?.isTouched || r.isFocused || r.isValid) continue;
|
|
1048
|
+
let i = r.errors?.[0];
|
|
1049
|
+
if (!i) continue;
|
|
1050
|
+
let a = A(n, i.code);
|
|
1051
|
+
a && (t[n] = e(a));
|
|
1052
|
+
}
|
|
1053
|
+
return t;
|
|
1054
|
+
}
|
|
1055
|
+
getSubmitting() {
|
|
1056
|
+
return this.isSubmitting;
|
|
1057
|
+
}
|
|
1058
|
+
cleanup() {
|
|
1059
|
+
this.fontCleanup &&= (this.fontCleanup(), void 0);
|
|
1060
|
+
}
|
|
1061
|
+
}, ie = class extends v {
|
|
1062
|
+
titleElement;
|
|
1063
|
+
constructor(e = {}) {
|
|
1064
|
+
super("div", ["blur-bg"]);
|
|
1065
|
+
let t = S.createDiv(["loader"]);
|
|
1066
|
+
this.titleElement = new v("h3", ["title"]), this.titleElement.setText(e.text || ""), this.appendChild(t), this.appendChild(this.titleElement);
|
|
1067
|
+
}
|
|
1068
|
+
setText(e) {
|
|
1069
|
+
return this.titleElement.setText(e), this;
|
|
1070
|
+
}
|
|
1071
|
+
}, X = {
|
|
1072
|
+
street: "",
|
|
1073
|
+
firstName: "",
|
|
1074
|
+
lastName: "",
|
|
1075
|
+
state: "",
|
|
1076
|
+
city: "",
|
|
1077
|
+
zipCode: "",
|
|
1078
|
+
country: ""
|
|
1079
|
+
}, Z = (e, t) => {
|
|
1080
|
+
let n = {}, r = `${t}.`;
|
|
1081
|
+
return Object.keys(e).forEach((t) => {
|
|
1082
|
+
if (t.startsWith(r)) {
|
|
1083
|
+
let i = t.slice(r.length);
|
|
1084
|
+
n[i] = e[t];
|
|
1085
|
+
}
|
|
1086
|
+
}), n;
|
|
1087
|
+
}, ae = class {
|
|
1088
|
+
formElement;
|
|
1089
|
+
componentManager;
|
|
1090
|
+
onLoadingStateChange;
|
|
1091
|
+
spinner;
|
|
1092
|
+
formSkeleton;
|
|
1093
|
+
alert;
|
|
1094
|
+
constructor(e) {
|
|
1095
|
+
this.formElement = e.formElement, this.componentManager = e.componentManager, this.onLoadingStateChange = e.onLoadingStateChange;
|
|
1096
|
+
}
|
|
1097
|
+
updateFormUI(e, t) {
|
|
1098
|
+
this.componentManager.updatePaymentMethods(e.formData), this.componentManager.updateEmailField(e.formData.email, !!(e.errors.email && e.touched.email), e.errors.email), this.componentManager.updatePhoneNumberField(e.formData.phoneNumber ?? "", !!(e.errors.phoneNumber && e.touched.phoneNumber), e.errors.phoneNumber), this.componentManager.updateCardSection(e.formData.cardNumber, e.errors.cardNumber, !!e.touched.cardNumber, e.formData.cardCvv, e.errors.cardCvv, !!e.touched.cardCvv, e.formData.cardExpiry, e.errors.cardExpiry, !!e.touched.cardExpiry), this.componentManager.updateCardholderSection(e.formData.name, !!(e.errors.name && e.touched.name), e.errors.name), this.componentManager.updateBillingAddressSection(e.formData.billingAddress ?? X, e.errors.billingAddress ?? {}, Z(e.touched, "billingAddress")), this.componentManager.updateShippingAddressSection(e.formData.shippingAddress ?? X, e.errors.shippingAddress ?? {}, Z(e.touched, "shippingAddress")), this.componentManager.updateSubmitButton(t);
|
|
1099
|
+
}
|
|
1100
|
+
setLoadingState(e) {
|
|
1101
|
+
if (this.onLoadingStateChange) {
|
|
1102
|
+
this.onLoadingStateChange(e);
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
e ? (this.hideSkeleton(), this.formSkeleton = new V(), this.formElement.appendChild(this.formSkeleton.getElement())) : this.hideSkeleton();
|
|
1106
|
+
}
|
|
1107
|
+
showSpinner(e) {
|
|
1108
|
+
this.hideSpinner(), this.spinner = new ie({ text: e }), this.formElement.appendChild(this.spinner.getElement());
|
|
1109
|
+
}
|
|
1110
|
+
hideSpinner() {
|
|
1111
|
+
this.spinner &&= (this.spinner.getElement().remove(), void 0);
|
|
1112
|
+
}
|
|
1113
|
+
hideSkeleton() {
|
|
1114
|
+
this.formSkeleton &&= (this.formSkeleton.getElement().remove(), void 0);
|
|
1115
|
+
}
|
|
1116
|
+
setErrorMessage(e) {
|
|
1117
|
+
this.alert &&= (this.alert.getElement().remove(), void 0), this.alert = new j({ message: e }), this.formElement.insertBefore(this.alert.getElement(), this.formElement.firstChild);
|
|
1118
|
+
}
|
|
1119
|
+
clearErrorMessage() {
|
|
1120
|
+
this.alert &&= (this.alert.getElement().remove(), void 0);
|
|
1121
|
+
}
|
|
1122
|
+
cleanup() {
|
|
1123
|
+
this.spinner &&= (this.spinner.getElement().remove(), void 0), this.formSkeleton &&= (this.formSkeleton.getElement().remove(), void 0), this.alert &&= (this.alert.getElement().remove(), void 0);
|
|
1124
|
+
}
|
|
393
1125
|
};
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
_vgsFieldsReady = !1;
|
|
891
|
-
_fieldHeight = "38.5px";
|
|
892
|
-
_borderRadius = 0;
|
|
893
|
-
constructor(e) {
|
|
894
|
-
const {
|
|
895
|
-
value: t,
|
|
896
|
-
onChange: s,
|
|
897
|
-
onBlur: a,
|
|
898
|
-
errorMsg: i,
|
|
899
|
-
checkoutProfile: n,
|
|
900
|
-
translationFunc: r,
|
|
901
|
-
autocomplete: d = "cc-name",
|
|
902
|
-
isVgsMode: c = !1
|
|
903
|
-
} = e;
|
|
904
|
-
this.isVgsMode = c, this.wrapperElement = document.createElement("div"), c ? this.buildVgsLayout(n, r) : this.buildNativeLayout(
|
|
905
|
-
t,
|
|
906
|
-
s,
|
|
907
|
-
a,
|
|
908
|
-
i,
|
|
909
|
-
n,
|
|
910
|
-
r,
|
|
911
|
-
d
|
|
912
|
-
);
|
|
913
|
-
}
|
|
914
|
-
buildVgsLayout(e, t) {
|
|
915
|
-
const s = e.styles.borderRadius;
|
|
916
|
-
this._borderRadius = s;
|
|
917
|
-
const a = document.createElement("div");
|
|
918
|
-
a.style.marginBottom = "4px";
|
|
919
|
-
const i = document.createElement("label");
|
|
920
|
-
i.className = "input-label", i.textContent = t("cardholderNameLabel"), i.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, i.style.fontSize = `${e.styles.fontSize}px`, a.appendChild(i), 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";
|
|
921
|
-
const n = document.createElement("div");
|
|
922
|
-
n.className = "vgs-field-skeleton", this.vgsWrapper.appendChild(n), 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 J({ visible: !1 }), this.wrapperElement.appendChild(this.vgsHelperText.getElement());
|
|
923
|
-
}
|
|
924
|
-
buildNativeLayout(e, t, s, a, i, n, r) {
|
|
925
|
-
this.input = new K({
|
|
926
|
-
name: "name",
|
|
927
|
-
label: n("cardholderNameLabel"),
|
|
928
|
-
error: !1,
|
|
929
|
-
errorMsg: a,
|
|
930
|
-
styles: {
|
|
931
|
-
color: i.styles.textColor,
|
|
932
|
-
borderRadius: `${i.styles.borderRadius}px`,
|
|
933
|
-
fontSize: i.styles.fontSize,
|
|
934
|
-
fontFamily: i.styles.fontFamily
|
|
935
|
-
},
|
|
936
|
-
placeholder: n("cardholderNamePlaceholder"),
|
|
937
|
-
value: e,
|
|
938
|
-
autocomplete: r,
|
|
939
|
-
onChange: (d) => {
|
|
940
|
-
const g = d.target.value, v = g.replace(/[^a-zA-Z\s\-'.]/g, "");
|
|
941
|
-
g !== v && this.input?.setValue(v), this.input?.setError(!1), this.trim(), t(d);
|
|
942
|
-
}
|
|
943
|
-
}), this.input.addEventListener("blur", (d) => {
|
|
944
|
-
s(d);
|
|
945
|
-
}), this.wrapperElement.appendChild(this.input.getElement());
|
|
946
|
-
}
|
|
947
|
-
getVgsContainerId() {
|
|
948
|
-
return this.vgsContainer?.id;
|
|
949
|
-
}
|
|
950
|
-
handleVgsStateChange(e, t) {
|
|
951
|
-
if (!this.isVgsMode || !this.vgsWrapper) return;
|
|
952
|
-
const s = e[R.CARDHOLDER]?.isFocused;
|
|
953
|
-
if (this._vgsFieldsReady && (this.vgsWrapper.style.boxShadow = s ? "0 0 0 1px rgba(50, 151, 211, 0.7), 0 1px 1px 0 rgba(0, 0, 0, 0.07), 0 0 0 4px rgba(50, 151, 211, 0.3)" : "0 0 0 1px #e0e0e0, 0 2px 4px 0 rgba(0,0,0,0.07), 0 1px 1.5px 0 rgba(0,0,0,0.05)"), !t || !this.vgsHelperText) return;
|
|
954
|
-
const a = t[R.CARDHOLDER];
|
|
955
|
-
a ? (this.vgsHelperText.setText(a), this.vgsHelperText.toggleVisibility(!0)) : this.vgsHelperText.toggleVisibility(!1);
|
|
956
|
-
}
|
|
957
|
-
setFieldHeight(e) {
|
|
958
|
-
this._fieldHeight = e, this.vgsWrapper && (this.vgsWrapper.style.height = e);
|
|
959
|
-
}
|
|
960
|
-
setBorderRadius(e) {
|
|
961
|
-
this._borderRadius = e, this.vgsWrapper && (this.vgsWrapper.style.borderRadius = `${e}px`);
|
|
962
|
-
}
|
|
963
|
-
hideFakePlaceholder() {
|
|
964
|
-
if (!this.vgsWrapper) return;
|
|
965
|
-
this._vgsFieldsReady = !0, this.vgsWrapper.style.overflow = "visible", this.vgsWrapper.style.transition = "box-shadow 0.1s ease-in", this.vgsWrapper.style.boxShadow = "0 0 0 1px #e0e0e0, 0 2px 4px 0 rgba(0,0,0,0.07), 0 1px 1.5px 0 rgba(0,0,0,0.05)";
|
|
966
|
-
const e = this.vgsWrapper.querySelector(".vgs-field-skeleton");
|
|
967
|
-
e && e.remove(), this.vgsContainer?.querySelectorAll("iframe").forEach((t) => {
|
|
968
|
-
t.style.height = this._fieldHeight, t.style.borderRadius = `${this._borderRadius}px`;
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
getValue() {
|
|
972
|
-
return this.isVgsMode ? "" : this.input?.getValue() ?? "";
|
|
973
|
-
}
|
|
974
|
-
setValue(e) {
|
|
975
|
-
return this.isVgsMode || this.input?.setValue(e), this;
|
|
976
|
-
}
|
|
977
|
-
trim() {
|
|
978
|
-
if (this.isVgsMode) return this;
|
|
979
|
-
const e = this.getValue().trimStart();
|
|
980
|
-
return this.setValue(e), this;
|
|
981
|
-
}
|
|
982
|
-
setError(e, t) {
|
|
983
|
-
if (this.isVgsMode) return this;
|
|
984
|
-
const s = this.input?.getElement().querySelector("input");
|
|
985
|
-
return s && document.activeElement !== s && this.input?.setError(e, t), this;
|
|
986
|
-
}
|
|
987
|
-
getElement() {
|
|
988
|
-
return !this.isVgsMode && this.input ? this.input.getElement() : this.wrapperElement;
|
|
989
|
-
}
|
|
990
|
-
appendTo(e) {
|
|
991
|
-
return e.appendChild(this.getElement()), this;
|
|
992
|
-
}
|
|
993
|
-
focus() {
|
|
994
|
-
this.isVgsMode || this.input?.focus();
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
class j extends P {
|
|
998
|
-
constructor() {
|
|
999
|
-
super("div", ["skeleton-container"]), this.createSkeletonElements();
|
|
1000
|
-
}
|
|
1001
|
-
createSkeletonElements() {
|
|
1002
|
-
this.appendChild(this.createPaymentMethodSkeleton()), this.appendChild(this.createPaymentSeparatorSkeleton());
|
|
1003
|
-
}
|
|
1004
|
-
createPaymentMethodSkeleton() {
|
|
1005
|
-
const e = A.createDiv(["skeleton-field"]), t = A.createDiv([
|
|
1006
|
-
"skeleton",
|
|
1007
|
-
"skeleton-payment-method"
|
|
1008
|
-
]);
|
|
1009
|
-
return e.appendChild(t), e;
|
|
1010
|
-
}
|
|
1011
|
-
createPaymentSeparatorSkeleton() {
|
|
1012
|
-
const e = A.createDiv([
|
|
1013
|
-
"payment-separator_container"
|
|
1014
|
-
]), t = A.createDiv(["payment-separator__line"]), s = A.createDiv([
|
|
1015
|
-
"skeleton",
|
|
1016
|
-
"skeleton-separator-text"
|
|
1017
|
-
]), a = A.createDiv(["payment-separator__line"]);
|
|
1018
|
-
return e.appendChild(t), e.appendChild(s), e.appendChild(a), e;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
class fe extends P {
|
|
1022
|
-
constructor(e) {
|
|
1023
|
-
const { translationFunc: t, checkoutProfile: s } = e;
|
|
1024
|
-
super("div", ["payment-separator"]);
|
|
1025
|
-
const a = this.getElement(), i = document.createElement("span");
|
|
1026
|
-
i.className = "payment-separator__line";
|
|
1027
|
-
const n = document.createElement("p");
|
|
1028
|
-
n.textContent = t("pay-with-card"), n.className = "payment-separator__text", n.style.fontFamily = `${s.styles.fontFamily}, sans-serif`;
|
|
1029
|
-
const r = document.createElement("span");
|
|
1030
|
-
r.className = "payment-separator__line", a.appendChild(i), a.appendChild(n), a.appendChild(r);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
class ye extends P {
|
|
1034
|
-
paymentMethods;
|
|
1035
|
-
paymentSeparator;
|
|
1036
|
-
skeleton;
|
|
1037
|
-
constructor(e) {
|
|
1038
|
-
const {
|
|
1039
|
-
checkoutProfile: t,
|
|
1040
|
-
formData: s,
|
|
1041
|
-
onPaypalSubmit: a,
|
|
1042
|
-
onApplePaySubmit: i,
|
|
1043
|
-
supportedPaymentMethods: n,
|
|
1044
|
-
translationFunc: r,
|
|
1045
|
-
paymentId: d,
|
|
1046
|
-
checkoutKey: c,
|
|
1047
|
-
checkoutDetails: g,
|
|
1048
|
-
environment: v,
|
|
1049
|
-
countryCode: l
|
|
1050
|
-
} = e;
|
|
1051
|
-
if (super("div", ["payment-methods"]), this.paymentMethods = /* @__PURE__ */ new Map(), !t?.additionalPaymentMethods) {
|
|
1052
|
-
this.getElement().style.display = "none";
|
|
1053
|
-
return;
|
|
1054
|
-
}
|
|
1055
|
-
if (n === void 0) {
|
|
1056
|
-
this.renderSkeleton();
|
|
1057
|
-
return;
|
|
1058
|
-
}
|
|
1059
|
-
const m = Object.entries(
|
|
1060
|
-
t.additionalPaymentMethods
|
|
1061
|
-
).filter(([y, u]) => {
|
|
1062
|
-
const p = u.enabled, h = n ? n[y] === !0 : !0, b = !u.countries || l && u.countries.includes(l);
|
|
1063
|
-
return p && h && b;
|
|
1064
|
-
}).sort((y, u) => y[1].order - u[1].order);
|
|
1065
|
-
if (m.length === 0) {
|
|
1066
|
-
this.getElement().style.display = "none";
|
|
1067
|
-
return;
|
|
1068
|
-
}
|
|
1069
|
-
for (const [y] of m)
|
|
1070
|
-
switch (y) {
|
|
1071
|
-
case "paypal": {
|
|
1072
|
-
if (a) {
|
|
1073
|
-
const u = new Q({
|
|
1074
|
-
checkoutProfile: t,
|
|
1075
|
-
formData: s,
|
|
1076
|
-
onSubmit: a
|
|
1077
|
-
});
|
|
1078
|
-
this.paymentMethods.set("paypal", u), u.appendTo(this.getElement());
|
|
1079
|
-
}
|
|
1080
|
-
break;
|
|
1081
|
-
}
|
|
1082
|
-
case "applePay": {
|
|
1083
|
-
if (i && d && c) {
|
|
1084
|
-
const u = t.appearance?.additionalPaymentMethods?.applePay, p = new Z({
|
|
1085
|
-
checkoutProfile: t,
|
|
1086
|
-
formData: s,
|
|
1087
|
-
onSubmit: i,
|
|
1088
|
-
paymentId: d,
|
|
1089
|
-
checkoutKey: c,
|
|
1090
|
-
checkoutDetails: g,
|
|
1091
|
-
environment: v,
|
|
1092
|
-
displayName: u?.displayName,
|
|
1093
|
-
requiredBillingContactFields: u?.requiredBillingContactFields,
|
|
1094
|
-
requiredShippingContactFields: u?.requiredShippingContactFields
|
|
1095
|
-
});
|
|
1096
|
-
this.paymentMethods.set("applePay", p), p.appendTo(this.getElement());
|
|
1097
|
-
}
|
|
1098
|
-
break;
|
|
1099
|
-
}
|
|
1100
|
-
// Add cases for other payment methods when they become available
|
|
1101
|
-
// case 'googlepay':
|
|
1102
|
-
// const googlePayButton = new GooglePayButton({ checkoutProfile });
|
|
1103
|
-
// this.paymentMethods.set('googlepay', googlePayButton);
|
|
1104
|
-
// googlePayButton.appendTo(this.getElement());
|
|
1105
|
-
// break;
|
|
1106
|
-
default:
|
|
1107
|
-
console.warn(
|
|
1108
|
-
`[PaymentMethods] Unsupported payment method: ${y}`
|
|
1109
|
-
);
|
|
1110
|
-
break;
|
|
1111
|
-
}
|
|
1112
|
-
this.paymentMethods.size > 0 && (this.paymentSeparator = new fe({
|
|
1113
|
-
translationFunc: r,
|
|
1114
|
-
checkoutProfile: t
|
|
1115
|
-
}), this.getElement().appendChild(this.paymentSeparator.getElement()));
|
|
1116
|
-
}
|
|
1117
|
-
renderSkeleton() {
|
|
1118
|
-
this.skeleton = new j(), this.getElement().appendChild(this.skeleton.getElement());
|
|
1119
|
-
}
|
|
1120
|
-
updateFormData(e) {
|
|
1121
|
-
const t = this.paymentMethods.get("paypal");
|
|
1122
|
-
t && t.updateFormData(e);
|
|
1123
|
-
const s = this.paymentMethods.get("applePay");
|
|
1124
|
-
return s && s.updateFormData(e), this;
|
|
1125
|
-
}
|
|
1126
|
-
hasVisiblePaymentMethods() {
|
|
1127
|
-
return this.paymentMethods.size > 0 && this.getElement().style.display !== "none";
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
const be = 17;
|
|
1131
|
-
class Se extends P {
|
|
1132
|
-
styles;
|
|
1133
|
-
isHovered = !1;
|
|
1134
|
-
constructor(e) {
|
|
1135
|
-
super("button", ["button"], {
|
|
1136
|
-
type: "submit"
|
|
1137
|
-
}), this.styles = e.styles, this.setText(e.text), this.getElement().disabled = e.disabled ?? !1, e.disabled ? this.addClass("disabled") : this.addClass("valid"), this.applyStyles(), this.addEventListener("mouseenter", () => this.handleMouseEnter()), this.addEventListener("mouseleave", () => this.handleMouseLeave());
|
|
1138
|
-
}
|
|
1139
|
-
applyStyles() {
|
|
1140
|
-
const e = this.getElement();
|
|
1141
|
-
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 === be ? "100vmax" : `${this.styles.borderRadius}px`, e.style.fontSize = `${this.styles.fontSize}px`, e.style.fontFamily = `${this.styles.fontFamily}, sans-serif`;
|
|
1142
|
-
}
|
|
1143
|
-
handleMouseEnter() {
|
|
1144
|
-
this.isHovered = !0, this.applyStyles();
|
|
1145
|
-
}
|
|
1146
|
-
handleMouseLeave() {
|
|
1147
|
-
this.isHovered = !1, this.applyStyles();
|
|
1148
|
-
}
|
|
1149
|
-
setDisabled(e) {
|
|
1150
|
-
return this.getElement().disabled = e, e ? (this.addClass("disabled"), this.removeClass("valid")) : (this.removeClass("disabled"), this.addClass("valid")), this.applyStyles(), this;
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
class ve {
|
|
1154
|
-
button;
|
|
1155
|
-
constructor(e) {
|
|
1156
|
-
const { disabled: t, checkoutProfile: s, translationFunc: a } = e;
|
|
1157
|
-
this.button = new Se({
|
|
1158
|
-
text: a(
|
|
1159
|
-
`buttonTexts.${s?.layout.actionButton.translationKey}`
|
|
1160
|
-
),
|
|
1161
|
-
styles: {
|
|
1162
|
-
backgroundColor: s.styles.buttonColor,
|
|
1163
|
-
color: s.styles.buttonTextColor,
|
|
1164
|
-
fontFamily: s.styles.fontFamily,
|
|
1165
|
-
borderRadius: s.styles.borderRadius,
|
|
1166
|
-
fontSize: s.styles.buttonFontSize
|
|
1167
|
-
},
|
|
1168
|
-
disabled: t
|
|
1169
|
-
});
|
|
1170
|
-
}
|
|
1171
|
-
getElement() {
|
|
1172
|
-
return this.button.getElement();
|
|
1173
|
-
}
|
|
1174
|
-
setDisabled(e) {
|
|
1175
|
-
return this.button.setDisabled(e), this;
|
|
1176
|
-
}
|
|
1177
|
-
addEventListener(e, t, s) {
|
|
1178
|
-
return this.button.addEventListener(e, t, s), this;
|
|
1179
|
-
}
|
|
1180
|
-
appendTo(e) {
|
|
1181
|
-
return this.button.appendTo(e), this;
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
class Ce {
|
|
1185
|
-
formElement;
|
|
1186
|
-
focusManager;
|
|
1187
|
-
translationFunc;
|
|
1188
|
-
locale;
|
|
1189
|
-
onFieldFocus;
|
|
1190
|
-
onChange;
|
|
1191
|
-
onBlur;
|
|
1192
|
-
onPaypalSubmit;
|
|
1193
|
-
onApplePaySubmit;
|
|
1194
|
-
supportedPaymentMethods;
|
|
1195
|
-
paymentId;
|
|
1196
|
-
checkoutKey;
|
|
1197
|
-
checkoutDetails;
|
|
1198
|
-
environment;
|
|
1199
|
-
vgsService;
|
|
1200
|
-
onVgsStateChange;
|
|
1201
|
-
// Form components
|
|
1202
|
-
emailField;
|
|
1203
|
-
phoneNumberField;
|
|
1204
|
-
phonePlaceholder;
|
|
1205
|
-
cardSection;
|
|
1206
|
-
cardholderSection;
|
|
1207
|
-
submitButton;
|
|
1208
|
-
paymentMethods;
|
|
1209
|
-
billingAddressSection;
|
|
1210
|
-
shippingAddressSection;
|
|
1211
|
-
cardSectionSkeleton;
|
|
1212
|
-
cardholderSectionSkeleton;
|
|
1213
|
-
isCheckoutDetailsLoaded = !1;
|
|
1214
|
-
// Event handler references
|
|
1215
|
-
emailFocusHandler;
|
|
1216
|
-
phoneNumberFocusHandler;
|
|
1217
|
-
cardExpiryFocusHandler;
|
|
1218
|
-
cardNumberFocusHandler;
|
|
1219
|
-
cardCvvFocusHandler;
|
|
1220
|
-
nameFocusHandler;
|
|
1221
|
-
constructor(e) {
|
|
1222
|
-
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;
|
|
1223
|
-
}
|
|
1224
|
-
createPaymentMethods(e, t, s = !1) {
|
|
1225
|
-
try {
|
|
1226
|
-
if (!e?.additionalPaymentMethods || Object.keys(e.additionalPaymentMethods).length === 0 || !Object.values(e.additionalPaymentMethods).some(
|
|
1227
|
-
(a) => a.enabled
|
|
1228
|
-
))
|
|
1229
|
-
return;
|
|
1230
|
-
this.paymentMethods = new ye({
|
|
1231
|
-
checkoutProfile: e,
|
|
1232
|
-
formData: t,
|
|
1233
|
-
supportedPaymentMethods: this.supportedPaymentMethods,
|
|
1234
|
-
translationFunc: this.translationFunc,
|
|
1235
|
-
onPaypalSubmit: this.onPaypalSubmit,
|
|
1236
|
-
onApplePaySubmit: this.onApplePaySubmit,
|
|
1237
|
-
paymentId: this.paymentId,
|
|
1238
|
-
checkoutKey: this.checkoutKey,
|
|
1239
|
-
checkoutDetails: this.checkoutDetails,
|
|
1240
|
-
environment: this.environment,
|
|
1241
|
-
countryCode: this.checkoutDetails?.countryCode
|
|
1242
|
-
}), s ? this.formElement.insertBefore(
|
|
1243
|
-
this.paymentMethods.getElement(),
|
|
1244
|
-
this.formElement.firstChild
|
|
1245
|
-
) : this.formElement.appendChild(this.paymentMethods.getElement());
|
|
1246
|
-
} catch (a) {
|
|
1247
|
-
throw console.error("Error creating payment methods:", a), a;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
createEmailField(e, t, s, a) {
|
|
1251
|
-
try {
|
|
1252
|
-
const i = e.layout.billingFields && Object.values(e.layout.billingFields).some(
|
|
1253
|
-
(n) => n?.enabled
|
|
1254
|
-
) || e.layout.shippingFields && Object.values(e.layout.shippingFields).some(
|
|
1255
|
-
(n) => n?.enabled
|
|
1256
|
-
);
|
|
1257
|
-
this.emailField = new X({
|
|
1258
|
-
value: t.email,
|
|
1259
|
-
onChange: this.onChange,
|
|
1260
|
-
onBlur: this.onBlur,
|
|
1261
|
-
onTab: i ? void 0 : () => this.focusManager.focusField(
|
|
1262
|
-
e.layout.phoneNumber?.enabled ? "phoneNumber" : "cardNumber"
|
|
1263
|
-
),
|
|
1264
|
-
error: !!(s.email && a.email),
|
|
1265
|
-
errorMsg: s.email,
|
|
1266
|
-
checkoutProfile: e,
|
|
1267
|
-
translationFunc: this.translationFunc
|
|
1268
|
-
}), 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());
|
|
1269
|
-
} catch (i) {
|
|
1270
|
-
throw console.error("Error creating email field:", i), i;
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
createPhoneNumberField(e, t, s, a) {
|
|
1274
|
-
const i = document.createElement("div");
|
|
1275
|
-
this.phonePlaceholder = i, this.formElement.appendChild(i), ee().then(({ PhoneNumberField: n }) => {
|
|
1276
|
-
i.isConnected && (this.phoneNumberField = new n({
|
|
1277
|
-
value: t.phoneNumber ?? "",
|
|
1278
|
-
onChange: this.onChange,
|
|
1279
|
-
onBlur: this.onBlur,
|
|
1280
|
-
onTab: () => this.focusManager.focusField("cardNumber"),
|
|
1281
|
-
error: !!(s.phoneNumber && a.phoneNumber),
|
|
1282
|
-
errorMsg: s.phoneNumber,
|
|
1283
|
-
checkoutProfile: e,
|
|
1284
|
-
translationFunc: this.translationFunc,
|
|
1285
|
-
defaultCountry: e.layout.phoneNumber?.defaultCountry || "US",
|
|
1286
|
-
allowedCountries: e.layout.phoneNumber?.allowedCountries,
|
|
1287
|
-
locale: this.locale
|
|
1288
|
-
}), this.phoneNumberFocusHandler = () => this.onFieldFocus("phoneNumber"), this.phoneNumberField.getElement().addEventListener("focus", this.phoneNumberFocusHandler, !0), this.focusManager.registerField("phoneNumber", this.phoneNumberField), i.replaceWith(this.phoneNumberField.getElement()), this.phonePlaceholder = void 0);
|
|
1289
|
-
}).catch((n) => {
|
|
1290
|
-
console.error("Error creating phone number field:", n), i.remove(), this.phonePlaceholder = void 0;
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
setCheckoutDetailsLoaded(e) {
|
|
1294
|
-
this.isCheckoutDetailsLoaded = e;
|
|
1295
|
-
}
|
|
1296
|
-
createCardSection(e, t, s, a) {
|
|
1297
|
-
try {
|
|
1298
|
-
if (!this.isCheckoutDetailsLoaded) {
|
|
1299
|
-
this.cardSectionSkeleton = this.buildCardSkeleton(e), this.formElement.appendChild(this.cardSectionSkeleton);
|
|
1300
|
-
return;
|
|
1301
|
-
}
|
|
1302
|
-
if (this.cardSection = new te({
|
|
1303
|
-
checkoutProfile: e,
|
|
1304
|
-
cardNumber: t.cardNumber,
|
|
1305
|
-
cardNumberError: s.cardNumber,
|
|
1306
|
-
cardNumberTouched: !!a.cardNumber,
|
|
1307
|
-
cardCvv: t.cardCvv,
|
|
1308
|
-
cardCvvError: s.cardCvv,
|
|
1309
|
-
cardCvvTouched: !!a.cardCvv,
|
|
1310
|
-
cardExpiry: t.cardExpiry,
|
|
1311
|
-
cardExpiryError: s.cardExpiry,
|
|
1312
|
-
cardExpiryTouched: !!a.cardExpiry,
|
|
1313
|
-
onChange: this.onChange,
|
|
1314
|
-
onBlur: this.onBlur,
|
|
1315
|
-
onCardBrandChange: () => {
|
|
1316
|
-
t.cardCvv && this.onBlur(
|
|
1317
|
-
N({
|
|
1318
|
-
type: "blur",
|
|
1319
|
-
target: { name: "cardCvv", value: t.cardCvv }
|
|
1320
|
-
})
|
|
1321
|
-
);
|
|
1322
|
-
},
|
|
1323
|
-
translationFunc: this.translationFunc,
|
|
1324
|
-
vgsService: this.vgsService,
|
|
1325
|
-
onVgsStateChange: this.onVgsStateChange
|
|
1326
|
-
}), this.vgsService)
|
|
1327
|
-
this.cardSection.setOnVgsAutoFocus((i) => {
|
|
1328
|
-
this.onFieldFocus(i);
|
|
1329
|
-
});
|
|
1330
|
-
else {
|
|
1331
|
-
const i = this.cardSection.getElement().querySelector('input[name="cardExpiry"]');
|
|
1332
|
-
i && (this.cardExpiryFocusHandler = () => this.onFieldFocus("cardExpiry"), i.addEventListener(
|
|
1333
|
-
"focus",
|
|
1334
|
-
this.cardExpiryFocusHandler
|
|
1335
|
-
));
|
|
1336
|
-
const n = this.cardSection.getElement().querySelector('input[name="cardNumber"]');
|
|
1337
|
-
n && (this.cardNumberFocusHandler = () => this.onFieldFocus("cardNumber"), n.addEventListener(
|
|
1338
|
-
"focus",
|
|
1339
|
-
this.cardNumberFocusHandler
|
|
1340
|
-
));
|
|
1341
|
-
const r = this.cardSection.getElement().querySelector('input[name="cardCvv"]');
|
|
1342
|
-
r && (this.cardCvvFocusHandler = () => this.onFieldFocus("cardCvv"), r.addEventListener("focus", this.cardCvvFocusHandler));
|
|
1343
|
-
}
|
|
1344
|
-
this.focusManager.registerField("cardNumber", {
|
|
1345
|
-
focus: () => this.cardSection?.focusField("cardNumber")
|
|
1346
|
-
}), this.focusManager.registerField("cardExpiry", {
|
|
1347
|
-
focus: () => this.cardSection?.focusField("cardExpiry")
|
|
1348
|
-
}), this.focusManager.registerField("cardCvv", {
|
|
1349
|
-
focus: () => this.cardSection?.focusField("cardCvv")
|
|
1350
|
-
}), this.formElement.appendChild(this.cardSection.getElement());
|
|
1351
|
-
} catch (i) {
|
|
1352
|
-
throw console.error("Error creating card section:", i), i;
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
createCardholderSection(e, t, s, a) {
|
|
1356
|
-
try {
|
|
1357
|
-
if (!this.isCheckoutDetailsLoaded) {
|
|
1358
|
-
this.cardholderSectionSkeleton = this.buildCardholderSkeleton(e), this.formElement.appendChild(this.cardholderSectionSkeleton);
|
|
1359
|
-
return;
|
|
1360
|
-
}
|
|
1361
|
-
if (this.cardholderSection = new ge({
|
|
1362
|
-
value: t.name,
|
|
1363
|
-
onChange: this.onChange,
|
|
1364
|
-
onBlur: this.onBlur,
|
|
1365
|
-
error: !!(s.name && a.name),
|
|
1366
|
-
errorMsg: s.name,
|
|
1367
|
-
checkoutProfile: e,
|
|
1368
|
-
translationFunc: this.translationFunc,
|
|
1369
|
-
isVgsMode: !!this.vgsService
|
|
1370
|
-
}), !this.vgsService) {
|
|
1371
|
-
const i = this.cardholderSection.getElement().querySelector('input[name="name"]');
|
|
1372
|
-
i && (this.nameFocusHandler = () => this.onFieldFocus("name"), i.addEventListener("focus", this.nameFocusHandler));
|
|
1373
|
-
}
|
|
1374
|
-
this.focusManager.registerField("name", this.cardholderSection), this.formElement.appendChild(this.cardholderSection.getElement());
|
|
1375
|
-
} catch (i) {
|
|
1376
|
-
throw console.error("Error creating cardholder section:", i), i;
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
createBillingAddressSection(e, t, s, a) {
|
|
1380
|
-
try {
|
|
1381
|
-
const i = e.layout.billingFields;
|
|
1382
|
-
if (!i || !Object.values(i).some(
|
|
1383
|
-
(d) => d?.enabled
|
|
1384
|
-
)) return;
|
|
1385
|
-
const r = {
|
|
1386
|
-
street: "",
|
|
1387
|
-
firstName: "",
|
|
1388
|
-
lastName: "",
|
|
1389
|
-
state: "",
|
|
1390
|
-
city: "",
|
|
1391
|
-
zipCode: "",
|
|
1392
|
-
country: ""
|
|
1393
|
-
};
|
|
1394
|
-
this.billingAddressSection = new O({
|
|
1395
|
-
type: "billing",
|
|
1396
|
-
title: this.translationFunc("address.billingTitle"),
|
|
1397
|
-
checkoutProfile: e,
|
|
1398
|
-
fieldsConfig: i,
|
|
1399
|
-
values: t.billingAddress ?? r,
|
|
1400
|
-
errors: s.billingAddress ?? {},
|
|
1401
|
-
touched: a.billingAddress ?? {},
|
|
1402
|
-
onChange: this.onChange,
|
|
1403
|
-
onBlur: this.onBlur,
|
|
1404
|
-
translationFunc: this.translationFunc,
|
|
1405
|
-
locale: this.locale,
|
|
1406
|
-
grouped: e.layout.grouped
|
|
1407
|
-
}), this.formElement.appendChild(this.billingAddressSection.getElement());
|
|
1408
|
-
} catch (i) {
|
|
1409
|
-
throw console.error("Error creating billing address section:", i), i;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
createShippingAddressSection(e, t, s, a) {
|
|
1413
|
-
try {
|
|
1414
|
-
const i = e.layout.shippingFields;
|
|
1415
|
-
if (!i || !Object.values(i).some(
|
|
1416
|
-
(d) => d?.enabled
|
|
1417
|
-
)) return;
|
|
1418
|
-
const r = {
|
|
1419
|
-
street: "",
|
|
1420
|
-
firstName: "",
|
|
1421
|
-
lastName: "",
|
|
1422
|
-
state: "",
|
|
1423
|
-
city: "",
|
|
1424
|
-
zipCode: "",
|
|
1425
|
-
country: ""
|
|
1426
|
-
};
|
|
1427
|
-
this.shippingAddressSection = new O({
|
|
1428
|
-
type: "shipping",
|
|
1429
|
-
title: this.translationFunc("address.shippingTitle"),
|
|
1430
|
-
checkoutProfile: e,
|
|
1431
|
-
fieldsConfig: i,
|
|
1432
|
-
values: t.shippingAddress ?? r,
|
|
1433
|
-
errors: s.shippingAddress ?? {},
|
|
1434
|
-
touched: a.shippingAddress ?? {},
|
|
1435
|
-
onChange: this.onChange,
|
|
1436
|
-
onBlur: this.onBlur,
|
|
1437
|
-
translationFunc: this.translationFunc,
|
|
1438
|
-
locale: this.locale,
|
|
1439
|
-
grouped: e.layout.grouped
|
|
1440
|
-
}), this.formElement.appendChild(this.shippingAddressSection.getElement());
|
|
1441
|
-
} catch (i) {
|
|
1442
|
-
throw console.error("Error creating shipping address section:", i), i;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
createSubmitButton(e, t) {
|
|
1446
|
-
try {
|
|
1447
|
-
this.submitButton = new ve({
|
|
1448
|
-
disabled: t,
|
|
1449
|
-
checkoutProfile: e,
|
|
1450
|
-
translationFunc: this.translationFunc
|
|
1451
|
-
}), this.formElement.appendChild(this.submitButton.getElement());
|
|
1452
|
-
} catch (s) {
|
|
1453
|
-
throw console.error("Error creating submit button:", s), s;
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
updateEmailField(e, t, s) {
|
|
1457
|
-
this.emailField && (this.emailField.setValue(e), this.emailField.setError(t, s));
|
|
1458
|
-
}
|
|
1459
|
-
updatePhoneNumberField(e, t, s) {
|
|
1460
|
-
this.phoneNumberField && (this.phoneNumberField.setValue(e), this.phoneNumberField.setError(t, s));
|
|
1461
|
-
}
|
|
1462
|
-
updateCardSection(e, t, s, a, i, n, r, d, c) {
|
|
1463
|
-
this.cardSection && (this.cardSection.updateCardNumber(
|
|
1464
|
-
e,
|
|
1465
|
-
t,
|
|
1466
|
-
s
|
|
1467
|
-
), this.cardSection.updateCardCvv(a, i, n), this.cardSection.updateCardExpiry(
|
|
1468
|
-
r,
|
|
1469
|
-
d,
|
|
1470
|
-
c
|
|
1471
|
-
));
|
|
1472
|
-
}
|
|
1473
|
-
updateCardholderSection(e, t, s) {
|
|
1474
|
-
this.cardholderSection && (this.cardholderSection.setValue(e), this.cardholderSection.setError(t, s));
|
|
1475
|
-
}
|
|
1476
|
-
updateBillingAddressSection(e, t, s) {
|
|
1477
|
-
this.billingAddressSection && this.billingAddressSection.updateAllFields(e, t, s);
|
|
1478
|
-
}
|
|
1479
|
-
updateShippingAddressSection(e, t, s) {
|
|
1480
|
-
this.shippingAddressSection && this.shippingAddressSection.updateAllFields(e, t, s);
|
|
1481
|
-
}
|
|
1482
|
-
updateSubmitButton(e) {
|
|
1483
|
-
this.submitButton && this.submitButton.setDisabled(e);
|
|
1484
|
-
}
|
|
1485
|
-
updatePaymentMethods(e) {
|
|
1486
|
-
this.paymentMethods && this.paymentMethods.updateFormData(e);
|
|
1487
|
-
}
|
|
1488
|
-
removePaymentMethods() {
|
|
1489
|
-
this.paymentMethods && (this.paymentMethods.getElement().remove(), this.paymentMethods = void 0);
|
|
1490
|
-
}
|
|
1491
|
-
updateSupportedPaymentMethods(e) {
|
|
1492
|
-
this.supportedPaymentMethods = e;
|
|
1493
|
-
}
|
|
1494
|
-
updatePaymentDetails(e, t, s) {
|
|
1495
|
-
this.paymentId = e, this.checkoutKey = t, this.checkoutDetails = s;
|
|
1496
|
-
}
|
|
1497
|
-
hasComponents() {
|
|
1498
|
-
return !!this.emailField;
|
|
1499
|
-
}
|
|
1500
|
-
setVgsService(e) {
|
|
1501
|
-
this.vgsService = e;
|
|
1502
|
-
}
|
|
1503
|
-
buildCardSkeleton(e) {
|
|
1504
|
-
const t = e.styles.borderRadius, s = document.createElement("div"), a = document.createElement("div");
|
|
1505
|
-
a.style.marginBottom = "4px";
|
|
1506
|
-
const i = document.createElement("label");
|
|
1507
|
-
i.className = "input-label", i.textContent = this.translationFunc("cardInformation"), i.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, a.appendChild(i), s.appendChild(a);
|
|
1508
|
-
const n = document.createElement("div");
|
|
1509
|
-
n.className = "vgs-card-group", n.style.borderRadius = `${t}px`, n.style.background = "#fff", n.style.display = "flex", n.style.flexDirection = "column", n.style.gap = "8px";
|
|
1510
|
-
const r = document.createElement("div");
|
|
1511
|
-
r.className = "card-number-row", r.style.position = "relative", r.style.height = "38.5px", r.style.overflow = "hidden", r.style.borderRadius = `${t}px`, r.appendChild(this.createSkeletonDiv()), n.appendChild(r);
|
|
1512
|
-
const d = document.createElement("div");
|
|
1513
|
-
d.style.display = "flex", d.style.gap = "8px";
|
|
1514
|
-
const c = document.createElement("div");
|
|
1515
|
-
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);
|
|
1516
|
-
const g = document.createElement("div");
|
|
1517
|
-
return g.style.position = "relative", g.style.flex = "1", g.style.height = "38.5px", g.style.overflow = "hidden", g.style.borderRadius = `${t}px`, g.appendChild(this.createSkeletonDiv()), d.appendChild(g), n.appendChild(d), s.appendChild(n), s;
|
|
1518
|
-
}
|
|
1519
|
-
createSkeletonDiv() {
|
|
1520
|
-
const e = document.createElement("div");
|
|
1521
|
-
return e.className = "vgs-field-skeleton", e;
|
|
1522
|
-
}
|
|
1523
|
-
buildCardholderSkeleton(e) {
|
|
1524
|
-
const t = e.styles.borderRadius, s = document.createElement("div"), a = document.createElement("div");
|
|
1525
|
-
a.style.marginBottom = "4px";
|
|
1526
|
-
const i = document.createElement("label");
|
|
1527
|
-
i.className = "input-label", i.textContent = this.translationFunc("cardholderNameLabel"), i.style.fontFamily = `"${e.styles.fontFamily}", sans-serif`, a.appendChild(i), s.appendChild(a);
|
|
1528
|
-
const n = document.createElement("div");
|
|
1529
|
-
return n.style.position = "relative", n.style.borderRadius = `${t}px`, n.style.height = "38.5px", n.style.width = "100%", n.style.overflow = "hidden", n.style.background = "#fff", n.appendChild(this.createSkeletonDiv()), s.appendChild(n), s;
|
|
1530
|
-
}
|
|
1531
|
-
async mountVgsFields(e) {
|
|
1532
|
-
if (!this.vgsService || !this.cardSection) return;
|
|
1533
|
-
await this.vgsService.whenReady();
|
|
1534
|
-
const t = this.cardSection.getVgsContainerIds(), s = this.cardholderSection?.getVgsContainerId(), a = await se(
|
|
1535
|
-
e.styles.fontFamily
|
|
1536
|
-
), i = this.cardSection.buildVgsFieldCss(
|
|
1537
|
-
e,
|
|
1538
|
-
a
|
|
1539
|
-
);
|
|
1540
|
-
if (this.cardholderSection && i.cardholderName) {
|
|
1541
|
-
const n = i.cardholderName;
|
|
1542
|
-
typeof n.height == "string" && this.cardholderSection.setFieldHeight(n.height);
|
|
1543
|
-
const r = n["border-radius"];
|
|
1544
|
-
typeof r == "string" && this.cardholderSection.setBorderRadius(parseFloat(r));
|
|
1545
|
-
}
|
|
1546
|
-
this.vgsService.mountCardFields(
|
|
1547
|
-
{
|
|
1548
|
-
cardNumber: t.cardNumber ? `#${t.cardNumber}` : void 0,
|
|
1549
|
-
cardExpiry: t.cardExpiry ? `#${t.cardExpiry}` : void 0,
|
|
1550
|
-
cardCvv: t.cardCvv ? `#${t.cardCvv}` : void 0,
|
|
1551
|
-
cardholderName: s ? `#${s}` : void 0
|
|
1552
|
-
},
|
|
1553
|
-
i,
|
|
1554
|
-
{
|
|
1555
|
-
cardNumber: "1234 5678 9012 3456",
|
|
1556
|
-
cardExpiry: this.translationFunc("cardExpiry"),
|
|
1557
|
-
cardCvv: "CVV",
|
|
1558
|
-
cardholderName: this.translationFunc("cardholderNamePlaceholder")
|
|
1559
|
-
},
|
|
1560
|
-
(n) => this.cardSection?.updateVgsCardBrand(n)
|
|
1561
|
-
), this.vgsService.waitForFieldsReady().then(() => {
|
|
1562
|
-
requestAnimationFrame(() => {
|
|
1563
|
-
this.cardSection?.hideFakePlaceholders(), this.cardholderSection?.hideFakePlaceholder();
|
|
1564
|
-
});
|
|
1565
|
-
});
|
|
1566
|
-
}
|
|
1567
|
-
handleVgsStateChange(e, t) {
|
|
1568
|
-
this.cardSection?.handleVgsStateChange(e, t), this.cardholderSection?.handleVgsStateChange(e, t);
|
|
1569
|
-
}
|
|
1570
|
-
cleanup() {
|
|
1571
|
-
if (this.emailField) {
|
|
1572
|
-
const e = this.emailField.getElement().querySelector('input[name="email"]');
|
|
1573
|
-
e && this.emailFocusHandler && e.removeEventListener("focus", this.emailFocusHandler), this.emailField.getElement().remove(), this.emailField = void 0;
|
|
1574
|
-
}
|
|
1575
|
-
if (this.phonePlaceholder && (this.phonePlaceholder.remove(), this.phonePlaceholder = void 0), this.phoneNumberField) {
|
|
1576
|
-
const e = this.phoneNumberField.getElement().querySelector('input[name="phoneNumber"]');
|
|
1577
|
-
e && this.phoneNumberFocusHandler && e.removeEventListener("focus", this.phoneNumberFocusHandler), this.phoneNumberField.getElement().remove(), this.phoneNumberField = void 0;
|
|
1578
|
-
}
|
|
1579
|
-
if (this.cardSectionSkeleton && (this.cardSectionSkeleton.remove(), this.cardSectionSkeleton = void 0), this.cardSection) {
|
|
1580
|
-
const e = this.cardSection.getElement().querySelector('input[name="cardExpiry"]');
|
|
1581
|
-
e && this.cardExpiryFocusHandler && e.removeEventListener(
|
|
1582
|
-
"focus",
|
|
1583
|
-
this.cardExpiryFocusHandler
|
|
1584
|
-
);
|
|
1585
|
-
const t = this.cardSection.getElement().querySelector('input[name="cardNumber"]');
|
|
1586
|
-
t && this.cardNumberFocusHandler && t.removeEventListener(
|
|
1587
|
-
"focus",
|
|
1588
|
-
this.cardNumberFocusHandler
|
|
1589
|
-
);
|
|
1590
|
-
const s = this.cardSection.getElement().querySelector('input[name="cardCvv"]');
|
|
1591
|
-
s && this.cardCvvFocusHandler && s.removeEventListener("focus", this.cardCvvFocusHandler), this.cardSection.getElement().remove(), this.cardSection = void 0;
|
|
1592
|
-
}
|
|
1593
|
-
if (this.cardholderSectionSkeleton && (this.cardholderSectionSkeleton.remove(), this.cardholderSectionSkeleton = void 0), this.cardholderSection) {
|
|
1594
|
-
const e = this.cardholderSection.getElement().querySelector('input[name="name"]');
|
|
1595
|
-
e && this.nameFocusHandler && e.removeEventListener("focus", this.nameFocusHandler), this.cardholderSection.getElement().remove(), this.cardholderSection = void 0;
|
|
1596
|
-
}
|
|
1597
|
-
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);
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
class Fe {
|
|
1601
|
-
formManager;
|
|
1602
|
-
focusManager;
|
|
1603
|
-
onFormSubmit;
|
|
1604
|
-
onUIUpdate;
|
|
1605
|
-
localTouchedFields = /* @__PURE__ */ new Set();
|
|
1606
|
-
constructor(e) {
|
|
1607
|
-
this.formManager = e.formManager, this.focusManager = e.focusManager, this.onFormSubmit = e.onFormSubmit, this.onUIUpdate = e.onUIUpdate;
|
|
1608
|
-
}
|
|
1609
|
-
handleChange = (e) => {
|
|
1610
|
-
const t = e.target, { name: s, value: a } = t, i = s;
|
|
1611
|
-
this.formManager.handleChange(i, a), e instanceof CustomEvent && e.detail?.programmatic ? this.localTouchedFields.delete(i) : this.localTouchedFields.has(i) || (this.localTouchedFields.add(i), this.formManager.handleBlur(i, a));
|
|
1612
|
-
const { formData: r, errors: d, touched: c } = this.formManager.getFormState();
|
|
1613
|
-
this.focusManager.handleStateUpdate(r, d, c);
|
|
1614
|
-
};
|
|
1615
|
-
handleBlur = (e) => {
|
|
1616
|
-
const t = e.target, { name: s, value: a } = t, i = s;
|
|
1617
|
-
this.localTouchedFields.add(i), this.formManager.handleBlur(i, a), setTimeout(() => {
|
|
1618
|
-
this.onUIUpdate();
|
|
1619
|
-
}, 0);
|
|
1620
|
-
const { formData: n, errors: r, touched: d } = this.formManager.getFormState();
|
|
1621
|
-
d[i] || this.focusManager.handleStateUpdate(n, r, d);
|
|
1622
|
-
};
|
|
1623
|
-
handleSubmit = async (e) => {
|
|
1624
|
-
e.preventDefault(), await this.onFormSubmit(e);
|
|
1625
|
-
};
|
|
1626
|
-
handleKeyDown = (e) => {
|
|
1627
|
-
e.key === "Enter" && (e.target instanceof HTMLTextAreaElement || (e.preventDefault(), this.handleSubmit(e)));
|
|
1628
|
-
};
|
|
1629
|
-
handleFieldFocus = (e) => {
|
|
1630
|
-
this.focusManager.handleFieldFocus(e);
|
|
1631
|
-
};
|
|
1632
|
-
syncTouchedFields(e) {
|
|
1633
|
-
Object.keys(e).forEach((t) => {
|
|
1634
|
-
e[t] && this.localTouchedFields.add(t);
|
|
1635
|
-
});
|
|
1636
|
-
}
|
|
1637
|
-
clearTouchedFields() {
|
|
1638
|
-
this.localTouchedFields.clear();
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
class Ee {
|
|
1642
|
-
formManager;
|
|
1643
|
-
checkoutProfile;
|
|
1644
|
-
formElement;
|
|
1645
|
-
onUIUpdate;
|
|
1646
|
-
onProfileLoaded;
|
|
1647
|
-
onError;
|
|
1648
|
-
onLoadingChange;
|
|
1649
|
-
fontCleanup;
|
|
1650
|
-
isSubmitting = !1;
|
|
1651
|
-
isVgsMode = !1;
|
|
1652
|
-
vgsFieldsState = {};
|
|
1653
|
-
constructor(e) {
|
|
1654
|
-
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;
|
|
1655
|
-
}
|
|
1656
|
-
handleFormStateChange = () => {
|
|
1657
|
-
this.onUIUpdate();
|
|
1658
|
-
};
|
|
1659
|
-
handleProfileStateChange = (e) => {
|
|
1660
|
-
if (!e.isLoading)
|
|
1661
|
-
if (e.checkoutProfile)
|
|
1662
|
-
try {
|
|
1663
|
-
if (e.checkoutProfile.styles?.fontFamily)
|
|
1664
|
-
try {
|
|
1665
|
-
const { cleanup: t } = ie({
|
|
1666
|
-
fontFamily: e.checkoutProfile.styles.fontFamily
|
|
1667
|
-
});
|
|
1668
|
-
this.fontCleanup = t, this.formElement.style.fontFamily = e.checkoutProfile.styles.fontFamily;
|
|
1669
|
-
} catch (t) {
|
|
1670
|
-
console.error("Error loading Google Font:", t);
|
|
1671
|
-
}
|
|
1672
|
-
this.onProfileLoaded(), this.onLoadingChange(!1);
|
|
1673
|
-
} catch (t) {
|
|
1674
|
-
console.error("Error in profile state change:", t);
|
|
1675
|
-
const s = e.error || "Failed to load checkout profile data";
|
|
1676
|
-
this.onError(s), this.onLoadingChange(!1);
|
|
1677
|
-
}
|
|
1678
|
-
else e.error && (console.error("NO profile found", e.error), this.onError(e.error), this.onLoadingChange(!1));
|
|
1679
|
-
};
|
|
1680
|
-
isFormDisabled() {
|
|
1681
|
-
const e = this.formManager.getFormState(), t = this.checkoutProfile.getState(), s = Object.keys(e.errors).filter(
|
|
1682
|
-
(f) => f !== "billingAddress" && f !== "shippingAddress"
|
|
1683
|
-
).length > 0, a = e.errors.billingAddress, i = a && typeof a == "object" ? Object.keys(a).length > 0 : !1, n = e.errors.shippingAddress, r = n && typeof n == "object" ? Object.keys(n).length > 0 : !1, d = s || i || r, g = B(
|
|
1684
|
-
t.checkoutProfile?.layout
|
|
1685
|
-
) ? !!(e.formData.billingAddress?.firstName || e.formData.billingAddress?.lastName || e.formData.shippingAddress?.firstName || e.formData.shippingAddress?.lastName) : !!e.formData.name, l = t.checkoutProfile?.layout.phoneNumber?.enabled ?? !1 ? !!e.formData.phoneNumber : !0, { billingFields: m, shippingFields: y } = t.checkoutProfile?.layout ?? {}, u = /* @__PURE__ */ new Set(["US", "CA"]), p = (f, S) => {
|
|
1686
|
-
if (!f) return !0;
|
|
1687
|
-
const C = S?.country ?? "";
|
|
1688
|
-
return Object.entries(f).every(([M, k]) => !k?.enabled || M === "state" && (!u.has(C) || k.hiddenForCountries?.includes(C)) ? !0 : !!S?.[M]?.trim());
|
|
1689
|
-
}, h = !this.isVgsMode || Object.values(this.vgsFieldsState).every(
|
|
1690
|
-
(f) => f?.isValid === !0
|
|
1691
|
-
), b = this.isVgsMode ? !!e.formData.email && l && h && p(m, e.formData.billingAddress) && p(y, e.formData.shippingAddress) : !!e.formData.email && l && g && !!e.formData.cardNumber && !!e.formData.cardCvv && !!e.formData.cardExpiry && p(m, e.formData.billingAddress) && p(y, e.formData.shippingAddress);
|
|
1692
|
-
return d || !b || this.isSubmitting;
|
|
1693
|
-
}
|
|
1694
|
-
setSubmitting(e) {
|
|
1695
|
-
this.isSubmitting = e;
|
|
1696
|
-
}
|
|
1697
|
-
setVgsMode(e) {
|
|
1698
|
-
this.isVgsMode = e;
|
|
1699
|
-
}
|
|
1700
|
-
updateVgsState(e) {
|
|
1701
|
-
this.vgsFieldsState = e;
|
|
1702
|
-
}
|
|
1703
|
-
getVgsFieldErrors(e) {
|
|
1704
|
-
const t = {};
|
|
1705
|
-
for (const [s, a] of Object.entries(this.vgsFieldsState)) {
|
|
1706
|
-
if (!a?.isTouched || a.isFocused || a.isValid)
|
|
1707
|
-
continue;
|
|
1708
|
-
const i = a.errors?.[0];
|
|
1709
|
-
if (!i) continue;
|
|
1710
|
-
const n = ae(s, i.code);
|
|
1711
|
-
n && (t[s] = e(n));
|
|
1712
|
-
}
|
|
1713
|
-
return t;
|
|
1714
|
-
}
|
|
1715
|
-
getSubmitting() {
|
|
1716
|
-
return this.isSubmitting;
|
|
1717
|
-
}
|
|
1718
|
-
cleanup() {
|
|
1719
|
-
this.fontCleanup && (this.fontCleanup(), this.fontCleanup = void 0);
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
class Me extends P {
|
|
1723
|
-
titleElement;
|
|
1724
|
-
constructor(e = {}) {
|
|
1725
|
-
super("div", ["blur-bg"]);
|
|
1726
|
-
const t = A.createDiv(["loader"]);
|
|
1727
|
-
this.titleElement = new P("h3", ["title"]), this.titleElement.setText(e.text || ""), this.appendChild(t), this.appendChild(this.titleElement);
|
|
1728
|
-
}
|
|
1729
|
-
setText(e) {
|
|
1730
|
-
return this.titleElement.setText(e), this;
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
const z = {
|
|
1734
|
-
street: "",
|
|
1735
|
-
firstName: "",
|
|
1736
|
-
lastName: "",
|
|
1737
|
-
state: "",
|
|
1738
|
-
city: "",
|
|
1739
|
-
zipCode: "",
|
|
1740
|
-
country: ""
|
|
1741
|
-
}, $ = (o, e) => {
|
|
1742
|
-
const t = {}, s = `${e}.`;
|
|
1743
|
-
return Object.keys(o).forEach((a) => {
|
|
1744
|
-
if (a.startsWith(s)) {
|
|
1745
|
-
const i = a.slice(s.length);
|
|
1746
|
-
t[i] = o[a];
|
|
1747
|
-
}
|
|
1748
|
-
}), t;
|
|
1749
|
-
};
|
|
1750
|
-
class Ne {
|
|
1751
|
-
formElement;
|
|
1752
|
-
componentManager;
|
|
1753
|
-
onLoadingStateChange;
|
|
1754
|
-
spinner;
|
|
1755
|
-
formSkeleton;
|
|
1756
|
-
alert;
|
|
1757
|
-
constructor(e) {
|
|
1758
|
-
this.formElement = e.formElement, this.componentManager = e.componentManager, this.onLoadingStateChange = e.onLoadingStateChange;
|
|
1759
|
-
}
|
|
1760
|
-
updateFormUI(e, t) {
|
|
1761
|
-
this.componentManager.updatePaymentMethods(e.formData), this.componentManager.updateEmailField(
|
|
1762
|
-
e.formData.email,
|
|
1763
|
-
!!(e.errors.email && e.touched.email),
|
|
1764
|
-
e.errors.email
|
|
1765
|
-
), this.componentManager.updatePhoneNumberField(
|
|
1766
|
-
e.formData.phoneNumber ?? "",
|
|
1767
|
-
!!(e.errors.phoneNumber && e.touched.phoneNumber),
|
|
1768
|
-
e.errors.phoneNumber
|
|
1769
|
-
), this.componentManager.updateCardSection(
|
|
1770
|
-
e.formData.cardNumber,
|
|
1771
|
-
e.errors.cardNumber,
|
|
1772
|
-
!!e.touched.cardNumber,
|
|
1773
|
-
e.formData.cardCvv,
|
|
1774
|
-
e.errors.cardCvv,
|
|
1775
|
-
!!e.touched.cardCvv,
|
|
1776
|
-
e.formData.cardExpiry,
|
|
1777
|
-
e.errors.cardExpiry,
|
|
1778
|
-
!!e.touched.cardExpiry
|
|
1779
|
-
), this.componentManager.updateCardholderSection(
|
|
1780
|
-
e.formData.name,
|
|
1781
|
-
!!(e.errors.name && e.touched.name),
|
|
1782
|
-
e.errors.name
|
|
1783
|
-
), this.componentManager.updateBillingAddressSection(
|
|
1784
|
-
e.formData.billingAddress ?? z,
|
|
1785
|
-
e.errors.billingAddress ?? {},
|
|
1786
|
-
$(e.touched, "billingAddress")
|
|
1787
|
-
), this.componentManager.updateShippingAddressSection(
|
|
1788
|
-
e.formData.shippingAddress ?? z,
|
|
1789
|
-
e.errors.shippingAddress ?? {},
|
|
1790
|
-
$(e.touched, "shippingAddress")
|
|
1791
|
-
), this.componentManager.updateSubmitButton(t);
|
|
1792
|
-
}
|
|
1793
|
-
setLoadingState(e) {
|
|
1794
|
-
if (this.onLoadingStateChange) {
|
|
1795
|
-
this.onLoadingStateChange(e);
|
|
1796
|
-
return;
|
|
1797
|
-
}
|
|
1798
|
-
e ? (this.hideSkeleton(), this.formSkeleton = new j(), this.formElement.appendChild(this.formSkeleton.getElement())) : this.hideSkeleton();
|
|
1799
|
-
}
|
|
1800
|
-
showSpinner(e) {
|
|
1801
|
-
this.hideSpinner(), this.spinner = new Me({ text: e }), this.formElement.appendChild(this.spinner.getElement());
|
|
1802
|
-
}
|
|
1803
|
-
hideSpinner() {
|
|
1804
|
-
this.spinner && (this.spinner.getElement().remove(), this.spinner = void 0);
|
|
1805
|
-
}
|
|
1806
|
-
hideSkeleton() {
|
|
1807
|
-
this.formSkeleton && (this.formSkeleton.getElement().remove(), this.formSkeleton = void 0);
|
|
1808
|
-
}
|
|
1809
|
-
setErrorMessage(e) {
|
|
1810
|
-
this.alert && (this.alert.getElement().remove(), this.alert = void 0), this.alert = new ne({ message: e }), this.formElement.insertBefore(
|
|
1811
|
-
this.alert.getElement(),
|
|
1812
|
-
this.formElement.firstChild
|
|
1813
|
-
);
|
|
1814
|
-
}
|
|
1815
|
-
clearErrorMessage() {
|
|
1816
|
-
this.alert && (this.alert.getElement().remove(), this.alert = void 0);
|
|
1817
|
-
}
|
|
1818
|
-
cleanup() {
|
|
1819
|
-
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);
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
const w = (o) => ({
|
|
1823
|
-
street: "",
|
|
1824
|
-
firstName: "",
|
|
1825
|
-
lastName: "",
|
|
1826
|
-
state: "",
|
|
1827
|
-
city: "",
|
|
1828
|
-
zipCode: "",
|
|
1829
|
-
country: "",
|
|
1830
|
-
...o
|
|
1831
|
-
});
|
|
1832
|
-
class Pe extends P {
|
|
1833
|
-
options;
|
|
1834
|
-
formManager = me();
|
|
1835
|
-
checkoutProfile;
|
|
1836
|
-
translation = re();
|
|
1837
|
-
focusManager = new oe();
|
|
1838
|
-
// Managers
|
|
1839
|
-
componentManager;
|
|
1840
|
-
eventHandler;
|
|
1841
|
-
stateCoordinator;
|
|
1842
|
-
uiManager;
|
|
1843
|
-
// VGS
|
|
1844
|
-
vgsService;
|
|
1845
|
-
vgsJwt;
|
|
1846
|
-
vgsCardResult;
|
|
1847
|
-
constructor(e) {
|
|
1848
|
-
super("form", ["form-container"]), this.options = e, this.vgsJwt = e.vgsJwt, this.vgsJwt && (this.vgsService = new _()), this.checkoutProfile = ue({
|
|
1849
|
-
appearance: e.appearance
|
|
1850
|
-
}), e.locale && this.translation.setLocale(e.locale), this.componentManager = new Ce({
|
|
1851
|
-
formElement: this.element,
|
|
1852
|
-
focusManager: this.focusManager,
|
|
1853
|
-
translationFunc: this.translation.t,
|
|
1854
|
-
locale: e.locale ?? void 0,
|
|
1855
|
-
onFieldFocus: (t) => this.eventHandler.handleFieldFocus(t),
|
|
1856
|
-
onChange: (t) => this.eventHandler.handleChange(t),
|
|
1857
|
-
onBlur: (t) => this.eventHandler.handleBlur(t),
|
|
1858
|
-
onPaypalSubmit: async () => this.handlePaypalSubmit(),
|
|
1859
|
-
onApplePaySubmit: async (t) => this.handleApplePaySubmit(t),
|
|
1860
|
-
supportedPaymentMethods: e.supportedPaymentMethods,
|
|
1861
|
-
paymentId: e.paymentId,
|
|
1862
|
-
checkoutKey: e.checkoutKey,
|
|
1863
|
-
checkoutDetails: e.checkoutDetails,
|
|
1864
|
-
environment: e.environment,
|
|
1865
|
-
vgsService: this.vgsService,
|
|
1866
|
-
onVgsStateChange: (t) => this.handleVgsStateChange(t)
|
|
1867
|
-
}), this.uiManager = new Ne({
|
|
1868
|
-
formElement: this.element,
|
|
1869
|
-
componentManager: this.componentManager,
|
|
1870
|
-
onLoadingStateChange: e.onLoadingStateChange
|
|
1871
|
-
}), this.stateCoordinator = new Ee({
|
|
1872
|
-
formManager: this.formManager,
|
|
1873
|
-
checkoutProfile: this.checkoutProfile,
|
|
1874
|
-
componentManager: this.componentManager,
|
|
1875
|
-
formElement: this.element,
|
|
1876
|
-
onUIUpdate: () => this.updateFormUI(),
|
|
1877
|
-
onProfileLoaded: () => this.renderFormComponents(),
|
|
1878
|
-
onError: (t) => this.uiManager.setErrorMessage(t),
|
|
1879
|
-
onLoadingChange: (t) => this.uiManager.setLoadingState(t),
|
|
1880
|
-
getInitialFormData: () => this._getFormStateData().formData
|
|
1881
|
-
}), this.vgsService && this.stateCoordinator.setVgsMode(!0), this.eventHandler = new Fe({
|
|
1882
|
-
formManager: this.formManager,
|
|
1883
|
-
focusManager: this.focusManager,
|
|
1884
|
-
onFormSubmit: async () => this.handleSubmit(),
|
|
1885
|
-
onUIUpdate: () => this.updateFormUI()
|
|
1886
|
-
}), this.getElement().addEventListener(
|
|
1887
|
-
"submit",
|
|
1888
|
-
this.eventHandler.handleSubmit
|
|
1889
|
-
), this.getElement().addEventListener(
|
|
1890
|
-
"keydown",
|
|
1891
|
-
this.eventHandler.handleKeyDown
|
|
1892
|
-
), this.formManager.subscribe(() => {
|
|
1893
|
-
const { touched: t } = this.formManager.getFormState();
|
|
1894
|
-
this.eventHandler.syncTouchedFields(t), this.stateCoordinator.handleFormStateChange();
|
|
1895
|
-
}), this.checkoutProfile.subscribe(
|
|
1896
|
-
this.stateCoordinator.handleProfileStateChange
|
|
1897
|
-
), e.initialValues && this.formManager.setFormData({
|
|
1898
|
-
...e.initialValues.email && {
|
|
1899
|
-
email: e.initialValues.email
|
|
1900
|
-
},
|
|
1901
|
-
...e.initialValues.phoneNumber && {
|
|
1902
|
-
phoneNumber: e.initialValues.phoneNumber
|
|
1903
|
-
},
|
|
1904
|
-
...e.initialValues.name && { name: e.initialValues.name },
|
|
1905
|
-
...e.initialValues.billingAddress && {
|
|
1906
|
-
billingAddress: w(
|
|
1907
|
-
e.initialValues.billingAddress
|
|
1908
|
-
)
|
|
1909
|
-
},
|
|
1910
|
-
...e.initialValues.shippingAddress && {
|
|
1911
|
-
shippingAddress: w(
|
|
1912
|
-
e.initialValues.shippingAddress
|
|
1913
|
-
)
|
|
1914
|
-
}
|
|
1915
|
-
}), this.initializeForm(), this.appendTo(e.container);
|
|
1916
|
-
}
|
|
1917
|
-
_getFormStateData() {
|
|
1918
|
-
const e = this.formManager.getFormState(), t = this.options.initialValues;
|
|
1919
|
-
return {
|
|
1920
|
-
formData: e.formData || {
|
|
1921
|
-
email: t?.email || "",
|
|
1922
|
-
name: t?.name || "",
|
|
1923
|
-
phoneNumber: t?.phoneNumber || "",
|
|
1924
|
-
cardExpiry: "",
|
|
1925
|
-
cardNumber: "",
|
|
1926
|
-
cardCvv: "",
|
|
1927
|
-
...t?.billingAddress && {
|
|
1928
|
-
billingAddress: w(t.billingAddress)
|
|
1929
|
-
},
|
|
1930
|
-
...t?.shippingAddress && {
|
|
1931
|
-
shippingAddress: w(t.shippingAddress)
|
|
1932
|
-
}
|
|
1933
|
-
},
|
|
1934
|
-
errors: e.errors || {},
|
|
1935
|
-
touched: e.touched || {}
|
|
1936
|
-
};
|
|
1937
|
-
}
|
|
1938
|
-
initializeForm() {
|
|
1939
|
-
this.uiManager.setLoadingState(!0), this.options.errorMsg && this.uiManager.setErrorMessage(this.options.errorMsg), this.vgsService && this.vgsService.init(this.options.environment).then((e) => {
|
|
1940
|
-
this.vgsService?.createForm(
|
|
1941
|
-
e,
|
|
1942
|
-
(t) => this.handleVgsStateChange(t)
|
|
1943
|
-
);
|
|
1944
|
-
}).catch(() => {
|
|
1945
|
-
this.vgsService = void 0, this.vgsJwt = void 0;
|
|
1946
|
-
});
|
|
1947
|
-
}
|
|
1948
|
-
renderFormComponents() {
|
|
1949
|
-
const e = this.checkoutProfile.getState();
|
|
1950
|
-
if (!e.checkoutProfile) {
|
|
1951
|
-
this.uiManager.setErrorMessage("Failed to load checkout configuration");
|
|
1952
|
-
return;
|
|
1953
|
-
}
|
|
1954
|
-
this.componentManager.hasComponents() && this.componentManager.cleanup(), e.checkoutProfile.layout.phoneNumber?.enabled && this.formManager.getFormState().formData.phoneNumber === void 0 && this.formManager.setFormData({
|
|
1955
|
-
phoneNumber: "",
|
|
1956
|
-
phoneCountryCode: e.checkoutProfile.layout.phoneNumber.defaultCountry?.toUpperCase() || "US"
|
|
1957
|
-
}), e.checkoutProfile.layout.billingFields && this.formManager.getFormState().formData.billingAddress === void 0 && this.formManager.setFormData({
|
|
1958
|
-
billingAddress: w()
|
|
1959
|
-
}), e.checkoutProfile.layout.shippingFields && this.formManager.getFormState().formData.shippingAddress === void 0 && this.formManager.setFormData({
|
|
1960
|
-
shippingAddress: w()
|
|
1961
|
-
});
|
|
1962
|
-
const { formData: t, errors: s, touched: a } = this._getFormStateData(), i = pe(
|
|
1963
|
-
e.checkoutProfile.layout
|
|
1964
|
-
);
|
|
1965
|
-
try {
|
|
1966
|
-
this.componentManager.createPaymentMethods(
|
|
1967
|
-
e.checkoutProfile,
|
|
1968
|
-
t
|
|
1969
|
-
);
|
|
1970
|
-
} catch (r) {
|
|
1971
|
-
console.error("Failed to create payment methods:", r);
|
|
1972
|
-
}
|
|
1973
|
-
try {
|
|
1974
|
-
this.componentManager.createEmailField(
|
|
1975
|
-
e.checkoutProfile,
|
|
1976
|
-
t,
|
|
1977
|
-
s,
|
|
1978
|
-
a
|
|
1979
|
-
);
|
|
1980
|
-
} catch (r) {
|
|
1981
|
-
console.error("Failed to create email field:", r);
|
|
1982
|
-
}
|
|
1983
|
-
if (i) {
|
|
1984
|
-
try {
|
|
1985
|
-
this.componentManager.createBillingAddressSection(
|
|
1986
|
-
e.checkoutProfile,
|
|
1987
|
-
t,
|
|
1988
|
-
s,
|
|
1989
|
-
a
|
|
1990
|
-
);
|
|
1991
|
-
} catch (r) {
|
|
1992
|
-
console.error("Failed to create billing address section:", r);
|
|
1993
|
-
}
|
|
1994
|
-
try {
|
|
1995
|
-
this.componentManager.createShippingAddressSection(
|
|
1996
|
-
e.checkoutProfile,
|
|
1997
|
-
t,
|
|
1998
|
-
s,
|
|
1999
|
-
a
|
|
2000
|
-
);
|
|
2001
|
-
} catch (r) {
|
|
2002
|
-
console.error("Failed to create shipping address section:", r);
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
if (e.checkoutProfile.layout.phoneNumber?.enabled)
|
|
2006
|
-
try {
|
|
2007
|
-
this.componentManager.createPhoneNumberField(
|
|
2008
|
-
e.checkoutProfile,
|
|
2009
|
-
t,
|
|
2010
|
-
s,
|
|
2011
|
-
a
|
|
2012
|
-
);
|
|
2013
|
-
} catch (r) {
|
|
2014
|
-
console.error("Failed to create phone number field:", r);
|
|
2015
|
-
}
|
|
2016
|
-
try {
|
|
2017
|
-
this.componentManager.createCardSection(
|
|
2018
|
-
e.checkoutProfile,
|
|
2019
|
-
t,
|
|
2020
|
-
s,
|
|
2021
|
-
a
|
|
2022
|
-
);
|
|
2023
|
-
} catch (r) {
|
|
2024
|
-
console.error("Failed to create card section:", r);
|
|
2025
|
-
}
|
|
2026
|
-
if (!B(
|
|
2027
|
-
e.checkoutProfile.layout
|
|
2028
|
-
))
|
|
2029
|
-
try {
|
|
2030
|
-
this.componentManager.createCardholderSection(
|
|
2031
|
-
e.checkoutProfile,
|
|
2032
|
-
t,
|
|
2033
|
-
s,
|
|
2034
|
-
a
|
|
2035
|
-
);
|
|
2036
|
-
} catch (r) {
|
|
2037
|
-
console.error("Failed to create cardholder section:", r);
|
|
2038
|
-
}
|
|
2039
|
-
this.vgsService && this.componentManager.mountVgsFields(e.checkoutProfile).catch((r) => {
|
|
2040
|
-
console.error("Failed to mount VGS fields:", r);
|
|
2041
|
-
});
|
|
2042
|
-
try {
|
|
2043
|
-
this.componentManager.createSubmitButton(
|
|
2044
|
-
e.checkoutProfile,
|
|
2045
|
-
this.stateCoordinator.isFormDisabled()
|
|
2046
|
-
);
|
|
2047
|
-
} catch (r) {
|
|
2048
|
-
console.error("Failed to create submit button:", r);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
updateFormUI() {
|
|
2052
|
-
const e = this.formManager.getFormState();
|
|
2053
|
-
this.uiManager.updateFormUI(
|
|
2054
|
-
e,
|
|
2055
|
-
this.stateCoordinator.isFormDisabled()
|
|
2056
|
-
);
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Infers cardholder name from address fields (first + last name).
|
|
2060
|
-
* Uses billing address if available, otherwise shipping address.
|
|
2061
|
-
*/
|
|
2062
|
-
inferCardholderName() {
|
|
2063
|
-
const e = this.checkoutProfile.getState();
|
|
2064
|
-
if (!e.checkoutProfile || !B(
|
|
2065
|
-
e.checkoutProfile.layout
|
|
2066
|
-
)) return;
|
|
2067
|
-
const { formData: s } = this._getFormStateData(), a = s.billingAddress ?? s.shippingAddress;
|
|
2068
|
-
if (!a) return;
|
|
2069
|
-
const i = a.firstName?.trim() ?? "", n = a.lastName?.trim() ?? "", r = [i, n].filter(Boolean).join(" ");
|
|
2070
|
-
r && this.formManager.setFormData({ name: r });
|
|
2071
|
-
}
|
|
2072
|
-
/**
|
|
2073
|
-
* Infers address data based on field configuration.
|
|
2074
|
-
* If billing fields are disabled but shipping is enabled, copies shipping to billing.
|
|
2075
|
-
* If shipping fields are disabled but billing is enabled, copies billing to shipping.
|
|
2076
|
-
*/
|
|
2077
|
-
inferAddresses() {
|
|
2078
|
-
const e = this.checkoutProfile.getState();
|
|
2079
|
-
if (!e.checkoutProfile) return;
|
|
2080
|
-
const { billingFields: t, shippingFields: s } = e.checkoutProfile.layout, a = t && Object.values(t).some((r) => r?.enabled), i = s && Object.values(s).some((r) => r?.enabled), { formData: n } = this._getFormStateData();
|
|
2081
|
-
!a && i && n.shippingAddress ? this.formManager.setFormData({
|
|
2082
|
-
billingAddress: { ...n.shippingAddress }
|
|
2083
|
-
}) : !i && a && n.billingAddress && this.formManager.setFormData({
|
|
2084
|
-
shippingAddress: { ...n.billingAddress }
|
|
2085
|
-
});
|
|
2086
|
-
}
|
|
2087
|
-
handleVgsStateChange(e) {
|
|
2088
|
-
this.stateCoordinator.updateVgsState(e);
|
|
2089
|
-
const t = this.stateCoordinator.getVgsFieldErrors(
|
|
2090
|
-
this.translation.t
|
|
2091
|
-
);
|
|
2092
|
-
this.componentManager.handleVgsStateChange(e, t), this.updateFormUI();
|
|
2093
|
-
}
|
|
2094
|
-
async handleSubmit() {
|
|
2095
|
-
if (!this.stateCoordinator.isFormDisabled())
|
|
2096
|
-
try {
|
|
2097
|
-
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)
|
|
2098
|
-
try {
|
|
2099
|
-
this.vgsCardResult = await this.vgsService.createCard(this.vgsJwt);
|
|
2100
|
-
} catch (t) {
|
|
2101
|
-
console.error("VGS card creation failed:", t), this.handleSubmitError(
|
|
2102
|
-
"Card processing failed. Please check your card details and try again."
|
|
2103
|
-
);
|
|
2104
|
-
return;
|
|
2105
|
-
}
|
|
2106
|
-
const e = this.formManager.getFormState().formData;
|
|
2107
|
-
await this.options.onSubmit({
|
|
2108
|
-
formData: this.vgsCardResult ? {
|
|
2109
|
-
...e,
|
|
2110
|
-
vgsCardData: {
|
|
2111
|
-
cardId: this.vgsCardResult.cardId,
|
|
2112
|
-
expMonth: this.vgsCardResult.expMonth,
|
|
2113
|
-
expYear: this.vgsCardResult.expYear,
|
|
2114
|
-
name: this.vgsCardResult.name,
|
|
2115
|
-
...this.vgsCardResult.updatedValues && {
|
|
2116
|
-
updatedValues: this.vgsCardResult.updatedValues
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
|
-
} : e
|
|
2120
|
-
}), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
2121
|
-
} catch {
|
|
2122
|
-
this.handleSubmitError("Payment processing failed. Please try again.");
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
handleSubmitError(e) {
|
|
2126
|
-
this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.uiManager.setErrorMessage(e), this.updateFormUI();
|
|
2127
|
-
}
|
|
2128
|
-
async handlePaypalSubmit() {
|
|
2129
|
-
this.stateCoordinator.setSubmitting(!0), this.updateFormUI(), this.options.onLoadingStateChange?.(!0), this.uiManager.showSpinner(this.translation.t("loading"));
|
|
2130
|
-
try {
|
|
2131
|
-
await this.options.onSubmit({
|
|
2132
|
-
formData: null
|
|
2133
|
-
});
|
|
2134
|
-
} catch {
|
|
2135
|
-
this.uiManager.setErrorMessage(
|
|
2136
|
-
"PayPal processing failed. Please try again."
|
|
2137
|
-
), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
2138
|
-
}
|
|
2139
|
-
}
|
|
2140
|
-
async handleApplePaySubmit(e) {
|
|
2141
|
-
this.stateCoordinator.setSubmitting(!0), this.updateFormUI(), this.options.onLoadingStateChange?.(!0), this.uiManager.showSpinner(this.translation.t("loading"));
|
|
2142
|
-
try {
|
|
2143
|
-
await this.options.onSubmit({
|
|
2144
|
-
formData: null,
|
|
2145
|
-
applePayData: e.applePayData
|
|
2146
|
-
}), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
2147
|
-
} catch {
|
|
2148
|
-
this.uiManager.setErrorMessage(
|
|
2149
|
-
"Apple Pay processing failed. Please try again."
|
|
2150
|
-
), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
setErrorMessage(e) {
|
|
2154
|
-
return this.uiManager.setErrorMessage(e), this;
|
|
2155
|
-
}
|
|
2156
|
-
clearErrorMessage() {
|
|
2157
|
-
return this.uiManager.clearErrorMessage(), this;
|
|
2158
|
-
}
|
|
2159
|
-
updateAppearance(e) {
|
|
2160
|
-
e.locale && this.translation.setLocale(e.locale), e.appearance && this.checkoutProfile.updateProfile(e.appearance), e.locale && (this.componentManager.cleanup(), this.renderFormComponents());
|
|
2161
|
-
}
|
|
2162
|
-
destroy() {
|
|
2163
|
-
this.vgsService?.destroy(), this.stateCoordinator.cleanup(), this.eventHandler.clearTouchedFields(), this.getElement().removeEventListener(
|
|
2164
|
-
"submit",
|
|
2165
|
-
this.eventHandler.handleSubmit
|
|
2166
|
-
), this.getElement().removeEventListener(
|
|
2167
|
-
"keydown",
|
|
2168
|
-
this.eventHandler.handleKeyDown
|
|
2169
|
-
), this.componentManager.cleanup(), this.uiManager.cleanup(), this.getElement().remove();
|
|
2170
|
-
}
|
|
2171
|
-
associatePayment(e, t, s, a, i) {
|
|
2172
|
-
this.options.paymentId = e, this.options.checkoutKey = t, this.options.supportedPaymentMethods = s, this.options.checkoutDetails = a, this.componentManager.setCheckoutDetailsLoaded(!0), i && !this.vgsService && (this.vgsJwt = i, this.vgsService = new _(), this.componentManager.setVgsService(this.vgsService), this.stateCoordinator.setVgsMode(!0), this.vgsService.init(this.options.environment).then((r) => {
|
|
2173
|
-
this.vgsService?.createForm(
|
|
2174
|
-
r,
|
|
2175
|
-
(d) => this.handleVgsStateChange(d)
|
|
2176
|
-
), this.renderFormComponents();
|
|
2177
|
-
}).catch((r) => {
|
|
2178
|
-
console.error("Failed to load VGS Collect:", r), this.vgsService = void 0, this.vgsJwt = void 0, this.renderFormComponents();
|
|
2179
|
-
})), this.componentManager.removePaymentMethods(), this.componentManager.updateSupportedPaymentMethods(
|
|
2180
|
-
s
|
|
2181
|
-
), this.componentManager.updatePaymentDetails(
|
|
2182
|
-
e,
|
|
2183
|
-
t,
|
|
2184
|
-
a
|
|
2185
|
-
), !i && this.checkoutProfile.getState().checkoutProfile && this.renderFormComponents();
|
|
2186
|
-
const n = this.checkoutProfile.getState();
|
|
2187
|
-
if (n.checkoutProfile) {
|
|
2188
|
-
const { formData: r } = this._getFormStateData();
|
|
2189
|
-
this.componentManager.createPaymentMethods(
|
|
2190
|
-
n.checkoutProfile,
|
|
2191
|
-
r,
|
|
2192
|
-
!0
|
|
2193
|
-
);
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
class ke {
|
|
2198
|
-
container = null;
|
|
2199
|
-
options;
|
|
2200
|
-
onSubmit;
|
|
2201
|
-
form = null;
|
|
2202
|
-
constructor(e, t) {
|
|
2203
|
-
this.options = e, this.onSubmit = t;
|
|
2204
|
-
}
|
|
2205
|
-
mount(e) {
|
|
2206
|
-
this.unmount(), this.container = e, this.renderForm();
|
|
2207
|
-
}
|
|
2208
|
-
update(e) {
|
|
2209
|
-
if (!(!this.container || !this.form)) {
|
|
2210
|
-
if (e.appearance || e.locale) {
|
|
2211
|
-
this.form.updateAppearance({
|
|
2212
|
-
appearance: e.appearance,
|
|
2213
|
-
locale: e.locale
|
|
2214
|
-
});
|
|
2215
|
-
return;
|
|
2216
|
-
}
|
|
2217
|
-
e.errorMsg && !this.options.disableErrorMessages ? this.form.setErrorMessage(e.errorMsg) : this.renderForm(e.errorMsg);
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
renderForm(e) {
|
|
2221
|
-
this.container && (this.form && (this.form.destroy(), this.form = null), this.form = new Pe({
|
|
2222
|
-
apiKey: this.options.apiKey,
|
|
2223
|
-
onSubmit: this.onSubmit,
|
|
2224
|
-
locale: this.options.locale,
|
|
2225
|
-
errorMsg: this.options.disableErrorMessages ? void 0 : e,
|
|
2226
|
-
container: this.container,
|
|
2227
|
-
environment: this.options.environment,
|
|
2228
|
-
appearance: this.options.appearance,
|
|
2229
|
-
onLoadingStateChange: this.options.onLoadingStateChange,
|
|
2230
|
-
paymentId: this.options.paymentId,
|
|
2231
|
-
checkoutKey: this.options.checkoutKey,
|
|
2232
|
-
checkoutDetails: this.options.checkoutDetails,
|
|
2233
|
-
initialValues: this.options.initialValues,
|
|
2234
|
-
vgsJwt: this.options.vgsJwt
|
|
2235
|
-
}));
|
|
2236
|
-
}
|
|
2237
|
-
unmount() {
|
|
2238
|
-
this.form && (this.form.destroy(), this.form = null);
|
|
2239
|
-
}
|
|
2240
|
-
displayError(e) {
|
|
2241
|
-
if (!this.form)
|
|
2242
|
-
throw new Error("Cannot display error: form is not mounted");
|
|
2243
|
-
this.form.setErrorMessage(e);
|
|
2244
|
-
}
|
|
2245
|
-
clearError() {
|
|
2246
|
-
this.form && this.form.clearErrorMessage();
|
|
2247
|
-
}
|
|
2248
|
-
async associatePayment(e, t, s, a, i) {
|
|
2249
|
-
this.options.paymentId = e, this.options.checkoutKey = t, this.options.checkoutDetails = a, this.options.vgsJwt = i, this.form && this.form.associatePayment(
|
|
2250
|
-
e,
|
|
2251
|
-
t,
|
|
2252
|
-
s,
|
|
2253
|
-
a,
|
|
2254
|
-
i
|
|
2255
|
-
);
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
class Ae {
|
|
2259
|
-
state;
|
|
2260
|
-
listeners = /* @__PURE__ */ new Set();
|
|
2261
|
-
constructor(e) {
|
|
2262
|
-
this.state = e;
|
|
2263
|
-
}
|
|
2264
|
-
getState() {
|
|
2265
|
-
return { ...this.state };
|
|
2266
|
-
}
|
|
2267
|
-
updateState(e) {
|
|
2268
|
-
this.state = { ...this.state, ...e }, this.notifyListeners();
|
|
2269
|
-
}
|
|
2270
|
-
subscribe(e) {
|
|
2271
|
-
return this.listeners.add(e), () => {
|
|
2272
|
-
this.listeners.delete(e);
|
|
2273
|
-
};
|
|
2274
|
-
}
|
|
2275
|
-
notifyListeners() {
|
|
2276
|
-
const e = this.getState();
|
|
2277
|
-
this.listeners.forEach((t) => t(e));
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
const we = "en";
|
|
2281
|
-
class De {
|
|
2282
|
-
config;
|
|
2283
|
-
_callbacks;
|
|
2284
|
-
paymentState;
|
|
2285
|
-
apiService;
|
|
2286
|
-
formManager;
|
|
2287
|
-
stateManager;
|
|
2288
|
-
sessionId;
|
|
2289
|
-
constructor(e) {
|
|
2290
|
-
this.config = this.validateConfig(e), this._callbacks = { ...this.config.callbacks }, this.paymentState = {}, this.sessionId = crypto.randomUUID(), le({
|
|
2291
|
-
environment: this.config.environment,
|
|
2292
|
-
sessionId: this.sessionId
|
|
2293
|
-
}), F(E.CHECKOUT_INITIALIZED, {
|
|
2294
|
-
environment: this.config.environment
|
|
2295
|
-
}), this.apiService = new de(
|
|
2296
|
-
this.config.apiKey,
|
|
2297
|
-
this.config.environment
|
|
2298
|
-
), this.stateManager = new Ae({
|
|
2299
|
-
mounted: !1,
|
|
2300
|
-
form: null
|
|
2301
|
-
}), this.formManager = new ke(
|
|
2302
|
-
{
|
|
2303
|
-
locale: this.config.locale,
|
|
2304
|
-
apiKey: this.config.apiKey,
|
|
2305
|
-
disableErrorMessages: this.config.disableErrorMessages,
|
|
2306
|
-
environment: this.config.environment,
|
|
2307
|
-
appearance: this.config.appearance,
|
|
2308
|
-
onLoadingStateChange: (...t) => this._callbacks.onLoadingStateChange?.(...t),
|
|
2309
|
-
initialValues: this.config.initialValues
|
|
2310
|
-
},
|
|
2311
|
-
this.handleSubmit.bind(this)
|
|
2312
|
-
);
|
|
2313
|
-
}
|
|
2314
|
-
validateConfig(e) {
|
|
2315
|
-
if (!e.apiKey)
|
|
2316
|
-
throw new Error("API key is required");
|
|
2317
|
-
if (!e.environment || !["test", "live"].includes(e.environment))
|
|
2318
|
-
throw new Error('Environment must be "test" or "live"');
|
|
2319
|
-
return {
|
|
2320
|
-
apiKey: e.apiKey,
|
|
2321
|
-
returnUrl: e.returnUrl,
|
|
2322
|
-
environment: e.environment,
|
|
2323
|
-
locale: e.locale || we,
|
|
2324
|
-
disableErrorMessages: e.disableErrorMessages ?? !1,
|
|
2325
|
-
manualActionHandling: e.manualActionHandling ?? !1,
|
|
2326
|
-
appearance: e.appearance,
|
|
2327
|
-
initialValues: e.initialValues || {},
|
|
2328
|
-
callbacks: {
|
|
2329
|
-
onPaymentSucceeded: e.callbacks?.onPaymentSucceeded || void 0,
|
|
2330
|
-
onPaymentFailed: e.callbacks?.onPaymentFailed || void 0,
|
|
2331
|
-
onActionRequired: e.callbacks?.onActionRequired || void 0,
|
|
2332
|
-
onLoadingStateChange: e.callbacks?.onLoadingStateChange || void 0
|
|
2333
|
-
}
|
|
2334
|
-
};
|
|
2335
|
-
}
|
|
2336
|
-
mount(e) {
|
|
2337
|
-
const t = document.querySelector(e);
|
|
2338
|
-
if (!t)
|
|
2339
|
-
throw new Error(`Container ${e} not found`);
|
|
2340
|
-
const s = document.createElement("div");
|
|
2341
|
-
return t.appendChild(s), this.stateManager.updateState({
|
|
2342
|
-
form: s,
|
|
2343
|
-
mounted: !0
|
|
2344
|
-
}), this.formManager.mount(s), F(E.CHECKOUT_MOUNTED, {
|
|
2345
|
-
container_id: e
|
|
2346
|
-
}), this;
|
|
2347
|
-
}
|
|
2348
|
-
unmount() {
|
|
2349
|
-
const { mounted: e } = this.stateManager.getState();
|
|
2350
|
-
e && Promise.resolve().then(() => {
|
|
2351
|
-
this.formManager.unmount();
|
|
2352
|
-
const { form: t } = this.stateManager.getState();
|
|
2353
|
-
t && t.remove(), this.stateManager.updateState({
|
|
2354
|
-
form: null,
|
|
2355
|
-
mounted: !1
|
|
2356
|
-
}), F(E.CHECKOUT_UNMOUNTED);
|
|
2357
|
-
});
|
|
2358
|
-
}
|
|
2359
|
-
async handleSubmit({
|
|
2360
|
-
formData: e,
|
|
2361
|
-
applePayData: t
|
|
2362
|
-
}) {
|
|
2363
|
-
if (!this.paymentState.paymentId || !this.paymentState.checkoutKey)
|
|
2364
|
-
throw new Error(
|
|
2365
|
-
"Payment must be associated before submitting. Call associatePayment() first."
|
|
2366
|
-
);
|
|
2367
|
-
const s = this.getPaymentMethod(e, t);
|
|
2368
|
-
F(E.PAYMENT_SUBMIT_STARTED, {
|
|
2369
|
-
payment_id: this.paymentState.paymentId,
|
|
2370
|
-
payment_method: s
|
|
2371
|
-
});
|
|
2372
|
-
const a = performance.now();
|
|
2373
|
-
try {
|
|
2374
|
-
const i = await this.apiService.authorizePayment({
|
|
2375
|
-
checkoutKey: this.paymentState.checkoutKey,
|
|
2376
|
-
formData: e || null,
|
|
2377
|
-
paymentId: this.paymentState.paymentId,
|
|
2378
|
-
returnUrl: this.config.returnUrl,
|
|
2379
|
-
applePayData: t
|
|
2380
|
-
}), n = performance.now() - a;
|
|
2381
|
-
U(
|
|
2382
|
-
H.PAYMENT_AUTHORIZATION_TIME,
|
|
2383
|
-
n,
|
|
2384
|
-
"ms",
|
|
2385
|
-
{
|
|
2386
|
-
payment_id: this.paymentState.paymentId,
|
|
2387
|
-
payment_method: s,
|
|
2388
|
-
status: "success"
|
|
2389
|
-
}
|
|
2390
|
-
), F(E.PAYMENT_SUBMIT_SUCCESS, {
|
|
2391
|
-
payment_id: this.paymentState.paymentId,
|
|
2392
|
-
payment_method: s
|
|
2393
|
-
}), this.handlePaymentResponse(i);
|
|
2394
|
-
} catch (i) {
|
|
2395
|
-
const n = performance.now() - a;
|
|
2396
|
-
U(
|
|
2397
|
-
H.PAYMENT_AUTHORIZATION_TIME,
|
|
2398
|
-
n,
|
|
2399
|
-
"ms",
|
|
2400
|
-
{
|
|
2401
|
-
payment_id: this.paymentState.paymentId,
|
|
2402
|
-
payment_method: s,
|
|
2403
|
-
status: "failed"
|
|
2404
|
-
}
|
|
2405
|
-
), F(E.PAYMENT_SUBMIT_FAILED, {
|
|
2406
|
-
payment_id: this.paymentState.paymentId,
|
|
2407
|
-
payment_method: s,
|
|
2408
|
-
error_message: i.details?.message ?? "Unknown error"
|
|
2409
|
-
}), this.handleAuthorizationError(i);
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
handlePaymentResponse(e) {
|
|
2413
|
-
if (e.latestTransaction.status === "authorized" && (F(E.PAYMENT_AUTHORIZED, {
|
|
2414
|
-
payment_id: this.paymentState.paymentId ?? "",
|
|
2415
|
-
status: e.latestTransaction.status
|
|
2416
|
-
}), this._callbacks.onPaymentSucceeded?.(e.latestTransaction.status)), e.latestTransaction.status === "failed" && (F(E.PAYMENT_FAILED, {
|
|
2417
|
-
payment_id: this.paymentState.paymentId ?? "",
|
|
2418
|
-
status: e.latestTransaction.status
|
|
2419
|
-
}), this._callbacks.onPaymentFailed?.(e.latestTransaction.status)), e.status === "requires_action") {
|
|
2420
|
-
const { redirectUrl: t } = e.action;
|
|
2421
|
-
F(E.PAYMENT_ACTION_REQUIRED, {
|
|
2422
|
-
payment_id: this.paymentState.paymentId ?? "",
|
|
2423
|
-
status: e.status
|
|
2424
|
-
}), this.config.manualActionHandling ? this._callbacks.onActionRequired?.(t) : globalThis.location.href = t;
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
handleAuthorizationError(e) {
|
|
2428
|
-
this._callbacks.onPaymentFailed?.(e.details?.message);
|
|
2429
|
-
const { form: t } = this.stateManager.getState();
|
|
2430
|
-
t && this.formManager.update({ errorMsg: e.details?.message });
|
|
2431
|
-
}
|
|
2432
|
-
getPaymentMethod(e, t) {
|
|
2433
|
-
return t ? "apple_pay" : e === null ? "paypal" : "card";
|
|
2434
|
-
}
|
|
2435
|
-
displayError(e) {
|
|
2436
|
-
const { mounted: t } = this.stateManager.getState();
|
|
2437
|
-
if (!t)
|
|
2438
|
-
throw new Error("Cannot display error: checkout is not mounted");
|
|
2439
|
-
this.formManager.displayError(e);
|
|
2440
|
-
}
|
|
2441
|
-
clearError() {
|
|
2442
|
-
const { mounted: e } = this.stateManager.getState();
|
|
2443
|
-
if (!e)
|
|
2444
|
-
throw new Error("Cannot clear error: checkout is not mounted");
|
|
2445
|
-
this.formManager.clearError();
|
|
2446
|
-
}
|
|
2447
|
-
update(e) {
|
|
2448
|
-
const { mounted: t } = this.stateManager.getState();
|
|
2449
|
-
if (!t)
|
|
2450
|
-
throw new Error("Cannot update: checkout is not mounted");
|
|
2451
|
-
e.appearance && (this.config.appearance = e.appearance), e.locale && (this.config.locale = e.locale), this.formManager.update({
|
|
2452
|
-
appearance: e.appearance,
|
|
2453
|
-
locale: e.locale
|
|
2454
|
-
});
|
|
2455
|
-
}
|
|
2456
|
-
async associatePayment(e, t) {
|
|
2457
|
-
if (!e || !t)
|
|
2458
|
-
throw new Error("paymentId and checkoutKey are required");
|
|
2459
|
-
this.paymentState.paymentId = e, this.paymentState.checkoutKey = t;
|
|
2460
|
-
try {
|
|
2461
|
-
const s = await he({
|
|
2462
|
-
id: e,
|
|
2463
|
-
checkoutKey: t,
|
|
2464
|
-
environment: this.config.environment
|
|
2465
|
-
});
|
|
2466
|
-
if (!s || !s.supportedPaymentMethods || !Array.isArray(s.supportedPaymentMethods))
|
|
2467
|
-
throw new Error(
|
|
2468
|
-
"Invalid response: supportedPaymentMethods must be an array"
|
|
2469
|
-
);
|
|
2470
|
-
if (!s.supportedPaymentMethods.every(
|
|
2471
|
-
(i) => typeof i == "string"
|
|
2472
|
-
))
|
|
2473
|
-
throw new Error(
|
|
2474
|
-
"Invalid response: all supportedPaymentMethods must be strings"
|
|
2475
|
-
);
|
|
2476
|
-
this.paymentState.checkoutDetails = {
|
|
2477
|
-
amount: s.amount,
|
|
2478
|
-
currency: s.currency,
|
|
2479
|
-
countryCode: s.countryCode
|
|
2480
|
-
};
|
|
2481
|
-
const a = s.supportedPaymentMethods.reduce(
|
|
2482
|
-
(i, n) => (i[n] = !0, i),
|
|
2483
|
-
{}
|
|
2484
|
-
);
|
|
2485
|
-
await this.formManager.associatePayment(
|
|
2486
|
-
e,
|
|
2487
|
-
t,
|
|
2488
|
-
a,
|
|
2489
|
-
this.paymentState.checkoutDetails,
|
|
2490
|
-
s.vgsJwt
|
|
2491
|
-
), F(E.PAYMENT_ASSOCIATED, {
|
|
2492
|
-
payment_id: e,
|
|
2493
|
-
currency: s.currency,
|
|
2494
|
-
country_code: s.countryCode
|
|
2495
|
-
});
|
|
2496
|
-
} catch (s) {
|
|
2497
|
-
throw F(E.PAYMENT_ASSOCIATION_FAILED, {
|
|
2498
|
-
payment_id: e,
|
|
2499
|
-
error_message: s instanceof Error ? s.message : "Unknown error"
|
|
2500
|
-
}), ce(
|
|
2501
|
-
s instanceof Error ? s : new Error("Failed to associate payment"),
|
|
2502
|
-
{ payment_id: e }
|
|
2503
|
-
), s;
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
setCallbacks(e) {
|
|
2507
|
-
Object.assign(this._callbacks, e);
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
typeof globalThis < "u" && (globalThis.OdusCheckout = De);
|
|
2511
|
-
export {
|
|
2512
|
-
De as OdusCheckout,
|
|
2513
|
-
Ie as deLocale,
|
|
2514
|
-
Be as enLocale,
|
|
2515
|
-
Te as esLocale,
|
|
2516
|
-
Re as frLocale,
|
|
2517
|
-
_e as itLocale,
|
|
2518
|
-
Ue as plLocale,
|
|
2519
|
-
He as ptLocale,
|
|
2520
|
-
ce as pushError,
|
|
2521
|
-
F as pushEvent,
|
|
2522
|
-
Oe as pushLog,
|
|
2523
|
-
U as pushMeasurement,
|
|
2524
|
-
ze as trLocale
|
|
1126
|
+
globalThis.navigator.userAgent;
|
|
1127
|
+
var Q = (e) => ({
|
|
1128
|
+
street: "",
|
|
1129
|
+
firstName: "",
|
|
1130
|
+
lastName: "",
|
|
1131
|
+
state: "",
|
|
1132
|
+
city: "",
|
|
1133
|
+
zipCode: "",
|
|
1134
|
+
country: "",
|
|
1135
|
+
...e
|
|
1136
|
+
}), oe = class extends v {
|
|
1137
|
+
options;
|
|
1138
|
+
formManager = u();
|
|
1139
|
+
checkoutProfile;
|
|
1140
|
+
translation = p();
|
|
1141
|
+
focusManager = new M();
|
|
1142
|
+
componentManager;
|
|
1143
|
+
eventHandler;
|
|
1144
|
+
stateCoordinator;
|
|
1145
|
+
uiManager;
|
|
1146
|
+
vgsService;
|
|
1147
|
+
vgsJwt;
|
|
1148
|
+
vgsCardResult;
|
|
1149
|
+
constructor(e) {
|
|
1150
|
+
super("form", ["form-container"]), this.options = e, this.vgsJwt = e.vgsJwt, this.vgsJwt && (this.vgsService = new s()), this.checkoutProfile = i({ appearance: e.appearance }), e.locale && this.translation.setLocale(e.locale), this.componentManager = new q({
|
|
1151
|
+
formElement: this.element,
|
|
1152
|
+
focusManager: this.focusManager,
|
|
1153
|
+
translationFunc: this.translation.t,
|
|
1154
|
+
locale: e.locale ?? void 0,
|
|
1155
|
+
onFieldFocus: (e) => this.eventHandler.handleFieldFocus(e),
|
|
1156
|
+
onChange: (e) => this.eventHandler.handleChange(e),
|
|
1157
|
+
onBlur: (e) => this.eventHandler.handleBlur(e),
|
|
1158
|
+
onPaypalSubmit: async () => this.handlePaypalSubmit(),
|
|
1159
|
+
onApplePaySubmit: async (e) => this.handleApplePaySubmit(e),
|
|
1160
|
+
supportedPaymentMethods: e.supportedPaymentMethods,
|
|
1161
|
+
paymentId: e.paymentId,
|
|
1162
|
+
checkoutKey: e.checkoutKey,
|
|
1163
|
+
checkoutDetails: e.checkoutDetails,
|
|
1164
|
+
environment: e.environment,
|
|
1165
|
+
vgsService: this.vgsService,
|
|
1166
|
+
onVgsStateChange: (e) => this.handleVgsStateChange(e)
|
|
1167
|
+
}), this.uiManager = new ae({
|
|
1168
|
+
formElement: this.element,
|
|
1169
|
+
componentManager: this.componentManager,
|
|
1170
|
+
onLoadingStateChange: e.onLoadingStateChange
|
|
1171
|
+
}), this.stateCoordinator = new Y({
|
|
1172
|
+
formManager: this.formManager,
|
|
1173
|
+
checkoutProfile: this.checkoutProfile,
|
|
1174
|
+
componentManager: this.componentManager,
|
|
1175
|
+
formElement: this.element,
|
|
1176
|
+
onUIUpdate: () => this.updateFormUI(),
|
|
1177
|
+
onProfileLoaded: () => this.renderFormComponents(),
|
|
1178
|
+
onError: (e) => this.uiManager.setErrorMessage(e),
|
|
1179
|
+
onLoadingChange: (e) => this.uiManager.setLoadingState(e),
|
|
1180
|
+
getInitialFormData: () => this._getFormStateData().formData
|
|
1181
|
+
}), this.vgsService && this.stateCoordinator.setVgsMode(!0), this.eventHandler = new J({
|
|
1182
|
+
formManager: this.formManager,
|
|
1183
|
+
focusManager: this.focusManager,
|
|
1184
|
+
onFormSubmit: async () => this.handleSubmit(),
|
|
1185
|
+
onUIUpdate: () => this.updateFormUI()
|
|
1186
|
+
}), this.getElement().addEventListener("submit", this.eventHandler.handleSubmit), this.getElement().addEventListener("keydown", this.eventHandler.handleKeyDown), this.formManager.subscribe(() => {
|
|
1187
|
+
let { touched: e } = this.formManager.getFormState();
|
|
1188
|
+
this.eventHandler.syncTouchedFields(e), this.stateCoordinator.handleFormStateChange();
|
|
1189
|
+
}), this.checkoutProfile.subscribe(this.stateCoordinator.handleProfileStateChange), e.initialValues && this.formManager.setFormData({
|
|
1190
|
+
...e.initialValues.email && { email: e.initialValues.email },
|
|
1191
|
+
...e.initialValues.phoneNumber && { phoneNumber: e.initialValues.phoneNumber },
|
|
1192
|
+
...e.initialValues.name && { name: e.initialValues.name },
|
|
1193
|
+
...e.initialValues.billingAddress && { billingAddress: Q(e.initialValues.billingAddress) },
|
|
1194
|
+
...e.initialValues.shippingAddress && { shippingAddress: Q(e.initialValues.shippingAddress) }
|
|
1195
|
+
}), this.initializeForm(), this.appendTo(e.container);
|
|
1196
|
+
}
|
|
1197
|
+
_getFormStateData() {
|
|
1198
|
+
let e = this.formManager.getFormState(), t = this.options.initialValues;
|
|
1199
|
+
return {
|
|
1200
|
+
formData: e.formData || {
|
|
1201
|
+
email: t?.email || "",
|
|
1202
|
+
name: t?.name || "",
|
|
1203
|
+
phoneNumber: t?.phoneNumber || "",
|
|
1204
|
+
cardExpiry: "",
|
|
1205
|
+
cardNumber: "",
|
|
1206
|
+
cardCvv: "",
|
|
1207
|
+
...t?.billingAddress && { billingAddress: Q(t.billingAddress) },
|
|
1208
|
+
...t?.shippingAddress && { shippingAddress: Q(t.shippingAddress) }
|
|
1209
|
+
},
|
|
1210
|
+
errors: e.errors || {},
|
|
1211
|
+
touched: e.touched || {}
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
initializeForm() {
|
|
1215
|
+
this.uiManager.setLoadingState(!0), this.options.errorMsg && this.uiManager.setErrorMessage(this.options.errorMsg), this.vgsService && this.vgsService.init(this.options.environment).then((e) => {
|
|
1216
|
+
this.vgsService?.createForm(e, (e) => this.handleVgsStateChange(e));
|
|
1217
|
+
}).catch(() => {
|
|
1218
|
+
this.vgsService = void 0, this.vgsJwt = void 0;
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
renderFormComponents() {
|
|
1222
|
+
let e = this.checkoutProfile.getState();
|
|
1223
|
+
if (!e.checkoutProfile) {
|
|
1224
|
+
this.uiManager.setErrorMessage("Failed to load checkout configuration");
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
this.componentManager.hasComponents() && this.componentManager.cleanup(), e.checkoutProfile.layout.phoneNumber?.enabled && this.formManager.getFormState().formData.phoneNumber === void 0 && this.formManager.setFormData({
|
|
1228
|
+
phoneNumber: "",
|
|
1229
|
+
phoneCountryCode: e.checkoutProfile.layout.phoneNumber.defaultCountry?.toUpperCase() || "US"
|
|
1230
|
+
}), e.checkoutProfile.layout.billingFields && this.formManager.getFormState().formData.billingAddress === void 0 && this.formManager.setFormData({ billingAddress: Q() }), e.checkoutProfile.layout.shippingFields && this.formManager.getFormState().formData.shippingAddress === void 0 && this.formManager.setFormData({ shippingAddress: Q() });
|
|
1231
|
+
let { formData: t, errors: n, touched: r } = this._getFormStateData(), i = I(e.checkoutProfile.layout);
|
|
1232
|
+
try {
|
|
1233
|
+
this.componentManager.createPaymentMethods(e.checkoutProfile, t);
|
|
1234
|
+
} catch (e) {
|
|
1235
|
+
console.error("Failed to create payment methods:", e);
|
|
1236
|
+
}
|
|
1237
|
+
try {
|
|
1238
|
+
this.componentManager.createEmailField(e.checkoutProfile, t, n, r);
|
|
1239
|
+
} catch (e) {
|
|
1240
|
+
console.error("Failed to create email field:", e);
|
|
1241
|
+
}
|
|
1242
|
+
if (i) {
|
|
1243
|
+
try {
|
|
1244
|
+
this.componentManager.createBillingAddressSection(e.checkoutProfile, t, n, r);
|
|
1245
|
+
} catch (e) {
|
|
1246
|
+
console.error("Failed to create billing address section:", e);
|
|
1247
|
+
}
|
|
1248
|
+
try {
|
|
1249
|
+
this.componentManager.createShippingAddressSection(e.checkoutProfile, t, n, r);
|
|
1250
|
+
} catch (e) {
|
|
1251
|
+
console.error("Failed to create shipping address section:", e);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
if (e.checkoutProfile.layout.phoneNumber?.enabled) try {
|
|
1255
|
+
this.componentManager.createPhoneNumberField(e.checkoutProfile, t, n, r);
|
|
1256
|
+
} catch (e) {
|
|
1257
|
+
console.error("Failed to create phone number field:", e);
|
|
1258
|
+
}
|
|
1259
|
+
try {
|
|
1260
|
+
this.componentManager.createCardSection(e.checkoutProfile, t, n, r);
|
|
1261
|
+
} catch (e) {
|
|
1262
|
+
console.error("Failed to create card section:", e);
|
|
1263
|
+
}
|
|
1264
|
+
if (!L(e.checkoutProfile.layout)) try {
|
|
1265
|
+
this.componentManager.createCardholderSection(e.checkoutProfile, t, n, r);
|
|
1266
|
+
} catch (e) {
|
|
1267
|
+
console.error("Failed to create cardholder section:", e);
|
|
1268
|
+
}
|
|
1269
|
+
this.vgsService && this.componentManager.mountVgsFields(e.checkoutProfile).catch((e) => {
|
|
1270
|
+
console.error("Failed to mount VGS fields:", e);
|
|
1271
|
+
});
|
|
1272
|
+
try {
|
|
1273
|
+
this.componentManager.createSubmitButton(e.checkoutProfile, this.stateCoordinator.isFormDisabled());
|
|
1274
|
+
} catch (e) {
|
|
1275
|
+
console.error("Failed to create submit button:", e);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
updateFormUI() {
|
|
1279
|
+
let e = this.formManager.getFormState();
|
|
1280
|
+
this.uiManager.updateFormUI(e, this.stateCoordinator.isFormDisabled());
|
|
1281
|
+
}
|
|
1282
|
+
inferCardholderName() {
|
|
1283
|
+
let e = this.checkoutProfile.getState();
|
|
1284
|
+
if (!e.checkoutProfile || !L(e.checkoutProfile.layout)) return;
|
|
1285
|
+
let { formData: t } = this._getFormStateData(), n = t.billingAddress ?? t.shippingAddress;
|
|
1286
|
+
if (!n) return;
|
|
1287
|
+
let r = [n.firstName?.trim() ?? "", n.lastName?.trim() ?? ""].filter(Boolean).join(" ");
|
|
1288
|
+
r && this.formManager.setFormData({ name: r });
|
|
1289
|
+
}
|
|
1290
|
+
inferAddresses() {
|
|
1291
|
+
let e = this.checkoutProfile.getState();
|
|
1292
|
+
if (!e.checkoutProfile) return;
|
|
1293
|
+
let { billingFields: t, shippingFields: n } = e.checkoutProfile.layout, r = t && Object.values(t).some((e) => e?.enabled), i = n && Object.values(n).some((e) => e?.enabled), { formData: a } = this._getFormStateData();
|
|
1294
|
+
!r && i && a.shippingAddress ? this.formManager.setFormData({ billingAddress: { ...a.shippingAddress } }) : !i && r && a.billingAddress && this.formManager.setFormData({ shippingAddress: { ...a.billingAddress } });
|
|
1295
|
+
}
|
|
1296
|
+
handleVgsStateChange(e) {
|
|
1297
|
+
this.stateCoordinator.updateVgsState(e);
|
|
1298
|
+
let t = this.stateCoordinator.getVgsFieldErrors(this.translation.t);
|
|
1299
|
+
this.componentManager.handleVgsStateChange(e, t), this.updateFormUI();
|
|
1300
|
+
}
|
|
1301
|
+
async handleSubmit() {
|
|
1302
|
+
if (!this.stateCoordinator.isFormDisabled()) try {
|
|
1303
|
+
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) try {
|
|
1304
|
+
this.vgsCardResult = await this.vgsService.createCard(this.vgsJwt);
|
|
1305
|
+
} catch (e) {
|
|
1306
|
+
console.error("VGS card creation failed:", e), this.handleSubmitError("Card processing failed. Please check your card details and try again.");
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
let e = this.formManager.getFormState().formData;
|
|
1310
|
+
await this.options.onSubmit({ formData: this.vgsCardResult ? {
|
|
1311
|
+
...e,
|
|
1312
|
+
vgsCardData: {
|
|
1313
|
+
cardId: this.vgsCardResult.cardId,
|
|
1314
|
+
expMonth: this.vgsCardResult.expMonth,
|
|
1315
|
+
expYear: this.vgsCardResult.expYear,
|
|
1316
|
+
name: this.vgsCardResult.name,
|
|
1317
|
+
...this.vgsCardResult.updatedValues && { updatedValues: this.vgsCardResult.updatedValues }
|
|
1318
|
+
}
|
|
1319
|
+
} : e }), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
1320
|
+
} catch {
|
|
1321
|
+
this.handleSubmitError("Payment processing failed. Please try again.");
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
handleSubmitError(e) {
|
|
1325
|
+
this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.uiManager.setErrorMessage(e), this.updateFormUI();
|
|
1326
|
+
}
|
|
1327
|
+
async handlePaypalSubmit() {
|
|
1328
|
+
this.stateCoordinator.setSubmitting(!0), this.updateFormUI(), this.options.onLoadingStateChange?.(!0), this.uiManager.showSpinner(this.translation.t("loading"));
|
|
1329
|
+
try {
|
|
1330
|
+
await this.options.onSubmit({ formData: null });
|
|
1331
|
+
} catch {
|
|
1332
|
+
this.uiManager.setErrorMessage("PayPal processing failed. Please try again."), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
async handleApplePaySubmit(e) {
|
|
1336
|
+
this.stateCoordinator.setSubmitting(!0), this.updateFormUI(), this.options.onLoadingStateChange?.(!0), this.uiManager.showSpinner(this.translation.t("loading"));
|
|
1337
|
+
try {
|
|
1338
|
+
await this.options.onSubmit({
|
|
1339
|
+
formData: null,
|
|
1340
|
+
applePayData: e.applePayData
|
|
1341
|
+
}), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
1342
|
+
} catch {
|
|
1343
|
+
this.uiManager.setErrorMessage("Apple Pay processing failed. Please try again."), this.uiManager.hideSpinner(), this.options.onLoadingStateChange?.(!1), this.stateCoordinator.setSubmitting(!1), this.updateFormUI();
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
setErrorMessage(e) {
|
|
1347
|
+
return this.uiManager.setErrorMessage(e), this;
|
|
1348
|
+
}
|
|
1349
|
+
clearErrorMessage() {
|
|
1350
|
+
return this.uiManager.clearErrorMessage(), this;
|
|
1351
|
+
}
|
|
1352
|
+
updateAppearance(e) {
|
|
1353
|
+
e.locale && this.translation.setLocale(e.locale), e.appearance && this.checkoutProfile.updateProfile(e.appearance), e.locale && (this.componentManager.cleanup(), this.renderFormComponents());
|
|
1354
|
+
}
|
|
1355
|
+
destroy() {
|
|
1356
|
+
this.vgsService?.destroy(), this.stateCoordinator.cleanup(), this.eventHandler.clearTouchedFields(), this.getElement().removeEventListener("submit", this.eventHandler.handleSubmit), this.getElement().removeEventListener("keydown", this.eventHandler.handleKeyDown), this.componentManager.cleanup(), this.uiManager.cleanup(), this.getElement().remove();
|
|
1357
|
+
}
|
|
1358
|
+
associatePayment(e, t, n, r, i) {
|
|
1359
|
+
this.options.paymentId = e, this.options.checkoutKey = t, this.options.supportedPaymentMethods = n, this.options.checkoutDetails = r, this.componentManager.setCheckoutDetailsLoaded(!0), i && !this.vgsService && (this.vgsJwt = i, this.vgsService = new s(), this.componentManager.setVgsService(this.vgsService), this.stateCoordinator.setVgsMode(!0), this.vgsService.init(this.options.environment).then((e) => {
|
|
1360
|
+
this.vgsService?.createForm(e, (e) => this.handleVgsStateChange(e)), this.renderFormComponents();
|
|
1361
|
+
}).catch((e) => {
|
|
1362
|
+
console.error("Failed to load VGS Collect:", e), this.vgsService = void 0, this.vgsJwt = void 0, this.renderFormComponents();
|
|
1363
|
+
})), this.componentManager.removePaymentMethods(), this.componentManager.updateSupportedPaymentMethods(n), this.componentManager.updatePaymentDetails(e, t, r), !i && this.checkoutProfile.getState().checkoutProfile && this.renderFormComponents();
|
|
1364
|
+
let a = this.checkoutProfile.getState();
|
|
1365
|
+
if (a.checkoutProfile) {
|
|
1366
|
+
let { formData: e } = this._getFormStateData();
|
|
1367
|
+
this.componentManager.createPaymentMethods(a.checkoutProfile, e, !0);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}, se = class {
|
|
1371
|
+
container = null;
|
|
1372
|
+
options;
|
|
1373
|
+
onSubmit;
|
|
1374
|
+
form = null;
|
|
1375
|
+
constructor(e, t) {
|
|
1376
|
+
this.options = e, this.onSubmit = t;
|
|
1377
|
+
}
|
|
1378
|
+
mount(e) {
|
|
1379
|
+
this.unmount(), this.container = e, this.renderForm();
|
|
1380
|
+
}
|
|
1381
|
+
update(e) {
|
|
1382
|
+
if (!(!this.container || !this.form)) {
|
|
1383
|
+
if (e.appearance || e.locale) {
|
|
1384
|
+
this.form.updateAppearance({
|
|
1385
|
+
appearance: e.appearance,
|
|
1386
|
+
locale: e.locale
|
|
1387
|
+
});
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
e.errorMsg && !this.options.disableErrorMessages ? this.form.setErrorMessage(e.errorMsg) : this.renderForm(e.errorMsg);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
renderForm(e) {
|
|
1394
|
+
this.container && (this.form &&= (this.form.destroy(), null), this.form = new oe({
|
|
1395
|
+
apiKey: this.options.apiKey,
|
|
1396
|
+
onSubmit: this.onSubmit,
|
|
1397
|
+
locale: this.options.locale,
|
|
1398
|
+
errorMsg: this.options.disableErrorMessages ? void 0 : e,
|
|
1399
|
+
container: this.container,
|
|
1400
|
+
environment: this.options.environment,
|
|
1401
|
+
appearance: this.options.appearance,
|
|
1402
|
+
onLoadingStateChange: this.options.onLoadingStateChange,
|
|
1403
|
+
paymentId: this.options.paymentId,
|
|
1404
|
+
checkoutKey: this.options.checkoutKey,
|
|
1405
|
+
checkoutDetails: this.options.checkoutDetails,
|
|
1406
|
+
initialValues: this.options.initialValues,
|
|
1407
|
+
vgsJwt: this.options.vgsJwt
|
|
1408
|
+
}));
|
|
1409
|
+
}
|
|
1410
|
+
unmount() {
|
|
1411
|
+
this.form &&= (this.form.destroy(), null);
|
|
1412
|
+
}
|
|
1413
|
+
displayError(e) {
|
|
1414
|
+
if (!this.form) throw Error("Cannot display error: form is not mounted");
|
|
1415
|
+
this.form.setErrorMessage(e);
|
|
1416
|
+
}
|
|
1417
|
+
clearError() {
|
|
1418
|
+
this.form && this.form.clearErrorMessage();
|
|
1419
|
+
}
|
|
1420
|
+
async associatePayment(e, t, n, r, i) {
|
|
1421
|
+
this.options.paymentId = e, this.options.checkoutKey = t, this.options.checkoutDetails = r, this.options.vgsJwt = i, this.form && this.form.associatePayment(e, t, n, r, i);
|
|
1422
|
+
}
|
|
1423
|
+
}, ce = class {
|
|
1424
|
+
state;
|
|
1425
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1426
|
+
constructor(e) {
|
|
1427
|
+
this.state = e;
|
|
1428
|
+
}
|
|
1429
|
+
getState() {
|
|
1430
|
+
return { ...this.state };
|
|
1431
|
+
}
|
|
1432
|
+
updateState(e) {
|
|
1433
|
+
this.state = {
|
|
1434
|
+
...this.state,
|
|
1435
|
+
...e
|
|
1436
|
+
}, this.notifyListeners();
|
|
1437
|
+
}
|
|
1438
|
+
subscribe(e) {
|
|
1439
|
+
return this.listeners.add(e), () => {
|
|
1440
|
+
this.listeners.delete(e);
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
notifyListeners() {
|
|
1444
|
+
let e = this.getState();
|
|
1445
|
+
this.listeners.forEach((t) => t(e));
|
|
1446
|
+
}
|
|
1447
|
+
}, le = "en", $ = class {
|
|
1448
|
+
config;
|
|
1449
|
+
_callbacks;
|
|
1450
|
+
paymentState;
|
|
1451
|
+
apiService;
|
|
1452
|
+
formManager;
|
|
1453
|
+
stateManager;
|
|
1454
|
+
sessionId;
|
|
1455
|
+
constructor(e) {
|
|
1456
|
+
this.config = this.validateConfig(e), this._callbacks = { ...this.config.callbacks }, this.paymentState = {}, this.sessionId = crypto.randomUUID(), t({
|
|
1457
|
+
environment: this.config.environment,
|
|
1458
|
+
sessionId: this.sessionId
|
|
1459
|
+
}), o(a.CHECKOUT_INITIALIZED, { environment: this.config.environment }), this.apiService = new l(this.config.apiKey, this.config.environment), this.stateManager = new ce({
|
|
1460
|
+
mounted: !1,
|
|
1461
|
+
form: null
|
|
1462
|
+
}), this.formManager = new se({
|
|
1463
|
+
locale: this.config.locale,
|
|
1464
|
+
apiKey: this.config.apiKey,
|
|
1465
|
+
disableErrorMessages: this.config.disableErrorMessages,
|
|
1466
|
+
environment: this.config.environment,
|
|
1467
|
+
appearance: this.config.appearance,
|
|
1468
|
+
onLoadingStateChange: (...e) => this._callbacks.onLoadingStateChange?.(...e),
|
|
1469
|
+
initialValues: this.config.initialValues
|
|
1470
|
+
}, this.handleSubmit.bind(this));
|
|
1471
|
+
}
|
|
1472
|
+
validateConfig(e) {
|
|
1473
|
+
if (!e.apiKey) throw Error("API key is required");
|
|
1474
|
+
if (!e.environment || !["test", "live"].includes(e.environment)) throw Error("Environment must be \"test\" or \"live\"");
|
|
1475
|
+
return {
|
|
1476
|
+
apiKey: e.apiKey,
|
|
1477
|
+
returnUrl: e.returnUrl,
|
|
1478
|
+
environment: e.environment,
|
|
1479
|
+
locale: e.locale || le,
|
|
1480
|
+
disableErrorMessages: e.disableErrorMessages ?? !1,
|
|
1481
|
+
manualActionHandling: e.manualActionHandling ?? !1,
|
|
1482
|
+
appearance: e.appearance,
|
|
1483
|
+
initialValues: e.initialValues || {},
|
|
1484
|
+
callbacks: {
|
|
1485
|
+
onPaymentSucceeded: e.callbacks?.onPaymentSucceeded || void 0,
|
|
1486
|
+
onPaymentFailed: e.callbacks?.onPaymentFailed || void 0,
|
|
1487
|
+
onActionRequired: e.callbacks?.onActionRequired || void 0,
|
|
1488
|
+
onLoadingStateChange: e.callbacks?.onLoadingStateChange || void 0
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
mount(e) {
|
|
1493
|
+
let t = document.querySelector(e);
|
|
1494
|
+
if (!t) throw Error(`Container ${e} not found`);
|
|
1495
|
+
let n = document.createElement("div");
|
|
1496
|
+
return t.appendChild(n), this.stateManager.updateState({
|
|
1497
|
+
form: n,
|
|
1498
|
+
mounted: !0
|
|
1499
|
+
}), this.formManager.mount(n), o(a.CHECKOUT_MOUNTED, { container_id: e }), this;
|
|
1500
|
+
}
|
|
1501
|
+
unmount() {
|
|
1502
|
+
let { mounted: e } = this.stateManager.getState();
|
|
1503
|
+
e && Promise.resolve().then(() => {
|
|
1504
|
+
this.formManager.unmount();
|
|
1505
|
+
let { form: e } = this.stateManager.getState();
|
|
1506
|
+
e && e.remove(), this.stateManager.updateState({
|
|
1507
|
+
form: null,
|
|
1508
|
+
mounted: !1
|
|
1509
|
+
}), o(a.CHECKOUT_UNMOUNTED);
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
async handleSubmit({ formData: e, applePayData: t }) {
|
|
1513
|
+
if (!this.paymentState.paymentId || !this.paymentState.checkoutKey) throw Error("Payment must be associated before submitting. Call associatePayment() first.");
|
|
1514
|
+
let n = this.getPaymentMethod(e, t);
|
|
1515
|
+
o(a.PAYMENT_SUBMIT_STARTED, {
|
|
1516
|
+
payment_id: this.paymentState.paymentId,
|
|
1517
|
+
payment_method: n
|
|
1518
|
+
});
|
|
1519
|
+
let r = performance.now();
|
|
1520
|
+
try {
|
|
1521
|
+
let i = await this.apiService.authorizePayment({
|
|
1522
|
+
checkoutKey: this.paymentState.checkoutKey,
|
|
1523
|
+
formData: e || null,
|
|
1524
|
+
paymentId: this.paymentState.paymentId,
|
|
1525
|
+
returnUrl: this.config.returnUrl,
|
|
1526
|
+
applePayData: t
|
|
1527
|
+
}), s = performance.now() - r;
|
|
1528
|
+
_(c.PAYMENT_AUTHORIZATION_TIME, s, "ms", {
|
|
1529
|
+
payment_id: this.paymentState.paymentId,
|
|
1530
|
+
payment_method: n,
|
|
1531
|
+
status: "success"
|
|
1532
|
+
}), o(a.PAYMENT_SUBMIT_SUCCESS, {
|
|
1533
|
+
payment_id: this.paymentState.paymentId,
|
|
1534
|
+
payment_method: n
|
|
1535
|
+
}), this.handlePaymentResponse(i);
|
|
1536
|
+
} catch (e) {
|
|
1537
|
+
let t = performance.now() - r;
|
|
1538
|
+
_(c.PAYMENT_AUTHORIZATION_TIME, t, "ms", {
|
|
1539
|
+
payment_id: this.paymentState.paymentId,
|
|
1540
|
+
payment_method: n,
|
|
1541
|
+
status: "failed"
|
|
1542
|
+
}), o(a.PAYMENT_SUBMIT_FAILED, {
|
|
1543
|
+
payment_id: this.paymentState.paymentId,
|
|
1544
|
+
payment_method: n,
|
|
1545
|
+
error_message: e.details?.message ?? "Unknown error"
|
|
1546
|
+
}), this.handleAuthorizationError(e);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
handlePaymentResponse(e) {
|
|
1550
|
+
if (e.latestTransaction.status === "authorized" && (o(a.PAYMENT_AUTHORIZED, {
|
|
1551
|
+
payment_id: this.paymentState.paymentId ?? "",
|
|
1552
|
+
status: e.latestTransaction.status
|
|
1553
|
+
}), this._callbacks.onPaymentSucceeded?.(e.latestTransaction.status)), e.latestTransaction.status === "failed" && (o(a.PAYMENT_FAILED, {
|
|
1554
|
+
payment_id: this.paymentState.paymentId ?? "",
|
|
1555
|
+
status: e.latestTransaction.status
|
|
1556
|
+
}), this._callbacks.onPaymentFailed?.(e.latestTransaction.status)), e.status === "requires_action") {
|
|
1557
|
+
let { redirectUrl: t } = e.action;
|
|
1558
|
+
o(a.PAYMENT_ACTION_REQUIRED, {
|
|
1559
|
+
payment_id: this.paymentState.paymentId ?? "",
|
|
1560
|
+
status: e.status
|
|
1561
|
+
}), this.config.manualActionHandling ? this._callbacks.onActionRequired?.(t) : globalThis.location.href = t;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
handleAuthorizationError(e) {
|
|
1565
|
+
this._callbacks.onPaymentFailed?.(e.details?.message);
|
|
1566
|
+
let { form: t } = this.stateManager.getState();
|
|
1567
|
+
t && this.formManager.update({ errorMsg: e.details?.message });
|
|
1568
|
+
}
|
|
1569
|
+
getPaymentMethod(e, t) {
|
|
1570
|
+
return t ? "apple_pay" : e === null ? "paypal" : "card";
|
|
1571
|
+
}
|
|
1572
|
+
displayError(e) {
|
|
1573
|
+
let { mounted: t } = this.stateManager.getState();
|
|
1574
|
+
if (!t) throw Error("Cannot display error: checkout is not mounted");
|
|
1575
|
+
this.formManager.displayError(e);
|
|
1576
|
+
}
|
|
1577
|
+
clearError() {
|
|
1578
|
+
let { mounted: e } = this.stateManager.getState();
|
|
1579
|
+
if (!e) throw Error("Cannot clear error: checkout is not mounted");
|
|
1580
|
+
this.formManager.clearError();
|
|
1581
|
+
}
|
|
1582
|
+
update(e) {
|
|
1583
|
+
let { mounted: t } = this.stateManager.getState();
|
|
1584
|
+
if (!t) throw Error("Cannot update: checkout is not mounted");
|
|
1585
|
+
e.appearance && (this.config.appearance = e.appearance), e.locale && (this.config.locale = e.locale), this.formManager.update({
|
|
1586
|
+
appearance: e.appearance,
|
|
1587
|
+
locale: e.locale
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
async associatePayment(e, t) {
|
|
1591
|
+
if (!e || !t) throw Error("paymentId and checkoutKey are required");
|
|
1592
|
+
this.paymentState.paymentId = e, this.paymentState.checkoutKey = t;
|
|
1593
|
+
try {
|
|
1594
|
+
let n = await ne({
|
|
1595
|
+
id: e,
|
|
1596
|
+
checkoutKey: t,
|
|
1597
|
+
environment: this.config.environment
|
|
1598
|
+
});
|
|
1599
|
+
if (!n || !n.supportedPaymentMethods || !Array.isArray(n.supportedPaymentMethods)) throw Error("Invalid response: supportedPaymentMethods must be an array");
|
|
1600
|
+
if (!n.supportedPaymentMethods.every((e) => typeof e == "string")) throw Error("Invalid response: all supportedPaymentMethods must be strings");
|
|
1601
|
+
this.paymentState.checkoutDetails = {
|
|
1602
|
+
amount: n.amount,
|
|
1603
|
+
currency: n.currency,
|
|
1604
|
+
countryCode: n.countryCode
|
|
1605
|
+
};
|
|
1606
|
+
let r = n.supportedPaymentMethods.reduce((e, t) => (e[t] = !0, e), {});
|
|
1607
|
+
await this.formManager.associatePayment(e, t, r, this.paymentState.checkoutDetails, n.vgsJwt), o(a.PAYMENT_ASSOCIATED, {
|
|
1608
|
+
payment_id: e,
|
|
1609
|
+
currency: n.currency,
|
|
1610
|
+
country_code: n.countryCode
|
|
1611
|
+
});
|
|
1612
|
+
} catch (t) {
|
|
1613
|
+
throw o(a.PAYMENT_ASSOCIATION_FAILED, {
|
|
1614
|
+
payment_id: e,
|
|
1615
|
+
error_message: t instanceof Error ? t.message : "Unknown error"
|
|
1616
|
+
}), g(t instanceof Error ? t : /* @__PURE__ */ Error("Failed to associate payment"), { payment_id: e }), t;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
setCallbacks(e) {
|
|
1620
|
+
Object.assign(this._callbacks, e);
|
|
1621
|
+
}
|
|
2525
1622
|
};
|
|
1623
|
+
//#endregion
|
|
1624
|
+
//#region libs/checkout/src/index.ts
|
|
1625
|
+
typeof globalThis < "u" && (globalThis.OdusCheckout = $);
|
|
1626
|
+
//#endregion
|
|
1627
|
+
export { $ as OdusCheckout, te as deLocale, e as enLocale, w as esLocale, d as frLocale, n as itLocale, r as plLocale, m as ptLocale, g as pushError, o as pushEvent, h as pushLog, _ as pushMeasurement, N as trLocale };
|