@payconductor/react 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +253 -253
  2. package/dist/esm/three-ds.d.ts +1 -1
  3. package/dist/esm/tokenizer.d.ts +1 -1
  4. package/dist/index.cjs.js +49 -49
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.d.ts +12 -11
  7. package/dist/index.es.js +1318 -1308
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/payconductor/constants.d.ts +31 -31
  10. package/dist/payconductor/hooks/index.d.ts +7 -7
  11. package/dist/payconductor/hooks/use-element.d.ts +30 -30
  12. package/dist/payconductor/hooks/use-payconductor.d.ts +6 -6
  13. package/dist/payconductor/hooks/use-three-ds.d.ts +13 -13
  14. package/dist/payconductor/hooks/use-tokenizer.d.ts +11 -11
  15. package/dist/payconductor/iframe/constants.d.ts +8 -8
  16. package/dist/payconductor/iframe/types.d.ts +464 -464
  17. package/dist/payconductor/internal.d.ts +11 -11
  18. package/dist/payconductor/loader.d.ts +1 -1
  19. package/dist/payconductor/payconductor-element.d.ts +5 -5
  20. package/dist/payconductor/payconductor-three-ds.d.ts +5 -5
  21. package/dist/payconductor/payconductor.d.ts +17 -17
  22. package/dist/payconductor/three-ds/api.d.ts +12 -12
  23. package/dist/payconductor/three-ds/browser.d.ts +13 -13
  24. package/dist/payconductor/three-ds/handler.d.ts +11 -11
  25. package/dist/payconductor/three-ds/index.d.ts +3 -1
  26. package/dist/payconductor/three-ds/providers/index.d.ts +6 -6
  27. package/dist/payconductor/three-ds/providers/mercado-pago.d.ts +9 -9
  28. package/dist/payconductor/three-ds/providers/pagarme.d.ts +9 -9
  29. package/dist/payconductor/three-ds/providers/pagseguro.d.ts +7 -7
  30. package/dist/payconductor/three-ds/providers/payconductor.d.ts +7 -7
  31. package/dist/payconductor/three-ds/types.d.ts +93 -78
  32. package/dist/payconductor/tokenizer/api.d.ts +26 -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 +6 -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 +58 -58
