@payconductor/react 1.2.0 → 1.2.1
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/esm/three-ds.d.ts +1 -1
- package/dist/esm/tokenizer.d.ts +1 -1
- package/dist/index.cjs.js +49 -49
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.es.js +1401 -1318
- package/dist/index.es.js.map +1 -1
- package/dist/payconductor/constants.d.ts +32 -31
- package/dist/payconductor/hooks/index.d.ts +7 -7
- package/dist/payconductor/hooks/use-element.d.ts +30 -30
- package/dist/payconductor/hooks/use-payconductor.d.ts +6 -6
- package/dist/payconductor/hooks/use-three-ds.d.ts +13 -13
- package/dist/payconductor/hooks/use-tokenizer.d.ts +11 -11
- package/dist/payconductor/iframe/constants.d.ts +7 -8
- package/dist/payconductor/iframe/types.d.ts +464 -464
- package/dist/payconductor/internal.d.ts +11 -11
- package/dist/payconductor/loader.d.ts +1 -1
- package/dist/payconductor/payconductor-element.d.ts +5 -5
- package/dist/payconductor/payconductor-three-ds.d.ts +5 -5
- package/dist/payconductor/payconductor.d.ts +17 -17
- package/dist/payconductor/three-ds/api.d.ts +14 -12
- package/dist/payconductor/three-ds/browser.d.ts +13 -13
- package/dist/payconductor/three-ds/handler.d.ts +12 -11
- package/dist/payconductor/three-ds/index.d.ts +3 -3
- package/dist/payconductor/three-ds/providers/index.d.ts +6 -6
- package/dist/payconductor/three-ds/providers/mercado-pago.d.ts +9 -9
- package/dist/payconductor/three-ds/providers/pagarme.d.ts +9 -9
- package/dist/payconductor/three-ds/providers/pagseguro.d.ts +7 -7
- package/dist/payconductor/three-ds/providers/payconductor.d.ts +7 -7
- package/dist/payconductor/three-ds/providers/sandbox.d.ts +9 -0
- package/dist/payconductor/three-ds/types.d.ts +100 -93
- package/dist/payconductor/tokenizer/api.d.ts +25 -26
- package/dist/payconductor/tokenizer/handler.d.ts +9 -9
- package/dist/payconductor/tokenizer/index.d.ts +1 -1
- package/dist/payconductor/tokenizer/providers/index.d.ts +6 -6
- package/dist/payconductor/tokenizer/providers/mercado-pago.d.ts +7 -6
- package/dist/payconductor/tokenizer/types.d.ts +50 -50
- package/dist/payconductor/types.d.ts +42 -42
- package/dist/payconductor/utils.d.ts +6 -6
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,1318 +1,1401 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { jsx as
|
|
5
|
-
import { useState as I, useEffect as
|
|
6
|
-
const
|
|
7
|
-
var
|
|
8
|
-
const
|
|
9
|
-
primaryColor: "#0066ff",
|
|
10
|
-
secondaryColor: "#5a6b7c",
|
|
11
|
-
backgroundColor: "transparent",
|
|
12
|
-
surfaceColor: "#f8fafc",
|
|
13
|
-
textColor: "#0f172a",
|
|
14
|
-
textSecondaryColor: "#64748b",
|
|
15
|
-
errorColor: "#ef4444",
|
|
16
|
-
successColor: "#22c55e",
|
|
17
|
-
warningColor: "#f59e0b",
|
|
18
|
-
borderColor: "#e2e8f0",
|
|
19
|
-
disabledColor: "#cbd5e1",
|
|
20
|
-
fontFamily: '"Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
21
|
-
fontSize: {
|
|
22
|
-
xs: "0.75rem",
|
|
23
|
-
sm: "0.875rem",
|
|
24
|
-
md: "1rem",
|
|
25
|
-
lg: "1.125rem",
|
|
26
|
-
xl: "1.25rem"
|
|
27
|
-
},
|
|
28
|
-
fontWeight: {
|
|
29
|
-
normal: 400,
|
|
30
|
-
medium: 500,
|
|
31
|
-
bold: 600
|
|
32
|
-
},
|
|
33
|
-
lineHeight: "1.5",
|
|
34
|
-
spacing: {
|
|
35
|
-
xs: "4px",
|
|
36
|
-
sm: "8px",
|
|
37
|
-
md: "16px",
|
|
38
|
-
lg: "24px",
|
|
39
|
-
xl: "32px"
|
|
40
|
-
},
|
|
41
|
-
borderRadius: "8px",
|
|
42
|
-
borderWidth: "1px",
|
|
43
|
-
boxShadow: "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)",
|
|
44
|
-
boxShadowHover: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
|
|
45
|
-
inputBackground: "#ffffff",
|
|
46
|
-
inputBorderColor: "#cbd5e1",
|
|
47
|
-
inputBorderRadius: "8px",
|
|
48
|
-
inputHeight: "44px",
|
|
49
|
-
inputPadding: "12px 16px",
|
|
50
|
-
buttonHeight: "48px",
|
|
51
|
-
buttonPadding: "16px 24px",
|
|
52
|
-
buttonBorderRadius: "8px",
|
|
53
|
-
transitionDuration: "0.2s",
|
|
54
|
-
transitionTimingFunction: "ease"
|
|
55
|
-
},
|
|
56
|
-
INIT:
|
|
57
|
-
CONFIG:
|
|
58
|
-
UPDATE:
|
|
59
|
-
CONFIRM_PAYMENT:
|
|
60
|
-
VALIDATE:
|
|
61
|
-
RESET:
|
|
62
|
-
READY:
|
|
63
|
-
ERROR:
|
|
64
|
-
PAYMENT_COMPLETE:
|
|
65
|
-
PAYMENT_FAILED:
|
|
66
|
-
PAYMENT_PENDING:
|
|
67
|
-
VALIDATION_ERROR:
|
|
68
|
-
PAYMENT_METHOD_SELECTED:
|
|
69
|
-
RESIZE:
|
|
70
|
-
},
|
|
71
|
-
INVALID_CLIENT: "InvalidClient",
|
|
72
|
-
INVALID_TOKEN: "InvalidToken",
|
|
73
|
-
NETWORK_ERROR: "NetworkError",
|
|
74
|
-
IFRAME_NOT_READY: "IframeNotReady",
|
|
75
|
-
PAYMENT_DECLINED: "PaymentDeclined",
|
|
76
|
-
VALIDATION_ERROR: "ValidationError",
|
|
77
|
-
TIMEOUT: "Timeout"
|
|
78
|
-
}, H = "payconductor-skeleton-style",
|
|
79
|
-
@keyframes payconductor-shimmer {
|
|
80
|
-
0% { background-position: -200% 0; }
|
|
81
|
-
100% { background-position: 200% 0; }
|
|
82
|
-
}
|
|
83
|
-
.payconductor-skeleton {
|
|
84
|
-
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
|
85
|
-
background-size: 200% 100%;
|
|
86
|
-
animation: payconductor-shimmer 1.5s infinite linear;
|
|
87
|
-
border-radius: 4px;
|
|
88
|
-
width: 100%;
|
|
89
|
-
}
|
|
90
|
-
`;
|
|
91
|
-
function
|
|
92
|
-
const
|
|
93
|
-
publicKey: e.publicKey
|
|
94
|
-
});
|
|
95
|
-
return `${
|
|
96
|
-
}
|
|
97
|
-
function
|
|
98
|
-
return crypto.randomUUID();
|
|
99
|
-
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
102
|
-
try {
|
|
103
|
-
return new URL(t).origin === e;
|
|
104
|
-
} catch {
|
|
105
|
-
return t === e;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function
|
|
110
|
-
return /* @__PURE__ */ new Map();
|
|
111
|
-
}
|
|
112
|
-
function
|
|
113
|
-
return new Promise((i,
|
|
114
|
-
if (!e || !("contentWindow" in e)) {
|
|
115
|
-
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (!(e != null && e.contentWindow)) {
|
|
119
|
-
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (!
|
|
123
|
-
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
resolve: i,
|
|
129
|
-
reject:
|
|
130
|
-
}), e.contentWindow.postMessage({
|
|
131
|
-
type: t,
|
|
132
|
-
data:
|
|
133
|
-
requestId:
|
|
134
|
-
}, "*"), setTimeout(() => {
|
|
135
|
-
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
function
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
async function
|
|
143
|
-
return await
|
|
144
|
-
orderId: t.orderId
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
function
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
function
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
function
|
|
154
|
-
return
|
|
155
|
-
}
|
|
156
|
-
function
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
function
|
|
160
|
-
const
|
|
161
|
-
requestId: f,
|
|
162
|
-
type: u,
|
|
163
|
-
data:
|
|
164
|
-
error:
|
|
165
|
-
} =
|
|
166
|
-
if (u ===
|
|
167
|
-
if (
|
|
168
|
-
const {
|
|
169
|
-
resolve:
|
|
170
|
-
} =
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (
|
|
176
|
-
if (f &&
|
|
177
|
-
const {
|
|
178
|
-
resolve:
|
|
179
|
-
reject:
|
|
180
|
-
} =
|
|
181
|
-
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (u ===
|
|
185
|
-
t((
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (u ===
|
|
189
|
-
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (u ===
|
|
193
|
-
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
if (u ===
|
|
197
|
-
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
if (u ===
|
|
201
|
-
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (u !==
|
|
205
|
-
if (u ===
|
|
206
|
-
c == null || c();
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
if (u ===
|
|
210
|
-
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
if (u ===
|
|
214
|
-
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function
|
|
221
|
-
const [
|
|
222
|
-
() => !1
|
|
223
|
-
), [
|
|
224
|
-
() => ""
|
|
225
|
-
), [
|
|
226
|
-
return
|
|
227
|
-
const c = (...
|
|
228
|
-
e.debug && console.log("[PayConductor]", ...
|
|
229
|
-
},
|
|
230
|
-
publicKey: e.publicKey
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
let
|
|
235
|
-
c("init", e.publicKey), c("iframeUrl",
|
|
236
|
-
const f = () => {
|
|
237
|
-
var C, l;
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
240
|
-
if (
|
|
241
|
-
if (typeof
|
|
242
|
-
const y =
|
|
243
|
-
if ("current" in y && y.current instanceof HTMLIFrameElement)
|
|
244
|
-
return y.current;
|
|
245
|
-
if ("value" in y && y.value instanceof HTMLIFrameElement)
|
|
246
|
-
return y.value;
|
|
247
|
-
}
|
|
248
|
-
return
|
|
249
|
-
}
|
|
250
|
-
return document.querySelector(
|
|
251
|
-
".payconductor-element iframe"
|
|
252
|
-
) ?? void 0;
|
|
253
|
-
}, u = {
|
|
254
|
-
get iframe() {
|
|
255
|
-
return document.querySelector(
|
|
256
|
-
".payconductor-element iframe"
|
|
257
|
-
) ?? null;
|
|
258
|
-
},
|
|
259
|
-
set iframe(
|
|
260
|
-
},
|
|
261
|
-
iframeUrl:
|
|
262
|
-
error: null
|
|
263
|
-
},
|
|
264
|
-
publicKey: e.publicKey,
|
|
265
|
-
theme: e.theme,
|
|
266
|
-
locale: e.locale,
|
|
267
|
-
paymentMethods: e.paymentMethods,
|
|
268
|
-
defaultPaymentMethod: e.defaultPaymentMethod
|
|
269
|
-
},
|
|
270
|
-
confirmPayment: (
|
|
271
|
-
var l;
|
|
272
|
-
c("→ CONFIRM_PAYMENT", {
|
|
273
|
-
orderId:
|
|
274
|
-
});
|
|
275
|
-
const C = f();
|
|
276
|
-
return C != null && C.contentWindow && C.contentWindow.postMessage(
|
|
277
|
-
{
|
|
278
|
-
type:
|
|
279
|
-
data: {
|
|
280
|
-
publicKey: e.publicKey,
|
|
281
|
-
orderId:
|
|
282
|
-
theme: e.theme,
|
|
283
|
-
locale: e.locale,
|
|
284
|
-
paymentMethods: e.paymentMethods,
|
|
285
|
-
defaultPaymentMethod: e.defaultPaymentMethod,
|
|
286
|
-
showPaymentButtons: e.showPaymentButtons,
|
|
287
|
-
nuPayConfig: e.nuPayConfig
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
"*"
|
|
291
|
-
),
|
|
292
|
-
},
|
|
293
|
-
validate: (
|
|
294
|
-
reset: () => (c("→ RESET"),
|
|
295
|
-
getSelectedPaymentMethod: () =>
|
|
296
|
-
};
|
|
297
|
-
window.PayConductor = {
|
|
298
|
-
frame: u,
|
|
299
|
-
config:
|
|
300
|
-
api:
|
|
301
|
-
selectedPaymentMethod:
|
|
302
|
-
}, c("registered"), window.dispatchEvent(
|
|
303
|
-
new CustomEvent("payconductor:registered", {
|
|
304
|
-
detail: window.PayConductor
|
|
305
|
-
})
|
|
306
|
-
);
|
|
307
|
-
const
|
|
308
|
-
if (!
|
|
309
|
-
const
|
|
310
|
-
if (!
|
|
311
|
-
c("→ CONFIG skipped: iframe not found");
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
theme: e.theme,
|
|
316
|
-
locale: e.locale,
|
|
317
|
-
paymentMethods: e.paymentMethods,
|
|
318
|
-
defaultPaymentMethod: e.defaultPaymentMethod,
|
|
319
|
-
showPaymentButtons: e.showPaymentButtons
|
|
320
|
-
}),
|
|
321
|
-
theme: e.theme,
|
|
322
|
-
locale: e.locale,
|
|
323
|
-
paymentMethods: e.paymentMethods,
|
|
324
|
-
defaultPaymentMethod: e.defaultPaymentMethod,
|
|
325
|
-
showPaymentButtons: e.showPaymentButtons,
|
|
326
|
-
nuPayConfig: e.nuPayConfig
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
},
|
|
330
|
-
var C;
|
|
331
|
-
(C =
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
(l) => {
|
|
335
|
-
var y;
|
|
336
|
-
i(l), u.error = l, (y = window.PayConductor) != null && y.frame && (window.PayConductor.frame.error = l);
|
|
337
|
-
},
|
|
338
|
-
() => {
|
|
339
|
-
var l;
|
|
340
|
-
(l = e.onReady) == null || l.call(e),
|
|
341
|
-
},
|
|
342
|
-
(l) => {
|
|
343
|
-
var y;
|
|
344
|
-
(y = e.onError) == null || y.call(e, l);
|
|
345
|
-
},
|
|
346
|
-
(l) => {
|
|
347
|
-
var y;
|
|
348
|
-
(y = e.onPaymentComplete) == null || y.call(e, l);
|
|
349
|
-
},
|
|
350
|
-
(l) => {
|
|
351
|
-
var y;
|
|
352
|
-
(y = e.onPaymentFailed) == null || y.call(e, l);
|
|
353
|
-
},
|
|
354
|
-
(l) => {
|
|
355
|
-
var y;
|
|
356
|
-
(y = e.onPaymentPending) == null || y.call(e, l);
|
|
357
|
-
},
|
|
358
|
-
(l) => {
|
|
359
|
-
var y;
|
|
360
|
-
|
|
361
|
-
},
|
|
362
|
-
() => {
|
|
363
|
-
var l;
|
|
364
|
-
(l = e.onThreeDSChallenge) == null || l.call(e);
|
|
365
|
-
},
|
|
366
|
-
() => {
|
|
367
|
-
var l;
|
|
368
|
-
(l = e.onThreeDSComplete) == null || l.call(e);
|
|
369
|
-
},
|
|
370
|
-
() => {
|
|
371
|
-
var l;
|
|
372
|
-
(l = e.onThreeDSFailed) == null || l.call(e);
|
|
373
|
-
}
|
|
374
|
-
);
|
|
375
|
-
};
|
|
376
|
-
window.addEventListener("message",
|
|
377
|
-
const
|
|
378
|
-
var C, l, y;
|
|
379
|
-
const
|
|
380
|
-
if (!
|
|
381
|
-
try {
|
|
382
|
-
if ((((C =
|
|
383
|
-
return
|
|
384
|
-
} catch {
|
|
385
|
-
}
|
|
386
|
-
return !1;
|
|
387
|
-
},
|
|
388
|
-
if (
|
|
389
|
-
const
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
once: !0
|
|
393
|
-
});
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
setTimeout(
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
}, []), /* @__PURE__ */
|
|
400
|
-
"div",
|
|
401
|
-
{
|
|
402
|
-
className: "payconductor",
|
|
403
|
-
id: "payconductor",
|
|
404
|
-
style: {
|
|
405
|
-
display: "contents"
|
|
406
|
-
},
|
|
407
|
-
children: e.children
|
|
408
|
-
}
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
function
|
|
412
|
-
const
|
|
413
|
-
return
|
|
414
|
-
if (typeof document < "u" && !document.getElementById(H)) {
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
PayConductor: window.PayConductor
|
|
421
|
-
}));
|
|
422
|
-
}, c = typeof window < "u" ? window.PayConductor : null;
|
|
423
|
-
if (c)
|
|
424
|
-
|
|
425
|
-
else {
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
};
|
|
429
|
-
window.addEventListener("payconductor:registered",
|
|
430
|
-
}
|
|
431
|
-
let
|
|
432
|
-
const
|
|
433
|
-
var f, u,
|
|
434
|
-
if (((f =
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
".payconductor-element iframe"
|
|
438
|
-
);
|
|
439
|
-
|
|
440
|
-
{
|
|
441
|
-
type:
|
|
442
|
-
data: {
|
|
443
|
-
height: e.height
|
|
444
|
-
},
|
|
445
|
-
requestId: "element-height"
|
|
446
|
-
},
|
|
447
|
-
"*"
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
return window.addEventListener("message",
|
|
452
|
-
}, []), /* @__PURE__ */
|
|
453
|
-
"div",
|
|
454
|
-
{
|
|
455
|
-
className: "payconductor-element",
|
|
456
|
-
style: {
|
|
457
|
-
width: "100%"
|
|
458
|
-
},
|
|
459
|
-
children: [
|
|
460
|
-
i ? null : /* @__PURE__ */
|
|
461
|
-
"div",
|
|
462
|
-
{
|
|
463
|
-
className: "payconductor-skeleton",
|
|
464
|
-
style: {
|
|
465
|
-
height: e.height ||
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
),
|
|
469
|
-
i && t ? /* @__PURE__ */
|
|
470
|
-
"iframe",
|
|
471
|
-
{
|
|
472
|
-
allow: "payment",
|
|
473
|
-
title: "PayConductor",
|
|
474
|
-
ref:
|
|
475
|
-
src: t,
|
|
476
|
-
style: {
|
|
477
|
-
width: "100%",
|
|
478
|
-
height: e.height ||
|
|
479
|
-
border: "none"
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
) : null
|
|
483
|
-
]
|
|
484
|
-
}
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
function
|
|
488
|
-
const [
|
|
489
|
-
return
|
|
490
|
-
const
|
|
491
|
-
t(!0);
|
|
492
|
-
}, i = () => {
|
|
493
|
-
t(!1);
|
|
494
|
-
};
|
|
495
|
-
return window.addEventListener("payconductor:3ds:show",
|
|
496
|
-
container: () => document.getElementById("payconductor-3ds-container"),
|
|
497
|
-
show:
|
|
498
|
-
hide: i
|
|
499
|
-
}, window.dispatchEvent(new CustomEvent("payconductor:3ds:registered"))), () => {
|
|
500
|
-
window.removeEventListener("payconductor:3ds:show",
|
|
501
|
-
};
|
|
502
|
-
}, []), /* @__PURE__ */
|
|
503
|
-
"div",
|
|
504
|
-
{
|
|
505
|
-
className: "payconductor-three-ds",
|
|
506
|
-
id: "payconductor-3ds-container",
|
|
507
|
-
style: {
|
|
508
|
-
width: "100%",
|
|
509
|
-
display:
|
|
510
|
-
minHeight:
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
function
|
|
516
|
-
const e = typeof window < "u" ? window.PayConductor : null,
|
|
517
|
-
publicKey: e.config.publicKey,
|
|
518
|
-
orderId: e.config.orderId,
|
|
519
|
-
theme: e.config.theme,
|
|
520
|
-
locale: e.config.locale
|
|
521
|
-
} : {}, t = e != null && e.frame ? {
|
|
522
|
-
iframe: e.frame.iframe,
|
|
523
|
-
error: e.frame.error
|
|
524
|
-
} : {
|
|
525
|
-
iframe: null,
|
|
526
|
-
error: null
|
|
527
|
-
};
|
|
528
|
-
return {
|
|
529
|
-
...
|
|
530
|
-
...t
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
function
|
|
534
|
-
var
|
|
535
|
-
if ((
|
|
536
|
-
const t = e.frame.iframe;
|
|
537
|
-
if (t instanceof HTMLIFrameElement) return t;
|
|
538
|
-
if (t && typeof t == "object") {
|
|
539
|
-
if ("current" in t) {
|
|
540
|
-
const
|
|
541
|
-
if (
|
|
542
|
-
}
|
|
543
|
-
if ("value" in t) {
|
|
544
|
-
const
|
|
545
|
-
if (
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
return document.querySelector(".payconductor-element iframe") ?? null;
|
|
550
|
-
}
|
|
551
|
-
function
|
|
552
|
-
const e = () => typeof window < "u" ? window.PayConductor : null,
|
|
553
|
-
const i = e();
|
|
554
|
-
if (!i) return;
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
type: t,
|
|
558
|
-
data:
|
|
559
|
-
}, "*");
|
|
560
|
-
};
|
|
561
|
-
return {
|
|
562
|
-
init: async (t) => {
|
|
563
|
-
const
|
|
564
|
-
return
|
|
565
|
-
},
|
|
566
|
-
confirmPayment: async (t) => {
|
|
567
|
-
if (!t.orderId)
|
|
568
|
-
throw new Error("Order ID is required");
|
|
569
|
-
const
|
|
570
|
-
if (!(
|
|
571
|
-
return
|
|
572
|
-
},
|
|
573
|
-
validate: (t) => {
|
|
574
|
-
const
|
|
575
|
-
return
|
|
576
|
-
},
|
|
577
|
-
reset: () => {
|
|
578
|
-
const t = e();
|
|
579
|
-
return t ? t.api.reset() : Promise.resolve();
|
|
580
|
-
},
|
|
581
|
-
getSelectedPaymentMethod: () => {
|
|
582
|
-
var t;
|
|
583
|
-
return ((t = e()) == null ? void 0 : t.selectedPaymentMethod) ?? null;
|
|
584
|
-
},
|
|
585
|
-
updateConfig: (t) => {
|
|
586
|
-
var i;
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
publicKey:
|
|
590
|
-
orderId:
|
|
591
|
-
theme: t.theme ?? (
|
|
592
|
-
locale: t.locale ?? (
|
|
593
|
-
paymentMethods: t.paymentMethods ?? (
|
|
594
|
-
});
|
|
595
|
-
},
|
|
596
|
-
updateOrderId: (t) => {
|
|
597
|
-
var i;
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
publicKey:
|
|
601
|
-
orderId: t,
|
|
602
|
-
theme:
|
|
603
|
-
locale:
|
|
604
|
-
paymentMethods:
|
|
605
|
-
});
|
|
606
|
-
},
|
|
607
|
-
update: (t) => {
|
|
608
|
-
|
|
609
|
-
},
|
|
610
|
-
submit: async () => {
|
|
611
|
-
const t =
|
|
612
|
-
try {
|
|
613
|
-
return await
|
|
614
|
-
paymentMethod: void 0
|
|
615
|
-
};
|
|
616
|
-
} catch (i) {
|
|
617
|
-
return {
|
|
618
|
-
error: {
|
|
619
|
-
message: i instanceof Error ? i.message : "Payment failed",
|
|
620
|
-
code: "payment_error",
|
|
621
|
-
type: "payment_error"
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
};
|
|
627
|
-
}
|
|
628
|
-
var
|
|
629
|
-
class k {
|
|
630
|
-
constructor(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
this.data =
|
|
634
|
-
}
|
|
635
|
-
/** Os SDKs de 3DS dos provedores (Pagar.me, PagSeguro) esperam o valor em centavos. */
|
|
636
|
-
get amountInCents() {
|
|
637
|
-
return this.data.amount === void 0 ? void 0 : Math.round(this.data.amount * 100);
|
|
638
|
-
}
|
|
639
|
-
fail(
|
|
640
|
-
var i,
|
|
641
|
-
const
|
|
642
|
-
return (
|
|
643
|
-
...t,
|
|
644
|
-
status: "Failed",
|
|
645
|
-
error:
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
//#region Modal
|
|
649
|
-
showModal() {
|
|
650
|
-
return this.injectStyles(), this.overlay = document.createElement("div"), this.overlay.id = "payconductor-3ds-overlay", this.modalContent = document.createElement("div"), this.modalContent.id = "payconductor-3ds-modal", this.overlay.appendChild(this.modalContent), document.body.appendChild(this.overlay), this.modalContent;
|
|
651
|
-
}
|
|
652
|
-
closeModal() {
|
|
653
|
-
this.overlay && (this.overlay.remove(), this.overlay = null, this.modalContent = null);
|
|
654
|
-
}
|
|
655
|
-
resolveContainer() {
|
|
656
|
-
return this.modalContent ?? this.showModal();
|
|
657
|
-
}
|
|
658
|
-
injectStyles() {
|
|
659
|
-
if (document.getElementById("payconductor-3ds-styles")) return;
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
#payconductor-3ds-overlay {
|
|
663
|
-
position: fixed;
|
|
664
|
-
inset: 0;
|
|
665
|
-
z-index: 99999;
|
|
666
|
-
display: flex;
|
|
667
|
-
align-items: center;
|
|
668
|
-
justify-content: center;
|
|
669
|
-
background: rgba(0, 0, 0, 0.6);
|
|
670
|
-
}
|
|
671
|
-
#payconductor-3ds-modal {
|
|
672
|
-
width: 500px;
|
|
673
|
-
max-width: 95vw;
|
|
674
|
-
min-height: 600px;
|
|
675
|
-
border-radius: 8px;
|
|
676
|
-
overflow: hidden;
|
|
677
|
-
background: #fff;
|
|
678
|
-
}
|
|
679
|
-
#payconductor-3ds-modal iframe {
|
|
680
|
-
width: 100%;
|
|
681
|
-
height: 600px;
|
|
682
|
-
border: none;
|
|
683
|
-
display: block;
|
|
684
|
-
}
|
|
685
|
-
@media only screen and (max-width: 600px) {
|
|
686
|
-
#payconductor-3ds-modal {
|
|
687
|
-
width: 100vw;
|
|
688
|
-
max-width: 100vw;
|
|
689
|
-
min-height: 440px;
|
|
690
|
-
border-radius: 0;
|
|
691
|
-
}
|
|
692
|
-
#payconductor-3ds-modal iframe {
|
|
693
|
-
height: 440px;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
`, document.head.appendChild(
|
|
697
|
-
}
|
|
698
|
-
//#endregion
|
|
699
|
-
}
|
|
700
|
-
const
|
|
701
|
-
class
|
|
702
|
-
constructor() {
|
|
703
|
-
super(...arguments);
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
async authenticate() {
|
|
709
|
-
const {
|
|
710
|
-
threeDsUrl: t,
|
|
711
|
-
creq:
|
|
712
|
-
} = this.data;
|
|
713
|
-
if (!t || !
|
|
714
|
-
return this.fail("Missing threeDsUrl or creq");
|
|
715
|
-
const i = this.resolveContainer();
|
|
716
|
-
return new Promise((
|
|
717
|
-
var c;
|
|
718
|
-
this.iframe = document.createElement("iframe"), this.iframe.name = "payconductor-3ds-challenge", this.iframe.id = "payconductor-3ds-challenge", i.appendChild(this.iframe), this.messageListener = (
|
|
719
|
-
var
|
|
720
|
-
((
|
|
721
|
-
status:
|
|
722
|
-
}));
|
|
723
|
-
}, window.addEventListener("message", this.messageListener), this.timeoutId = setTimeout(() => {
|
|
724
|
-
var
|
|
725
|
-
this.cleanup(), (
|
|
726
|
-
status:
|
|
727
|
-
});
|
|
728
|
-
}, this.options.timeoutMs ??
|
|
729
|
-
const
|
|
730
|
-
if (!
|
|
731
|
-
this.cleanup(),
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
const
|
|
735
|
-
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
cleanup() {
|
|
741
|
-
this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.messageListener && (window.removeEventListener("message", this.messageListener), this.messageListener = null), this.iframe && (this.iframe.remove(), this.iframe = null), this.closeModal();
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
const
|
|
745
|
-
function
|
|
746
|
-
const
|
|
747
|
-
if (
|
|
748
|
-
const t = new Promise((
|
|
749
|
-
if (document.querySelector(`script[src="${e}"]`)) {
|
|
750
|
-
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}, (document.head || document.body).appendChild(
|
|
757
|
-
});
|
|
758
|
-
return
|
|
759
|
-
}
|
|
760
|
-
const
|
|
761
|
-
class
|
|
762
|
-
constructor() {
|
|
763
|
-
super(...arguments);
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
async authenticate() {
|
|
767
|
-
const {
|
|
768
|
-
operationUrl: t,
|
|
769
|
-
publicKey:
|
|
770
|
-
} = this.data;
|
|
771
|
-
if (!t || !
|
|
772
|
-
return this.fail("Missing operationUrl or publicKey");
|
|
773
|
-
try {
|
|
774
|
-
await
|
|
775
|
-
} catch {
|
|
776
|
-
return this.fail("Failed to load 3DS SDK");
|
|
777
|
-
}
|
|
778
|
-
const i = window.KrAuthenticate;
|
|
779
|
-
return i ? new Promise((
|
|
780
|
-
this.timeoutId = setTimeout(() => {
|
|
781
|
-
var
|
|
782
|
-
this.cleanup(), (
|
|
783
|
-
status:
|
|
784
|
-
});
|
|
785
|
-
}, this.options.timeoutMs ??
|
|
786
|
-
var
|
|
787
|
-
this.cleanup(), (
|
|
788
|
-
status:
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
}) : this.fail("KrAuthenticate not available");
|
|
792
|
-
}
|
|
793
|
-
cleanup() {
|
|
794
|
-
this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
const
|
|
798
|
-
[
|
|
799
|
-
[
|
|
800
|
-
},
|
|
801
|
-
function
|
|
802
|
-
const e = window.innerWidth;
|
|
803
|
-
return e <= 480 ? "01" : e <= 768 ? "02" : e <= 1024 ? "03" : "04";
|
|
804
|
-
}
|
|
805
|
-
class
|
|
806
|
-
constructor() {
|
|
807
|
-
super(...arguments);
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
}
|
|
811
|
-
async authenticate() {
|
|
812
|
-
const {
|
|
813
|
-
authToken: t,
|
|
814
|
-
card:
|
|
815
|
-
} = this.data;
|
|
816
|
-
if (!t) return this.fail("Missing authToken for PagarMe 3DS");
|
|
817
|
-
if (!
|
|
818
|
-
const i = this.data.environment ??
|
|
819
|
-
try {
|
|
820
|
-
await
|
|
821
|
-
} catch {
|
|
822
|
-
return this.fail("Failed to load Stone 3DS SDK");
|
|
823
|
-
}
|
|
824
|
-
const
|
|
825
|
-
if (!
|
|
826
|
-
const
|
|
827
|
-
return this.methodContainer = document.createElement("div"), this.methodContainer.style.display = "none", document.body.appendChild(this.methodContainer), new Promise((
|
|
828
|
-
this.timeoutId = setTimeout(() => {
|
|
829
|
-
var
|
|
830
|
-
this.cleanup(), (c = (
|
|
831
|
-
status:
|
|
832
|
-
});
|
|
833
|
-
}, this.options.timeoutMs ??
|
|
834
|
-
token: t,
|
|
835
|
-
tds_method_container_element: this.methodContainer,
|
|
836
|
-
challenge_container_element:
|
|
837
|
-
use_default_challenge_iframe_style: !0,
|
|
838
|
-
challenge_window_size:
|
|
839
|
-
}, this.buildOrderData()).then((
|
|
840
|
-
var
|
|
841
|
-
if (this.cleanup(), !(
|
|
842
|
-
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
const c =
|
|
846
|
-
transStatus:
|
|
847
|
-
providerTransactionId: c.tds_server_trans_id,
|
|
848
|
-
challengeCanceled: c.challenge_canceled
|
|
849
|
-
};
|
|
850
|
-
if (c.challenge_canceled) {
|
|
851
|
-
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
...
|
|
856
|
-
status:
|
|
857
|
-
dsTransactionId: c.tds_server_trans_id
|
|
858
|
-
})) :
|
|
859
|
-
}).catch((
|
|
860
|
-
this.cleanup(),
|
|
861
|
-
});
|
|
862
|
-
});
|
|
863
|
-
}
|
|
864
|
-
cleanup() {
|
|
865
|
-
this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.methodContainer && (this.methodContainer.remove(), this.methodContainer = null), this.closeModal();
|
|
866
|
-
}
|
|
867
|
-
buildOrderData() {
|
|
868
|
-
var
|
|
869
|
-
const {
|
|
870
|
-
card: t,
|
|
871
|
-
customer:
|
|
872
|
-
billingAddress: i
|
|
873
|
-
} = this.data;
|
|
874
|
-
return {
|
|
875
|
-
payments: [{
|
|
876
|
-
payment_method: "credit_card",
|
|
877
|
-
credit_card: {
|
|
878
|
-
card: {
|
|
879
|
-
number: t == null ? void 0 : t.number,
|
|
880
|
-
holder_name: t == null ? void 0 : t.holderName,
|
|
881
|
-
exp_month: Number(t == null ? void 0 : t.expMonth),
|
|
882
|
-
exp_year: Number(t == null ? void 0 : t.expYear),
|
|
883
|
-
billing_address: i ? {
|
|
884
|
-
country: i.country,
|
|
885
|
-
state: i.state,
|
|
886
|
-
city: i.city,
|
|
887
|
-
zip_code: i.zipCode,
|
|
888
|
-
line_1: `${i.number}, ${i.street}${i.district ? `, ${i.district}` : ""}`,
|
|
889
|
-
line_2: i.complement ?? ""
|
|
890
|
-
} : void 0
|
|
891
|
-
}
|
|
892
|
-
},
|
|
893
|
-
amount: this.amountInCents
|
|
894
|
-
}],
|
|
895
|
-
...
|
|
896
|
-
customer: {
|
|
897
|
-
name:
|
|
898
|
-
email:
|
|
899
|
-
...
|
|
900
|
-
document:
|
|
901
|
-
} : {},
|
|
902
|
-
...(
|
|
903
|
-
phones: Object.fromEntries(
|
|
904
|
-
country_code:
|
|
905
|
-
area_code:
|
|
906
|
-
number:
|
|
907
|
-
}]))
|
|
908
|
-
} : {}
|
|
909
|
-
}
|
|
910
|
-
} : {}
|
|
911
|
-
};
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
const
|
|
915
|
-
class
|
|
916
|
-
async authenticate() {
|
|
917
|
-
var
|
|
918
|
-
const {
|
|
919
|
-
authToken:
|
|
920
|
-
card: t,
|
|
921
|
-
customer:
|
|
922
|
-
currency: i,
|
|
923
|
-
billingAddress:
|
|
924
|
-
} = this.data,
|
|
925
|
-
if (!
|
|
926
|
-
if (!t) return this.fail("Missing card data for PagSeguro 3DS");
|
|
927
|
-
if (!
|
|
928
|
-
if (!
|
|
929
|
-
if (!
|
|
930
|
-
const
|
|
931
|
-
try {
|
|
932
|
-
await
|
|
933
|
-
} catch {
|
|
934
|
-
return this.fail("Failed to load PagSeguro SDK");
|
|
935
|
-
}
|
|
936
|
-
const
|
|
937
|
-
if (!
|
|
938
|
-
|
|
939
|
-
session:
|
|
940
|
-
env:
|
|
941
|
-
});
|
|
942
|
-
const c = ((
|
|
943
|
-
country: u.countryCode,
|
|
944
|
-
area: u.areaCode,
|
|
945
|
-
number: u.number,
|
|
946
|
-
type: u.type ?? "MOBILE"
|
|
947
|
-
}))) ?? [{
|
|
948
|
-
country: "55",
|
|
949
|
-
area: "11",
|
|
950
|
-
number: "999999999",
|
|
951
|
-
type: "MOBILE"
|
|
952
|
-
}];
|
|
953
|
-
c.some((u) => u.type === "MOBILE") || (c[0].type = "MOBILE");
|
|
954
|
-
try {
|
|
955
|
-
const u = await
|
|
956
|
-
data: {
|
|
957
|
-
customer: {
|
|
958
|
-
name:
|
|
959
|
-
email:
|
|
960
|
-
phones: c
|
|
961
|
-
},
|
|
962
|
-
paymentMethod: {
|
|
963
|
-
type: this.data.installments === 0 ? "DEBIT_CARD" : "CREDIT_CARD",
|
|
964
|
-
installments: this.data.installments ?? 1,
|
|
965
|
-
card: {
|
|
966
|
-
number: t.number,
|
|
967
|
-
expMonth: t.expMonth,
|
|
968
|
-
expYear: t.expYear,
|
|
969
|
-
holder: {
|
|
970
|
-
name: t.holderName
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
},
|
|
974
|
-
amount: {
|
|
975
|
-
value:
|
|
976
|
-
currency: i ?? "BRL"
|
|
977
|
-
},
|
|
978
|
-
billingAddress: {
|
|
979
|
-
street:
|
|
980
|
-
number:
|
|
981
|
-
complement:
|
|
982
|
-
regionCode:
|
|
983
|
-
country:
|
|
984
|
-
city:
|
|
985
|
-
postalCode:
|
|
986
|
-
},
|
|
987
|
-
dataOnly: !1
|
|
988
|
-
}
|
|
989
|
-
});
|
|
990
|
-
return u.status === "AUTH_FLOW_COMPLETED" || u.status === "AUTH_NOT_SUPPORTED" ? ((f = (
|
|
991
|
-
status:
|
|
992
|
-
dsTransactionId: u.id
|
|
993
|
-
}) : u.status === "CHANGE_PAYMENT_METHOD" ? this.fail("PagSeguro requires a different payment method") : {
|
|
994
|
-
status:
|
|
995
|
-
dsTransactionId: u.id
|
|
996
|
-
};
|
|
997
|
-
} catch (u) {
|
|
998
|
-
return this.fail(u instanceof Error ? u.message : "PagSeguro 3DS failed");
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
cleanup() {
|
|
1002
|
-
}
|
|
1003
|
-
toAlpha3(
|
|
1004
|
-
return {
|
|
1005
|
-
BR: "BRA",
|
|
1006
|
-
US: "USA",
|
|
1007
|
-
AR: "ARG",
|
|
1008
|
-
CL: "CHL",
|
|
1009
|
-
CO: "COL",
|
|
1010
|
-
MX: "MEX",
|
|
1011
|
-
PE: "PER",
|
|
1012
|
-
UY: "URY"
|
|
1013
|
-
}[
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
this.
|
|
1137
|
-
}
|
|
1138
|
-
async
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1
|
+
var X = Object.defineProperty;
|
|
2
|
+
var Z = (e, a, t) => a in e ? X(e, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[a] = t;
|
|
3
|
+
var b = (e, a, t) => Z(e, typeof a != "symbol" ? a + "" : a, t);
|
|
4
|
+
import { jsx as N, jsxs as Q } from "react/jsx-runtime";
|
|
5
|
+
import { useState as I, useEffect as z, useRef as ee } from "react";
|
|
6
|
+
const te = "https://app.payconductor.ai", ne = "http://localhost:3000", G = "https://iframe.payconductor.ai/v1", V = "http://localhost:5175/v1", ae = 3e5, ie = "600px";
|
|
7
|
+
var re = /* @__PURE__ */ ((e) => (e.Pix = "Pix", e.CreditCard = "CreditCard", e.DebitCard = "DebitCard", e.BankSlip = "BankSlip", e.Crypto = "Crypto", e.ApplePay = "ApplePay", e.NuPay = "NuPay", e.PicPay = "PicPay", e.AmazonPay = "AmazonPay", e.SepaDebit = "SepaDebit", e.GooglePay = "GooglePay", e))(re || {}), oe = /* @__PURE__ */ ((e) => (e.Grid = "grid", e.Vertical = "vertical", e.Horizontal = "horizontal", e))(oe || {}), se = /* @__PURE__ */ ((e) => (e.Succeeded = "succeeded", e.Pending = "pending", e.Failed = "failed", e))(se || {}), de = /* @__PURE__ */ ((e) => (e.ThreeDsAwaitingChallenge = "ThreeDsAwaitingChallenge", e))(de || {}), ce = /* @__PURE__ */ ((e) => (e.Authenticated = "Authenticated", e.NotAuthenticated = "NotAuthenticated", e.NeedChallenge = "NeedChallenge", e))(ce || {}), le = /* @__PURE__ */ ((e) => (e.Pending = "Pending", e.Authenticated = "Authenticated", e.Failed = "Failed", e.NotEnrolled = "NotEnrolled", e))(le || {}), q = /* @__PURE__ */ ((e) => (e.Cpf = "Cpf", e.Cnpj = "Cnpj", e))(q || {}), v = /* @__PURE__ */ ((e) => (e.Asaas = "Asaas", e.Sandbox = "Sandbox", e.SandboxSplit = "SandboxSplit", e.MercadoPago = "MercadoPago", e.NuPay = "NuPay", e.PicPay = "PicPay", e.Woovi = "Woovi", e.EfiBank = "EfiBank", e.BrasPag = "BrasPag", e.PagarMe = "PagarMe", e.BancoDoBrasil = "BancoDoBrasil", e.PagSeguro = "PagSeguro", e.Ebanx = "Ebanx", e.OnlyUp = "OnlyUp", e.Barte = "Barte", e.BarteSplit = "BarteSplit", e.PagSmileA55 = "PagSmileA55", e.Avantti = "Avantti", e.MonsterGateway = "MonsterGateway", e.SAC = "SAC", e.Lyra = "Lyra", e))(v || {}), ue = /* @__PURE__ */ ((e) => (e.Visa = "Visa", e.Mastercard = "Mastercard", e.AmericanExpress = "AmericanExpress", e.DinersClub = "DinersClub", e.Discover = "Discover", e.JCB = "JCB", e.UnionPay = "UnionPay", e.Maestro = "Maestro", e.Mir = "Mir", e.Elo = "Elo", e.Hiper = "Hiper", e.Hipercard = "Hipercard", e.Verve = "Verve", e.Unknown = "Unknown", e))(ue || {}), R = /* @__PURE__ */ ((e) => (e.Production = "Production", e.Sandbox = "Sandbox", e))(R || {}), he = /* @__PURE__ */ ((e) => (e.USD = "USD", e.EUR = "EUR", e.BRL = "BRL", e.ARS = "ARS", e.CAD = "CAD", e.COP = "COP", e.GBP = "GBP", e.JPY = "JPY", e.MXN = "MXN", e.MZN = "MZN", e.CNY = "CNY", e.SAR = "SAR", e.ETH = "ETH", e.BNB = "BNB", e.BTC = "BTC", e.USDT = "USDT", e.USDC = "USDC", e.DOGE = "DOGE", e.SOL = "SOL", e))(he || {}), me = /* @__PURE__ */ ((e) => (e.Android = "android", e.IOS = "ios", e.Web = "web", e.Chrome = "chrome", e.Safari = "safari", e))(me || {}), fe = /* @__PURE__ */ ((e) => (e.Padding = "padding", e.Radius = "radius", e.Color = "color", e.Background = "background", e.Shadow = "shadow", e))(fe || {}), M = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(M || {}), T = /* @__PURE__ */ ((e) => (e.Ready = "Ready", e.Error = "Error", e.CheckoutSessionCreated = "CheckoutSessionCreated", e.PaymentComplete = "PaymentComplete", e.PaymentFailed = "PaymentFailed", e.PaymentPending = "PaymentPending", e.ValidationError = "ValidationError", e.PaymentMethodSelected = "PaymentMethodSelected", e.Resize = "Resize", e.ThreeDSChallenge = "ThreeDSChallenge", e.ThreeDSComplete = "ThreeDSComplete", e.ThreeDSFailed = "ThreeDSFailed", e))(T || {}), ye = /* @__PURE__ */ ((e) => (e.InvalidClient = "InvalidClient", e.InvalidToken = "InvalidToken", e.NetworkError = "NetworkError", e.IframeNotReady = "IframeNotReady", e.PaymentDeclined = "PaymentDeclined", e.ValidationError = "ValidationError", e.Timeout = "Timeout", e))(ye || {});
|
|
8
|
+
const at = {
|
|
9
|
+
primaryColor: "#0066ff",
|
|
10
|
+
secondaryColor: "#5a6b7c",
|
|
11
|
+
backgroundColor: "transparent",
|
|
12
|
+
surfaceColor: "#f8fafc",
|
|
13
|
+
textColor: "#0f172a",
|
|
14
|
+
textSecondaryColor: "#64748b",
|
|
15
|
+
errorColor: "#ef4444",
|
|
16
|
+
successColor: "#22c55e",
|
|
17
|
+
warningColor: "#f59e0b",
|
|
18
|
+
borderColor: "#e2e8f0",
|
|
19
|
+
disabledColor: "#cbd5e1",
|
|
20
|
+
fontFamily: '"Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
21
|
+
fontSize: {
|
|
22
|
+
xs: "0.75rem",
|
|
23
|
+
sm: "0.875rem",
|
|
24
|
+
md: "1rem",
|
|
25
|
+
lg: "1.125rem",
|
|
26
|
+
xl: "1.25rem"
|
|
27
|
+
},
|
|
28
|
+
fontWeight: {
|
|
29
|
+
normal: 400,
|
|
30
|
+
medium: 500,
|
|
31
|
+
bold: 600
|
|
32
|
+
},
|
|
33
|
+
lineHeight: "1.5",
|
|
34
|
+
spacing: {
|
|
35
|
+
xs: "4px",
|
|
36
|
+
sm: "8px",
|
|
37
|
+
md: "16px",
|
|
38
|
+
lg: "24px",
|
|
39
|
+
xl: "32px"
|
|
40
|
+
},
|
|
41
|
+
borderRadius: "8px",
|
|
42
|
+
borderWidth: "1px",
|
|
43
|
+
boxShadow: "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)",
|
|
44
|
+
boxShadowHover: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
|
|
45
|
+
inputBackground: "#ffffff",
|
|
46
|
+
inputBorderColor: "#cbd5e1",
|
|
47
|
+
inputBorderRadius: "8px",
|
|
48
|
+
inputHeight: "44px",
|
|
49
|
+
inputPadding: "12px 16px",
|
|
50
|
+
buttonHeight: "48px",
|
|
51
|
+
buttonPadding: "16px 24px",
|
|
52
|
+
buttonBorderRadius: "8px",
|
|
53
|
+
transitionDuration: "0.2s",
|
|
54
|
+
transitionTimingFunction: "ease"
|
|
55
|
+
}, W = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") && !window.location.search.includes("production"), Ee = W ? V : G, _ = `${W ? ne : te}/api/v1/sdk`, ge = [V, G], j = ie, we = ae, p = {
|
|
56
|
+
INIT: M.Init,
|
|
57
|
+
CONFIG: M.Config,
|
|
58
|
+
UPDATE: M.Update,
|
|
59
|
+
CONFIRM_PAYMENT: M.ConfirmPayment,
|
|
60
|
+
VALIDATE: M.Validate,
|
|
61
|
+
RESET: M.Reset,
|
|
62
|
+
READY: T.Ready,
|
|
63
|
+
ERROR: T.Error,
|
|
64
|
+
PAYMENT_COMPLETE: T.PaymentComplete,
|
|
65
|
+
PAYMENT_FAILED: T.PaymentFailed,
|
|
66
|
+
PAYMENT_PENDING: T.PaymentPending,
|
|
67
|
+
VALIDATION_ERROR: T.ValidationError,
|
|
68
|
+
PAYMENT_METHOD_SELECTED: T.PaymentMethodSelected,
|
|
69
|
+
RESIZE: T.Resize
|
|
70
|
+
}, it = {
|
|
71
|
+
INVALID_CLIENT: "InvalidClient",
|
|
72
|
+
INVALID_TOKEN: "InvalidToken",
|
|
73
|
+
NETWORK_ERROR: "NetworkError",
|
|
74
|
+
IFRAME_NOT_READY: "IframeNotReady",
|
|
75
|
+
PAYMENT_DECLINED: "PaymentDeclined",
|
|
76
|
+
VALIDATION_ERROR: "ValidationError",
|
|
77
|
+
TIMEOUT: "Timeout"
|
|
78
|
+
}, H = "payconductor-skeleton-style", pe = `
|
|
79
|
+
@keyframes payconductor-shimmer {
|
|
80
|
+
0% { background-position: -200% 0; }
|
|
81
|
+
100% { background-position: 200% 0; }
|
|
82
|
+
}
|
|
83
|
+
.payconductor-skeleton {
|
|
84
|
+
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
|
85
|
+
background-size: 200% 100%;
|
|
86
|
+
animation: payconductor-shimmer 1.5s infinite linear;
|
|
87
|
+
border-radius: 4px;
|
|
88
|
+
width: 100%;
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
function be(e) {
|
|
92
|
+
const a = new URLSearchParams({
|
|
93
|
+
publicKey: e.publicKey
|
|
94
|
+
});
|
|
95
|
+
return `${Ee}?${a.toString()}`;
|
|
96
|
+
}
|
|
97
|
+
function Pe() {
|
|
98
|
+
return crypto.randomUUID();
|
|
99
|
+
}
|
|
100
|
+
function Ce(e, a) {
|
|
101
|
+
return a.some((t) => {
|
|
102
|
+
try {
|
|
103
|
+
return new URL(t).origin === e;
|
|
104
|
+
} catch {
|
|
105
|
+
return t === e;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function B() {
|
|
110
|
+
return /* @__PURE__ */ new Map();
|
|
111
|
+
}
|
|
112
|
+
function x(e, a, t, n) {
|
|
113
|
+
return new Promise((i, r) => {
|
|
114
|
+
if (!e || !("contentWindow" in e)) {
|
|
115
|
+
r(new Error("Iframe not defined"));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!(e != null && e.contentWindow)) {
|
|
119
|
+
r(new Error("Iframe not ready"));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!a) {
|
|
123
|
+
r(new Error("Pending requests not initialized"));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const s = Pe();
|
|
127
|
+
a.set(s, {
|
|
128
|
+
resolve: i,
|
|
129
|
+
reject: r
|
|
130
|
+
}), e.contentWindow.postMessage({
|
|
131
|
+
type: t,
|
|
132
|
+
data: n,
|
|
133
|
+
requestId: s
|
|
134
|
+
}, "*"), setTimeout(() => {
|
|
135
|
+
a != null && a.has(s) && (a.delete(s), r(new Error("Request timeout")));
|
|
136
|
+
}, we);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function Se(e, a, t) {
|
|
140
|
+
return x(e, a, p.CONFIRM_PAYMENT, t);
|
|
141
|
+
}
|
|
142
|
+
async function Ae(e, a, t) {
|
|
143
|
+
return await Se(e, a, {
|
|
144
|
+
orderId: t.orderId
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
function Te(e, a, t) {
|
|
148
|
+
return x(e, a, p.VALIDATE, t);
|
|
149
|
+
}
|
|
150
|
+
function ve(e, a) {
|
|
151
|
+
return x(e, a, p.RESET);
|
|
152
|
+
}
|
|
153
|
+
function Ie(e, a, t) {
|
|
154
|
+
return x(e, a, p.CONFIG, t);
|
|
155
|
+
}
|
|
156
|
+
function Me(e, a, t) {
|
|
157
|
+
return x(e, a, p.INIT, t);
|
|
158
|
+
}
|
|
159
|
+
function xe(e, a, t, n, i, r, s, d, o, c, w, E) {
|
|
160
|
+
const m = e.data, {
|
|
161
|
+
requestId: f,
|
|
162
|
+
type: u,
|
|
163
|
+
data: g,
|
|
164
|
+
error: S
|
|
165
|
+
} = m;
|
|
166
|
+
if (u === p.READY) {
|
|
167
|
+
if (n == null || n(), f && (a != null && a.has(f))) {
|
|
168
|
+
const {
|
|
169
|
+
resolve: A
|
|
170
|
+
} = a.get(f);
|
|
171
|
+
a.delete(f), A(g);
|
|
172
|
+
}
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (Ce(e.origin, ge)) {
|
|
176
|
+
if (f && a && a.has(f)) {
|
|
177
|
+
const {
|
|
178
|
+
resolve: A,
|
|
179
|
+
reject: O
|
|
180
|
+
} = a.get(f);
|
|
181
|
+
a.delete(f), S ? O(new Error(String(S.message))) : A(g);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (u === p.ERROR) {
|
|
185
|
+
t((S == null ? void 0 : S.message) || "Unknown error"), i == null || i(new Error(String(S == null ? void 0 : S.message)));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (u === p.PAYMENT_COMPLETE) {
|
|
189
|
+
g && typeof g == "object" && "status" in g && (r == null || r(g));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (u === p.PAYMENT_FAILED) {
|
|
193
|
+
g && typeof g == "object" && "status" in g && (s == null || s(g));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (u === p.PAYMENT_PENDING) {
|
|
197
|
+
g && typeof g == "object" && "status" in g && (d == null || d(g));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (u === p.PAYMENT_METHOD_SELECTED) {
|
|
201
|
+
g && typeof g == "object" && "paymentMethod" in g && (o == null || o(g.paymentMethod));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (u !== p.RESIZE) {
|
|
205
|
+
if (u === T.ThreeDSChallenge) {
|
|
206
|
+
c == null || c();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (u === T.ThreeDSComplete) {
|
|
210
|
+
w == null || w();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (u === T.ThreeDSFailed) {
|
|
214
|
+
E == null || E();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function rt(e) {
|
|
221
|
+
const [a, t] = I(
|
|
222
|
+
() => !1
|
|
223
|
+
), [n, i] = I(() => null), [r, s] = I(
|
|
224
|
+
() => ""
|
|
225
|
+
), [d, o] = I(() => null);
|
|
226
|
+
return z(() => {
|
|
227
|
+
const c = (...h) => {
|
|
228
|
+
e.debug && console.log("[PayConductor]", ...h);
|
|
229
|
+
}, w = be({
|
|
230
|
+
publicKey: e.publicKey
|
|
231
|
+
});
|
|
232
|
+
s(w), t(!0);
|
|
233
|
+
const E = B();
|
|
234
|
+
let m = !1;
|
|
235
|
+
c("init", e.publicKey), c("iframeUrl", w);
|
|
236
|
+
const f = () => {
|
|
237
|
+
var C, l;
|
|
238
|
+
const h = (l = (C = window.PayConductor) == null ? void 0 : C.frame) == null ? void 0 : l.iframe;
|
|
239
|
+
if (h) {
|
|
240
|
+
if (h instanceof HTMLIFrameElement) return h;
|
|
241
|
+
if (typeof h == "object" && h !== null) {
|
|
242
|
+
const y = h;
|
|
243
|
+
if ("current" in y && y.current instanceof HTMLIFrameElement)
|
|
244
|
+
return y.current;
|
|
245
|
+
if ("value" in y && y.value instanceof HTMLIFrameElement)
|
|
246
|
+
return y.value;
|
|
247
|
+
}
|
|
248
|
+
return h;
|
|
249
|
+
}
|
|
250
|
+
return document.querySelector(
|
|
251
|
+
".payconductor-element iframe"
|
|
252
|
+
) ?? void 0;
|
|
253
|
+
}, u = {
|
|
254
|
+
get iframe() {
|
|
255
|
+
return document.querySelector(
|
|
256
|
+
".payconductor-element iframe"
|
|
257
|
+
) ?? null;
|
|
258
|
+
},
|
|
259
|
+
set iframe(h) {
|
|
260
|
+
},
|
|
261
|
+
iframeUrl: w,
|
|
262
|
+
error: null
|
|
263
|
+
}, g = {
|
|
264
|
+
publicKey: e.publicKey,
|
|
265
|
+
theme: e.theme,
|
|
266
|
+
locale: e.locale,
|
|
267
|
+
paymentMethods: e.paymentMethods,
|
|
268
|
+
defaultPaymentMethod: e.defaultPaymentMethod
|
|
269
|
+
}, S = {
|
|
270
|
+
confirmPayment: (h) => {
|
|
271
|
+
var l;
|
|
272
|
+
c("→ CONFIRM_PAYMENT", {
|
|
273
|
+
orderId: h.orderId
|
|
274
|
+
});
|
|
275
|
+
const C = f();
|
|
276
|
+
return C != null && C.contentWindow && C.contentWindow.postMessage(
|
|
277
|
+
{
|
|
278
|
+
type: p.CONFIG,
|
|
279
|
+
data: {
|
|
280
|
+
publicKey: e.publicKey,
|
|
281
|
+
orderId: h.orderId,
|
|
282
|
+
theme: e.theme,
|
|
283
|
+
locale: e.locale,
|
|
284
|
+
paymentMethods: e.paymentMethods,
|
|
285
|
+
defaultPaymentMethod: e.defaultPaymentMethod,
|
|
286
|
+
showPaymentButtons: e.showPaymentButtons,
|
|
287
|
+
nuPayConfig: e.nuPayConfig
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
"*"
|
|
291
|
+
), g.orderId = h.orderId, (l = window.PayConductor) != null && l.config && (window.PayConductor.config.orderId = h.orderId), Ae(C, E, h);
|
|
292
|
+
},
|
|
293
|
+
validate: (h) => (c("→ VALIDATE", h), Te(f(), E, h)),
|
|
294
|
+
reset: () => (c("→ RESET"), ve(f(), E)),
|
|
295
|
+
getSelectedPaymentMethod: () => d
|
|
296
|
+
};
|
|
297
|
+
window.PayConductor = {
|
|
298
|
+
frame: u,
|
|
299
|
+
config: g,
|
|
300
|
+
api: S,
|
|
301
|
+
selectedPaymentMethod: d
|
|
302
|
+
}, c("registered"), window.dispatchEvent(
|
|
303
|
+
new CustomEvent("payconductor:registered", {
|
|
304
|
+
detail: window.PayConductor
|
|
305
|
+
})
|
|
306
|
+
);
|
|
307
|
+
const A = async () => {
|
|
308
|
+
if (!m) {
|
|
309
|
+
const h = f();
|
|
310
|
+
if (!h) {
|
|
311
|
+
c("→ CONFIG skipped: iframe not found");
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
m = !0, c("→ CONFIG", {
|
|
315
|
+
theme: e.theme,
|
|
316
|
+
locale: e.locale,
|
|
317
|
+
paymentMethods: e.paymentMethods,
|
|
318
|
+
defaultPaymentMethod: e.defaultPaymentMethod,
|
|
319
|
+
showPaymentButtons: e.showPaymentButtons
|
|
320
|
+
}), Ie(h, E, {
|
|
321
|
+
theme: e.theme,
|
|
322
|
+
locale: e.locale,
|
|
323
|
+
paymentMethods: e.paymentMethods,
|
|
324
|
+
defaultPaymentMethod: e.defaultPaymentMethod,
|
|
325
|
+
showPaymentButtons: e.showPaymentButtons,
|
|
326
|
+
nuPayConfig: e.nuPayConfig
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}, O = (h) => {
|
|
330
|
+
var C;
|
|
331
|
+
(C = h.data) != null && C.type && c("←", h.data.type, h.data.data ?? ""), xe(
|
|
332
|
+
h,
|
|
333
|
+
E,
|
|
334
|
+
(l) => {
|
|
335
|
+
var y;
|
|
336
|
+
i(l), u.error = l, (y = window.PayConductor) != null && y.frame && (window.PayConductor.frame.error = l);
|
|
337
|
+
},
|
|
338
|
+
() => {
|
|
339
|
+
var l;
|
|
340
|
+
(l = e.onReady) == null || l.call(e), A();
|
|
341
|
+
},
|
|
342
|
+
(l) => {
|
|
343
|
+
var y;
|
|
344
|
+
(y = e.onError) == null || y.call(e, l);
|
|
345
|
+
},
|
|
346
|
+
(l) => {
|
|
347
|
+
var y;
|
|
348
|
+
(y = e.onPaymentComplete) == null || y.call(e, l);
|
|
349
|
+
},
|
|
350
|
+
(l) => {
|
|
351
|
+
var y;
|
|
352
|
+
(y = e.onPaymentFailed) == null || y.call(e, l);
|
|
353
|
+
},
|
|
354
|
+
(l) => {
|
|
355
|
+
var y;
|
|
356
|
+
(y = e.onPaymentPending) == null || y.call(e, l);
|
|
357
|
+
},
|
|
358
|
+
(l) => {
|
|
359
|
+
var y;
|
|
360
|
+
o(l), window.PayConductor && (window.PayConductor.selectedPaymentMethod = l), (y = e.onPaymentMethodSelected) == null || y.call(e, l);
|
|
361
|
+
},
|
|
362
|
+
() => {
|
|
363
|
+
var l;
|
|
364
|
+
(l = e.onThreeDSChallenge) == null || l.call(e);
|
|
365
|
+
},
|
|
366
|
+
() => {
|
|
367
|
+
var l;
|
|
368
|
+
(l = e.onThreeDSComplete) == null || l.call(e);
|
|
369
|
+
},
|
|
370
|
+
() => {
|
|
371
|
+
var l;
|
|
372
|
+
(l = e.onThreeDSFailed) == null || l.call(e);
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
};
|
|
376
|
+
window.addEventListener("message", O);
|
|
377
|
+
const J = () => {
|
|
378
|
+
var C, l, y;
|
|
379
|
+
const h = f();
|
|
380
|
+
if (!h) return !1;
|
|
381
|
+
try {
|
|
382
|
+
if ((((C = h.contentDocument) == null ? void 0 : C.readyState) ?? ((y = (l = h.contentWindow) == null ? void 0 : l.document) == null ? void 0 : y.readyState)) === "complete")
|
|
383
|
+
return A(), !0;
|
|
384
|
+
} catch {
|
|
385
|
+
}
|
|
386
|
+
return !1;
|
|
387
|
+
}, K = () => {
|
|
388
|
+
if (J()) return;
|
|
389
|
+
const h = f();
|
|
390
|
+
if (h) {
|
|
391
|
+
h.addEventListener("load", () => A(), {
|
|
392
|
+
once: !0
|
|
393
|
+
});
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
setTimeout(K, 50);
|
|
397
|
+
};
|
|
398
|
+
K();
|
|
399
|
+
}, []), /* @__PURE__ */ N(
|
|
400
|
+
"div",
|
|
401
|
+
{
|
|
402
|
+
className: "payconductor",
|
|
403
|
+
id: "payconductor",
|
|
404
|
+
style: {
|
|
405
|
+
display: "contents"
|
|
406
|
+
},
|
|
407
|
+
children: e.children
|
|
408
|
+
}
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
function ot(e) {
|
|
412
|
+
const a = ee(null), [t, n] = I(() => ""), [i, r] = I(() => !1), [s, d] = I(() => "");
|
|
413
|
+
return z(() => {
|
|
414
|
+
if (typeof document < "u" && !document.getElementById(H)) {
|
|
415
|
+
const m = document.createElement("style");
|
|
416
|
+
m.id = H, m.textContent = pe, document.head.appendChild(m);
|
|
417
|
+
}
|
|
418
|
+
const o = (m) => {
|
|
419
|
+
m != null && m.frame && (n(m.frame.iframeUrl || ""), r(!0), console.log("init", {
|
|
420
|
+
PayConductor: window.PayConductor
|
|
421
|
+
}));
|
|
422
|
+
}, c = typeof window < "u" ? window.PayConductor : null;
|
|
423
|
+
if (c)
|
|
424
|
+
o(c);
|
|
425
|
+
else {
|
|
426
|
+
const m = (f) => {
|
|
427
|
+
o(f.detail), window.removeEventListener("payconductor:registered", m);
|
|
428
|
+
};
|
|
429
|
+
window.addEventListener("payconductor:registered", m);
|
|
430
|
+
}
|
|
431
|
+
let w = !1;
|
|
432
|
+
const E = (m) => {
|
|
433
|
+
var f, u, g, S;
|
|
434
|
+
if (((f = m.data) == null ? void 0 : f.type) === p.RESIZE && ((g = (u = m.data) == null ? void 0 : u.data) != null && g.height) && d(m.data.data.height + "px"), ((S = m.data) == null ? void 0 : S.type) === p.READY && e.height && !w) {
|
|
435
|
+
w = !0;
|
|
436
|
+
const A = document.querySelector(
|
|
437
|
+
".payconductor-element iframe"
|
|
438
|
+
);
|
|
439
|
+
A != null && A.contentWindow && A.contentWindow.postMessage(
|
|
440
|
+
{
|
|
441
|
+
type: p.CONFIG,
|
|
442
|
+
data: {
|
|
443
|
+
height: e.height
|
|
444
|
+
},
|
|
445
|
+
requestId: "element-height"
|
|
446
|
+
},
|
|
447
|
+
"*"
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
return window.addEventListener("message", E), () => window.removeEventListener("message", E);
|
|
452
|
+
}, []), /* @__PURE__ */ Q(
|
|
453
|
+
"div",
|
|
454
|
+
{
|
|
455
|
+
className: "payconductor-element",
|
|
456
|
+
style: {
|
|
457
|
+
width: "100%"
|
|
458
|
+
},
|
|
459
|
+
children: [
|
|
460
|
+
i ? null : /* @__PURE__ */ N(
|
|
461
|
+
"div",
|
|
462
|
+
{
|
|
463
|
+
className: "payconductor-skeleton",
|
|
464
|
+
style: {
|
|
465
|
+
height: e.height || j
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
),
|
|
469
|
+
i && t ? /* @__PURE__ */ N(
|
|
470
|
+
"iframe",
|
|
471
|
+
{
|
|
472
|
+
allow: "payment",
|
|
473
|
+
title: "PayConductor",
|
|
474
|
+
ref: a,
|
|
475
|
+
src: t,
|
|
476
|
+
style: {
|
|
477
|
+
width: "100%",
|
|
478
|
+
height: e.height || s || j,
|
|
479
|
+
border: "none"
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
) : null
|
|
483
|
+
]
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
function st(e) {
|
|
488
|
+
const [a, t] = I(() => !1);
|
|
489
|
+
return z(() => {
|
|
490
|
+
const n = () => {
|
|
491
|
+
t(!0);
|
|
492
|
+
}, i = () => {
|
|
493
|
+
t(!1);
|
|
494
|
+
};
|
|
495
|
+
return window.addEventListener("payconductor:3ds:show", n), window.addEventListener("payconductor:3ds:hide", i), typeof window < "u" && (window.PayConductor3DS = {
|
|
496
|
+
container: () => document.getElementById("payconductor-3ds-container"),
|
|
497
|
+
show: n,
|
|
498
|
+
hide: i
|
|
499
|
+
}, window.dispatchEvent(new CustomEvent("payconductor:3ds:registered"))), () => {
|
|
500
|
+
window.removeEventListener("payconductor:3ds:show", n), window.removeEventListener("payconductor:3ds:hide", i), window.PayConductor3DS = null;
|
|
501
|
+
};
|
|
502
|
+
}, []), /* @__PURE__ */ N(
|
|
503
|
+
"div",
|
|
504
|
+
{
|
|
505
|
+
className: "payconductor-three-ds",
|
|
506
|
+
id: "payconductor-3ds-container",
|
|
507
|
+
style: {
|
|
508
|
+
width: "100%",
|
|
509
|
+
display: a ? "block" : "none",
|
|
510
|
+
minHeight: a ? e.height || "600px" : "0"
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
function dt() {
|
|
516
|
+
const e = typeof window < "u" ? window.PayConductor : null, a = e != null && e.config ? {
|
|
517
|
+
publicKey: e.config.publicKey,
|
|
518
|
+
orderId: e.config.orderId,
|
|
519
|
+
theme: e.config.theme,
|
|
520
|
+
locale: e.config.locale
|
|
521
|
+
} : {}, t = e != null && e.frame ? {
|
|
522
|
+
iframe: e.frame.iframe,
|
|
523
|
+
error: e.frame.error
|
|
524
|
+
} : {
|
|
525
|
+
iframe: null,
|
|
526
|
+
error: null
|
|
527
|
+
};
|
|
528
|
+
return {
|
|
529
|
+
...a,
|
|
530
|
+
...t
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function U(e) {
|
|
534
|
+
var a;
|
|
535
|
+
if ((a = e == null ? void 0 : e.frame) != null && a.iframe) {
|
|
536
|
+
const t = e.frame.iframe;
|
|
537
|
+
if (t instanceof HTMLIFrameElement) return t;
|
|
538
|
+
if (t && typeof t == "object") {
|
|
539
|
+
if ("current" in t) {
|
|
540
|
+
const n = t.current;
|
|
541
|
+
if (n instanceof HTMLIFrameElement) return n;
|
|
542
|
+
}
|
|
543
|
+
if ("value" in t) {
|
|
544
|
+
const n = t.value;
|
|
545
|
+
if (n instanceof HTMLIFrameElement) return n;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return document.querySelector(".payconductor-element iframe") ?? null;
|
|
550
|
+
}
|
|
551
|
+
function ct() {
|
|
552
|
+
const e = () => typeof window < "u" ? window.PayConductor : null, a = (t, n) => {
|
|
553
|
+
const i = e();
|
|
554
|
+
if (!i) return;
|
|
555
|
+
const r = U(i);
|
|
556
|
+
r != null && r.contentWindow && r.contentWindow.postMessage({
|
|
557
|
+
type: t,
|
|
558
|
+
data: n
|
|
559
|
+
}, "*");
|
|
560
|
+
};
|
|
561
|
+
return {
|
|
562
|
+
init: async (t) => {
|
|
563
|
+
const n = U(e()), i = B();
|
|
564
|
+
return Me(n || void 0, i, t);
|
|
565
|
+
},
|
|
566
|
+
confirmPayment: async (t) => {
|
|
567
|
+
if (!t.orderId)
|
|
568
|
+
throw new Error("Order ID is required");
|
|
569
|
+
const n = e();
|
|
570
|
+
if (!(n != null && n.api)) throw new Error("PayConductor not initialized");
|
|
571
|
+
return n.api.confirmPayment(t);
|
|
572
|
+
},
|
|
573
|
+
validate: (t) => {
|
|
574
|
+
const n = e();
|
|
575
|
+
return n ? n.api.validate(t) : Promise.resolve(!1);
|
|
576
|
+
},
|
|
577
|
+
reset: () => {
|
|
578
|
+
const t = e();
|
|
579
|
+
return t ? t.api.reset() : Promise.resolve();
|
|
580
|
+
},
|
|
581
|
+
getSelectedPaymentMethod: () => {
|
|
582
|
+
var t;
|
|
583
|
+
return ((t = e()) == null ? void 0 : t.selectedPaymentMethod) ?? null;
|
|
584
|
+
},
|
|
585
|
+
updateConfig: (t) => {
|
|
586
|
+
var i;
|
|
587
|
+
const n = (i = e()) == null ? void 0 : i.config;
|
|
588
|
+
a(p.CONFIG, {
|
|
589
|
+
publicKey: n == null ? void 0 : n.publicKey,
|
|
590
|
+
orderId: n == null ? void 0 : n.orderId,
|
|
591
|
+
theme: t.theme ?? (n == null ? void 0 : n.theme),
|
|
592
|
+
locale: t.locale ?? (n == null ? void 0 : n.locale),
|
|
593
|
+
paymentMethods: t.paymentMethods ?? (n == null ? void 0 : n.paymentMethods)
|
|
594
|
+
});
|
|
595
|
+
},
|
|
596
|
+
updateOrderId: (t) => {
|
|
597
|
+
var i;
|
|
598
|
+
const n = (i = e()) == null ? void 0 : i.config;
|
|
599
|
+
a(p.CONFIG, {
|
|
600
|
+
publicKey: n == null ? void 0 : n.publicKey,
|
|
601
|
+
orderId: t,
|
|
602
|
+
theme: n == null ? void 0 : n.theme,
|
|
603
|
+
locale: n == null ? void 0 : n.locale,
|
|
604
|
+
paymentMethods: n == null ? void 0 : n.paymentMethods
|
|
605
|
+
});
|
|
606
|
+
},
|
|
607
|
+
update: (t) => {
|
|
608
|
+
a(p.UPDATE, t);
|
|
609
|
+
},
|
|
610
|
+
submit: async () => {
|
|
611
|
+
const t = U(e()), n = B();
|
|
612
|
+
try {
|
|
613
|
+
return await x(t || void 0, n, p.CONFIRM_PAYMENT, {}), {
|
|
614
|
+
paymentMethod: void 0
|
|
615
|
+
};
|
|
616
|
+
} catch (i) {
|
|
617
|
+
return {
|
|
618
|
+
error: {
|
|
619
|
+
message: i instanceof Error ? i.message : "Payment failed",
|
|
620
|
+
code: "payment_error",
|
|
621
|
+
type: "payment_error"
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
var P = /* @__PURE__ */ ((e) => (e.Success = "Success", e.Failed = "Failed", e.Timeout = "Timeout", e))(P || {}), D = /* @__PURE__ */ ((e) => (e.Authenticated = "Y", e.Attempted = "A", e.ChallengeRequired = "C", e.NotAuthenticated = "N", e.Unavailable = "U", e.Rejected = "R", e.InformationOnly = "I", e))(D || {});
|
|
629
|
+
class k {
|
|
630
|
+
constructor(a, t) {
|
|
631
|
+
b(this, "overlay", null);
|
|
632
|
+
b(this, "modalContent", null);
|
|
633
|
+
this.data = a, this.options = t;
|
|
634
|
+
}
|
|
635
|
+
/** Os SDKs de 3DS dos provedores (Pagar.me, PagSeguro) esperam o valor em centavos. */
|
|
636
|
+
get amountInCents() {
|
|
637
|
+
return this.data.amount === void 0 ? void 0 : Math.round(this.data.amount * 100);
|
|
638
|
+
}
|
|
639
|
+
fail(a, t = {}) {
|
|
640
|
+
var i, r;
|
|
641
|
+
const n = new Error(a);
|
|
642
|
+
return (r = (i = this.options).onError) == null || r.call(i, n), {
|
|
643
|
+
...t,
|
|
644
|
+
status: "Failed",
|
|
645
|
+
error: n
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
//#region Modal
|
|
649
|
+
showModal() {
|
|
650
|
+
return this.injectStyles(), this.overlay = document.createElement("div"), this.overlay.id = "payconductor-3ds-overlay", this.modalContent = document.createElement("div"), this.modalContent.id = "payconductor-3ds-modal", this.overlay.appendChild(this.modalContent), document.body.appendChild(this.overlay), this.modalContent;
|
|
651
|
+
}
|
|
652
|
+
closeModal() {
|
|
653
|
+
this.overlay && (this.overlay.remove(), this.overlay = null, this.modalContent = null);
|
|
654
|
+
}
|
|
655
|
+
resolveContainer() {
|
|
656
|
+
return this.modalContent ?? this.showModal();
|
|
657
|
+
}
|
|
658
|
+
injectStyles() {
|
|
659
|
+
if (document.getElementById("payconductor-3ds-styles")) return;
|
|
660
|
+
const a = document.createElement("style");
|
|
661
|
+
a.id = "payconductor-3ds-styles", a.textContent = `
|
|
662
|
+
#payconductor-3ds-overlay {
|
|
663
|
+
position: fixed;
|
|
664
|
+
inset: 0;
|
|
665
|
+
z-index: 99999;
|
|
666
|
+
display: flex;
|
|
667
|
+
align-items: center;
|
|
668
|
+
justify-content: center;
|
|
669
|
+
background: rgba(0, 0, 0, 0.6);
|
|
670
|
+
}
|
|
671
|
+
#payconductor-3ds-modal {
|
|
672
|
+
width: 500px;
|
|
673
|
+
max-width: 95vw;
|
|
674
|
+
min-height: 600px;
|
|
675
|
+
border-radius: 8px;
|
|
676
|
+
overflow: hidden;
|
|
677
|
+
background: #fff;
|
|
678
|
+
}
|
|
679
|
+
#payconductor-3ds-modal iframe {
|
|
680
|
+
width: 100%;
|
|
681
|
+
height: 600px;
|
|
682
|
+
border: none;
|
|
683
|
+
display: block;
|
|
684
|
+
}
|
|
685
|
+
@media only screen and (max-width: 600px) {
|
|
686
|
+
#payconductor-3ds-modal {
|
|
687
|
+
width: 100vw;
|
|
688
|
+
max-width: 100vw;
|
|
689
|
+
min-height: 440px;
|
|
690
|
+
border-radius: 0;
|
|
691
|
+
}
|
|
692
|
+
#payconductor-3ds-modal iframe {
|
|
693
|
+
height: 440px;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
`, document.head.appendChild(a);
|
|
697
|
+
}
|
|
698
|
+
//#endregion
|
|
699
|
+
}
|
|
700
|
+
const _e = 5 * 60 * 1e3;
|
|
701
|
+
class De extends k {
|
|
702
|
+
constructor() {
|
|
703
|
+
super(...arguments);
|
|
704
|
+
b(this, "iframe", null);
|
|
705
|
+
b(this, "messageListener", null);
|
|
706
|
+
b(this, "timeoutId", null);
|
|
707
|
+
}
|
|
708
|
+
async authenticate() {
|
|
709
|
+
const {
|
|
710
|
+
threeDsUrl: t,
|
|
711
|
+
creq: n
|
|
712
|
+
} = this.data;
|
|
713
|
+
if (!t || !n)
|
|
714
|
+
return this.fail("Missing threeDsUrl or creq");
|
|
715
|
+
const i = this.resolveContainer();
|
|
716
|
+
return new Promise((r) => {
|
|
717
|
+
var c;
|
|
718
|
+
this.iframe = document.createElement("iframe"), this.iframe.name = "payconductor-3ds-challenge", this.iframe.id = "payconductor-3ds-challenge", i.appendChild(this.iframe), this.messageListener = (w) => {
|
|
719
|
+
var E, m, f;
|
|
720
|
+
((E = w.data) == null ? void 0 : E.status) === "COMPLETE" && (this.cleanup(), (f = (m = this.options).onComplete) == null || f.call(m), r({
|
|
721
|
+
status: P.Success
|
|
722
|
+
}));
|
|
723
|
+
}, window.addEventListener("message", this.messageListener), this.timeoutId = setTimeout(() => {
|
|
724
|
+
var w, E;
|
|
725
|
+
this.cleanup(), (E = (w = this.options).onTimeout) == null || E.call(w), r({
|
|
726
|
+
status: P.Timeout
|
|
727
|
+
});
|
|
728
|
+
}, this.options.timeoutMs ?? _e);
|
|
729
|
+
const s = (c = this.iframe.contentWindow) == null ? void 0 : c.document;
|
|
730
|
+
if (!s) {
|
|
731
|
+
this.cleanup(), r(this.fail("Cannot access iframe document"));
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
const d = s.createElement("form");
|
|
735
|
+
d.name = "threeDsChallengeForm", d.setAttribute("target", "payconductor-3ds-challenge"), d.setAttribute("method", "post"), d.setAttribute("action", t);
|
|
736
|
+
const o = s.createElement("input");
|
|
737
|
+
o.setAttribute("type", "hidden"), o.setAttribute("name", "creq"), o.setAttribute("value", n), d.appendChild(o), this.iframe.appendChild(d), d.submit();
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
cleanup() {
|
|
741
|
+
this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.messageListener && (window.removeEventListener("message", this.messageListener), this.messageListener = null), this.iframe && (this.iframe.remove(), this.iframe = null), this.closeModal();
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
const F = /* @__PURE__ */ new Map();
|
|
745
|
+
function L(e) {
|
|
746
|
+
const a = F.get(e);
|
|
747
|
+
if (a) return a;
|
|
748
|
+
const t = new Promise((n, i) => {
|
|
749
|
+
if (document.querySelector(`script[src="${e}"]`)) {
|
|
750
|
+
n();
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
const r = document.createElement("script");
|
|
754
|
+
r.src = e, r.async = !0, r.onload = () => n(), r.onerror = () => {
|
|
755
|
+
F.delete(e), i(new Error(`Failed to load script: ${e}`));
|
|
756
|
+
}, (document.head || document.body).appendChild(r);
|
|
757
|
+
});
|
|
758
|
+
return F.set(e, t), t;
|
|
759
|
+
}
|
|
760
|
+
const Re = "https://static.payzen.lat/static/js/authenticate-client/V1.0/kr-authenticate.umd.js", ke = 10 * 60 * 1e3;
|
|
761
|
+
class Ne extends k {
|
|
762
|
+
constructor() {
|
|
763
|
+
super(...arguments);
|
|
764
|
+
b(this, "timeoutId", null);
|
|
765
|
+
}
|
|
766
|
+
async authenticate() {
|
|
767
|
+
const {
|
|
768
|
+
operationUrl: t,
|
|
769
|
+
publicKey: n
|
|
770
|
+
} = this.data;
|
|
771
|
+
if (!t || !n)
|
|
772
|
+
return this.fail("Missing operationUrl or publicKey");
|
|
773
|
+
try {
|
|
774
|
+
await L(Re);
|
|
775
|
+
} catch {
|
|
776
|
+
return this.fail("Failed to load 3DS SDK");
|
|
777
|
+
}
|
|
778
|
+
const i = window.KrAuthenticate;
|
|
779
|
+
return i ? new Promise((r) => {
|
|
780
|
+
this.timeoutId = setTimeout(() => {
|
|
781
|
+
var d, o;
|
|
782
|
+
this.cleanup(), (o = (d = this.options).onTimeout) == null || o.call(d), r({
|
|
783
|
+
status: P.Timeout
|
|
784
|
+
});
|
|
785
|
+
}, this.options.timeoutMs ?? ke), new i(n).authenticate(t, () => {
|
|
786
|
+
var d, o;
|
|
787
|
+
this.cleanup(), (o = (d = this.options).onComplete) == null || o.call(d), r({
|
|
788
|
+
status: P.Success
|
|
789
|
+
});
|
|
790
|
+
});
|
|
791
|
+
}) : this.fail("KrAuthenticate not available");
|
|
792
|
+
}
|
|
793
|
+
cleanup() {
|
|
794
|
+
this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
const Le = {
|
|
798
|
+
[R.Production]: "https://3ds-nx-js.stone.com.br/live/v2/3ds2.min.js",
|
|
799
|
+
[R.Sandbox]: "https://3ds-nx-js.stone.com.br/test/v2/3ds2.min.js"
|
|
800
|
+
}, Oe = 5 * 60 * 1e3;
|
|
801
|
+
function Ue() {
|
|
802
|
+
const e = window.innerWidth;
|
|
803
|
+
return e <= 480 ? "01" : e <= 768 ? "02" : e <= 1024 ? "03" : "04";
|
|
804
|
+
}
|
|
805
|
+
class Fe extends k {
|
|
806
|
+
constructor() {
|
|
807
|
+
super(...arguments);
|
|
808
|
+
b(this, "timeoutId", null);
|
|
809
|
+
b(this, "methodContainer", null);
|
|
810
|
+
}
|
|
811
|
+
async authenticate() {
|
|
812
|
+
const {
|
|
813
|
+
authToken: t,
|
|
814
|
+
card: n
|
|
815
|
+
} = this.data;
|
|
816
|
+
if (!t) return this.fail("Missing authToken for PagarMe 3DS");
|
|
817
|
+
if (!n) return this.fail("Missing card data for PagarMe 3DS");
|
|
818
|
+
const i = this.data.environment ?? R.Production;
|
|
819
|
+
try {
|
|
820
|
+
await L(Le[i]);
|
|
821
|
+
} catch {
|
|
822
|
+
return this.fail("Failed to load Stone 3DS SDK");
|
|
823
|
+
}
|
|
824
|
+
const r = window.TDS;
|
|
825
|
+
if (!r) return this.fail("Stone TDS SDK not available");
|
|
826
|
+
const s = this.resolveContainer();
|
|
827
|
+
return this.methodContainer = document.createElement("div"), this.methodContainer.style.display = "none", document.body.appendChild(this.methodContainer), new Promise((d) => {
|
|
828
|
+
this.timeoutId = setTimeout(() => {
|
|
829
|
+
var o, c;
|
|
830
|
+
this.cleanup(), (c = (o = this.options).onTimeout) == null || c.call(o), d({
|
|
831
|
+
status: P.Timeout
|
|
832
|
+
});
|
|
833
|
+
}, this.options.timeoutMs ?? Oe), r.init({
|
|
834
|
+
token: t,
|
|
835
|
+
tds_method_container_element: this.methodContainer,
|
|
836
|
+
challenge_container_element: s,
|
|
837
|
+
use_default_challenge_iframe_style: !0,
|
|
838
|
+
challenge_window_size: Ue()
|
|
839
|
+
}, this.buildOrderData()).then((o) => {
|
|
840
|
+
var m, f;
|
|
841
|
+
if (this.cleanup(), !(o != null && o.length)) {
|
|
842
|
+
d(this.fail("PagarMe 3DS returned no response"));
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
const c = o[0], w = Object.values(D).find((u) => u === c.trans_status), E = {
|
|
846
|
+
transStatus: w,
|
|
847
|
+
providerTransactionId: c.tds_server_trans_id,
|
|
848
|
+
challengeCanceled: c.challenge_canceled
|
|
849
|
+
};
|
|
850
|
+
if (c.challenge_canceled) {
|
|
851
|
+
d(this.fail("3DS challenge canceled by user", E));
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
w === D.Authenticated || w === D.Attempted ? ((f = (m = this.options).onComplete) == null || f.call(m), d({
|
|
855
|
+
...E,
|
|
856
|
+
status: P.Success,
|
|
857
|
+
dsTransactionId: c.tds_server_trans_id
|
|
858
|
+
})) : d(this.fail(`3DS failed with status: ${c.trans_status}`, E));
|
|
859
|
+
}).catch((o) => {
|
|
860
|
+
this.cleanup(), d(this.fail(o instanceof Error ? o.message : "PagarMe 3DS failed"));
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
cleanup() {
|
|
865
|
+
this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.methodContainer && (this.methodContainer.remove(), this.methodContainer = null), this.closeModal();
|
|
866
|
+
}
|
|
867
|
+
buildOrderData() {
|
|
868
|
+
var r;
|
|
869
|
+
const {
|
|
870
|
+
card: t,
|
|
871
|
+
customer: n,
|
|
872
|
+
billingAddress: i
|
|
873
|
+
} = this.data;
|
|
874
|
+
return {
|
|
875
|
+
payments: [{
|
|
876
|
+
payment_method: "credit_card",
|
|
877
|
+
credit_card: {
|
|
878
|
+
card: {
|
|
879
|
+
number: t == null ? void 0 : t.number,
|
|
880
|
+
holder_name: t == null ? void 0 : t.holderName,
|
|
881
|
+
exp_month: Number(t == null ? void 0 : t.expMonth),
|
|
882
|
+
exp_year: Number(t == null ? void 0 : t.expYear),
|
|
883
|
+
billing_address: i ? {
|
|
884
|
+
country: i.country,
|
|
885
|
+
state: i.state,
|
|
886
|
+
city: i.city,
|
|
887
|
+
zip_code: i.zipCode,
|
|
888
|
+
line_1: `${i.number}, ${i.street}${i.district ? `, ${i.district}` : ""}`,
|
|
889
|
+
line_2: i.complement ?? ""
|
|
890
|
+
} : void 0
|
|
891
|
+
}
|
|
892
|
+
},
|
|
893
|
+
amount: this.amountInCents
|
|
894
|
+
}],
|
|
895
|
+
...n ? {
|
|
896
|
+
customer: {
|
|
897
|
+
name: n.name,
|
|
898
|
+
email: n.email,
|
|
899
|
+
...n.document ? {
|
|
900
|
+
document: n.document
|
|
901
|
+
} : {},
|
|
902
|
+
...(r = n.phones) != null && r.length ? {
|
|
903
|
+
phones: Object.fromEntries(n.phones.map((s) => [s.type === "HOME" ? "home_phone" : "mobile_phone", {
|
|
904
|
+
country_code: s.countryCode,
|
|
905
|
+
area_code: s.areaCode,
|
|
906
|
+
number: s.number
|
|
907
|
+
}]))
|
|
908
|
+
} : {}
|
|
909
|
+
}
|
|
910
|
+
} : {}
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
const Be = "https://assets.pagseguro.com.br/checkout-sdk-js/rc/dist/browser/pagseguro.min.js";
|
|
915
|
+
class ze extends k {
|
|
916
|
+
async authenticate() {
|
|
917
|
+
var E, m, f;
|
|
918
|
+
const {
|
|
919
|
+
authToken: a,
|
|
920
|
+
card: t,
|
|
921
|
+
customer: n,
|
|
922
|
+
currency: i,
|
|
923
|
+
billingAddress: r
|
|
924
|
+
} = this.data, s = this.amountInCents;
|
|
925
|
+
if (!a) return this.fail("Missing authToken (session) for PagSeguro 3DS");
|
|
926
|
+
if (!t) return this.fail("Missing card data for PagSeguro 3DS");
|
|
927
|
+
if (!n) return this.fail("Missing customer data for PagSeguro 3DS");
|
|
928
|
+
if (!s) return this.fail("Missing amount for PagSeguro 3DS");
|
|
929
|
+
if (!r) return this.fail("Missing billingAddress for PagSeguro 3DS");
|
|
930
|
+
const d = this.data.environment === R.Sandbox ? "SANDBOX" : "PROD";
|
|
931
|
+
try {
|
|
932
|
+
await L(Be);
|
|
933
|
+
} catch {
|
|
934
|
+
return this.fail("Failed to load PagSeguro SDK");
|
|
935
|
+
}
|
|
936
|
+
const o = window.PagSeguro;
|
|
937
|
+
if (!o) return this.fail("PagSeguro SDK not available");
|
|
938
|
+
o.setUp({
|
|
939
|
+
session: a,
|
|
940
|
+
env: d
|
|
941
|
+
});
|
|
942
|
+
const c = ((E = n.phones) == null ? void 0 : E.map((u) => ({
|
|
943
|
+
country: u.countryCode,
|
|
944
|
+
area: u.areaCode,
|
|
945
|
+
number: u.number,
|
|
946
|
+
type: u.type ?? "MOBILE"
|
|
947
|
+
}))) ?? [{
|
|
948
|
+
country: "55",
|
|
949
|
+
area: "11",
|
|
950
|
+
number: "999999999",
|
|
951
|
+
type: "MOBILE"
|
|
952
|
+
}];
|
|
953
|
+
c.some((u) => u.type === "MOBILE") || (c[0].type = "MOBILE");
|
|
954
|
+
try {
|
|
955
|
+
const u = await o.authenticate3DS({
|
|
956
|
+
data: {
|
|
957
|
+
customer: {
|
|
958
|
+
name: n.name,
|
|
959
|
+
email: n.email,
|
|
960
|
+
phones: c
|
|
961
|
+
},
|
|
962
|
+
paymentMethod: {
|
|
963
|
+
type: this.data.installments === 0 ? "DEBIT_CARD" : "CREDIT_CARD",
|
|
964
|
+
installments: this.data.installments ?? 1,
|
|
965
|
+
card: {
|
|
966
|
+
number: t.number,
|
|
967
|
+
expMonth: t.expMonth,
|
|
968
|
+
expYear: t.expYear,
|
|
969
|
+
holder: {
|
|
970
|
+
name: t.holderName
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
},
|
|
974
|
+
amount: {
|
|
975
|
+
value: s,
|
|
976
|
+
currency: i ?? "BRL"
|
|
977
|
+
},
|
|
978
|
+
billingAddress: {
|
|
979
|
+
street: r.street,
|
|
980
|
+
number: r.number,
|
|
981
|
+
complement: r.complement,
|
|
982
|
+
regionCode: r.state,
|
|
983
|
+
country: r.country.length === 2 ? this.toAlpha3(r.country) : r.country,
|
|
984
|
+
city: r.city,
|
|
985
|
+
postalCode: r.zipCode.replace(/\D/g, "")
|
|
986
|
+
},
|
|
987
|
+
dataOnly: !1
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
return u.status === "AUTH_FLOW_COMPLETED" || u.status === "AUTH_NOT_SUPPORTED" ? ((f = (m = this.options).onComplete) == null || f.call(m), {
|
|
991
|
+
status: P.Success,
|
|
992
|
+
dsTransactionId: u.id
|
|
993
|
+
}) : u.status === "CHANGE_PAYMENT_METHOD" ? this.fail("PagSeguro requires a different payment method") : {
|
|
994
|
+
status: P.Success,
|
|
995
|
+
dsTransactionId: u.id
|
|
996
|
+
};
|
|
997
|
+
} catch (u) {
|
|
998
|
+
return this.fail(u instanceof Error ? u.message : "PagSeguro 3DS failed");
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
cleanup() {
|
|
1002
|
+
}
|
|
1003
|
+
toAlpha3(a) {
|
|
1004
|
+
return {
|
|
1005
|
+
BR: "BRA",
|
|
1006
|
+
US: "USA",
|
|
1007
|
+
AR: "ARG",
|
|
1008
|
+
CL: "CHL",
|
|
1009
|
+
CO: "COL",
|
|
1010
|
+
MX: "MEX",
|
|
1011
|
+
PE: "PER",
|
|
1012
|
+
UY: "URY"
|
|
1013
|
+
}[a.toUpperCase()] ?? a;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
const Ke = 5 * 60 * 1e3, Y = "payconductor-3ds-sandbox-title";
|
|
1017
|
+
class $ extends k {
|
|
1018
|
+
constructor() {
|
|
1019
|
+
super(...arguments);
|
|
1020
|
+
b(this, "timeoutId", null);
|
|
1021
|
+
}
|
|
1022
|
+
async authenticate() {
|
|
1023
|
+
const {
|
|
1024
|
+
authToken: t
|
|
1025
|
+
} = this.data;
|
|
1026
|
+
if (!t) return this.fail("Missing authToken for 3DS challenge");
|
|
1027
|
+
const n = this.resolveContainer();
|
|
1028
|
+
return new Promise((i) => {
|
|
1029
|
+
this.timeoutId = setTimeout(() => {
|
|
1030
|
+
var r, s;
|
|
1031
|
+
this.cleanup(), (s = (r = this.options).onTimeout) == null || s.call(r), i({
|
|
1032
|
+
status: P.Timeout
|
|
1033
|
+
});
|
|
1034
|
+
}, this.options.timeoutMs ?? Ke), this.renderChallenge(n, {
|
|
1035
|
+
onConfirm: () => {
|
|
1036
|
+
var r, s;
|
|
1037
|
+
this.cleanup(), (s = (r = this.options).onComplete) == null || s.call(r), i({
|
|
1038
|
+
status: P.Success,
|
|
1039
|
+
transStatus: D.Authenticated,
|
|
1040
|
+
providerTransactionId: t
|
|
1041
|
+
});
|
|
1042
|
+
},
|
|
1043
|
+
onCancel: () => {
|
|
1044
|
+
this.cleanup(), i(this.fail("3DS challenge canceled by user", {
|
|
1045
|
+
challengeCanceled: !0
|
|
1046
|
+
}));
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
cleanup() {
|
|
1052
|
+
this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.closeModal();
|
|
1053
|
+
}
|
|
1054
|
+
renderChallenge(t, n) {
|
|
1055
|
+
const i = document.createElement("div");
|
|
1056
|
+
i.setAttribute("role", "dialog"), i.setAttribute("aria-modal", "true"), i.setAttribute("aria-labelledby", Y), i.style.cssText = "min-height:inherit;box-sizing:border-box;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;padding:32px;font-family:system-ui,-apple-system,sans-serif;text-align:center;color:#111827";
|
|
1057
|
+
const r = document.createElement("h2");
|
|
1058
|
+
r.id = Y, r.textContent = "Autenticação 3DS (sandbox)", r.style.cssText = "margin:0;font-size:20px";
|
|
1059
|
+
const s = document.createElement("p");
|
|
1060
|
+
s.textContent = "Simulação do desafio do banco emissor. Confirme para aprovar a autenticação ou cancele para simular a desistência do comprador.", s.style.cssText = "margin:0 0 8px;max-width:360px;font-size:14px;line-height:1.5;color:#4b5563";
|
|
1061
|
+
const d = this.createButton("Confirmar autenticação", "background:#111827;color:#fff;border-color:#111827", n.onConfirm), o = this.createButton("Cancelar", "background:#fff;color:#111827;border-color:#d1d5db", n.onCancel);
|
|
1062
|
+
i.append(r, s, d, o), t.appendChild(i), d.focus();
|
|
1063
|
+
}
|
|
1064
|
+
createButton(t, n, i) {
|
|
1065
|
+
const r = document.createElement("button");
|
|
1066
|
+
return r.type = "button", r.textContent = t, r.style.cssText = `width:100%;max-width:320px;padding:12px 16px;border:1px solid;border-radius:6px;font:inherit;font-size:14px;font-weight:600;cursor:pointer;${n}`, r.addEventListener("click", i), r;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
const je = {
|
|
1070
|
+
// Agnostic providers
|
|
1071
|
+
[v.Lyra]: Ne,
|
|
1072
|
+
// Acquirer-specific providers
|
|
1073
|
+
[v.MercadoPago]: De,
|
|
1074
|
+
[v.PagarMe]: Fe,
|
|
1075
|
+
[v.PagSeguro]: ze,
|
|
1076
|
+
[v.Sandbox]: $,
|
|
1077
|
+
[v.SandboxSplit]: $
|
|
1078
|
+
};
|
|
1079
|
+
class He extends Error {
|
|
1080
|
+
constructor(a, t) {
|
|
1081
|
+
super(a), this.title = t, this.name = "PayConductorThreeDSApiError";
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
class Ye {
|
|
1085
|
+
constructor(a) {
|
|
1086
|
+
this.publicKey = a;
|
|
1087
|
+
}
|
|
1088
|
+
async completeManualChallenge(a, t) {
|
|
1089
|
+
const n = await fetch(`${_}/three-ds/complete/${a}`, {
|
|
1090
|
+
method: "POST",
|
|
1091
|
+
headers: this.headers,
|
|
1092
|
+
body: JSON.stringify({
|
|
1093
|
+
providerTransactionId: t
|
|
1094
|
+
})
|
|
1095
|
+
});
|
|
1096
|
+
n.ok || await this.parseResponseError("Failed to complete native 3DS challenge", n);
|
|
1097
|
+
}
|
|
1098
|
+
async getThreeDSecureData(a) {
|
|
1099
|
+
const t = await fetch(`${_}/three-ds/challenge/${a}`, {
|
|
1100
|
+
method: "GET",
|
|
1101
|
+
headers: this.headers
|
|
1102
|
+
});
|
|
1103
|
+
t.ok || await this.parseResponseError("Failed to fetch 3DS data", t);
|
|
1104
|
+
const n = await t.json();
|
|
1105
|
+
return Object.fromEntries(Object.entries(n).filter(([, i]) => i != null));
|
|
1106
|
+
}
|
|
1107
|
+
async parseResponseError(a, t) {
|
|
1108
|
+
var i, r, s, d;
|
|
1109
|
+
let n = "";
|
|
1110
|
+
try {
|
|
1111
|
+
const o = await t.json();
|
|
1112
|
+
o != null && o.message ? n = o.message : (i = o == null ? void 0 : o.error) != null && i.message ? n = o.error : (s = (r = o == null ? void 0 : o.error) == null ? void 0 : r.value) != null && s.message ? n = o.error.value.message : (d = o == null ? void 0 : o.value) != null && d.message ? n = o.value.message : n = JSON.stringify(o);
|
|
1113
|
+
} catch {
|
|
1114
|
+
}
|
|
1115
|
+
throw new He(n, a);
|
|
1116
|
+
}
|
|
1117
|
+
get headers() {
|
|
1118
|
+
return {
|
|
1119
|
+
Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
|
|
1120
|
+
"Content-Type": "application/json"
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
const $e = [v.PagSeguro];
|
|
1125
|
+
class Ge {
|
|
1126
|
+
constructor(a) {
|
|
1127
|
+
b(this, "data");
|
|
1128
|
+
b(this, "provider", null);
|
|
1129
|
+
b(this, "api");
|
|
1130
|
+
this.data = a, this.api = new Ye(this.data.publicKey);
|
|
1131
|
+
}
|
|
1132
|
+
get needsChallenge() {
|
|
1133
|
+
return this.data.status === "NeedChallenge" || this.data.statusDetail === "ThreeDsAwaitingChallenge";
|
|
1134
|
+
}
|
|
1135
|
+
get acquirer() {
|
|
1136
|
+
return this.data.acquirer;
|
|
1137
|
+
}
|
|
1138
|
+
async authenticate(a) {
|
|
1139
|
+
var d;
|
|
1140
|
+
const t = await this.api.getThreeDSecureData(this.data.orderId);
|
|
1141
|
+
if (this.data = {
|
|
1142
|
+
...this.data,
|
|
1143
|
+
...t
|
|
1144
|
+
}, !this.needsChallenge)
|
|
1145
|
+
return {
|
|
1146
|
+
status: P.Success
|
|
1147
|
+
};
|
|
1148
|
+
const {
|
|
1149
|
+
acquirer: n
|
|
1150
|
+
} = this.data;
|
|
1151
|
+
if (!n)
|
|
1152
|
+
return {
|
|
1153
|
+
status: P.Failed,
|
|
1154
|
+
error: new Error("Missing 3DS acquirer")
|
|
1155
|
+
};
|
|
1156
|
+
const i = je[n];
|
|
1157
|
+
if (!i)
|
|
1158
|
+
return {
|
|
1159
|
+
status: P.Failed,
|
|
1160
|
+
error: new Error(`Unsupported 3DS provider: ${n}`)
|
|
1161
|
+
};
|
|
1162
|
+
(d = a == null ? void 0 : a.onChallenge) == null || d.call(a);
|
|
1163
|
+
const r = {
|
|
1164
|
+
...a,
|
|
1165
|
+
threeDSecure: this.data
|
|
1166
|
+
};
|
|
1167
|
+
this.provider = new i(this.data, r);
|
|
1168
|
+
const s = await this.provider.authenticate();
|
|
1169
|
+
return s.status === P.Success && s.dsTransactionId && $e.includes(n) && await this.api.completeManualChallenge(this.data.orderId, s.dsTransactionId), s;
|
|
1170
|
+
}
|
|
1171
|
+
destroy() {
|
|
1172
|
+
this.provider && (this.provider.cleanup(), this.provider = null);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
function lt(e) {
|
|
1176
|
+
let a = null;
|
|
1177
|
+
return {
|
|
1178
|
+
handleChallenge: async (i) => {
|
|
1179
|
+
const r = new Ge(i);
|
|
1180
|
+
a = r;
|
|
1181
|
+
try {
|
|
1182
|
+
return await r.authenticate({
|
|
1183
|
+
onChallenge: e == null ? void 0 : e.onChallenge,
|
|
1184
|
+
onComplete: e == null ? void 0 : e.onComplete,
|
|
1185
|
+
onError: e == null ? void 0 : e.onError,
|
|
1186
|
+
onTimeout: e == null ? void 0 : e.onTimeout
|
|
1187
|
+
});
|
|
1188
|
+
} finally {
|
|
1189
|
+
r.destroy(), a = null;
|
|
1190
|
+
}
|
|
1191
|
+
},
|
|
1192
|
+
destroy: () => {
|
|
1193
|
+
a == null || a.destroy(), a = null;
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
class Ve extends Error {
|
|
1198
|
+
constructor(a, t) {
|
|
1199
|
+
super(a), this.title = t, this.name = "PayConductorTokenizerApiError";
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
class qe {
|
|
1203
|
+
constructor(a) {
|
|
1204
|
+
this.publicKey = a;
|
|
1205
|
+
}
|
|
1206
|
+
async getSettings() {
|
|
1207
|
+
const a = await fetch(`${_}/card-tokenization/settings`, {
|
|
1208
|
+
method: "GET",
|
|
1209
|
+
headers: this.headers
|
|
1210
|
+
});
|
|
1211
|
+
return a.ok || await this.parseResponseError("Failed to fetch settings", a), await a.json();
|
|
1212
|
+
}
|
|
1213
|
+
async createToken(a) {
|
|
1214
|
+
const t = await fetch(`${_}/card-tokenization/tokenize`, {
|
|
1215
|
+
method: "POST",
|
|
1216
|
+
headers: this.headers,
|
|
1217
|
+
body: JSON.stringify(a)
|
|
1218
|
+
});
|
|
1219
|
+
return t.ok || await this.parseResponseError("Failed to generate token", t), await t.json();
|
|
1220
|
+
}
|
|
1221
|
+
async saveTokens(a, t, n) {
|
|
1222
|
+
const i = await fetch(`${_}/card-tokenization/save-tokens/${t}/${n}`, {
|
|
1223
|
+
method: "POST",
|
|
1224
|
+
headers: this.headers,
|
|
1225
|
+
body: JSON.stringify(a)
|
|
1226
|
+
});
|
|
1227
|
+
i.ok || await this.parseResponseError("Failed to save tokens", i);
|
|
1228
|
+
}
|
|
1229
|
+
async parseResponseError(a, t) {
|
|
1230
|
+
var i, r, s, d;
|
|
1231
|
+
let n = "";
|
|
1232
|
+
try {
|
|
1233
|
+
const o = await t.json();
|
|
1234
|
+
o != null && o.message ? n = o.message : (i = o == null ? void 0 : o.error) != null && i.message ? n = o.error : (s = (r = o == null ? void 0 : o.error) == null ? void 0 : r.value) != null && s.message ? n = o.error.value.message : (d = o == null ? void 0 : o.value) != null && d.message ? n = o.value.message : n = JSON.stringify(o);
|
|
1235
|
+
} catch {
|
|
1236
|
+
}
|
|
1237
|
+
throw new Ve(n, a);
|
|
1238
|
+
}
|
|
1239
|
+
get headers() {
|
|
1240
|
+
return {
|
|
1241
|
+
Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
|
|
1242
|
+
"Content-Type": "application/json"
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
class We {
|
|
1247
|
+
constructor(a) {
|
|
1248
|
+
this.input = a;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
class Je extends We {
|
|
1252
|
+
constructor() {
|
|
1253
|
+
super(...arguments);
|
|
1254
|
+
b(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
|
|
1255
|
+
}
|
|
1256
|
+
async tokenize() {
|
|
1257
|
+
const {
|
|
1258
|
+
publicKey: t
|
|
1259
|
+
} = this.input.setting;
|
|
1260
|
+
if (typeof t != "string" || !t.trim())
|
|
1261
|
+
throw new Error("MercadoPago public key is missing in settings");
|
|
1262
|
+
if (!this.input.customer.documentNumber)
|
|
1263
|
+
throw new Error("Customer document number is required for tokenization");
|
|
1264
|
+
const n = window.MercadoPago;
|
|
1265
|
+
if (!n) throw new Error("MercadoPago SDK not available");
|
|
1266
|
+
const i = new n(t.trim()), {
|
|
1267
|
+
expiration: r,
|
|
1268
|
+
cvv: s,
|
|
1269
|
+
number: d,
|
|
1270
|
+
holderName: o
|
|
1271
|
+
} = this.input.card, c = await i.createCardToken({
|
|
1272
|
+
cardExpirationMonth: String(r.month).padStart(2, "0"),
|
|
1273
|
+
cardExpirationYear: String(r.year),
|
|
1274
|
+
cardholderName: o,
|
|
1275
|
+
cardNumber: d,
|
|
1276
|
+
securityCode: s,
|
|
1277
|
+
identificationType: this.input.customer.documentType === q.Cpf ? "CPF" : "CNPJ",
|
|
1278
|
+
identificationNumber: this.input.customer.documentNumber
|
|
1279
|
+
}).catch((w) => {
|
|
1280
|
+
throw new Error(this.describeMercadoPagoError(w));
|
|
1281
|
+
});
|
|
1282
|
+
if ("id" in c && c.id) return c.id;
|
|
1283
|
+
throw new Error(this.describeMercadoPagoError(c));
|
|
1284
|
+
}
|
|
1285
|
+
describeMercadoPagoError(t) {
|
|
1286
|
+
if (typeof t == "string") return t;
|
|
1287
|
+
if (Array.isArray(t)) return t.map((n) => this.describeMercadoPagoError(n)).join("; ");
|
|
1288
|
+
if (typeof t == "object" && t !== null) {
|
|
1289
|
+
if ("cause" in t && Array.isArray(t.cause) && t.cause.length > 0)
|
|
1290
|
+
return this.describeMercadoPagoError(t.cause);
|
|
1291
|
+
if ("message" in t && typeof t.message == "string") return t.message;
|
|
1292
|
+
if ("description" in t && typeof t.description == "string") return t.description;
|
|
1293
|
+
}
|
|
1294
|
+
return "Failed to tokenize card";
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
const Xe = {
|
|
1298
|
+
[v.MercadoPago]: Je
|
|
1299
|
+
};
|
|
1300
|
+
class Ze {
|
|
1301
|
+
constructor(a) {
|
|
1302
|
+
b(this, "api");
|
|
1303
|
+
this.publicKey = a, this.api = new qe(this.publicKey);
|
|
1304
|
+
}
|
|
1305
|
+
async tokenizeCard(a) {
|
|
1306
|
+
this.validateCard(a);
|
|
1307
|
+
const {
|
|
1308
|
+
customerId: t,
|
|
1309
|
+
token: n
|
|
1310
|
+
} = await this.api.createToken({
|
|
1311
|
+
card: a.card,
|
|
1312
|
+
customer: a.customer,
|
|
1313
|
+
saveCard: !1
|
|
1314
|
+
}), {
|
|
1315
|
+
settings: i
|
|
1316
|
+
} = await this.api.getSettings(), s = (await Promise.all(i.map(async (d) => {
|
|
1317
|
+
const o = Xe[d.key];
|
|
1318
|
+
if (!o) return null;
|
|
1319
|
+
const c = new o({
|
|
1320
|
+
...a,
|
|
1321
|
+
setting: d.settings
|
|
1322
|
+
});
|
|
1323
|
+
return await L(c.scriptUrl), {
|
|
1324
|
+
token: await c.tokenize(),
|
|
1325
|
+
integrationId: d.integrationId,
|
|
1326
|
+
providerKey: d.key
|
|
1327
|
+
};
|
|
1328
|
+
}))).filter((d) => d !== null);
|
|
1329
|
+
return s.length > 0 && await this.api.saveTokens(s, t, n), n;
|
|
1330
|
+
}
|
|
1331
|
+
validateCard(a) {
|
|
1332
|
+
const {
|
|
1333
|
+
number: t,
|
|
1334
|
+
cvv: n,
|
|
1335
|
+
expiration: i,
|
|
1336
|
+
holderName: r
|
|
1337
|
+
} = a.card;
|
|
1338
|
+
if (!t || !n || !(i != null && i.month) || !(i != null && i.year) || !r)
|
|
1339
|
+
throw new Error("Invalid card data");
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
function ut(e) {
|
|
1343
|
+
const a = new Ze(e.publicKey);
|
|
1344
|
+
return {
|
|
1345
|
+
tokenizeCard: async (n) => {
|
|
1346
|
+
var i, r;
|
|
1347
|
+
try {
|
|
1348
|
+
const s = await a.tokenizeCard(n);
|
|
1349
|
+
return (i = e.onSuccess) == null || i.call(e, s), s;
|
|
1350
|
+
} catch (s) {
|
|
1351
|
+
const d = s instanceof Error ? s : new Error("Tokenization failed");
|
|
1352
|
+
return (r = e.onError) == null || r.call(e, d), null;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
export {
|
|
1358
|
+
ge as ALLOWED_ORIGINS,
|
|
1359
|
+
ue as CardBrand,
|
|
1360
|
+
de as ChargeStatusDetail,
|
|
1361
|
+
he as CurrencyType,
|
|
1362
|
+
me as DeviceType,
|
|
1363
|
+
q as DocumentType,
|
|
1364
|
+
it as ERROR_CODES,
|
|
1365
|
+
ye as ErrorCode,
|
|
1366
|
+
Ee as IFRAME_BASE_URL,
|
|
1367
|
+
j as IFRAME_DEFAULT_HEIGHT_VALUE,
|
|
1368
|
+
T as IncomingMessage,
|
|
1369
|
+
fe as InputStyleKey,
|
|
1370
|
+
v as IntegrationProvider,
|
|
1371
|
+
R as OrganizationEnvironment,
|
|
1372
|
+
M as OutgoingMessage,
|
|
1373
|
+
p as POST_MESSAGES,
|
|
1374
|
+
rt as PayConductor,
|
|
1375
|
+
Ge as PayConductor3DSSDK,
|
|
1376
|
+
ot as PayConductorCheckoutElement,
|
|
1377
|
+
st as PayConductorThreeDSElement,
|
|
1378
|
+
Ze as PayConductorTokenizerSDK,
|
|
1379
|
+
re as PaymentMethod,
|
|
1380
|
+
oe as PaymentMethodLayout,
|
|
1381
|
+
se as PaymentStatus,
|
|
1382
|
+
we as REQUEST_TIMEOUT,
|
|
1383
|
+
_ as SDK_API_BASE_URL,
|
|
1384
|
+
pe as SKELETON_CSS,
|
|
1385
|
+
H as SKELETON_STYLE_ID,
|
|
1386
|
+
le as ThreeDSResultStatus,
|
|
1387
|
+
D as ThreeDSTransStatus,
|
|
1388
|
+
P as ThreeDSecureResultStatus,
|
|
1389
|
+
ce as ThreeDsAuthenticationStatus,
|
|
1390
|
+
be as buildIframeUrl,
|
|
1391
|
+
rt as default,
|
|
1392
|
+
at as defaultTheme,
|
|
1393
|
+
Pe as generateRequestId,
|
|
1394
|
+
Ce as isValidOrigin,
|
|
1395
|
+
L as loadScript,
|
|
1396
|
+
dt as usePayConductor,
|
|
1397
|
+
ct as usePayconductorElement,
|
|
1398
|
+
lt as useThreeDS,
|
|
1399
|
+
ut as useTokenizer
|
|
1400
|
+
};
|
|
1401
|
+
//# sourceMappingURL=index.es.js.map
|