@payconductor/react 1.0.3 → 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.
Files changed (34) hide show
  1. package/dist/esm/three-ds.d.ts +1 -0
  2. package/dist/esm/tokenize.d.ts +1 -0
  3. package/dist/index.cjs.js +37 -2
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.d.ts +4 -0
  6. package/dist/index.es.js +1008 -306
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/payconductor/constants.d.ts +1 -1
  9. package/dist/payconductor/hooks/index.d.ts +4 -0
  10. package/dist/payconductor/hooks/use-three-ds.d.ts +13 -0
  11. package/dist/payconductor/hooks/use-tokenize.d.ts +11 -0
  12. package/dist/payconductor/iframe/constants.d.ts +1 -1
  13. package/dist/payconductor/iframe/types.d.ts +133 -2
  14. package/dist/payconductor/internal.d.ts +1 -1
  15. package/dist/payconductor/loader.d.ts +1 -0
  16. package/dist/payconductor/payconductor-three-ds.d.ts +5 -0
  17. package/dist/payconductor/payconductor.d.ts +3 -0
  18. package/dist/payconductor/three-ds/api.d.ts +12 -0
  19. package/dist/payconductor/three-ds/browser.d.ts +13 -0
  20. package/dist/payconductor/three-ds/handler.d.ts +12 -0
  21. package/dist/payconductor/three-ds/index.d.ts +1 -0
  22. package/dist/payconductor/three-ds/providers/index.d.ts +6 -0
  23. package/dist/payconductor/three-ds/providers/mercado-pago.d.ts +9 -0
  24. package/dist/payconductor/three-ds/providers/pagarme.d.ts +9 -0
  25. package/dist/payconductor/three-ds/providers/pagseguro.d.ts +7 -0
  26. package/dist/payconductor/three-ds/providers/payconductor.d.ts +7 -0
  27. package/dist/payconductor/three-ds/types.d.ts +78 -0
  28. package/dist/payconductor/tokenize/api.d.ts +26 -0
  29. package/dist/payconductor/tokenize/index.d.ts +1 -0
  30. package/dist/payconductor/tokenize/providers/index.d.ts +6 -0
  31. package/dist/payconductor/tokenize/providers/mercado-pago.d.ts +6 -0
  32. package/dist/payconductor/tokenize/tokenize.d.ts +9 -0
  33. package/dist/payconductor/tokenize/types.d.ts +50 -0
  34. package/package.json +1 -1