package/dist/index.es.js CHANGED
@@ -1,1308 +1,1318 @@
1
- var j = Object.defineProperty;
2
- var $ = (e, n, t) => n in e ? j(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var p = (e, n, t) => $(e, typeof n != "symbol" ? n + "" : n, t);
4
- import { jsx as N, jsxs as q } from "react/jsx-runtime";
5
- import { useState as A, useEffect as F, useRef as W } from "react";
6
- const H = "https://iframe.payconductor.ai/v1", Y = "http://localhost:5175/v1", J = 3e5, X = "600px";
7
- var Z = /* @__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))(Z || {}), Q = /* @__PURE__ */ ((e) => (e.Grid = "grid", e.Vertical = "vertical", e.Horizontal = "horizontal", e))(Q || {}), ee = /* @__PURE__ */ ((e) => (e.Succeeded = "succeeded", e.Pending = "pending", e.Failed = "failed", e))(ee || {}), te = /* @__PURE__ */ ((e) => (e.ThreeDsAwaitingChallenge = "ThreeDsAwaitingChallenge", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Authenticated = "Authenticated", e.NotAuthenticated = "NotAuthenticated", e.NeedChallenge = "NeedChallenge", e))(ne || {}), ae = /* @__PURE__ */ ((e) => (e.Pending = "Pending", e.Authenticated = "Authenticated", e.Failed = "Failed", e.NotEnrolled = "NotEnrolled", e))(ae || {}), G = /* @__PURE__ */ ((e) => (e.Cpf = "Cpf", e.Cnpj = "Cnpj", e))(G || {}), I = /* @__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))(I || {}), 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 || {}), _ = /* @__PURE__ */ ((e) => (e.Production = "Production", e.Sandbox = "Sandbox", e))(_ || {}), ie = /* @__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))(ie || {}), oe = /* @__PURE__ */ ((e) => (e.Android = "android", e.IOS = "ios", e.Web = "web", e.Chrome = "chrome", e.Safari = "safari", e))(oe || {}), se = /* @__PURE__ */ ((e) => (e.Padding = "padding", e.Radius = "radius", e.Color = "color", e.Background = "background", e.Shadow = "shadow", e))(se || {}), M = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(M || {}), v = /* @__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))(v || {}), de = /* @__PURE__ */ ((e) => (e.InvalidClient = "InvalidClient", e.InvalidToken = "InvalidToken", e.NetworkError = "NetworkError", e.IframeNotReady = "IframeNotReady", e.PaymentDeclined = "PaymentDeclined", e.ValidationError = "ValidationError", e.Timeout = "Timeout", e))(de || {});
8
- const Je = {
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
- }, ce = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") && !window.location.search.includes("production"), le = ce ? Y : H, ue = [Y, H], B = X, he = J, 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: v.Ready,
63
- ERROR: v.Error,
64
- PAYMENT_COMPLETE: v.PaymentComplete,
65
- PAYMENT_FAILED: v.PaymentFailed,
66
- PAYMENT_PENDING: v.PaymentPending,
67
- VALIDATION_ERROR: v.ValidationError,
68
- PAYMENT_METHOD_SELECTED: v.PaymentMethodSelected,
69
- RESIZE: v.Resize
70
- }, Xe = {
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
- }, z = "payconductor-skeleton-style", me = `
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 fe(e) {
92
- const n = new URLSearchParams({
93
- publicKey: e.publicKey
94
- });
95
- return `${le}?${n.toString()}`;
96
- }
97
- function ye() {
98
- return crypto.randomUUID();
99
- }
100
- function we(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 O() {
110
- return /* @__PURE__ */ new Map();
111
- }
112
- function D(e, n, t, a) {
113
- return new Promise((r, 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 = ye();
127
- n.set(d, {
128
- resolve: r,
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 Ee(e, n, t) {
140
- return D(e, n, P.CONFIRM_PAYMENT, t);
141
- }
142
- async function ge(e, n, t) {
143
- return await Ee(e, n, {
144
- orderId: t.orderId
145
- });
146
- }
147
- function Pe(e, n, t) {
148
- return D(e, n, P.VALIDATE, t);
149
- }
150
- function Se(e, n) {
151
- return D(e, n, P.RESET);
152
- }
153
- function be(e, n, t) {
154
- return D(e, n, P.CONFIG, t);
155
- }
156
- function Ce(e, n, t) {
157
- return D(e, n, P.INIT, t);
158
- }
159
- function pe(e, n, t, a, r, o, d, s, i, l, g, w) {
160
- const m = e.data, {
161
- requestId: y,
162
- type: h,
163
- data: E,
164
- error: C
165
- } = m;
166
- if (h === P.READY) {
167
- if (a == null || a(), y && (n != null && n.has(y))) {
168
- const {
169
- resolve: T
170
- } = n.get(y);
171
- n.delete(y), T(E);
172
- }
173
- return;
174
- }
175
- if (we(e.origin, ue)) {
176
- if (y && n && n.has(y)) {
177
- const {
178
- resolve: T,
179
- reject: x
180
- } = n.get(y);
181
- n.delete(y), C ? x(new Error(String(C.message))) : T(E);
182
- return;
183
- }
184
- if (h === P.ERROR) {
185
- t((C == null ? void 0 : C.message) || "Unknown error"), r == null || r(new Error(String(C == null ? void 0 : C.message)));
186
- return;
187
- }
188
- if (h === P.PAYMENT_COMPLETE) {
189
- E && typeof E == "object" && "status" in E && (o == null || o(E));
190
- return;
191
- }
192
- if (h === P.PAYMENT_FAILED) {
193
- E && typeof E == "object" && "status" in E && (d == null || d(E));
194
- return;
195
- }
196
- if (h === P.PAYMENT_PENDING) {
197
- E && typeof E == "object" && "status" in E && (s == null || s(E));
198
- return;
199
- }
200
- if (h === P.PAYMENT_METHOD_SELECTED) {
201
- E && typeof E == "object" && "paymentMethod" in E && (i == null || i(E.paymentMethod));
202
- return;
203
- }
204
- if (h !== P.RESIZE) {
205
- if (h === v.ThreeDSChallenge) {
206
- l == null || l();
207
- return;
208
- }
209
- if (h === v.ThreeDSComplete) {
210
- g == null || g();
211
- return;
212
- }
213
- if (h === v.ThreeDSFailed) {
214
- w == null || w();
215
- return;
216
- }
217
- }
218
- }
219
- }
220
- function Ze(e) {
221
- const [n, t] = A(
222
- () => !1
223
- ), [a, r] = A(() => null), [o, d] = A(
224
- () => ""
225
- ), [s, i] = A(() => null);
226
- return F(() => {
227
- const l = (...u) => {
228
- e.debug && console.log("[PayConductor]", ...u);
229
- }, g = fe({
230
- publicKey: e.publicKey
231
- });
232
- d(g), t(!0);
233
- const w = O();
234
- let m = !1;
235
- l("init", e.publicKey), l("iframeUrl", g);
236
- const y = () => {
237
- var S, c;
238
- const u = (c = (S = window.PayConductor) == null ? void 0 : S.frame) == null ? void 0 : c.iframe;
239
- if (u) {
240
- if (u instanceof HTMLIFrameElement) return u;
241
- if (typeof u == "object" && u !== null) {
242
- const f = u;
243
- if ("current" in f && f.current instanceof HTMLIFrameElement)
244
- return f.current;
245
- if ("value" in f && f.value instanceof HTMLIFrameElement)
246
- return f.value;
247
- }
248
- return u;
249
- }
250
- return document.querySelector(
251
- ".payconductor-element iframe"
252
- ) ?? void 0;
253
- }, h = {
254
- get iframe() {
255
- return document.querySelector(
256
- ".payconductor-element iframe"
257
- ) ?? null;
258
- },
259
- set iframe(u) {
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
- }, C = {
270
- confirmPayment: (u) => {
271
- var c;
272
- l("→ CONFIRM_PAYMENT", {
273
- orderId: u.orderId
274
- });
275
- const S = y();
276
- return S != null && S.contentWindow && S.contentWindow.postMessage(
277
- {
278
- type: P.CONFIG,
279
- data: {
280
- publicKey: e.publicKey,
281
- orderId: u.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 = u.orderId, (c = window.PayConductor) != null && c.config && (window.PayConductor.config.orderId = u.orderId), ge(S, w, u);
292
- },
293
- validate: (u) => (l("→ VALIDATE", u), Pe(y(), w, u)),
294
- reset: () => (l("→ RESET"), Se(y(), w)),
295
- getSelectedPaymentMethod: () => s
296
- };
297
- window.PayConductor = {
298
- frame: h,
299
- config: E,
300
- api: C,
301
- selectedPaymentMethod: s
302
- }, l("registered"), window.dispatchEvent(
303
- new CustomEvent("payconductor:registered", {
304
- detail: window.PayConductor
305
- })
306
- );
307
- const T = async () => {
308
- if (!m) {
309
- const u = y();
310
- if (!u) {
311
- l("→ CONFIG skipped: iframe not found");
312
- return;
313
- }
314
- m = !0, l("→ CONFIG", {
315
- theme: e.theme,
316
- locale: e.locale,
317
- paymentMethods: e.paymentMethods,
318
- defaultPaymentMethod: e.defaultPaymentMethod,
319
- showPaymentButtons: e.showPaymentButtons
320
- }), be(u, 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
- }, x = (u) => {
330
- var S;
331
- (S = u.data) != null && S.type && l("←", u.data.type, u.data.data ?? ""), pe(
332
- u,
333
- w,
334
- (c) => {
335
- var f;
336
- r(c), h.error = c, (f = window.PayConductor) != null && f.frame && (window.PayConductor.frame.error = c);
337
- },
338
- () => {
339
- var c;
340
- (c = e.onReady) == null || c.call(e), T();
341
- },
342
- (c) => {
343
- var f;
344
- (f = e.onError) == null || f.call(e, c);
345
- },
346
- (c) => {
347
- var f;
348
- (f = e.onPaymentComplete) == null || f.call(e, c);
349
- },
350
- (c) => {
351
- var f;
352
- (f = e.onPaymentFailed) == null || f.call(e, c);
353
- },
354
- (c) => {
355
- var f;
356
- (f = e.onPaymentPending) == null || f.call(e, c);
357
- },
358
- (c) => {
359
- var f;
360
- i(c), window.PayConductor && (window.PayConductor.selectedPaymentMethod = c), (f = e.onPaymentMethodSelected) == null || f.call(e, c);
361
- },
362
- () => {
363
- var c;
364
- (c = e.onThreeDSChallenge) == null || c.call(e);
365
- },
366
- () => {
367
- var c;
368
- (c = e.onThreeDSComplete) == null || c.call(e);
369
- },
370
- () => {
371
- var c;
372
- (c = e.onThreeDSFailed) == null || c.call(e);
373
- }
374
- );
375
- };
376
- window.addEventListener("message", x);
377
- const V = () => {
378
- var S, c, f;
379
- const u = y();
380
- if (!u) return !1;
381
- try {
382
- if ((((S = u.contentDocument) == null ? void 0 : S.readyState) ?? ((f = (c = u.contentWindow) == null ? void 0 : c.document) == null ? void 0 : f.readyState)) === "complete")
383
- return T(), !0;
384
- } catch {
385
- }
386
- return !1;
387
- }, K = () => {
388
- if (V()) return;
389
- const u = y();
390
- if (u) {
391
- u.addEventListener("load", () => T(), {
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 Qe(e) {
412
- const n = W(null), [t, a] = A(() => ""), [r, o] = A(() => !1), [d, s] = A(() => "");
413
- return F(() => {
414
- if (typeof document < "u" && !document.getElementById(z)) {
415
- const m = document.createElement("style");
416
- m.id = z, m.textContent = me, document.head.appendChild(m);
417
- }
418
- const i = (m) => {
419
- m != null && m.frame && (a(m.frame.iframeUrl || ""), o(!0), console.log("init", {
420
- PayConductor: window.PayConductor
421
- }));
422
- }, l = typeof window < "u" ? window.PayConductor : null;
423
- if (l)
424
- i(l);
425
- else {
426
- const m = (y) => {
427
- i(y.detail), window.removeEventListener("payconductor:registered", m);
428
- };
429
- window.addEventListener("payconductor:registered", m);
430
- }
431
- let g = !1;
432
- const w = (m) => {
433
- var y, h, E, C;
434
- if (((y = m.data) == null ? void 0 : y.type) === P.RESIZE && ((E = (h = m.data) == null ? void 0 : h.data) != null && E.height) && s(m.data.data.height + "px"), ((C = m.data) == null ? void 0 : C.type) === P.READY && e.height && !g) {
435
- g = !0;
436
- const T = document.querySelector(
437
- ".payconductor-element iframe"
438
- );
439
- T != null && T.contentWindow && T.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__ */ q(
453
- "div",
454
- {
455
- className: "payconductor-element",
456
- style: {
457
- width: "100%"
458
- },
459
- children: [
460
- r ? null : /* @__PURE__ */ N(
461
- "div",
462
- {
463
- className: "payconductor-skeleton",
464
- style: {
465
- height: e.height || B
466
- }
467
- }
468
- ),
469
- r && t ? /* @__PURE__ */ N(
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 || B,
479
- border: "none"
480
- }
481
- }
482
- ) : null
483
- ]
484
- }
485
- );
486
- }
487
- function et(e) {
488
- const [n, t] = A(() => !1);
489
- return F(() => {
490
- const a = () => {
491
- t(!0);
492
- }, r = () => {
493
- t(!1);
494
- };
495
- return window.addEventListener("payconductor:3ds:show", a), window.addEventListener("payconductor:3ds:hide", r), typeof window < "u" && (window.PayConductor3DS = {
496
- container: () => document.getElementById("payconductor-3ds-container"),
497
- show: a,
498
- hide: r
499
- }, window.dispatchEvent(new CustomEvent("payconductor:3ds:registered"))), () => {
500
- window.removeEventListener("payconductor:3ds:show", a), window.removeEventListener("payconductor:3ds:hide", r), 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: n ? "block" : "none",
510
- minHeight: n ? e.height || "600px" : "0"
511
- }
512
- }
513
- );
514
- }
515
- function tt() {
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 nt() {
552
- const e = () => typeof window < "u" ? window.PayConductor : null, n = (t, a) => {
553
- const r = e();
554
- if (!r) return;
555
- const o = L(r);
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()), r = O();
564
- return Ce(a || void 0, r, 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 r;
587
- const a = (r = e()) == null ? void 0 : r.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 r;
598
- const a = (r = e()) == null ? void 0 : r.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 = O();
612
- try {
613
- return await D(t || void 0, a, P.CONFIRM_PAYMENT, {}), {
614
- paymentMethod: void 0
615
- };
616
- } catch (r) {
617
- return {
618
- error: {
619
- message: r instanceof Error ? r.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 || {});
629
- class R {
630
- constructor(n, t) {
631
- p(this, "overlay", null);
632
- p(this, "modalContent", null);
633
- this.data = n, this.options = t;
634
- }
635
- fail(n) {
636
- var a, r;
637
- const t = new Error(n);
638
- return (r = (a = this.options).onError) == null || r.call(a, t), {
639
- status: "Failed",
640
- error: t
641
- };
642
- }
643
- //#region Modal
644
- showModal() {
645
- 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;
646
- }
647
- closeModal() {
648
- this.overlay && (this.overlay.remove(), this.overlay = null, this.modalContent = null);
649
- }
650
- resolveContainer() {
651
- return this.modalContent ?? this.showModal();
652
- }
653
- injectStyles() {
654
- if (document.getElementById("payconductor-3ds-styles")) return;
655
- const n = document.createElement("style");
656
- n.id = "payconductor-3ds-styles", n.textContent = `
657
- #payconductor-3ds-overlay {
658
- position: fixed;
659
- inset: 0;
660
- z-index: 99999;
661
- display: flex;
662
- align-items: center;
663
- justify-content: center;
664
- background: rgba(0, 0, 0, 0.6);
665
- }
666
- #payconductor-3ds-modal {
667
- width: 500px;
668
- max-width: 95vw;
669
- min-height: 600px;
670
- border-radius: 8px;
671
- overflow: hidden;
672
- background: #fff;
673
- }
674
- #payconductor-3ds-modal iframe {
675
- width: 100%;
676
- height: 600px;
677
- border: none;
678
- display: block;
679
- }
680
- @media only screen and (max-width: 600px) {
681
- #payconductor-3ds-modal {
682
- width: 100vw;
683
- max-width: 100vw;
684
- min-height: 440px;
685
- border-radius: 0;
686
- }
687
- #payconductor-3ds-modal iframe {
688
- height: 440px;
689
- }
690
- }
691
- `, document.head.appendChild(n);
692
- }
693
- //#endregion
694
- }
695
- const Te = 5 * 60 * 1e3;
696
- class ve extends R {
697
- constructor() {
698
- super(...arguments);
699
- p(this, "iframe", null);
700
- p(this, "messageListener", null);
701
- p(this, "timeoutId", null);
702
- }
703
- async authenticate() {
704
- const {
705
- threeDsUrl: t,
706
- creq: a
707
- } = this.data;
708
- if (!t || !a)
709
- return this.fail("Missing threeDsUrl or creq");
710
- const r = this.resolveContainer();
711
- return new Promise((o) => {
712
- var l;
713
- this.iframe = document.createElement("iframe"), this.iframe.name = "payconductor-3ds-challenge", this.iframe.id = "payconductor-3ds-challenge", r.appendChild(this.iframe), this.messageListener = (g) => {
714
- var w, m, y;
715
- ((w = g.data) == null ? void 0 : w.status) === "COMPLETE" && (this.cleanup(), (y = (m = this.options).onComplete) == null || y.call(m), o({
716
- status: b.Success
717
- }));
718
- }, window.addEventListener("message", this.messageListener), this.timeoutId = setTimeout(() => {
719
- var g, w;
720
- this.cleanup(), (w = (g = this.options).onTimeout) == null || w.call(g), o({
721
- status: b.Timeout
722
- });
723
- }, this.options.timeoutMs ?? Te);
724
- const d = (l = this.iframe.contentWindow) == null ? void 0 : l.document;
725
- if (!d) {
726
- this.cleanup(), o(this.fail("Cannot access iframe document"));
727
- return;
728
- }
729
- const s = d.createElement("form");
730
- s.name = "threeDsChallengeForm", s.setAttribute("target", "payconductor-3ds-challenge"), s.setAttribute("method", "post"), s.setAttribute("action", t);
731
- const i = d.createElement("input");
732
- i.setAttribute("type", "hidden"), i.setAttribute("name", "creq"), i.setAttribute("value", a), s.appendChild(i), this.iframe.appendChild(s), s.submit();
733
- });
734
- }
735
- cleanup() {
736
- 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();
737
- }
738
- }
739
- const U = /* @__PURE__ */ new Map();
740
- function k(e) {
741
- const n = U.get(e);
742
- if (n) return n;
743
- const t = new Promise((a, r) => {
744
- if (document.querySelector(`script[src="${e}"]`)) {
745
- a();
746
- return;
747
- }
748
- const o = document.createElement("script");
749
- o.src = e, o.async = !0, o.onload = () => a(), o.onerror = () => {
750
- U.delete(e), r(new Error(`Failed to load script: ${e}`));
751
- }, (document.head || document.body).appendChild(o);
752
- });
753
- return U.set(e, t), t;
754
- }
755
- const Ae = "https://static.payzen.lat/static/js/authenticate-client/V1.0/kr-authenticate.umd", Me = 10 * 60 * 1e3;
756
- class Ie extends R {
757
- constructor() {
758
- super(...arguments);
759
- p(this, "timeoutId", null);
760
- }
761
- async authenticate() {
762
- const {
763
- operationUrl: t,
764
- publicKey: a
765
- } = this.data;
766
- if (!t || !a)
767
- return this.fail("Missing operationUrl or publicKey");
768
- try {
769
- await k(Ae);
770
- } catch {
771
- return this.fail("Failed to load 3DS SDK");
772
- }
773
- const r = window.KrAuthenticate;
774
- return r ? new Promise((o) => {
775
- this.timeoutId = setTimeout(() => {
776
- var s, i;
777
- this.cleanup(), (i = (s = this.options).onTimeout) == null || i.call(s), o({
778
- status: b.Timeout
779
- });
780
- }, this.options.timeoutMs ?? Me), new r(a).authenticate(t, () => {
781
- var s, i;
782
- this.cleanup(), (i = (s = this.options).onComplete) == null || i.call(s), o({
783
- status: b.Success
784
- });
785
- });
786
- }) : this.fail("KrAuthenticate not available");
787
- }
788
- cleanup() {
789
- this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null);
790
- }
791
- }
792
- const De = {
793
- [_.Production]: "https://3ds-nx-js.stone.com.br/live/v2/3ds2.min",
794
- [_.Sandbox]: "https://3ds-nx-js.stone.com.br/test/v2/3ds2.min"
795
- }, _e = 5 * 60 * 1e3;
796
- function Ne() {
797
- const e = window.innerWidth;
798
- return e <= 480 ? "01" : e <= 768 ? "02" : e <= 1024 ? "03" : "04";
799
- }
800
- class Re extends R {
801
- constructor() {
802
- super(...arguments);
803
- p(this, "timeoutId", null);
804
- p(this, "methodContainer", null);
805
- }
806
- async authenticate() {
807
- const {
808
- authToken: t,
809
- card: a
810
- } = this.data;
811
- if (!t) return this.fail("Missing authToken for PagarMe 3DS");
812
- if (!a) return this.fail("Missing card data for PagarMe 3DS");
813
- const r = this.data.environment ?? _.Production;
814
- try {
815
- await k(De[r]);
816
- } catch {
817
- return this.fail("Failed to load Stone 3DS SDK");
818
- }
819
- const o = window.TDS;
820
- if (!o) return this.fail("Stone TDS SDK not available");
821
- const d = this.resolveContainer();
822
- return this.methodContainer = document.createElement("div"), this.methodContainer.style.display = "none", document.body.appendChild(this.methodContainer), new Promise((s) => {
823
- this.timeoutId = setTimeout(() => {
824
- var i, l;
825
- this.cleanup(), (l = (i = this.options).onTimeout) == null || l.call(i), s({
826
- status: b.Timeout
827
- });
828
- }, this.options.timeoutMs ?? _e), o.init({
829
- token: t,
830
- tds_method_container_element: this.methodContainer,
831
- challenge_container_element: d,
832
- use_default_challenge_iframe_style: !0,
833
- challenge_window_size: Ne()
834
- }, this.buildOrderData()).then((i) => {
835
- var g, w;
836
- if (this.cleanup(), !(i != null && i.length)) {
837
- s(this.fail("PagarMe 3DS returned no response"));
838
- return;
839
- }
840
- const l = i[0];
841
- if (l.challenge_canceled) {
842
- s(this.fail("3DS challenge canceled by user"));
843
- return;
844
- }
845
- l.trans_status === "Y" || l.trans_status === "A" ? ((w = (g = this.options).onComplete) == null || w.call(g), s({
846
- status: b.Success,
847
- dsTransactionId: l.tds_server_trans_id
848
- })) : s(this.fail(`3DS failed with status: ${l.trans_status}`));
849
- }).catch((i) => {
850
- this.cleanup(), s(this.fail(i instanceof Error ? i.message : "PagarMe 3DS failed"));
851
- });
852
- });
853
- }
854
- cleanup() {
855
- this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.methodContainer && (this.methodContainer.remove(), this.methodContainer = null), this.closeModal();
856
- }
857
- buildOrderData() {
858
- var d;
859
- const {
860
- card: t,
861
- customer: a,
862
- amount: r,
863
- billingAddress: o
864
- } = this.data;
865
- return {
866
- payments: [{
867
- payment_method: "credit_card",
868
- credit_card: {
869
- card: {
870
- number: t == null ? void 0 : t.number,
871
- holder_name: t == null ? void 0 : t.holderName,
872
- exp_month: Number(t == null ? void 0 : t.expMonth),
873
- exp_year: Number(t == null ? void 0 : t.expYear),
874
- billing_address: o ? {
875
- country: o.country,
876
- state: o.state,
877
- city: o.city,
878
- zip_code: o.zipCode,
879
- line_1: `${o.number}, ${o.street}${o.district ? `, ${o.district}` : ""}`,
880
- line_2: o.complement ?? ""
881
- } : void 0
882
- }
883
- },
884
- amount: r
885
- }],
886
- ...a ? {
887
- customer: {
888
- name: a.name,
889
- email: a.email,
890
- ...a.document ? {
891
- document: a.document
892
- } : {},
893
- ...(d = a.phones) != null && d.length ? {
894
- phones: Object.fromEntries(a.phones.map((s) => [s.type === "HOME" ? "home_phone" : "mobile_phone", {
895
- country_code: s.countryCode,
896
- area_code: s.areaCode,
897
- number: s.number
898
- }]))
899
- } : {}
900
- }
901
- } : {}
902
- };
903
- }
904
- }
905
- const ke = "https://assets.pagseguro.com.br/checkout-sdk-js/rc/dist/browser/pagseguro.min";
906
- class xe extends R {
907
- async authenticate() {
908
- var w, m, y;
909
- const {
910
- authToken: n,
911
- card: t,
912
- customer: a,
913
- amount: r,
914
- currency: o,
915
- billingAddress: d
916
- } = this.data;
917
- if (!n) return this.fail("Missing authToken (session) for PagSeguro 3DS");
918
- if (!t) return this.fail("Missing card data for PagSeguro 3DS");
919
- if (!a) return this.fail("Missing customer data for PagSeguro 3DS");
920
- if (!r) return this.fail("Missing amount for PagSeguro 3DS");
921
- if (!d) return this.fail("Missing billingAddress for PagSeguro 3DS");
922
- const s = this.data.environment === _.Sandbox ? "SANDBOX" : "PROD";
923
- try {
924
- await k(ke);
925
- } catch {
926
- return this.fail("Failed to load PagSeguro SDK");
927
- }
928
- const i = window.PagSeguro;
929
- if (!i) return this.fail("PagSeguro SDK not available");
930
- i.setUp({
931
- session: n,
932
- env: s
933
- });
934
- const l = ((w = a.phones) == null ? void 0 : w.map((h) => ({
935
- country: h.countryCode,
936
- area: h.areaCode,
937
- number: h.number,
938
- type: h.type ?? "MOBILE"
939
- }))) ?? [{
940
- country: "55",
941
- area: "11",
942
- number: "999999999",
943
- type: "MOBILE"
944
- }];
945
- l.some((h) => h.type === "MOBILE") || (l[0].type = "MOBILE");
946
- try {
947
- const h = await i.authenticate3DS({
948
- data: {
949
- customer: {
950
- name: a.name,
951
- email: a.email,
952
- phones: l
953
- },
954
- paymentMethod: {
955
- type: this.data.installments === 0 ? "DEBIT_CARD" : "CREDIT_CARD",
956
- installments: this.data.installments ?? 1,
957
- card: {
958
- number: t.number,
959
- expMonth: t.expMonth,
960
- expYear: t.expYear,
961
- holder: {
962
- name: t.holderName
963
- }
964
- }
965
- },
966
- amount: {
967
- value: r,
968
- currency: o ?? "BRL"
969
- },
970
- billingAddress: {
971
- street: d.street,
972
- number: d.number,
973
- complement: d.complement,
974
- regionCode: d.state,
975
- country: d.country.length === 2 ? this.toAlpha3(d.country) : d.country,
976
- city: d.city,
977
- postalCode: d.zipCode.replace(/\D/g, "")
978
- },
979
- dataOnly: !1
980
- }
981
- });
982
- return h.status === "AUTH_FLOW_COMPLETED" || h.status === "AUTH_NOT_SUPPORTED" ? ((y = (m = this.options).onComplete) == null || y.call(m), {
983
- status: b.Success,
984
- dsTransactionId: h.id
985
- }) : h.status === "CHANGE_PAYMENT_METHOD" ? this.fail("PagSeguro requires a different payment method") : {
986
- status: b.Success,
987
- dsTransactionId: h.id
988
- };
989
- } catch (h) {
990
- return this.fail(h instanceof Error ? h.message : "PagSeguro 3DS failed");
991
- }
992
- }
993
- cleanup() {
994
- }
995
- toAlpha3(n) {
996
- return {
997
- BR: "BRA",
998
- US: "USA",
999
- AR: "ARG",
1000
- CL: "CHL",
1001
- CO: "COL",
1002
- MX: "MEX",
1003
- PE: "PER",
1004
- UY: "URY"
1005
- }[n.toUpperCase()] ?? n;
1006
- }
1007
- }
1008
- const Le = {
1009
- // Agnostic providers
1010
- [I.Lyra]: Ie,
1011
- // Acquirer-specific providers
1012
- [I.MercadoPago]: ve,
1013
- [I.PagarMe]: Re,
1014
- [I.PagSeguro]: xe
1015
- };
1016
- class Ue extends Error {
1017
- constructor(n, t) {
1018
- super(n), this.title = t, this.name = "PayConductorThreeDSApiError";
1019
- }
1020
- }
1021
- class Oe {
1022
- constructor(n) {
1023
- this.publicKey = n;
1024
- }
1025
- async completeManualChallenge(n, t) {
1026
- const a = await fetch(`${this.baseUrl}/three-ds/complete/${n}`, {
1027
- method: "POST",
1028
- headers: this.headers,
1029
- body: JSON.stringify({
1030
- providerTransactionId: t
1031
- })
1032
- });
1033
- a.ok || await this.parseResponseError("Failed to complete native 3DS challenge", a);
1034
- }
1035
- async parseResponseError(n, t) {
1036
- var r, o, d, s;
1037
- let a = "";
1038
- try {
1039
- const i = await t.json();
1040
- i != null && i.message ? a = i.message : (r = i == null ? void 0 : i.error) != null && r.message ? a = i.error : (d = (o = i == null ? void 0 : i.error) == null ? void 0 : o.value) != null && d.message ? a = i.error.value.message : (s = i == null ? void 0 : i.value) != null && s.message ? a = i.value.message : a = JSON.stringify(i);
1041
- } catch {
1042
- }
1043
- throw new Ue(a, n);
1044
- }
1045
- get baseUrl() {
1046
- return typeof window < "u" && window.location.href.includes("localhost") ? "http://localhost:3000/api/v1/sdk" : "https://payconductor.ai/api/v1/sdk";
1047
- }
1048
- get headers() {
1049
- return {
1050
- Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
1051
- "Content-Type": "application/json"
1052
- };
1053
- }
1054
- }
1055
- const Fe = [I.PagSeguro];
1056
- class Ke {
1057
- constructor(n) {
1058
- p(this, "data");
1059
- p(this, "provider", null);
1060
- this.data = n;
1061
- }
1062
- get needsChallenge() {
1063
- return this.data.status === "NeedChallenge" || this.data.statusDetail === "ThreeDsAwaitingChallenge";
1064
- }
1065
- get acquirer() {
1066
- return this.data.acquirer;
1067
- }
1068
- async authenticate(n) {
1069
- if (!this.needsChallenge)
1070
- return {
1071
- status: b.Success
1072
- };
1073
- const {
1074
- acquirer: t
1075
- } = this.data;
1076
- if (!t)
1077
- return {
1078
- status: b.Failed,
1079
- error: new Error("Missing 3DS acquirer")
1080
- };
1081
- const a = Le[t];
1082
- if (!a)
1083
- return {
1084
- status: b.Failed,
1085
- error: new Error(`Unsupported 3DS provider: ${t}`)
1086
- };
1087
- const r = {
1088
- ...n,
1089
- threeDSecure: this.data
1090
- };
1091
- this.provider = new a(this.data, r);
1092
- const o = await this.provider.authenticate();
1093
- return o.status === b.Success && o.dsTransactionId && Fe.includes(t) && this.data.orderId && this.data.publicKey && await new Oe(this.data.publicKey).completeManualChallenge(this.data.orderId, o.dsTransactionId), o;
1094
- }
1095
- destroy() {
1096
- this.provider && (this.provider.cleanup(), this.provider = null);
1097
- }
1098
- }
1099
- function at(e) {
1100
- let n = null;
1101
- return {
1102
- handleChallenge: async (r) => {
1103
- var s;
1104
- if (!(r.status === "NeedChallenge" || r.statusDetail === "ThreeDsAwaitingChallenge"))
1105
- return {
1106
- status: b.Success
1107
- };
1108
- (s = e == null ? void 0 : e.onChallenge) == null || s.call(e), n = new Ke(r);
1109
- const d = await n.authenticate({
1110
- onComplete: e == null ? void 0 : e.onComplete,
1111
- onError: e == null ? void 0 : e.onError,
1112
- onTimeout: e == null ? void 0 : e.onTimeout
1113
- });
1114
- return n.destroy(), n = null, d;
1115
- },
1116
- destroy: () => {
1117
- n == null || n.destroy(), n = null;
1118
- }
1119
- };
1120
- }
1121
- class Be extends Error {
1122
- constructor(n, t) {
1123
- super(n), this.title = t, this.name = "PayConductorTokenizerApiError";
1124
- }
1125
- }
1126
- class ze {
1127
- constructor(n) {
1128
- this.publicKey = n;
1129
- }
1130
- async getSettings() {
1131
- const n = await fetch(`${this.baseUrl}/card-tokenization/settings`, {
1132
- method: "GET",
1133
- headers: this.headers
1134
- });
1135
- return n.ok || await this.parseResponseError("Failed to fetch settings", n), await n.json();
1136
- }
1137
- async createToken(n) {
1138
- const t = await fetch(`${this.baseUrl}/card-tokenization/tokenize`, {
1139
- method: "POST",
1140
- headers: this.headers,
1141
- body: JSON.stringify(n)
1142
- });
1143
- return t.ok || await this.parseResponseError("Failed to generate token", t), await t.json();
1144
- }
1145
- async saveTokens(n, t, a) {
1146
- const r = await fetch(`${this.baseUrl}/card-tokenization/save-tokens/${t}/${a}`, {
1147
- method: "POST",
1148
- headers: this.headers,
1149
- body: JSON.stringify(n)
1150
- });
1151
- r.ok || await this.parseResponseError("Failed to save tokens", r);
1152
- }
1153
- async parseResponseError(n, t) {
1154
- var r, o, d, s;
1155
- let a = "";
1156
- try {
1157
- const i = await t.json();
1158
- i != null && i.message ? a = i.message : (r = i == null ? void 0 : i.error) != null && r.message ? a = i.error : (d = (o = i == null ? void 0 : i.error) == null ? void 0 : o.value) != null && d.message ? a = i.error.value.message : (s = i == null ? void 0 : i.value) != null && s.message ? a = i.value.message : a = JSON.stringify(i);
1159
- } catch {
1160
- }
1161
- throw new Be(a, n);
1162
- }
1163
- get baseUrl() {
1164
- return typeof window < "u" && window.location.href.includes("localhost") ? "http://localhost:3000/api/v1/sdk" : "https://payconductor.ai/api/v1/sdk";
1165
- }
1166
- get headers() {
1167
- return {
1168
- Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
1169
- "Content-Type": "application/json"
1170
- };
1171
- }
1172
- }
1173
- class He {
1174
- constructor(n) {
1175
- this.input = n;
1176
- }
1177
- }
1178
- class Ye extends He {
1179
- constructor() {
1180
- super(...arguments);
1181
- p(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
1182
- }
1183
- async tokenize() {
1184
- if (!("publicKey" in this.input.setting))
1185
- throw new Error("MercadoPago public key is missing in settings");
1186
- if (!this.input.customer.documentNumber)
1187
- throw new Error("Customer document number is required for tokenization");
1188
- const t = window.MercadoPago;
1189
- if (!t) throw new Error("MercadoPago SDK not available");
1190
- const a = new t(this.input.setting.publicKey), {
1191
- expiration: r,
1192
- cvv: o,
1193
- number: d,
1194
- holderName: s
1195
- } = this.input.card;
1196
- return (await a.createCardToken({
1197
- cardExpirationMonth: String(r.month),
1198
- cardExpirationYear: String(r.year),
1199
- cardholderName: s,
1200
- cardNumber: d,
1201
- securityCode: o,
1202
- identificationType: this.input.customer.documentType === G.Cpf ? "CPF" : "CNPJ",
1203
- identificationNumber: this.input.customer.documentNumber
1204
- })).id;
1205
- }
1206
- }
1207
- const Ge = {
1208
- [I.MercadoPago]: Ye
1209
- };
1210
- class Ve {
1211
- constructor(n) {
1212
- p(this, "api");
1213
- this.publicKey = n, this.api = new ze(this.publicKey);
1214
- }
1215
- async tokenizeCard(n) {
1216
- this.validateCard(n);
1217
- const {
1218
- customerId: t,
1219
- token: a
1220
- } = await this.api.createToken({
1221
- card: n.card,
1222
- customer: n.customer,
1223
- saveCard: !1
1224
- }), {
1225
- settings: r
1226
- } = await this.api.getSettings(), d = (await Promise.all(r.map(async (s) => {
1227
- const i = Ge[s.key];
1228
- if (!i) return null;
1229
- const l = new i({
1230
- ...n,
1231
- setting: s.settings
1232
- });
1233
- return await k(l.scriptUrl), {
1234
- token: await l.tokenize(),
1235
- integrationId: s.integrationId,
1236
- providerKey: s.key
1237
- };
1238
- }))).filter((s) => s !== null);
1239
- return d.length > 0 && await this.api.saveTokens(d, t, a), a;
1240
- }
1241
- validateCard(n) {
1242
- const {
1243
- number: t,
1244
- cvv: a,
1245
- expiration: r,
1246
- holderName: o
1247
- } = n.card;
1248
- if (!t || !a || !(r != null && r.month) || !(r != null && r.year) || !o)
1249
- throw new Error("Invalid card data");
1250
- }
1251
- }
1252
- function rt(e) {
1253
- const n = new Ve(e.publicKey);
1254
- return {
1255
- tokenizeCard: async (a) => {
1256
- var r, o;
1257
- try {
1258
- const d = await n.tokenizeCard(a);
1259
- return (r = e.onSuccess) == null || r.call(e, d), d;
1260
- } catch (d) {
1261
- const s = d instanceof Error ? d : new Error("Tokenization failed");
1262
- return (o = e.onError) == null || o.call(e, s), null;
1263
- }
1264
- }
1265
- };
1266
- }
1267
- export {
1268
- ue as ALLOWED_ORIGINS,
1269
- re as CardBrand,
1270
- te as ChargeStatusDetail,
1271
- ie as CurrencyType,
1272
- oe as DeviceType,
1273
- G as DocumentType,
1274
- Xe as ERROR_CODES,
1275
- de as ErrorCode,
1276
- le as IFRAME_BASE_URL,
1277
- B as IFRAME_DEFAULT_HEIGHT_VALUE,
1278
- v as IncomingMessage,
1279
- se as InputStyleKey,
1280
- I as IntegrationProvider,
1281
- _ as OrganizationEnvironment,
1282
- M as OutgoingMessage,
1283
- P as POST_MESSAGES,
1284
- Ze as PayConductor,
1285
- Ke as PayConductor3DSSDK,
1286
- Qe as PayConductorCheckoutElement,
1287
- et as PayConductorThreeDSElement,
1288
- Ve as PayConductorTokenizerSDK,
1289
- Z as PaymentMethod,
1290
- Q as PaymentMethodLayout,
1291
- ee as PaymentStatus,
1292
- he as REQUEST_TIMEOUT,
1293
- me as SKELETON_CSS,
1294
- z as SKELETON_STYLE_ID,
1295
- ae as ThreeDSResultStatus,
1296
- ne as ThreeDsAuthenticationStatus,
1297
- fe as buildIframeUrl,
1298
- Ze as default,
1299
- Je as defaultTheme,
1300
- ye as generateRequestId,
1301
- we as isValidOrigin,
1302
- k as loadScript,
1303
- tt as usePayConductor,
1304
- nt as usePayconductorElement,
1305
- at as useThreeDS,
1306
- rt as useTokenizer
1307
- };
1308
- //# sourceMappingURL=index.es.js.map
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