@test-glide/glide-payment 0.0.3 → 0.0.4
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/index.cjs.js +13 -13
- package/dist/index.es.js +253 -250
- package/dist/index.umd.js +13 -13
- package/dist/native/native.cjs.js +1 -1
- package/dist/native/native.es.js +127 -124
- package/dist/react/react.cjs.js +12 -12
- package/dist/react/react.es.js +247 -244
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
function u(
|
|
2
|
-
const
|
|
3
|
-
if (
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
function u(t, n = {}) {
|
|
2
|
+
const e = document.createElement(t), { className: a, id: l, innerHTML: m, textContent: c, attributes: o, styles: h, dataset: s, children: r, events: d } = n;
|
|
3
|
+
if (a) {
|
|
4
|
+
const p = Array.isArray(a) ? a : a.split(" ");
|
|
5
|
+
e.classList.add(...p.filter(Boolean));
|
|
6
6
|
}
|
|
7
|
-
if (
|
|
8
|
-
for (const [
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
for (const [
|
|
12
|
-
|
|
7
|
+
if (l && (e.id = l), m && (e.innerHTML = m), c && (e.textContent = c), o)
|
|
8
|
+
for (const [p, i] of Object.entries(o))
|
|
9
|
+
i && e.setAttribute(p, i);
|
|
10
|
+
if (h)
|
|
11
|
+
for (const [p, i] of Object.entries(h))
|
|
12
|
+
e.style[p] = i;
|
|
13
13
|
if (s)
|
|
14
|
-
for (const [
|
|
15
|
-
|
|
16
|
-
if (r &&
|
|
17
|
-
for (const [
|
|
18
|
-
|
|
19
|
-
return
|
|
14
|
+
for (const [p, i] of Object.entries(s))
|
|
15
|
+
e.dataset[p] = i;
|
|
16
|
+
if (r && e.append(...r.filter(Boolean)), d)
|
|
17
|
+
for (const [p, i] of Object.entries(d))
|
|
18
|
+
e.addEventListener(p, i);
|
|
19
|
+
return e;
|
|
20
20
|
}
|
|
21
|
-
function x(
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
console.warn("updateElements: no elements found for",
|
|
21
|
+
function x(t, n) {
|
|
22
|
+
const e = "id" in t ? [document.getElementById(t.id)].filter(Boolean) : "className" in t ? Array.from(document.getElementsByClassName(t.className)) : [t.element];
|
|
23
|
+
if (!e.length) {
|
|
24
|
+
console.warn("updateElements: no elements found for", t);
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
for (const
|
|
28
|
-
const { styles:
|
|
29
|
-
if (
|
|
30
|
-
for (const [r,
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
for (const [r,
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
for (const [r,
|
|
37
|
-
|
|
38
|
-
if (
|
|
27
|
+
for (const a of e) {
|
|
28
|
+
const { styles: l, attributes: m, dataset: c, innerHTML: o, textContent: h, className: s } = n;
|
|
29
|
+
if (l)
|
|
30
|
+
for (const [r, d] of Object.entries(l))
|
|
31
|
+
a.style[r] = d;
|
|
32
|
+
if (m)
|
|
33
|
+
for (const [r, d] of Object.entries(m))
|
|
34
|
+
a.setAttribute(r, d);
|
|
35
|
+
if (c)
|
|
36
|
+
for (const [r, d] of Object.entries(c))
|
|
37
|
+
a.dataset[r] = d;
|
|
38
|
+
if (o !== void 0 && (a.innerHTML = o), h !== void 0 && (a.textContent = h), s?.add) {
|
|
39
39
|
const r = Array.isArray(s.add) ? s.add : [s.add];
|
|
40
|
-
|
|
40
|
+
a.classList.add(...r);
|
|
41
41
|
}
|
|
42
42
|
if (s?.remove) {
|
|
43
43
|
const r = Array.isArray(s.remove) ? s.remove : [s.remove];
|
|
44
|
-
|
|
44
|
+
a.classList.remove(...r);
|
|
45
45
|
}
|
|
46
|
-
s?.toggle && (Array.isArray(s.toggle) ? s.toggle : [s.toggle]).forEach((
|
|
46
|
+
s?.toggle && (Array.isArray(s.toggle) ? s.toggle : [s.toggle]).forEach((d) => a.classList.toggle(d));
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
const Q = `
|
|
@@ -93,211 +93,214 @@ const Q = `
|
|
|
93
93
|
></path>
|
|
94
94
|
</svg>`, k = `
|
|
95
95
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 256 256"><path d="M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm16-40a8,8,0,0,1-8,8,16,16,0,0,1-16-16V128a8,8,0,0,1,0-16,16,16,0,0,1,16,16v40A8,8,0,0,1,144,176ZM112,84a12,12,0,1,1,12,12A12,12,0,0,1,112,84Z"></path></svg>
|
|
96
|
-
`, te = ({ children:
|
|
97
|
-
const
|
|
96
|
+
`, te = ({ children: t, onClick: n, disabled: e = !1, size: a = "medium", type: l = "button", className: m = "", variant: c = "primary" }) => {
|
|
97
|
+
const o = u("span", {
|
|
98
98
|
className: "button-spinner",
|
|
99
99
|
innerHTML: X,
|
|
100
100
|
dataset: { show: "false" }
|
|
101
|
-
}),
|
|
101
|
+
}), h = u("span", {
|
|
102
102
|
className: "button-label",
|
|
103
103
|
children: [
|
|
104
104
|
null
|
|
105
105
|
],
|
|
106
|
-
textContent:
|
|
106
|
+
textContent: t
|
|
107
107
|
}), s = u("button", {
|
|
108
|
-
className: `custom-button ${
|
|
108
|
+
className: `custom-button ${c} ${a} ${m}`,
|
|
109
109
|
attributes: {
|
|
110
|
-
type:
|
|
111
|
-
...
|
|
110
|
+
type: l,
|
|
111
|
+
...e ? { disabled: "true" } : {}
|
|
112
112
|
},
|
|
113
113
|
events: {
|
|
114
|
-
click:
|
|
114
|
+
click: n
|
|
115
115
|
},
|
|
116
116
|
children: [
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
o,
|
|
118
|
+
h
|
|
119
119
|
]
|
|
120
|
-
}), r = (
|
|
121
|
-
x({ element:
|
|
122
|
-
dataset: { show: String(
|
|
123
|
-
}),
|
|
124
|
-
},
|
|
125
|
-
|
|
120
|
+
}), r = (p = !1) => {
|
|
121
|
+
x({ element: o }, {
|
|
122
|
+
dataset: { show: String(p) }
|
|
123
|
+
}), d(p);
|
|
124
|
+
}, d = (p = !1) => {
|
|
125
|
+
p ? s.setAttribute("disabled", "true") : s.removeAttribute("disabled");
|
|
126
126
|
};
|
|
127
127
|
return {
|
|
128
128
|
element: s,
|
|
129
129
|
setLoading: r,
|
|
130
|
-
setDisabled:
|
|
130
|
+
setDisabled: d
|
|
131
131
|
};
|
|
132
|
-
}, ne = ({ content:
|
|
133
|
-
var
|
|
134
|
-
className: `tooltip ${
|
|
132
|
+
}, ne = ({ content: t, position: n = "top", delay: e = 200, maxWidth: a = 250, className: l = "", id: m = "" }) => {
|
|
133
|
+
var c = u("div", {
|
|
134
|
+
className: `tooltip ${n} ${l}`,
|
|
135
135
|
styles: {
|
|
136
136
|
// top: `${tooltipPosition.top}px`,
|
|
137
137
|
// left: `${tooltipPosition.left}px`,
|
|
138
|
-
maxWidth: `${
|
|
138
|
+
maxWidth: `${a}px`
|
|
139
139
|
},
|
|
140
140
|
attributes: {
|
|
141
141
|
role: "tooltip"
|
|
142
142
|
},
|
|
143
143
|
dataset: { show: "false" },
|
|
144
144
|
innerHTML: `
|
|
145
|
-
<div class="tooltip-content">${
|
|
145
|
+
<div class="tooltip-content">${t}</div>
|
|
146
146
|
<div class="tooltip-arrow"></div>
|
|
147
147
|
`
|
|
148
148
|
});
|
|
149
|
-
let
|
|
149
|
+
let o = null;
|
|
150
150
|
var r = u("span", {
|
|
151
151
|
className: "tooltip-trigger",
|
|
152
152
|
innerHTML: k,
|
|
153
153
|
events: {
|
|
154
154
|
mouseenter: () => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
},
|
|
155
|
+
e > 0 ? o = window.setTimeout(() => {
|
|
156
|
+
c.dataset.show = "true", d();
|
|
157
|
+
}, e) : (c.dataset.show = "true", d());
|
|
158
158
|
},
|
|
159
159
|
mouseleave: () => {
|
|
160
|
-
|
|
160
|
+
o && clearTimeout(o), c.dataset.show = "false";
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
|
-
function
|
|
165
|
-
if (!r || !
|
|
166
|
-
const
|
|
167
|
-
let
|
|
168
|
-
switch (
|
|
164
|
+
function d() {
|
|
165
|
+
if (!r || !c) return;
|
|
166
|
+
const i = r.getBoundingClientRect(), g = c.getBoundingClientRect(), b = 8;
|
|
167
|
+
let f, y;
|
|
168
|
+
switch (n) {
|
|
169
169
|
case "top":
|
|
170
|
-
|
|
170
|
+
f = i.top - g.height - b, y = i.left + i.width / 2 - g.width / 2;
|
|
171
171
|
break;
|
|
172
172
|
case "bottom":
|
|
173
|
-
|
|
173
|
+
f = i.bottom + b, y = i.left + i.width / 2 - g.width / 2;
|
|
174
174
|
break;
|
|
175
175
|
case "left":
|
|
176
|
-
|
|
176
|
+
f = i.top + i.height / 2 - g.height / 2, y = i.left - g.width - b;
|
|
177
177
|
break;
|
|
178
178
|
case "right":
|
|
179
|
-
|
|
179
|
+
f = i.top + i.height / 2 - g.height / 2, y = i.right + b;
|
|
180
180
|
break;
|
|
181
181
|
default:
|
|
182
|
-
|
|
182
|
+
f = i.top - g.height - b, y = i.left + i.width / 2 - g.width / 2;
|
|
183
183
|
}
|
|
184
|
-
const N = window.innerWidth,
|
|
185
|
-
|
|
184
|
+
const N = window.innerWidth, C = window.innerHeight;
|
|
185
|
+
y < 0 && (y = b), y + g.width > N && (y = N - g.width - b), f < 0 && (f = b), f + g.height > C && (f = C - g.height - b), c.style.top = `${f}px`, c.style.left = `${y}px`;
|
|
186
186
|
}
|
|
187
187
|
return u("div", {
|
|
188
188
|
className: "tooltip-wrapper",
|
|
189
|
-
id: `tooltip-${
|
|
189
|
+
id: `tooltip-${m}`,
|
|
190
190
|
children: [
|
|
191
191
|
r,
|
|
192
|
-
|
|
192
|
+
c
|
|
193
193
|
]
|
|
194
194
|
});
|
|
195
|
-
}, se = (n) => {
|
|
196
|
-
const e = {},
|
|
197
|
-
(
|
|
198
|
-
), l =
|
|
199
|
-
if (l ? /^\d{13,19}$/.test(l) || (e.cardNumber = "Card number must be 13-19 digits") : e.cardNumber = "Card number is required", !
|
|
195
|
+
}, se = (t, n = !1) => {
|
|
196
|
+
const e = {}, a = Object.values(t).every(
|
|
197
|
+
(o) => !o || o.trim() === ""
|
|
198
|
+
), l = t.cardNumber?.replace(/\s/g, "");
|
|
199
|
+
if (l ? /^\d{13,19}$/.test(l) || (e.cardNumber = "Card number must be 13-19 digits") : e.cardNumber = "Card number is required", !t.expiryDate && !n)
|
|
200
200
|
e.expiryDate = "Expiry date is required";
|
|
201
|
-
else {
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
201
|
+
else if (t.expiryDate) {
|
|
202
|
+
const o = t.expiryDate.replace(/\D/g, "");
|
|
203
|
+
if (o.length < 4)
|
|
204
204
|
e.expiryDate = "Enter complete expiry date (MM/YY)";
|
|
205
205
|
else {
|
|
206
|
-
const h = parseInt(
|
|
206
|
+
const h = parseInt(o.substring(0, 2), 10), s = parseInt(o.substring(2, 4), 10);
|
|
207
207
|
if (isNaN(h) || h < 1 || h > 12)
|
|
208
208
|
e.expiryDate = "Invalid month (must be 01-12)";
|
|
209
|
-
else if (isNaN(
|
|
209
|
+
else if (isNaN(s) || s < 0 || s > 99)
|
|
210
210
|
e.expiryDate = "Invalid year";
|
|
211
211
|
else {
|
|
212
|
-
const
|
|
213
|
-
let
|
|
214
|
-
|
|
212
|
+
const r = /* @__PURE__ */ new Date(), d = r.getFullYear(), p = r.getMonth() + 1, i = Math.floor(d / 100) * 100, g = i + s, b = i + 100 + s;
|
|
213
|
+
let f;
|
|
214
|
+
g >= d && g <= d + 20 ? f = g : (b >= d && b <= d + 20, f = b), f < d || f === d && h < p ? e.expiryDate = "Card has expired" : f > d + 20 && (e.expiryDate = "Expiry year is too far in the future");
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
|
|
218
|
+
const m = t.cvv.trim();
|
|
219
|
+
m && !/^\d{3,4}$/.test(m) && (e.cvv = "CVV must be 3 or 4 digits");
|
|
220
|
+
const c = t.zipCode.trim();
|
|
221
|
+
return c && !/^[A-Z0-9\s-]{3,10}$/i.test(c) && (e.zipCode = "Invalid ZIP code format"), {
|
|
219
222
|
isValid: Object.keys(e).length === 0,
|
|
220
223
|
errors: e,
|
|
221
|
-
isEmpty:
|
|
224
|
+
isEmpty: a
|
|
222
225
|
};
|
|
223
226
|
};
|
|
224
|
-
function re(
|
|
225
|
-
const
|
|
226
|
-
if (isNaN(
|
|
227
|
-
const
|
|
228
|
-
let
|
|
229
|
-
return
|
|
227
|
+
function re(t) {
|
|
228
|
+
const n = parseInt(t, 10);
|
|
229
|
+
if (isNaN(n) || n < 0 || n > 99) return null;
|
|
230
|
+
const e = (/* @__PURE__ */ new Date()).getFullYear(), a = Math.floor(e / 100) * 100;
|
|
231
|
+
let l = a + n;
|
|
232
|
+
return l >= e && l <= e + 20 || (l = a + 100 + n, l >= e && l <= e + 20) ? l : a + 100 + n;
|
|
230
233
|
}
|
|
231
|
-
function V(
|
|
232
|
-
return
|
|
234
|
+
function V(t = "") {
|
|
235
|
+
return t.trim().replaceAll(/\s/g, "").replaceAll("-", "");
|
|
233
236
|
}
|
|
234
|
-
const
|
|
235
|
-
card: (
|
|
236
|
-
phone: (
|
|
237
|
-
const
|
|
238
|
-
return
|
|
237
|
+
const ae = {
|
|
238
|
+
card: (t) => t.replace(/\s+/g, "").replace(/[^0-9]/gi, "").substring(0, 16).match(/.{1,4}/g)?.join(" ") ?? "",
|
|
239
|
+
phone: (t) => {
|
|
240
|
+
const n = t.replace(/\D/g, "").substring(0, 10), e = n.match(/^(\d{3})(\d{3})(\d{4})$/);
|
|
241
|
+
return e ? `(${e[1]}) ${e[2]}-${e[3]}` : n;
|
|
239
242
|
},
|
|
240
|
-
expiry: (
|
|
241
|
-
const
|
|
242
|
-
return
|
|
243
|
+
expiry: (t) => {
|
|
244
|
+
const n = t.replace(/[^0-9/]/g, "");
|
|
245
|
+
return n.length <= 2 ? n : n.includes("/") ? n.substring(0, 5) : n.substring(0, 2) + "/" + n.substring(2, 4);
|
|
243
246
|
},
|
|
244
|
-
cvv: (
|
|
245
|
-
zip: (
|
|
246
|
-
const
|
|
247
|
-
return
|
|
247
|
+
cvv: (t) => t.replace(/\D/g, "").substring(0, 4),
|
|
248
|
+
zip: (t) => {
|
|
249
|
+
const n = t.replace(/\D/g, "").substring(0, 9);
|
|
250
|
+
return n.length > 5 ? `${n.substring(0, 5)}-${n.substring(5)}` : n;
|
|
248
251
|
}
|
|
249
252
|
};
|
|
250
|
-
function
|
|
251
|
-
return
|
|
253
|
+
function oe(t, n) {
|
|
254
|
+
return n === "none" ? t : ae[n](t);
|
|
252
255
|
}
|
|
253
|
-
const $ = ({ label:
|
|
254
|
-
const
|
|
256
|
+
const $ = ({ label: t, maskType: n, id: e, name: a, type: l = "text", placeholder: m = "Enter value", tooltip: c = "", onChange: o }) => {
|
|
257
|
+
const h = ["card", "expiry", "phone", "cvv", "zip"].includes(n) ? "numeric" : "", s = u("label", {
|
|
255
258
|
className: "input-label",
|
|
256
|
-
innerHTML:
|
|
259
|
+
innerHTML: t,
|
|
257
260
|
attributes: {
|
|
258
|
-
for:
|
|
261
|
+
for: e
|
|
259
262
|
}
|
|
260
263
|
});
|
|
261
264
|
let r = !1;
|
|
262
|
-
const
|
|
263
|
-
id:
|
|
265
|
+
const p = u("input", {
|
|
266
|
+
id: e || "input-id",
|
|
264
267
|
className: "styled-input",
|
|
265
268
|
attributes: {
|
|
266
|
-
placeholder:
|
|
267
|
-
type:
|
|
268
|
-
inputMode:
|
|
269
|
-
name:
|
|
269
|
+
placeholder: m,
|
|
270
|
+
type: l,
|
|
271
|
+
inputMode: h,
|
|
272
|
+
name: a
|
|
270
273
|
},
|
|
271
274
|
events: {
|
|
272
|
-
input:
|
|
273
|
-
blur:
|
|
274
|
-
keydown: (
|
|
275
|
-
|
|
275
|
+
input: i,
|
|
276
|
+
blur: g,
|
|
277
|
+
keydown: (w) => {
|
|
278
|
+
w.key === "Enter" && (r = !0);
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
281
|
});
|
|
279
|
-
function
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
+
function i(w) {
|
|
283
|
+
const T = n !== "none" ? oe(w?.target?.value, n) : w?.target?.value;
|
|
284
|
+
p.value = T, o?.(T);
|
|
282
285
|
}
|
|
283
|
-
function
|
|
284
|
-
r = !0,
|
|
286
|
+
function g() {
|
|
287
|
+
r = !0, o?.(p?.value || "");
|
|
285
288
|
}
|
|
286
|
-
const
|
|
289
|
+
const b = u("div", {
|
|
287
290
|
className: "input-loader",
|
|
288
291
|
innerHTML: '<div class="loader"></div>',
|
|
289
292
|
dataset: { show: "false" }
|
|
290
|
-
}),
|
|
293
|
+
}), f = c ? u("div", {
|
|
291
294
|
className: "input-right-element",
|
|
292
295
|
children: [
|
|
293
|
-
ne({ content:
|
|
296
|
+
ne({ content: c, id: e })
|
|
294
297
|
]
|
|
295
|
-
}) : null,
|
|
298
|
+
}) : null, y = u("div", {
|
|
296
299
|
className: "input-wrapper",
|
|
297
300
|
children: [
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
+
p,
|
|
302
|
+
b,
|
|
303
|
+
f
|
|
301
304
|
]
|
|
302
305
|
}), N = u("div", {
|
|
303
306
|
className: "error-message",
|
|
@@ -312,124 +315,124 @@ const $ = ({ label: n, maskType: e, id: t, name: l, type: a = "text", placeholde
|
|
|
312
315
|
className: "custom-input-group",
|
|
313
316
|
children: [
|
|
314
317
|
s,
|
|
315
|
-
|
|
318
|
+
y,
|
|
316
319
|
N
|
|
317
320
|
]
|
|
318
321
|
}),
|
|
319
|
-
setLoading: (
|
|
320
|
-
x({ element:
|
|
321
|
-
dataset: { loading:
|
|
322
|
-
}), x({ element:
|
|
323
|
-
attributes: { disabled:
|
|
324
|
-
}), x({ element:
|
|
325
|
-
dataset: { show:
|
|
322
|
+
setLoading: (w) => {
|
|
323
|
+
x({ element: y }, {
|
|
324
|
+
dataset: { loading: w ? "true" : "false" }
|
|
325
|
+
}), x({ element: p }, {
|
|
326
|
+
attributes: { disabled: w ? "true" : "false" }
|
|
327
|
+
}), x({ element: b }, {
|
|
328
|
+
dataset: { show: w ? "true" : "false" }
|
|
326
329
|
});
|
|
327
330
|
},
|
|
328
|
-
setError: (
|
|
329
|
-
x({ element:
|
|
330
|
-
className:
|
|
331
|
+
setError: (w = "") => {
|
|
332
|
+
x({ element: y }, {
|
|
333
|
+
className: w && r ? { add: "input-error" } : { remove: "input-error" }
|
|
331
334
|
}), x({ element: N }, {
|
|
332
|
-
dataset: { show:
|
|
335
|
+
dataset: { show: w && r ? "true" : "false" },
|
|
333
336
|
innerHTML: `
|
|
334
337
|
${k}
|
|
335
|
-
<span>${
|
|
338
|
+
<span>${w || ""}</span>
|
|
336
339
|
`
|
|
337
340
|
});
|
|
338
341
|
}
|
|
339
342
|
};
|
|
340
|
-
}, ie = async (
|
|
341
|
-
const { method:
|
|
343
|
+
}, ie = async (t, n = {}) => {
|
|
344
|
+
const { method: e = "GET", headers: a = {}, body: l = null, ...m } = n;
|
|
342
345
|
try {
|
|
343
|
-
const
|
|
344
|
-
method:
|
|
346
|
+
const c = {
|
|
347
|
+
method: e,
|
|
345
348
|
headers: {
|
|
346
349
|
Accept: "*/*",
|
|
347
350
|
"Content-Type": "application/json",
|
|
348
|
-
...
|
|
351
|
+
...a
|
|
349
352
|
},
|
|
350
|
-
...
|
|
353
|
+
...m
|
|
351
354
|
};
|
|
352
|
-
|
|
353
|
-
const
|
|
355
|
+
l && ["POST", "PUT", "PATCH", "DELETE"].includes(e.toUpperCase()) && (c.body = typeof l == "string" ? l : JSON.stringify(l));
|
|
356
|
+
const o = await fetch(t, c), h = o.headers.get("content-type");
|
|
354
357
|
let s;
|
|
355
|
-
if (
|
|
358
|
+
if (h?.includes("application/json") ? s = await o.json() : s = await o.text(), !o.ok) {
|
|
356
359
|
const r = s;
|
|
357
360
|
throw new Error(
|
|
358
|
-
r?.message || `HTTP error! status: ${
|
|
361
|
+
r?.message || `HTTP error! status: ${o.status}`
|
|
359
362
|
);
|
|
360
363
|
}
|
|
361
364
|
return { data: s, error: null };
|
|
362
|
-
} catch (
|
|
363
|
-
return { data: null, error:
|
|
365
|
+
} catch (c) {
|
|
366
|
+
return { data: null, error: c instanceof Error ? c.message : "An error occurred" };
|
|
364
367
|
}
|
|
365
368
|
}, le = ({
|
|
366
|
-
title:
|
|
367
|
-
children:
|
|
368
|
-
onClose:
|
|
369
|
-
showBackBtn:
|
|
370
|
-
showCloseBtn:
|
|
369
|
+
title: t = "",
|
|
370
|
+
children: n,
|
|
371
|
+
onClose: e,
|
|
372
|
+
showBackBtn: a = !1,
|
|
373
|
+
showCloseBtn: l = !0
|
|
371
374
|
}) => {
|
|
372
|
-
const
|
|
375
|
+
const m = u("button", {
|
|
373
376
|
className: "back-btn",
|
|
374
377
|
innerHTML: ee,
|
|
375
|
-
dataset: { show: String(
|
|
376
|
-
events: { click: () =>
|
|
377
|
-
}),
|
|
378
|
-
textContent:
|
|
379
|
-
}),
|
|
378
|
+
dataset: { show: String(a) },
|
|
379
|
+
events: { click: () => d() }
|
|
380
|
+
}), c = u("h3", {
|
|
381
|
+
textContent: t
|
|
382
|
+
}), o = u("button", {
|
|
380
383
|
className: "close-btn",
|
|
381
384
|
innerHTML: "×",
|
|
382
|
-
dataset: { show: String(
|
|
385
|
+
dataset: { show: String(l) },
|
|
383
386
|
attributes: { "aria-label": "Close modal" },
|
|
384
|
-
events: { click: () =>
|
|
385
|
-
}),
|
|
387
|
+
events: { click: () => d() }
|
|
388
|
+
}), h = u("div", {
|
|
386
389
|
className: "modal-header",
|
|
387
|
-
children: [
|
|
390
|
+
children: [m, c, o]
|
|
388
391
|
}), s = u("div", {
|
|
389
392
|
className: "modal-content",
|
|
390
|
-
children: [
|
|
393
|
+
children: [n]
|
|
391
394
|
}), r = u("dialog", {
|
|
392
395
|
className: "custom-modal",
|
|
393
|
-
children: [
|
|
396
|
+
children: [h, s],
|
|
394
397
|
events: {
|
|
395
|
-
cancel: (
|
|
396
|
-
|
|
398
|
+
cancel: (i) => {
|
|
399
|
+
i.preventDefault(), d();
|
|
397
400
|
}
|
|
398
401
|
}
|
|
399
|
-
}),
|
|
400
|
-
r.close(),
|
|
402
|
+
}), d = () => {
|
|
403
|
+
r.close(), e?.();
|
|
401
404
|
};
|
|
402
405
|
return {
|
|
403
406
|
element: r,
|
|
404
|
-
setModalVisibility: (
|
|
405
|
-
|
|
407
|
+
setModalVisibility: (i) => {
|
|
408
|
+
i ? r.showModal() : r.close();
|
|
406
409
|
}
|
|
407
410
|
};
|
|
408
|
-
}, ce = ({ token:
|
|
409
|
-
const
|
|
411
|
+
}, ce = ({ token: t, endpoint: n, beneficiaryCard: e = !1, isModal: a = !1, onCallback: l = () => null }) => {
|
|
412
|
+
const m = e ? "Enter Recipient Debit Card Details" : "Enter Your Debit Card Details", c = e ? "Enter the debit card details of the recipient you're sending funds to." : "Linking an external account allows you to send and receive money to your account.", o = e ? "Debit Card Number" : "Your Debit Card Number", h = e ? "Enter recipient's card number" : "Enter your card number", s = `add-card-form-wrapper${e ? " recipient-form" : ""}`, r = {
|
|
410
413
|
cardNumber: "",
|
|
411
414
|
expiryDate: "",
|
|
412
415
|
cvv: "",
|
|
413
416
|
zipCode: ""
|
|
414
|
-
}, { element:
|
|
415
|
-
label:
|
|
416
|
-
placeholder:
|
|
417
|
+
}, { element: d, setError: p } = $({
|
|
418
|
+
label: o,
|
|
419
|
+
placeholder: h,
|
|
417
420
|
id: "card-number-input",
|
|
418
421
|
name: "cardNumber",
|
|
419
422
|
maskType: "card",
|
|
420
|
-
onChange(
|
|
421
|
-
L("cardNumber",
|
|
423
|
+
onChange(v) {
|
|
424
|
+
L("cardNumber", v, p);
|
|
422
425
|
}
|
|
423
|
-
}), { element:
|
|
426
|
+
}), { element: i, setError: g } = $({
|
|
424
427
|
label: "Expiration Date",
|
|
425
428
|
placeholder: "MM/YY",
|
|
426
429
|
id: "expiry-input",
|
|
427
430
|
name: "expiryDate",
|
|
428
431
|
maskType: "expiry",
|
|
429
|
-
onChange(
|
|
430
|
-
L("expiryDate",
|
|
432
|
+
onChange(v) {
|
|
433
|
+
L("expiryDate", v, g);
|
|
431
434
|
}
|
|
432
|
-
}), { element:
|
|
435
|
+
}), { element: b, setError: f } = $({
|
|
433
436
|
label: "CVV",
|
|
434
437
|
placeholder: "3-Digit",
|
|
435
438
|
type: "number",
|
|
@@ -437,59 +440,59 @@ const $ = ({ label: n, maskType: e, id: t, name: l, type: a = "text", placeholde
|
|
|
437
440
|
id: "cvv-input",
|
|
438
441
|
name: "cvv",
|
|
439
442
|
tooltip: "A CVV is a 3-digit number on your debit card. You can find it on the back side of the card.",
|
|
440
|
-
onChange(
|
|
441
|
-
L("cvv",
|
|
443
|
+
onChange(v) {
|
|
444
|
+
L("cvv", v, f);
|
|
442
445
|
}
|
|
443
|
-
}), { element:
|
|
446
|
+
}), { element: y, setError: N } = $({
|
|
444
447
|
label: "ZIP Code",
|
|
445
|
-
placeholder:
|
|
448
|
+
placeholder: e ? "ZIP Code" : "Enter your ZIP Code",
|
|
446
449
|
id: "zip-input",
|
|
447
450
|
name: "zipCode",
|
|
448
451
|
maskType: "zip",
|
|
449
|
-
onChange(
|
|
450
|
-
L("zipCode",
|
|
452
|
+
onChange(v) {
|
|
453
|
+
L("zipCode", v, N);
|
|
451
454
|
}
|
|
452
|
-
}),
|
|
453
|
-
className:
|
|
454
|
-
children: [
|
|
455
|
+
}), C = u("div", {
|
|
456
|
+
className: e ? "input-sections" : "inputs",
|
|
457
|
+
children: [d, i, b, y]
|
|
455
458
|
}), A = u("p", {
|
|
456
459
|
className: "submit-error",
|
|
457
460
|
dataset: { show: "false" }
|
|
458
461
|
// innerHTML: `//icon`
|
|
459
|
-
}), { element:
|
|
462
|
+
}), { element: S, setDisabled: w, setLoading: T } = te({
|
|
460
463
|
children: "Link Card",
|
|
461
464
|
type: "submit",
|
|
462
465
|
disabled: !0
|
|
463
|
-
}),
|
|
466
|
+
}), j = (v = "") => {
|
|
464
467
|
x({ element: A }, {
|
|
465
|
-
dataset: { show: String(!!
|
|
468
|
+
dataset: { show: String(!!v) },
|
|
466
469
|
innerHTML: `
|
|
467
470
|
${k}
|
|
468
|
-
${
|
|
471
|
+
${v || ""}
|
|
469
472
|
`
|
|
470
473
|
});
|
|
471
|
-
}, B = (
|
|
472
|
-
|
|
474
|
+
}, B = (v = !0) => {
|
|
475
|
+
w(v), T(v);
|
|
473
476
|
};
|
|
474
|
-
function L(
|
|
475
|
-
r[
|
|
476
|
-
const { isValid: I, errors:
|
|
477
|
-
|
|
477
|
+
function L(v, H, E) {
|
|
478
|
+
r[v] = H;
|
|
479
|
+
const { isValid: I, errors: D } = se(r, e);
|
|
480
|
+
D[v] ? E(D[v]) : E(""), w(!I);
|
|
478
481
|
}
|
|
479
482
|
const O = u("div", {
|
|
480
483
|
className: "submit-button-wrapper",
|
|
481
|
-
children: [A,
|
|
484
|
+
children: [A, S]
|
|
482
485
|
});
|
|
483
|
-
async function P(
|
|
484
|
-
|
|
485
|
-
const H = new FormData(
|
|
486
|
+
async function P(v) {
|
|
487
|
+
v.preventDefault();
|
|
488
|
+
const H = new FormData(v.target), E = Object.fromEntries(H.entries());
|
|
486
489
|
console.log(E);
|
|
487
|
-
const I = E?.cardNumber,
|
|
488
|
-
B(!0),
|
|
489
|
-
const
|
|
490
|
+
const I = E?.cardNumber, D = E?.expiryDate, _ = E?.cvv, G = E?.zipCode, K = Number(D?.split("/")[0]), U = re(D?.split("/")[1]), J = V(I);
|
|
491
|
+
B(!0), j("");
|
|
492
|
+
const M = await ie(n, {
|
|
490
493
|
method: "POST",
|
|
491
494
|
body: {
|
|
492
|
-
token:
|
|
495
|
+
token: t,
|
|
493
496
|
pan: J,
|
|
494
497
|
expiry_month: K,
|
|
495
498
|
expiry_year: U,
|
|
@@ -499,20 +502,20 @@ const $ = ({ label: n, maskType: e, id: t, name: l, type: a = "text", placeholde
|
|
|
499
502
|
}
|
|
500
503
|
}
|
|
501
504
|
});
|
|
502
|
-
|
|
505
|
+
M.error ? (console.error("Request failed:", M.error), B(!1), j(M.error), l?.({ success: !1, error: M.error })) : (console.log("Request success:", M.data), B(!1), l?.({ success: !0, data: M.data }));
|
|
503
506
|
}
|
|
504
507
|
const Z = () => u("form", {
|
|
505
508
|
events: {
|
|
506
509
|
submit: P
|
|
507
510
|
},
|
|
508
511
|
children: [
|
|
509
|
-
|
|
512
|
+
C,
|
|
510
513
|
O
|
|
511
514
|
]
|
|
512
515
|
}), W = () => u("div", {
|
|
513
516
|
className: "form-title",
|
|
514
517
|
innerHTML: `
|
|
515
|
-
<p>${
|
|
518
|
+
<p>${c}</p>
|
|
516
519
|
|
|
517
520
|
<div>
|
|
518
521
|
${Q}
|
|
@@ -521,55 +524,55 @@ const $ = ({ label: n, maskType: e, id: t, name: l, type: a = "text", placeholde
|
|
|
521
524
|
</div>
|
|
522
525
|
`
|
|
523
526
|
}), Y = () => u("div", {
|
|
524
|
-
className:
|
|
527
|
+
className: a ? "" : "non-modal-content",
|
|
525
528
|
children: [W(), Z()]
|
|
526
|
-
}),
|
|
529
|
+
}), R = a ? null : u("div", {
|
|
527
530
|
className: `${s} non-modal`,
|
|
528
531
|
children: [
|
|
529
532
|
u("div", {
|
|
530
533
|
className: "non-modal-header",
|
|
531
534
|
innerHTML: `
|
|
532
535
|
<span></span>
|
|
533
|
-
<h3>${
|
|
536
|
+
<h3>${m}</h3>
|
|
534
537
|
<span></span>
|
|
535
538
|
`
|
|
536
539
|
}),
|
|
537
540
|
Y()
|
|
538
541
|
]
|
|
539
|
-
}), { element:
|
|
542
|
+
}), { element: z, setModalVisibility: F } = a ? le({ title: m, children: Y() }) : { element: null, setModalVisibility: () => {
|
|
540
543
|
} };
|
|
541
|
-
function
|
|
542
|
-
|
|
544
|
+
function q() {
|
|
545
|
+
z && (document.body.appendChild(
|
|
543
546
|
u("div", {
|
|
544
547
|
className: s,
|
|
545
|
-
children: [
|
|
548
|
+
children: [z]
|
|
546
549
|
})
|
|
547
|
-
),
|
|
550
|
+
), F(!0));
|
|
548
551
|
}
|
|
549
552
|
return {
|
|
550
|
-
renderFormWithModal:
|
|
551
|
-
nonModalForm:
|
|
552
|
-
closeModal: () =>
|
|
553
|
+
renderFormWithModal: q,
|
|
554
|
+
nonModalForm: R,
|
|
555
|
+
closeModal: () => F(!1)
|
|
553
556
|
};
|
|
554
557
|
};
|
|
555
|
-
function de({ token:
|
|
556
|
-
const { renderFormWithModal:
|
|
557
|
-
token:
|
|
558
|
-
endpoint:
|
|
559
|
-
beneficiaryCard:
|
|
560
|
-
isModal:
|
|
561
|
-
onCallback:
|
|
558
|
+
function de({ token: t, endpoint: n, beneficiaryCard: e, isModal: a, onCallback: l, onModalClose: m }) {
|
|
559
|
+
const { renderFormWithModal: c, nonModalForm: o, closeModal: h } = ce({
|
|
560
|
+
token: t,
|
|
561
|
+
endpoint: n,
|
|
562
|
+
beneficiaryCard: e,
|
|
563
|
+
isModal: a,
|
|
564
|
+
onCallback: l
|
|
562
565
|
});
|
|
563
566
|
return {
|
|
564
567
|
mount(s) {
|
|
565
568
|
const r = "className" in s ? document.querySelector(s.className) : "id" in s ? document.getElementById(s.id) : s.element;
|
|
566
|
-
r &&
|
|
569
|
+
r && o && r.appendChild(o);
|
|
567
570
|
},
|
|
568
571
|
open() {
|
|
569
|
-
|
|
572
|
+
c();
|
|
570
573
|
},
|
|
571
574
|
destroy() {
|
|
572
|
-
|
|
575
|
+
h(), m?.();
|
|
573
576
|
}
|
|
574
577
|
};
|
|
575
578
|
}
|