@payconductor/react 1.1.1 → 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.
Files changed (40) hide show
  1. package/dist/esm/three-ds.d.ts +1 -1
  2. package/dist/esm/tokenizer.d.ts +1 -1
  3. package/dist/index.cjs.js +49 -49
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.d.ts +12 -12
  6. package/dist/index.es.js +1401 -1318
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/payconductor/constants.d.ts +32 -31
  9. package/dist/payconductor/hooks/index.d.ts +7 -7
  10. package/dist/payconductor/hooks/use-element.d.ts +30 -30
  11. package/dist/payconductor/hooks/use-payconductor.d.ts +6 -6
  12. package/dist/payconductor/hooks/use-three-ds.d.ts +13 -13
  13. package/dist/payconductor/hooks/use-tokenizer.d.ts +11 -11
  14. package/dist/payconductor/iframe/constants.d.ts +7 -8
  15. package/dist/payconductor/iframe/types.d.ts +464 -464
  16. package/dist/payconductor/internal.d.ts +11 -11
  17. package/dist/payconductor/loader.d.ts +1 -1
  18. package/dist/payconductor/payconductor-element.d.ts +5 -5
  19. package/dist/payconductor/payconductor-three-ds.d.ts +5 -5
  20. package/dist/payconductor/payconductor.d.ts +17 -17
  21. package/dist/payconductor/three-ds/api.d.ts +14 -12
  22. package/dist/payconductor/three-ds/browser.d.ts +13 -13
  23. package/dist/payconductor/three-ds/handler.d.ts +12 -11
  24. package/dist/payconductor/three-ds/index.d.ts +3 -3
  25. package/dist/payconductor/three-ds/providers/index.d.ts +6 -6
  26. package/dist/payconductor/three-ds/providers/mercado-pago.d.ts +9 -9
  27. package/dist/payconductor/three-ds/providers/pagarme.d.ts +9 -9
  28. package/dist/payconductor/three-ds/providers/pagseguro.d.ts +7 -7
  29. package/dist/payconductor/three-ds/providers/payconductor.d.ts +7 -7
  30. package/dist/payconductor/three-ds/providers/sandbox.d.ts +9 -0
  31. package/dist/payconductor/three-ds/types.d.ts +100 -93
  32. package/dist/payconductor/tokenizer/api.d.ts +25 -26
  33. package/dist/payconductor/tokenizer/handler.d.ts +9 -9
  34. package/dist/payconductor/tokenizer/index.d.ts +1 -1
  35. package/dist/payconductor/tokenizer/providers/index.d.ts +6 -6
  36. package/dist/payconductor/tokenizer/providers/mercado-pago.d.ts +7 -6
  37. package/dist/payconductor/tokenizer/types.d.ts +50 -50
  38. package/dist/payconductor/types.d.ts +42 -42
  39. package/dist/payconductor/utils.d.ts +6 -6
  40. package/package.json +1 -1
