@payconductor/react 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,11 +1,11 @@
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 = {
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 C = (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.Shield = "Shield", e.Hopy = "Hopy", e.SAC = "SAC", e))(I || {}), ie = /* @__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))(ie || {}), _ = /* @__PURE__ */ ((e) => (e.Production = "Production", e.Sandbox = "Sandbox", e))(_ || {}), re = /* @__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))(re || {}), oe = /* @__PURE__ */ ((e) => (e.Android = "android", e.IOS = "ios", e.Web = "web", 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.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
9
  primaryColor: "#0066ff",
10
10
  secondaryColor: "#5a6b7c",
11
11
  backgroundColor: "transparent",
@@ -52,22 +52,22 @@ const He = {
52
52
  buttonBorderRadius: "8px",
53
53
  transitionDuration: "0.2s",
54
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 = {
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
71
  INVALID_CLIENT: "InvalidClient",
72
72
  INVALID_TOKEN: "InvalidToken",
73
73
  NETWORK_ERROR: "NetworkError",
@@ -75,661 +75,210 @@ const He = {
75
75
  PAYMENT_DECLINED: "PaymentDeclined",
76
76
  VALIDATION_ERROR: "ValidationError",
77
77
  TIMEOUT: "Timeout"
78
- };
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
- };
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()}`;
90
96
  }
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
97
+ function ye() {
98
+ return crypto.randomUUID();
157
99
  }
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
- }
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
+ });
201
108
  }
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();
109
+ function O() {
110
+ return /* @__PURE__ */ new Map();
111
+ }
112
+ function D(e, n, t, a) {
113
+ return new Promise((i, o) => {
114
+ if (!e || !("contentWindow" in e)) {
115
+ o(new Error("Iframe not defined"));
209
116
  return;
210
117
  }
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);
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: 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);
215
137
  });
216
- return k.set(e, t), t;
217
138
  }
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
- }
139
+ function Ee(e, n, t) {
140
+ return D(e, n, P.CONFIRM_PAYMENT, t);
254
141
  }
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";
142
+ async function ge(e, n, t) {
143
+ return await Ee(e, n, {
144
+ orderId: t.orderId
145
+ });
262
146
  }
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");
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 pe(e, n, t) {
154
+ return D(e, n, P.CONFIG, t);
155
+ }
156
+ function be(e, n, t) {
157
+ return D(e, n, P.INIT, t);
158
+ }
159
+ function Ce(e, n, t, a, i, o, d, s, r, l, g, w) {
160
+ const m = e.data, {
161
+ requestId: y,
162
+ type: h,
163
+ data: E,
164
+ error: b
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);
281
172
  }
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();
173
+ return;
319
174
  }
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
- };
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), b ? x(new Error(String(b.message))) : T(E);
182
+ return;
183
+ }
184
+ if (h === P.ERROR) {
185
+ t((b == null ? void 0 : b.message) || "Unknown error"), i == null || i(new Error(String(b == null ? void 0 : b.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 && (r == null || r(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
+ }
366
218
  }
367
219
  }
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
220
+ function Ze(e) {
221
+ const [n, t] = A(
222
+ () => !1
223
+ ), [a, i] = A(() => null), [o, d] = A(
224
+ () => ""
225
+ ), [s, r] = A(() => null);
226
+ return F(() => {
227
+ const l = (...u) => {
228
+ e.debug && console.log("[PayConductor]", ...u);
229
+ }, g = fe({
230
+ publicKey: e.publicKey
396
231
  });
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) {
532
- const r = new URLSearchParams({
533
- publicKey: e.publicKey
534
- });
535
- return `${oe}?${r.toString()}`;
536
- }
537
- function Te() {
538
- return crypto.randomUUID();
539
- }
540
- function be(e, r) {
541
- return r.some((t) => {
542
- try {
543
- return new URL(t).origin === e;
544
- } catch {
545
- return t === e;
546
- }
547
- });
548
- }
549
- function x() {
550
- return /* @__PURE__ */ new Map();
551
- }
552
- function D(e, r, t, n) {
553
- return new Promise((a, o) => {
554
- if (!e || !("contentWindow" in e)) {
555
- o(new Error("Iframe not defined"));
556
- return;
557
- }
558
- if (!(e != null && e.contentWindow)) {
559
- o(new Error("Iframe not ready"));
560
- return;
561
- }
562
- if (!r) {
563
- o(new Error("Pending requests not initialized"));
564
- return;
565
- }
566
- const d = Te();
567
- r.set(d, {
568
- resolve: a,
569
- reject: o
570
- }), e.contentWindow.postMessage({
571
- type: t,
572
- data: n,
573
- requestId: d
574
- }, "*"), setTimeout(() => {
575
- r != null && r.has(d) && (r.delete(d), o(new Error("Request timeout")));
576
- }, se);
577
- });
578
- }
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, {
585
- orderId: t.orderId
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
- });
610
- }
611
- function De(e, r, t) {
612
- return D(e, r, E.VALIDATE, t);
613
- }
614
- function Me(e, r) {
615
- return D(e, r, E.RESET);
616
- }
617
- function _e(e, r, t) {
618
- return D(e, r, E.CONFIG, t);
619
- }
620
- function Ae(e, r, t) {
621
- return D(e, r, E.INIT, t);
622
- }
623
- function Re(e, r, t, n, a, o, d, s, i) {
624
- const u = e.data, {
625
- requestId: m,
626
- type: h,
627
- data: c,
628
- error: w
629
- } = u;
630
- if (h === E.READY) {
631
- if (n == null || n(), m && (r != null && r.has(m))) {
632
- const {
633
- resolve: g
634
- } = r.get(m);
635
- r.delete(m), g(c);
636
- }
637
- return;
638
- }
639
- if (be(e.origin, ie)) {
640
- if (m && r && r.has(m)) {
641
- const {
642
- resolve: g,
643
- reject: I
644
- } = r.get(m);
645
- r.delete(m), w ? I(new Error(String(w.message))) : g(c);
646
- return;
647
- }
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)));
650
- return;
651
- }
652
- if (h === E.PAYMENT_COMPLETE) {
653
- c && typeof c == "object" && "status" in c && (o == null || o(c));
654
- return;
655
- }
656
- if (h === E.PAYMENT_FAILED) {
657
- c && typeof c == "object" && "status" in c && (d == null || d(c));
658
- return;
659
- }
660
- if (h === E.PAYMENT_PENDING) {
661
- c && typeof c == "object" && "status" in c && (s == null || s(c));
662
- return;
663
- }
664
- if (h === E.PAYMENT_METHOD_SELECTED) {
665
- c && typeof c == "object" && "paymentMethod" in c && (i == null || i(c.paymentMethod));
666
- return;
667
- }
668
- E.RESIZE;
669
- }
670
- }
671
- function je(e) {
672
- const [r, t] = b(
673
- () => !1
674
- ), [n, a] = b(() => null), [o, d] = b(
675
- () => ""
676
- ), [s, i] = b(() => null);
677
- return L(() => {
678
- const u = (...l) => {
679
- e.debug && console.log("[PayConductor]", ...l);
680
- }, m = Pe({
681
- publicKey: e.publicKey
682
- });
683
- d(m), t(!0);
684
- const h = x();
685
- let c = !1;
686
- u("init", e.publicKey), u("iframeUrl", m);
687
- const w = () => {
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;
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;
698
247
  }
699
- return l;
248
+ return u;
700
249
  }
701
250
  return document.querySelector(
702
251
  ".payconductor-element iframe"
703
252
  ) ?? void 0;
704
- }, g = {
253
+ }, h = {
705
254
  get iframe() {
706
255
  return document.querySelector(
707
256
  ".payconductor-element iframe"
708
257
  ) ?? null;
709
258
  },
710
- set iframe(l) {
259
+ set iframe(u) {
711
260
  },
712
- iframeUrl: m,
261
+ iframeUrl: g,
713
262
  error: null
714
- }, I = {
263
+ }, E = {
715
264
  publicKey: e.publicKey,
716
265
  theme: e.theme,
717
266
  locale: e.locale,
718
267
  paymentMethods: e.paymentMethods,
719
268
  defaultPaymentMethod: e.defaultPaymentMethod
720
- }, M = {
721
- confirmPayment: (l) => {
722
- var f;
723
- u("→ CONFIRM_PAYMENT", {
724
- orderId: l.orderId
269
+ }, b = {
270
+ confirmPayment: (u) => {
271
+ var c;
272
+ l("→ CONFIRM_PAYMENT", {
273
+ orderId: u.orderId
725
274
  });
726
- const S = w();
275
+ const S = y();
727
276
  return S != null && S.contentWindow && S.contentWindow.postMessage(
728
277
  {
729
- type: E.CONFIG,
278
+ type: P.CONFIG,
730
279
  data: {
731
280
  publicKey: e.publicKey,
732
- orderId: l.orderId,
281
+ orderId: u.orderId,
733
282
  theme: e.theme,
734
283
  locale: e.locale,
735
284
  paymentMethods: e.paymentMethods,
@@ -739,36 +288,36 @@ function je(e) {
739
288
  }
740
289
  },
741
290
  "*"
742
- ), I.orderId = l.orderId, (f = window.PayConductor) != null && f.config && (window.PayConductor.config.orderId = l.orderId), ve(S, h, l);
291
+ ), E.orderId = u.orderId, (c = window.PayConductor) != null && c.config && (window.PayConductor.config.orderId = u.orderId), ge(S, w, u);
743
292
  },
744
- validate: (l) => (u("→ VALIDATE", l), De(w(), h, l)),
745
- reset: () => (u("→ RESET"), Me(w(), h)),
293
+ validate: (u) => (l("→ VALIDATE", u), Pe(y(), w, u)),
294
+ reset: () => (l("→ RESET"), Se(y(), w)),
746
295
  getSelectedPaymentMethod: () => s
747
296
  };
748
297
  window.PayConductor = {
749
- frame: g,
750
- config: I,
751
- api: M,
298
+ frame: h,
299
+ config: E,
300
+ api: b,
752
301
  selectedPaymentMethod: s
753
- }, u("registered"), window.dispatchEvent(
302
+ }, l("registered"), window.dispatchEvent(
754
303
  new CustomEvent("payconductor:registered", {
755
304
  detail: window.PayConductor
756
305
  })
757
306
  );
758
307
  const T = async () => {
759
- if (!c) {
760
- const l = w();
761
- if (!l) {
762
- u("→ CONFIG skipped: iframe not found");
308
+ if (!m) {
309
+ const u = y();
310
+ if (!u) {
311
+ l("→ CONFIG skipped: iframe not found");
763
312
  return;
764
313
  }
765
- c = !0, u("→ CONFIG", {
314
+ m = !0, l("→ CONFIG", {
766
315
  theme: e.theme,
767
316
  locale: e.locale,
768
317
  paymentMethods: e.paymentMethods,
769
318
  defaultPaymentMethod: e.defaultPaymentMethod,
770
319
  showPaymentButtons: e.showPaymentButtons
771
- }), _e(l, h, {
320
+ }), pe(u, w, {
772
321
  theme: e.theme,
773
322
  locale: e.locale,
774
323
  paymentMethods: e.paymentMethods,
@@ -777,65 +326,77 @@ function je(e) {
777
326
  nuPayConfig: e.nuPayConfig
778
327
  });
779
328
  }
780
- }, q = (l) => {
329
+ }, x = (u) => {
781
330
  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);
331
+ (S = u.data) != null && S.type && l("←", u.data.type, u.data.data ?? ""), Ce(
332
+ u,
333
+ w,
334
+ (c) => {
335
+ var f;
336
+ i(c), h.error = c, (f = window.PayConductor) != null && f.frame && (window.PayConductor.frame.error = c);
788
337
  },
789
338
  () => {
339
+ var c;
340
+ (c = e.onReady) == null || c.call(e), T();
341
+ },
342
+ (c) => {
790
343
  var f;
791
- (f = e.onReady) == null || f.call(e), T();
344
+ (f = e.onError) == null || f.call(e, c);
792
345
  },
793
- (f) => {
794
- var y;
795
- (y = e.onError) == null || y.call(e, f);
346
+ (c) => {
347
+ var f;
348
+ (f = e.onPaymentComplete) == null || f.call(e, c);
796
349
  },
797
- (f) => {
798
- var y;
799
- (y = e.onPaymentComplete) == null || y.call(e, f);
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);
800
357
  },
801
- (f) => {
802
- var y;
803
- (y = e.onPaymentFailed) == null || y.call(e, f);
358
+ (c) => {
359
+ var f;
360
+ r(c), window.PayConductor && (window.PayConductor.selectedPaymentMethod = c), (f = e.onPaymentMethodSelected) == null || f.call(e, c);
804
361
  },
805
- (f) => {
806
- var y;
807
- (y = e.onPaymentPending) == null || y.call(e, f);
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);
808
369
  },
809
- (f) => {
810
- var y;
811
- i(f), window.PayConductor && (window.PayConductor.selectedPaymentMethod = f), (y = e.onPaymentMethodSelected) == null || y.call(e, f);
370
+ () => {
371
+ var c;
372
+ (c = e.onThreeDSFailed) == null || c.call(e);
812
373
  }
813
374
  );
814
375
  };
815
- window.addEventListener("message", q);
376
+ window.addEventListener("message", x);
816
377
  const V = () => {
817
- var S, f, y;
818
- const l = w();
819
- if (!l) return !1;
378
+ var S, c, f;
379
+ const u = y();
380
+ if (!u) return !1;
820
381
  try {
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")
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")
822
383
  return T(), !0;
823
384
  } catch {
824
385
  }
825
386
  return !1;
826
- }, O = () => {
387
+ }, K = () => {
827
388
  if (V()) return;
828
- const l = w();
829
- if (l) {
830
- l.addEventListener("load", () => T(), {
389
+ const u = y();
390
+ if (u) {
391
+ u.addEventListener("load", () => T(), {
831
392
  once: !0
832
393
  });
833
394
  return;
834
395
  }
835
- setTimeout(O, 50);
396
+ setTimeout(K, 50);
836
397
  };
837
- O();
838
- }, []), /* @__PURE__ */ _(
398
+ K();
399
+ }, []), /* @__PURE__ */ N(
839
400
  "div",
840
401
  {
841
402
  className: "payconductor",
@@ -847,37 +408,37 @@ function je(e) {
847
408
  }
848
409
  );
849
410
  }
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);
411
+ function Qe(e) {
412
+ const n = W(null), [t, a] = A(() => ""), [i, 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);
856
417
  }
857
- const i = (c) => {
858
- c != null && c.frame && (n(c.frame.iframeUrl || ""), o(!0), console.log("init", {
418
+ const r = (m) => {
419
+ m != null && m.frame && (a(m.frame.iframeUrl || ""), o(!0), console.log("init", {
859
420
  PayConductor: window.PayConductor
860
421
  }));
861
- }, u = typeof window < "u" ? window.PayConductor : null;
862
- if (u)
863
- i(u);
422
+ }, l = typeof window < "u" ? window.PayConductor : null;
423
+ if (l)
424
+ r(l);
864
425
  else {
865
- const c = (w) => {
866
- i(w.detail), window.removeEventListener("payconductor:registered", c);
426
+ const m = (y) => {
427
+ r(y.detail), window.removeEventListener("payconductor:registered", m);
867
428
  };
868
- window.addEventListener("payconductor:registered", c);
429
+ window.addEventListener("payconductor:registered", m);
869
430
  }
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;
431
+ let g = !1;
432
+ const w = (m) => {
433
+ var y, h, E, b;
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"), ((b = m.data) == null ? void 0 : b.type) === P.READY && e.height && !g) {
435
+ g = !0;
875
436
  const T = document.querySelector(
876
437
  ".payconductor-element iframe"
877
438
  );
878
439
  T != null && T.contentWindow && T.contentWindow.postMessage(
879
440
  {
880
- type: E.CONFIG,
441
+ type: P.CONFIG,
881
442
  data: {
882
443
  height: e.height
883
444
  },
@@ -887,8 +448,8 @@ function qe(e) {
887
448
  );
888
449
  }
889
450
  };
890
- return window.addEventListener("message", h), () => window.removeEventListener("message", h);
891
- }, []), /* @__PURE__ */ $(
451
+ return window.addEventListener("message", w), () => window.removeEventListener("message", w);
452
+ }, []), /* @__PURE__ */ q(
892
453
  "div",
893
454
  {
894
455
  className: "payconductor-element",
@@ -896,25 +457,25 @@ function qe(e) {
896
457
  width: "100%"
897
458
  },
898
459
  children: [
899
- a ? null : /* @__PURE__ */ _(
460
+ i ? null : /* @__PURE__ */ N(
900
461
  "div",
901
462
  {
902
463
  className: "payconductor-skeleton",
903
464
  style: {
904
- height: e.height || U
465
+ height: e.height || B
905
466
  }
906
467
  }
907
468
  ),
908
- a && t ? /* @__PURE__ */ _(
469
+ i && t ? /* @__PURE__ */ N(
909
470
  "iframe",
910
471
  {
911
472
  allow: "payment",
912
473
  title: "PayConductor",
913
- ref: r,
474
+ ref: n,
914
475
  src: t,
915
476
  style: {
916
477
  width: "100%",
917
- height: e.height || d || U,
478
+ height: e.height || d || B,
918
479
  border: "none"
919
480
  }
920
481
  }
@@ -923,36 +484,36 @@ function qe(e) {
923
484
  }
924
485
  );
925
486
  }
926
- function Ve(e) {
927
- const [r, t] = b(() => !1);
928
- return L(() => {
929
- const n = () => {
487
+ function et(e) {
488
+ const [n, t] = A(() => !1);
489
+ return F(() => {
490
+ const a = () => {
930
491
  t(!0);
931
- }, a = () => {
492
+ }, i = () => {
932
493
  t(!1);
933
494
  };
934
- return window.addEventListener("payconductor:3ds:show", n), window.addEventListener("payconductor:3ds:hide", a), typeof window < "u" && (window.PayConductor3DS = {
495
+ return window.addEventListener("payconductor:3ds:show", a), window.addEventListener("payconductor:3ds:hide", i), typeof window < "u" && (window.PayConductor3DS = {
935
496
  container: () => document.getElementById("payconductor-3ds-container"),
936
- show: n,
937
- hide: a
497
+ show: a,
498
+ hide: i
938
499
  }, window.dispatchEvent(new CustomEvent("payconductor:3ds:registered"))), () => {
939
- window.removeEventListener("payconductor:3ds:show", n), window.removeEventListener("payconductor:3ds:hide", a), window.PayConductor3DS = null;
500
+ window.removeEventListener("payconductor:3ds:show", a), window.removeEventListener("payconductor:3ds:hide", i), window.PayConductor3DS = null;
940
501
  };
941
- }, []), /* @__PURE__ */ _(
502
+ }, []), /* @__PURE__ */ N(
942
503
  "div",
943
504
  {
944
505
  className: "payconductor-three-ds",
945
506
  id: "payconductor-3ds-container",
946
507
  style: {
947
508
  width: "100%",
948
- display: r ? "block" : "none",
949
- minHeight: r ? e.height || "600px" : "0"
509
+ display: n ? "block" : "none",
510
+ minHeight: n ? e.height || "600px" : "0"
950
511
  }
951
512
  }
952
513
  );
953
514
  }
954
- function We() {
955
- const e = typeof window < "u" ? window.PayConductor : null, r = e != null && e.config ? {
515
+ function tt() {
516
+ const e = typeof window < "u" ? window.PayConductor : null, n = e != null && e.config ? {
956
517
  publicKey: e.config.publicKey,
957
518
  orderId: e.config.orderId,
958
519
  theme: e.config.theme,
@@ -965,53 +526,53 @@ function We() {
965
526
  error: null
966
527
  };
967
528
  return {
968
- ...r,
529
+ ...n,
969
530
  ...t
970
531
  };
971
532
  }
972
- function N(e) {
973
- var r;
974
- if ((r = e == null ? void 0 : e.frame) != null && r.iframe) {
533
+ function U(e) {
534
+ var n;
535
+ if ((n = e == null ? void 0 : e.frame) != null && n.iframe) {
975
536
  const t = e.frame.iframe;
976
537
  if (t instanceof HTMLIFrameElement) return t;
977
538
  if (t && typeof t == "object") {
978
539
  if ("current" in t) {
979
- const n = t.current;
980
- if (n instanceof HTMLIFrameElement) return n;
540
+ const a = t.current;
541
+ if (a instanceof HTMLIFrameElement) return a;
981
542
  }
982
543
  if ("value" in t) {
983
- const n = t.value;
984
- if (n instanceof HTMLIFrameElement) return n;
544
+ const a = t.value;
545
+ if (a instanceof HTMLIFrameElement) return a;
985
546
  }
986
547
  }
987
548
  }
988
549
  return document.querySelector(".payconductor-element iframe") ?? null;
989
550
  }
990
- function Ge() {
991
- const e = () => typeof window < "u" ? window.PayConductor : null, r = (t, n) => {
992
- const a = e();
993
- if (!a) return;
994
- const o = N(a);
551
+ function nt() {
552
+ const e = () => typeof window < "u" ? window.PayConductor : null, n = (t, a) => {
553
+ const i = e();
554
+ if (!i) return;
555
+ const o = U(i);
995
556
  o != null && o.contentWindow && o.contentWindow.postMessage({
996
557
  type: t,
997
- data: n
558
+ data: a
998
559
  }, "*");
999
560
  };
1000
561
  return {
1001
562
  init: async (t) => {
1002
- const n = N(e()), a = x();
1003
- return Ae(n || void 0, a, t);
563
+ const a = U(e()), i = O();
564
+ return be(a || void 0, i, t);
1004
565
  },
1005
566
  confirmPayment: async (t) => {
1006
567
  if (!t.orderId)
1007
568
  throw new Error("Order ID is required");
1008
- const n = e();
1009
- if (!(n != null && n.api)) throw new Error("PayConductor not initialized");
1010
- return n.api.confirmPayment(t);
569
+ const a = e();
570
+ if (!(a != null && a.api)) throw new Error("PayConductor not initialized");
571
+ return a.api.confirmPayment(t);
1011
572
  },
1012
573
  validate: (t) => {
1013
- const n = e();
1014
- return n ? n.api.validate(t) : Promise.resolve(!1);
574
+ const a = e();
575
+ return a ? a.api.validate(t) : Promise.resolve(!1);
1015
576
  },
1016
577
  reset: () => {
1017
578
  const t = e();
@@ -1022,40 +583,40 @@ function Ge() {
1022
583
  return ((t = e()) == null ? void 0 : t.selectedPaymentMethod) ?? null;
1023
584
  },
1024
585
  updateConfig: (t) => {
1025
- var a;
1026
- const n = (a = e()) == null ? void 0 : a.config;
1027
- r(E.CONFIG, {
1028
- publicKey: n == null ? void 0 : n.publicKey,
1029
- orderId: n == null ? void 0 : n.orderId,
1030
- theme: t.theme ?? (n == null ? void 0 : n.theme),
1031
- locale: t.locale ?? (n == null ? void 0 : n.locale),
1032
- paymentMethods: t.paymentMethods ?? (n == null ? void 0 : n.paymentMethods)
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)
1033
594
  });
1034
595
  },
1035
596
  updateOrderId: (t) => {
1036
- var a;
1037
- const n = (a = e()) == null ? void 0 : a.config;
1038
- r(E.CONFIG, {
1039
- publicKey: n == null ? void 0 : n.publicKey,
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,
1040
601
  orderId: t,
1041
- theme: n == null ? void 0 : n.theme,
1042
- locale: n == null ? void 0 : n.locale,
1043
- paymentMethods: n == null ? void 0 : n.paymentMethods
602
+ theme: a == null ? void 0 : a.theme,
603
+ locale: a == null ? void 0 : a.locale,
604
+ paymentMethods: a == null ? void 0 : a.paymentMethods
1044
605
  });
1045
606
  },
1046
607
  update: (t) => {
1047
- r(E.UPDATE, t);
608
+ n(P.UPDATE, t);
1048
609
  },
1049
610
  submit: async () => {
1050
- const t = N(e()), n = x();
611
+ const t = U(e()), a = O();
1051
612
  try {
1052
- return await D(t || void 0, n, E.CONFIRM_PAYMENT, {}), {
613
+ return await D(t || void 0, a, P.CONFIRM_PAYMENT, {}), {
1053
614
  paymentMethod: void 0
1054
615
  };
1055
- } catch (a) {
616
+ } catch (i) {
1056
617
  return {
1057
618
  error: {
1058
- message: a instanceof Error ? a.message : "Payment failed",
619
+ message: i instanceof Error ? i.message : "Payment failed",
1059
620
  code: "payment_error",
1060
621
  type: "payment_error"
1061
622
  }
@@ -1064,69 +625,538 @@ function Ge() {
1064
625
  }
1065
626
  };
1066
627
  }
1067
- function $e(e) {
1068
- let r = null;
628
+ var p = /* @__PURE__ */ ((e) => (e.Success = "Success", e.Failed = "Failed", e.Timeout = "Timeout", e))(p || {});
629
+ class R {
630
+ constructor(n, t) {
631
+ C(this, "overlay", null);
632
+ C(this, "modalContent", null);
633
+ this.data = n, this.options = t;
634
+ }
635
+ fail(n) {
636
+ var a, i;
637
+ const t = new Error(n);
638
+ return (i = (a = this.options).onError) == null || i.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
+ C(this, "iframe", null);
700
+ C(this, "messageListener", null);
701
+ C(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 i = 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", i.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: p.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: p.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 r = d.createElement("input");
732
+ r.setAttribute("type", "hidden"), r.setAttribute("name", "creq"), r.setAttribute("value", a), s.appendChild(r), 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 L = /* @__PURE__ */ new Map();
740
+ function k(e) {
741
+ const n = L.get(e);
742
+ if (n) return n;
743
+ const t = new Promise((a, i) => {
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
+ L.delete(e), i(new Error(`Failed to load script: ${e}`));
751
+ }, (document.head || document.body).appendChild(o);
752
+ });
753
+ return L.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
+ C(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 i = window.KrAuthenticate;
774
+ return i ? new Promise((o) => {
775
+ this.timeoutId = setTimeout(() => {
776
+ var s, r;
777
+ this.cleanup(), (r = (s = this.options).onTimeout) == null || r.call(s), o({
778
+ status: p.Timeout
779
+ });
780
+ }, this.options.timeoutMs ?? Me), new i(a).authenticate(t, () => {
781
+ var s, r;
782
+ this.cleanup(), (r = (s = this.options).onComplete) == null || r.call(s), o({
783
+ status: p.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
+ C(this, "timeoutId", null);
804
+ C(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 i = this.data.environment ?? _.Production;
814
+ try {
815
+ await k(De[i]);
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 r, l;
825
+ this.cleanup(), (l = (r = this.options).onTimeout) == null || l.call(r), s({
826
+ status: p.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((r) => {
835
+ var g, w;
836
+ if (this.cleanup(), !(r != null && r.length)) {
837
+ s(this.fail("PagarMe 3DS returned no response"));
838
+ return;
839
+ }
840
+ const l = r[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: p.Success,
847
+ dsTransactionId: l.tds_server_trans_id
848
+ })) : s(this.fail(`3DS failed with status: ${l.trans_status}`));
849
+ }).catch((r) => {
850
+ this.cleanup(), s(this.fail(r instanceof Error ? r.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: i,
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: i
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: i,
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 (!i) 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 r = window.PagSeguro;
929
+ if (!r) return this.fail("PagSeguro SDK not available");
930
+ r.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 r.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: i,
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: p.Success,
984
+ dsTransactionId: h.id
985
+ }) : h.status === "CHANGE_PAYMENT_METHOD" ? this.fail("PagSeguro requires a different payment method") : {
986
+ status: p.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 Ue = {
1009
+ [I.MercadoPago]: ve,
1010
+ PayConductor: Ie,
1011
+ [I.PagarMe]: Re,
1012
+ [I.PagSeguro]: xe
1013
+ };
1014
+ class Le extends Error {
1015
+ constructor(n, t) {
1016
+ super(n), this.title = t, this.name = "PayConductorThreeDSApiError";
1017
+ }
1018
+ }
1019
+ class Oe {
1020
+ constructor(n) {
1021
+ this.publicKey = n;
1022
+ }
1023
+ async completeManualChallenge(n, t) {
1024
+ const a = await fetch(`${this.baseUrl}/three-ds/complete/${n}`, {
1025
+ method: "POST",
1026
+ headers: this.headers,
1027
+ body: JSON.stringify({
1028
+ providerTransactionId: t
1029
+ })
1030
+ });
1031
+ a.ok || await this.parseResponseError("Failed to complete native 3DS challenge", a);
1032
+ }
1033
+ async parseResponseError(n, t) {
1034
+ var i, o, d, s;
1035
+ let a = "";
1036
+ try {
1037
+ const r = await t.json();
1038
+ 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);
1039
+ } catch {
1040
+ }
1041
+ throw new Le(a, n);
1042
+ }
1043
+ get baseUrl() {
1044
+ return typeof window < "u" && window.location.href.includes("localhost") ? "http://localhost:3000/api/v1/sdk" : "https://payconductor.ai/api/v1/sdk";
1045
+ }
1046
+ get headers() {
1047
+ return {
1048
+ Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
1049
+ "Content-Type": "application/json"
1050
+ };
1051
+ }
1052
+ }
1053
+ const Fe = [I.PagSeguro];
1054
+ class Ke {
1055
+ constructor(n) {
1056
+ C(this, "data");
1057
+ C(this, "provider", null);
1058
+ this.data = n;
1059
+ }
1060
+ get needsChallenge() {
1061
+ return this.data.status === "NeedChallenge" || this.data.statusDetail === "ThreeDsAwaitingChallenge";
1062
+ }
1063
+ get acquirer() {
1064
+ return this.data.acquirer;
1065
+ }
1066
+ async authenticate(n) {
1067
+ if (!this.needsChallenge)
1068
+ return {
1069
+ status: p.Success
1070
+ };
1071
+ const {
1072
+ acquirer: t
1073
+ } = this.data;
1074
+ if (!t)
1075
+ return {
1076
+ status: p.Failed,
1077
+ error: new Error("Missing 3DS acquirer")
1078
+ };
1079
+ const a = Ue[t];
1080
+ if (!a)
1081
+ return {
1082
+ status: p.Failed,
1083
+ error: new Error(`Unsupported 3DS provider: ${t}`)
1084
+ };
1085
+ const i = {
1086
+ ...n,
1087
+ threeDSecure: this.data
1088
+ };
1089
+ this.provider = new a(this.data, i);
1090
+ const o = await this.provider.authenticate();
1091
+ return o.status === p.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;
1092
+ }
1093
+ destroy() {
1094
+ this.provider && (this.provider.cleanup(), this.provider = null);
1095
+ }
1096
+ }
1097
+ function at(e) {
1098
+ let n = null;
1069
1099
  return {
1070
- handleChallenge: async (a) => {
1100
+ handleChallenge: async (i) => {
1071
1101
  var s;
1072
- if (!(a.status === "NeedChallenge" || a.statusDetail === "ThreeDsAwaitingChallenge"))
1102
+ if (!(i.status === "NeedChallenge" || i.statusDetail === "ThreeDsAwaitingChallenge"))
1073
1103
  return {
1074
- status: C.Success
1104
+ status: p.Success
1075
1105
  };
1076
- (s = e == null ? void 0 : e.onChallenge) == null || s.call(e), r = new H(a);
1077
- const d = await r.authenticate({
1106
+ (s = e == null ? void 0 : e.onChallenge) == null || s.call(e), n = new Ke(i);
1107
+ const d = await n.authenticate({
1078
1108
  onComplete: e == null ? void 0 : e.onComplete,
1079
1109
  onError: e == null ? void 0 : e.onError,
1080
1110
  onTimeout: e == null ? void 0 : e.onTimeout
1081
1111
  });
1082
- return r.destroy(), r = null, d;
1112
+ return n.destroy(), n = null, d;
1083
1113
  },
1084
1114
  destroy: () => {
1085
- r == null || r.destroy(), r = null;
1115
+ n == null || n.destroy(), n = null;
1086
1116
  }
1087
1117
  };
1088
1118
  }
1089
- class ke extends Error {
1090
- constructor(r, t) {
1091
- super(r), this.title = t, this.name = "PayConductorApiError";
1119
+ class Be extends Error {
1120
+ constructor(n, t) {
1121
+ super(n), this.title = t, this.name = "PayConductorTokenizeApiError";
1092
1122
  }
1093
1123
  }
1094
- class Ne {
1095
- constructor(r) {
1096
- this.publicKey = r;
1124
+ class ze {
1125
+ constructor(n) {
1126
+ this.publicKey = n;
1097
1127
  }
1098
1128
  async getSettings() {
1099
- const r = await fetch(`${this.baseUrl}/card-tokenization/settings`, {
1129
+ const n = await fetch(`${this.baseUrl}/card-tokenization/settings`, {
1100
1130
  method: "GET",
1101
1131
  headers: this.headers
1102
1132
  });
1103
- return r.ok || await this.parseResponseError("Failed to fetch settings", r), r.json();
1133
+ return n.ok || await this.parseResponseError("Failed to fetch settings", n), await n.json();
1104
1134
  }
1105
- async createToken(r) {
1135
+ async createToken(n) {
1106
1136
  const t = await fetch(`${this.baseUrl}/card-tokenization/tokenize`, {
1107
1137
  method: "POST",
1108
1138
  headers: this.headers,
1109
- body: JSON.stringify(r)
1139
+ body: JSON.stringify(n)
1110
1140
  });
1111
- return t.ok || await this.parseResponseError("Failed to generate token", t), t.json();
1141
+ return t.ok || await this.parseResponseError("Failed to generate token", t), await t.json();
1112
1142
  }
1113
- async saveTokens(r, t, n) {
1114
- const a = await fetch(`${this.baseUrl}/card-tokenization/save-tokens/${t}/${n}`, {
1143
+ async saveTokens(n, t, a) {
1144
+ const i = await fetch(`${this.baseUrl}/card-tokenization/save-tokens/${t}/${a}`, {
1115
1145
  method: "POST",
1116
1146
  headers: this.headers,
1117
- body: JSON.stringify(r)
1147
+ body: JSON.stringify(n)
1118
1148
  });
1119
- a.ok || await this.parseResponseError("Failed to save tokens", a);
1149
+ i.ok || await this.parseResponseError("Failed to save tokens", i);
1120
1150
  }
1121
- async parseResponseError(r, t) {
1122
- var a, o, d, s;
1123
- let n = "";
1151
+ async parseResponseError(n, t) {
1152
+ var i, o, d, s;
1153
+ let a = "";
1124
1154
  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);
1155
+ const r = await t.json();
1156
+ 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);
1127
1157
  } catch {
1128
1158
  }
1129
- throw new ke(n, r);
1159
+ throw new Be(a, n);
1130
1160
  }
1131
1161
  get baseUrl() {
1132
1162
  return typeof window < "u" && window.location.href.includes("localhost") ? "http://localhost:3000/api/v1/sdk" : "https://payconductor.ai/api/v1/sdk";
@@ -1138,16 +1168,15 @@ class Ne {
1138
1168
  };
1139
1169
  }
1140
1170
  }
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;
1171
+ class He {
1172
+ constructor(n) {
1173
+ this.input = n;
1145
1174
  }
1146
1175
  }
1147
- class Le extends xe {
1176
+ class Ye extends He {
1148
1177
  constructor() {
1149
1178
  super(...arguments);
1150
- p(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
1179
+ C(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
1151
1180
  }
1152
1181
  async tokenize() {
1153
1182
  if (!("publicKey" in this.input.setting))
@@ -1156,76 +1185,76 @@ class Le extends xe {
1156
1185
  throw new Error("Customer document number is required for tokenization");
1157
1186
  const t = window.MercadoPago;
1158
1187
  if (!t) throw new Error("MercadoPago SDK not available");
1159
- const n = new t(this.input.setting.publicKey), {
1160
- expiration: a,
1188
+ const a = new t(this.input.setting.publicKey), {
1189
+ expiration: i,
1161
1190
  cvv: o,
1162
1191
  number: d,
1163
1192
  holderName: s
1164
1193
  } = this.input.card;
1165
- return (await n.createCardToken({
1166
- cardExpirationMonth: String(a.month),
1167
- cardExpirationYear: String(a.year),
1194
+ return (await a.createCardToken({
1195
+ cardExpirationMonth: String(i.month),
1196
+ cardExpirationYear: String(i.year),
1168
1197
  cardholderName: s,
1169
1198
  cardNumber: d,
1170
1199
  securityCode: o,
1171
- identificationType: this.input.customer.documentType === Y.Cpf ? "CPF" : "CNPJ",
1200
+ identificationType: this.input.customer.documentType === G.Cpf ? "CPF" : "CNPJ",
1172
1201
  identificationNumber: this.input.customer.documentNumber
1173
1202
  })).id;
1174
1203
  }
1175
1204
  }
1176
- const Oe = {
1177
- [j.MercadoPago]: Le
1205
+ const Ge = {
1206
+ [I.MercadoPago]: Ye
1178
1207
  };
1179
- class Ue {
1180
- constructor(r) {
1181
- p(this, "api");
1182
- this.publicKey = r, this.api = new Ne(this.publicKey);
1208
+ class Ve {
1209
+ constructor(n) {
1210
+ C(this, "api");
1211
+ this.publicKey = n, this.api = new ze(this.publicKey);
1183
1212
  }
1184
- async tokenizeCard(r) {
1185
- this.validateCard(r);
1213
+ async tokenizeCard(n) {
1214
+ this.validateCard(n);
1186
1215
  const {
1187
1216
  customerId: t,
1188
- token: n
1217
+ token: a
1189
1218
  } = await this.api.createToken({
1190
- card: r.card,
1191
- customer: r.customer,
1219
+ card: n.card,
1220
+ customer: n.customer,
1192
1221
  saveCard: !1
1193
1222
  }), {
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,
1223
+ settings: i
1224
+ } = await this.api.getSettings(), d = (await Promise.all(i.map(async (s) => {
1225
+ const r = Ge[s.key];
1226
+ if (!r) return null;
1227
+ const l = new r({
1228
+ ...n,
1200
1229
  setting: s.settings
1201
1230
  });
1202
- return await R(u.scriptUrl), {
1203
- token: await u.tokenize(),
1231
+ return await k(l.scriptUrl), {
1232
+ token: await l.tokenize(),
1204
1233
  integrationId: s.integrationId,
1205
1234
  providerKey: s.key
1206
1235
  };
1207
1236
  }))).filter((s) => s !== null);
1208
- return d.length > 0 && await this.api.saveTokens(d, t, n), n;
1237
+ return d.length > 0 && await this.api.saveTokens(d, t, a), a;
1209
1238
  }
1210
- validateCard(r) {
1239
+ validateCard(n) {
1211
1240
  const {
1212
1241
  number: t,
1213
- cvv: n,
1214
- expiration: a,
1242
+ cvv: a,
1243
+ expiration: i,
1215
1244
  holderName: o
1216
- } = r.card;
1217
- if (!t || !n || !(a != null && a.month) || !(a != null && a.year) || !o)
1245
+ } = n.card;
1246
+ if (!t || !a || !(i != null && i.month) || !(i != null && i.year) || !o)
1218
1247
  throw new Error("Invalid card data");
1219
1248
  }
1220
1249
  }
1221
- function Je(e) {
1222
- const r = new Ue(e.publicKey);
1250
+ function it(e) {
1251
+ const n = new Ve(e.publicKey);
1223
1252
  return {
1224
- tokenizeCard: async (n) => {
1225
- var a, o;
1253
+ tokenizeCard: async (a) => {
1254
+ var i, o;
1226
1255
  try {
1227
- const d = await r.tokenizeCard(n);
1228
- return (a = e.onSuccess) == null || a.call(e, d), d;
1256
+ const d = await n.tokenizeCard(a);
1257
+ return (i = e.onSuccess) == null || i.call(e, d), d;
1229
1258
  } catch (d) {
1230
1259
  const s = d instanceof Error ? d : new Error("Tokenization failed");
1231
1260
  return (o = e.onError) == null || o.call(e, s), null;
@@ -1234,36 +1263,44 @@ function Je(e) {
1234
1263
  };
1235
1264
  }
1236
1265
  export {
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
1266
+ ue as ALLOWED_ORIGINS,
1267
+ ie as CardBrand,
1268
+ re as CurrencyType,
1269
+ oe as DeviceType,
1270
+ G as DocumentType,
1271
+ Xe as ERROR_CODES,
1272
+ de as ErrorCode,
1273
+ le as IFRAME_BASE_URL,
1274
+ B as IFRAME_DEFAULT_HEIGHT_VALUE,
1275
+ v as IncomingMessage,
1276
+ se as InputStyleKey,
1277
+ I as IntegrationProvider,
1278
+ _ as OrganizationEnvironment,
1279
+ M as OutgoingMessage,
1280
+ P as POST_MESSAGES,
1281
+ Ze as PayConductor,
1282
+ Ke as PayConductor3DSSDK,
1283
+ Qe as PayConductorCheckoutElement,
1284
+ et as PayConductorThreeDSElement,
1285
+ Ve as PayConductorTokenizeSDK,
1286
+ Z as PaymentMethod,
1287
+ Q as PaymentMethodLayout,
1288
+ ee as PaymentStatus,
1289
+ he as REQUEST_TIMEOUT,
1290
+ me as SKELETON_CSS,
1291
+ z as SKELETON_STYLE_ID,
1292
+ te as StatusDetail,
1293
+ ae as ThreeDSResultStatus,
1294
+ ne as ThreeDsAuthenticationStatus,
1295
+ fe as buildIframeUrl,
1296
+ Ze as default,
1297
+ Je as defaultTheme,
1298
+ ye as generateRequestId,
1299
+ we as isValidOrigin,
1300
+ k as loadScript,
1301
+ tt as usePayConductor,
1302
+ nt as usePayconductorElement,
1303
+ at as useThreeDS,
1304
+ it as useTokenize
1268
1305
  };
1269
1306
  //# sourceMappingURL=index.es.js.map