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