package/dist/index.es.js CHANGED
@@ -1,1318 +1,1401 @@
1
- var q = Object.defineProperty;
2
- var $ = (e, n, t) => n in e ? q(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var S = (e, n, t) => $(e, typeof n != "symbol" ? n + "" : n, t);
4
- import { jsx as D, jsxs as W } from "react/jsx-runtime";
5
- import { useState as I, useEffect as K, useRef as J } from "react";
6
- const Y = "https://iframe.payconductor.ai/v1", j = "http://localhost:5175/v1", X = 3e5, Z = "600px";
7
- var Q = /* @__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))(Q || {}), ee = /* @__PURE__ */ ((e) => (e.Grid = "grid", e.Vertical = "vertical", e.Horizontal = "horizontal", e))(ee || {}), te = /* @__PURE__ */ ((e) => (e.Succeeded = "succeeded", e.Pending = "pending", e.Failed = "failed", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.ThreeDsAwaitingChallenge = "ThreeDsAwaitingChallenge", e))(ne || {}), ae = /* @__PURE__ */ ((e) => (e.Authenticated = "Authenticated", e.NotAuthenticated = "NotAuthenticated", e.NeedChallenge = "NeedChallenge", e))(ae || {}), ie = /* @__PURE__ */ ((e) => (e.Pending = "Pending", e.Authenticated = "Authenticated", e.Failed = "Failed", e.NotEnrolled = "NotEnrolled", e))(ie || {}), G = /* @__PURE__ */ ((e) => (e.Cpf = "Cpf", e.Cnpj = "Cnpj", e))(G || {}), M = /* @__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))(M || {}), re = /* @__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))(re || {}), N = /* @__PURE__ */ ((e) => (e.Production = "Production", e.Sandbox = "Sandbox", e))(N || {}), oe = /* @__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))(oe || {}), se = /* @__PURE__ */ ((e) => (e.Android = "android", e.IOS = "ios", e.Web = "web", e.Chrome = "chrome", e.Safari = "safari", e))(se || {}), de = /* @__PURE__ */ ((e) => (e.Padding = "padding", e.Radius = "radius", e.Color = "color", e.Background = "background", e.Shadow = "shadow", e))(de || {}), T = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(T || {}), A = /* @__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))(A || {}), ce = /* @__PURE__ */ ((e) => (e.InvalidClient = "InvalidClient", e.InvalidToken = "InvalidToken", e.NetworkError = "NetworkError", e.IframeNotReady = "IframeNotReady", e.PaymentDeclined = "PaymentDeclined", e.ValidationError = "ValidationError", e.Timeout = "Timeout", e))(ce || {});
8
- const Xe = {
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
- }, le = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") && !window.location.search.includes("production"), ue = le ? j : Y, me = [j, Y], z = Z, he = X, P = {
56
- INIT: T.Init,
57
- CONFIG: T.Config,
58
- UPDATE: T.Update,
59
- CONFIRM_PAYMENT: T.ConfirmPayment,
60
- VALIDATE: T.Validate,
61
- RESET: T.Reset,
62
- READY: A.Ready,
63
- ERROR: A.Error,
64
- PAYMENT_COMPLETE: A.PaymentComplete,
65
- PAYMENT_FAILED: A.PaymentFailed,
66
- PAYMENT_PENDING: A.PaymentPending,
67
- VALIDATION_ERROR: A.ValidationError,
68
- PAYMENT_METHOD_SELECTED: A.PaymentMethodSelected,
69
- RESIZE: A.Resize
70
- }, Ze = {
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", fe = `
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 ye(e) {
92
- const n = new URLSearchParams({
93
- publicKey: e.publicKey
94
- });
95
- return `${ue}?${n.toString()}`;
96
- }
97
- function we() {
98
- return crypto.randomUUID();
99
- }
100
- function Ee(e, n) {
101
- return n.some((t) => {
102
- try {
103
- return new URL(t).origin === e;
104
- } catch {
105
- return t === e;
106
- }
107
- });
108
- }
109
- function F() {
110
- return /* @__PURE__ */ new Map();
111
- }
112
- function _(e, n, t, a) {
113
- return new Promise((i, o) => {
114
- if (!e || !("contentWindow" in e)) {
115
- o(new Error("Iframe not defined"));
116
- return;
117
- }
118
- if (!(e != null && e.contentWindow)) {
119
- o(new Error("Iframe not ready"));
120
- return;
121
- }
122
- if (!n) {
123
- o(new Error("Pending requests not initialized"));
124
- return;
125
- }
126
- const d = we();
127
- n.set(d, {
128
- resolve: i,
129
- reject: o
130
- }), e.contentWindow.postMessage({
131
- type: t,
132
- data: a,
133
- requestId: d
134
- }, "*"), setTimeout(() => {
135
- n != null && n.has(d) && (n.delete(d), o(new Error("Request timeout")));
136
- }, he);
137
- });
138
- }
139
- function ge(e, n, t) {
140
- return _(e, n, P.CONFIRM_PAYMENT, t);
141
- }
142
- async function Pe(e, n, t) {
143
- return await ge(e, n, {
144
- orderId: t.orderId
145
- });
146
- }
147
- function Ce(e, n, t) {
148
- return _(e, n, P.VALIDATE, t);
149
- }
150
- function be(e, n) {
151
- return _(e, n, P.RESET);
152
- }
153
- function pe(e, n, t) {
154
- return _(e, n, P.CONFIG, t);
155
- }
156
- function Se(e, n, t) {
157
- return _(e, n, P.INIT, t);
158
- }
159
- function ve(e, n, t, a, i, o, d, s, r, c, g, w) {
160
- const h = e.data, {
161
- requestId: f,
162
- type: u,
163
- data: E,
164
- error: p
165
- } = h;
166
- if (u === P.READY) {
167
- if (a == null || a(), f && (n != null && n.has(f))) {
168
- const {
169
- resolve: v
170
- } = n.get(f);
171
- n.delete(f), v(E);
172
- }
173
- return;
174
- }
175
- if (Ee(e.origin, me)) {
176
- if (f && n && n.has(f)) {
177
- const {
178
- resolve: v,
179
- reject: U
180
- } = n.get(f);
181
- n.delete(f), p ? U(new Error(String(p.message))) : v(E);
182
- return;
183
- }
184
- if (u === P.ERROR) {
185
- t((p == null ? void 0 : p.message) || "Unknown error"), i == null || i(new Error(String(p == null ? void 0 : p.message)));
186
- return;
187
- }
188
- if (u === P.PAYMENT_COMPLETE) {
189
- E && typeof E == "object" && "status" in E && (o == null || o(E));
190
- return;
191
- }
192
- if (u === P.PAYMENT_FAILED) {
193
- E && typeof E == "object" && "status" in E && (d == null || d(E));
194
- return;
195
- }
196
- if (u === P.PAYMENT_PENDING) {
197
- E && typeof E == "object" && "status" in E && (s == null || s(E));
198
- return;
199
- }
200
- if (u === P.PAYMENT_METHOD_SELECTED) {
201
- E && typeof E == "object" && "paymentMethod" in E && (r == null || r(E.paymentMethod));
202
- return;
203
- }
204
- if (u !== P.RESIZE) {
205
- if (u === A.ThreeDSChallenge) {
206
- c == null || c();
207
- return;
208
- }
209
- if (u === A.ThreeDSComplete) {
210
- g == null || g();
211
- return;
212
- }
213
- if (u === A.ThreeDSFailed) {
214
- w == null || w();
215
- return;
216
- }
217
- }
218
- }
219
- }
220
- function Qe(e) {
221
- const [n, t] = I(
222
- () => !1
223
- ), [a, i] = I(() => null), [o, d] = I(
224
- () => ""
225
- ), [s, r] = I(() => null);
226
- return K(() => {
227
- const c = (...m) => {
228
- e.debug && console.log("[PayConductor]", ...m);
229
- }, g = ye({
230
- publicKey: e.publicKey
231
- });
232
- d(g), t(!0);
233
- const w = F();
234
- let h = !1;
235
- c("init", e.publicKey), c("iframeUrl", g);
236
- const f = () => {
237
- var C, l;
238
- const m = (l = (C = window.PayConductor) == null ? void 0 : C.frame) == null ? void 0 : l.iframe;
239
- if (m) {
240
- if (m instanceof HTMLIFrameElement) return m;
241
- if (typeof m == "object" && m !== null) {
242
- const y = m;
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 m;
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(m) {
260
- },
261
- iframeUrl: g,
262
- error: null
263
- }, E = {
264
- publicKey: e.publicKey,
265
- theme: e.theme,
266
- locale: e.locale,
267
- paymentMethods: e.paymentMethods,
268
- defaultPaymentMethod: e.defaultPaymentMethod
269
- }, p = {
270
- confirmPayment: (m) => {
271
- var l;
272
- c("→ CONFIRM_PAYMENT", {
273
- orderId: m.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: m.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
- ), E.orderId = m.orderId, (l = window.PayConductor) != null && l.config && (window.PayConductor.config.orderId = m.orderId), Pe(C, w, m);
292
- },
293
- validate: (m) => (c("→ VALIDATE", m), Ce(f(), w, m)),
294
- reset: () => (c("→ RESET"), be(f(), w)),
295
- getSelectedPaymentMethod: () => s
296
- };
297
- window.PayConductor = {
298
- frame: u,
299
- config: E,
300
- api: p,
301
- selectedPaymentMethod: s
302
- }, c("registered"), window.dispatchEvent(
303
- new CustomEvent("payconductor:registered", {
304
- detail: window.PayConductor
305
- })
306
- );
307
- const v = async () => {
308
- if (!h) {
309
- const m = f();
310
- if (!m) {
311
- c("→ CONFIG skipped: iframe not found");
312
- return;
313
- }
314
- h = !0, c("→ CONFIG", {
315
- theme: e.theme,
316
- locale: e.locale,
317
- paymentMethods: e.paymentMethods,
318
- defaultPaymentMethod: e.defaultPaymentMethod,
319
- showPaymentButtons: e.showPaymentButtons
320
- }), pe(m, w, {
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
- }, U = (m) => {
330
- var C;
331
- (C = m.data) != null && C.type && c("←", m.data.type, m.data.data ?? ""), ve(
332
- m,
333
- w,
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), v();
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
- r(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", U);
377
- const V = () => {
378
- var C, l, y;
379
- const m = f();
380
- if (!m) return !1;
381
- try {
382
- if ((((C = m.contentDocument) == null ? void 0 : C.readyState) ?? ((y = (l = m.contentWindow) == null ? void 0 : l.document) == null ? void 0 : y.readyState)) === "complete")
383
- return v(), !0;
384
- } catch {
385
- }
386
- return !1;
387
- }, B = () => {
388
- if (V()) return;
389
- const m = f();
390
- if (m) {
391
- m.addEventListener("load", () => v(), {
392
- once: !0
393
- });
394
- return;
395
- }
396
- setTimeout(B, 50);
397
- };
398
- B();
399
- }, []), /* @__PURE__ */ D(
400
- "div",
401
- {
402
- className: "payconductor",
403
- id: "payconductor",
404
- style: {
405
- display: "contents"
406
- },
407
- children: e.children
408
- }
409
- );
410
- }
411
- function et(e) {
412
- const n = J(null), [t, a] = I(() => ""), [i, o] = I(() => !1), [d, s] = I(() => "");
413
- return K(() => {
414
- if (typeof document < "u" && !document.getElementById(H)) {
415
- const h = document.createElement("style");
416
- h.id = H, h.textContent = fe, document.head.appendChild(h);
417
- }
418
- const r = (h) => {
419
- h != null && h.frame && (a(h.frame.iframeUrl || ""), o(!0), console.log("init", {
420
- PayConductor: window.PayConductor
421
- }));
422
- }, c = typeof window < "u" ? window.PayConductor : null;
423
- if (c)
424
- r(c);
425
- else {
426
- const h = (f) => {
427
- r(f.detail), window.removeEventListener("payconductor:registered", h);
428
- };
429
- window.addEventListener("payconductor:registered", h);
430
- }
431
- let g = !1;
432
- const w = (h) => {
433
- var f, u, E, p;
434
- if (((f = h.data) == null ? void 0 : f.type) === P.RESIZE && ((E = (u = h.data) == null ? void 0 : u.data) != null && E.height) && s(h.data.data.height + "px"), ((p = h.data) == null ? void 0 : p.type) === P.READY && e.height && !g) {
435
- g = !0;
436
- const v = document.querySelector(
437
- ".payconductor-element iframe"
438
- );
439
- v != null && v.contentWindow && v.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", w), () => window.removeEventListener("message", w);
452
- }, []), /* @__PURE__ */ W(
453
- "div",
454
- {
455
- className: "payconductor-element",
456
- style: {
457
- width: "100%"
458
- },
459
- children: [
460
- i ? null : /* @__PURE__ */ D(
461
- "div",
462
- {
463
- className: "payconductor-skeleton",
464
- style: {
465
- height: e.height || z
466
- }
467
- }
468
- ),
469
- i && t ? /* @__PURE__ */ D(
470
- "iframe",
471
- {
472
- allow: "payment",
473
- title: "PayConductor",
474
- ref: n,
475
- src: t,
476
- style: {
477
- width: "100%",
478
- height: e.height || d || z,
479
- border: "none"
480
- }
481
- }
482
- ) : null
483
- ]
484
- }
485
- );
486
- }
487
- function tt(e) {
488
- const [n, t] = I(() => !1);
489
- return K(() => {
490
- const a = () => {
491
- t(!0);
492
- }, i = () => {
493
- t(!1);
494
- };
495
- return window.addEventListener("payconductor:3ds:show", a), window.addEventListener("payconductor:3ds:hide", i), typeof window < "u" && (window.PayConductor3DS = {
496
- container: () => document.getElementById("payconductor-3ds-container"),
497
- show: a,
498
- hide: i
499
- }, window.dispatchEvent(new CustomEvent("payconductor:3ds:registered"))), () => {
500
- window.removeEventListener("payconductor:3ds:show", a), window.removeEventListener("payconductor:3ds:hide", i), window.PayConductor3DS = null;
501
- };
502
- }, []), /* @__PURE__ */ D(
503
- "div",
504
- {
505
- className: "payconductor-three-ds",
506
- id: "payconductor-3ds-container",
507
- style: {
508
- width: "100%",
509
- display: n ? "block" : "none",
510
- minHeight: n ? e.height || "600px" : "0"
511
- }
512
- }
513
- );
514
- }
515
- function nt() {
516
- const e = typeof window < "u" ? window.PayConductor : null, n = 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
- ...n,
530
- ...t
531
- };
532
- }
533
- function L(e) {
534
- var n;
535
- if ((n = e == null ? void 0 : e.frame) != null && n.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 a = t.current;
541
- if (a instanceof HTMLIFrameElement) return a;
542
- }
543
- if ("value" in t) {
544
- const a = t.value;
545
- if (a instanceof HTMLIFrameElement) return a;
546
- }
547
- }
548
- }
549
- return document.querySelector(".payconductor-element iframe") ?? null;
550
- }
551
- function at() {
552
- const e = () => typeof window < "u" ? window.PayConductor : null, n = (t, a) => {
553
- const i = e();
554
- if (!i) return;
555
- const o = L(i);
556
- o != null && o.contentWindow && o.contentWindow.postMessage({
557
- type: t,
558
- data: a
559
- }, "*");
560
- };
561
- return {
562
- init: async (t) => {
563
- const a = L(e()), i = F();
564
- return Se(a || void 0, i, t);
565
- },
566
- confirmPayment: async (t) => {
567
- if (!t.orderId)
568
- throw new Error("Order ID is required");
569
- const a = e();
570
- if (!(a != null && a.api)) throw new Error("PayConductor not initialized");
571
- return a.api.confirmPayment(t);
572
- },
573
- validate: (t) => {
574
- const a = e();
575
- return a ? a.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 a = (i = e()) == null ? void 0 : i.config;
588
- n(P.CONFIG, {
589
- publicKey: a == null ? void 0 : a.publicKey,
590
- orderId: a == null ? void 0 : a.orderId,
591
- theme: t.theme ?? (a == null ? void 0 : a.theme),
592
- locale: t.locale ?? (a == null ? void 0 : a.locale),
593
- paymentMethods: t.paymentMethods ?? (a == null ? void 0 : a.paymentMethods)
594
- });
595
- },
596
- updateOrderId: (t) => {
597
- var i;
598
- const a = (i = e()) == null ? void 0 : i.config;
599
- n(P.CONFIG, {
600
- publicKey: a == null ? void 0 : a.publicKey,
601
- orderId: t,
602
- theme: a == null ? void 0 : a.theme,
603
- locale: a == null ? void 0 : a.locale,
604
- paymentMethods: a == null ? void 0 : a.paymentMethods
605
- });
606
- },
607
- update: (t) => {
608
- n(P.UPDATE, t);
609
- },
610
- submit: async () => {
611
- const t = L(e()), a = F();
612
- try {
613
- return await _(t || void 0, a, 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 b = /* @__PURE__ */ ((e) => (e.Success = "Success", e.Failed = "Failed", e.Timeout = "Timeout", e))(b || {}), R = /* @__PURE__ */ ((e) => (e.Authenticated = "Y", e.Attempted = "A", e.ChallengeRequired = "C", e.NotAuthenticated = "N", e.Unavailable = "U", e.Rejected = "R", e.InformationOnly = "I", e))(R || {});
629
- class k {
630
- constructor(n, t) {
631
- S(this, "overlay", null);
632
- S(this, "modalContent", null);
633
- this.data = n, 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(n, t = {}) {
640
- var i, o;
641
- const a = new Error(n);
642
- return (o = (i = this.options).onError) == null || o.call(i, a), {
643
- ...t,
644
- status: "Failed",
645
- error: a
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 n = document.createElement("style");
661
- n.id = "payconductor-3ds-styles", n.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(n);
697
- }
698
- //#endregion
699
- }
700
- const Ae = 5 * 60 * 1e3;
701
- class Ie extends k {
702
- constructor() {
703
- super(...arguments);
704
- S(this, "iframe", null);
705
- S(this, "messageListener", null);
706
- S(this, "timeoutId", null);
707
- }
708
- async authenticate() {
709
- const {
710
- threeDsUrl: t,
711
- creq: a
712
- } = this.data;
713
- if (!t || !a)
714
- return this.fail("Missing threeDsUrl or creq");
715
- const i = this.resolveContainer();
716
- return new Promise((o) => {
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 = (g) => {
719
- var w, h, f;
720
- ((w = g.data) == null ? void 0 : w.status) === "COMPLETE" && (this.cleanup(), (f = (h = this.options).onComplete) == null || f.call(h), o({
721
- status: b.Success
722
- }));
723
- }, window.addEventListener("message", this.messageListener), this.timeoutId = setTimeout(() => {
724
- var g, w;
725
- this.cleanup(), (w = (g = this.options).onTimeout) == null || w.call(g), o({
726
- status: b.Timeout
727
- });
728
- }, this.options.timeoutMs ?? Ae);
729
- const d = (c = this.iframe.contentWindow) == null ? void 0 : c.document;
730
- if (!d) {
731
- this.cleanup(), o(this.fail("Cannot access iframe document"));
732
- return;
733
- }
734
- const s = d.createElement("form");
735
- s.name = "threeDsChallengeForm", s.setAttribute("target", "payconductor-3ds-challenge"), s.setAttribute("method", "post"), s.setAttribute("action", t);
736
- const r = d.createElement("input");
737
- r.setAttribute("type", "hidden"), r.setAttribute("name", "creq"), r.setAttribute("value", a), s.appendChild(r), this.iframe.appendChild(s), s.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 O = /* @__PURE__ */ new Map();
745
- function x(e) {
746
- const n = O.get(e);
747
- if (n) return n;
748
- const t = new Promise((a, i) => {
749
- if (document.querySelector(`script[src="${e}"]`)) {
750
- a();
751
- return;
752
- }
753
- const o = document.createElement("script");
754
- o.src = e, o.async = !0, o.onload = () => a(), o.onerror = () => {
755
- O.delete(e), i(new Error(`Failed to load script: ${e}`));
756
- }, (document.head || document.body).appendChild(o);
757
- });
758
- return O.set(e, t), t;
759
- }
760
- const Te = "https://static.payzen.lat/static/js/authenticate-client/V1.0/kr-authenticate.umd.js", Me = 10 * 60 * 1e3;
761
- class _e extends k {
762
- constructor() {
763
- super(...arguments);
764
- S(this, "timeoutId", null);
765
- }
766
- async authenticate() {
767
- const {
768
- operationUrl: t,
769
- publicKey: a
770
- } = this.data;
771
- if (!t || !a)
772
- return this.fail("Missing operationUrl or publicKey");
773
- try {
774
- await x(Te);
775
- } catch {
776
- return this.fail("Failed to load 3DS SDK");
777
- }
778
- const i = window.KrAuthenticate;
779
- return i ? new Promise((o) => {
780
- this.timeoutId = setTimeout(() => {
781
- var s, r;
782
- this.cleanup(), (r = (s = this.options).onTimeout) == null || r.call(s), o({
783
- status: b.Timeout
784
- });
785
- }, this.options.timeoutMs ?? Me), new i(a).authenticate(t, () => {
786
- var s, r;
787
- this.cleanup(), (r = (s = this.options).onComplete) == null || r.call(s), o({
788
- status: b.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 Ne = {
798
- [N.Production]: "https://3ds-nx-js.stone.com.br/live/v2/3ds2.min.js",
799
- [N.Sandbox]: "https://3ds-nx-js.stone.com.br/test/v2/3ds2.min.js"
800
- }, Re = 5 * 60 * 1e3;
801
- function De() {
802
- const e = window.innerWidth;
803
- return e <= 480 ? "01" : e <= 768 ? "02" : e <= 1024 ? "03" : "04";
804
- }
805
- class ke extends k {
806
- constructor() {
807
- super(...arguments);
808
- S(this, "timeoutId", null);
809
- S(this, "methodContainer", null);
810
- }
811
- async authenticate() {
812
- const {
813
- authToken: t,
814
- card: a
815
- } = this.data;
816
- if (!t) return this.fail("Missing authToken for PagarMe 3DS");
817
- if (!a) return this.fail("Missing card data for PagarMe 3DS");
818
- const i = this.data.environment ?? N.Production;
819
- try {
820
- await x(Ne[i]);
821
- } catch {
822
- return this.fail("Failed to load Stone 3DS SDK");
823
- }
824
- const o = window.TDS;
825
- if (!o) return this.fail("Stone TDS SDK not available");
826
- const d = this.resolveContainer();
827
- return this.methodContainer = document.createElement("div"), this.methodContainer.style.display = "none", document.body.appendChild(this.methodContainer), new Promise((s) => {
828
- this.timeoutId = setTimeout(() => {
829
- var r, c;
830
- this.cleanup(), (c = (r = this.options).onTimeout) == null || c.call(r), s({
831
- status: b.Timeout
832
- });
833
- }, this.options.timeoutMs ?? Re), o.init({
834
- token: t,
835
- tds_method_container_element: this.methodContainer,
836
- challenge_container_element: d,
837
- use_default_challenge_iframe_style: !0,
838
- challenge_window_size: De()
839
- }, this.buildOrderData()).then((r) => {
840
- var h, f;
841
- if (this.cleanup(), !(r != null && r.length)) {
842
- s(this.fail("PagarMe 3DS returned no response"));
843
- return;
844
- }
845
- const c = r[0], g = Object.values(R).find((u) => u === c.trans_status), w = {
846
- transStatus: g,
847
- providerTransactionId: c.tds_server_trans_id,
848
- challengeCanceled: c.challenge_canceled
849
- };
850
- if (c.challenge_canceled) {
851
- s(this.fail("3DS challenge canceled by user", w));
852
- return;
853
- }
854
- g === R.Authenticated || g === R.Attempted ? ((f = (h = this.options).onComplete) == null || f.call(h), s({
855
- ...w,
856
- status: b.Success,
857
- dsTransactionId: c.tds_server_trans_id
858
- })) : s(this.fail(`3DS failed with status: ${c.trans_status}`, w));
859
- }).catch((r) => {
860
- this.cleanup(), s(this.fail(r instanceof Error ? r.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 o;
869
- const {
870
- card: t,
871
- customer: a,
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
- ...a ? {
896
- customer: {
897
- name: a.name,
898
- email: a.email,
899
- ...a.document ? {
900
- document: a.document
901
- } : {},
902
- ...(o = a.phones) != null && o.length ? {
903
- phones: Object.fromEntries(a.phones.map((d) => [d.type === "HOME" ? "home_phone" : "mobile_phone", {
904
- country_code: d.countryCode,
905
- area_code: d.areaCode,
906
- number: d.number
907
- }]))
908
- } : {}
909
- }
910
- } : {}
911
- };
912
- }
913
- }
914
- const xe = "https://assets.pagseguro.com.br/checkout-sdk-js/rc/dist/browser/pagseguro.min.js";
915
- class Ue extends k {
916
- async authenticate() {
917
- var w, h, f;
918
- const {
919
- authToken: n,
920
- card: t,
921
- customer: a,
922
- currency: i,
923
- billingAddress: o
924
- } = this.data, d = this.amountInCents;
925
- if (!n) return this.fail("Missing authToken (session) for PagSeguro 3DS");
926
- if (!t) return this.fail("Missing card data for PagSeguro 3DS");
927
- if (!a) return this.fail("Missing customer data for PagSeguro 3DS");
928
- if (!d) return this.fail("Missing amount for PagSeguro 3DS");
929
- if (!o) return this.fail("Missing billingAddress for PagSeguro 3DS");
930
- const s = this.data.environment === N.Sandbox ? "SANDBOX" : "PROD";
931
- try {
932
- await x(xe);
933
- } catch {
934
- return this.fail("Failed to load PagSeguro SDK");
935
- }
936
- const r = window.PagSeguro;
937
- if (!r) return this.fail("PagSeguro SDK not available");
938
- r.setUp({
939
- session: n,
940
- env: s
941
- });
942
- const c = ((w = a.phones) == null ? void 0 : w.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 r.authenticate3DS({
956
- data: {
957
- customer: {
958
- name: a.name,
959
- email: a.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: d,
976
- currency: i ?? "BRL"
977
- },
978
- billingAddress: {
979
- street: o.street,
980
- number: o.number,
981
- complement: o.complement,
982
- regionCode: o.state,
983
- country: o.country.length === 2 ? this.toAlpha3(o.country) : o.country,
984
- city: o.city,
985
- postalCode: o.zipCode.replace(/\D/g, "")
986
- },
987
- dataOnly: !1
988
- }
989
- });
990
- return u.status === "AUTH_FLOW_COMPLETED" || u.status === "AUTH_NOT_SUPPORTED" ? ((f = (h = this.options).onComplete) == null || f.call(h), {
991
- status: b.Success,
992
- dsTransactionId: u.id
993
- }) : u.status === "CHANGE_PAYMENT_METHOD" ? this.fail("PagSeguro requires a different payment method") : {
994
- status: b.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(n) {
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
- }[n.toUpperCase()] ?? n;
1014
- }
1015
- }
1016
- const Le = {
1017
- // Agnostic providers
1018
- [M.Lyra]: _e,
1019
- // Acquirer-specific providers
1020
- [M.MercadoPago]: Ie,
1021
- [M.PagarMe]: ke,
1022
- [M.PagSeguro]: Ue
1023
- };
1024
- class Oe extends Error {
1025
- constructor(n, t) {
1026
- super(n), this.title = t, this.name = "PayConductorThreeDSApiError";
1027
- }
1028
- }
1029
- class Fe {
1030
- constructor(n) {
1031
- this.publicKey = n;
1032
- }
1033
- async completeManualChallenge(n, t) {
1034
- const a = await fetch(`${this.baseUrl}/three-ds/complete/${n}`, {
1035
- method: "POST",
1036
- headers: this.headers,
1037
- body: JSON.stringify({
1038
- providerTransactionId: t
1039
- })
1040
- });
1041
- a.ok || await this.parseResponseError("Failed to complete native 3DS challenge", a);
1042
- }
1043
- async parseResponseError(n, t) {
1044
- var i, o, d, s;
1045
- let a = "";
1046
- try {
1047
- const r = await t.json();
1048
- r != null && r.message ? a = r.message : (i = r == null ? void 0 : r.error) != null && i.message ? a = r.error : (d = (o = r == null ? void 0 : r.error) == null ? void 0 : o.value) != null && d.message ? a = r.error.value.message : (s = r == null ? void 0 : r.value) != null && s.message ? a = r.value.message : a = JSON.stringify(r);
1049
- } catch {
1050
- }
1051
- throw new Oe(a, n);
1052
- }
1053
- get baseUrl() {
1054
- return typeof window < "u" && window.location.href.includes("localhost") ? "http://localhost:3000/api/v1/sdk" : "https://payconductor.ai/api/v1/sdk";
1055
- }
1056
- get headers() {
1057
- return {
1058
- Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
1059
- "Content-Type": "application/json"
1060
- };
1061
- }
1062
- }
1063
- const Ke = [M.PagSeguro];
1064
- class Be {
1065
- constructor(n) {
1066
- S(this, "data");
1067
- S(this, "provider", null);
1068
- this.data = n;
1069
- }
1070
- get needsChallenge() {
1071
- return this.data.status === "NeedChallenge" || this.data.statusDetail === "ThreeDsAwaitingChallenge";
1072
- }
1073
- get acquirer() {
1074
- return this.data.acquirer;
1075
- }
1076
- async authenticate(n) {
1077
- if (!this.needsChallenge)
1078
- return {
1079
- status: b.Success
1080
- };
1081
- const {
1082
- acquirer: t
1083
- } = this.data;
1084
- if (!t)
1085
- return {
1086
- status: b.Failed,
1087
- error: new Error("Missing 3DS acquirer")
1088
- };
1089
- const a = Le[t];
1090
- if (!a)
1091
- return {
1092
- status: b.Failed,
1093
- error: new Error(`Unsupported 3DS provider: ${t}`)
1094
- };
1095
- const i = {
1096
- ...n,
1097
- threeDSecure: this.data
1098
- };
1099
- this.provider = new a(this.data, i);
1100
- const o = await this.provider.authenticate();
1101
- return o.status === b.Success && o.dsTransactionId && Ke.includes(t) && this.data.orderId && this.data.publicKey && await new Fe(this.data.publicKey).completeManualChallenge(this.data.orderId, o.dsTransactionId), o;
1102
- }
1103
- destroy() {
1104
- this.provider && (this.provider.cleanup(), this.provider = null);
1105
- }
1106
- }
1107
- function it(e) {
1108
- let n = null;
1109
- return {
1110
- handleChallenge: async (i) => {
1111
- var s;
1112
- if (!(i.status === "NeedChallenge" || i.statusDetail === "ThreeDsAwaitingChallenge"))
1113
- return {
1114
- status: b.Success
1115
- };
1116
- (s = e == null ? void 0 : e.onChallenge) == null || s.call(e), n = new Be(i);
1117
- const d = await n.authenticate({
1118
- onComplete: e == null ? void 0 : e.onComplete,
1119
- onError: e == null ? void 0 : e.onError,
1120
- onTimeout: e == null ? void 0 : e.onTimeout
1121
- });
1122
- return n.destroy(), n = null, d;
1123
- },
1124
- destroy: () => {
1125
- n == null || n.destroy(), n = null;
1126
- }
1127
- };
1128
- }
1129
- class ze extends Error {
1130
- constructor(n, t) {
1131
- super(n), this.title = t, this.name = "PayConductorTokenizerApiError";
1132
- }
1133
- }
1134
- class He {
1135
- constructor(n) {
1136
- this.publicKey = n;
1137
- }
1138
- async getSettings() {
1139
- const n = await fetch(`${this.baseUrl}/card-tokenization/settings`, {
1140
- method: "GET",
1141
- headers: this.headers
1142
- });
1143
- return n.ok || await this.parseResponseError("Failed to fetch settings", n), await n.json();
1144
- }
1145
- async createToken(n) {
1146
- const t = await fetch(`${this.baseUrl}/card-tokenization/tokenize`, {
1147
- method: "POST",
1148
- headers: this.headers,
1149
- body: JSON.stringify(n)
1150
- });
1151
- return t.ok || await this.parseResponseError("Failed to generate token", t), await t.json();
1152
- }
1153
- async saveTokens(n, t, a) {
1154
- const i = await fetch(`${this.baseUrl}/card-tokenization/save-tokens/${t}/${a}`, {
1155
- method: "POST",
1156
- headers: this.headers,
1157
- body: JSON.stringify(n)
1158
- });
1159
- i.ok || await this.parseResponseError("Failed to save tokens", i);
1160
- }
1161
- async parseResponseError(n, t) {
1162
- var i, o, d, s;
1163
- let a = "";
1164
- try {
1165
- const r = await t.json();
1166
- r != null && r.message ? a = r.message : (i = r == null ? void 0 : r.error) != null && i.message ? a = r.error : (d = (o = r == null ? void 0 : r.error) == null ? void 0 : o.value) != null && d.message ? a = r.error.value.message : (s = r == null ? void 0 : r.value) != null && s.message ? a = r.value.message : a = JSON.stringify(r);
1167
- } catch {
1168
- }
1169
- throw new ze(a, n);
1170
- }
1171
- get baseUrl() {
1172
- return typeof window < "u" && window.location.href.includes("localhost") ? "http://localhost:3000/api/v1/sdk" : "https://payconductor.ai/api/v1/sdk";
1173
- }
1174
- get headers() {
1175
- return {
1176
- Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
1177
- "Content-Type": "application/json"
1178
- };
1179
- }
1180
- }
1181
- class Ye {
1182
- constructor(n) {
1183
- this.input = n;
1184
- }
1185
- }
1186
- class je extends Ye {
1187
- constructor() {
1188
- super(...arguments);
1189
- S(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
1190
- }
1191
- async tokenize() {
1192
- if (!("publicKey" in this.input.setting))
1193
- throw new Error("MercadoPago public key is missing in settings");
1194
- if (!this.input.customer.documentNumber)
1195
- throw new Error("Customer document number is required for tokenization");
1196
- const t = window.MercadoPago;
1197
- if (!t) throw new Error("MercadoPago SDK not available");
1198
- const a = new t(this.input.setting.publicKey), {
1199
- expiration: i,
1200
- cvv: o,
1201
- number: d,
1202
- holderName: s
1203
- } = this.input.card;
1204
- return (await a.createCardToken({
1205
- cardExpirationMonth: String(i.month),
1206
- cardExpirationYear: String(i.year),
1207
- cardholderName: s,
1208
- cardNumber: d,
1209
- securityCode: o,
1210
- identificationType: this.input.customer.documentType === G.Cpf ? "CPF" : "CNPJ",
1211
- identificationNumber: this.input.customer.documentNumber
1212
- })).id;
1213
- }
1214
- }
1215
- const Ge = {
1216
- [M.MercadoPago]: je
1217
- };
1218
- class Ve {
1219
- constructor(n) {
1220
- S(this, "api");
1221
- this.publicKey = n, this.api = new He(this.publicKey);
1222
- }
1223
- async tokenizeCard(n) {
1224
- this.validateCard(n);
1225
- const {
1226
- customerId: t,
1227
- token: a
1228
- } = await this.api.createToken({
1229
- card: n.card,
1230
- customer: n.customer,
1231
- saveCard: !1
1232
- }), {
1233
- settings: i
1234
- } = await this.api.getSettings(), d = (await Promise.all(i.map(async (s) => {
1235
- const r = Ge[s.key];
1236
- if (!r) return null;
1237
- const c = new r({
1238
- ...n,
1239
- setting: s.settings
1240
- });
1241
- return await x(c.scriptUrl), {
1242
- token: await c.tokenize(),
1243
- integrationId: s.integrationId,
1244
- providerKey: s.key
1245
- };
1246
- }))).filter((s) => s !== null);
1247
- return d.length > 0 && await this.api.saveTokens(d, t, a), a;
1248
- }
1249
- validateCard(n) {
1250
- const {
1251
- number: t,
1252
- cvv: a,
1253
- expiration: i,
1254
- holderName: o
1255
- } = n.card;
1256
- if (!t || !a || !(i != null && i.month) || !(i != null && i.year) || !o)
1257
- throw new Error("Invalid card data");
1258
- }
1259
- }
1260
- function rt(e) {
1261
- const n = new Ve(e.publicKey);
1262
- return {
1263
- tokenizeCard: async (a) => {
1264
- var i, o;
1265
- try {
1266
- const d = await n.tokenizeCard(a);
1267
- return (i = e.onSuccess) == null || i.call(e, d), d;
1268
- } catch (d) {
1269
- const s = d instanceof Error ? d : new Error("Tokenization failed");
1270
- return (o = e.onError) == null || o.call(e, s), null;
1271
- }
1272
- }
1273
- };
1274
- }
1275
- export {
1276
- me as ALLOWED_ORIGINS,
1277
- re as CardBrand,
1278
- ne as ChargeStatusDetail,
1279
- oe as CurrencyType,
1280
- se as DeviceType,
1281
- G as DocumentType,
1282
- Ze as ERROR_CODES,
1283
- ce as ErrorCode,
1284
- ue as IFRAME_BASE_URL,
1285
- z as IFRAME_DEFAULT_HEIGHT_VALUE,
1286
- A as IncomingMessage,
1287
- de as InputStyleKey,
1288
- M as IntegrationProvider,
1289
- N as OrganizationEnvironment,
1290
- T as OutgoingMessage,
1291
- P as POST_MESSAGES,
1292
- Qe as PayConductor,
1293
- Be as PayConductor3DSSDK,
1294
- et as PayConductorCheckoutElement,
1295
- tt as PayConductorThreeDSElement,
1296
- Ve as PayConductorTokenizerSDK,
1297
- Q as PaymentMethod,
1298
- ee as PaymentMethodLayout,
1299
- te as PaymentStatus,
1300
- he as REQUEST_TIMEOUT,
1301
- fe as SKELETON_CSS,
1302
- H as SKELETON_STYLE_ID,
1303
- ie as ThreeDSResultStatus,
1304
- R as ThreeDSTransStatus,
1305
- b as ThreeDSecureResultStatus,
1306
- ae as ThreeDsAuthenticationStatus,
1307
- ye as buildIframeUrl,
1308
- Qe as default,
1309
- Xe as defaultTheme,
1310
- we as generateRequestId,
1311
- Ee as isValidOrigin,
1312
- x as loadScript,
1313
- nt as usePayConductor,
1314
- at as usePayconductorElement,
1315
- it as useThreeDS,
1316
- rt as useTokenizer
1317
- };
1318
- //# sourceMappingURL=index.es.js.map
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