@payconductor/react 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/dist/esm/three-ds.d.ts +1 -0
  3. package/dist/esm/tokenize.d.ts +1 -0
  4. package/dist/index.cjs.js +48 -1
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.d.ts +4 -0
  7. package/dist/index.es.js +1020 -227
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/payconductor/constants.d.ts +1 -0
  10. package/dist/payconductor/hooks/index.d.ts +4 -0
  11. package/dist/payconductor/hooks/use-element.d.ts +1 -1
  12. package/dist/payconductor/hooks/use-three-ds.d.ts +13 -0
  13. package/dist/payconductor/hooks/use-tokenize.d.ts +11 -0
  14. package/dist/payconductor/iframe/types.d.ts +51 -1
  15. package/dist/payconductor/internal.d.ts +1 -1
  16. package/dist/payconductor/loader.d.ts +1 -0
  17. package/dist/payconductor/payconductor-three-ds.d.ts +5 -0
  18. package/dist/payconductor/three-ds/browser.d.ts +13 -0
  19. package/dist/payconductor/three-ds/handler.d.ts +11 -0
  20. package/dist/payconductor/three-ds/index.d.ts +1 -0
  21. package/dist/payconductor/three-ds/providers/index.d.ts +6 -0
  22. package/dist/payconductor/three-ds/providers/mercado-pago.d.ts +9 -0
  23. package/dist/payconductor/three-ds/providers/pagarme.d.ts +9 -0
  24. package/dist/payconductor/three-ds/providers/pagseguro.d.ts +7 -0
  25. package/dist/payconductor/three-ds/providers/payconductor.d.ts +7 -0
  26. package/dist/payconductor/three-ds/types.d.ts +75 -0
  27. package/dist/payconductor/tokenize/api.d.ts +25 -0
  28. package/dist/payconductor/tokenize/index.d.ts +1 -0
  29. package/dist/payconductor/tokenize/providers/index.d.ts +5 -0
  30. package/dist/payconductor/tokenize/providers/mercado-pago.d.ts +6 -0
  31. package/dist/payconductor/tokenize/tokenize.d.ts +9 -0
  32. package/dist/payconductor/tokenize/types.d.ts +63 -0
  33. package/dist/payconductor/types.d.ts +4 -3
  34. package/dist/payconductor/utils.d.ts +2 -1
  35. package/package.json +1 -1