package/dist/index.es.js CHANGED
@@ -1,8 +1,11 @@
1
- import { jsx as _, jsxs as H } from "react/jsx-runtime";
2
- import { useState as N, useEffect as O, useRef as V } from "react";
3
- const x = "https://iframe.payconductor.ai/v1", F = "http://localhost:5175/v1", B = 3e4, Y = "600px";
4
- var G = /* @__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))(G || {}), K = /* @__PURE__ */ ((e) => (e.Grid = "grid", e.Vertical = "vertical", e.Horizontal = "horizontal", e))(K || {}), W = /* @__PURE__ */ ((e) => (e.Succeeded = "succeeded", e.Pending = "pending", e.Failed = "failed", e))(W || {}), q = /* @__PURE__ */ ((e) => (e.Android = "android", e.IOS = "ios", e.Web = "web", e))(q || {}), z = /* @__PURE__ */ ((e) => (e.Padding = "padding", e.Radius = "radius", e.Color = "color", e.Background = "background", e.Shadow = "shadow", e))(z || {}), b = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(b || {}), I = /* @__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))(I || {}), j = /* @__PURE__ */ ((e) => (e.InvalidClient = "InvalidClient", e.InvalidToken = "InvalidToken", e.NetworkError = "NetworkError", e.IframeNotReady = "IframeNotReady", e.PaymentDeclined = "PaymentDeclined", e.ValidationError = "ValidationError", e.Timeout = "Timeout", e))(j || {});
5
- const se = {
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 = {
6
9
  primaryColor: "#0066ff",
7
10
  secondaryColor: "#5a6b7c",
8
11
  backgroundColor: "transparent",
@@ -49,22 +52,22 @@ const se = {
49
52
  buttonBorderRadius: "8px",
50
53
  transitionDuration: "0.2s",
51
54
  transitionTimingFunction: "ease"
52
- }, Z = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") && !window.location.search.includes("production"), Q = Z ? F : x, $ = [F, x], D = Y, p = B, u = {
53
- INIT: b.Init,
54
- CONFIG: b.Config,
55
- UPDATE: b.Update,
56
- CONFIRM_PAYMENT: b.ConfirmPayment,
57
- VALIDATE: b.Validate,
58
- RESET: b.Reset,
59
- READY: I.Ready,
60
- ERROR: I.Error,
61
- PAYMENT_COMPLETE: I.PaymentComplete,
62
- PAYMENT_FAILED: I.PaymentFailed,
63
- PAYMENT_PENDING: I.PaymentPending,
64
- VALIDATION_ERROR: I.ValidationError,
65
- PAYMENT_METHOD_SELECTED: I.PaymentMethodSelected,
66
- RESIZE: I.Resize
67
- }, fe = {
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 = {
68
71
  INVALID_CLIENT: "InvalidClient",
69
72
  INVALID_TOKEN: "InvalidToken",
70
73
  NETWORK_ERROR: "NetworkError",
@@ -72,7 +75,7 @@ const se = {
72
75
  PAYMENT_DECLINED: "PaymentDeclined",
73
76
  VALIDATION_ERROR: "ValidationError",
74
77
  TIMEOUT: "Timeout"
75
- }, M = "payconductor-skeleton-style", J = `
78
+ }, z = "payconductor-skeleton-style", me = `
76
79
  @keyframes payconductor-shimmer {
77
80
  0% { background-position: -200% 0; }
78
81
  100% { background-position: 200% 0; }
@@ -85,182 +88,197 @@ const se = {
85
88
  width: 100%;
86
89
  }
87
90
  `;
88
- function X(e) {
89
- const r = new URLSearchParams({
91
+ function fe(e) {
92
+ const n = new URLSearchParams({
90
93
  publicKey: e.publicKey
91
94
  });
92
- return `${Q}?${r.toString()}`;
95
+ return `${le}?${n.toString()}`;
93
96
  }
94
- function ee() {
97
+ function ye() {
95
98
  return crypto.randomUUID();
96
99
  }
97
- function te(e, r) {
98
- return r.some((n) => {
100
+ function we(e, n) {
101
+ return n.some((t) => {
99
102
  try {
100
- return new URL(n).origin === e;
103
+ return new URL(t).origin === e;
101
104
  } catch {
102
- return n === e;
105
+ return t === e;
103
106
  }
104
107
  });
105
108
  }
106
- function L() {
109
+ function O() {
107
110
  return /* @__PURE__ */ new Map();
108
111
  }
109
- function A(e, r, n, t) {
110
- return new Promise((c, s) => {
112
+ function D(e, n, t, a) {
113
+ return new Promise((i, o) => {
111
114
  if (!e || !("contentWindow" in e)) {
112
- s(new Error("Iframe not defined"));
115
+ o(new Error("Iframe not defined"));
113
116
  return;
114
117
  }
115
118
  if (!(e != null && e.contentWindow)) {
116
- s(new Error("Iframe not ready"));
119
+ o(new Error("Iframe not ready"));
117
120
  return;
118
121
  }
119
- if (!r) {
120
- s(new Error("Pending requests not initialized"));
122
+ if (!n) {
123
+ o(new Error("Pending requests not initialized"));
121
124
  return;
122
125
  }
123
- const h = ee();
124
- r.set(h, {
125
- resolve: c,
126
- reject: s
126
+ const d = ye();
127
+ n.set(d, {
128
+ resolve: i,
129
+ reject: o
127
130
  }), e.contentWindow.postMessage({
128
- type: n,
129
- data: t,
130
- requestId: h
131
+ type: t,
132
+ data: a,
133
+ requestId: d
131
134
  }, "*"), setTimeout(() => {
132
- r != null && r.has(h) && (r.delete(h), s(new Error("Request timeout")));
133
- }, p);
135
+ n != null && n.has(d) && (n.delete(d), o(new Error("Request timeout")));
136
+ }, he);
134
137
  });
135
138
  }
136
- function ne(e, r, n) {
137
- return A(e, r, u.CONFIRM_PAYMENT, {
138
- orderId: n.orderId
139
+ function Ee(e, n, t) {
140
+ return D(e, n, P.CONFIRM_PAYMENT, t);
141
+ }
142
+ async function ge(e, n, t) {
143
+ return await Ee(e, n, {
144
+ orderId: t.orderId
139
145
  });
140
146
  }
141
- function re(e, r, n) {
142
- return A(e, r, u.VALIDATE, n);
147
+ function Pe(e, n, t) {
148
+ return D(e, n, P.VALIDATE, t);
143
149
  }
144
- function oe(e, r) {
145
- return A(e, r, u.RESET);
150
+ function Se(e, n) {
151
+ return D(e, n, P.RESET);
146
152
  }
147
- function ae(e, r, n) {
148
- return A(e, r, u.CONFIG, n);
153
+ function pe(e, n, t) {
154
+ return D(e, n, P.CONFIG, t);
149
155
  }
150
- function ie(e, r, n) {
151
- return A(e, r, u.INIT, n);
156
+ function be(e, n, t) {
157
+ return D(e, n, P.INIT, t);
152
158
  }
153
- function de(e, r, n, t, c, s, h, P, T) {
154
- const y = e.data, {
155
- requestId: m,
156
- type: f,
157
- data: o,
158
- error: l
159
- } = y;
160
- if (f === u.READY) {
161
- if (t == null || t(), m && (r != null && r.has(m))) {
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))) {
162
168
  const {
163
- resolve: w
164
- } = r.get(m);
165
- r.delete(m), w(o);
169
+ resolve: T
170
+ } = n.get(y);
171
+ n.delete(y), T(E);
166
172
  }
167
173
  return;
168
174
  }
169
- if (te(e.origin, $)) {
170
- if (m && r && r.has(m)) {
175
+ if (we(e.origin, ue)) {
176
+ if (y && n && n.has(y)) {
171
177
  const {
172
- resolve: w,
173
- reject: C
174
- } = r.get(m);
175
- r.delete(m), l ? C(new Error(String(l.message))) : w(o);
178
+ resolve: T,
179
+ reject: x
180
+ } = n.get(y);
181
+ n.delete(y), b ? x(new Error(String(b.message))) : T(E);
176
182
  return;
177
183
  }
178
- if (f === u.ERROR) {
179
- n((l == null ? void 0 : l.message) || "Unknown error"), c == null || c(new Error(String(l == null ? void 0 : l.message)));
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)));
180
186
  return;
181
187
  }
182
- if (f === u.PAYMENT_COMPLETE) {
183
- o && typeof o == "object" && "status" in o && (s == null || s(o));
188
+ if (h === P.PAYMENT_COMPLETE) {
189
+ E && typeof E == "object" && "status" in E && (o == null || o(E));
184
190
  return;
185
191
  }
186
- if (f === u.PAYMENT_FAILED) {
187
- o && typeof o == "object" && "status" in o && (h == null || h(o));
192
+ if (h === P.PAYMENT_FAILED) {
193
+ E && typeof E == "object" && "status" in E && (d == null || d(E));
188
194
  return;
189
195
  }
190
- if (f === u.PAYMENT_PENDING) {
191
- o && typeof o == "object" && "status" in o && (P == null || P(o));
196
+ if (h === P.PAYMENT_PENDING) {
197
+ E && typeof E == "object" && "status" in E && (s == null || s(E));
192
198
  return;
193
199
  }
194
- if (f === u.PAYMENT_METHOD_SELECTED) {
195
- o && typeof o == "object" && "paymentMethod" in o && (T == null || T(o.paymentMethod));
200
+ if (h === P.PAYMENT_METHOD_SELECTED) {
201
+ E && typeof E == "object" && "paymentMethod" in E && (r == null || r(E.paymentMethod));
196
202
  return;
197
203
  }
198
- u.RESIZE;
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
+ }
199
218
  }
200
219
  }
201
- function me(e) {
202
- const [r, n] = N(
220
+ function Ze(e) {
221
+ const [n, t] = A(
203
222
  () => !1
204
- ), [t, c] = N(() => null), [s, h] = N(
223
+ ), [a, i] = A(() => null), [o, d] = A(
205
224
  () => ""
206
- ), [P, T] = N(() => null);
207
- return O(() => {
208
- const y = (...a) => {
209
- e.debug && console.log("[PayConductor]", ...a);
210
- }, m = X({
225
+ ), [s, r] = A(() => null);
226
+ return F(() => {
227
+ const l = (...u) => {
228
+ e.debug && console.log("[PayConductor]", ...u);
229
+ }, g = fe({
211
230
  publicKey: e.publicKey
212
231
  });
213
- h(m), n(!0);
214
- const f = L();
215
- let o = !1;
216
- y("init", e.publicKey), y("iframeUrl", m);
217
- const l = () => {
218
- var E, i;
219
- const a = (i = (E = window.PayConductor) == null ? void 0 : E.frame) == null ? void 0 : i.iframe;
220
- if (a) {
221
- if (a instanceof HTMLIFrameElement)
222
- return a;
223
- if (typeof a == "object" && a !== null) {
224
- const d = a;
225
- if ("current" in d && d.current instanceof HTMLIFrameElement)
226
- return d.current;
227
- if ("value" in d && d.value instanceof HTMLIFrameElement)
228
- return d.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;
229
247
  }
230
- return a;
248
+ return u;
231
249
  }
232
250
  return document.querySelector(
233
251
  ".payconductor-element iframe"
234
252
  ) ?? void 0;
235
- }, w = {
253
+ }, h = {
236
254
  get iframe() {
237
255
  return document.querySelector(
238
256
  ".payconductor-element iframe"
239
257
  ) ?? null;
240
258
  },
241
- set iframe(a) {
259
+ set iframe(u) {
242
260
  },
243
- iframeUrl: m,
261
+ iframeUrl: g,
244
262
  error: null
245
- }, C = {
263
+ }, E = {
246
264
  publicKey: e.publicKey,
247
265
  theme: e.theme,
248
266
  locale: e.locale,
249
267
  paymentMethods: e.paymentMethods,
250
268
  defaultPaymentMethod: e.defaultPaymentMethod
251
- }, S = {
252
- confirmPayment: (a) => {
253
- var i;
254
- y("→ CONFIRM_PAYMENT", {
255
- orderId: a.orderId
269
+ }, b = {
270
+ confirmPayment: (u) => {
271
+ var c;
272
+ l("→ CONFIRM_PAYMENT", {
273
+ orderId: u.orderId
256
274
  });
257
- const E = l();
258
- return E != null && E.contentWindow && E.contentWindow.postMessage(
275
+ const S = y();
276
+ return S != null && S.contentWindow && S.contentWindow.postMessage(
259
277
  {
260
- type: u.CONFIG,
278
+ type: P.CONFIG,
261
279
  data: {
262
280
  publicKey: e.publicKey,
263
- orderId: a.orderId,
281
+ orderId: u.orderId,
264
282
  theme: e.theme,
265
283
  locale: e.locale,
266
284
  paymentMethods: e.paymentMethods,
@@ -270,36 +288,36 @@ function me(e) {
270
288
  }
271
289
  },
272
290
  "*"
273
- ), C.orderId = a.orderId, (i = window.PayConductor) != null && i.config && (window.PayConductor.config.orderId = a.orderId), ne(E, f, a);
291
+ ), E.orderId = u.orderId, (c = window.PayConductor) != null && c.config && (window.PayConductor.config.orderId = u.orderId), ge(S, w, u);
274
292
  },
275
- validate: (a) => (y("→ VALIDATE", a), re(l(), f, a)),
276
- reset: () => (y("→ RESET"), oe(l(), f)),
277
- getSelectedPaymentMethod: () => P
293
+ validate: (u) => (l("→ VALIDATE", u), Pe(y(), w, u)),
294
+ reset: () => (l("→ RESET"), Se(y(), w)),
295
+ getSelectedPaymentMethod: () => s
278
296
  };
279
297
  window.PayConductor = {
280
- frame: w,
281
- config: C,
282
- api: S,
283
- selectedPaymentMethod: P
284
- }, y("registered"), window.dispatchEvent(
298
+ frame: h,
299
+ config: E,
300
+ api: b,
301
+ selectedPaymentMethod: s
302
+ }, l("registered"), window.dispatchEvent(
285
303
  new CustomEvent("payconductor:registered", {
286
304
  detail: window.PayConductor
287
305
  })
288
306
  );
289
- const R = async () => {
290
- if (!o) {
291
- const a = l();
292
- if (!a) {
293
- y("→ CONFIG skipped: iframe not found");
307
+ const T = async () => {
308
+ if (!m) {
309
+ const u = y();
310
+ if (!u) {
311
+ l("→ CONFIG skipped: iframe not found");
294
312
  return;
295
313
  }
296
- o = !0, y("→ CONFIG", {
314
+ m = !0, l("→ CONFIG", {
297
315
  theme: e.theme,
298
316
  locale: e.locale,
299
317
  paymentMethods: e.paymentMethods,
300
318
  defaultPaymentMethod: e.defaultPaymentMethod,
301
319
  showPaymentButtons: e.showPaymentButtons
302
- }), ae(a, f, {
320
+ }), pe(u, w, {
303
321
  theme: e.theme,
304
322
  locale: e.locale,
305
323
  paymentMethods: e.paymentMethods,
@@ -308,67 +326,77 @@ function me(e) {
308
326
  nuPayConfig: e.nuPayConfig
309
327
  });
310
328
  }
311
- }, U = (a) => {
312
- var E;
313
- (E = a.data) != null && E.type && y("←", a.data.type, a.data.data ?? ""), de(
314
- a,
315
- f,
316
- (i) => {
317
- var d;
318
- c(i), w.error = i, (d = window.PayConductor) != null && d.frame && (window.PayConductor.frame.error = i);
329
+ }, x = (u) => {
330
+ var S;
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);
319
337
  },
320
338
  () => {
321
- var i;
322
- (i = e.onReady) == null || i.call(e), R();
339
+ var c;
340
+ (c = e.onReady) == null || c.call(e), T();
323
341
  },
324
- (i) => {
325
- var d;
326
- (d = e.onError) == null || d.call(e, i);
342
+ (c) => {
343
+ var f;
344
+ (f = e.onError) == null || f.call(e, c);
327
345
  },
328
- (i) => {
329
- var d;
330
- (d = e.onPaymentComplete) == null || d.call(e, i);
346
+ (c) => {
347
+ var f;
348
+ (f = e.onPaymentComplete) == null || f.call(e, c);
331
349
  },
332
- (i) => {
333
- var d;
334
- (d = e.onPaymentFailed) == null || d.call(e, i);
350
+ (c) => {
351
+ var f;
352
+ (f = e.onPaymentFailed) == null || f.call(e, c);
335
353
  },
336
- (i) => {
337
- var d;
338
- (d = e.onPaymentPending) == null || d.call(e, i);
354
+ (c) => {
355
+ var f;
356
+ (f = e.onPaymentPending) == null || f.call(e, c);
339
357
  },
340
- (i) => {
341
- var d;
342
- T(i), window.PayConductor && (window.PayConductor.selectedPaymentMethod = i), (d = e.onPaymentMethodSelected) == null || d.call(e, i);
358
+ (c) => {
359
+ var f;
360
+ r(c), window.PayConductor && (window.PayConductor.selectedPaymentMethod = c), (f = e.onPaymentMethodSelected) == null || f.call(e, c);
361
+ },
362
+ () => {
363
+ var c;
364
+ (c = e.onThreeDSChallenge) == null || c.call(e);
365
+ },
366
+ () => {
367
+ var c;
368
+ (c = e.onThreeDSComplete) == null || c.call(e);
369
+ },
370
+ () => {
371
+ var c;
372
+ (c = e.onThreeDSFailed) == null || c.call(e);
343
373
  }
344
374
  );
345
375
  };
346
- window.addEventListener("message", U);
347
- const k = () => {
348
- var E, i, d;
349
- const a = l();
350
- if (!a)
351
- return !1;
376
+ window.addEventListener("message", x);
377
+ const V = () => {
378
+ var S, c, f;
379
+ const u = y();
380
+ if (!u) return !1;
352
381
  try {
353
- if ((((E = a.contentDocument) == null ? void 0 : E.readyState) ?? ((d = (i = a.contentWindow) == null ? void 0 : i.document) == null ? void 0 : d.readyState)) === "complete")
354
- return R(), !0;
382
+ if ((((S = u.contentDocument) == null ? void 0 : S.readyState) ?? ((f = (c = u.contentWindow) == null ? void 0 : c.document) == null ? void 0 : f.readyState)) === "complete")
383
+ return T(), !0;
355
384
  } catch {
356
385
  }
357
386
  return !1;
358
- }, v = () => {
359
- if (k())
360
- return;
361
- const a = l();
362
- if (a) {
363
- a.addEventListener("load", () => R(), {
387
+ }, K = () => {
388
+ if (V()) return;
389
+ const u = y();
390
+ if (u) {
391
+ u.addEventListener("load", () => T(), {
364
392
  once: !0
365
393
  });
366
394
  return;
367
395
  }
368
- setTimeout(v, 50);
396
+ setTimeout(K, 50);
369
397
  };
370
- v();
371
- }, []), /* @__PURE__ */ _(
398
+ K();
399
+ }, []), /* @__PURE__ */ N(
372
400
  "div",
373
401
  {
374
402
  className: "payconductor",
@@ -380,37 +408,37 @@ function me(e) {
380
408
  }
381
409
  );
382
410
  }
383
- function ye(e) {
384
- const r = V(null), [n, t] = N(() => ""), [c, s] = N(() => !1), [h, P] = N(() => "");
385
- return O(() => {
386
- if (typeof document < "u" && !document.getElementById(M)) {
387
- const o = document.createElement("style");
388
- o.id = M, o.textContent = J, document.head.appendChild(o);
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);
389
417
  }
390
- const T = (o) => {
391
- o != null && o.frame && (t(o.frame.iframeUrl || ""), s(!0), console.log("init", {
418
+ const r = (m) => {
419
+ m != null && m.frame && (a(m.frame.iframeUrl || ""), o(!0), console.log("init", {
392
420
  PayConductor: window.PayConductor
393
421
  }));
394
- }, y = typeof window < "u" ? window.PayConductor : null;
395
- if (y)
396
- T(y);
422
+ }, l = typeof window < "u" ? window.PayConductor : null;
423
+ if (l)
424
+ r(l);
397
425
  else {
398
- const o = (l) => {
399
- T(l.detail), window.removeEventListener("payconductor:registered", o);
426
+ const m = (y) => {
427
+ r(y.detail), window.removeEventListener("payconductor:registered", m);
400
428
  };
401
- window.addEventListener("payconductor:registered", o);
429
+ window.addEventListener("payconductor:registered", m);
402
430
  }
403
- let m = !1;
404
- const f = (o) => {
405
- var l, w, C, S;
406
- if (((l = o.data) == null ? void 0 : l.type) === u.RESIZE && ((C = (w = o.data) == null ? void 0 : w.data) != null && C.height) && P(o.data.data.height + "px"), ((S = o.data) == null ? void 0 : S.type) === u.READY && e.height && !m) {
407
- m = !0;
408
- const R = document.querySelector(
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;
436
+ const T = document.querySelector(
409
437
  ".payconductor-element iframe"
410
438
  );
411
- R != null && R.contentWindow && R.contentWindow.postMessage(
439
+ T != null && T.contentWindow && T.contentWindow.postMessage(
412
440
  {
413
- type: u.CONFIG,
441
+ type: P.CONFIG,
414
442
  data: {
415
443
  height: e.height
416
444
  },
@@ -420,8 +448,8 @@ function ye(e) {
420
448
  );
421
449
  }
422
450
  };
423
- return window.addEventListener("message", f), () => window.removeEventListener("message", f);
424
- }, []), /* @__PURE__ */ H(
451
+ return window.addEventListener("message", w), () => window.removeEventListener("message", w);
452
+ }, []), /* @__PURE__ */ q(
425
453
  "div",
426
454
  {
427
455
  className: "payconductor-element",
@@ -429,25 +457,25 @@ function ye(e) {
429
457
  width: "100%"
430
458
  },
431
459
  children: [
432
- c ? null : /* @__PURE__ */ _(
460
+ i ? null : /* @__PURE__ */ N(
433
461
  "div",
434
462
  {
435
463
  className: "payconductor-skeleton",
436
464
  style: {
437
- height: e.height || D
465
+ height: e.height || B
438
466
  }
439
467
  }
440
468
  ),
441
- c && n ? /* @__PURE__ */ _(
469
+ i && t ? /* @__PURE__ */ N(
442
470
  "iframe",
443
471
  {
444
472
  allow: "payment",
445
473
  title: "PayConductor",
446
- ref: r,
447
- src: n,
474
+ ref: n,
475
+ src: t,
448
476
  style: {
449
477
  width: "100%",
450
- height: e.height || h || D,
478
+ height: e.height || d || B,
451
479
  border: "none"
452
480
  }
453
481
  }
@@ -456,13 +484,41 @@ function ye(e) {
456
484
  }
457
485
  );
458
486
  }
459
- function Ee() {
460
- const e = typeof window < "u" ? window.PayConductor : null, r = e != null && e.config ? {
487
+ function et(e) {
488
+ const [n, t] = A(() => !1);
489
+ return F(() => {
490
+ const a = () => {
491
+ t(!0);
492
+ }, i = () => {
493
+ t(!1);
494
+ };
495
+ return window.addEventListener("payconductor:3ds:show", a), window.addEventListener("payconductor:3ds:hide", i), typeof window < "u" && (window.PayConductor3DS = {
496
+ container: () => document.getElementById("payconductor-3ds-container"),
497
+ show: a,
498
+ hide: i
499
+ }, window.dispatchEvent(new CustomEvent("payconductor:3ds:registered"))), () => {
500
+ window.removeEventListener("payconductor:3ds:show", a), window.removeEventListener("payconductor:3ds:hide", i), window.PayConductor3DS = null;
501
+ };
502
+ }, []), /* @__PURE__ */ N(
503
+ "div",
504
+ {
505
+ className: "payconductor-three-ds",
506
+ id: "payconductor-3ds-container",
507
+ style: {
508
+ width: "100%",
509
+ display: n ? "block" : "none",
510
+ minHeight: n ? e.height || "600px" : "0"
511
+ }
512
+ }
513
+ );
514
+ }
515
+ function tt() {
516
+ const e = typeof window < "u" ? window.PayConductor : null, n = e != null && e.config ? {
461
517
  publicKey: e.config.publicKey,
462
518
  orderId: e.config.orderId,
463
519
  theme: e.config.theme,
464
520
  locale: e.config.locale
465
- } : {}, n = e != null && e.frame ? {
521
+ } : {}, t = e != null && e.frame ? {
466
522
  iframe: e.frame.iframe,
467
523
  error: e.frame.error
468
524
  } : {
@@ -470,102 +526,97 @@ function Ee() {
470
526
  error: null
471
527
  };
472
528
  return {
473
- ...r,
474
- ...n
529
+ ...n,
530
+ ...t
475
531
  };
476
532
  }
477
- function g(e) {
478
- var r;
479
- if ((r = e == null ? void 0 : e.frame) != null && r.iframe) {
480
- const n = e.frame.iframe;
481
- if (n instanceof HTMLIFrameElement)
482
- return n;
483
- if (n && typeof n == "object") {
484
- if ("current" in n) {
485
- const t = n.current;
486
- if (t instanceof HTMLIFrameElement)
487
- return t;
533
+ function U(e) {
534
+ var n;
535
+ if ((n = e == null ? void 0 : e.frame) != null && n.iframe) {
536
+ const t = e.frame.iframe;
537
+ if (t instanceof HTMLIFrameElement) return t;
538
+ if (t && typeof t == "object") {
539
+ if ("current" in t) {
540
+ const a = t.current;
541
+ if (a instanceof HTMLIFrameElement) return a;
488
542
  }
489
- if ("value" in n) {
490
- const t = n.value;
491
- if (t instanceof HTMLIFrameElement)
492
- return t;
543
+ if ("value" in t) {
544
+ const a = t.value;
545
+ if (a instanceof HTMLIFrameElement) return a;
493
546
  }
494
547
  }
495
548
  }
496
549
  return document.querySelector(".payconductor-element iframe") ?? null;
497
550
  }
498
- function he() {
499
- const e = () => typeof window < "u" ? window.PayConductor : null, r = (n, t) => {
500
- const c = e();
501
- if (!c)
502
- return;
503
- const s = g(c);
504
- s != null && s.contentWindow && s.contentWindow.postMessage({
505
- type: n,
506
- data: t
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);
556
+ o != null && o.contentWindow && o.contentWindow.postMessage({
557
+ type: t,
558
+ data: a
507
559
  }, "*");
508
560
  };
509
561
  return {
510
- init: async (n) => {
511
- const t = g(e()), c = L();
512
- return ie(t || void 0, c, n);
562
+ init: async (t) => {
563
+ const a = U(e()), i = O();
564
+ return be(a || void 0, i, t);
513
565
  },
514
- confirmPayment: async (n) => {
515
- if (!n.orderId)
566
+ confirmPayment: async (t) => {
567
+ if (!t.orderId)
516
568
  throw new Error("Order ID is required");
517
- const t = e();
518
- if (!(t != null && t.api))
519
- throw new Error("PayConductor not initialized");
520
- return t.api.confirmPayment(n);
569
+ const a = e();
570
+ if (!(a != null && a.api)) throw new Error("PayConductor not initialized");
571
+ return a.api.confirmPayment(t);
521
572
  },
522
- validate: (n) => {
523
- const t = e();
524
- return t ? t.api.validate(n) : Promise.resolve(!1);
573
+ validate: (t) => {
574
+ const a = e();
575
+ return a ? a.api.validate(t) : Promise.resolve(!1);
525
576
  },
526
577
  reset: () => {
527
- const n = e();
528
- return n ? n.api.reset() : Promise.resolve();
578
+ const t = e();
579
+ return t ? t.api.reset() : Promise.resolve();
529
580
  },
530
581
  getSelectedPaymentMethod: () => {
531
- var n;
532
- return ((n = e()) == null ? void 0 : n.selectedPaymentMethod) ?? null;
582
+ var t;
583
+ return ((t = e()) == null ? void 0 : t.selectedPaymentMethod) ?? null;
533
584
  },
534
- updateConfig: (n) => {
535
- var c;
536
- const t = (c = e()) == null ? void 0 : c.config;
537
- r(u.CONFIG, {
538
- publicKey: t == null ? void 0 : t.publicKey,
539
- orderId: t == null ? void 0 : t.orderId,
540
- theme: n.theme ?? (t == null ? void 0 : t.theme),
541
- locale: n.locale ?? (t == null ? void 0 : t.locale),
542
- paymentMethods: n.paymentMethods ?? (t == null ? void 0 : t.paymentMethods)
585
+ updateConfig: (t) => {
586
+ var i;
587
+ const a = (i = e()) == null ? void 0 : i.config;
588
+ n(P.CONFIG, {
589
+ publicKey: a == null ? void 0 : a.publicKey,
590
+ orderId: a == null ? void 0 : a.orderId,
591
+ theme: t.theme ?? (a == null ? void 0 : a.theme),
592
+ locale: t.locale ?? (a == null ? void 0 : a.locale),
593
+ paymentMethods: t.paymentMethods ?? (a == null ? void 0 : a.paymentMethods)
543
594
  });
544
595
  },
545
- updateOrderId: (n) => {
546
- var c;
547
- const t = (c = e()) == null ? void 0 : c.config;
548
- r(u.CONFIG, {
549
- publicKey: t == null ? void 0 : t.publicKey,
550
- orderId: n,
551
- theme: t == null ? void 0 : t.theme,
552
- locale: t == null ? void 0 : t.locale,
553
- paymentMethods: t == null ? void 0 : t.paymentMethods
596
+ updateOrderId: (t) => {
597
+ var i;
598
+ const a = (i = e()) == null ? void 0 : i.config;
599
+ n(P.CONFIG, {
600
+ publicKey: a == null ? void 0 : a.publicKey,
601
+ orderId: t,
602
+ theme: a == null ? void 0 : a.theme,
603
+ locale: a == null ? void 0 : a.locale,
604
+ paymentMethods: a == null ? void 0 : a.paymentMethods
554
605
  });
555
606
  },
556
- update: (n) => {
557
- r(u.UPDATE, n);
607
+ update: (t) => {
608
+ n(P.UPDATE, t);
558
609
  },
559
610
  submit: async () => {
560
- const n = g(e()), t = L();
611
+ const t = U(e()), a = O();
561
612
  try {
562
- return await A(n || void 0, t, u.CONFIRM_PAYMENT, {}), {
613
+ return await D(t || void 0, a, P.CONFIRM_PAYMENT, {}), {
563
614
  paymentMethod: void 0
564
615
  };
565
- } catch (c) {
616
+ } catch (i) {
566
617
  return {
567
618
  error: {
568
- message: c instanceof Error ? c.message : "Payment failed",
619
+ message: i instanceof Error ? i.message : "Payment failed",
569
620
  code: "payment_error",
570
621
  type: "payment_error"
571
622
  }
@@ -574,31 +625,682 @@ function he() {
574
625
  }
575
626
  };
576
627
  }
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;
1099
+ return {
1100
+ handleChallenge: async (i) => {
1101
+ var s;
1102
+ if (!(i.status === "NeedChallenge" || i.statusDetail === "ThreeDsAwaitingChallenge"))
1103
+ return {
1104
+ status: p.Success
1105
+ };
1106
+ (s = e == null ? void 0 : e.onChallenge) == null || s.call(e), n = new Ke(i);
1107
+ const d = await n.authenticate({
1108
+ onComplete: e == null ? void 0 : e.onComplete,
1109
+ onError: e == null ? void 0 : e.onError,
1110
+ onTimeout: e == null ? void 0 : e.onTimeout
1111
+ });
1112
+ return n.destroy(), n = null, d;
1113
+ },
1114
+ destroy: () => {
1115
+ n == null || n.destroy(), n = null;
1116
+ }
1117
+ };
1118
+ }
1119
+ class Be extends Error {
1120
+ constructor(n, t) {
1121
+ super(n), this.title = t, this.name = "PayConductorTokenizeApiError";
1122
+ }
1123
+ }
1124
+ class ze {
1125
+ constructor(n) {
1126
+ this.publicKey = n;
1127
+ }
1128
+ async getSettings() {
1129
+ const n = await fetch(`${this.baseUrl}/card-tokenization/settings`, {
1130
+ method: "GET",
1131
+ headers: this.headers
1132
+ });
1133
+ return n.ok || await this.parseResponseError("Failed to fetch settings", n), await n.json();
1134
+ }
1135
+ async createToken(n) {
1136
+ const t = await fetch(`${this.baseUrl}/card-tokenization/tokenize`, {
1137
+ method: "POST",
1138
+ headers: this.headers,
1139
+ body: JSON.stringify(n)
1140
+ });
1141
+ return t.ok || await this.parseResponseError("Failed to generate token", t), await t.json();
1142
+ }
1143
+ async saveTokens(n, t, a) {
1144
+ const i = await fetch(`${this.baseUrl}/card-tokenization/save-tokens/${t}/${a}`, {
1145
+ method: "POST",
1146
+ headers: this.headers,
1147
+ body: JSON.stringify(n)
1148
+ });
1149
+ i.ok || await this.parseResponseError("Failed to save tokens", i);
1150
+ }
1151
+ async parseResponseError(n, t) {
1152
+ var i, o, d, s;
1153
+ let a = "";
1154
+ try {
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);
1157
+ } catch {
1158
+ }
1159
+ throw new Be(a, n);
1160
+ }
1161
+ get baseUrl() {
1162
+ return typeof window < "u" && window.location.href.includes("localhost") ? "http://localhost:3000/api/v1/sdk" : "https://payconductor.ai/api/v1/sdk";
1163
+ }
1164
+ get headers() {
1165
+ return {
1166
+ Authorization: `Basic ${btoa(`${this.publicKey}:x`)}`,
1167
+ "Content-Type": "application/json"
1168
+ };
1169
+ }
1170
+ }
1171
+ class He {
1172
+ constructor(n) {
1173
+ this.input = n;
1174
+ }
1175
+ }
1176
+ class Ye extends He {
1177
+ constructor() {
1178
+ super(...arguments);
1179
+ C(this, "scriptUrl", "https://sdk.mercadopago.com/js/v2");
1180
+ }
1181
+ async tokenize() {
1182
+ if (!("publicKey" in this.input.setting))
1183
+ throw new Error("MercadoPago public key is missing in settings");
1184
+ if (!this.input.customer.documentNumber)
1185
+ throw new Error("Customer document number is required for tokenization");
1186
+ const t = window.MercadoPago;
1187
+ if (!t) throw new Error("MercadoPago SDK not available");
1188
+ const a = new t(this.input.setting.publicKey), {
1189
+ expiration: i,
1190
+ cvv: o,
1191
+ number: d,
1192
+ holderName: s
1193
+ } = this.input.card;
1194
+ return (await a.createCardToken({
1195
+ cardExpirationMonth: String(i.month),
1196
+ cardExpirationYear: String(i.year),
1197
+ cardholderName: s,
1198
+ cardNumber: d,
1199
+ securityCode: o,
1200
+ identificationType: this.input.customer.documentType === G.Cpf ? "CPF" : "CNPJ",
1201
+ identificationNumber: this.input.customer.documentNumber
1202
+ })).id;
1203
+ }
1204
+ }
1205
+ const Ge = {
1206
+ [I.MercadoPago]: Ye
1207
+ };
1208
+ class Ve {
1209
+ constructor(n) {
1210
+ C(this, "api");
1211
+ this.publicKey = n, this.api = new ze(this.publicKey);
1212
+ }
1213
+ async tokenizeCard(n) {
1214
+ this.validateCard(n);
1215
+ const {
1216
+ customerId: t,
1217
+ token: a
1218
+ } = await this.api.createToken({
1219
+ card: n.card,
1220
+ customer: n.customer,
1221
+ saveCard: !1
1222
+ }), {
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,
1229
+ setting: s.settings
1230
+ });
1231
+ return await k(l.scriptUrl), {
1232
+ token: await l.tokenize(),
1233
+ integrationId: s.integrationId,
1234
+ providerKey: s.key
1235
+ };
1236
+ }))).filter((s) => s !== null);
1237
+ return d.length > 0 && await this.api.saveTokens(d, t, a), a;
1238
+ }
1239
+ validateCard(n) {
1240
+ const {
1241
+ number: t,
1242
+ cvv: a,
1243
+ expiration: i,
1244
+ holderName: o
1245
+ } = n.card;
1246
+ if (!t || !a || !(i != null && i.month) || !(i != null && i.year) || !o)
1247
+ throw new Error("Invalid card data");
1248
+ }
1249
+ }
1250
+ function it(e) {
1251
+ const n = new Ve(e.publicKey);
1252
+ return {
1253
+ tokenizeCard: async (a) => {
1254
+ var i, o;
1255
+ try {
1256
+ const d = await n.tokenizeCard(a);
1257
+ return (i = e.onSuccess) == null || i.call(e, d), d;
1258
+ } catch (d) {
1259
+ const s = d instanceof Error ? d : new Error("Tokenization failed");
1260
+ return (o = e.onError) == null || o.call(e, s), null;
1261
+ }
1262
+ }
1263
+ };
1264
+ }
577
1265
  export {
578
- $ as ALLOWED_ORIGINS,
579
- q as DeviceType,
580
- fe as ERROR_CODES,
581
- j as ErrorCode,
582
- Q as IFRAME_BASE_URL,
583
- D as IFRAME_DEFAULT_HEIGHT_VALUE,
584
- I as IncomingMessage,
585
- z as InputStyleKey,
586
- b as OutgoingMessage,
587
- u as POST_MESSAGES,
588
- me as PayConductor,
589
- ye as PayConductorCheckoutElement,
590
- G as PaymentMethod,
591
- K as PaymentMethodLayout,
592
- W as PaymentStatus,
593
- p as REQUEST_TIMEOUT,
594
- J as SKELETON_CSS,
595
- M as SKELETON_STYLE_ID,
596
- X as buildIframeUrl,
597
- me as default,
598
- se as defaultTheme,
599
- ee as generateRequestId,
600
- te as isValidOrigin,
601
- Ee as usePayConductor,
602
- he as usePayconductorElement
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
603
1305
  };
604
1306
  //# sourceMappingURL=index.es.js.map