@payconductor/react 1.0.1 → 1.0.3

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,22 +1,70 @@
1
- import { jsx as D } from "react/jsx-runtime";
2
- import { useState as A, useEffect as U, useRef as G } from "react";
3
- const F = "https://iframe.payconductor.ai/v1", v = "http://localhost:5175/v1", q = 3e4, W = "600px";
4
- var T = /* @__PURE__ */ ((e) => (e.Init = "Init", e.Config = "Config", e.Update = "Update", e.ConfirmPayment = "ConfirmPayment", e.Validate = "Validate", e.Reset = "Reset", e))(T || {}), h = /* @__PURE__ */ ((e) => (e.Ready = "Ready", e.Error = "Error", e.PaymentComplete = "PaymentComplete", e.PaymentFailed = "PaymentFailed", e.PaymentPending = "PaymentPending", e.ValidationError = "ValidationError", e.PaymentMethodSelected = "PaymentMethodSelected", e))(h || {});
5
- const B = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") && !window.location.search.includes("production"), j = B ? v : F, k = [v, F], Q = W, $ = q, f = {
6
- INIT: T.Init,
7
- CONFIG: T.Config,
8
- UPDATE: T.Update,
9
- CONFIRM_PAYMENT: T.ConfirmPayment,
10
- VALIDATE: T.Validate,
11
- RESET: T.Reset,
12
- READY: h.Ready,
13
- ERROR: h.Error,
14
- PAYMENT_COMPLETE: h.PaymentComplete,
15
- PAYMENT_FAILED: h.PaymentFailed,
16
- PAYMENT_PENDING: h.PaymentPending,
17
- VALIDATION_ERROR: h.ValidationError,
18
- PAYMENT_METHOD_SELECTED: h.PaymentMethodSelected
19
- }, oe = {
1
+ 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 = {
6
+ primaryColor: "#0066ff",
7
+ secondaryColor: "#5a6b7c",
8
+ backgroundColor: "transparent",
9
+ surfaceColor: "#f8fafc",
10
+ textColor: "#0f172a",
11
+ textSecondaryColor: "#64748b",
12
+ errorColor: "#ef4444",
13
+ successColor: "#22c55e",
14
+ warningColor: "#f59e0b",
15
+ borderColor: "#e2e8f0",
16
+ disabledColor: "#cbd5e1",
17
+ fontFamily: '"Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
18
+ fontSize: {
19
+ xs: "0.75rem",
20
+ sm: "0.875rem",
21
+ md: "1rem",
22
+ lg: "1.125rem",
23
+ xl: "1.25rem"
24
+ },
25
+ fontWeight: {
26
+ normal: 400,
27
+ medium: 500,
28
+ bold: 600
29
+ },
30
+ lineHeight: "1.5",
31
+ spacing: {
32
+ xs: "4px",
33
+ sm: "8px",
34
+ md: "16px",
35
+ lg: "24px",
36
+ xl: "32px"
37
+ },
38
+ borderRadius: "8px",
39
+ borderWidth: "1px",
40
+ boxShadow: "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)",
41
+ boxShadowHover: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
42
+ inputBackground: "#ffffff",
43
+ inputBorderColor: "#cbd5e1",
44
+ inputBorderRadius: "8px",
45
+ inputHeight: "44px",
46
+ inputPadding: "12px 16px",
47
+ buttonHeight: "48px",
48
+ buttonPadding: "16px 24px",
49
+ buttonBorderRadius: "8px",
50
+ transitionDuration: "0.2s",
51
+ 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 = {
20
68
  INVALID_CLIENT: "InvalidClient",
21
69
  INVALID_TOKEN: "InvalidToken",
22
70
  NETWORK_ERROR: "NetworkError",
@@ -24,203 +72,234 @@ const B = typeof window < "u" && (window.location.hostname === "localhost" || wi
24
72
  PAYMENT_DECLINED: "PaymentDeclined",
25
73
  VALIDATION_ERROR: "ValidationError",
26
74
  TIMEOUT: "Timeout"
27
- };
28
- function z(e) {
75
+ }, M = "payconductor-skeleton-style", J = `
76
+ @keyframes payconductor-shimmer {
77
+ 0% { background-position: -200% 0; }
78
+ 100% { background-position: 200% 0; }
79
+ }
80
+ .payconductor-skeleton {
81
+ background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
82
+ background-size: 200% 100%;
83
+ animation: payconductor-shimmer 1.5s infinite linear;
84
+ border-radius: 4px;
85
+ width: 100%;
86
+ }
87
+ `;
88
+ function X(e) {
29
89
  const r = new URLSearchParams({
30
90
  publicKey: e.publicKey
31
91
  });
32
- return `${j}?${r.toString()}`;
92
+ return `${Q}?${r.toString()}`;
33
93
  }
34
- function J() {
94
+ function ee() {
35
95
  return crypto.randomUUID();
36
96
  }
37
- function X(e, r) {
38
- return r.some((t) => {
97
+ function te(e, r) {
98
+ return r.some((n) => {
39
99
  try {
40
- return new URL(t).origin === e;
100
+ return new URL(n).origin === e;
41
101
  } catch {
42
- return t === e;
102
+ return n === e;
43
103
  }
44
104
  });
45
105
  }
46
- function N() {
106
+ function L() {
47
107
  return /* @__PURE__ */ new Map();
48
108
  }
49
- function C(e, r, t, n) {
50
- return new Promise((d, u) => {
109
+ function A(e, r, n, t) {
110
+ return new Promise((c, s) => {
51
111
  if (!e || !("contentWindow" in e)) {
52
- u(new Error("Iframe not defined"));
112
+ s(new Error("Iframe not defined"));
53
113
  return;
54
114
  }
55
115
  if (!(e != null && e.contentWindow)) {
56
- u(new Error("Iframe not ready"));
116
+ s(new Error("Iframe not ready"));
57
117
  return;
58
118
  }
59
119
  if (!r) {
60
- u(new Error("Pending requests not initialized"));
120
+ s(new Error("Pending requests not initialized"));
61
121
  return;
62
122
  }
63
- const s = J();
64
- r.set(s, {
65
- resolve: d,
66
- reject: u
123
+ const h = ee();
124
+ r.set(h, {
125
+ resolve: c,
126
+ reject: s
67
127
  }), e.contentWindow.postMessage({
68
- type: t,
69
- data: n,
70
- requestId: s
128
+ type: n,
129
+ data: t,
130
+ requestId: h
71
131
  }, "*"), setTimeout(() => {
72
- r != null && r.has(s) && (r.delete(s), u(new Error("Request timeout")));
73
- }, $);
132
+ r != null && r.has(h) && (r.delete(h), s(new Error("Request timeout")));
133
+ }, p);
74
134
  });
75
135
  }
76
- function b(e, r, t) {
77
- return C(e, r, f.CONFIRM_PAYMENT, {
78
- orderId: t.orderId
136
+ function ne(e, r, n) {
137
+ return A(e, r, u.CONFIRM_PAYMENT, {
138
+ orderId: n.orderId
79
139
  });
80
140
  }
81
- function Z(e, r, t) {
82
- return C(e, r, f.VALIDATE, t);
141
+ function re(e, r, n) {
142
+ return A(e, r, u.VALIDATE, n);
83
143
  }
84
- function g(e, r) {
85
- return C(e, r, f.RESET);
144
+ function oe(e, r) {
145
+ return A(e, r, u.RESET);
86
146
  }
87
- function x(e, r, t) {
88
- return C(e, r, f.CONFIG, t);
147
+ function ae(e, r, n) {
148
+ return A(e, r, u.CONFIG, n);
89
149
  }
90
- function p(e, r, t) {
91
- return C(e, r, f.INIT, t);
150
+ function ie(e, r, n) {
151
+ return A(e, r, u.INIT, n);
92
152
  }
93
- function ee(e, r, t, n, d, u, s, R, m, P) {
94
- const L = e.data, {
95
- requestId: l,
96
- type: E,
97
- data: c,
98
- error: y
99
- } = L;
100
- if (E === f.READY) {
101
- if (t(!0), window.PayConductor && window.PayConductor.frame && (window.PayConductor.frame.isReady = !0), d == null || d(), l && (r != null && r.has(l))) {
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))) {
102
162
  const {
103
163
  resolve: w
104
- } = r.get(l);
105
- r.delete(l), w(c);
164
+ } = r.get(m);
165
+ r.delete(m), w(o);
106
166
  }
107
167
  return;
108
168
  }
109
- if (X(e.origin, k)) {
110
- if (l && r && r.has(l)) {
169
+ if (te(e.origin, $)) {
170
+ if (m && r && r.has(m)) {
111
171
  const {
112
172
  resolve: w,
113
- reject: M
114
- } = r.get(l);
115
- r.delete(l), y ? M(new Error(String(y.message))) : w(c);
173
+ reject: C
174
+ } = r.get(m);
175
+ r.delete(m), l ? C(new Error(String(l.message))) : w(o);
116
176
  return;
117
177
  }
118
- if (E === f.ERROR) {
119
- n((y == null ? void 0 : y.message) || "Unknown error"), u == null || u(new Error(String(y == null ? void 0 : y.message)));
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)));
120
180
  return;
121
181
  }
122
- if (E === f.PAYMENT_COMPLETE) {
123
- c && typeof c == "object" && "status" in c && (s == null || s(c));
182
+ if (f === u.PAYMENT_COMPLETE) {
183
+ o && typeof o == "object" && "status" in o && (s == null || s(o));
124
184
  return;
125
185
  }
126
- if (E === f.PAYMENT_FAILED) {
127
- c && typeof c == "object" && "status" in c && (R == null || R(c));
186
+ if (f === u.PAYMENT_FAILED) {
187
+ o && typeof o == "object" && "status" in o && (h == null || h(o));
128
188
  return;
129
189
  }
130
- if (E === f.PAYMENT_PENDING) {
131
- c && typeof c == "object" && "status" in c && (m == null || m(c));
190
+ if (f === u.PAYMENT_PENDING) {
191
+ o && typeof o == "object" && "status" in o && (P == null || P(o));
132
192
  return;
133
193
  }
134
- if (E === f.PAYMENT_METHOD_SELECTED) {
135
- c && typeof c == "object" && "paymentMethod" in c && (P == null || P(c.paymentMethod));
194
+ if (f === u.PAYMENT_METHOD_SELECTED) {
195
+ o && typeof o == "object" && "paymentMethod" in o && (T == null || T(o.paymentMethod));
136
196
  return;
137
197
  }
198
+ u.RESIZE;
138
199
  }
139
200
  }
140
- function ae(e) {
141
- const [r, t] = A(
142
- () => !1
143
- ), [n, d] = A(
201
+ function me(e) {
202
+ const [r, n] = N(
144
203
  () => !1
145
- ), [u, s] = A(() => null), [R, m] = A(
204
+ ), [t, c] = N(() => null), [s, h] = N(
146
205
  () => ""
147
- ), [P, L] = A(() => null);
148
- return U(() => {
149
- const l = (...o) => {
150
- e.debug && console.log("[PayConductor]", ...o);
151
- }, E = z({
206
+ ), [P, T] = N(() => null);
207
+ return O(() => {
208
+ const y = (...a) => {
209
+ e.debug && console.log("[PayConductor]", ...a);
210
+ }, m = X({
152
211
  publicKey: e.publicKey
153
212
  });
154
- m(E), t(!0);
155
- const c = N();
156
- let y = !1;
157
- l("init", e.publicKey), l("iframeUrl", E);
158
- const w = () => {
159
- var I, i;
160
- const o = (i = (I = window.PayConductor) == null ? void 0 : I.frame) == null ? void 0 : i.iframe;
161
- if (o) {
162
- if (o instanceof HTMLIFrameElement) return o;
163
- if (typeof o == "object" && o !== null) {
164
- const a = o;
165
- if ("current" in a && a.current instanceof HTMLIFrameElement)
166
- return a.current;
167
- if ("value" in a && a.value instanceof HTMLIFrameElement)
168
- return a.value;
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;
169
229
  }
170
- return o;
230
+ return a;
171
231
  }
172
232
  return document.querySelector(
173
233
  ".payconductor-element iframe"
174
234
  ) ?? void 0;
175
- }, M = {
235
+ }, w = {
176
236
  get iframe() {
177
237
  return document.querySelector(
178
238
  ".payconductor-element iframe"
179
239
  ) ?? null;
180
240
  },
181
- set iframe(o) {
241
+ set iframe(a) {
182
242
  },
183
- iframeUrl: E,
184
- isReady: window.PayConductor && window.PayConductor.frame ? window.PayConductor.frame.isReady : !1,
243
+ iframeUrl: m,
185
244
  error: null
186
- }, V = {
245
+ }, C = {
187
246
  publicKey: e.publicKey,
188
247
  theme: e.theme,
189
248
  locale: e.locale,
190
249
  paymentMethods: e.paymentMethods,
191
250
  defaultPaymentMethod: e.defaultPaymentMethod
192
- }, Y = {
193
- confirmPayment: (o) => (l("→ CONFIRM_PAYMENT", {
194
- orderId: o.orderId
195
- }), b(w(), c, o)),
196
- validate: (o) => (l("→ VALIDATE", o), Z(w(), c, o)),
197
- reset: () => (l("→ RESET"), g(w(), c)),
251
+ }, S = {
252
+ confirmPayment: (a) => {
253
+ var i;
254
+ y("→ CONFIRM_PAYMENT", {
255
+ orderId: a.orderId
256
+ });
257
+ const E = l();
258
+ return E != null && E.contentWindow && E.contentWindow.postMessage(
259
+ {
260
+ type: u.CONFIG,
261
+ data: {
262
+ publicKey: e.publicKey,
263
+ orderId: a.orderId,
264
+ theme: e.theme,
265
+ locale: e.locale,
266
+ paymentMethods: e.paymentMethods,
267
+ defaultPaymentMethod: e.defaultPaymentMethod,
268
+ showPaymentButtons: e.showPaymentButtons,
269
+ nuPayConfig: e.nuPayConfig
270
+ }
271
+ },
272
+ "*"
273
+ ), C.orderId = a.orderId, (i = window.PayConductor) != null && i.config && (window.PayConductor.config.orderId = a.orderId), ne(E, f, a);
274
+ },
275
+ validate: (a) => (y("→ VALIDATE", a), re(l(), f, a)),
276
+ reset: () => (y("→ RESET"), oe(l(), f)),
198
277
  getSelectedPaymentMethod: () => P
199
278
  };
200
279
  window.PayConductor = {
201
- frame: M,
202
- config: V,
203
- api: Y,
280
+ frame: w,
281
+ config: C,
282
+ api: S,
204
283
  selectedPaymentMethod: P
205
- }, l("registered"), window.dispatchEvent(
284
+ }, y("registered"), window.dispatchEvent(
206
285
  new CustomEvent("payconductor:registered", {
207
286
  detail: window.PayConductor
208
287
  })
209
288
  );
210
- const S = async () => {
211
- if (!y) {
212
- const o = w();
213
- if (!o) {
214
- l("→ CONFIG skipped: iframe not found");
289
+ const R = async () => {
290
+ if (!o) {
291
+ const a = l();
292
+ if (!a) {
293
+ y("→ CONFIG skipped: iframe not found");
215
294
  return;
216
295
  }
217
- y = !0, l("→ CONFIG", {
296
+ o = !0, y("→ CONFIG", {
218
297
  theme: e.theme,
219
298
  locale: e.locale,
220
299
  paymentMethods: e.paymentMethods,
221
300
  defaultPaymentMethod: e.defaultPaymentMethod,
222
301
  showPaymentButtons: e.showPaymentButtons
223
- }), x(o, c, {
302
+ }), ae(a, f, {
224
303
  theme: e.theme,
225
304
  locale: e.locale,
226
305
  paymentMethods: e.paymentMethods,
@@ -229,69 +308,67 @@ function ae(e) {
229
308
  nuPayConfig: e.nuPayConfig
230
309
  });
231
310
  }
232
- }, K = (o) => {
233
- var I;
234
- (I = o.data) != null && I.type && l("←", o.data.type, o.data.data ?? ""), ee(
235
- o,
236
- c,
237
- (i) => {
238
- var a;
239
- d(i), M.isReady = i, (a = window.PayConductor) != null && a.frame && (window.PayConductor.frame.isReady = i), i && S();
240
- },
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,
241
316
  (i) => {
242
- var a;
243
- s(i), M.error = i, (a = window.PayConductor) != null && a.frame && (window.PayConductor.frame.error = i);
317
+ var d;
318
+ c(i), w.error = i, (d = window.PayConductor) != null && d.frame && (window.PayConductor.frame.error = i);
244
319
  },
245
320
  () => {
246
321
  var i;
247
- (i = e.onReady) == null || i.call(e);
322
+ (i = e.onReady) == null || i.call(e), R();
248
323
  },
249
324
  (i) => {
250
- var a;
251
- (a = e.onError) == null || a.call(e, i);
325
+ var d;
326
+ (d = e.onError) == null || d.call(e, i);
252
327
  },
253
328
  (i) => {
254
- var a;
255
- (a = e.onPaymentComplete) == null || a.call(e, i);
329
+ var d;
330
+ (d = e.onPaymentComplete) == null || d.call(e, i);
256
331
  },
257
332
  (i) => {
258
- var a;
259
- (a = e.onPaymentFailed) == null || a.call(e, i);
333
+ var d;
334
+ (d = e.onPaymentFailed) == null || d.call(e, i);
260
335
  },
261
336
  (i) => {
262
- var a;
263
- (a = e.onPaymentPending) == null || a.call(e, i);
337
+ var d;
338
+ (d = e.onPaymentPending) == null || d.call(e, i);
264
339
  },
265
340
  (i) => {
266
- var a;
267
- L(i), window.PayConductor && (window.PayConductor.selectedPaymentMethod = i), (a = e.onPaymentMethodSelected) == null || a.call(e, i);
341
+ var d;
342
+ T(i), window.PayConductor && (window.PayConductor.selectedPaymentMethod = i), (d = e.onPaymentMethodSelected) == null || d.call(e, i);
268
343
  }
269
344
  );
270
345
  };
271
- window.addEventListener("message", K);
272
- const H = () => {
273
- var I, i, a;
274
- const o = w();
275
- if (!o) return !1;
346
+ window.addEventListener("message", U);
347
+ const k = () => {
348
+ var E, i, d;
349
+ const a = l();
350
+ if (!a)
351
+ return !1;
276
352
  try {
277
- if ((((I = o.contentDocument) == null ? void 0 : I.readyState) ?? ((a = (i = o.contentWindow) == null ? void 0 : i.document) == null ? void 0 : a.readyState)) === "complete")
278
- return S(), !0;
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;
279
355
  } catch {
280
356
  }
281
357
  return !1;
282
- }, O = () => {
283
- if (H()) return;
284
- const o = w();
285
- if (o) {
286
- o.addEventListener("load", () => S(), {
358
+ }, v = () => {
359
+ if (k())
360
+ return;
361
+ const a = l();
362
+ if (a) {
363
+ a.addEventListener("load", () => R(), {
287
364
  once: !0
288
365
  });
289
366
  return;
290
367
  }
291
- setTimeout(O, 50);
368
+ setTimeout(v, 50);
292
369
  };
293
- O();
294
- }, []), /* @__PURE__ */ D(
370
+ v();
371
+ }, []), /* @__PURE__ */ _(
295
372
  "div",
296
373
  {
297
374
  className: "payconductor",
@@ -303,152 +380,192 @@ function ae(e) {
303
380
  }
304
381
  );
305
382
  }
306
- function ie(e) {
307
- const r = G(null), [t, n] = A(() => ""), [d, u] = A(() => !1);
308
- return U(() => {
309
- const s = (m) => {
310
- m != null && m.frame && (n(m.frame.iframeUrl || ""), u(!0), window.PayConductor && window.PayConductor.frame && (window.PayConductor.frame.isReady = !0), console.log("init", {
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);
389
+ }
390
+ const T = (o) => {
391
+ o != null && o.frame && (t(o.frame.iframeUrl || ""), s(!0), console.log("init", {
311
392
  PayConductor: window.PayConductor
312
393
  }));
313
- }, R = typeof window < "u" ? window.PayConductor : null;
314
- if (R)
315
- s(R);
394
+ }, y = typeof window < "u" ? window.PayConductor : null;
395
+ if (y)
396
+ T(y);
316
397
  else {
317
- const m = (P) => {
318
- s(P.detail), window.removeEventListener("payconductor:registered", m);
398
+ const o = (l) => {
399
+ T(l.detail), window.removeEventListener("payconductor:registered", o);
319
400
  };
320
- window.addEventListener("payconductor:registered", m);
401
+ window.addEventListener("payconductor:registered", o);
321
402
  }
322
- }, []), /* @__PURE__ */ D(
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(
409
+ ".payconductor-element iframe"
410
+ );
411
+ R != null && R.contentWindow && R.contentWindow.postMessage(
412
+ {
413
+ type: u.CONFIG,
414
+ data: {
415
+ height: e.height
416
+ },
417
+ requestId: "element-height"
418
+ },
419
+ "*"
420
+ );
421
+ }
422
+ };
423
+ return window.addEventListener("message", f), () => window.removeEventListener("message", f);
424
+ }, []), /* @__PURE__ */ H(
323
425
  "div",
324
426
  {
325
427
  className: "payconductor-element",
326
428
  style: {
327
429
  width: "100%"
328
430
  },
329
- children: d && t ? /* @__PURE__ */ D(
330
- "iframe",
331
- {
332
- allow: "payment",
333
- title: "PayConductor",
334
- ref: r,
335
- src: t,
336
- style: {
337
- width: "100%",
338
- height: e.height || Q,
339
- border: "none"
431
+ children: [
432
+ c ? null : /* @__PURE__ */ _(
433
+ "div",
434
+ {
435
+ className: "payconductor-skeleton",
436
+ style: {
437
+ height: e.height || D
438
+ }
340
439
  }
341
- }
342
- ) : null
440
+ ),
441
+ c && n ? /* @__PURE__ */ _(
442
+ "iframe",
443
+ {
444
+ allow: "payment",
445
+ title: "PayConductor",
446
+ ref: r,
447
+ src: n,
448
+ style: {
449
+ width: "100%",
450
+ height: e.height || h || D,
451
+ border: "none"
452
+ }
453
+ }
454
+ ) : null
455
+ ]
343
456
  }
344
457
  );
345
458
  }
346
- function de() {
459
+ function Ee() {
347
460
  const e = typeof window < "u" ? window.PayConductor : null, r = e != null && e.config ? {
348
461
  publicKey: e.config.publicKey,
349
462
  orderId: e.config.orderId,
350
463
  theme: e.config.theme,
351
464
  locale: e.config.locale
352
- } : {}, t = e != null && e.frame ? {
465
+ } : {}, n = e != null && e.frame ? {
353
466
  iframe: e.frame.iframe,
354
- isReady: e.frame.isReady,
355
467
  error: e.frame.error
356
468
  } : {
357
469
  iframe: null,
358
- isReady: !1,
359
470
  error: null
360
471
  };
361
472
  return {
362
473
  ...r,
363
- ...t
474
+ ...n
364
475
  };
365
476
  }
366
- function _(e) {
477
+ function g(e) {
367
478
  var r;
368
479
  if ((r = e == null ? void 0 : e.frame) != null && r.iframe) {
369
- const t = e.frame.iframe;
370
- if (t instanceof HTMLIFrameElement) return t;
371
- if (t && typeof t == "object") {
372
- if ("current" in t) {
373
- const n = t.current;
374
- if (n instanceof HTMLIFrameElement) return n;
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;
375
488
  }
376
- if ("value" in t) {
377
- const n = t.value;
378
- if (n instanceof HTMLIFrameElement) return n;
489
+ if ("value" in n) {
490
+ const t = n.value;
491
+ if (t instanceof HTMLIFrameElement)
492
+ return t;
379
493
  }
380
494
  }
381
495
  }
382
496
  return document.querySelector(".payconductor-element iframe") ?? null;
383
497
  }
384
- function ce() {
385
- const e = () => typeof window < "u" ? window.PayConductor : null, r = (t, n) => {
386
- const d = e();
387
- if (!d) return;
388
- const u = _(d);
389
- u != null && u.contentWindow && u.contentWindow.postMessage({
390
- type: t,
391
- data: n
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
392
507
  }, "*");
393
508
  };
394
509
  return {
395
- init: async (t) => {
396
- const n = _(e()), d = N();
397
- return p(n || void 0, d, t);
510
+ init: async (n) => {
511
+ const t = g(e()), c = L();
512
+ return ie(t || void 0, c, n);
398
513
  },
399
- confirmPayment: async (t) => {
400
- const n = _(e()), d = N();
401
- if (!t.orderId)
514
+ confirmPayment: async (n) => {
515
+ if (!n.orderId)
402
516
  throw new Error("Order ID is required");
403
- return b(n || void 0, d, t);
517
+ const t = e();
518
+ if (!(t != null && t.api))
519
+ throw new Error("PayConductor not initialized");
520
+ return t.api.confirmPayment(n);
404
521
  },
405
- validate: (t) => {
406
- const n = e();
407
- return n ? n.api.validate(t) : Promise.resolve(!1);
522
+ validate: (n) => {
523
+ const t = e();
524
+ return t ? t.api.validate(n) : Promise.resolve(!1);
408
525
  },
409
526
  reset: () => {
410
- const t = e();
411
- return t ? t.api.reset() : Promise.resolve();
527
+ const n = e();
528
+ return n ? n.api.reset() : Promise.resolve();
412
529
  },
413
530
  getSelectedPaymentMethod: () => {
414
- var t;
415
- return ((t = e()) == null ? void 0 : t.selectedPaymentMethod) ?? null;
531
+ var n;
532
+ return ((n = e()) == null ? void 0 : n.selectedPaymentMethod) ?? null;
416
533
  },
417
- updateConfig: (t) => {
418
- var d;
419
- const n = (d = e()) == null ? void 0 : d.config;
420
- r(f.CONFIG, {
421
- publicKey: n == null ? void 0 : n.publicKey,
422
- orderId: n == null ? void 0 : n.orderId,
423
- theme: t.theme ?? (n == null ? void 0 : n.theme),
424
- locale: t.locale ?? (n == null ? void 0 : n.locale),
425
- paymentMethods: t.paymentMethods ?? (n == null ? void 0 : n.paymentMethods)
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)
426
543
  });
427
544
  },
428
- updateorderId: (t) => {
429
- var d;
430
- const n = (d = e()) == null ? void 0 : d.config;
431
- r(f.CONFIG, {
432
- publicKey: n == null ? void 0 : n.publicKey,
433
- orderId: t,
434
- theme: n == null ? void 0 : n.theme,
435
- locale: n == null ? void 0 : n.locale,
436
- paymentMethods: n == null ? void 0 : n.paymentMethods
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
437
554
  });
438
555
  },
439
- update: (t) => {
440
- r(f.UPDATE, t);
556
+ update: (n) => {
557
+ r(u.UPDATE, n);
441
558
  },
442
559
  submit: async () => {
443
- const t = _(e()), n = N();
560
+ const n = g(e()), t = L();
444
561
  try {
445
- return await C(t || void 0, n, f.CONFIRM_PAYMENT, {}), {
562
+ return await A(n || void 0, t, u.CONFIRM_PAYMENT, {}), {
446
563
  paymentMethod: void 0
447
564
  };
448
- } catch (d) {
565
+ } catch (c) {
449
566
  return {
450
567
  error: {
451
- message: d instanceof Error ? d.message : "Payment failed",
568
+ message: c instanceof Error ? c.message : "Payment failed",
452
569
  code: "payment_error",
453
570
  type: "payment_error"
454
571
  }
@@ -458,19 +575,30 @@ function ce() {
458
575
  };
459
576
  }
460
577
  export {
461
- k as ALLOWED_ORIGINS,
462
- oe as ERROR_CODES,
463
- j as IFRAME_BASE_URL,
464
- Q as IFRAME_DEFAULT_HEIGHT_VALUE,
465
- f as POST_MESSAGES,
466
- ae as PayConductor,
467
- ie as PayConductorCheckoutElement,
468
- $ as REQUEST_TIMEOUT,
469
- z as buildIframeUrl,
470
- ae as default,
471
- J as generateRequestId,
472
- X as isValidOrigin,
473
- de as usePayConductor,
474
- ce as usePayconductorElement
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
475
603
  };
476
604
  //# sourceMappingURL=index.es.js.map