package/dist/index.es.js CHANGED
@@ -1,22 +1,73 @@
1
- import { jsx as D } from "react/jsx-runtime";
2
- import { useState as A, useEffect as U, useRef as G } from "react";
3
- const F = "https://iframe.payconductor.ai/v1", v = "http://localhost:5175/v1", q = 3e4, W = "600px";
4
- var T = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(T || {}), h = /* @__PURE__ */ ((e) => (e.Ready = "Ready", e.Error = "Error", e.PaymentComplete = "PaymentComplete", e.PaymentFailed = "PaymentFailed", e.PaymentPending = "PaymentPending", e.ValidationError = "ValidationError", e.PaymentMethodSelected = "PaymentMethodSelected", e))(h || {});
5
- const B = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") && !window.location.search.includes("production"), j = B ? v : F, k = [v, F], Q = W, $ = q, f = {
6
- INIT: T.Init,
7
- CONFIG: T.Config,
8
- UPDATE: T.Update,
9
- CONFIRM_PAYMENT: T.ConfirmPayment,
10
- VALIDATE: T.Validate,
11
- RESET: T.Reset,
12
- READY: h.Ready,
13
- ERROR: h.Error,
14
- PAYMENT_COMPLETE: h.PaymentComplete,
15
- PAYMENT_FAILED: h.PaymentFailed,
16
- PAYMENT_PENDING: h.PaymentPending,
17
- VALIDATION_ERROR: h.ValidationError,
18
- PAYMENT_METHOD_SELECTED: h.PaymentMethodSelected
19
- }, oe = {
1
+ var W = Object.defineProperty;
2
+ var G = (e, r, t) => r in e ? W(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var p = (e, r, t) => G(e, typeof r != "symbol" ? r + "" : r, t);
4
+ import { jsx as _, jsxs as $ } from "react/jsx-runtime";
5
+ import { useState as b, useEffect as L, useRef as J } from "react";
6
+ const K = "https://iframe.payconductor.ai/v1", z = "http://localhost:5175/v1", Z = 3e4, X = "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 || {}), B = /* @__PURE__ */ ((e) => (e.Succeeded = "succeeded", e.Pending = "pending", e.Failed = "failed", e))(B || {}), te = /* @__PURE__ */ ((e) => (e.Android = "android", e.IOS = "ios", e.Web = "web", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Padding = "padding", e.Radius = "radius", e.Color = "color", e.Background = "background", e.Shadow = "shadow", e))(ne || {}), v = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(v || {}), P = /* @__PURE__ */ ((e) => (e.Ready = "Ready", e.Error = "Error", 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))(P || {}), re = /* @__PURE__ */ ((e) => (e.InvalidClient = "InvalidClient", e.InvalidToken = "InvalidToken", e.NetworkError = "NetworkError", e.IframeNotReady = "IframeNotReady", e.PaymentDeclined = "PaymentDeclined", e.ValidationError = "ValidationError", e.Timeout = "Timeout", e))(re || {});
8
+ const He = {
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
+ }, ae = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") && !window.location.search.includes("production"), oe = ae ? z : K, ie = [z, K], U = X, se = Z, E = {
56
+ INIT: v.Init,
57
+ CONFIG: v.Config,
58
+ UPDATE: v.Update,
59
+ CONFIRM_PAYMENT: v.ConfirmPayment,
60
+ VALIDATE: v.Validate,
61
+ RESET: v.Reset,
62
+ READY: P.Ready,
63
+ ERROR: P.Error,
64
+ PAYMENT_COMPLETE: P.PaymentComplete,
65
+ PAYMENT_FAILED: P.PaymentFailed,
66
+ PAYMENT_PENDING: P.PaymentPending,
67
+ VALIDATION_ERROR: P.ValidationError,
68
+ PAYMENT_METHOD_SELECTED: P.PaymentMethodSelected,
69
+ RESIZE: P.Resize
70
+ }, Ye = {
20
71
  INVALID_CLIENT: "InvalidClient",
21
72
  INVALID_TOKEN: "InvalidToken",
22
73
  NETWORK_ERROR: "NetworkError",
@@ -25,16 +76,468 @@ const B = typeof window < "u" && (window.location.hostname === "localhost" || wi
25
76
  VALIDATION_ERROR: "ValidationError",
26
77
  TIMEOUT: "Timeout"
27
78
  };
28
- function z(e) {
79
+ function de() {
80
+ return {
81
+ userAgent: navigator.userAgent,
82
+ language: navigator.language,
83
+ colorDepth: String(screen.colorDepth),
84
+ screenHeight: String(screen.height),
85
+ screenWidth: String(screen.width),
86
+ timeZoneOffset: String((/* @__PURE__ */ new Date()).getTimezoneOffset()),
87
+ javaEnabled: !1,
88
+ javaScriptEnabled: !0
89
+ };
90
+ }
91
+ var C = /* @__PURE__ */ ((e) => (e.Success = "Success", e.Failed = "Failed", e.Timeout = "Timeout", e))(C || {});
92
+ class A {
93
+ constructor(r, t) {
94
+ p(this, "overlay", null);
95
+ p(this, "modalContent", null);
96
+ this.data = r, this.options = t;
97
+ }
98
+ fail(r) {
99
+ var n, a;
100
+ const t = new Error(r);
101
+ return (a = (n = this.options).onError) == null || a.call(n, t), {
102
+ status: "Failed",
103
+ error: t
104
+ };
105
+ }
106
+ //#region Modal
107
+ showModal() {
108
+ 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;
109
+ }
110
+ closeModal() {
111
+ this.overlay && (this.overlay.remove(), this.overlay = null, this.modalContent = null);
112
+ }
113
+ resolveContainer() {
114
+ return this.modalContent ?? this.showModal();
115
+ }
116
+ injectStyles() {
117
+ if (document.getElementById("payconductor-3ds-styles")) return;
118
+ const r = document.createElement("style");
119
+ r.id = "payconductor-3ds-styles", r.textContent = `
120
+ #payconductor-3ds-overlay {
121
+ position: fixed;
122
+ inset: 0;
123
+ z-index: 99999;
124
+ display: flex;
125
+ align-items: center;
126
+ justify-content: center;
127
+ background: rgba(0, 0, 0, 0.6);
128
+ }
129
+ #payconductor-3ds-modal {
130
+ width: 500px;
131
+ max-width: 95vw;
132
+ min-height: 600px;
133
+ border-radius: 8px;
134
+ overflow: hidden;
135
+ background: #fff;
136
+ }
137
+ #payconductor-3ds-modal iframe {
138
+ width: 100%;
139
+ height: 600px;
140
+ border: none;
141
+ display: block;
142
+ }
143
+ @media only screen and (max-width: 600px) {
144
+ #payconductor-3ds-modal {
145
+ width: 100vw;
146
+ max-width: 100vw;
147
+ min-height: 440px;
148
+ border-radius: 0;
149
+ }
150
+ #payconductor-3ds-modal iframe {
151
+ height: 440px;
152
+ }
153
+ }
154
+ `, document.head.appendChild(r);
155
+ }
156
+ //#endregion
157
+ }
158
+ const ce = 5 * 60 * 1e3;
159
+ class ue extends A {
160
+ constructor() {
161
+ super(...arguments);
162
+ p(this, "iframe", null);
163
+ p(this, "messageListener", null);
164
+ p(this, "timeoutId", null);
165
+ }
166
+ async authenticate() {
167
+ const {
168
+ threeDsUrl: t,
169
+ creq: n
170
+ } = this.data;
171
+ if (!t || !n)
172
+ return this.fail("Missing threeDsUrl or creq");
173
+ const a = this.resolveContainer();
174
+ return new Promise((o) => {
175
+ var u;
176
+ this.iframe = document.createElement("iframe"), this.iframe.name = "payconductor-3ds-challenge", this.iframe.id = "payconductor-3ds-challenge", a.appendChild(this.iframe), this.messageListener = (m) => {
177
+ var h, c, w;
178
+ ((h = m.data) == null ? void 0 : h.status) === "COMPLETE" && (this.cleanup(), (w = (c = this.options).onComplete) == null || w.call(c), o({
179
+ status: C.Success
180
+ }));
181
+ }, window.addEventListener("message", this.messageListener), this.timeoutId = setTimeout(() => {
182
+ var m, h;
183
+ this.cleanup(), (h = (m = this.options).onTimeout) == null || h.call(m), o({
184
+ status: C.Timeout
185
+ });
186
+ }, this.options.timeoutMs ?? ce);
187
+ const d = (u = this.iframe.contentWindow) == null ? void 0 : u.document;
188
+ if (!d) {
189
+ this.cleanup(), o(this.fail("Cannot access iframe document"));
190
+ return;
191
+ }
192
+ const s = d.createElement("form");
193
+ s.name = "threeDsChallengeForm", s.setAttribute("target", "payconductor-3ds-challenge"), s.setAttribute("method", "post"), s.setAttribute("action", t);
194
+ const i = d.createElement("input");
195
+ i.setAttribute("type", "hidden"), i.setAttribute("name", "creq"), i.setAttribute("value", n), s.appendChild(i), this.iframe.appendChild(s), s.submit();
196
+ });
197
+ }
198
+ cleanup() {
199
+ 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();
200
+ }
201
+ }
202
+ const k = /* @__PURE__ */ new Map();
203
+ function R(e) {
204
+ const r = k.get(e);
205
+ if (r) return r;
206
+ const t = new Promise((n, a) => {
207
+ if (document.querySelector(`script[src="${e}"]`)) {
208
+ n();
209
+ return;
210
+ }
211
+ const o = document.createElement("script");
212
+ o.src = e, o.async = !0, o.onload = () => n(), o.onerror = () => {
213
+ k.delete(e), a(new Error(`Failed to load script: ${e}`));
214
+ }, (document.head || document.body).appendChild(o);
215
+ });
216
+ return k.set(e, t), t;
217
+ }
218
+ const le = "https://static.payzen.lat/static/js/authenticate-client/V1.0/kr-authenticate.umd", he = 10 * 60 * 1e3;
219
+ class me extends A {
220
+ constructor() {
221
+ super(...arguments);
222
+ p(this, "timeoutId", null);
223
+ }
224
+ async authenticate() {
225
+ const {
226
+ operationUrl: t,
227
+ publicKey: n
228
+ } = this.data;
229
+ if (!t || !n)
230
+ return this.fail("Missing operationUrl or publicKey");
231
+ try {
232
+ await R(le);
233
+ } catch {
234
+ return this.fail("Failed to load 3DS SDK");
235
+ }
236
+ const a = window.KrAuthenticate;
237
+ return a ? new Promise((o) => {
238
+ this.timeoutId = setTimeout(() => {
239
+ var s, i;
240
+ this.cleanup(), (i = (s = this.options).onTimeout) == null || i.call(s), o({
241
+ status: C.Timeout
242
+ });
243
+ }, this.options.timeoutMs ?? he), new a(n).authenticate(t, () => {
244
+ var s, i;
245
+ this.cleanup(), (i = (s = this.options).onComplete) == null || i.call(s), o({
246
+ status: C.Success
247
+ });
248
+ });
249
+ }) : this.fail("KrAuthenticate not available");
250
+ }
251
+ cleanup() {
252
+ this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null);
253
+ }
254
+ }
255
+ const fe = {
256
+ Production: "https://3ds-nx-js.stone.com.br/live/v2/3ds2.min",
257
+ Sandbox: "https://3ds-nx-js.stone.com.br/test/v2/3ds2.min"
258
+ }, ye = 5 * 60 * 1e3;
259
+ function we() {
260
+ const e = window.innerWidth;
261
+ return e <= 480 ? "01" : e <= 768 ? "02" : e <= 1024 ? "03" : "04";
262
+ }
263
+ class ge extends A {
264
+ constructor() {
265
+ super(...arguments);
266
+ p(this, "timeoutId", null);
267
+ p(this, "methodContainer", null);
268
+ }
269
+ async authenticate() {
270
+ const {
271
+ authToken: t,
272
+ card: n
273
+ } = this.data;
274
+ if (!t) return this.fail("Missing authToken for PagarMe 3DS");
275
+ if (!n) return this.fail("Missing card data for PagarMe 3DS");
276
+ const a = this.data.environment ?? "Production";
277
+ try {
278
+ await R(fe[a]);
279
+ } catch {
280
+ return this.fail("Failed to load Stone 3DS SDK");
281
+ }
282
+ const o = window.TDS;
283
+ if (!o) return this.fail("Stone TDS SDK not available");
284
+ const d = this.resolveContainer();
285
+ return this.methodContainer = document.createElement("div"), this.methodContainer.style.display = "none", document.body.appendChild(this.methodContainer), new Promise((s) => {
286
+ this.timeoutId = setTimeout(() => {
287
+ var i, u;
288
+ this.cleanup(), (u = (i = this.options).onTimeout) == null || u.call(i), s({
289
+ status: C.Timeout
290
+ });
291
+ }, this.options.timeoutMs ?? ye), o.init({
292
+ token: t,
293
+ tds_method_container_element: this.methodContainer,
294
+ challenge_container_element: d,
295
+ use_default_challenge_iframe_style: !0,
296
+ challenge_window_size: we()
297
+ }, this.buildOrderData()).then((i) => {
298
+ var m, h;
299
+ if (this.cleanup(), !(i != null && i.length)) {
300
+ s(this.fail("PagarMe 3DS returned no response"));
301
+ return;
302
+ }
303
+ const u = i[0];
304
+ if (u.challenge_canceled) {
305
+ s(this.fail("3DS challenge canceled by user"));
306
+ return;
307
+ }
308
+ u.trans_status === "Y" || u.trans_status === "A" ? ((h = (m = this.options).onComplete) == null || h.call(m), s({
309
+ status: C.Success,
310
+ dsTransactionId: u.tds_server_trans_id
311
+ })) : s(this.fail(`3DS failed with status: ${u.trans_status}`));
312
+ }).catch((i) => {
313
+ this.cleanup(), s(this.fail(i instanceof Error ? i.message : "PagarMe 3DS failed"));
314
+ });
315
+ });
316
+ }
317
+ cleanup() {
318
+ this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.methodContainer && (this.methodContainer.remove(), this.methodContainer = null), this.closeModal();
319
+ }
320
+ buildOrderData() {
321
+ var d;
322
+ const {
323
+ card: t,
324
+ customer: n,
325
+ amount: a,
326
+ billingAddress: o
327
+ } = this.data;
328
+ return {
329
+ payments: [{
330
+ payment_method: "credit_card",
331
+ credit_card: {
332
+ card: {
333
+ number: t == null ? void 0 : t.number,
334
+ holder_name: t == null ? void 0 : t.holderName,
335
+ exp_month: Number(t == null ? void 0 : t.expMonth),
336
+ exp_year: Number(t == null ? void 0 : t.expYear),
337
+ billing_address: o ? {
338
+ country: o.country,
339
+ state: o.state,
340
+ city: o.city,
341
+ zip_code: o.zipCode,
342
+ line_1: `${o.number}, ${o.street}${o.district ? `, ${o.district}` : ""}`,
343
+ line_2: o.complement ?? ""
344
+ } : void 0
345
+ }
346
+ },
347
+ amount: a
348
+ }],
349
+ ...n ? {
350
+ customer: {
351
+ name: n.name,
352
+ email: n.email,
353
+ ...n.document ? {
354
+ document: n.document
355
+ } : {},
356
+ ...(d = n.phones) != null && d.length ? {
357
+ phones: Object.fromEntries(n.phones.map((s) => [s.type === "HOME" ? "home_phone" : "mobile_phone", {
358
+ country_code: s.countryCode,
359
+ area_code: s.areaCode,
360
+ number: s.number
361
+ }]))
362
+ } : {}
363
+ }
364
+ } : {}
365
+ };
366
+ }
367
+ }
368
+ const Ee = "https://assets.pagseguro.com.br/checkout-sdk-js/rc/dist/browser/pagseguro.min";
369
+ class Ce extends A {
370
+ async authenticate() {
371
+ var h, c, w;
372
+ const {
373
+ authToken: r,
374
+ card: t,
375
+ customer: n,
376
+ amount: a,
377
+ currency: o,
378
+ billingAddress: d
379
+ } = this.data;
380
+ if (!r) return this.fail("Missing authToken (session) for PagSeguro 3DS");
381
+ if (!t) return this.fail("Missing card data for PagSeguro 3DS");
382
+ if (!n) return this.fail("Missing customer data for PagSeguro 3DS");
383
+ if (!a) return this.fail("Missing amount for PagSeguro 3DS");
384
+ if (!d) return this.fail("Missing billingAddress for PagSeguro 3DS");
385
+ const s = this.data.environment === "Sandbox" ? "SANDBOX" : "PROD";
386
+ try {
387
+ await R(Ee);
388
+ } catch {
389
+ return this.fail("Failed to load PagSeguro SDK");
390
+ }
391
+ const i = window.PagSeguro;
392
+ if (!i) return this.fail("PagSeguro SDK not available");
393
+ i.setUp({
394
+ session: r,
395
+ env: s
396
+ });
397
+ const u = ((h = n.phones) == null ? void 0 : h.map((g) => ({
398
+ country: g.countryCode,
399
+ area: g.areaCode,
400
+ number: g.number,
401
+ type: g.type ?? "MOBILE"
402
+ }))) ?? [{
403
+ country: "55",
404
+ area: "11",
405
+ number: "999999999",
406
+ type: "MOBILE"
407
+ }];
408
+ u.some((g) => g.type === "MOBILE") || (u[0].type = "MOBILE");
409
+ try {
410
+ const g = await i.authenticate3DS({
411
+ data: {
412
+ customer: {
413
+ name: n.name,
414
+ email: n.email,
415
+ phones: u
416
+ },
417
+ paymentMethod: {
418
+ type: this.data.installments === 0 ? "DEBIT_CARD" : "CREDIT_CARD",
419
+ installments: this.data.installments ?? 1,
420
+ card: {
421
+ number: t.number,
422
+ expMonth: t.expMonth,
423
+ expYear: t.expYear,
424
+ holder: {
425
+ name: t.holderName
426
+ }
427
+ }
428
+ },
429
+ amount: {
430
+ value: a,
431
+ currency: o ?? "BRL"
432
+ },
433
+ billingAddress: {
434
+ street: d.street,
435
+ number: d.number,
436
+ complement: d.complement,
437
+ regionCode: d.state,
438
+ country: d.country.length === 2 ? this.toAlpha3(d.country) : d.country,
439
+ city: d.city,
440
+ postalCode: d.zipCode.replace(/\D/g, "")
441
+ },
442
+ dataOnly: !1
443
+ }
444
+ });
445
+ return g.status === "AUTH_FLOW_COMPLETED" || g.status === "AUTH_NOT_SUPPORTED" ? ((w = (c = this.options).onComplete) == null || w.call(c), {
446
+ status: C.Success,
447
+ dsTransactionId: g.id
448
+ }) : g.status === "CHANGE_PAYMENT_METHOD" ? this.fail("PagSeguro requires a different payment method") : {
449
+ status: C.Success,
450
+ dsTransactionId: g.id
451
+ };
452
+ } catch (g) {
453
+ return this.fail(g instanceof Error ? g.message : "PagSeguro 3DS failed");
454
+ }
455
+ }
456
+ cleanup() {
457
+ }
458
+ toAlpha3(r) {
459
+ return {
460
+ BR: "BRA",
461
+ US: "USA",
462
+ AR: "ARG",
463
+ CL: "CHL",
464
+ CO: "COL",
465
+ MX: "MEX",
466
+ PE: "PER",
467
+ UY: "URY"
468
+ }[r.toUpperCase()] ?? r;
469
+ }
470
+ }
471
+ const Se = {
472
+ MercadoPago: ue,
473
+ PayConductor: me,
474
+ PagarMe: ge,
475
+ PagSeguro: Ce
476
+ };
477
+ class H {
478
+ constructor(r) {
479
+ p(this, "data");
480
+ p(this, "provider", null);
481
+ this.data = r;
482
+ }
483
+ get needsChallenge() {
484
+ return this.data.status === "NeedChallenge" || this.data.statusDetail === "ThreeDsAwaitingChallenge";
485
+ }
486
+ get acquirer() {
487
+ return this.data.acquirer;
488
+ }
489
+ async authenticate(r) {
490
+ if (!this.needsChallenge)
491
+ return {
492
+ status: C.Success
493
+ };
494
+ const {
495
+ acquirer: t
496
+ } = this.data;
497
+ if (!t)
498
+ return {
499
+ status: C.Failed,
500
+ error: new Error("Missing 3DS acquirer")
501
+ };
502
+ const n = Se[t];
503
+ if (!n)
504
+ return {
505
+ status: C.Failed,
506
+ error: new Error(`Unsupported 3DS provider: ${t}`)
507
+ };
508
+ const a = {
509
+ ...r,
510
+ threeDSecure: this.data
511
+ };
512
+ return this.provider = new n(this.data, a), this.provider.authenticate();
513
+ }
514
+ destroy() {
515
+ this.provider && (this.provider.cleanup(), this.provider = null);
516
+ }
517
+ }
518
+ const F = "payconductor-skeleton-style", pe = `
519
+ @keyframes payconductor-shimmer {
520
+ 0% { background-position: -200% 0; }
521
+ 100% { background-position: 200% 0; }
522
+ }
523
+ .payconductor-skeleton {
524
+ background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
525
+ background-size: 200% 100%;
526
+ animation: payconductor-shimmer 1.5s infinite linear;
527
+ border-radius: 4px;
528
+ width: 100%;
529
+ }
530
+ `;
531
+ function Pe(e) {
29
532
  const r = new URLSearchParams({
30
533
  publicKey: e.publicKey
31
534
  });
32
- return `${j}?${r.toString()}`;
535
+ return `${oe}?${r.toString()}`;
33
536
  }
34
- function J() {
537
+ function Te() {
35
538
  return crypto.randomUUID();
36
539
  }
37
- function X(e, r) {
540
+ function be(e, r) {
38
541
  return r.some((t) => {
39
542
  try {
40
543
  return new URL(t).origin === e;
@@ -43,184 +546,229 @@ function X(e, r) {
43
546
  }
44
547
  });
45
548
  }
46
- function N() {
549
+ function x() {
47
550
  return /* @__PURE__ */ new Map();
48
551
  }
49
- function C(e, r, t, n) {
50
- return new Promise((d, u) => {
552
+ function D(e, r, t, n) {
553
+ return new Promise((a, o) => {
51
554
  if (!e || !("contentWindow" in e)) {
52
- u(new Error("Iframe not defined"));
555
+ o(new Error("Iframe not defined"));
53
556
  return;
54
557
  }
55
558
  if (!(e != null && e.contentWindow)) {
56
- u(new Error("Iframe not ready"));
559
+ o(new Error("Iframe not ready"));
57
560
  return;
58
561
  }
59
562
  if (!r) {
60
- u(new Error("Pending requests not initialized"));
563
+ o(new Error("Pending requests not initialized"));
61
564
  return;
62
565
  }
63
- const s = J();
64
- r.set(s, {
65
- resolve: d,
66
- reject: u
566
+ const d = Te();
567
+ r.set(d, {
568
+ resolve: a,
569
+ reject: o
67
570
  }), e.contentWindow.postMessage({
68
571
  type: t,
69
572
  data: n,
70
- requestId: s
573
+ requestId: d
71
574
  }, "*"), setTimeout(() => {
72
- r != null && r.has(s) && (r.delete(s), u(new Error("Request timeout")));
73
- }, $);
575
+ r != null && r.has(d) && (r.delete(d), o(new Error("Request timeout")));
576
+ }, se);
74
577
  });
75
578
  }
76
- function b(e, r, t) {
77
- return C(e, r, f.CONFIRM_PAYMENT, {
579
+ function Ie(e, r, t) {
580
+ return D(e, r, E.CONFIRM_PAYMENT, t);
581
+ }
582
+ async function ve(e, r, t) {
583
+ var s, i, u, m, h;
584
+ const n = await Ie(e, r, {
78
585
  orderId: t.orderId
79
586
  });
587
+ if (!(n.statusDetail === "ThreeDsAwaitingChallenge" || ((s = n.threeDSecure) == null ? void 0 : s.status) === "NeedChallenge") || !n.threeDSecure) return n;
588
+ (i = t.onThreeDSChallenge) == null || i.call(t);
589
+ const o = new H({
590
+ ...n.threeDSecure,
591
+ statusDetail: n.statusDetail
592
+ }), d = await o.authenticate({
593
+ onComplete: t.onThreeDSComplete,
594
+ onError: t.onThreeDSError
595
+ });
596
+ return o.destroy(), d.status !== C.Success ? {
597
+ ...n,
598
+ status: B.Failed,
599
+ message: d.status === C.Timeout ? "3DS challenge timed out" : ((u = d.error) == null ? void 0 : u.message) || "3DS challenge failed"
600
+ } : await D(e, r, E.CONFIRM_PAYMENT, {
601
+ orderId: t.orderId,
602
+ confirmThreeDS: !0,
603
+ threeDSecure: {
604
+ type: "internal",
605
+ authToken: (m = n.threeDSecure) == null ? void 0 : m.authToken,
606
+ dsTransactionId: d.dsTransactionId ?? ((h = n.threeDSecure) == null ? void 0 : h.dsTransactionId),
607
+ browser: de()
608
+ }
609
+ });
80
610
  }
81
- function Z(e, r, t) {
82
- return C(e, r, f.VALIDATE, t);
611
+ function De(e, r, t) {
612
+ return D(e, r, E.VALIDATE, t);
83
613
  }
84
- function g(e, r) {
85
- return C(e, r, f.RESET);
614
+ function Me(e, r) {
615
+ return D(e, r, E.RESET);
86
616
  }
87
- function x(e, r, t) {
88
- return C(e, r, f.CONFIG, t);
617
+ function _e(e, r, t) {
618
+ return D(e, r, E.CONFIG, t);
89
619
  }
90
- function p(e, r, t) {
91
- return C(e, r, f.INIT, t);
620
+ function Ae(e, r, t) {
621
+ return D(e, r, E.INIT, t);
92
622
  }
93
- function ee(e, r, t, n, d, u, s, R, m, P) {
94
- const L = e.data, {
95
- requestId: l,
96
- type: E,
623
+ function Re(e, r, t, n, a, o, d, s, i) {
624
+ const u = e.data, {
625
+ requestId: m,
626
+ type: h,
97
627
  data: c,
98
- error: y
99
- } = L;
100
- if (E === f.READY) {
101
- if (t(!0), window.PayConductor && window.PayConductor.frame && (window.PayConductor.frame.isReady = !0), d == null || d(), l && (r != null && r.has(l))) {
628
+ error: w
629
+ } = u;
630
+ if (h === E.READY) {
631
+ if (n == null || n(), m && (r != null && r.has(m))) {
102
632
  const {
103
- resolve: w
104
- } = r.get(l);
105
- r.delete(l), w(c);
633
+ resolve: g
634
+ } = r.get(m);
635
+ r.delete(m), g(c);
106
636
  }
107
637
  return;
108
638
  }
109
- if (X(e.origin, k)) {
110
- if (l && r && r.has(l)) {
639
+ if (be(e.origin, ie)) {
640
+ if (m && r && r.has(m)) {
111
641
  const {
112
- resolve: w,
113
- reject: M
114
- } = r.get(l);
115
- r.delete(l), y ? M(new Error(String(y.message))) : w(c);
642
+ resolve: g,
643
+ reject: I
644
+ } = r.get(m);
645
+ r.delete(m), w ? I(new Error(String(w.message))) : g(c);
116
646
  return;
117
647
  }
118
- if (E === f.ERROR) {
119
- n((y == null ? void 0 : y.message) || "Unknown error"), u == null || u(new Error(String(y == null ? void 0 : y.message)));
648
+ if (h === E.ERROR) {
649
+ t((w == null ? void 0 : w.message) || "Unknown error"), a == null || a(new Error(String(w == null ? void 0 : w.message)));
120
650
  return;
121
651
  }
122
- if (E === f.PAYMENT_COMPLETE) {
123
- c && typeof c == "object" && "status" in c && (s == null || s(c));
652
+ if (h === E.PAYMENT_COMPLETE) {
653
+ c && typeof c == "object" && "status" in c && (o == null || o(c));
124
654
  return;
125
655
  }
126
- if (E === f.PAYMENT_FAILED) {
127
- c && typeof c == "object" && "status" in c && (R == null || R(c));
656
+ if (h === E.PAYMENT_FAILED) {
657
+ c && typeof c == "object" && "status" in c && (d == null || d(c));
128
658
  return;
129
659
  }
130
- if (E === f.PAYMENT_PENDING) {
131
- c && typeof c == "object" && "status" in c && (m == null || m(c));
660
+ if (h === E.PAYMENT_PENDING) {
661
+ c && typeof c == "object" && "status" in c && (s == null || s(c));
132
662
  return;
133
663
  }
134
- if (E === f.PAYMENT_METHOD_SELECTED) {
135
- c && typeof c == "object" && "paymentMethod" in c && (P == null || P(c.paymentMethod));
664
+ if (h === E.PAYMENT_METHOD_SELECTED) {
665
+ c && typeof c == "object" && "paymentMethod" in c && (i == null || i(c.paymentMethod));
136
666
  return;
137
667
  }
668
+ E.RESIZE;
138
669
  }
139
670
  }
140
- function ae(e) {
141
- const [r, t] = A(
671
+ function je(e) {
672
+ const [r, t] = b(
142
673
  () => !1
143
- ), [n, d] = A(
144
- () => !1
145
- ), [u, s] = A(() => null), [R, m] = A(
674
+ ), [n, a] = b(() => null), [o, d] = b(
146
675
  () => ""
147
- ), [P, L] = A(() => null);
148
- return U(() => {
149
- const l = (...o) => {
150
- e.debug && console.log("[PayConductor]", ...o);
151
- }, E = z({
676
+ ), [s, i] = b(() => null);
677
+ return L(() => {
678
+ const u = (...l) => {
679
+ e.debug && console.log("[PayConductor]", ...l);
680
+ }, m = Pe({
152
681
  publicKey: e.publicKey
153
682
  });
154
- m(E), t(!0);
155
- const c = N();
156
- let y = !1;
157
- l("init", e.publicKey), l("iframeUrl", E);
683
+ d(m), t(!0);
684
+ const h = x();
685
+ let c = !1;
686
+ u("init", e.publicKey), u("iframeUrl", m);
158
687
  const w = () => {
159
- var I, i;
160
- const o = (i = (I = window.PayConductor) == null ? void 0 : I.frame) == null ? void 0 : i.iframe;
161
- if (o) {
162
- if (o instanceof HTMLIFrameElement) return o;
163
- if (typeof o == "object" && o !== null) {
164
- const a = o;
165
- if ("current" in a && a.current instanceof HTMLIFrameElement)
166
- return a.current;
167
- if ("value" in a && a.value instanceof HTMLIFrameElement)
168
- return a.value;
688
+ var S, f;
689
+ const l = (f = (S = window.PayConductor) == null ? void 0 : S.frame) == null ? void 0 : f.iframe;
690
+ if (l) {
691
+ if (l instanceof HTMLIFrameElement) return l;
692
+ if (typeof l == "object" && l !== null) {
693
+ const y = l;
694
+ if ("current" in y && y.current instanceof HTMLIFrameElement)
695
+ return y.current;
696
+ if ("value" in y && y.value instanceof HTMLIFrameElement)
697
+ return y.value;
169
698
  }
170
- return o;
699
+ return l;
171
700
  }
172
701
  return document.querySelector(
173
702
  ".payconductor-element iframe"
174
703
  ) ?? void 0;
175
- }, M = {
704
+ }, g = {
176
705
  get iframe() {
177
706
  return document.querySelector(
178
707
  ".payconductor-element iframe"
179
708
  ) ?? null;
180
709
  },
181
- set iframe(o) {
710
+ set iframe(l) {
182
711
  },
183
- iframeUrl: E,
184
- isReady: window.PayConductor && window.PayConductor.frame ? window.PayConductor.frame.isReady : !1,
712
+ iframeUrl: m,
185
713
  error: null
186
- }, V = {
714
+ }, I = {
187
715
  publicKey: e.publicKey,
188
716
  theme: e.theme,
189
717
  locale: e.locale,
190
718
  paymentMethods: e.paymentMethods,
191
719
  defaultPaymentMethod: e.defaultPaymentMethod
192
- }, Y = {
193
- confirmPayment: (o) => (l("→ CONFIRM_PAYMENT", {
194
- orderId: o.orderId
195
- }), b(w(), c, o)),
196
- validate: (o) => (l("→ VALIDATE", o), Z(w(), c, o)),
197
- reset: () => (l("→ RESET"), g(w(), c)),
198
- getSelectedPaymentMethod: () => P
720
+ }, M = {
721
+ confirmPayment: (l) => {
722
+ var f;
723
+ u("→ CONFIRM_PAYMENT", {
724
+ orderId: l.orderId
725
+ });
726
+ const S = w();
727
+ return S != null && S.contentWindow && S.contentWindow.postMessage(
728
+ {
729
+ type: E.CONFIG,
730
+ data: {
731
+ publicKey: e.publicKey,
732
+ orderId: l.orderId,
733
+ theme: e.theme,
734
+ locale: e.locale,
735
+ paymentMethods: e.paymentMethods,
736
+ defaultPaymentMethod: e.defaultPaymentMethod,
737
+ showPaymentButtons: e.showPaymentButtons,
738
+ nuPayConfig: e.nuPayConfig
739
+ }
740
+ },
741
+ "*"
742
+ ), I.orderId = l.orderId, (f = window.PayConductor) != null && f.config && (window.PayConductor.config.orderId = l.orderId), ve(S, h, l);
743
+ },
744
+ validate: (l) => (u("→ VALIDATE", l), De(w(), h, l)),
745
+ reset: () => (u("→ RESET"), Me(w(), h)),
746
+ getSelectedPaymentMethod: () => s
199
747
  };
200
748
  window.PayConductor = {
201
- frame: M,
202
- config: V,
203
- api: Y,
204
- selectedPaymentMethod: P
205
- }, l("registered"), window.dispatchEvent(
749
+ frame: g,
750
+ config: I,
751
+ api: M,
752
+ selectedPaymentMethod: s
753
+ }, u("registered"), window.dispatchEvent(
206
754
  new CustomEvent("payconductor:registered", {
207
755
  detail: window.PayConductor
208
756
  })
209
757
  );
210
- const S = async () => {
211
- if (!y) {
212
- const o = w();
213
- if (!o) {
214
- l("→ CONFIG skipped: iframe not found");
758
+ const T = async () => {
759
+ if (!c) {
760
+ const l = w();
761
+ if (!l) {
762
+ u("→ CONFIG skipped: iframe not found");
215
763
  return;
216
764
  }
217
- y = !0, l("→ CONFIG", {
765
+ c = !0, u("→ CONFIG", {
218
766
  theme: e.theme,
219
767
  locale: e.locale,
220
768
  paymentMethods: e.paymentMethods,
221
769
  defaultPaymentMethod: e.defaultPaymentMethod,
222
770
  showPaymentButtons: e.showPaymentButtons
223
- }), x(o, c, {
771
+ }), _e(l, h, {
224
772
  theme: e.theme,
225
773
  locale: e.locale,
226
774
  paymentMethods: e.paymentMethods,
@@ -229,61 +777,57 @@ function ae(e) {
229
777
  nuPayConfig: e.nuPayConfig
230
778
  });
231
779
  }
232
- }, K = (o) => {
233
- var I;
234
- (I = o.data) != null && I.type && l("←", o.data.type, o.data.data ?? ""), ee(
235
- o,
236
- c,
237
- (i) => {
238
- var a;
239
- d(i), M.isReady = i, (a = window.PayConductor) != null && a.frame && (window.PayConductor.frame.isReady = i), i && S();
240
- },
241
- (i) => {
242
- var a;
243
- s(i), M.error = i, (a = window.PayConductor) != null && a.frame && (window.PayConductor.frame.error = i);
780
+ }, q = (l) => {
781
+ var S;
782
+ (S = l.data) != null && S.type && u("←", l.data.type, l.data.data ?? ""), Re(
783
+ l,
784
+ h,
785
+ (f) => {
786
+ var y;
787
+ a(f), g.error = f, (y = window.PayConductor) != null && y.frame && (window.PayConductor.frame.error = f);
244
788
  },
245
789
  () => {
246
- var i;
247
- (i = e.onReady) == null || i.call(e);
790
+ var f;
791
+ (f = e.onReady) == null || f.call(e), T();
248
792
  },
249
- (i) => {
250
- var a;
251
- (a = e.onError) == null || a.call(e, i);
793
+ (f) => {
794
+ var y;
795
+ (y = e.onError) == null || y.call(e, f);
252
796
  },
253
- (i) => {
254
- var a;
255
- (a = e.onPaymentComplete) == null || a.call(e, i);
797
+ (f) => {
798
+ var y;
799
+ (y = e.onPaymentComplete) == null || y.call(e, f);
256
800
  },
257
- (i) => {
258
- var a;
259
- (a = e.onPaymentFailed) == null || a.call(e, i);
801
+ (f) => {
802
+ var y;
803
+ (y = e.onPaymentFailed) == null || y.call(e, f);
260
804
  },
261
- (i) => {
262
- var a;
263
- (a = e.onPaymentPending) == null || a.call(e, i);
805
+ (f) => {
806
+ var y;
807
+ (y = e.onPaymentPending) == null || y.call(e, f);
264
808
  },
265
- (i) => {
266
- var a;
267
- L(i), window.PayConductor && (window.PayConductor.selectedPaymentMethod = i), (a = e.onPaymentMethodSelected) == null || a.call(e, i);
809
+ (f) => {
810
+ var y;
811
+ i(f), window.PayConductor && (window.PayConductor.selectedPaymentMethod = f), (y = e.onPaymentMethodSelected) == null || y.call(e, f);
268
812
  }
269
813
  );
270
814
  };
271
- window.addEventListener("message", K);
272
- const H = () => {
273
- var I, i, a;
274
- const o = w();
275
- if (!o) return !1;
815
+ window.addEventListener("message", q);
816
+ const V = () => {
817
+ var S, f, y;
818
+ const l = w();
819
+ if (!l) return !1;
276
820
  try {
277
- if ((((I = o.contentDocument) == null ? void 0 : I.readyState) ?? ((a = (i = o.contentWindow) == null ? void 0 : i.document) == null ? void 0 : a.readyState)) === "complete")
278
- return S(), !0;
821
+ if ((((S = l.contentDocument) == null ? void 0 : S.readyState) ?? ((y = (f = l.contentWindow) == null ? void 0 : f.document) == null ? void 0 : y.readyState)) === "complete")
822
+ return T(), !0;
279
823
  } catch {
280
824
  }
281
825
  return !1;
282
826
  }, O = () => {
283
- if (H()) return;
284
- const o = w();
285
- if (o) {
286
- o.addEventListener("load", () => S(), {
827
+ if (V()) return;
828
+ const l = w();
829
+ if (l) {
830
+ l.addEventListener("load", () => T(), {
287
831
  once: !0
288
832
  });
289
833
  return;
@@ -291,7 +835,7 @@ function ae(e) {
291
835
  setTimeout(O, 50);
292
836
  };
293
837
  O();
294
- }, []), /* @__PURE__ */ D(
838
+ }, []), /* @__PURE__ */ _(
295
839
  "div",
296
840
  {
297
841
  className: "payconductor",
@@ -303,47 +847,111 @@ function ae(e) {
303
847
  }
304
848
  );
305
849
  }
306
- function ie(e) {
307
- const r = G(null), [t, n] = A(() => ""), [d, u] = A(() => !1);
308
- return U(() => {
309
- const s = (m) => {
310
- m != null && m.frame && (n(m.frame.iframeUrl || ""), u(!0), window.PayConductor && window.PayConductor.frame && (window.PayConductor.frame.isReady = !0), console.log("init", {
850
+ function qe(e) {
851
+ const r = J(null), [t, n] = b(() => ""), [a, o] = b(() => !1), [d, s] = b(() => "");
852
+ return L(() => {
853
+ if (typeof document < "u" && !document.getElementById(F)) {
854
+ const c = document.createElement("style");
855
+ c.id = F, c.textContent = pe, document.head.appendChild(c);
856
+ }
857
+ const i = (c) => {
858
+ c != null && c.frame && (n(c.frame.iframeUrl || ""), o(!0), console.log("init", {
311
859
  PayConductor: window.PayConductor
312
860
  }));
313
- }, R = typeof window < "u" ? window.PayConductor : null;
314
- if (R)
315
- s(R);
861
+ }, u = typeof window < "u" ? window.PayConductor : null;
862
+ if (u)
863
+ i(u);
316
864
  else {
317
- const m = (P) => {
318
- s(P.detail), window.removeEventListener("payconductor:registered", m);
865
+ const c = (w) => {
866
+ i(w.detail), window.removeEventListener("payconductor:registered", c);
319
867
  };
320
- window.addEventListener("payconductor:registered", m);
868
+ window.addEventListener("payconductor:registered", c);
321
869
  }
322
- }, []), /* @__PURE__ */ D(
870
+ let m = !1;
871
+ const h = (c) => {
872
+ var w, g, I, M;
873
+ if (((w = c.data) == null ? void 0 : w.type) === E.RESIZE && ((I = (g = c.data) == null ? void 0 : g.data) != null && I.height) && s(c.data.data.height + "px"), ((M = c.data) == null ? void 0 : M.type) === E.READY && e.height && !m) {
874
+ m = !0;
875
+ const T = document.querySelector(
876
+ ".payconductor-element iframe"
877
+ );
878
+ T != null && T.contentWindow && T.contentWindow.postMessage(
879
+ {
880
+ type: E.CONFIG,
881
+ data: {
882
+ height: e.height
883
+ },
884
+ requestId: "element-height"
885
+ },
886
+ "*"
887
+ );
888
+ }
889
+ };
890
+ return window.addEventListener("message", h), () => window.removeEventListener("message", h);
891
+ }, []), /* @__PURE__ */ $(
323
892
  "div",
324
893
  {
325
894
  className: "payconductor-element",
326
895
  style: {
327
896
  width: "100%"
328
897
  },
329
- children: d && t ? /* @__PURE__ */ D(
330
- "iframe",
331
- {
332
- allow: "payment",
333
- title: "PayConductor",
334
- ref: r,
335
- src: t,
336
- style: {
337
- width: "100%",
338
- height: e.height || Q,
339
- border: "none"
898
+ children: [
899
+ a ? null : /* @__PURE__ */ _(
900
+ "div",
901
+ {
902
+ className: "payconductor-skeleton",
903
+ style: {
904
+ height: e.height || U
905
+ }
340
906
  }
341
- }
342
- ) : null
907
+ ),
908
+ a && t ? /* @__PURE__ */ _(
909
+ "iframe",
910
+ {
911
+ allow: "payment",
912
+ title: "PayConductor",
913
+ ref: r,
914
+ src: t,
915
+ style: {
916
+ width: "100%",
917
+ height: e.height || d || U,
918
+ border: "none"
919
+ }
920
+ }
921
+ ) : null
922
+ ]
343
923
  }
344
924
  );
345
925
  }
346
- function de() {
926
+ function Ve(e) {
927
+ const [r, t] = b(() => !1);
928
+ return L(() => {
929
+ const n = () => {
930
+ t(!0);
931
+ }, a = () => {
932
+ t(!1);
933
+ };
934
+ return window.addEventListener("payconductor:3ds:show", n), window.addEventListener("payconductor:3ds:hide", a), typeof window < "u" && (window.PayConductor3DS = {
935
+ container: () => document.getElementById("payconductor-3ds-container"),
936
+ show: n,
937
+ hide: a
938
+ }, window.dispatchEvent(new CustomEvent("payconductor:3ds:registered"))), () => {
939
+ window.removeEventListener("payconductor:3ds:show", n), window.removeEventListener("payconductor:3ds:hide", a), window.PayConductor3DS = null;
940
+ };
941
+ }, []), /* @__PURE__ */ _(
942
+ "div",
943
+ {
944
+ className: "payconductor-three-ds",
945
+ id: "payconductor-3ds-container",
946
+ style: {
947
+ width: "100%",
948
+ display: r ? "block" : "none",
949
+ minHeight: r ? e.height || "600px" : "0"
950
+ }
951
+ }
952
+ );
953
+ }
954
+ function We() {
347
955
  const e = typeof window < "u" ? window.PayConductor : null, r = e != null && e.config ? {
348
956
  publicKey: e.config.publicKey,
349
957
  orderId: e.config.orderId,
@@ -351,11 +959,9 @@ function de() {
351
959
  locale: e.config.locale
352
960
  } : {}, t = e != null && e.frame ? {
353
961
  iframe: e.frame.iframe,
354
- isReady: e.frame.isReady,
355
962
  error: e.frame.error
356
963
  } : {
357
964
  iframe: null,
358
- isReady: !1,
359
965
  error: null
360
966
  };
361
967
  return {
@@ -363,7 +969,7 @@ function de() {
363
969
  ...t
364
970
  };
365
971
  }
366
- function _(e) {
972
+ function N(e) {
367
973
  var r;
368
974
  if ((r = e == null ? void 0 : e.frame) != null && r.iframe) {
369
975
  const t = e.frame.iframe;
@@ -381,26 +987,27 @@ function _(e) {
381
987
  }
382
988
  return document.querySelector(".payconductor-element iframe") ?? null;
383
989
  }
384
- function ce() {
990
+ function Ge() {
385
991
  const e = () => typeof window < "u" ? window.PayConductor : null, r = (t, n) => {
386
- const d = e();
387
- if (!d) return;
388
- const u = _(d);
389
- u != null && u.contentWindow && u.contentWindow.postMessage({
992
+ const a = e();
993
+ if (!a) return;
994
+ const o = N(a);
995
+ o != null && o.contentWindow && o.contentWindow.postMessage({
390
996
  type: t,
391
997
  data: n
392
998
  }, "*");
393
999
  };
394
1000
  return {
395
1001
  init: async (t) => {
396
- const n = _(e()), d = N();
397
- return p(n || void 0, d, t);
1002
+ const n = N(e()), a = x();
1003
+ return Ae(n || void 0, a, t);
398
1004
  },
399
1005
  confirmPayment: async (t) => {
400
- const n = _(e()), d = N();
401
1006
  if (!t.orderId)
402
1007
  throw new Error("Order ID is required");
403
- return b(n || void 0, d, t);
1008
+ const n = e();
1009
+ if (!(n != null && n.api)) throw new Error("PayConductor not initialized");
1010
+ return n.api.confirmPayment(t);
404
1011
  },
405
1012
  validate: (t) => {
406
1013
  const n = e();
@@ -415,9 +1022,9 @@ function ce() {
415
1022
  return ((t = e()) == null ? void 0 : t.selectedPaymentMethod) ?? null;
416
1023
  },
417
1024
  updateConfig: (t) => {
418
- var d;
419
- const n = (d = e()) == null ? void 0 : d.config;
420
- r(f.CONFIG, {
1025
+ var a;
1026
+ const n = (a = e()) == null ? void 0 : a.config;
1027
+ r(E.CONFIG, {
421
1028
  publicKey: n == null ? void 0 : n.publicKey,
422
1029
  orderId: n == null ? void 0 : n.orderId,
423
1030
  theme: t.theme ?? (n == null ? void 0 : n.theme),
@@ -425,10 +1032,10 @@ function ce() {
425
1032
  paymentMethods: t.paymentMethods ?? (n == null ? void 0 : n.paymentMethods)
426
1033
  });
427
1034
  },
428
- updateorderId: (t) => {
429
- var d;
430
- const n = (d = e()) == null ? void 0 : d.config;
431
- r(f.CONFIG, {
1035
+ updateOrderId: (t) => {
1036
+ var a;
1037
+ const n = (a = e()) == null ? void 0 : a.config;
1038
+ r(E.CONFIG, {
432
1039
  publicKey: n == null ? void 0 : n.publicKey,
433
1040
  orderId: t,
434
1041
  theme: n == null ? void 0 : n.theme,
@@ -437,18 +1044,18 @@ function ce() {
437
1044
  });
438
1045
  },
439
1046
  update: (t) => {
440
- r(f.UPDATE, t);
1047
+ r(E.UPDATE, t);
441
1048
  },
442
1049
  submit: async () => {
443
- const t = _(e()), n = N();
1050
+ const t = N(e()), n = x();
444
1051
  try {
445
- return await C(t || void 0, n, f.CONFIRM_PAYMENT, {}), {
1052
+ return await D(t || void 0, n, E.CONFIRM_PAYMENT, {}), {
446
1053
  paymentMethod: void 0
447
1054
  };
448
- } catch (d) {
1055
+ } catch (a) {
449
1056
  return {
450
1057
  error: {
451
- message: d instanceof Error ? d.message : "Payment failed",
1058
+ message: a instanceof Error ? a.message : "Payment failed",
452
1059
  code: "payment_error",
453
1060
  type: "payment_error"
454
1061
  }
@@ -457,20 +1064,206 @@ function ce() {
457
1064
  }
458
1065
  };
459
1066
  }
1067
+ function $e(e) {
1068
+ let r = null;
1069
+ return {
1070
+ handleChallenge: async (a) => {
1071
+ var s;
1072
+ if (!(a.status === "NeedChallenge" || a.statusDetail === "ThreeDsAwaitingChallenge"))
1073
+ return {
1074
+ status: C.Success
1075
+ };
1076
+ (s = e == null ? void 0 : e.onChallenge) == null || s.call(e), r = new H(a);
1077
+ const d = await r.authenticate({
1078
+ onComplete: e == null ? void 0 : e.onComplete,
1079
+ onError: e == null ? void 0 : e.onError,
1080
+ onTimeout: e == null ? void 0 : e.onTimeout
1081
+ });
1082
+ return r.destroy(), r = null, d;
1083
+ },
1084
+ destroy: () => {
1085
+ r == null || r.destroy(), r = null;
1086
+ }
1087
+ };
1088
+ }
1089
+ class ke extends Error {
1090
+ constructor(r, t) {
1091
+ super(r), this.title = t, this.name = "PayConductorApiError";
1092
+ }
1093
+ }
1094
+ class Ne {
1095
+ constructor(r) {
1096
+ this.publicKey = r;
1097
+ }
1098
+ async getSettings() {
1099
+ const r = await fetch(`${this.baseUrl}/card-tokenization/settings`, {
1100
+ method: "GET",
1101
+ headers: this.headers
1102
+ });
1103
+ return r.ok || await this.parseResponseError("Failed to fetch settings", r), r.json();
1104
+ }
1105
+ async createToken(r) {
1106
+ const t = await fetch(`${this.baseUrl}/card-tokenization/tokenize`, {
1107
+ method: "POST",
1108
+ headers: this.headers,
1109
+ body: JSON.stringify(r)
1110
+ });
1111
+ return t.ok || await this.parseResponseError("Failed to generate token", t), t.json();
1112
+ }
1113
+ async saveTokens(r, t, n) {
1114
+ const a = await fetch(`${this.baseUrl}/card-tokenization/save-tokens/${t}/${n}`, {
1115
+ method: "POST",
1116
+ headers: this.headers,
1117
+ body: JSON.stringify(r)
1118
+ });
1119
+ a.ok || await this.parseResponseError("Failed to save tokens", a);
1120
+ }
1121
+ async parseResponseError(r, t) {
1122
+ var a, o, d, s;
1123
+ let n = "";
1124
+ try {
1125
+ const i = await t.json();
1126
+ i != null && i.message ? n = i.message : (a = i == null ? void 0 : i.error) != null && a.message ? n = i.error : (d = (o = i == null ? void 0 : i.error) == null ? void 0 : o.value) != null && d.message ? n = i.error.value.message : (s = i == null ? void 0 : i.value) != null && s.message ? n = i.value.message : n = JSON.stringify(i);
1127
+ } catch {
1128
+ }
1129
+ throw new ke(n, r);
1130
+ }
1131
+ get baseUrl() {
1132
+ return typeof window < "u" && window.location.href.includes("localhost") ? "http://localhost:3000/api/v1/sdk" : "https://payconductor.ai/api/v1/sdk";
1133
+ }
1134
+ get headers() {
1135
+ return {
1136
+ Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
1137
+ "Content-Type": "application/json"
1138
+ };
1139
+ }
1140
+ }
1141
+ var Y = /* @__PURE__ */ ((e) => (e.Cpf = "Cpf", e.Cnpj = "Cnpj", e))(Y || {}), j = /* @__PURE__ */ ((e) => (e.Asaas = "Asaas", e.Sandbox = "Sandbox", e.MercadoPago = "MercadoPago", e.NuPay = "NuPay", e.PicPay = "PicPay", e.Woovi = "Woovi", e.PagarMe = "PagarMe", e.PagSeguro = "PagSeguro", e.BancoDoBrasil = "BancoDoBrasil", e))(j || {});
1142
+ class xe {
1143
+ constructor(r) {
1144
+ this.input = r;
1145
+ }
1146
+ }
1147
+ class Le extends xe {
1148
+ constructor() {
1149
+ super(...arguments);
1150
+ p(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
1151
+ }
1152
+ async tokenize() {
1153
+ if (!("publicKey" in this.input.setting))
1154
+ throw new Error("MercadoPago public key is missing in settings");
1155
+ if (!this.input.customer.documentNumber)
1156
+ throw new Error("Customer document number is required for tokenization");
1157
+ const t = window.MercadoPago;
1158
+ if (!t) throw new Error("MercadoPago SDK not available");
1159
+ const n = new t(this.input.setting.publicKey), {
1160
+ expiration: a,
1161
+ cvv: o,
1162
+ number: d,
1163
+ holderName: s
1164
+ } = this.input.card;
1165
+ return (await n.createCardToken({
1166
+ cardExpirationMonth: String(a.month),
1167
+ cardExpirationYear: String(a.year),
1168
+ cardholderName: s,
1169
+ cardNumber: d,
1170
+ securityCode: o,
1171
+ identificationType: this.input.customer.documentType === Y.Cpf ? "CPF" : "CNPJ",
1172
+ identificationNumber: this.input.customer.documentNumber
1173
+ })).id;
1174
+ }
1175
+ }
1176
+ const Oe = {
1177
+ [j.MercadoPago]: Le
1178
+ };
1179
+ class Ue {
1180
+ constructor(r) {
1181
+ p(this, "api");
1182
+ this.publicKey = r, this.api = new Ne(this.publicKey);
1183
+ }
1184
+ async tokenizeCard(r) {
1185
+ this.validateCard(r);
1186
+ const {
1187
+ customerId: t,
1188
+ token: n
1189
+ } = await this.api.createToken({
1190
+ card: r.card,
1191
+ customer: r.customer,
1192
+ saveCard: !1
1193
+ }), {
1194
+ settings: a
1195
+ } = await this.api.getSettings(), d = (await Promise.all(a.map(async (s) => {
1196
+ const i = Oe[s.key];
1197
+ if (!i) return null;
1198
+ const u = new i({
1199
+ ...r,
1200
+ setting: s.settings
1201
+ });
1202
+ return await R(u.scriptUrl), {
1203
+ token: await u.tokenize(),
1204
+ integrationId: s.integrationId,
1205
+ providerKey: s.key
1206
+ };
1207
+ }))).filter((s) => s !== null);
1208
+ return d.length > 0 && await this.api.saveTokens(d, t, n), n;
1209
+ }
1210
+ validateCard(r) {
1211
+ const {
1212
+ number: t,
1213
+ cvv: n,
1214
+ expiration: a,
1215
+ holderName: o
1216
+ } = r.card;
1217
+ if (!t || !n || !(a != null && a.month) || !(a != null && a.year) || !o)
1218
+ throw new Error("Invalid card data");
1219
+ }
1220
+ }
1221
+ function Je(e) {
1222
+ const r = new Ue(e.publicKey);
1223
+ return {
1224
+ tokenizeCard: async (n) => {
1225
+ var a, o;
1226
+ try {
1227
+ const d = await r.tokenizeCard(n);
1228
+ return (a = e.onSuccess) == null || a.call(e, d), d;
1229
+ } catch (d) {
1230
+ const s = d instanceof Error ? d : new Error("Tokenization failed");
1231
+ return (o = e.onError) == null || o.call(e, s), null;
1232
+ }
1233
+ }
1234
+ };
1235
+ }
460
1236
  export {
461
- k as ALLOWED_ORIGINS,
462
- oe as ERROR_CODES,
463
- j as IFRAME_BASE_URL,
464
- Q as IFRAME_DEFAULT_HEIGHT_VALUE,
465
- f as POST_MESSAGES,
466
- ae as PayConductor,
467
- ie as PayConductorCheckoutElement,
468
- $ as REQUEST_TIMEOUT,
469
- z as buildIframeUrl,
470
- ae as default,
471
- J as generateRequestId,
472
- X as isValidOrigin,
473
- de as usePayConductor,
474
- ce as usePayconductorElement
1237
+ ie as ALLOWED_ORIGINS,
1238
+ te as DeviceType,
1239
+ Ye as ERROR_CODES,
1240
+ re as ErrorCode,
1241
+ oe as IFRAME_BASE_URL,
1242
+ U as IFRAME_DEFAULT_HEIGHT_VALUE,
1243
+ P as IncomingMessage,
1244
+ ne as InputStyleKey,
1245
+ v as OutgoingMessage,
1246
+ E as POST_MESSAGES,
1247
+ je as PayConductor,
1248
+ H as PayConductor3DSSDK,
1249
+ qe as PayConductorCheckoutElement,
1250
+ Ve as PayConductorThreeDSElement,
1251
+ Ue as PayConductorTokenizeSDK,
1252
+ Q as PaymentMethod,
1253
+ ee as PaymentMethodLayout,
1254
+ B as PaymentStatus,
1255
+ se as REQUEST_TIMEOUT,
1256
+ pe as SKELETON_CSS,
1257
+ F as SKELETON_STYLE_ID,
1258
+ Pe as buildIframeUrl,
1259
+ je as default,
1260
+ He as defaultTheme,
1261
+ Te as generateRequestId,
1262
+ be as isValidOrigin,
1263
+ R as loadScript,
1264
+ We as usePayConductor,
1265
+ Ge as usePayconductorElement,
1266
+ $e as useThreeDS,
1267
+ Je as useTokenize
475
1268
  };
476
1269
  //# sourceMappingURL=index.es.js.map