@payconductor/react 1.2.5 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,11 +1,11 @@
1
- var X = Object.defineProperty;
2
- var Z = (e, a, t) => a in e ? X(e, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[a] = t;
3
- var b = (e, a, t) => Z(e, typeof a != "symbol" ? a + "" : a, t);
4
- import { jsx as N, jsxs as Q } from "react/jsx-runtime";
5
- import { useState as I, useEffect as z, useRef as ee } from "react";
6
- const te = "https://app.payconductor.ai", ne = "http://localhost:3000", G = "https://iframe.payconductor.ai/v1", V = "http://localhost:5175/v1", ae = 3e5, ie = "600px";
7
- var re = /* @__PURE__ */ ((e) => (e.Pix = "Pix", e.CreditCard = "CreditCard", e.DebitCard = "DebitCard", e.BankSlip = "BankSlip", e.Crypto = "Crypto", e.ApplePay = "ApplePay", e.NuPay = "NuPay", e.PicPay = "PicPay", e.AmazonPay = "AmazonPay", e.SepaDebit = "SepaDebit", e.GooglePay = "GooglePay", e))(re || {}), oe = /* @__PURE__ */ ((e) => (e.Grid = "grid", e.Vertical = "vertical", e.Horizontal = "horizontal", e))(oe || {}), se = /* @__PURE__ */ ((e) => (e.Succeeded = "succeeded", e.Pending = "pending", e.Failed = "failed", e))(se || {}), de = /* @__PURE__ */ ((e) => (e.ThreeDsAwaitingChallenge = "ThreeDsAwaitingChallenge", e))(de || {}), ce = /* @__PURE__ */ ((e) => (e.Authenticated = "Authenticated", e.NotAuthenticated = "NotAuthenticated", e.NeedChallenge = "NeedChallenge", e))(ce || {}), le = /* @__PURE__ */ ((e) => (e.Pending = "Pending", e.Authenticated = "Authenticated", e.Failed = "Failed", e.NotEnrolled = "NotEnrolled", e))(le || {}), q = /* @__PURE__ */ ((e) => (e.Cpf = "Cpf", e.Cnpj = "Cnpj", e))(q || {}), v = /* @__PURE__ */ ((e) => (e.Asaas = "Asaas", e.Sandbox = "Sandbox", e.SandboxSplit = "SandboxSplit", e.MercadoPago = "MercadoPago", e.NuPay = "NuPay", e.PicPay = "PicPay", e.Woovi = "Woovi", e.EfiBank = "EfiBank", e.BrasPag = "BrasPag", e.PagarMe = "PagarMe", e.BancoDoBrasil = "BancoDoBrasil", e.PagSeguro = "PagSeguro", e.Ebanx = "Ebanx", e.OnlyUp = "OnlyUp", e.Barte = "Barte", e.BarteSplit = "BarteSplit", e.PagSmileA55 = "PagSmileA55", e.Avantti = "Avantti", e.MonsterGateway = "MonsterGateway", e.SAC = "SAC", e.Lyra = "Lyra", e))(v || {}), ue = /* @__PURE__ */ ((e) => (e.Visa = "Visa", e.Mastercard = "Mastercard", e.AmericanExpress = "AmericanExpress", e.DinersClub = "DinersClub", e.Discover = "Discover", e.JCB = "JCB", e.UnionPay = "UnionPay", e.Maestro = "Maestro", e.Mir = "Mir", e.Elo = "Elo", e.Hiper = "Hiper", e.Hipercard = "Hipercard", e.Verve = "Verve", e.Unknown = "Unknown", e))(ue || {}), R = /* @__PURE__ */ ((e) => (e.Production = "Production", e.Sandbox = "Sandbox", e))(R || {}), he = /* @__PURE__ */ ((e) => (e.USD = "USD", e.EUR = "EUR", e.BRL = "BRL", e.ARS = "ARS", e.CAD = "CAD", e.COP = "COP", e.GBP = "GBP", e.JPY = "JPY", e.MXN = "MXN", e.MZN = "MZN", e.CNY = "CNY", e.SAR = "SAR", e.ETH = "ETH", e.BNB = "BNB", e.BTC = "BTC", e.USDT = "USDT", e.USDC = "USDC", e.DOGE = "DOGE", e.SOL = "SOL", e))(he || {}), me = /* @__PURE__ */ ((e) => (e.Android = "android", e.IOS = "ios", e.Web = "web", e.Chrome = "chrome", e.Safari = "safari", e))(me || {}), fe = /* @__PURE__ */ ((e) => (e.Padding = "padding", e.Radius = "radius", e.Color = "color", e.Background = "background", e.Shadow = "shadow", e))(fe || {}), M = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(M || {}), T = /* @__PURE__ */ ((e) => (e.Ready = "Ready", e.Error = "Error", e.CheckoutSessionCreated = "CheckoutSessionCreated", e.PaymentComplete = "PaymentComplete", e.PaymentFailed = "PaymentFailed", e.PaymentPending = "PaymentPending", e.ValidationError = "ValidationError", e.PaymentMethodSelected = "PaymentMethodSelected", e.Resize = "Resize", e.ThreeDSChallenge = "ThreeDSChallenge", e.ThreeDSComplete = "ThreeDSComplete", e.ThreeDSFailed = "ThreeDSFailed", e))(T || {}), ye = /* @__PURE__ */ ((e) => (e.InvalidClient = "InvalidClient", e.InvalidToken = "InvalidToken", e.NetworkError = "NetworkError", e.IframeNotReady = "IframeNotReady", e.PaymentDeclined = "PaymentDeclined", e.ValidationError = "ValidationError", e.Timeout = "Timeout", e))(ye || {});
8
- const at = {
1
+ var te = Object.defineProperty;
2
+ var ae = (e, a, t) => a in e ? te(e, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[a] = t;
3
+ var P = (e, a, t) => ae(e, typeof a != "symbol" ? a + "" : a, t);
4
+ import { jsx as O, jsxs as ne } from "react/jsx-runtime";
5
+ import { useState as I, useEffect as K, useRef as re } from "react";
6
+ const ie = "https://app.payconductor.ai", oe = "http://localhost:3000", W = "https://iframe.payconductor.ai/v1", J = "http://localhost:5175/v1", se = 3e5, de = "600px";
7
+ var ce = /* @__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))(ce || {}), le = /* @__PURE__ */ ((e) => (e.Grid = "grid", e.Vertical = "vertical", e.Horizontal = "horizontal", e))(le || {}), R = /* @__PURE__ */ ((e) => (e.Succeeded = "succeeded", e.Pending = "pending", e.Failed = "failed", e))(R || {}), j = /* @__PURE__ */ ((e) => (e.ThreeDsAwaitingChallenge = "ThreeDsAwaitingChallenge", e))(j || {}), ue = /* @__PURE__ */ ((e) => (e.Authenticated = "Authenticated", e.NotAuthenticated = "NotAuthenticated", e.NeedChallenge = "NeedChallenge", e))(ue || {}), he = /* @__PURE__ */ ((e) => (e.Pending = "Pending", e.Authenticated = "Authenticated", e.Failed = "Failed", e.NotEnrolled = "NotEnrolled", e))(he || {}), X = /* @__PURE__ */ ((e) => (e.Cpf = "Cpf", e.Cnpj = "Cnpj", e))(X || {}), T = /* @__PURE__ */ ((e) => (e.Asaas = "Asaas", e.Sandbox = "Sandbox", e.SandboxSplit = "SandboxSplit", e.MercadoPago = "MercadoPago", e.NuPay = "NuPay", e.PicPay = "PicPay", e.Woovi = "Woovi", e.EfiBank = "EfiBank", e.BrasPag = "BrasPag", e.PagarMe = "PagarMe", e.BancoDoBrasil = "BancoDoBrasil", e.PagSeguro = "PagSeguro", e.Ebanx = "Ebanx", e.OnlyUp = "OnlyUp", e.Barte = "Barte", e.BarteSplit = "BarteSplit", e.PagSmileA55 = "PagSmileA55", e.Avantti = "Avantti", e.MonsterGateway = "MonsterGateway", e.SAC = "SAC", e.Lyra = "Lyra", e))(T || {}), me = /* @__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))(me || {}), k = /* @__PURE__ */ ((e) => (e.Production = "Production", e.Sandbox = "Sandbox", e))(k || {}), fe = /* @__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))(fe || {}), ye = /* @__PURE__ */ ((e) => (e.Android = "android", e.IOS = "ios", e.Web = "web", e.Chrome = "chrome", e.Safari = "safari", e))(ye || {}), ge = /* @__PURE__ */ ((e) => (e.Padding = "padding", e.Radius = "radius", e.Color = "color", e.Background = "background", e.Shadow = "shadow", e))(ge || {}), D = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(D || {}), v = /* @__PURE__ */ ((e) => (e.Ready = "Ready", e.Error = "Error", e.CheckoutSessionCreated = "CheckoutSessionCreated", e.PaymentComplete = "PaymentComplete", e.PaymentFailed = "PaymentFailed", e.PaymentPending = "PaymentPending", e.ValidationError = "ValidationError", e.PaymentMethodSelected = "PaymentMethodSelected", e.Resize = "Resize", e.ThreeDSChallenge = "ThreeDSChallenge", e.ThreeDSComplete = "ThreeDSComplete", e.ThreeDSFailed = "ThreeDSFailed", e))(v || {}), Ee = /* @__PURE__ */ ((e) => (e.InvalidClient = "InvalidClient", e.InvalidToken = "InvalidToken", e.NetworkError = "NetworkError", e.IframeNotReady = "IframeNotReady", e.PaymentDeclined = "PaymentDeclined", e.ValidationError = "ValidationError", e.Timeout = "Timeout", e))(Ee || {});
8
+ const ot = {
9
9
  primaryColor: "#0066ff",
10
10
  secondaryColor: "#5a6b7c",
11
11
  backgroundColor: "transparent",
@@ -52,22 +52,22 @@ const at = {
52
52
  buttonBorderRadius: "8px",
53
53
  transitionDuration: "0.2s",
54
54
  transitionTimingFunction: "ease"
55
- }, W = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") && !window.location.search.includes("production"), Ee = W ? V : G, _ = `${W ? ne : te}/api/v1/sdk`, ge = [V, G], j = ie, we = ae, p = {
56
- INIT: M.Init,
57
- CONFIG: M.Config,
58
- UPDATE: M.Update,
59
- CONFIRM_PAYMENT: M.ConfirmPayment,
60
- VALIDATE: M.Validate,
61
- RESET: M.Reset,
62
- READY: T.Ready,
63
- ERROR: T.Error,
64
- PAYMENT_COMPLETE: T.PaymentComplete,
65
- PAYMENT_FAILED: T.PaymentFailed,
66
- PAYMENT_PENDING: T.PaymentPending,
67
- VALIDATION_ERROR: T.ValidationError,
68
- PAYMENT_METHOD_SELECTED: T.PaymentMethodSelected,
69
- RESIZE: T.Resize
70
- }, it = {
55
+ }, Z = window.location.search.includes("development"), we = Z ? J : W, M = `${Z ? oe : ie}/api/v1/sdk`, Se = [J, W], G = de, be = se, w = {
56
+ INIT: D.Init,
57
+ CONFIG: D.Config,
58
+ UPDATE: D.Update,
59
+ CONFIRM_PAYMENT: D.ConfirmPayment,
60
+ VALIDATE: D.Validate,
61
+ RESET: D.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
+ }, st = {
71
71
  INVALID_CLIENT: "InvalidClient",
72
72
  INVALID_TOKEN: "InvalidToken",
73
73
  NETWORK_ERROR: "NetworkError",
@@ -75,7 +75,7 @@ const at = {
75
75
  PAYMENT_DECLINED: "PaymentDeclined",
76
76
  VALIDATION_ERROR: "ValidationError",
77
77
  TIMEOUT: "Timeout"
78
- }, H = "payconductor-skeleton-style", pe = `
78
+ }, Y = "payconductor-skeleton-style", Pe = `
79
79
  @keyframes payconductor-shimmer {
80
80
  0% { background-position: -200% 0; }
81
81
  100% { background-position: 200% 0; }
@@ -88,16 +88,16 @@ const at = {
88
88
  width: 100%;
89
89
  }
90
90
  `;
91
- function be(e) {
91
+ function Ce(e) {
92
92
  const a = new URLSearchParams({
93
93
  publicKey: e.publicKey
94
94
  });
95
- return `${Ee}?${a.toString()}`;
95
+ return `${we}?${a.toString()}`;
96
96
  }
97
- function Pe() {
97
+ function pe() {
98
98
  return crypto.randomUUID();
99
99
  }
100
- function Ce(e, a) {
100
+ function Ae(e, a) {
101
101
  return a.some((t) => {
102
102
  try {
103
103
  return new URL(t).origin === e;
@@ -106,151 +106,151 @@ function Ce(e, a) {
106
106
  }
107
107
  });
108
108
  }
109
- function B() {
109
+ function z() {
110
110
  return /* @__PURE__ */ new Map();
111
111
  }
112
112
  function x(e, a, t, n) {
113
- return new Promise((i, r) => {
113
+ return new Promise((r, i) => {
114
114
  if (!e || !("contentWindow" in e)) {
115
- r(new Error("Iframe not defined"));
115
+ i(new Error("Iframe not defined"));
116
116
  return;
117
117
  }
118
118
  if (!(e != null && e.contentWindow)) {
119
- r(new Error("Iframe not ready"));
119
+ i(new Error("Iframe not ready"));
120
120
  return;
121
121
  }
122
122
  if (!a) {
123
- r(new Error("Pending requests not initialized"));
123
+ i(new Error("Pending requests not initialized"));
124
124
  return;
125
125
  }
126
- const s = Pe();
126
+ const s = pe();
127
127
  a.set(s, {
128
- resolve: i,
129
- reject: r
128
+ resolve: r,
129
+ reject: i
130
130
  }), e.contentWindow.postMessage({
131
131
  type: t,
132
132
  data: n,
133
133
  requestId: s
134
134
  }, "*"), setTimeout(() => {
135
- a != null && a.has(s) && (a.delete(s), r(new Error("Request timeout")));
136
- }, we);
135
+ a != null && a.has(s) && (a.delete(s), i(new Error("Request timeout")));
136
+ }, be);
137
137
  });
138
138
  }
139
- function Se(e, a, t) {
140
- return x(e, a, p.CONFIRM_PAYMENT, t);
139
+ function ve(e, a, t) {
140
+ return x(e, a, w.CONFIRM_PAYMENT, t);
141
141
  }
142
- async function Ae(e, a, t) {
143
- return await Se(e, a, {
142
+ async function Te(e, a, t) {
143
+ return await ve(e, a, {
144
144
  orderId: t.orderId
145
145
  });
146
146
  }
147
- function Te(e, a, t) {
148
- return x(e, a, p.VALIDATE, t);
149
- }
150
- function ve(e, a) {
151
- return x(e, a, p.RESET);
152
- }
153
147
  function Ie(e, a, t) {
154
- return x(e, a, p.CONFIG, t);
148
+ return x(e, a, w.VALIDATE, t);
149
+ }
150
+ function De(e, a) {
151
+ return x(e, a, w.RESET);
155
152
  }
156
153
  function Me(e, a, t) {
157
- return x(e, a, p.INIT, t);
154
+ return x(e, a, w.CONFIG, t);
158
155
  }
159
- function xe(e, a, t, n, i, r, s, d, o, c, w, E) {
160
- const m = e.data, {
161
- requestId: f,
162
- type: u,
156
+ function xe(e, a, t) {
157
+ return x(e, a, w.INIT, t);
158
+ }
159
+ function Re(e, a, t, n, r, i, s, d, o, l, y, E) {
160
+ const c = e.data, {
161
+ requestId: m,
162
+ type: b,
163
163
  data: g,
164
- error: S
165
- } = m;
166
- if (u === p.READY) {
167
- if (n == null || n(), f && (a != null && a.has(f))) {
164
+ error: p
165
+ } = c;
166
+ if (b === w.READY) {
167
+ if (n == null || n(), m && (a != null && a.has(m))) {
168
168
  const {
169
169
  resolve: A
170
- } = a.get(f);
171
- a.delete(f), A(g);
170
+ } = a.get(m);
171
+ a.delete(m), A(g);
172
172
  }
173
173
  return;
174
174
  }
175
- if (Ce(e.origin, ge)) {
176
- if (f && a && a.has(f)) {
175
+ if (Ae(e.origin, Se)) {
176
+ if (m && a && a.has(m)) {
177
177
  const {
178
178
  resolve: A,
179
- reject: O
180
- } = a.get(f);
181
- a.delete(f), S ? O(new Error(String(S.message))) : A(g);
179
+ reject: U
180
+ } = a.get(m);
181
+ a.delete(m), p ? U(new Error(String(p.message))) : A(g);
182
182
  return;
183
183
  }
184
- if (u === p.ERROR) {
185
- t((S == null ? void 0 : S.message) || "Unknown error"), i == null || i(new Error(String(S == null ? void 0 : S.message)));
184
+ if (b === w.ERROR) {
185
+ t((p == null ? void 0 : p.message) || "Unknown error"), r == null || r(new Error(String(p == null ? void 0 : p.message)));
186
186
  return;
187
187
  }
188
- if (u === p.PAYMENT_COMPLETE) {
189
- g && typeof g == "object" && "status" in g && (r == null || r(g));
188
+ if (b === w.PAYMENT_COMPLETE) {
189
+ g && typeof g == "object" && "status" in g && (i == null || i(g));
190
190
  return;
191
191
  }
192
- if (u === p.PAYMENT_FAILED) {
192
+ if (b === w.PAYMENT_FAILED) {
193
193
  g && typeof g == "object" && "status" in g && (s == null || s(g));
194
194
  return;
195
195
  }
196
- if (u === p.PAYMENT_PENDING) {
196
+ if (b === w.PAYMENT_PENDING) {
197
197
  g && typeof g == "object" && "status" in g && (d == null || d(g));
198
198
  return;
199
199
  }
200
- if (u === p.PAYMENT_METHOD_SELECTED) {
200
+ if (b === w.PAYMENT_METHOD_SELECTED) {
201
201
  g && typeof g == "object" && "paymentMethod" in g && (o == null || o(g.paymentMethod));
202
202
  return;
203
203
  }
204
- if (u !== p.RESIZE) {
205
- if (u === T.ThreeDSChallenge) {
206
- c == null || c();
204
+ if (b !== w.RESIZE) {
205
+ if (b === v.ThreeDSChallenge) {
206
+ l == null || l();
207
207
  return;
208
208
  }
209
- if (u === T.ThreeDSComplete) {
210
- w == null || w();
209
+ if (b === v.ThreeDSComplete) {
210
+ y == null || y();
211
211
  return;
212
212
  }
213
- if (u === T.ThreeDSFailed) {
213
+ if (b === v.ThreeDSFailed) {
214
214
  E == null || E();
215
215
  return;
216
216
  }
217
217
  }
218
218
  }
219
219
  }
220
- function rt(e) {
220
+ function dt(e) {
221
221
  const [a, t] = I(
222
222
  () => !1
223
- ), [n, i] = I(() => null), [r, s] = I(
223
+ ), [n, r] = I(() => null), [i, s] = I(
224
224
  () => ""
225
225
  ), [d, o] = I(() => null);
226
- return z(() => {
227
- const c = (...h) => {
226
+ return K(() => {
227
+ const l = (...h) => {
228
228
  e.debug && console.log("[PayConductor]", ...h);
229
- }, w = be({
229
+ }, y = Ce({
230
230
  publicKey: e.publicKey
231
231
  });
232
- s(w), t(!0);
233
- const E = B();
234
- let m = !1;
235
- c("init", e.publicKey), c("iframeUrl", w);
236
- const f = () => {
237
- var C, l;
238
- const h = (l = (C = window.PayConductor) == null ? void 0 : C.frame) == null ? void 0 : l.iframe;
232
+ s(y), t(!0);
233
+ const E = z();
234
+ let c = !1;
235
+ l("init", e.publicKey), l("iframeUrl", y);
236
+ const m = () => {
237
+ var C, u;
238
+ const h = (u = (C = window.PayConductor) == null ? void 0 : C.frame) == null ? void 0 : u.iframe;
239
239
  if (h) {
240
240
  if (h instanceof HTMLIFrameElement) return h;
241
241
  if (typeof h == "object" && h !== null) {
242
- const y = h;
243
- if ("current" in y && y.current instanceof HTMLIFrameElement)
244
- return y.current;
245
- if ("value" in y && y.value instanceof HTMLIFrameElement)
246
- return y.value;
242
+ const f = h;
243
+ if ("current" in f && f.current instanceof HTMLIFrameElement)
244
+ return f.current;
245
+ if ("value" in f && f.value instanceof HTMLIFrameElement)
246
+ return f.value;
247
247
  }
248
248
  return h;
249
249
  }
250
250
  return document.querySelector(
251
251
  ".payconductor-element iframe"
252
252
  ) ?? void 0;
253
- }, u = {
253
+ }, b = {
254
254
  get iframe() {
255
255
  return document.querySelector(
256
256
  ".payconductor-element iframe"
@@ -258,7 +258,7 @@ function rt(e) {
258
258
  },
259
259
  set iframe(h) {
260
260
  },
261
- iframeUrl: w,
261
+ iframeUrl: y,
262
262
  error: null
263
263
  }, g = {
264
264
  publicKey: e.publicKey,
@@ -266,16 +266,16 @@ function rt(e) {
266
266
  locale: e.locale,
267
267
  paymentMethods: e.paymentMethods,
268
268
  defaultPaymentMethod: e.defaultPaymentMethod
269
- }, S = {
269
+ }, p = {
270
270
  confirmPayment: (h) => {
271
- var l;
272
- c("→ CONFIRM_PAYMENT", {
271
+ var u;
272
+ l("→ CONFIRM_PAYMENT", {
273
273
  orderId: h.orderId
274
274
  });
275
- const C = f();
275
+ const C = m();
276
276
  return C != null && C.contentWindow && C.contentWindow.postMessage(
277
277
  {
278
- type: p.CONFIG,
278
+ type: w.CONFIG,
279
279
  data: {
280
280
  publicKey: e.publicKey,
281
281
  orderId: h.orderId,
@@ -288,36 +288,36 @@ function rt(e) {
288
288
  }
289
289
  },
290
290
  "*"
291
- ), g.orderId = h.orderId, (l = window.PayConductor) != null && l.config && (window.PayConductor.config.orderId = h.orderId), Ae(C, E, h);
291
+ ), g.orderId = h.orderId, (u = window.PayConductor) != null && u.config && (window.PayConductor.config.orderId = h.orderId), Te(C, E, h);
292
292
  },
293
- validate: (h) => (c("→ VALIDATE", h), Te(f(), E, h)),
294
- reset: () => (c("→ RESET"), ve(f(), E)),
293
+ validate: (h) => (l("→ VALIDATE", h), Ie(m(), E, h)),
294
+ reset: () => (l("→ RESET"), De(m(), E)),
295
295
  getSelectedPaymentMethod: () => d
296
296
  };
297
297
  window.PayConductor = {
298
- frame: u,
298
+ frame: b,
299
299
  config: g,
300
- api: S,
300
+ api: p,
301
301
  selectedPaymentMethod: d
302
- }, c("registered"), window.dispatchEvent(
302
+ }, l("registered"), window.dispatchEvent(
303
303
  new CustomEvent("payconductor:registered", {
304
304
  detail: window.PayConductor
305
305
  })
306
306
  );
307
307
  const A = async () => {
308
- if (!m) {
309
- const h = f();
308
+ if (!c) {
309
+ const h = m();
310
310
  if (!h) {
311
- c("→ CONFIG skipped: iframe not found");
311
+ l("→ CONFIG skipped: iframe not found");
312
312
  return;
313
313
  }
314
- m = !0, c("→ CONFIG", {
314
+ c = !0, l("→ CONFIG", {
315
315
  theme: e.theme,
316
316
  locale: e.locale,
317
317
  paymentMethods: e.paymentMethods,
318
318
  defaultPaymentMethod: e.defaultPaymentMethod,
319
319
  showPaymentButtons: e.showPaymentButtons
320
- }), Ie(h, E, {
320
+ }), Me(h, E, {
321
321
  theme: e.theme,
322
322
  locale: e.locale,
323
323
  paymentMethods: e.paymentMethods,
@@ -326,77 +326,77 @@ function rt(e) {
326
326
  nuPayConfig: e.nuPayConfig
327
327
  });
328
328
  }
329
- }, O = (h) => {
329
+ }, U = (h) => {
330
330
  var C;
331
- (C = h.data) != null && C.type && c("←", h.data.type, h.data.data ?? ""), xe(
331
+ (C = h.data) != null && C.type && l("←", h.data.type, h.data.data ?? ""), Re(
332
332
  h,
333
333
  E,
334
- (l) => {
335
- var y;
336
- i(l), u.error = l, (y = window.PayConductor) != null && y.frame && (window.PayConductor.frame.error = l);
334
+ (u) => {
335
+ var f;
336
+ r(u), b.error = u, (f = window.PayConductor) != null && f.frame && (window.PayConductor.frame.error = u);
337
337
  },
338
338
  () => {
339
- var l;
340
- (l = e.onReady) == null || l.call(e), A();
339
+ var u;
340
+ (u = e.onReady) == null || u.call(e), A();
341
341
  },
342
- (l) => {
343
- var y;
344
- (y = e.onError) == null || y.call(e, l);
342
+ (u) => {
343
+ var f;
344
+ (f = e.onError) == null || f.call(e, u);
345
345
  },
346
- (l) => {
347
- var y;
348
- (y = e.onPaymentComplete) == null || y.call(e, l);
346
+ (u) => {
347
+ var f;
348
+ (f = e.onPaymentComplete) == null || f.call(e, u);
349
349
  },
350
- (l) => {
351
- var y;
352
- (y = e.onPaymentFailed) == null || y.call(e, l);
350
+ (u) => {
351
+ var f;
352
+ (f = e.onPaymentFailed) == null || f.call(e, u);
353
353
  },
354
- (l) => {
355
- var y;
356
- (y = e.onPaymentPending) == null || y.call(e, l);
354
+ (u) => {
355
+ var f;
356
+ (f = e.onPaymentPending) == null || f.call(e, u);
357
357
  },
358
- (l) => {
359
- var y;
360
- o(l), window.PayConductor && (window.PayConductor.selectedPaymentMethod = l), (y = e.onPaymentMethodSelected) == null || y.call(e, l);
358
+ (u) => {
359
+ var f;
360
+ o(u), window.PayConductor && (window.PayConductor.selectedPaymentMethod = u), (f = e.onPaymentMethodSelected) == null || f.call(e, u);
361
361
  },
362
362
  () => {
363
- var l;
364
- (l = e.onThreeDSChallenge) == null || l.call(e);
363
+ var u;
364
+ (u = e.onThreeDSChallenge) == null || u.call(e);
365
365
  },
366
366
  () => {
367
- var l;
368
- (l = e.onThreeDSComplete) == null || l.call(e);
367
+ var u;
368
+ (u = e.onThreeDSComplete) == null || u.call(e);
369
369
  },
370
370
  () => {
371
- var l;
372
- (l = e.onThreeDSFailed) == null || l.call(e);
371
+ var u;
372
+ (u = e.onThreeDSFailed) == null || u.call(e);
373
373
  }
374
374
  );
375
375
  };
376
- window.addEventListener("message", O);
377
- const J = () => {
378
- var C, l, y;
379
- const h = f();
376
+ window.addEventListener("message", U);
377
+ const ee = () => {
378
+ var C, u, f;
379
+ const h = m();
380
380
  if (!h) return !1;
381
381
  try {
382
- if ((((C = h.contentDocument) == null ? void 0 : C.readyState) ?? ((y = (l = h.contentWindow) == null ? void 0 : l.document) == null ? void 0 : y.readyState)) === "complete")
382
+ if ((((C = h.contentDocument) == null ? void 0 : C.readyState) ?? ((f = (u = h.contentWindow) == null ? void 0 : u.document) == null ? void 0 : f.readyState)) === "complete")
383
383
  return A(), !0;
384
384
  } catch {
385
385
  }
386
386
  return !1;
387
- }, K = () => {
388
- if (J()) return;
389
- const h = f();
387
+ }, $ = () => {
388
+ if (ee()) return;
389
+ const h = m();
390
390
  if (h) {
391
391
  h.addEventListener("load", () => A(), {
392
392
  once: !0
393
393
  });
394
394
  return;
395
395
  }
396
- setTimeout(K, 50);
396
+ setTimeout($, 50);
397
397
  };
398
- K();
399
- }, []), /* @__PURE__ */ N(
398
+ $();
399
+ }, []), /* @__PURE__ */ O(
400
400
  "div",
401
401
  {
402
402
  className: "payconductor",
@@ -408,37 +408,37 @@ function rt(e) {
408
408
  }
409
409
  );
410
410
  }
411
- function ot(e) {
412
- const a = ee(null), [t, n] = I(() => ""), [i, r] = I(() => !1), [s, d] = I(() => "");
413
- return z(() => {
414
- if (typeof document < "u" && !document.getElementById(H)) {
415
- const m = document.createElement("style");
416
- m.id = H, m.textContent = pe, document.head.appendChild(m);
411
+ function ct(e) {
412
+ const a = re(null), [t, n] = I(() => ""), [r, i] = I(() => !1), [s, d] = I(() => "");
413
+ return K(() => {
414
+ if (typeof document < "u" && !document.getElementById(Y)) {
415
+ const c = document.createElement("style");
416
+ c.id = Y, c.textContent = Pe, document.head.appendChild(c);
417
417
  }
418
- const o = (m) => {
419
- m != null && m.frame && (n(m.frame.iframeUrl || ""), r(!0), console.log("init", {
418
+ const o = (c) => {
419
+ c != null && c.frame && (n(c.frame.iframeUrl || ""), i(!0), console.log("init", {
420
420
  PayConductor: window.PayConductor
421
421
  }));
422
- }, c = typeof window < "u" ? window.PayConductor : null;
423
- if (c)
424
- o(c);
422
+ }, l = typeof window < "u" ? window.PayConductor : null;
423
+ if (l)
424
+ o(l);
425
425
  else {
426
- const m = (f) => {
427
- o(f.detail), window.removeEventListener("payconductor:registered", m);
426
+ const c = (m) => {
427
+ o(m.detail), window.removeEventListener("payconductor:registered", c);
428
428
  };
429
- window.addEventListener("payconductor:registered", m);
429
+ window.addEventListener("payconductor:registered", c);
430
430
  }
431
- let w = !1;
432
- const E = (m) => {
433
- var f, u, g, S;
434
- if (((f = m.data) == null ? void 0 : f.type) === p.RESIZE && ((g = (u = m.data) == null ? void 0 : u.data) != null && g.height) && d(m.data.data.height + "px"), ((S = m.data) == null ? void 0 : S.type) === p.READY && e.height && !w) {
435
- w = !0;
431
+ let y = !1;
432
+ const E = (c) => {
433
+ var m, b, g, p;
434
+ if (((m = c.data) == null ? void 0 : m.type) === w.RESIZE && ((g = (b = c.data) == null ? void 0 : b.data) != null && g.height) && d(c.data.data.height + "px"), ((p = c.data) == null ? void 0 : p.type) === w.READY && e.height && !y) {
435
+ y = !0;
436
436
  const A = document.querySelector(
437
437
  ".payconductor-element iframe"
438
438
  );
439
439
  A != null && A.contentWindow && A.contentWindow.postMessage(
440
440
  {
441
- type: p.CONFIG,
441
+ type: w.CONFIG,
442
442
  data: {
443
443
  height: e.height
444
444
  },
@@ -449,7 +449,7 @@ function ot(e) {
449
449
  }
450
450
  };
451
451
  return window.addEventListener("message", E), () => window.removeEventListener("message", E);
452
- }, []), /* @__PURE__ */ Q(
452
+ }, []), /* @__PURE__ */ ne(
453
453
  "div",
454
454
  {
455
455
  className: "payconductor-element",
@@ -457,16 +457,16 @@ function ot(e) {
457
457
  width: "100%"
458
458
  },
459
459
  children: [
460
- i ? null : /* @__PURE__ */ N(
460
+ r ? null : /* @__PURE__ */ O(
461
461
  "div",
462
462
  {
463
463
  className: "payconductor-skeleton",
464
464
  style: {
465
- height: e.height || j
465
+ height: e.height || G
466
466
  }
467
467
  }
468
468
  ),
469
- i && t ? /* @__PURE__ */ N(
469
+ r && t ? /* @__PURE__ */ O(
470
470
  "iframe",
471
471
  {
472
472
  allow: "payment",
@@ -475,7 +475,7 @@ function ot(e) {
475
475
  src: t,
476
476
  style: {
477
477
  width: "100%",
478
- height: e.height || s || j,
478
+ height: e.height || s || G,
479
479
  border: "none"
480
480
  }
481
481
  }
@@ -484,22 +484,22 @@ function ot(e) {
484
484
  }
485
485
  );
486
486
  }
487
- function st(e) {
487
+ function lt(e) {
488
488
  const [a, t] = I(() => !1);
489
- return z(() => {
489
+ return K(() => {
490
490
  const n = () => {
491
491
  t(!0);
492
- }, i = () => {
492
+ }, r = () => {
493
493
  t(!1);
494
494
  };
495
- return window.addEventListener("payconductor:3ds:show", n), window.addEventListener("payconductor:3ds:hide", i), typeof window < "u" && (window.PayConductor3DS = {
495
+ return window.addEventListener("payconductor:3ds:show", n), window.addEventListener("payconductor:3ds:hide", r), typeof window < "u" && (window.PayConductor3DS = {
496
496
  container: () => document.getElementById("payconductor-3ds-container"),
497
497
  show: n,
498
- hide: i
498
+ hide: r
499
499
  }, window.dispatchEvent(new CustomEvent("payconductor:3ds:registered"))), () => {
500
- window.removeEventListener("payconductor:3ds:show", n), window.removeEventListener("payconductor:3ds:hide", i), window.PayConductor3DS = null;
500
+ window.removeEventListener("payconductor:3ds:show", n), window.removeEventListener("payconductor:3ds:hide", r), window.PayConductor3DS = null;
501
501
  };
502
- }, []), /* @__PURE__ */ N(
502
+ }, []), /* @__PURE__ */ O(
503
503
  "div",
504
504
  {
505
505
  className: "payconductor-three-ds",
@@ -512,7 +512,7 @@ function st(e) {
512
512
  }
513
513
  );
514
514
  }
515
- function dt() {
515
+ function ut() {
516
516
  const e = typeof window < "u" ? window.PayConductor : null, a = e != null && e.config ? {
517
517
  publicKey: e.config.publicKey,
518
518
  orderId: e.config.orderId,
@@ -530,7 +530,7 @@ function dt() {
530
530
  ...t
531
531
  };
532
532
  }
533
- function U(e) {
533
+ function F(e) {
534
534
  var a;
535
535
  if ((a = e == null ? void 0 : e.frame) != null && a.iframe) {
536
536
  const t = e.frame.iframe;
@@ -548,20 +548,20 @@ function U(e) {
548
548
  }
549
549
  return document.querySelector(".payconductor-element iframe") ?? null;
550
550
  }
551
- function ct() {
551
+ function ht() {
552
552
  const e = () => typeof window < "u" ? window.PayConductor : null, a = (t, n) => {
553
- const i = e();
554
- if (!i) return;
555
- const r = U(i);
556
- r != null && r.contentWindow && r.contentWindow.postMessage({
553
+ const r = e();
554
+ if (!r) return;
555
+ const i = F(r);
556
+ i != null && i.contentWindow && i.contentWindow.postMessage({
557
557
  type: t,
558
558
  data: n
559
559
  }, "*");
560
560
  };
561
561
  return {
562
562
  init: async (t) => {
563
- const n = U(e()), i = B();
564
- return Me(n || void 0, i, t);
563
+ const n = F(e()), r = z();
564
+ return xe(n || void 0, r, t);
565
565
  },
566
566
  confirmPayment: async (t) => {
567
567
  if (!t.orderId)
@@ -583,9 +583,9 @@ function ct() {
583
583
  return ((t = e()) == null ? void 0 : t.selectedPaymentMethod) ?? null;
584
584
  },
585
585
  updateConfig: (t) => {
586
- var i;
587
- const n = (i = e()) == null ? void 0 : i.config;
588
- a(p.CONFIG, {
586
+ var r;
587
+ const n = (r = e()) == null ? void 0 : r.config;
588
+ a(w.CONFIG, {
589
589
  publicKey: n == null ? void 0 : n.publicKey,
590
590
  orderId: n == null ? void 0 : n.orderId,
591
591
  theme: t.theme ?? (n == null ? void 0 : n.theme),
@@ -594,9 +594,9 @@ function ct() {
594
594
  });
595
595
  },
596
596
  updateOrderId: (t) => {
597
- var i;
598
- const n = (i = e()) == null ? void 0 : i.config;
599
- a(p.CONFIG, {
597
+ var r;
598
+ const n = (r = e()) == null ? void 0 : r.config;
599
+ a(w.CONFIG, {
600
600
  publicKey: n == null ? void 0 : n.publicKey,
601
601
  orderId: t,
602
602
  theme: n == null ? void 0 : n.theme,
@@ -605,18 +605,18 @@ function ct() {
605
605
  });
606
606
  },
607
607
  update: (t) => {
608
- a(p.UPDATE, t);
608
+ a(w.UPDATE, t);
609
609
  },
610
610
  submit: async () => {
611
- const t = U(e()), n = B();
611
+ const t = F(e()), n = z();
612
612
  try {
613
- return await x(t || void 0, n, p.CONFIRM_PAYMENT, {}), {
613
+ return await x(t || void 0, n, w.CONFIRM_PAYMENT, {}), {
614
614
  paymentMethod: void 0
615
615
  };
616
- } catch (i) {
616
+ } catch (r) {
617
617
  return {
618
618
  error: {
619
- message: i instanceof Error ? i.message : "Payment failed",
619
+ message: r instanceof Error ? r.message : "Payment failed",
620
620
  code: "payment_error",
621
621
  type: "payment_error"
622
622
  }
@@ -625,11 +625,11 @@ function ct() {
625
625
  }
626
626
  };
627
627
  }
628
- var P = /* @__PURE__ */ ((e) => (e.Success = "Success", e.Failed = "Failed", e.Timeout = "Timeout", e))(P || {}), D = /* @__PURE__ */ ((e) => (e.Authenticated = "Y", e.Attempted = "A", e.ChallengeRequired = "C", e.NotAuthenticated = "N", e.Unavailable = "U", e.Rejected = "R", e.InformationOnly = "I", e))(D || {});
629
- class k {
628
+ var H = /* @__PURE__ */ ((e) => (e.Auto = "Auto", e.Manual = "Manual", e.Agnostic = "Agnostic", e))(H || {}), S = /* @__PURE__ */ ((e) => (e.Success = "Success", e.Failed = "Failed", e.Timeout = "Timeout", e))(S || {}), _ = /* @__PURE__ */ ((e) => (e.Authenticated = "Y", e.Attempted = "A", e.ChallengeRequired = "C", e.NotAuthenticated = "N", e.Unavailable = "U", e.Rejected = "R", e.InformationOnly = "I", e))(_ || {});
629
+ class N {
630
630
  constructor(a, t) {
631
- b(this, "overlay", null);
632
- b(this, "modalContent", null);
631
+ P(this, "overlay", null);
632
+ P(this, "modalContent", null);
633
633
  this.data = a, this.options = t;
634
634
  }
635
635
  /** Os SDKs de 3DS dos provedores (Pagar.me, PagSeguro) esperam o valor em centavos. */
@@ -637,9 +637,8 @@ class k {
637
637
  return this.data.amount === void 0 ? void 0 : Math.round(this.data.amount * 100);
638
638
  }
639
639
  fail(a, t = {}) {
640
- var i, r;
641
640
  const n = new Error(a);
642
- return (r = (i = this.options).onError) == null || r.call(i, n), {
641
+ return {
643
642
  ...t,
644
643
  status: "Failed",
645
644
  error: n
@@ -698,12 +697,12 @@ class k {
698
697
  //#endregion
699
698
  }
700
699
  const _e = 5 * 60 * 1e3;
701
- class De extends k {
700
+ class ke extends N {
702
701
  constructor() {
703
702
  super(...arguments);
704
- b(this, "iframe", null);
705
- b(this, "messageListener", null);
706
- b(this, "timeoutId", null);
703
+ P(this, "iframe", null);
704
+ P(this, "messageListener", null);
705
+ P(this, "timeoutId", null);
707
706
  }
708
707
  async authenticate() {
709
708
  const {
@@ -712,23 +711,22 @@ class De extends k {
712
711
  } = this.data;
713
712
  if (!t || !n)
714
713
  return this.fail("Missing threeDsUrl or creq");
715
- const i = this.resolveContainer();
716
- return new Promise((r) => {
717
- var c;
718
- this.iframe = document.createElement("iframe"), this.iframe.name = "payconductor-3ds-challenge", this.iframe.id = "payconductor-3ds-challenge", i.appendChild(this.iframe), this.messageListener = (w) => {
719
- var E, m, f;
720
- ((E = w.data) == null ? void 0 : E.status) === "COMPLETE" && (this.cleanup(), (f = (m = this.options).onComplete) == null || f.call(m), r({
721
- status: P.Success
714
+ const r = this.resolveContainer();
715
+ return new Promise((i) => {
716
+ var l;
717
+ this.iframe = document.createElement("iframe"), this.iframe.name = "payconductor-3ds-challenge", this.iframe.id = "payconductor-3ds-challenge", r.appendChild(this.iframe), this.messageListener = (y) => {
718
+ var E;
719
+ ((E = y.data) == null ? void 0 : E.status) === "COMPLETE" && (this.cleanup(), i({
720
+ status: S.Success
722
721
  }));
723
722
  }, window.addEventListener("message", this.messageListener), this.timeoutId = setTimeout(() => {
724
- var w, E;
725
- this.cleanup(), (E = (w = this.options).onTimeout) == null || E.call(w), r({
726
- status: P.Timeout
723
+ this.cleanup(), i({
724
+ status: S.Timeout
727
725
  });
728
726
  }, this.options.timeoutMs ?? _e);
729
- const s = (c = this.iframe.contentWindow) == null ? void 0 : c.document;
727
+ const s = (l = this.iframe.contentWindow) == null ? void 0 : l.document;
730
728
  if (!s) {
731
- this.cleanup(), r(this.fail("Cannot access iframe document"));
729
+ this.cleanup(), i(this.fail("Cannot access iframe document"));
732
730
  return;
733
731
  }
734
732
  const d = s.createElement("form");
@@ -741,27 +739,27 @@ class De extends k {
741
739
  this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.messageListener && (window.removeEventListener("message", this.messageListener), this.messageListener = null), this.iframe && (this.iframe.remove(), this.iframe = null), this.closeModal();
742
740
  }
743
741
  }
744
- const F = /* @__PURE__ */ new Map();
742
+ const B = /* @__PURE__ */ new Map();
745
743
  function L(e) {
746
- const a = F.get(e);
744
+ const a = B.get(e);
747
745
  if (a) return a;
748
- const t = new Promise((n, i) => {
746
+ const t = new Promise((n, r) => {
749
747
  if (document.querySelector(`script[src="${e}"]`)) {
750
748
  n();
751
749
  return;
752
750
  }
753
- const r = document.createElement("script");
754
- r.src = e, r.async = !0, r.onload = () => n(), r.onerror = () => {
755
- F.delete(e), i(new Error(`Failed to load script: ${e}`));
756
- }, (document.head || document.body).appendChild(r);
751
+ const i = document.createElement("script");
752
+ i.src = e, i.async = !0, i.onload = () => n(), i.onerror = () => {
753
+ B.delete(e), r(new Error(`Failed to load script: ${e}`));
754
+ }, (document.head || document.body).appendChild(i);
757
755
  });
758
- return F.set(e, t), t;
756
+ return B.set(e, t), t;
759
757
  }
760
- const Re = "https://static.payzen.lat/static/js/authenticate-client/V1.0/kr-authenticate.umd.js", ke = 10 * 60 * 1e3;
761
- class Ne extends k {
758
+ const Ne = "https://static.payzen.lat/static/js/authenticate-client/V1.0/kr-authenticate.umd.js", Oe = 10 * 60 * 1e3;
759
+ class Le extends N {
762
760
  constructor() {
763
761
  super(...arguments);
764
- b(this, "timeoutId", null);
762
+ P(this, "timeoutId", null);
765
763
  }
766
764
  async authenticate() {
767
765
  const {
@@ -771,21 +769,19 @@ class Ne extends k {
771
769
  if (!t || !n)
772
770
  return this.fail("Missing operationUrl or publicKey");
773
771
  try {
774
- await L(Re);
772
+ await L(Ne);
775
773
  } catch {
776
774
  return this.fail("Failed to load 3DS SDK");
777
775
  }
778
- const i = window.KrAuthenticate;
779
- return i ? new Promise((r) => {
776
+ const r = window.KrAuthenticate;
777
+ return r ? new Promise((i) => {
780
778
  this.timeoutId = setTimeout(() => {
781
- var d, o;
782
- this.cleanup(), (o = (d = this.options).onTimeout) == null || o.call(d), r({
783
- status: P.Timeout
779
+ this.cleanup(), i({
780
+ status: S.Timeout
784
781
  });
785
- }, this.options.timeoutMs ?? ke), new i(n).authenticate(t, () => {
786
- var d, o;
787
- this.cleanup(), (o = (d = this.options).onComplete) == null || o.call(d), r({
788
- status: P.Success
782
+ }, this.options.timeoutMs ?? Oe), new r(n).authenticate(t, () => {
783
+ this.cleanup(), i({
784
+ status: S.Success
789
785
  });
790
786
  });
791
787
  }) : this.fail("KrAuthenticate not available");
@@ -794,19 +790,19 @@ class Ne extends k {
794
790
  this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null);
795
791
  }
796
792
  }
797
- const Le = {
798
- [R.Production]: "https://3ds-nx-js.stone.com.br/live/v2/3ds2.min.js",
799
- [R.Sandbox]: "https://3ds-nx-js.stone.com.br/test/v2/3ds2.min.js"
800
- }, Oe = 5 * 60 * 1e3;
801
- function Ue() {
793
+ const Ue = {
794
+ [k.Production]: "https://3ds-nx-js.stone.com.br/live/v2/3ds2.min.js",
795
+ [k.Sandbox]: "https://3ds-nx-js.stone.com.br/test/v2/3ds2.min.js"
796
+ }, Fe = 5 * 60 * 1e3;
797
+ function Be() {
802
798
  const e = window.innerWidth;
803
799
  return e <= 480 ? "01" : e <= 768 ? "02" : e <= 1024 ? "03" : "04";
804
800
  }
805
- class Fe extends k {
801
+ class ze extends N {
806
802
  constructor() {
807
803
  super(...arguments);
808
- b(this, "timeoutId", null);
809
- b(this, "methodContainer", null);
804
+ P(this, "timeoutId", null);
805
+ P(this, "methodContainer", null);
810
806
  }
811
807
  async authenticate() {
812
808
  const {
@@ -815,47 +811,45 @@ class Fe extends k {
815
811
  } = this.data;
816
812
  if (!t) return this.fail("Missing authToken for PagarMe 3DS");
817
813
  if (!n) return this.fail("Missing card data for PagarMe 3DS");
818
- const i = this.data.environment ?? R.Production;
814
+ const r = this.data.environment ?? k.Production;
819
815
  try {
820
- await L(Le[i]);
816
+ await L(Ue[r]);
821
817
  } catch {
822
818
  return this.fail("Failed to load Stone 3DS SDK");
823
819
  }
824
- const r = window.TDS;
825
- if (!r) return this.fail("Stone TDS SDK not available");
820
+ const i = window.TDS;
821
+ if (!i) return this.fail("Stone TDS SDK not available");
826
822
  const s = this.resolveContainer();
827
823
  return this.methodContainer = document.createElement("div"), this.methodContainer.style.display = "none", document.body.appendChild(this.methodContainer), new Promise((d) => {
828
824
  this.timeoutId = setTimeout(() => {
829
- var o, c;
830
- this.cleanup(), (c = (o = this.options).onTimeout) == null || c.call(o), d({
831
- status: P.Timeout
825
+ this.cleanup(), d({
826
+ status: S.Timeout
832
827
  });
833
- }, this.options.timeoutMs ?? Oe), r.init({
828
+ }, this.options.timeoutMs ?? Fe), i.init({
834
829
  token: t,
835
830
  tds_method_container_element: this.methodContainer,
836
831
  challenge_container_element: s,
837
832
  use_default_challenge_iframe_style: !0,
838
- challenge_window_size: Ue()
833
+ challenge_window_size: Be()
839
834
  }, this.buildOrderData()).then((o) => {
840
- var m, f;
841
835
  if (this.cleanup(), !(o != null && o.length)) {
842
836
  d(this.fail("PagarMe 3DS returned no response"));
843
837
  return;
844
838
  }
845
- const c = o[0], w = Object.values(D).find((u) => u === c.trans_status), E = {
846
- transStatus: w,
847
- providerTransactionId: c.tds_server_trans_id,
848
- challengeCanceled: c.challenge_canceled
839
+ const l = o[0], y = Object.values(_).find((c) => c === l.trans_status), E = {
840
+ transStatus: y,
841
+ providerTransactionId: l.tds_server_trans_id,
842
+ challengeCanceled: l.challenge_canceled
849
843
  };
850
- if (c.challenge_canceled) {
844
+ if (l.challenge_canceled) {
851
845
  d(this.fail("3DS challenge canceled by user", E));
852
846
  return;
853
847
  }
854
- w === D.Authenticated || w === D.Attempted ? ((f = (m = this.options).onComplete) == null || f.call(m), d({
848
+ y === _.Authenticated || y === _.Attempted ? d({
855
849
  ...E,
856
- status: P.Success,
857
- dsTransactionId: c.tds_server_trans_id
858
- })) : d(this.fail(`3DS failed with status: ${c.trans_status}`, E));
850
+ status: S.Success,
851
+ dsTransactionId: l.tds_server_trans_id
852
+ }) : d(this.fail(`3DS failed with status: ${l.trans_status}`, E));
859
853
  }).catch((o) => {
860
854
  this.cleanup(), d(this.fail(o instanceof Error ? o.message : "PagarMe 3DS failed"));
861
855
  });
@@ -865,11 +859,11 @@ class Fe extends k {
865
859
  this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.methodContainer && (this.methodContainer.remove(), this.methodContainer = null), this.closeModal();
866
860
  }
867
861
  buildOrderData() {
868
- var r;
862
+ var i;
869
863
  const {
870
864
  card: t,
871
865
  customer: n,
872
- billingAddress: i
866
+ billingAddress: r
873
867
  } = this.data;
874
868
  return {
875
869
  payments: [{
@@ -878,15 +872,15 @@ class Fe extends k {
878
872
  card: {
879
873
  number: t == null ? void 0 : t.number,
880
874
  holder_name: t == null ? void 0 : t.holderName,
881
- exp_month: Number(t == null ? void 0 : t.expMonth),
882
- exp_year: Number(t == null ? void 0 : t.expYear),
883
- billing_address: i ? {
884
- country: i.country,
885
- state: i.state,
886
- city: i.city,
887
- zip_code: i.zipCode,
888
- line_1: `${i.number}, ${i.street}${i.district ? `, ${i.district}` : ""}`,
889
- line_2: i.complement ?? ""
875
+ exp_month: Number(t == null ? void 0 : t.expiration.month),
876
+ exp_year: Number(t == null ? void 0 : t.expiration.year),
877
+ billing_address: r ? {
878
+ country: r.country,
879
+ state: r.state,
880
+ city: r.city,
881
+ zip_code: r.zipCode,
882
+ line_1: `${r.number}, ${r.street}${r.district ? `, ${r.district}` : ""}`,
883
+ line_2: r.complement ?? ""
890
884
  } : void 0
891
885
  }
892
886
  },
@@ -899,7 +893,7 @@ class Fe extends k {
899
893
  ...n.document ? {
900
894
  document: n.document
901
895
  } : {},
902
- ...(r = n.phones) != null && r.length ? {
896
+ ...(i = n.phones) != null && i.length ? {
903
897
  phones: Object.fromEntries(n.phones.map((s) => [s.type === "HOME" ? "home_phone" : "mobile_phone", {
904
898
  country_code: s.countryCode,
905
899
  area_code: s.areaCode,
@@ -911,25 +905,25 @@ class Fe extends k {
911
905
  };
912
906
  }
913
907
  }
914
- const Be = "https://assets.pagseguro.com.br/checkout-sdk-js/rc/dist/browser/pagseguro.min.js";
915
- class ze extends k {
908
+ const Ke = "https://assets.pagseguro.com.br/checkout-sdk-js/rc/dist/browser/pagseguro.min.js";
909
+ class je extends N {
916
910
  async authenticate() {
917
- var E, m, f;
911
+ var E;
918
912
  const {
919
913
  authToken: a,
920
914
  card: t,
921
915
  customer: n,
922
- currency: i,
923
- billingAddress: r
916
+ currency: r,
917
+ billingAddress: i
924
918
  } = this.data, s = this.amountInCents;
925
919
  if (!a) return this.fail("Missing authToken (session) for PagSeguro 3DS");
926
920
  if (!t) return this.fail("Missing card data for PagSeguro 3DS");
927
921
  if (!n) return this.fail("Missing customer data for PagSeguro 3DS");
928
922
  if (!s) return this.fail("Missing amount for PagSeguro 3DS");
929
- if (!r) return this.fail("Missing billingAddress for PagSeguro 3DS");
930
- const d = this.data.environment === R.Sandbox ? "SANDBOX" : "PROD";
923
+ if (!i) return this.fail("Missing billingAddress for PagSeguro 3DS");
924
+ const d = this.data.environment === k.Sandbox ? "SANDBOX" : "PROD";
931
925
  try {
932
- await L(Be);
926
+ await L(Ke);
933
927
  } catch {
934
928
  return this.fail("Failed to load PagSeguro SDK");
935
929
  }
@@ -939,33 +933,33 @@ class ze extends k {
939
933
  session: a,
940
934
  env: d
941
935
  });
942
- const c = ((E = n.phones) == null ? void 0 : E.map((u) => ({
943
- country: u.countryCode,
944
- area: u.areaCode,
945
- number: u.number,
946
- type: u.type ?? "MOBILE"
936
+ const l = ((E = n.phones) == null ? void 0 : E.map((c) => ({
937
+ country: c.countryCode,
938
+ area: c.areaCode,
939
+ number: c.number,
940
+ type: c.type ?? "MOBILE"
947
941
  }))) ?? [{
948
942
  country: "55",
949
943
  area: "11",
950
944
  number: "999999999",
951
945
  type: "MOBILE"
952
946
  }];
953
- c.some((u) => u.type === "MOBILE") || (c[0].type = "MOBILE");
947
+ l.some((c) => c.type === "MOBILE") || (l[0].type = "MOBILE");
954
948
  try {
955
- const u = await o.authenticate3DS({
949
+ const c = await o.authenticate3DS({
956
950
  data: {
957
951
  customer: {
958
952
  name: n.name,
959
953
  email: n.email,
960
- phones: c
954
+ phones: l
961
955
  },
962
956
  paymentMethod: {
963
957
  type: this.data.installments === 0 ? "DEBIT_CARD" : "CREDIT_CARD",
964
958
  installments: this.data.installments ?? 1,
965
959
  card: {
966
960
  number: t.number,
967
- expMonth: t.expMonth,
968
- expYear: t.expYear,
961
+ expMonth: t.expiration.month,
962
+ expYear: t.expiration.year,
969
963
  holder: {
970
964
  name: t.holderName
971
965
  }
@@ -973,29 +967,29 @@ class ze extends k {
973
967
  },
974
968
  amount: {
975
969
  value: s,
976
- currency: i ?? "BRL"
970
+ currency: r ?? "BRL"
977
971
  },
978
972
  billingAddress: {
979
- street: r.street,
980
- number: r.number,
981
- complement: r.complement,
982
- regionCode: r.state,
983
- country: r.country.length === 2 ? this.toAlpha3(r.country) : r.country,
984
- city: r.city,
985
- postalCode: r.zipCode.replace(/\D/g, "")
973
+ street: i.street,
974
+ number: i.number,
975
+ complement: i.complement,
976
+ regionCode: i.state,
977
+ country: i.country.length === 2 ? this.toAlpha3(i.country) : i.country,
978
+ city: i.city,
979
+ postalCode: i.zipCode.replace(/\D/g, "")
986
980
  },
987
981
  dataOnly: !1
988
982
  }
989
983
  });
990
- return u.status === "AUTH_FLOW_COMPLETED" || u.status === "AUTH_NOT_SUPPORTED" ? ((f = (m = this.options).onComplete) == null || f.call(m), {
991
- status: P.Success,
992
- dsTransactionId: u.id
993
- }) : u.status === "CHANGE_PAYMENT_METHOD" ? this.fail("PagSeguro requires a different payment method") : {
994
- status: P.Success,
995
- dsTransactionId: u.id
984
+ return c.status === "AUTH_FLOW_COMPLETED" || c.status === "AUTH_NOT_SUPPORTED" ? {
985
+ status: S.Success,
986
+ dsTransactionId: c.id
987
+ } : c.status === "CHANGE_PAYMENT_METHOD" ? this.fail("PagSeguro requires a different payment method") : {
988
+ status: S.Success,
989
+ dsTransactionId: c.id
996
990
  };
997
- } catch (u) {
998
- return this.fail(u instanceof Error ? u.message : "PagSeguro 3DS failed");
991
+ } catch (c) {
992
+ return this.fail(c instanceof Error ? c.message : "PagSeguro 3DS failed");
999
993
  }
1000
994
  }
1001
995
  cleanup() {
@@ -1013,11 +1007,11 @@ class ze extends k {
1013
1007
  }[a.toUpperCase()] ?? a;
1014
1008
  }
1015
1009
  }
1016
- const Ke = 5 * 60 * 1e3, Y = "payconductor-3ds-sandbox-title";
1017
- class $ extends k {
1010
+ const He = 5 * 60 * 1e3, V = "payconductor-3ds-sandbox-title";
1011
+ class q extends N {
1018
1012
  constructor() {
1019
1013
  super(...arguments);
1020
- b(this, "timeoutId", null);
1014
+ P(this, "timeoutId", null);
1021
1015
  }
1022
1016
  async authenticate() {
1023
1017
  const {
@@ -1025,23 +1019,21 @@ class $ extends k {
1025
1019
  } = this.data;
1026
1020
  if (!t) return this.fail("Missing authToken for 3DS challenge");
1027
1021
  const n = this.resolveContainer();
1028
- return new Promise((i) => {
1022
+ return new Promise((r) => {
1029
1023
  this.timeoutId = setTimeout(() => {
1030
- var r, s;
1031
- this.cleanup(), (s = (r = this.options).onTimeout) == null || s.call(r), i({
1032
- status: P.Timeout
1024
+ this.cleanup(), r({
1025
+ status: S.Timeout
1033
1026
  });
1034
- }, this.options.timeoutMs ?? Ke), this.renderChallenge(n, {
1027
+ }, this.options.timeoutMs ?? He), this.renderChallenge(n, {
1035
1028
  onConfirm: () => {
1036
- var r, s;
1037
- this.cleanup(), (s = (r = this.options).onComplete) == null || s.call(r), i({
1038
- status: P.Success,
1039
- transStatus: D.Authenticated,
1029
+ this.cleanup(), r({
1030
+ status: S.Success,
1031
+ transStatus: _.Authenticated,
1040
1032
  providerTransactionId: t
1041
1033
  });
1042
1034
  },
1043
1035
  onCancel: () => {
1044
- this.cleanup(), i(this.fail("3DS challenge canceled by user", {
1036
+ this.cleanup(), r(this.fail("3DS challenge canceled by user", {
1045
1037
  challengeCanceled: !0
1046
1038
  }));
1047
1039
  }
@@ -1052,31 +1044,31 @@ class $ extends k {
1052
1044
  this.timeoutId && (clearTimeout(this.timeoutId), this.timeoutId = null), this.closeModal();
1053
1045
  }
1054
1046
  renderChallenge(t, n) {
1055
- const i = document.createElement("div");
1056
- i.setAttribute("role", "dialog"), i.setAttribute("aria-modal", "true"), i.setAttribute("aria-labelledby", Y), i.style.cssText = "min-height:inherit;box-sizing:border-box;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;padding:32px;font-family:system-ui,-apple-system,sans-serif;text-align:center;color:#111827";
1057
- const r = document.createElement("h2");
1058
- r.id = Y, r.textContent = "Autenticação 3DS (sandbox)", r.style.cssText = "margin:0;font-size:20px";
1047
+ const r = document.createElement("div");
1048
+ r.setAttribute("role", "dialog"), r.setAttribute("aria-modal", "true"), r.setAttribute("aria-labelledby", V), r.style.cssText = "min-height:inherit;box-sizing:border-box;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;padding:32px;font-family:system-ui,-apple-system,sans-serif;text-align:center;color:#111827";
1049
+ const i = document.createElement("h2");
1050
+ i.id = V, i.textContent = "Autenticação 3DS (sandbox)", i.style.cssText = "margin:0;font-size:20px";
1059
1051
  const s = document.createElement("p");
1060
1052
  s.textContent = "Simulação do desafio do banco emissor. Confirme para aprovar a autenticação ou cancele para simular a desistência do comprador.", s.style.cssText = "margin:0 0 8px;max-width:360px;font-size:14px;line-height:1.5;color:#4b5563";
1061
1053
  const d = this.createButton("Confirmar autenticação", "background:#111827;color:#fff;border-color:#111827", n.onConfirm), o = this.createButton("Cancelar", "background:#fff;color:#111827;border-color:#d1d5db", n.onCancel);
1062
- i.append(r, s, d, o), t.appendChild(i), d.focus();
1054
+ r.append(i, s, d, o), t.appendChild(r), d.focus();
1063
1055
  }
1064
- createButton(t, n, i) {
1065
- const r = document.createElement("button");
1066
- return r.type = "button", r.textContent = t, r.style.cssText = `width:100%;max-width:320px;padding:12px 16px;border:1px solid;border-radius:6px;font:inherit;font-size:14px;font-weight:600;cursor:pointer;${n}`, r.addEventListener("click", i), r;
1056
+ createButton(t, n, r) {
1057
+ const i = document.createElement("button");
1058
+ return i.type = "button", i.textContent = t, i.style.cssText = `width:100%;max-width:320px;padding:12px 16px;border:1px solid;border-radius:6px;font:inherit;font-size:14px;font-weight:600;cursor:pointer;${n}`, i.addEventListener("click", r), i;
1067
1059
  }
1068
1060
  }
1069
- const je = {
1061
+ const $e = {
1070
1062
  // Agnostic providers
1071
- [v.Lyra]: Ne,
1063
+ [T.Lyra]: Le,
1072
1064
  // Acquirer-specific providers
1073
- [v.MercadoPago]: De,
1074
- [v.PagarMe]: Fe,
1075
- [v.PagSeguro]: ze,
1076
- [v.Sandbox]: $,
1077
- [v.SandboxSplit]: $
1078
- };
1079
- class He extends Error {
1065
+ [T.MercadoPago]: ke,
1066
+ [T.PagarMe]: ze,
1067
+ [T.PagSeguro]: je,
1068
+ [T.Sandbox]: q,
1069
+ [T.SandboxSplit]: q
1070
+ }, Ge = M.replace(/\/sdk\/?$/, "");
1071
+ class Q extends Error {
1080
1072
  constructor(a, t) {
1081
1073
  super(a), this.title = t, this.name = "PayConductorThreeDSApiError";
1082
1074
  }
@@ -1085,34 +1077,67 @@ class Ye {
1085
1077
  constructor(a) {
1086
1078
  this.publicKey = a;
1087
1079
  }
1088
- async completeManualChallenge(a, t) {
1089
- const n = await fetch(`${_}/three-ds/complete/${a}`, {
1080
+ async completeChallenge(a, t) {
1081
+ const n = await fetch(`${M}/three-ds/complete/${a}`, {
1090
1082
  method: "POST",
1091
1083
  headers: this.headers,
1092
- body: JSON.stringify({
1093
- providerTransactionId: t
1094
- })
1084
+ body: JSON.stringify(t)
1085
+ });
1086
+ n.ok || await this.parseResponseError("Falha ao concluir a autenticação 3DS", n);
1087
+ }
1088
+ async getOrderStatus(a) {
1089
+ const t = await fetch(`${Ge}/orders/${a}/status`, {
1090
+ method: "GET",
1091
+ headers: this.headers
1095
1092
  });
1096
- n.ok || await this.parseResponseError("Failed to complete native 3DS challenge", n);
1093
+ return t.ok || await this.parseResponseError("Falha ao consultar o status do pedido", t), qe(await t.json());
1094
+ }
1095
+ /**
1096
+ * Aguarda o pedido sair de `ThreeDsAwaitingChallenge`.
1097
+ * No modo `Auto` não existe `statusDetail`; a espera é enquanto o pedido seguir `Pending`.
1098
+ */
1099
+ async pollOrderStatus(a, {
1100
+ maxAttempts: t = 30,
1101
+ intervalMs: n = 2e3,
1102
+ mode: r
1103
+ } = {}) {
1104
+ let i = null;
1105
+ for (let s = 0; s < t; s++) {
1106
+ if (i = await this.getOrderStatus(a), !(i.status === R.Pending && (i.statusDetail === j.ThreeDsAwaitingChallenge || r === H.Auto))) return {
1107
+ order: i,
1108
+ timedOut: !1
1109
+ };
1110
+ await new Promise((o) => setTimeout(o, n));
1111
+ }
1112
+ return {
1113
+ order: i,
1114
+ timedOut: !0
1115
+ };
1097
1116
  }
1098
1117
  async getThreeDSecureData(a) {
1099
- const t = await fetch(`${_}/three-ds/challenge/${a}`, {
1118
+ const t = await fetch(`${M}/three-ds/challenge/${a}`, {
1100
1119
  method: "GET",
1101
1120
  headers: this.headers
1102
1121
  });
1103
- t.ok || await this.parseResponseError("Failed to fetch 3DS data", t);
1104
- const n = await t.json();
1105
- return Object.fromEntries(Object.entries(n).filter(([, i]) => i != null));
1122
+ t.ok || await this.parseResponseError("Falha ao buscar dados 3DS", t);
1123
+ const n = await t.json(), r = Object.fromEntries(Object.entries(n.threeDSecure ?? {}).filter(([, i]) => i != null));
1124
+ return {
1125
+ ...r,
1126
+ ...n.mode ? {
1127
+ mode: n.mode
1128
+ } : {},
1129
+ statusDetail: r.statusDetail ?? n.statusDetail ?? void 0
1130
+ };
1106
1131
  }
1107
1132
  async parseResponseError(a, t) {
1108
- var i, r, s, d;
1133
+ var r, i, s, d;
1109
1134
  let n = "";
1110
1135
  try {
1111
1136
  const o = await t.json();
1112
- o != null && o.message ? n = o.message : (i = o == null ? void 0 : o.error) != null && i.message ? n = o.error : (s = (r = o == null ? void 0 : o.error) == null ? void 0 : r.value) != null && s.message ? n = o.error.value.message : (d = o == null ? void 0 : o.value) != null && d.message ? n = o.value.message : n = JSON.stringify(o);
1137
+ o != null && o.message ? n = o.message : (r = o == null ? void 0 : o.error) != null && r.message ? n = o.error : (s = (i = o == null ? void 0 : o.error) == null ? void 0 : i.value) != null && s.message ? n = o.error.value.message : (d = o == null ? void 0 : o.value) != null && d.message ? n = o.value.message : n = JSON.stringify(o);
1113
1138
  } catch {
1114
1139
  }
1115
- throw new He(n, a);
1140
+ throw new Q(n, a);
1116
1141
  }
1117
1142
  get headers() {
1118
1143
  return {
@@ -1121,12 +1146,36 @@ class Ye {
1121
1146
  };
1122
1147
  }
1123
1148
  }
1124
- const $e = [v.PagSeguro];
1125
- class Ge {
1149
+ function Ve(e) {
1150
+ switch (e) {
1151
+ case "Completed":
1152
+ return R.Succeeded;
1153
+ case "Pending":
1154
+ case "Generating":
1155
+ return R.Pending;
1156
+ default:
1157
+ return R.Failed;
1158
+ }
1159
+ }
1160
+ function qe(e) {
1161
+ const a = e ?? {};
1162
+ return {
1163
+ ...a,
1164
+ orderId: a.id ?? "",
1165
+ status: Ve(a.status),
1166
+ statusDetail: a.statusDetail ?? void 0,
1167
+ amount: a.amount ?? 0,
1168
+ currency: a.currency ?? "BRL",
1169
+ errorCode: a.errorCode ?? void 0,
1170
+ errorMessage: a.errorMessage ?? void 0,
1171
+ message: a.errorMessage ?? void 0
1172
+ };
1173
+ }
1174
+ class We {
1126
1175
  constructor(a) {
1127
- b(this, "data");
1128
- b(this, "provider", null);
1129
- b(this, "api");
1176
+ P(this, "data");
1177
+ P(this, "provider", null);
1178
+ P(this, "api");
1130
1179
  this.data = a, this.api = new Ye(this.data.publicKey);
1131
1180
  }
1132
1181
  get needsChallenge() {
@@ -1135,58 +1184,139 @@ class Ge {
1135
1184
  get acquirer() {
1136
1185
  return this.data.acquirer;
1137
1186
  }
1187
+ /** Indica se o pedido precisa de autenticação 3DS. */
1188
+ static requiresChallenge(a) {
1189
+ var t, n, r;
1190
+ return a.statusDetail === "ThreeDsAwaitingChallenge" || ((t = a.threeDSecure) == null ? void 0 : t.status) === "NeedChallenge" || ((r = (n = a.creditCard) == null ? void 0 : n.threeDSecure) == null ? void 0 : r.status) === "NeedChallenge";
1191
+ }
1192
+ /**
1193
+ * Executa o fluxo completo de 3DS: carrega os dados, resolve o provedor,
1194
+ * conduz o desafio, envia o `complete` (só no modo `Manual`) e faz o polling
1195
+ * do pedido. O integrador não precisa ramificar por modo.
1196
+ */
1138
1197
  async authenticate(a) {
1139
- var d;
1140
- const t = await this.api.getThreeDSecureData(this.data.orderId);
1141
- if (this.data = {
1142
- ...this.data,
1143
- ...t
1144
- }, !this.needsChallenge)
1198
+ var c;
1199
+ try {
1200
+ const m = await this.api.getThreeDSecureData(this.data.orderId);
1201
+ this.data = {
1202
+ ...this.data,
1203
+ ...m
1204
+ };
1205
+ } catch (m) {
1206
+ if (m instanceof Q)
1207
+ return {
1208
+ status: S.Failed,
1209
+ error: m
1210
+ };
1211
+ throw m;
1212
+ }
1213
+ if (!this.needsChallenge)
1145
1214
  return {
1146
- status: P.Success
1215
+ status: S.Success
1147
1216
  };
1148
1217
  const {
1149
- acquirer: n
1218
+ acquirer: t,
1219
+ mode: n
1150
1220
  } = this.data;
1151
- if (!n)
1152
- return {
1153
- status: P.Failed,
1154
- error: new Error("Missing 3DS acquirer")
1155
- };
1156
- const i = je[n];
1157
- if (!i)
1158
- return {
1159
- status: P.Failed,
1160
- error: new Error(`Unsupported 3DS provider: ${n}`)
1161
- };
1162
- (d = a == null ? void 0 : a.onChallenge) == null || d.call(a);
1163
- const r = {
1164
- ...a,
1165
- threeDSecure: this.data
1166
- };
1167
- this.provider = new i(this.data, r);
1168
- const s = await this.provider.authenticate();
1169
- return s.status === P.Success && s.dsTransactionId && $e.includes(n) && await this.api.completeManualChallenge(this.data.orderId, s.dsTransactionId), s;
1221
+ if (!t)
1222
+ return this.finish({
1223
+ status: S.Failed,
1224
+ error: new Error("Adquirente 3DS não informada na cobrança"),
1225
+ failureReason: "Adquirente 3DS não informada na cobrança"
1226
+ }, a);
1227
+ const r = $e[t];
1228
+ if (!r) {
1229
+ const m = `Provedor 3DS não suportado: ${t}`;
1230
+ return this.finish({
1231
+ status: S.Failed,
1232
+ error: new Error(m),
1233
+ failureReason: m
1234
+ }, a);
1235
+ }
1236
+ (c = a == null ? void 0 : a.onChallenge) == null || c.call(a);
1237
+ const i = new r(this.data, {
1238
+ threeDSecure: this.data,
1239
+ timeoutMs: a == null ? void 0 : a.timeoutMs
1240
+ });
1241
+ this.provider = i;
1242
+ let s;
1243
+ try {
1244
+ s = await i.authenticate();
1245
+ } finally {
1246
+ i.cleanup(), this.provider = null;
1247
+ }
1248
+ const d = {
1249
+ ...s
1250
+ }, o = this.deriveFailureReason(s);
1251
+ d.failureReason = o;
1252
+ const l = n ? n === H.Manual : this.data.statusDetail === j.ThreeDsAwaitingChallenge;
1253
+ let y;
1254
+ if (l && (a == null ? void 0 : a.complete) !== !1)
1255
+ try {
1256
+ await this.api.completeChallenge(this.data.orderId, this.buildCompletionPayload(s, o));
1257
+ } catch (m) {
1258
+ y = m;
1259
+ }
1260
+ if ((a == null ? void 0 : a.poll) !== !1 && s.status === S.Success) {
1261
+ const {
1262
+ order: m,
1263
+ timedOut: b
1264
+ } = await this.api.pollOrderStatus(this.data.orderId, {
1265
+ ...a == null ? void 0 : a.polling,
1266
+ mode: n
1267
+ });
1268
+ d.order = m ?? void 0, d.timedOut = b;
1269
+ } else y && !d.error && (d.error = this.toError(y));
1270
+ return this.finish(d, a);
1170
1271
  }
1171
1272
  destroy() {
1172
1273
  this.provider && (this.provider.cleanup(), this.provider = null);
1173
1274
  }
1275
+ /** Mensagem amigável da falha do desafio (pt-BR). */
1276
+ deriveFailureReason(a) {
1277
+ var t;
1278
+ if (a.status !== S.Success)
1279
+ return a.status === S.Timeout ? "Tempo da autenticação 3DS esgotado" : ((t = a.error) == null ? void 0 : t.message) || "Falha na autenticação 3DS";
1280
+ }
1281
+ /**
1282
+ * Payload do `complete`. `failureReason` só vai quando é falha técnica
1283
+ * (sem `transStatus` do emissor nem cancelamento) — string vazia quebra o backend.
1284
+ */
1285
+ buildCompletionPayload(a, t) {
1286
+ const n = a.challengeCanceled === !0, r = a.transStatus;
1287
+ return {
1288
+ providerTransactionId: a.providerTransactionId ?? a.dsTransactionId,
1289
+ transStatus: r,
1290
+ challengeCanceled: n,
1291
+ failureReason: !!t && !r && !n ? t : void 0
1292
+ };
1293
+ }
1294
+ finish(a, t) {
1295
+ var n, r, i;
1296
+ return (n = t == null ? void 0 : t.onComplete) == null || n.call(t, a), a.failureReason && ((r = t == null ? void 0 : t.onError) == null || r.call(t, new Error(a.failureReason))), (a.status === S.Timeout || a.timedOut) && ((i = t == null ? void 0 : t.onTimeout) == null || i.call(t)), a;
1297
+ }
1298
+ toError(a) {
1299
+ return a instanceof Error ? a : new Error("Falha ao concluir a autenticação 3DS");
1300
+ }
1174
1301
  }
1175
- function lt(e) {
1302
+ function mt(e) {
1176
1303
  let a = null;
1177
1304
  return {
1178
- handleChallenge: async (i) => {
1179
- const r = new Ge(i);
1180
- a = r;
1305
+ authenticate: async (r) => {
1306
+ const i = new We(r);
1307
+ a = i;
1181
1308
  try {
1182
- return await r.authenticate({
1309
+ return await i.authenticate({
1183
1310
  onChallenge: e == null ? void 0 : e.onChallenge,
1184
1311
  onComplete: e == null ? void 0 : e.onComplete,
1185
1312
  onError: e == null ? void 0 : e.onError,
1186
- onTimeout: e == null ? void 0 : e.onTimeout
1313
+ onTimeout: e == null ? void 0 : e.onTimeout,
1314
+ complete: e == null ? void 0 : e.complete,
1315
+ poll: e == null ? void 0 : e.poll,
1316
+ polling: e == null ? void 0 : e.polling
1187
1317
  });
1188
1318
  } finally {
1189
- r.destroy(), a = null;
1319
+ i.destroy(), a = null;
1190
1320
  }
1191
1321
  },
1192
1322
  destroy: () => {
@@ -1194,24 +1324,24 @@ function lt(e) {
1194
1324
  }
1195
1325
  };
1196
1326
  }
1197
- class Ve extends Error {
1327
+ class Je extends Error {
1198
1328
  constructor(a, t) {
1199
1329
  super(a), this.title = t, this.name = "PayConductorTokenizerApiError";
1200
1330
  }
1201
1331
  }
1202
- class qe {
1332
+ class Xe {
1203
1333
  constructor(a) {
1204
1334
  this.publicKey = a;
1205
1335
  }
1206
1336
  async getSettings() {
1207
- const a = await fetch(`${_}/card-tokenization/settings`, {
1337
+ const a = await fetch(`${M}/card-tokenization/settings`, {
1208
1338
  method: "GET",
1209
1339
  headers: this.headers
1210
1340
  });
1211
1341
  return a.ok || await this.parseResponseError("Failed to fetch settings", a), await a.json();
1212
1342
  }
1213
1343
  async createToken(a) {
1214
- const t = await fetch(`${_}/card-tokenization/tokenize`, {
1344
+ const t = await fetch(`${M}/card-tokenization/tokenize`, {
1215
1345
  method: "POST",
1216
1346
  headers: this.headers,
1217
1347
  body: JSON.stringify(a)
@@ -1219,22 +1349,22 @@ class qe {
1219
1349
  return t.ok || await this.parseResponseError("Failed to generate token", t), await t.json();
1220
1350
  }
1221
1351
  async saveTokens(a, t, n) {
1222
- const i = await fetch(`${_}/card-tokenization/save-tokens/${t}/${n}`, {
1352
+ const r = await fetch(`${M}/card-tokenization/save-tokens/${t}/${n}`, {
1223
1353
  method: "POST",
1224
1354
  headers: this.headers,
1225
1355
  body: JSON.stringify(a)
1226
1356
  });
1227
- i.ok || await this.parseResponseError("Failed to save tokens", i);
1357
+ r.ok || await this.parseResponseError("Failed to save tokens", r);
1228
1358
  }
1229
1359
  async parseResponseError(a, t) {
1230
- var i, r, s, d;
1360
+ var r, i, s, d;
1231
1361
  let n = "";
1232
1362
  try {
1233
1363
  const o = await t.json();
1234
- o != null && o.message ? n = o.message : (i = o == null ? void 0 : o.error) != null && i.message ? n = o.error : (s = (r = o == null ? void 0 : o.error) == null ? void 0 : r.value) != null && s.message ? n = o.error.value.message : (d = o == null ? void 0 : o.value) != null && d.message ? n = o.value.message : n = JSON.stringify(o);
1364
+ o != null && o.message ? n = o.message : (r = o == null ? void 0 : o.error) != null && r.message ? n = o.error : (s = (i = o == null ? void 0 : o.error) == null ? void 0 : i.value) != null && s.message ? n = o.error.value.message : (d = o == null ? void 0 : o.value) != null && d.message ? n = o.value.message : n = JSON.stringify(o);
1235
1365
  } catch {
1236
1366
  }
1237
- throw new Ve(n, a);
1367
+ throw new Je(n, a);
1238
1368
  }
1239
1369
  get headers() {
1240
1370
  return {
@@ -1243,15 +1373,15 @@ class qe {
1243
1373
  };
1244
1374
  }
1245
1375
  }
1246
- class We {
1376
+ class Ze {
1247
1377
  constructor(a) {
1248
1378
  this.input = a;
1249
1379
  }
1250
1380
  }
1251
- class Je extends We {
1381
+ class Qe extends Ze {
1252
1382
  constructor() {
1253
1383
  super(...arguments);
1254
- b(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
1384
+ P(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
1255
1385
  }
1256
1386
  async tokenize() {
1257
1387
  const {
@@ -1263,24 +1393,24 @@ class Je extends We {
1263
1393
  throw new Error("Customer document number is required for tokenization");
1264
1394
  const n = window.MercadoPago;
1265
1395
  if (!n) throw new Error("MercadoPago SDK not available");
1266
- const i = new n(t.trim()), {
1267
- expiration: r,
1396
+ const r = new n(t.trim()), {
1397
+ expiration: i,
1268
1398
  cvv: s,
1269
1399
  number: d,
1270
1400
  holderName: o
1271
- } = this.input.card, c = await i.createCardToken({
1272
- cardExpirationMonth: String(r.month).padStart(2, "0"),
1273
- cardExpirationYear: String(r.year),
1401
+ } = this.input.card, l = await r.createCardToken({
1402
+ cardExpirationMonth: String(i.month).padStart(2, "0"),
1403
+ cardExpirationYear: String(i.year),
1274
1404
  cardholderName: o,
1275
1405
  cardNumber: d,
1276
1406
  securityCode: s,
1277
- identificationType: this.input.customer.documentType === q.Cpf ? "CPF" : "CNPJ",
1407
+ identificationType: this.input.customer.documentType === X.Cpf ? "CPF" : "CNPJ",
1278
1408
  identificationNumber: this.input.customer.documentNumber
1279
- }).catch((w) => {
1280
- throw new Error(this.describeMercadoPagoError(w));
1409
+ }).catch((y) => {
1410
+ throw new Error(this.describeMercadoPagoError(y));
1281
1411
  });
1282
- if ("id" in c && c.id) return c.id;
1283
- throw new Error(this.describeMercadoPagoError(c));
1412
+ if ("id" in l && l.id) return l.id;
1413
+ throw new Error(this.describeMercadoPagoError(l));
1284
1414
  }
1285
1415
  describeMercadoPagoError(t) {
1286
1416
  if (typeof t == "string") return t;
@@ -1294,13 +1424,13 @@ class Je extends We {
1294
1424
  return "Failed to tokenize card";
1295
1425
  }
1296
1426
  }
1297
- const Xe = {
1298
- [v.MercadoPago]: Je
1427
+ const et = {
1428
+ [T.MercadoPago]: Qe
1299
1429
  };
1300
- class Ze {
1430
+ class tt {
1301
1431
  constructor(a) {
1302
- b(this, "api");
1303
- this.publicKey = a, this.api = new qe(this.publicKey);
1432
+ P(this, "api");
1433
+ this.publicKey = a, this.api = new Xe(this.publicKey);
1304
1434
  }
1305
1435
  async tokenizeCard(a) {
1306
1436
  this.validateCard(a);
@@ -1312,16 +1442,16 @@ class Ze {
1312
1442
  customer: a.customer,
1313
1443
  saveCard: !1
1314
1444
  }), {
1315
- settings: i
1316
- } = await this.api.getSettings(), s = (await Promise.all(i.map(async (d) => {
1317
- const o = Xe[d.key];
1445
+ settings: r
1446
+ } = await this.api.getSettings(), s = (await Promise.all(r.map(async (d) => {
1447
+ const o = et[d.key];
1318
1448
  if (!o) return null;
1319
- const c = new o({
1449
+ const l = new o({
1320
1450
  ...a,
1321
1451
  setting: d.settings
1322
1452
  });
1323
- return await L(c.scriptUrl), {
1324
- token: await c.tokenize(),
1453
+ return await L(l.scriptUrl), {
1454
+ token: await l.tokenize(),
1325
1455
  integrationId: d.integrationId,
1326
1456
  providerKey: d.key
1327
1457
  };
@@ -1332,70 +1462,71 @@ class Ze {
1332
1462
  const {
1333
1463
  number: t,
1334
1464
  cvv: n,
1335
- expiration: i,
1336
- holderName: r
1465
+ expiration: r,
1466
+ holderName: i
1337
1467
  } = a.card;
1338
- if (!t || !n || !(i != null && i.month) || !(i != null && i.year) || !r)
1468
+ if (!t || !n || !(r != null && r.month) || !(r != null && r.year) || !i)
1339
1469
  throw new Error("Invalid card data");
1340
1470
  }
1341
1471
  }
1342
- function ut(e) {
1343
- const a = new Ze(e.publicKey);
1472
+ function ft(e) {
1473
+ const a = new tt(e.publicKey);
1344
1474
  return {
1345
1475
  tokenizeCard: async (n) => {
1346
- var i, r;
1476
+ var r, i;
1347
1477
  try {
1348
1478
  const s = await a.tokenizeCard(n);
1349
- return (i = e.onSuccess) == null || i.call(e, s), s;
1479
+ return (r = e.onSuccess) == null || r.call(e, s), s;
1350
1480
  } catch (s) {
1351
1481
  const d = s instanceof Error ? s : new Error("Tokenization failed");
1352
- return (r = e.onError) == null || r.call(e, d), null;
1482
+ return (i = e.onError) == null || i.call(e, d), null;
1353
1483
  }
1354
1484
  }
1355
1485
  };
1356
1486
  }
1357
1487
  export {
1358
- ge as ALLOWED_ORIGINS,
1359
- ue as CardBrand,
1360
- de as ChargeStatusDetail,
1361
- he as CurrencyType,
1362
- me as DeviceType,
1363
- q as DocumentType,
1364
- it as ERROR_CODES,
1365
- ye as ErrorCode,
1366
- Ee as IFRAME_BASE_URL,
1367
- j as IFRAME_DEFAULT_HEIGHT_VALUE,
1368
- T as IncomingMessage,
1369
- fe as InputStyleKey,
1370
- v as IntegrationProvider,
1371
- R as OrganizationEnvironment,
1372
- M as OutgoingMessage,
1373
- p as POST_MESSAGES,
1374
- rt as PayConductor,
1375
- Ge as PayConductor3DSSDK,
1376
- ot as PayConductorCheckoutElement,
1377
- st as PayConductorThreeDSElement,
1378
- Ze as PayConductorTokenizerSDK,
1379
- re as PaymentMethod,
1380
- oe as PaymentMethodLayout,
1381
- se as PaymentStatus,
1382
- we as REQUEST_TIMEOUT,
1383
- _ as SDK_API_BASE_URL,
1384
- pe as SKELETON_CSS,
1385
- H as SKELETON_STYLE_ID,
1386
- le as ThreeDSResultStatus,
1387
- D as ThreeDSTransStatus,
1388
- P as ThreeDSecureResultStatus,
1389
- ce as ThreeDsAuthenticationStatus,
1390
- be as buildIframeUrl,
1391
- rt as default,
1392
- at as defaultTheme,
1393
- Pe as generateRequestId,
1394
- Ce as isValidOrigin,
1488
+ Se as ALLOWED_ORIGINS,
1489
+ me as CardBrand,
1490
+ j as ChargeStatusDetail,
1491
+ fe as CurrencyType,
1492
+ ye as DeviceType,
1493
+ X as DocumentType,
1494
+ st as ERROR_CODES,
1495
+ Ee as ErrorCode,
1496
+ we as IFRAME_BASE_URL,
1497
+ G as IFRAME_DEFAULT_HEIGHT_VALUE,
1498
+ v as IncomingMessage,
1499
+ ge as InputStyleKey,
1500
+ T as IntegrationProvider,
1501
+ k as OrganizationEnvironment,
1502
+ D as OutgoingMessage,
1503
+ w as POST_MESSAGES,
1504
+ dt as PayConductor,
1505
+ We as PayConductor3DSSDK,
1506
+ ct as PayConductorCheckoutElement,
1507
+ lt as PayConductorThreeDSElement,
1508
+ tt as PayConductorTokenizerSDK,
1509
+ ce as PaymentMethod,
1510
+ le as PaymentMethodLayout,
1511
+ R as PaymentStatus,
1512
+ be as REQUEST_TIMEOUT,
1513
+ M as SDK_API_BASE_URL,
1514
+ Pe as SKELETON_CSS,
1515
+ Y as SKELETON_STYLE_ID,
1516
+ H as ThreeDSMode,
1517
+ he as ThreeDSResultStatus,
1518
+ _ as ThreeDSTransStatus,
1519
+ S as ThreeDSecureResultStatus,
1520
+ ue as ThreeDsAuthenticationStatus,
1521
+ Ce as buildIframeUrl,
1522
+ dt as default,
1523
+ ot as defaultTheme,
1524
+ pe as generateRequestId,
1525
+ Ae as isValidOrigin,
1395
1526
  L as loadScript,
1396
- dt as usePayConductor,
1397
- ct as usePayconductorElement,
1398
- lt as useThreeDS,
1399
- ut as useTokenizer
1527
+ ut as usePayConductor,
1528
+ ht as usePayconductorElement,
1529
+ mt as useThreeDS,
1530
+ ft as useTokenizer
1400
1531
  };
1401
1532
  //# sourceMappingURL=index.es.js.map