@payconductor/react 1.0.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/README.md +253 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.es.js +476 -0
- package/dist/index.es.js.map +1 -0
- package/dist/payconductor/constants.d.ts +30 -0
- package/dist/payconductor/hooks/index.d.ts +3 -0
- package/dist/payconductor/hooks/use-element.d.ts +30 -0
- package/dist/payconductor/hooks/use-payconductor.d.ts +6 -0
- package/dist/payconductor/iframe/constants.d.ts +8 -0
- package/dist/payconductor/iframe/types.d.ts +241 -0
- package/dist/payconductor/internal.d.ts +11 -0
- package/dist/payconductor/payconductor-element.d.ts +5 -0
- package/dist/payconductor/payconductor.d.ts +14 -0
- package/dist/payconductor/types.d.ts +44 -0
- package/dist/payconductor/utils.d.ts +5 -0
- package/package.json +58 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
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 = {
|
|
20
|
+
INVALID_CLIENT: "InvalidClient",
|
|
21
|
+
INVALID_TOKEN: "InvalidToken",
|
|
22
|
+
NETWORK_ERROR: "NetworkError",
|
|
23
|
+
IFRAME_NOT_READY: "IframeNotReady",
|
|
24
|
+
PAYMENT_DECLINED: "PaymentDeclined",
|
|
25
|
+
VALIDATION_ERROR: "ValidationError",
|
|
26
|
+
TIMEOUT: "Timeout"
|
|
27
|
+
};
|
|
28
|
+
function z(e) {
|
|
29
|
+
const r = new URLSearchParams({
|
|
30
|
+
publicKey: e.publicKey
|
|
31
|
+
});
|
|
32
|
+
return `${j}?${r.toString()}`;
|
|
33
|
+
}
|
|
34
|
+
function J() {
|
|
35
|
+
return crypto.randomUUID();
|
|
36
|
+
}
|
|
37
|
+
function X(e, r) {
|
|
38
|
+
return r.some((t) => {
|
|
39
|
+
try {
|
|
40
|
+
return new URL(t).origin === e;
|
|
41
|
+
} catch {
|
|
42
|
+
return t === e;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function N() {
|
|
47
|
+
return /* @__PURE__ */ new Map();
|
|
48
|
+
}
|
|
49
|
+
function C(e, r, t, n) {
|
|
50
|
+
return new Promise((d, u) => {
|
|
51
|
+
if (!e || !("contentWindow" in e)) {
|
|
52
|
+
u(new Error("Iframe not defined"));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!(e != null && e.contentWindow)) {
|
|
56
|
+
u(new Error("Iframe not ready"));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!r) {
|
|
60
|
+
u(new Error("Pending requests not initialized"));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const s = J();
|
|
64
|
+
r.set(s, {
|
|
65
|
+
resolve: d,
|
|
66
|
+
reject: u
|
|
67
|
+
}), e.contentWindow.postMessage({
|
|
68
|
+
type: t,
|
|
69
|
+
data: n,
|
|
70
|
+
requestId: s
|
|
71
|
+
}, "*"), setTimeout(() => {
|
|
72
|
+
r != null && r.has(s) && (r.delete(s), u(new Error("Request timeout")));
|
|
73
|
+
}, $);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function b(e, r, t) {
|
|
77
|
+
return C(e, r, f.CONFIRM_PAYMENT, {
|
|
78
|
+
orderId: t.orderId
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function Z(e, r, t) {
|
|
82
|
+
return C(e, r, f.VALIDATE, t);
|
|
83
|
+
}
|
|
84
|
+
function g(e, r) {
|
|
85
|
+
return C(e, r, f.RESET);
|
|
86
|
+
}
|
|
87
|
+
function x(e, r, t) {
|
|
88
|
+
return C(e, r, f.CONFIG, t);
|
|
89
|
+
}
|
|
90
|
+
function p(e, r, t) {
|
|
91
|
+
return C(e, r, f.INIT, t);
|
|
92
|
+
}
|
|
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))) {
|
|
102
|
+
const {
|
|
103
|
+
resolve: w
|
|
104
|
+
} = r.get(l);
|
|
105
|
+
r.delete(l), w(c);
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (X(e.origin, k)) {
|
|
110
|
+
if (l && r && r.has(l)) {
|
|
111
|
+
const {
|
|
112
|
+
resolve: w,
|
|
113
|
+
reject: M
|
|
114
|
+
} = r.get(l);
|
|
115
|
+
r.delete(l), y ? M(new Error(String(y.message))) : w(c);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
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)));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (E === f.PAYMENT_COMPLETE) {
|
|
123
|
+
c && typeof c == "object" && "status" in c && (s == null || s(c));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (E === f.PAYMENT_FAILED) {
|
|
127
|
+
c && typeof c == "object" && "status" in c && (R == null || R(c));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (E === f.PAYMENT_PENDING) {
|
|
131
|
+
c && typeof c == "object" && "status" in c && (m == null || m(c));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (E === f.PAYMENT_METHOD_SELECTED) {
|
|
135
|
+
c && typeof c == "object" && "paymentMethod" in c && (P == null || P(c.paymentMethod));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function ae(e) {
|
|
141
|
+
const [r, t] = A(
|
|
142
|
+
() => !1
|
|
143
|
+
), [n, d] = A(
|
|
144
|
+
() => !1
|
|
145
|
+
), [u, s] = A(() => null), [R, m] = A(
|
|
146
|
+
() => ""
|
|
147
|
+
), [P, L] = A(() => null);
|
|
148
|
+
return U(() => {
|
|
149
|
+
const l = (...o) => {
|
|
150
|
+
e.debug && console.log("[PayConductor]", ...o);
|
|
151
|
+
}, E = z({
|
|
152
|
+
publicKey: e.publicKey
|
|
153
|
+
});
|
|
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;
|
|
169
|
+
}
|
|
170
|
+
return o;
|
|
171
|
+
}
|
|
172
|
+
return document.querySelector(
|
|
173
|
+
".payconductor-element iframe"
|
|
174
|
+
) ?? void 0;
|
|
175
|
+
}, M = {
|
|
176
|
+
get iframe() {
|
|
177
|
+
return document.querySelector(
|
|
178
|
+
".payconductor-element iframe"
|
|
179
|
+
) ?? null;
|
|
180
|
+
},
|
|
181
|
+
set iframe(o) {
|
|
182
|
+
},
|
|
183
|
+
iframeUrl: E,
|
|
184
|
+
isReady: window.PayConductor && window.PayConductor.frame ? window.PayConductor.frame.isReady : !1,
|
|
185
|
+
error: null
|
|
186
|
+
}, V = {
|
|
187
|
+
publicKey: e.publicKey,
|
|
188
|
+
theme: e.theme,
|
|
189
|
+
locale: e.locale,
|
|
190
|
+
paymentMethods: e.paymentMethods,
|
|
191
|
+
defaultPaymentMethod: e.defaultPaymentMethod
|
|
192
|
+
}, Y = {
|
|
193
|
+
confirmPayment: (o) => (l("→ CONFIRM_PAYMENT", {
|
|
194
|
+
orderId: o.orderId
|
|
195
|
+
}), b(w(), c, o)),
|
|
196
|
+
validate: (o) => (l("→ VALIDATE", o), Z(w(), c, o)),
|
|
197
|
+
reset: () => (l("→ RESET"), g(w(), c)),
|
|
198
|
+
getSelectedPaymentMethod: () => P
|
|
199
|
+
};
|
|
200
|
+
window.PayConductor = {
|
|
201
|
+
frame: M,
|
|
202
|
+
config: V,
|
|
203
|
+
api: Y,
|
|
204
|
+
selectedPaymentMethod: P
|
|
205
|
+
}, l("registered"), window.dispatchEvent(
|
|
206
|
+
new CustomEvent("payconductor:registered", {
|
|
207
|
+
detail: window.PayConductor
|
|
208
|
+
})
|
|
209
|
+
);
|
|
210
|
+
const S = async () => {
|
|
211
|
+
if (!y) {
|
|
212
|
+
const o = w();
|
|
213
|
+
if (!o) {
|
|
214
|
+
l("→ CONFIG skipped: iframe not found");
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
y = !0, l("→ CONFIG", {
|
|
218
|
+
theme: e.theme,
|
|
219
|
+
locale: e.locale,
|
|
220
|
+
paymentMethods: e.paymentMethods,
|
|
221
|
+
defaultPaymentMethod: e.defaultPaymentMethod,
|
|
222
|
+
showPaymentButtons: e.showPaymentButtons
|
|
223
|
+
}), x(o, c, {
|
|
224
|
+
theme: e.theme,
|
|
225
|
+
locale: e.locale,
|
|
226
|
+
paymentMethods: e.paymentMethods,
|
|
227
|
+
defaultPaymentMethod: e.defaultPaymentMethod,
|
|
228
|
+
showPaymentButtons: e.showPaymentButtons,
|
|
229
|
+
nuPayConfig: e.nuPayConfig
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}, K = (o) => {
|
|
233
|
+
var I;
|
|
234
|
+
(I = o.data) != null && I.type && l("←", o.data.type, o.data.data ?? ""), ee(
|
|
235
|
+
o,
|
|
236
|
+
c,
|
|
237
|
+
(i) => {
|
|
238
|
+
var a;
|
|
239
|
+
d(i), M.isReady = i, (a = window.PayConductor) != null && a.frame && (window.PayConductor.frame.isReady = i), i && S();
|
|
240
|
+
},
|
|
241
|
+
(i) => {
|
|
242
|
+
var a;
|
|
243
|
+
s(i), M.error = i, (a = window.PayConductor) != null && a.frame && (window.PayConductor.frame.error = i);
|
|
244
|
+
},
|
|
245
|
+
() => {
|
|
246
|
+
var i;
|
|
247
|
+
(i = e.onReady) == null || i.call(e);
|
|
248
|
+
},
|
|
249
|
+
(i) => {
|
|
250
|
+
var a;
|
|
251
|
+
(a = e.onError) == null || a.call(e, i);
|
|
252
|
+
},
|
|
253
|
+
(i) => {
|
|
254
|
+
var a;
|
|
255
|
+
(a = e.onPaymentComplete) == null || a.call(e, i);
|
|
256
|
+
},
|
|
257
|
+
(i) => {
|
|
258
|
+
var a;
|
|
259
|
+
(a = e.onPaymentFailed) == null || a.call(e, i);
|
|
260
|
+
},
|
|
261
|
+
(i) => {
|
|
262
|
+
var a;
|
|
263
|
+
(a = e.onPaymentPending) == null || a.call(e, i);
|
|
264
|
+
},
|
|
265
|
+
(i) => {
|
|
266
|
+
var a;
|
|
267
|
+
L(i), window.PayConductor && (window.PayConductor.selectedPaymentMethod = i), (a = e.onPaymentMethodSelected) == null || a.call(e, i);
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
window.addEventListener("message", K);
|
|
272
|
+
const H = () => {
|
|
273
|
+
var I, i, a;
|
|
274
|
+
const o = w();
|
|
275
|
+
if (!o) return !1;
|
|
276
|
+
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;
|
|
279
|
+
} catch {
|
|
280
|
+
}
|
|
281
|
+
return !1;
|
|
282
|
+
}, O = () => {
|
|
283
|
+
if (H()) return;
|
|
284
|
+
const o = w();
|
|
285
|
+
if (o) {
|
|
286
|
+
o.addEventListener("load", () => S(), {
|
|
287
|
+
once: !0
|
|
288
|
+
});
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
setTimeout(O, 50);
|
|
292
|
+
};
|
|
293
|
+
O();
|
|
294
|
+
}, []), /* @__PURE__ */ D(
|
|
295
|
+
"div",
|
|
296
|
+
{
|
|
297
|
+
className: "payconductor",
|
|
298
|
+
id: "payconductor",
|
|
299
|
+
style: {
|
|
300
|
+
display: "contents"
|
|
301
|
+
},
|
|
302
|
+
children: e.children
|
|
303
|
+
}
|
|
304
|
+
);
|
|
305
|
+
}
|
|
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", {
|
|
311
|
+
PayConductor: window.PayConductor
|
|
312
|
+
}));
|
|
313
|
+
}, R = typeof window < "u" ? window.PayConductor : null;
|
|
314
|
+
if (R)
|
|
315
|
+
s(R);
|
|
316
|
+
else {
|
|
317
|
+
const m = (P) => {
|
|
318
|
+
s(P.detail), window.removeEventListener("payconductor:registered", m);
|
|
319
|
+
};
|
|
320
|
+
window.addEventListener("payconductor:registered", m);
|
|
321
|
+
}
|
|
322
|
+
}, []), /* @__PURE__ */ D(
|
|
323
|
+
"div",
|
|
324
|
+
{
|
|
325
|
+
className: "payconductor-element",
|
|
326
|
+
style: {
|
|
327
|
+
width: "100%"
|
|
328
|
+
},
|
|
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"
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
) : null
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
function de() {
|
|
347
|
+
const e = typeof window < "u" ? window.PayConductor : null, r = e != null && e.config ? {
|
|
348
|
+
publicKey: e.config.publicKey,
|
|
349
|
+
orderId: e.config.orderId,
|
|
350
|
+
theme: e.config.theme,
|
|
351
|
+
locale: e.config.locale
|
|
352
|
+
} : {}, t = e != null && e.frame ? {
|
|
353
|
+
iframe: e.frame.iframe,
|
|
354
|
+
isReady: e.frame.isReady,
|
|
355
|
+
error: e.frame.error
|
|
356
|
+
} : {
|
|
357
|
+
iframe: null,
|
|
358
|
+
isReady: !1,
|
|
359
|
+
error: null
|
|
360
|
+
};
|
|
361
|
+
return {
|
|
362
|
+
...r,
|
|
363
|
+
...t
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function _(e) {
|
|
367
|
+
var r;
|
|
368
|
+
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;
|
|
375
|
+
}
|
|
376
|
+
if ("value" in t) {
|
|
377
|
+
const n = t.value;
|
|
378
|
+
if (n instanceof HTMLIFrameElement) return n;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return document.querySelector(".payconductor-element iframe") ?? null;
|
|
383
|
+
}
|
|
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
|
|
392
|
+
}, "*");
|
|
393
|
+
};
|
|
394
|
+
return {
|
|
395
|
+
init: async (t) => {
|
|
396
|
+
const n = _(e()), d = N();
|
|
397
|
+
return p(n || void 0, d, t);
|
|
398
|
+
},
|
|
399
|
+
confirmPayment: async (t) => {
|
|
400
|
+
const n = _(e()), d = N();
|
|
401
|
+
if (!t.orderId)
|
|
402
|
+
throw new Error("Order ID is required");
|
|
403
|
+
return b(n || void 0, d, t);
|
|
404
|
+
},
|
|
405
|
+
validate: (t) => {
|
|
406
|
+
const n = e();
|
|
407
|
+
return n ? n.api.validate(t) : Promise.resolve(!1);
|
|
408
|
+
},
|
|
409
|
+
reset: () => {
|
|
410
|
+
const t = e();
|
|
411
|
+
return t ? t.api.reset() : Promise.resolve();
|
|
412
|
+
},
|
|
413
|
+
getSelectedPaymentMethod: () => {
|
|
414
|
+
var t;
|
|
415
|
+
return ((t = e()) == null ? void 0 : t.selectedPaymentMethod) ?? null;
|
|
416
|
+
},
|
|
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)
|
|
426
|
+
});
|
|
427
|
+
},
|
|
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
|
|
437
|
+
});
|
|
438
|
+
},
|
|
439
|
+
update: (t) => {
|
|
440
|
+
r(f.UPDATE, t);
|
|
441
|
+
},
|
|
442
|
+
submit: async () => {
|
|
443
|
+
const t = _(e()), n = N();
|
|
444
|
+
try {
|
|
445
|
+
return await C(t || void 0, n, f.CONFIRM_PAYMENT, {}), {
|
|
446
|
+
paymentMethod: void 0
|
|
447
|
+
};
|
|
448
|
+
} catch (d) {
|
|
449
|
+
return {
|
|
450
|
+
error: {
|
|
451
|
+
message: d instanceof Error ? d.message : "Payment failed",
|
|
452
|
+
code: "payment_error",
|
|
453
|
+
type: "payment_error"
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
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
|
|
475
|
+
};
|
|
476
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/payconductor/iframe/constants.ts","../src/payconductor/iframe/types.ts","../src/payconductor/constants.ts","../src/payconductor/utils.ts","../src/payconductor/internal.ts","../src/payconductor/payconductor.tsx","../src/payconductor/payconductor-element.tsx","../src/payconductor/hooks/use-payconductor.ts","../src/payconductor/hooks/use-element.ts"],"sourcesContent":["// PayConductor Shared Constants\n// Served statically at iframe.payconductor.ai/constants.ts\n// Used by the iFrame (imported directly) and the SDK Web (synced with: bun sync)\n\nexport const APP_BASE_URL_PROD = \"https://app.payconductor.ai\";\nexport const API_BASE_URL_PROD = \"https://app.payconductor.ai/api/v1\";\nexport const IFRAME_BASE_URL_PROD = \"https://iframe.payconductor.ai/v1\";\nexport const IFRAME_BASE_URL_DEV = \"http://localhost:5175/v1\";\nexport const APP_BASE_URL_DEV = \"http://localhost:3000\";\nexport const DEFAULT_LOCALE = \"pt-BR\";\nexport const REQUEST_TIMEOUT_MS = 30000;\nexport const IFRAME_DEFAULT_HEIGHT = \"600px\"","// PayConductor Shared Types\n// Served statically at iframe.payconductor.ai/types.ts\n// Used by the iFrame (imported directly) and the SDK Web (synced with: bun sync)\n\nexport enum PaymentMethod {\n Pix = \"Pix\",\n CreditCard = \"CreditCard\",\n DebitCard = \"DebitCard\",\n BankSlip = \"BankSlip\",\n Crypto = \"Crypto\",\n ApplePay = \"ApplePay\",\n NuPay = \"NuPay\",\n PicPay = \"PicPay\",\n AmazonPay = \"AmazonPay\",\n SepaDebit = \"SepaDebit\",\n GooglePay = \"GooglePay\",\n}\nexport enum PaymentMethodLayout {\n Grid = \"grid\",\n Vertical = \"vertical\",\n Horizontal = \"horizontal\",\n}\nexport enum PaymentStatus {\n Succeeded = \"succeeded\",\n Pending = \"pending\",\n Failed = \"failed\",\n}\nexport enum DeviceType {\n Android = \"android\",\n IOS = \"ios\",\n Web = \"web\",\n}\nexport enum InputStyleKey {\n Padding = \"padding\",\n Radius = \"radius\",\n Color = \"color\",\n Background = \"background\",\n Shadow = \"shadow\",\n}\nexport enum OutgoingMessage {\n Init = \"Init\",\n Config = \"Config\",\n Update = \"Update\",\n ConfirmPayment = \"ConfirmPayment\",\n Validate = \"Validate\",\n Reset = \"Reset\",\n}\nexport enum IncomingMessage {\n Ready = \"Ready\",\n Error = \"Error\",\n PaymentComplete = \"PaymentComplete\",\n PaymentFailed = \"PaymentFailed\",\n PaymentPending = \"PaymentPending\",\n ValidationError = \"ValidationError\",\n PaymentMethodSelected = \"PaymentMethodSelected\",\n}\nexport enum ErrorCode {\n InvalidClient = \"InvalidClient\",\n InvalidToken = \"InvalidToken\",\n NetworkError = \"NetworkError\",\n IframeNotReady = \"IframeNotReady\",\n PaymentDeclined = \"PaymentDeclined\",\n ValidationError = \"ValidationError\",\n Timeout = \"Timeout\",\n}\nexport type InputStyleConfig = {\n padding?: string;\n radius?: string;\n color?: string;\n background?: string;\n shadow?: string;\n};\nexport type PaymentMethodsConfig = {\n layout?: PaymentMethodLayout;\n gap?: string;\n inputStyle?: InputStyleConfig;\n};\nexport type PaymentMethodConfig = {\n method: PaymentMethod;\n discount?: number;\n showBrands?: boolean;\n installments?: {\n count: number;\n amount: number;\n }[];\n};\nexport type PaymentMethodsResponse = {\n methods: PaymentMethod[];\n config: PaymentMethodsConfig;\n};\nexport type PayConductorTheme = {\n primaryColor?: string;\n secondaryColor?: string;\n backgroundColor?: string;\n surfaceColor?: string;\n textColor?: string;\n textSecondaryColor?: string;\n errorColor?: string;\n successColor?: string;\n warningColor?: string;\n borderColor?: string;\n disabledColor?: string;\n fontFamily?: string;\n fontSize?: {\n xs?: string;\n sm?: string;\n md?: string;\n lg?: string;\n xl?: string;\n };\n fontWeight?: {\n normal?: number;\n medium?: number;\n bold?: number;\n };\n lineHeight?: string;\n spacing?: {\n xs?: string;\n sm?: string;\n md?: string;\n lg?: string;\n xl?: string;\n };\n borderRadius?: string;\n borderWidth?: string;\n boxShadow?: string;\n boxShadowHover?: string;\n inputBackground?: string;\n inputBorderColor?: string;\n inputBorderRadius?: string;\n inputHeight?: string;\n inputPadding?: string;\n buttonHeight?: string;\n buttonPadding?: string;\n buttonBorderRadius?: string;\n transitionDuration?: string;\n transitionTimingFunction?: string;\n};\nexport const defaultTheme: PayConductorTheme = {\n primaryColor: \"#0066ff\",\n secondaryColor: \"#5a6b7c\",\n backgroundColor: \"transparent\",\n surfaceColor: \"#f8fafc\",\n textColor: \"#0f172a\",\n textSecondaryColor: \"#64748b\",\n errorColor: \"#ef4444\",\n successColor: \"#22c55e\",\n warningColor: \"#f59e0b\",\n borderColor: \"#e2e8f0\",\n disabledColor: \"#cbd5e1\",\n fontFamily: '\"Poppins\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif',\n fontSize: {\n xs: \"0.75rem\",\n sm: \"0.875rem\",\n md: \"1rem\",\n lg: \"1.125rem\",\n xl: \"1.25rem\"\n },\n fontWeight: {\n normal: 400,\n medium: 500,\n bold: 600\n },\n lineHeight: \"1.5\",\n spacing: {\n xs: \"4px\",\n sm: \"8px\",\n md: \"16px\",\n lg: \"24px\",\n xl: \"32px\"\n },\n borderRadius: \"8px\",\n borderWidth: \"1px\",\n boxShadow: \"0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)\",\n boxShadowHover: \"0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)\",\n inputBackground: \"#ffffff\",\n inputBorderColor: \"#cbd5e1\",\n inputBorderRadius: \"8px\",\n inputHeight: \"44px\",\n inputPadding: \"12px 16px\",\n buttonHeight: \"48px\",\n buttonPadding: \"16px 24px\",\n buttonBorderRadius: \"8px\",\n transitionDuration: \"0.2s\",\n transitionTimingFunction: \"ease\"\n};\nexport type PayConductorConfig = {\n publicKey: string;\n orderId?: string;\n theme?: PayConductorTheme;\n locale?: string;\n paymentMethods?: PaymentMethod[] | \"all\";\n defaultPaymentMethod?: PaymentMethod;\n paymentMethodsConfig?: PaymentMethodConfig[];\n methodsDirection?: \"vertical\" | \"horizontal\";\n showPaymentButtons?: boolean;\n /** Required when NuPay is an available payment method */\n nuPayConfig?: NuPayData;\n};\nexport type BillingDetails = {\n name: string;\n email?: string;\n phone?: string;\n address?: {\n line1: string;\n line2?: string;\n city: string;\n state: string;\n postalCode: string;\n country: string;\n };\n};\nexport type CardData = {\n number: string;\n expMonth: string;\n expYear: string;\n cvc: string;\n};\nexport type CreatePaymentMethodOptions = {\n billingDetails: BillingDetails;\n card?: CardData;\n};\nexport type PaymentMethodResult = {\n id: string;\n type: PaymentMethod;\n card?: {\n brand: string;\n last4: string;\n expMonth: number;\n expYear: number;\n };\n billingDetails?: BillingDetails;\n};\nexport type PaymentResult = {\n orderId: string;\n status: PaymentStatus;\n amount: number;\n currency: string;\n message?: string;\n};\nexport interface MessagePayload {\n type: OutgoingMessage | IncomingMessage;\n data?: unknown;\n requestId?: string;\n error?: {\n code: string;\n message: string;\n field?: string;\n };\n}\nexport type CardTokenData = {\n token: string;\n firstSixCardNumber?: string;\n};\nexport type CardFullData = {\n number: string;\n holderName: string;\n cvv: string;\n expiration: {\n month: number;\n year: number;\n };\n};\nexport type CardPaymentData = CardTokenData | CardFullData;\nexport type PixPaymentData = {\n paymentMethod: PaymentMethod.Pix;\n expirationInSeconds?: number;\n};\nexport type CreditCardPaymentData = {\n paymentMethod: PaymentMethod.CreditCard;\n card: CardPaymentData;\n installments: number;\n softDescriptor?: string;\n};\nexport type BankSlipPaymentData = {\n paymentMethod: PaymentMethod.BankSlip;\n expirationInDays?: number;\n};\nexport type NuPayData = {\n cancelUrl: string;\n merchantName: string;\n returnUrl: string;\n storeName?: string;\n};\nexport type NuPayPaymentData = {\n paymentMethod: PaymentMethod.NuPay;\n nuPay: NuPayData;\n};\nexport type PicPayPaymentData = {\n paymentMethod: PaymentMethod.PicPay;\n};\nexport type PaymentConfirmData = PixPaymentData | CreditCardPaymentData | BankSlipPaymentData | NuPayPaymentData | PicPayPaymentData","import { IFRAME_BASE_URL_DEV, IFRAME_BASE_URL_PROD, IFRAME_DEFAULT_HEIGHT, REQUEST_TIMEOUT_MS } from \"./iframe/constants\";\nimport { IncomingMessage, OutgoingMessage } from \"./iframe/types\";\nconst isDev = typeof window !== \"undefined\" && (window.location.hostname === \"localhost\" || window.location.hostname === \"127.0.0.1\") && !window.location.search.includes(\"production\");\nexport const IFRAME_BASE_URL = isDev ? IFRAME_BASE_URL_DEV : IFRAME_BASE_URL_PROD;\nexport const ALLOWED_ORIGINS = [IFRAME_BASE_URL_DEV, IFRAME_BASE_URL_PROD];\nexport const IFRAME_DEFAULT_HEIGHT_VALUE = IFRAME_DEFAULT_HEIGHT;\nexport const REQUEST_TIMEOUT = REQUEST_TIMEOUT_MS;\nexport const POST_MESSAGES = {\n INIT: OutgoingMessage.Init,\n CONFIG: OutgoingMessage.Config,\n UPDATE: OutgoingMessage.Update,\n CONFIRM_PAYMENT: OutgoingMessage.ConfirmPayment,\n VALIDATE: OutgoingMessage.Validate,\n RESET: OutgoingMessage.Reset,\n READY: IncomingMessage.Ready,\n ERROR: IncomingMessage.Error,\n PAYMENT_COMPLETE: IncomingMessage.PaymentComplete,\n PAYMENT_FAILED: IncomingMessage.PaymentFailed,\n PAYMENT_PENDING: IncomingMessage.PaymentPending,\n VALIDATION_ERROR: IncomingMessage.ValidationError,\n PAYMENT_METHOD_SELECTED: IncomingMessage.PaymentMethodSelected\n} as const;\nexport const ERROR_CODES = {\n INVALID_CLIENT: \"InvalidClient\",\n INVALID_TOKEN: \"InvalidToken\",\n NETWORK_ERROR: \"NetworkError\",\n IFRAME_NOT_READY: \"IframeNotReady\",\n PAYMENT_DECLINED: \"PaymentDeclined\",\n VALIDATION_ERROR: \"ValidationError\",\n TIMEOUT: \"Timeout\"\n} as const","import { IFRAME_BASE_URL } from \"./constants\";\nimport type { PayConductorConfig } from \"./iframe/types\";\nexport function buildIframeUrl(config: PayConductorConfig): string {\n const params = new URLSearchParams({\n publicKey: config.publicKey\n });\n return `${IFRAME_BASE_URL}?${params.toString()}`;\n}\nexport function generateRequestId(): string {\n return crypto.randomUUID();\n}\nexport function isValidOrigin(origin: string, allowedOrigins: string[]): boolean {\n return allowedOrigins.some(allowed => {\n try {\n return new URL(allowed).origin === origin;\n } catch {\n return allowed === origin;\n }\n });\n}","import { ALLOWED_ORIGINS, POST_MESSAGES, REQUEST_TIMEOUT } from \"./constants\";\nimport { IncomingMessage, OutgoingMessage, PayConductorConfig, PaymentMethod, PaymentResult } from \"./iframe/types\";\nimport type { ConfirmPaymentOptions, PendingRequest } from \"./types\";\nimport { generateRequestId, isValidOrigin } from \"./utils\";\nexport function createPendingRequestsMap(): Map<string, PendingRequest> {\n return new Map<string, PendingRequest>();\n}\nexport function sendMessageToIframe(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, type: OutgoingMessage | IncomingMessage, data?: unknown): Promise<unknown> {\n return new Promise((resolve, reject) => {\n if (!iframe || !(\"contentWindow\" in iframe)) {\n reject(new Error(\"Iframe not defined\"));\n return;\n }\n if (!iframe?.contentWindow) {\n reject(new Error(\"Iframe not ready\"));\n return;\n }\n if (!pendingMap) {\n reject(new Error(\"Pending requests not initialized\"));\n return;\n }\n const requestId = generateRequestId();\n pendingMap.set(requestId, {\n resolve,\n reject\n });\n iframe.contentWindow.postMessage({\n type,\n data,\n requestId\n }, \"*\");\n setTimeout(() => {\n if (pendingMap?.has(requestId)) {\n pendingMap.delete(requestId);\n reject(new Error(\"Request timeout\"));\n }\n }, REQUEST_TIMEOUT);\n });\n}\nexport function confirmPayment(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, options: ConfirmPaymentOptions): Promise<PaymentResult> {\n return sendMessageToIframe(iframe, pendingMap, POST_MESSAGES.CONFIRM_PAYMENT, {\n orderId: options.orderId\n }) as Promise<PaymentResult>;\n}\nexport function validatePayment(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, data: unknown): Promise<boolean> {\n return sendMessageToIframe(iframe, pendingMap, POST_MESSAGES.VALIDATE, data) as Promise<boolean>;\n}\nexport function resetPayment(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null): Promise<void> {\n return sendMessageToIframe(iframe, pendingMap, POST_MESSAGES.RESET) as Promise<void>;\n}\nexport function sendConfig(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, config: Pick<PayConductorConfig, \"theme\" | \"locale\" | \"paymentMethods\" | \"defaultPaymentMethod\" | \"showPaymentButtons\" | \"nuPayConfig\">): Promise<void> {\n return sendMessageToIframe(iframe, pendingMap, POST_MESSAGES.CONFIG, config) as Promise<void>;\n}\nexport function sendInit(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, config: PayConductorConfig): Promise<void> {\n return sendMessageToIframe(iframe, pendingMap, POST_MESSAGES.INIT, config) as Promise<void>;\n}\ntype MessagePayload = {\n requestId?: string;\n type?: string;\n data?: PaymentResult | {\n paymentMethod: PaymentMethod;\n };\n error?: {\n message?: string;\n };\n};\nexport function handleMessageEvent(event: MessageEvent, pendingMap: Map<string, PendingRequest> | null, setIsReady: (value: boolean) => void, setError: (value: string | null) => void, onReady?: () => void, onError?: (error: Error) => void, onPaymentComplete?: (data: PaymentResult) => void, onPaymentFailed?: (data: PaymentResult) => void, onPaymentPending?: (data: PaymentResult) => void, onPaymentMethodSelected?: (method: PaymentMethod) => void) {\n const payload: MessagePayload = event.data;\n const {\n requestId,\n type,\n data,\n error\n } = payload;\n if (type === POST_MESSAGES.READY) {\n setIsReady(true);\n if (window.PayConductor && window.PayConductor.frame) window.PayConductor.frame.isReady = true;\n onReady?.();\n if (requestId && pendingMap?.has(requestId)) {\n const {\n resolve\n } = pendingMap.get(requestId)!;\n pendingMap.delete(requestId);\n resolve(data);\n }\n return;\n }\n if (!isValidOrigin(event.origin, ALLOWED_ORIGINS)) {\n return;\n }\n if (requestId && pendingMap && pendingMap.has(requestId)) {\n const {\n resolve,\n reject\n } = pendingMap.get(requestId)!;\n pendingMap.delete(requestId);\n if (error) {\n reject(new Error(String(error.message)));\n } else {\n resolve(data);\n }\n return;\n }\n if (type === POST_MESSAGES.ERROR) {\n setError(error?.message || \"Unknown error\");\n onError?.(new Error(String(error?.message)));\n return;\n }\n if (type === POST_MESSAGES.PAYMENT_COMPLETE) {\n if (data && typeof data === \"object\" && \"status\" in data) {\n onPaymentComplete?.(data);\n }\n return;\n }\n if (type === POST_MESSAGES.PAYMENT_FAILED) {\n if (data && typeof data === \"object\" && \"status\" in data) {\n onPaymentFailed?.(data);\n }\n return;\n }\n if (type === POST_MESSAGES.PAYMENT_PENDING) {\n if (data && typeof data === \"object\" && \"status\" in data) {\n onPaymentPending?.(data);\n }\n return;\n }\n if (type === POST_MESSAGES.PAYMENT_METHOD_SELECTED) {\n if (data && typeof data === \"object\" && \"paymentMethod\" in data) {\n onPaymentMethodSelected?.(data.paymentMethod);\n }\n return;\n }\n}","\"use client\";\nimport * as React from \"react\";\nimport { useState, useEffect } from \"react\";\n\nexport interface PayConductorEmbedProps\n extends Omit<PayConductorConfig, \"orderId\"> {\n children?: any;\n showActionButtons?: boolean;\n debug?: boolean;\n onReady?: () => void;\n onError?: (error: Error) => void;\n onPaymentComplete?: (result: PaymentResult) => void;\n onPaymentFailed?: (result: PaymentResult) => void;\n onPaymentPending?: (result: PaymentResult) => void;\n onPaymentMethodSelected?: (method: PaymentMethod) => void;\n}\n\nimport type {\n PayConductorConfig,\n PaymentMethod,\n PaymentResult,\n} from \"./iframe/types\";\nimport {\n confirmPayment,\n createPendingRequestsMap,\n handleMessageEvent,\n resetPayment,\n sendConfig,\n validatePayment,\n} from \"./internal\";\nimport type {\n PayConductorApi,\n PayConductorFrame,\n PayConductorState,\n PendingRequest,\n} from \"./types\";\nimport { buildIframeUrl } from \"./utils\";\n\nfunction PayConductor(props: PayConductorEmbedProps) {\n const [isLoaded, setIsLoaded] = useState<PayConductorState[\"isLoaded\"]>(\n () => false\n );\n\n const [isReady, setIsReady] = useState<PayConductorState[\"isReady\"]>(\n () => false\n );\n\n const [error, setError] = useState<PayConductorState[\"error\"]>(() => null);\n\n const [iframeUrl, setIframeUrl] = useState<PayConductorState[\"iframeUrl\"]>(\n () => \"\"\n );\n\n const [selectedPaymentMethod, setSelectedPaymentMethod] = useState<\n PayConductorState[\"selectedPaymentMethod\"]\n >(() => null);\n\n useEffect(() => {\n const log = (...args: any[]) => {\n if (props.debug) console.log(\"[PayConductor]\", ...args);\n };\n const iframeUrl = buildIframeUrl({\n publicKey: props.publicKey,\n });\n setIframeUrl(iframeUrl);\n setIsLoaded(true);\n const pendingMap: Map<string, PendingRequest> = createPendingRequestsMap();\n let configSent = false;\n log(\"init\", props.publicKey);\n log(\"iframeUrl\", iframeUrl);\n const getIframe = (): HTMLIFrameElement | undefined => {\n const ref = window.PayConductor?.frame?.iframe;\n if (ref) {\n if (ref instanceof HTMLIFrameElement) return ref;\n if (typeof ref === \"object\" && ref !== null) {\n const obj = ref as Record<string, unknown>;\n if (\"current\" in obj && obj.current instanceof HTMLIFrameElement)\n return obj.current;\n if (\"value\" in obj && obj.value instanceof HTMLIFrameElement)\n return obj.value;\n }\n return ref as HTMLIFrameElement;\n }\n return (\n (document.querySelector(\n \".payconductor-element iframe\"\n ) as HTMLIFrameElement) ?? undefined\n );\n };\n const frame: PayConductorFrame = {\n get iframe(): HTMLIFrameElement | null {\n return (\n (document.querySelector(\n \".payconductor-element iframe\"\n ) as HTMLIFrameElement) ?? null\n );\n },\n set iframe(_: HTMLIFrameElement | Element | unknown | null) {},\n iframeUrl,\n isReady:\n window.PayConductor && window.PayConductor.frame\n ? window.PayConductor.frame.isReady\n : false,\n error: null,\n };\n const config: PayConductorConfig = {\n publicKey: props.publicKey,\n theme: props.theme,\n locale: props.locale,\n paymentMethods: props.paymentMethods,\n defaultPaymentMethod: props.defaultPaymentMethod,\n };\n const api: PayConductorApi = {\n confirmPayment: (options: { orderId: string }) => {\n log(\"→ CONFIRM_PAYMENT\", {\n orderId: options.orderId,\n });\n return confirmPayment(getIframe(), pendingMap, options);\n },\n validate: (data: unknown) => {\n log(\"→ VALIDATE\", data);\n return validatePayment(getIframe(), pendingMap, data);\n },\n reset: () => {\n log(\"→ RESET\");\n return resetPayment(getIframe(), pendingMap);\n },\n getSelectedPaymentMethod: () => selectedPaymentMethod,\n };\n window.PayConductor = {\n frame,\n config,\n api,\n selectedPaymentMethod: selectedPaymentMethod,\n };\n log(\"registered\");\n window.dispatchEvent(\n new CustomEvent(\"payconductor:registered\", {\n detail: window.PayConductor,\n })\n );\n const sendConfigToIframe = async () => {\n if (!configSent) {\n const iframe = getIframe();\n if (!iframe) {\n log(\"→ CONFIG skipped: iframe not found\");\n return;\n }\n configSent = true;\n log(\"→ CONFIG\", {\n theme: props.theme,\n locale: props.locale,\n paymentMethods: props.paymentMethods,\n defaultPaymentMethod: props.defaultPaymentMethod,\n showPaymentButtons: props.showPaymentButtons,\n });\n sendConfig(iframe, pendingMap, {\n theme: props.theme,\n locale: props.locale,\n paymentMethods: props.paymentMethods,\n defaultPaymentMethod: props.defaultPaymentMethod,\n showPaymentButtons: props.showPaymentButtons,\n nuPayConfig: props.nuPayConfig,\n });\n }\n };\n const eventHandler = (event: MessageEvent) => {\n if (event.data?.type) {\n log(\"←\", event.data.type, event.data.data ?? \"\");\n }\n handleMessageEvent(\n event,\n pendingMap,\n (val) => {\n setIsReady(val);\n frame.isReady = val;\n if (window.PayConductor?.frame)\n window.PayConductor.frame.isReady = val;\n if (val) sendConfigToIframe();\n },\n (val) => {\n setError(val);\n frame.error = val;\n if (window.PayConductor?.frame) window.PayConductor.frame.error = val;\n },\n () => {\n props.onReady?.();\n },\n (err) => {\n props.onError?.(err);\n },\n (data) => {\n props.onPaymentComplete?.(data as PaymentResult);\n },\n (data) => {\n props.onPaymentFailed?.(data as PaymentResult);\n },\n (data) => {\n props.onPaymentPending?.(data as PaymentResult);\n },\n (method) => {\n setSelectedPaymentMethod(method);\n if (window.PayConductor)\n window.PayConductor.selectedPaymentMethod = method;\n props.onPaymentMethodSelected?.(method);\n }\n );\n };\n window.addEventListener(\"message\", eventHandler);\n const trySendConfig = () => {\n const el = getIframe();\n if (!el) return false;\n try {\n const readyState =\n el.contentDocument?.readyState ??\n el.contentWindow?.document?.readyState;\n if (readyState === \"complete\") {\n sendConfigToIframe();\n return true;\n }\n } catch {}\n return false;\n };\n const pollForIframe = () => {\n if (trySendConfig()) return;\n const el = getIframe();\n if (el) {\n el.addEventListener(\"load\", () => sendConfigToIframe(), {\n once: true,\n });\n return;\n }\n setTimeout(pollForIframe, 50);\n };\n pollForIframe();\n }, []);\n\n return (\n <div\n className=\"payconductor\"\n id=\"payconductor\"\n style={{\n display: \"contents\",\n }}\n >\n {props.children}\n </div>\n );\n}\n\nexport default PayConductor;\n","\"use client\";\nimport * as React from \"react\";\nimport { useState, useRef, useEffect } from \"react\";\n\nexport interface PayConductorCheckoutElementProps {\n height?: string;\n}\n\nimport { IFRAME_DEFAULT_HEIGHT_VALUE } from \"./constants\";\n\nfunction PayConductorCheckoutElement(props: PayConductorCheckoutElementProps) {\n const iframeRef = useRef<any>(null);\n const [iframeUrl, setIframeUrl] = useState(() => \"\");\n\n const [isLoaded, setIsLoaded] = useState(() => false);\n\n useEffect(() => {\n const init = (ctx: typeof window.PayConductor) => {\n if (!ctx?.frame) return;\n setIframeUrl(ctx.frame.iframeUrl || \"\");\n setIsLoaded(true);\n if (window.PayConductor && window.PayConductor.frame)\n window.PayConductor.frame.isReady = true;\n console.log(\"init\", {\n PayConductor: window.PayConductor,\n });\n };\n const ctx = typeof window !== \"undefined\" ? window.PayConductor : null;\n if (ctx) {\n init(ctx);\n } else {\n const handler = (e: Event) => {\n init((e as CustomEvent).detail);\n window.removeEventListener(\"payconductor:registered\", handler);\n };\n window.addEventListener(\"payconductor:registered\", handler);\n }\n }, []);\n\n return (\n <div\n className=\"payconductor-element\"\n style={{\n width: \"100%\",\n }}\n >\n {isLoaded && iframeUrl ? (\n <iframe\n allow=\"payment\"\n title=\"PayConductor\"\n ref={iframeRef}\n src={iframeUrl}\n style={{\n width: \"100%\",\n height: props.height || IFRAME_DEFAULT_HEIGHT_VALUE,\n border: \"none\",\n }}\n />\n ) : null}\n </div>\n );\n}\n\nexport default PayConductorCheckoutElement;\n","import type { PayConductorConfig } from \"../iframe/types\";\nimport type { PayConductorFrame } from \"../types\";\ntype UsePayConductorReturn = PayConductorFrame & Partial<PayConductorConfig>;\nexport function usePayConductor(): UsePayConductorReturn {\n const ctx = typeof window !== \"undefined\" ? window.PayConductor : null;\n const config = ctx?.config ? {\n publicKey: ctx.config.publicKey,\n orderId: ctx.config.orderId,\n theme: ctx.config.theme,\n locale: ctx.config.locale\n } : {};\n const frame = ctx?.frame ? {\n iframe: ctx.frame.iframe,\n isReady: ctx.frame.isReady,\n error: ctx.frame.error\n } : {\n iframe: null,\n isReady: false,\n error: null\n };\n return {\n ...config,\n ...frame\n };\n}","import { POST_MESSAGES } from \"../constants\";\nimport type { BillingDetails, PayConductorConfig, PaymentMethod, PaymentResult } from \"../iframe/types\";\nimport { confirmPayment, createPendingRequestsMap, sendInit, sendMessageToIframe } from \"../internal\";\nexport type SubmitResult = {\n error?: {\n message: string;\n code?: string;\n type?: \"validation_error\" | \"payment_error\";\n };\n paymentMethod?: PaymentMethod;\n};\nexport type ConfirmPaymentOptions = {\n orderId: string;\n returnUrl?: string;\n};\nexport type UpdateOptions = {\n billingDetails?: Partial<BillingDetails>;\n address?: Partial<BillingDetails[\"address\"]>;\n};\nexport interface UsePayconductorElementReturn {\n init: (config: PayConductorConfig) => Promise<void>;\n confirmPayment: (options: ConfirmPaymentOptions) => Promise<PaymentResult>;\n validate: (data: unknown) => Promise<boolean>;\n reset: () => Promise<void>;\n getSelectedPaymentMethod: () => PaymentMethod | null;\n updateConfig: (config: Partial<Pick<PayConductorConfig, \"theme\" | \"locale\" | \"paymentMethods\">>) => void;\n updateorderId: (orderId: string) => void;\n update: (options: UpdateOptions) => void;\n submit: () => Promise<SubmitResult>;\n}\nfunction getIframeFromContext(ctx: typeof window.PayConductor): HTMLIFrameElement | null {\n if (ctx?.frame?.iframe) {\n const iframeRef = ctx.frame.iframe;\n if (iframeRef instanceof HTMLIFrameElement) return iframeRef;\n if (iframeRef && typeof iframeRef === \"object\") {\n if (\"current\" in iframeRef) {\n const el = (iframeRef as any).current;\n if (el instanceof HTMLIFrameElement) return el;\n }\n if (\"value\" in iframeRef) {\n const el = (iframeRef as any).value;\n if (el instanceof HTMLIFrameElement) return el;\n }\n }\n }\n return document.querySelector(\".payconductor-element iframe\") as HTMLIFrameElement ?? null;\n}\nexport function usePayconductorElement(): UsePayconductorElementReturn {\n const getCtx = () => typeof window !== \"undefined\" ? window.PayConductor : null;\n const sendToIframe = (type: string, data?: unknown) => {\n const ctx = getCtx();\n if (!ctx) return;\n const iframe = getIframeFromContext(ctx);\n if (iframe?.contentWindow) {\n iframe.contentWindow.postMessage({\n type,\n data\n }, \"*\");\n }\n };\n return {\n init: async (config: PayConductorConfig): Promise<void> => {\n const iframe = getIframeFromContext(getCtx());\n const pendingMap = createPendingRequestsMap();\n return sendInit(iframe || undefined, pendingMap, config);\n },\n confirmPayment: async (options: ConfirmPaymentOptions): Promise<PaymentResult> => {\n const iframe = getIframeFromContext(getCtx());\n const pendingMap = createPendingRequestsMap();\n if (!options.orderId) {\n throw new Error(\"Order ID is required\");\n }\n return confirmPayment(iframe || undefined, pendingMap, options);\n },\n validate: (data: unknown) => {\n const ctx = getCtx();\n if (!ctx) return Promise.resolve(false);\n return ctx.api.validate(data);\n },\n reset: () => {\n const ctx = getCtx();\n if (!ctx) return Promise.resolve();\n return ctx.api.reset();\n },\n getSelectedPaymentMethod: (): PaymentMethod | null => {\n return getCtx()?.selectedPaymentMethod ?? null;\n },\n updateConfig: (config: Partial<Pick<PayConductorConfig, \"theme\" | \"locale\" | \"paymentMethods\">>) => {\n const currentConfig = getCtx()?.config;\n sendToIframe(POST_MESSAGES.CONFIG, {\n publicKey: currentConfig?.publicKey,\n orderId: currentConfig?.orderId,\n theme: config.theme ?? currentConfig?.theme,\n locale: config.locale ?? currentConfig?.locale,\n paymentMethods: config.paymentMethods ?? currentConfig?.paymentMethods\n });\n },\n updateorderId: (orderId: string) => {\n const currentConfig = getCtx()?.config;\n sendToIframe(POST_MESSAGES.CONFIG, {\n publicKey: currentConfig?.publicKey,\n orderId: orderId,\n theme: currentConfig?.theme,\n locale: currentConfig?.locale,\n paymentMethods: currentConfig?.paymentMethods\n });\n },\n update: (options: UpdateOptions) => {\n sendToIframe(POST_MESSAGES.UPDATE, options);\n },\n submit: async (): Promise<SubmitResult> => {\n const iframe = getIframeFromContext(getCtx());\n const pendingMap = createPendingRequestsMap();\n try {\n await sendMessageToIframe(iframe || undefined, pendingMap, POST_MESSAGES.CONFIRM_PAYMENT, {});\n return {\n paymentMethod: undefined\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : \"Payment failed\";\n return {\n error: {\n message,\n code: \"payment_error\",\n type: \"payment_error\"\n }\n };\n }\n }\n };\n}"],"names":["IFRAME_BASE_URL_PROD","IFRAME_BASE_URL_DEV","REQUEST_TIMEOUT_MS","IFRAME_DEFAULT_HEIGHT","OutgoingMessage","IncomingMessage","isDev","IFRAME_BASE_URL","ALLOWED_ORIGINS","IFRAME_DEFAULT_HEIGHT_VALUE","REQUEST_TIMEOUT","POST_MESSAGES","ERROR_CODES","buildIframeUrl","config","params","generateRequestId","isValidOrigin","origin","allowedOrigins","allowed","createPendingRequestsMap","sendMessageToIframe","iframe","pendingMap","type","data","resolve","reject","requestId","confirmPayment","options","validatePayment","resetPayment","sendConfig","sendInit","handleMessageEvent","event","setIsReady","setError","onReady","onError","onPaymentComplete","onPaymentFailed","onPaymentPending","onPaymentMethodSelected","payload","error","PayConductor","props","isLoaded","setIsLoaded","useState","isReady","iframeUrl","setIframeUrl","selectedPaymentMethod","setSelectedPaymentMethod","useEffect","log","args","configSent","getIframe","ref","_b","_a","obj","frame","_","api","sendConfigToIframe","eventHandler","val","err","method","trySendConfig","el","_c","pollForIframe","jsx","PayConductorCheckoutElement","iframeRef","useRef","init","ctx","handler","e","usePayConductor","getIframeFromContext","usePayconductorElement","getCtx","sendToIframe","currentConfig","orderId"],"mappings":";;AAMO,MAAMA,IAAuB,qCACvBC,IAAsB,4BAGtBC,IAAqB,KACrBC,IAAwB;AC4B9B,IAAKC,sBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,SAAS,UACTA,EAAA,SAAS,UACTA,EAAA,iBAAiB,kBACjBA,EAAA,WAAW,YACXA,EAAA,QAAQ,SANEA,IAAAA,KAAA,CAAA,CAAA,GAQAC,sBAAAA,OACVA,EAAA,Q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';
|
|
2
|
+
|
|
3
|
+
export declare const IFRAME_BASE_URL: string;
|
|
4
|
+
export declare const ALLOWED_ORIGINS: string[];
|
|
5
|
+
export declare const IFRAME_DEFAULT_HEIGHT_VALUE = "600px";
|
|
6
|
+
export declare const REQUEST_TIMEOUT = 30000;
|
|
7
|
+
export declare const POST_MESSAGES: {
|
|
8
|
+
readonly INIT: OutgoingMessage.Init;
|
|
9
|
+
readonly CONFIG: OutgoingMessage.Config;
|
|
10
|
+
readonly UPDATE: OutgoingMessage.Update;
|
|
11
|
+
readonly CONFIRM_PAYMENT: OutgoingMessage.ConfirmPayment;
|
|
12
|
+
readonly VALIDATE: OutgoingMessage.Validate;
|
|
13
|
+
readonly RESET: OutgoingMessage.Reset;
|
|
14
|
+
readonly READY: IncomingMessage.Ready;
|
|
15
|
+
readonly ERROR: IncomingMessage.Error;
|
|
16
|
+
readonly PAYMENT_COMPLETE: IncomingMessage.PaymentComplete;
|
|
17
|
+
readonly PAYMENT_FAILED: IncomingMessage.PaymentFailed;
|
|
18
|
+
readonly PAYMENT_PENDING: IncomingMessage.PaymentPending;
|
|
19
|
+
readonly VALIDATION_ERROR: IncomingMessage.ValidationError;
|
|
20
|
+
readonly PAYMENT_METHOD_SELECTED: IncomingMessage.PaymentMethodSelected;
|
|
21
|
+
};
|
|
22
|
+
export declare const ERROR_CODES: {
|
|
23
|
+
readonly INVALID_CLIENT: "InvalidClient";
|
|
24
|
+
readonly INVALID_TOKEN: "InvalidToken";
|
|
25
|
+
readonly NETWORK_ERROR: "NetworkError";
|
|
26
|
+
readonly IFRAME_NOT_READY: "IframeNotReady";
|
|
27
|
+
readonly PAYMENT_DECLINED: "PaymentDeclined";
|
|
28
|
+
readonly VALIDATION_ERROR: "ValidationError";
|
|
29
|
+
readonly TIMEOUT: "Timeout";
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BillingDetails, PayConductorConfig, PaymentMethod, PaymentResult } from '../iframe/types';
|
|
2
|
+
|
|
3
|
+
export type SubmitResult = {
|
|
4
|
+
error?: {
|
|
5
|
+
message: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
type?: "validation_error" | "payment_error";
|
|
8
|
+
};
|
|
9
|
+
paymentMethod?: PaymentMethod;
|
|
10
|
+
};
|
|
11
|
+
export type ConfirmPaymentOptions = {
|
|
12
|
+
orderId: string;
|
|
13
|
+
returnUrl?: string;
|
|
14
|
+
};
|
|
15
|
+
export type UpdateOptions = {
|
|
16
|
+
billingDetails?: Partial<BillingDetails>;
|
|
17
|
+
address?: Partial<BillingDetails["address"]>;
|
|
18
|
+
};
|
|
19
|
+
export interface UsePayconductorElementReturn {
|
|
20
|
+
init: (config: PayConductorConfig) => Promise<void>;
|
|
21
|
+
confirmPayment: (options: ConfirmPaymentOptions) => Promise<PaymentResult>;
|
|
22
|
+
validate: (data: unknown) => Promise<boolean>;
|
|
23
|
+
reset: () => Promise<void>;
|
|
24
|
+
getSelectedPaymentMethod: () => PaymentMethod | null;
|
|
25
|
+
updateConfig: (config: Partial<Pick<PayConductorConfig, "theme" | "locale" | "paymentMethods">>) => void;
|
|
26
|
+
updateorderId: (orderId: string) => void;
|
|
27
|
+
update: (options: UpdateOptions) => void;
|
|
28
|
+
submit: () => Promise<SubmitResult>;
|
|
29
|
+
}
|
|
30
|
+
export declare function usePayconductorElement(): UsePayconductorElementReturn;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const APP_BASE_URL_PROD = "https://app.payconductor.ai";
|
|
2
|
+
export declare const API_BASE_URL_PROD = "https://app.payconductor.ai/api/v1";
|
|
3
|
+
export declare const IFRAME_BASE_URL_PROD = "https://iframe.payconductor.ai/v1";
|
|
4
|
+
export declare const IFRAME_BASE_URL_DEV = "http://localhost:5175/v1";
|
|
5
|
+
export declare const APP_BASE_URL_DEV = "http://localhost:3000";
|
|
6
|
+
export declare const DEFAULT_LOCALE = "pt-BR";
|
|
7
|
+
export declare const REQUEST_TIMEOUT_MS = 30000;
|
|
8
|
+
export declare const IFRAME_DEFAULT_HEIGHT = "600px";
|