@inflow_pay/sdk 0.0.1
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/LICENSE +22 -0
- package/README.md +336 -0
- package/dist/react.d.ts +104 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.esm.js +747 -0
- package/dist/react.esm.js.map +1 -0
- package/dist/react.umd.js +92 -0
- package/dist/react.umd.js.map +1 -0
- package/dist/sdk.d.ts +93 -0
- package/dist/sdk.esm.js +459 -0
- package/dist/sdk.esm.js.map +1 -0
- package/dist/sdk.umd.js +87 -0
- package/dist/sdk.umd.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import se, { createContext as ae, useState as H, useContext as J, useRef as K, useEffect as I } from "react";
|
|
2
|
+
var A = { exports: {} }, _ = {};
|
|
3
|
+
var $;
|
|
4
|
+
function le() {
|
|
5
|
+
if ($) return _;
|
|
6
|
+
$ = 1;
|
|
7
|
+
var l = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
8
|
+
function n(r, i, s) {
|
|
9
|
+
var d = null;
|
|
10
|
+
if (s !== void 0 && (d = "" + s), i.key !== void 0 && (d = "" + i.key), "key" in i) {
|
|
11
|
+
s = {};
|
|
12
|
+
for (var h in i)
|
|
13
|
+
h !== "key" && (s[h] = i[h]);
|
|
14
|
+
} else s = i;
|
|
15
|
+
return i = s.ref, {
|
|
16
|
+
$$typeof: l,
|
|
17
|
+
type: r,
|
|
18
|
+
key: d,
|
|
19
|
+
ref: i !== void 0 ? i : null,
|
|
20
|
+
props: s
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return _.Fragment = t, _.jsx = n, _.jsxs = n, _;
|
|
24
|
+
}
|
|
25
|
+
var T = {};
|
|
26
|
+
var W;
|
|
27
|
+
function ce() {
|
|
28
|
+
return W || (W = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
29
|
+
function l(e) {
|
|
30
|
+
if (e == null) return null;
|
|
31
|
+
if (typeof e == "function")
|
|
32
|
+
return e.$$typeof === ne ? null : e.displayName || e.name || null;
|
|
33
|
+
if (typeof e == "string") return e;
|
|
34
|
+
switch (e) {
|
|
35
|
+
case b:
|
|
36
|
+
return "Fragment";
|
|
37
|
+
case v:
|
|
38
|
+
return "Profiler";
|
|
39
|
+
case R:
|
|
40
|
+
return "StrictMode";
|
|
41
|
+
case Q:
|
|
42
|
+
return "Suspense";
|
|
43
|
+
case ee:
|
|
44
|
+
return "SuspenseList";
|
|
45
|
+
case re:
|
|
46
|
+
return "Activity";
|
|
47
|
+
}
|
|
48
|
+
if (typeof e == "object")
|
|
49
|
+
switch (typeof e.tag == "number" && console.error(
|
|
50
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
51
|
+
), e.$$typeof) {
|
|
52
|
+
case y:
|
|
53
|
+
return "Portal";
|
|
54
|
+
case X:
|
|
55
|
+
return e.displayName || "Context";
|
|
56
|
+
case B:
|
|
57
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
58
|
+
case Z:
|
|
59
|
+
var o = e.render;
|
|
60
|
+
return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
61
|
+
case te:
|
|
62
|
+
return o = e.displayName || null, o !== null ? o : l(e.type) || "Memo";
|
|
63
|
+
case P:
|
|
64
|
+
o = e._payload, e = e._init;
|
|
65
|
+
try {
|
|
66
|
+
return l(e(o));
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function t(e) {
|
|
73
|
+
return "" + e;
|
|
74
|
+
}
|
|
75
|
+
function n(e) {
|
|
76
|
+
try {
|
|
77
|
+
t(e);
|
|
78
|
+
var o = !1;
|
|
79
|
+
} catch {
|
|
80
|
+
o = !0;
|
|
81
|
+
}
|
|
82
|
+
if (o) {
|
|
83
|
+
o = console;
|
|
84
|
+
var a = o.error, c = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
85
|
+
return a.call(
|
|
86
|
+
o,
|
|
87
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
|
+
c
|
|
89
|
+
), t(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function r(e) {
|
|
93
|
+
if (e === b) return "<>";
|
|
94
|
+
if (typeof e == "object" && e !== null && e.$$typeof === P)
|
|
95
|
+
return "<...>";
|
|
96
|
+
try {
|
|
97
|
+
var o = l(e);
|
|
98
|
+
return o ? "<" + o + ">" : "<...>";
|
|
99
|
+
} catch {
|
|
100
|
+
return "<...>";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function i() {
|
|
104
|
+
var e = C.A;
|
|
105
|
+
return e === null ? null : e.getOwner();
|
|
106
|
+
}
|
|
107
|
+
function s() {
|
|
108
|
+
return Error("react-stack-top-frame");
|
|
109
|
+
}
|
|
110
|
+
function d(e) {
|
|
111
|
+
if (U.call(e, "key")) {
|
|
112
|
+
var o = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
113
|
+
if (o && o.isReactWarning) return !1;
|
|
114
|
+
}
|
|
115
|
+
return e.key !== void 0;
|
|
116
|
+
}
|
|
117
|
+
function h(e, o) {
|
|
118
|
+
function a() {
|
|
119
|
+
N || (N = !0, console.error(
|
|
120
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
121
|
+
o
|
|
122
|
+
));
|
|
123
|
+
}
|
|
124
|
+
a.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
125
|
+
get: a,
|
|
126
|
+
configurable: !0
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function S() {
|
|
130
|
+
var e = l(this.type);
|
|
131
|
+
return M[e] || (M[e] = !0, console.error(
|
|
132
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
133
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
134
|
+
}
|
|
135
|
+
function E(e, o, a, c, k, D) {
|
|
136
|
+
var u = a.ref;
|
|
137
|
+
return e = {
|
|
138
|
+
$$typeof: w,
|
|
139
|
+
type: e,
|
|
140
|
+
key: o,
|
|
141
|
+
props: a,
|
|
142
|
+
_owner: c
|
|
143
|
+
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
|
|
144
|
+
enumerable: !1,
|
|
145
|
+
get: S
|
|
146
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
147
|
+
configurable: !1,
|
|
148
|
+
enumerable: !1,
|
|
149
|
+
writable: !0,
|
|
150
|
+
value: 0
|
|
151
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
152
|
+
configurable: !1,
|
|
153
|
+
enumerable: !1,
|
|
154
|
+
writable: !0,
|
|
155
|
+
value: null
|
|
156
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
157
|
+
configurable: !1,
|
|
158
|
+
enumerable: !1,
|
|
159
|
+
writable: !0,
|
|
160
|
+
value: k
|
|
161
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
162
|
+
configurable: !1,
|
|
163
|
+
enumerable: !1,
|
|
164
|
+
writable: !0,
|
|
165
|
+
value: D
|
|
166
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
167
|
+
}
|
|
168
|
+
function p(e, o, a, c, k, D) {
|
|
169
|
+
var u = o.children;
|
|
170
|
+
if (u !== void 0)
|
|
171
|
+
if (c)
|
|
172
|
+
if (ie(u)) {
|
|
173
|
+
for (c = 0; c < u.length; c++)
|
|
174
|
+
f(u[c]);
|
|
175
|
+
Object.freeze && Object.freeze(u);
|
|
176
|
+
} else
|
|
177
|
+
console.error(
|
|
178
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
179
|
+
);
|
|
180
|
+
else f(u);
|
|
181
|
+
if (U.call(o, "key")) {
|
|
182
|
+
u = l(e);
|
|
183
|
+
var x = Object.keys(o).filter(function(oe) {
|
|
184
|
+
return oe !== "key";
|
|
185
|
+
});
|
|
186
|
+
c = 0 < x.length ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}", F[u + c] || (x = 0 < x.length ? "{" + x.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
188
|
+
let props = %s;
|
|
189
|
+
<%s {...props} />
|
|
190
|
+
React keys must be passed directly to JSX without using spread:
|
|
191
|
+
let props = %s;
|
|
192
|
+
<%s key={someKey} {...props} />`,
|
|
193
|
+
c,
|
|
194
|
+
u,
|
|
195
|
+
x,
|
|
196
|
+
u
|
|
197
|
+
), F[u + c] = !0);
|
|
198
|
+
}
|
|
199
|
+
if (u = null, a !== void 0 && (n(a), u = "" + a), d(o) && (n(o.key), u = "" + o.key), "key" in o) {
|
|
200
|
+
a = {};
|
|
201
|
+
for (var j in o)
|
|
202
|
+
j !== "key" && (a[j] = o[j]);
|
|
203
|
+
} else a = o;
|
|
204
|
+
return u && h(
|
|
205
|
+
a,
|
|
206
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
207
|
+
), E(
|
|
208
|
+
e,
|
|
209
|
+
u,
|
|
210
|
+
a,
|
|
211
|
+
i(),
|
|
212
|
+
k,
|
|
213
|
+
D
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function f(e) {
|
|
217
|
+
g(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === P && (e._payload.status === "fulfilled" ? g(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
218
|
+
}
|
|
219
|
+
function g(e) {
|
|
220
|
+
return typeof e == "object" && e !== null && e.$$typeof === w;
|
|
221
|
+
}
|
|
222
|
+
var m = se, w = Symbol.for("react.transitional.element"), y = Symbol.for("react.portal"), b = Symbol.for("react.fragment"), R = Symbol.for("react.strict_mode"), v = Symbol.for("react.profiler"), B = Symbol.for("react.consumer"), X = Symbol.for("react.context"), Z = Symbol.for("react.forward_ref"), Q = Symbol.for("react.suspense"), ee = Symbol.for("react.suspense_list"), te = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), re = Symbol.for("react.activity"), ne = Symbol.for("react.client.reference"), C = m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, U = Object.prototype.hasOwnProperty, ie = Array.isArray, O = console.createTask ? console.createTask : function() {
|
|
223
|
+
return null;
|
|
224
|
+
};
|
|
225
|
+
m = {
|
|
226
|
+
react_stack_bottom_frame: function(e) {
|
|
227
|
+
return e();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var N, M = {}, z = m.react_stack_bottom_frame.bind(
|
|
231
|
+
m,
|
|
232
|
+
s
|
|
233
|
+
)(), Y = O(r(s)), F = {};
|
|
234
|
+
T.Fragment = b, T.jsx = function(e, o, a) {
|
|
235
|
+
var c = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
236
|
+
return p(
|
|
237
|
+
e,
|
|
238
|
+
o,
|
|
239
|
+
a,
|
|
240
|
+
!1,
|
|
241
|
+
c ? Error("react-stack-top-frame") : z,
|
|
242
|
+
c ? O(r(e)) : Y
|
|
243
|
+
);
|
|
244
|
+
}, T.jsxs = function(e, o, a) {
|
|
245
|
+
var c = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
246
|
+
return p(
|
|
247
|
+
e,
|
|
248
|
+
o,
|
|
249
|
+
a,
|
|
250
|
+
!0,
|
|
251
|
+
c ? Error("react-stack-top-frame") : z,
|
|
252
|
+
c ? O(r(e)) : Y
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
})()), T;
|
|
256
|
+
}
|
|
257
|
+
var q;
|
|
258
|
+
function ue() {
|
|
259
|
+
return q || (q = 1, process.env.NODE_ENV === "production" ? A.exports = le() : A.exports = ce()), A.exports;
|
|
260
|
+
}
|
|
261
|
+
var V = ue();
|
|
262
|
+
class de {
|
|
263
|
+
constructor(t) {
|
|
264
|
+
if (this.iframe = null, this.messageListener = null, this.containerElement = null, this.config = t, this.iframeUrl = t.iframeUrl || "http://localhost:3000/iframe/checkout", this.environment = this.getEnvironmentFromApiKey(t.apiKey || ""), this.usePopup = !t.container, t.container)
|
|
265
|
+
if (typeof t.container == "string") {
|
|
266
|
+
if (this.containerElement = document.querySelector(t.container), !this.containerElement)
|
|
267
|
+
throw new Error(`Container not found: ${t.container}`);
|
|
268
|
+
} else
|
|
269
|
+
this.containerElement = t.container;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Initialize and open the payment iframe
|
|
273
|
+
*/
|
|
274
|
+
init() {
|
|
275
|
+
this.iframe || (this.createIframe(), this.addMessageListener(), this.sendConfigToIframe());
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Create and append the iframe to the document
|
|
279
|
+
*/
|
|
280
|
+
createIframe() {
|
|
281
|
+
const t = new URL(this.iframeUrl);
|
|
282
|
+
this.config.apiKey && t.searchParams.set("apiKey", this.config.apiKey), this.config.config?.paymentId && t.searchParams.set("paymentId", this.config.config.paymentId);
|
|
283
|
+
const n = t.toString();
|
|
284
|
+
if (this.usePopup) {
|
|
285
|
+
const r = document.createElement("div");
|
|
286
|
+
r.id = "inflowpay-sdk-overlay", r.style.cssText = `
|
|
287
|
+
position: fixed;
|
|
288
|
+
top: 0;
|
|
289
|
+
left: 0;
|
|
290
|
+
width: 100%;
|
|
291
|
+
height: 100%;
|
|
292
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
293
|
+
display: flex;
|
|
294
|
+
align-items: center;
|
|
295
|
+
justify-content: center;
|
|
296
|
+
z-index: 999999;
|
|
297
|
+
`;
|
|
298
|
+
const i = document.createElement("div");
|
|
299
|
+
i.style.cssText = `
|
|
300
|
+
position: relative;
|
|
301
|
+
width: 90%;
|
|
302
|
+
max-width: 500px;
|
|
303
|
+
height: 90%;
|
|
304
|
+
max-height: 600px;
|
|
305
|
+
background: white;
|
|
306
|
+
border-radius: 8px;
|
|
307
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
|
|
308
|
+
`;
|
|
309
|
+
const s = document.createElement("button");
|
|
310
|
+
s.innerHTML = "×", s.style.cssText = `
|
|
311
|
+
position: absolute;
|
|
312
|
+
top: 10px;
|
|
313
|
+
right: 10px;
|
|
314
|
+
width: 30px;
|
|
315
|
+
height: 30px;
|
|
316
|
+
border: none;
|
|
317
|
+
background: transparent;
|
|
318
|
+
font-size: 24px;
|
|
319
|
+
cursor: pointer;
|
|
320
|
+
z-index: 1000000;
|
|
321
|
+
color: #333;
|
|
322
|
+
display: flex;
|
|
323
|
+
align-items: center;
|
|
324
|
+
justify-content: center;
|
|
325
|
+
`, s.onclick = () => this.close(), this.iframe = document.createElement("iframe"), this.iframe.src = n, this.iframe.style.cssText = `
|
|
326
|
+
width: 100%;
|
|
327
|
+
height: 100%;
|
|
328
|
+
border: none;
|
|
329
|
+
border-radius: 8px;
|
|
330
|
+
`, this.iframe.setAttribute("allow", "payment"), i.appendChild(s), i.appendChild(this.iframe), r.appendChild(i), document.body.appendChild(r), r.addEventListener("click", (d) => {
|
|
331
|
+
d.target === r && this.close();
|
|
332
|
+
});
|
|
333
|
+
} else {
|
|
334
|
+
if (!this.containerElement)
|
|
335
|
+
throw new Error("Container element is required for inline mode");
|
|
336
|
+
if (this.containerElement.innerHTML = "", this.containerElement instanceof HTMLElement) {
|
|
337
|
+
const r = this.containerElement.getAttribute("style") || "";
|
|
338
|
+
r.includes("min-height") || (this.containerElement.style.minHeight = "300px"), r.includes("position") || (this.containerElement.style.position = "relative"), r.includes("overflow") || (this.containerElement.style.overflow = "hidden");
|
|
339
|
+
}
|
|
340
|
+
this.iframe = document.createElement("iframe"), this.iframe.src = n, this.iframe.style.cssText = `
|
|
341
|
+
width: 100%;
|
|
342
|
+
height: 100%;
|
|
343
|
+
min-height: 300px;
|
|
344
|
+
border: none;
|
|
345
|
+
display: block;
|
|
346
|
+
`, this.iframe.setAttribute("allow", "payment"), this.containerElement.appendChild(this.iframe);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Add message listener for communication with iframe
|
|
351
|
+
*/
|
|
352
|
+
addMessageListener() {
|
|
353
|
+
this.messageListener = (t) => {
|
|
354
|
+
const n = new URL(this.iframeUrl).origin;
|
|
355
|
+
let i = t.origin === n;
|
|
356
|
+
if (i || ((this.environment === "sandbox" || this.environment === "development") && (i = (t.origin.includes("localhost") || t.origin.includes("127.0.0.1")) && (n.includes("localhost") || n.includes("127.0.0.1"))), i || (i = t.origin === "https://dev.api.inflowpay.com" || t.origin === "https://pre-prod.api.inflowpay.xyz" || t.origin === "https://api.inflowpay.xyz")), !i) {
|
|
357
|
+
this.config.debug && console.warn("[SDK] Rejected message from unauthorized origin:", t.origin);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const s = t.data;
|
|
361
|
+
if (!(!s || !s.type))
|
|
362
|
+
switch (s.type) {
|
|
363
|
+
case "close":
|
|
364
|
+
this.close();
|
|
365
|
+
break;
|
|
366
|
+
case "success":
|
|
367
|
+
this.config.onSuccess && this.config.onSuccess(s.data);
|
|
368
|
+
break;
|
|
369
|
+
case "error":
|
|
370
|
+
this.config.onError && this.config.onError(s.data);
|
|
371
|
+
break;
|
|
372
|
+
case "3ds-required":
|
|
373
|
+
this.config.debug && console.log("[SDK] Received 3DS request:", s.threeDsSessionUrl), s.threeDsSessionUrl ? (this.config.debug && console.log("[SDK] Opening 3DS modal..."), this.open3DSModal(s.threeDsSessionUrl).then((d) => {
|
|
374
|
+
if (this.config.debug && console.log("[SDK] 3DS modal closed, result:", d), this.iframe && this.iframe.contentWindow) {
|
|
375
|
+
const h = this.getTargetOrigin();
|
|
376
|
+
this.iframe.contentWindow.postMessage({
|
|
377
|
+
type: "3ds-result",
|
|
378
|
+
success: d,
|
|
379
|
+
paymentId: s.paymentId || this.config.config?.paymentId
|
|
380
|
+
}, h);
|
|
381
|
+
}
|
|
382
|
+
})) : this.config.debug && console.error("[SDK] 3DS required but no threeDsSessionUrl provided");
|
|
383
|
+
break;
|
|
384
|
+
default:
|
|
385
|
+
this.config.debug && console.log("SDK: Received message:", s);
|
|
386
|
+
}
|
|
387
|
+
}, window.addEventListener("message", this.messageListener);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Send configuration to the iframe
|
|
391
|
+
*/
|
|
392
|
+
sendConfigToIframe() {
|
|
393
|
+
if (!this.iframe || !this.iframe.contentWindow) {
|
|
394
|
+
this.iframe && (this.iframe.onload = () => {
|
|
395
|
+
this.sendConfigToIframe();
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const t = {
|
|
400
|
+
type: "sdkData",
|
|
401
|
+
config: {
|
|
402
|
+
...this.config.config || {},
|
|
403
|
+
paymentId: this.config.config?.paymentId
|
|
404
|
+
},
|
|
405
|
+
data: {
|
|
406
|
+
apiKey: this.config.apiKey
|
|
407
|
+
}
|
|
408
|
+
}, n = this.getTargetOrigin();
|
|
409
|
+
this.iframe.contentWindow.postMessage(t, n);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Close the iframe and cleanup
|
|
413
|
+
*/
|
|
414
|
+
close() {
|
|
415
|
+
if (this.config.onClose && this.config.onClose(), this.messageListener && (window.removeEventListener("message", this.messageListener), this.messageListener = null), this.usePopup) {
|
|
416
|
+
const t = document.getElementById("inflowpay-sdk-overlay");
|
|
417
|
+
t && t.remove();
|
|
418
|
+
} else
|
|
419
|
+
this.containerElement && this.iframe && this.containerElement.removeChild(this.iframe);
|
|
420
|
+
this.iframe = null;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Open 3DS authentication modal
|
|
424
|
+
* Called when iframe requests 3DS authentication
|
|
425
|
+
*/
|
|
426
|
+
open3DSModal(t) {
|
|
427
|
+
return this.config.debug && console.log("[SDK] open3DSModal called with URL:", t), new Promise((n) => {
|
|
428
|
+
const r = document.createElement("div");
|
|
429
|
+
r.id = "inflowpay-3ds-overlay", r.style.cssText = `
|
|
430
|
+
position: fixed;
|
|
431
|
+
top: 0;
|
|
432
|
+
left: 0;
|
|
433
|
+
width: 100%;
|
|
434
|
+
height: 100%;
|
|
435
|
+
background-color: rgba(0, 0, 0, 0.7);
|
|
436
|
+
display: flex;
|
|
437
|
+
align-items: center;
|
|
438
|
+
justify-content: center;
|
|
439
|
+
z-index: 999999;
|
|
440
|
+
`;
|
|
441
|
+
const i = document.createElement("div");
|
|
442
|
+
i.style.cssText = `
|
|
443
|
+
position: relative;
|
|
444
|
+
width: 90%;
|
|
445
|
+
max-width: 500px;
|
|
446
|
+
height: 90%;
|
|
447
|
+
max-height: 600px;
|
|
448
|
+
background: white;
|
|
449
|
+
border-radius: 8px;
|
|
450
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
|
|
451
|
+
display: flex;
|
|
452
|
+
flex-direction: column;
|
|
453
|
+
`;
|
|
454
|
+
const s = document.createElement("div");
|
|
455
|
+
s.style.cssText = `
|
|
456
|
+
display: flex;
|
|
457
|
+
align-items: center;
|
|
458
|
+
justify-content: space-between;
|
|
459
|
+
padding: 15px 20px;
|
|
460
|
+
border-bottom: 1px solid #e5e5e5;
|
|
461
|
+
`, s.innerHTML = `
|
|
462
|
+
<h3 style="margin: 0; font-size: 18px; font-weight: 600;">Secure Payment Authentication</h3>
|
|
463
|
+
<button id="inflowpay-3ds-close" style="background: none; border: none; font-size: 24px; cursor: pointer; padding: 0; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: #333;">×</button>
|
|
464
|
+
`;
|
|
465
|
+
const d = document.createElement("div");
|
|
466
|
+
d.style.cssText = `
|
|
467
|
+
flex: 1;
|
|
468
|
+
position: relative;
|
|
469
|
+
overflow: hidden;
|
|
470
|
+
`;
|
|
471
|
+
const h = document.createElement("iframe");
|
|
472
|
+
h.src = t, h.style.cssText = `
|
|
473
|
+
width: 100%;
|
|
474
|
+
height: 100%;
|
|
475
|
+
border: none;
|
|
476
|
+
`, h.setAttribute("allow", "payment"), h.setAttribute("sandbox", "allow-forms allow-scripts allow-same-origin allow-popups"), d.appendChild(h), i.appendChild(s), i.appendChild(d), r.appendChild(i), document.body.appendChild(r);
|
|
477
|
+
const S = r.querySelector("#inflowpay-3ds-close"), E = () => {
|
|
478
|
+
r.remove(), window.removeEventListener("message", p), n(!1);
|
|
479
|
+
};
|
|
480
|
+
S?.addEventListener("click", E);
|
|
481
|
+
const p = (f) => {
|
|
482
|
+
if (!f.data) return;
|
|
483
|
+
const g = [
|
|
484
|
+
"https://dev.api.inflowpay.com",
|
|
485
|
+
"https://pre-prod.api.inflowpay.xyz",
|
|
486
|
+
"https://api.inflowpay.xyz"
|
|
487
|
+
];
|
|
488
|
+
if (this.environment === "sandbox" || this.environment === "development") {
|
|
489
|
+
if (!(f.origin.includes("localhost") || f.origin.includes("127.0.0.1"))) {
|
|
490
|
+
if (!g.includes(f.origin)) {
|
|
491
|
+
this.config.debug && console.warn("[SDK] Rejected 3DS message from unauthorized origin:", f.origin);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
} else if (!g.includes(f.origin)) {
|
|
496
|
+
this.config.debug && console.warn("[SDK] Rejected 3DS message from unauthorized origin:", f.origin);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const m = f.data, w = m.type === "THREE_DS_COMPLETE" || m.type === "3ds-complete", y = m.status === "success", b = m.status === "failed" || m.status === "failure";
|
|
500
|
+
if (w && y) {
|
|
501
|
+
r.remove(), window.removeEventListener("message", p), n(!0);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (y && !w) {
|
|
505
|
+
r.remove(), window.removeEventListener("message", p), n(!0);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (w && b || m.type === "3ds-failed" || b) {
|
|
509
|
+
r.remove(), window.removeEventListener("message", p), n(!1);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
window.addEventListener("message", p);
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Get target origin for postMessage based on environment
|
|
518
|
+
* In production/pre-prod: use exact origin for security
|
|
519
|
+
* In dev/sandbox: use wildcard for development flexibility
|
|
520
|
+
*/
|
|
521
|
+
getTargetOrigin() {
|
|
522
|
+
return this.environment === "production" || this.environment === "preprod" ? new URL(this.iframeUrl).origin : "*";
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Detect environment from API key
|
|
526
|
+
*/
|
|
527
|
+
getEnvironmentFromApiKey(t) {
|
|
528
|
+
return !t || t.includes("_local_") || t.startsWith("inflow_local_") ? "sandbox" : t.includes("_prod_") && !t.includes("_preprod_") ? "production" : t.includes("_preprod_") || t.startsWith("inflow_preprod_") ? "preprod" : t.includes("_dev_") ? "development" : "sandbox";
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Public method to close the iframe
|
|
532
|
+
*/
|
|
533
|
+
destroy() {
|
|
534
|
+
this.close();
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
let fe = class {
|
|
538
|
+
constructor(t, n) {
|
|
539
|
+
this.mounted = !1;
|
|
540
|
+
let r;
|
|
541
|
+
if (typeof n.container == "string") {
|
|
542
|
+
if (r = document.querySelector(n.container), !r)
|
|
543
|
+
throw new Error(`Container not found: ${n.container}`);
|
|
544
|
+
} else
|
|
545
|
+
r = n.container;
|
|
546
|
+
this.container = r, this.sdk = new de({
|
|
547
|
+
iframeUrl: t.iframeUrl,
|
|
548
|
+
apiKey: t.apiKey,
|
|
549
|
+
container: this.container,
|
|
550
|
+
config: {
|
|
551
|
+
paymentId: n.paymentId
|
|
552
|
+
},
|
|
553
|
+
onSuccess: (i) => {
|
|
554
|
+
n.onComplete && n.onComplete({
|
|
555
|
+
status: i?.data?.transaction?.status || "CHECKOUT_SUCCESS",
|
|
556
|
+
data: i
|
|
557
|
+
});
|
|
558
|
+
},
|
|
559
|
+
onError: (i) => {
|
|
560
|
+
n.onError ? n.onError(i) : n.onComplete && n.onComplete({
|
|
561
|
+
status: "PAYMENT_FAILED",
|
|
562
|
+
error: i
|
|
563
|
+
});
|
|
564
|
+
},
|
|
565
|
+
onClose: () => {
|
|
566
|
+
n.onClose && n.onClose();
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Mount the CardElement to the DOM
|
|
572
|
+
* This will create and display the iframe
|
|
573
|
+
*/
|
|
574
|
+
mount() {
|
|
575
|
+
if (this.mounted)
|
|
576
|
+
throw new Error("CardElement is already mounted");
|
|
577
|
+
this.sdk.init(), this.mounted = !0;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Destroy the CardElement and cleanup
|
|
581
|
+
*/
|
|
582
|
+
destroy() {
|
|
583
|
+
this.mounted && (this.sdk.destroy(), this.mounted = !1);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
class G {
|
|
587
|
+
/**
|
|
588
|
+
* Initialize the InflowPay Payment SDK
|
|
589
|
+
*
|
|
590
|
+
* @param config - SDK configuration
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* ```typescript
|
|
594
|
+
* const sdk = new PaymentSDK({
|
|
595
|
+
* apiKey: 'inflow_pub_local_xxx'
|
|
596
|
+
* });
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
constructor(t) {
|
|
600
|
+
if (!t.apiKey || typeof t.apiKey != "string")
|
|
601
|
+
throw new Error("API key is required");
|
|
602
|
+
let n = t.iframeUrl;
|
|
603
|
+
const r = this.getEnvironmentFromApiKey(t.apiKey);
|
|
604
|
+
n || (r === "production" ? n = "https://api.inflowpay.xyz/iframe/checkout" : r === "preprod" ? n = "https://pre-prod.api.inflowpay.xyz/iframe/checkout" : r === "development" ? n = "https://dev.api.inflowpay.com/iframe/checkout" : n = "http://localhost:3000/iframe/checkout");
|
|
605
|
+
const i = t.debug ?? !1;
|
|
606
|
+
i && (r === "production" || r === "preprod") && console.warn("[InflowPay SDK] Debug mode is not allowed in production/pre-prod environments. Debug mode disabled.");
|
|
607
|
+
const s = i && (r === "sandbox" || r === "development");
|
|
608
|
+
this.config = {
|
|
609
|
+
apiKey: t.apiKey,
|
|
610
|
+
iframeUrl: n,
|
|
611
|
+
timeout: t.timeout ?? 3e4,
|
|
612
|
+
debug: s
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Create a CardElement for iframe-based payment UI
|
|
617
|
+
*
|
|
618
|
+
* @param options - CardElement configuration
|
|
619
|
+
* @returns CardElement instance
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* const cardElement = sdk.createCardElement({
|
|
624
|
+
* container: '#card-container',
|
|
625
|
+
* paymentId: 'pay_123',
|
|
626
|
+
* onComplete: (result) => {
|
|
627
|
+
* if (result.status === 'CHECKOUT_SUCCESS') {
|
|
628
|
+
* window.location.href = '/success';
|
|
629
|
+
* }
|
|
630
|
+
* }
|
|
631
|
+
* });
|
|
632
|
+
*
|
|
633
|
+
* cardElement.mount();
|
|
634
|
+
* ```
|
|
635
|
+
*/
|
|
636
|
+
createCardElement(t) {
|
|
637
|
+
return new fe(this.config, t);
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Get the iframe URL being used
|
|
641
|
+
*/
|
|
642
|
+
getIframeUrl() {
|
|
643
|
+
return this.config.iframeUrl;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Get the API key
|
|
647
|
+
*/
|
|
648
|
+
getApiKey() {
|
|
649
|
+
return this.config.apiKey;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Auto-detect environment from API key
|
|
653
|
+
*/
|
|
654
|
+
getEnvironmentFromApiKey(t) {
|
|
655
|
+
return t.includes("_local_") || t.startsWith("inflow_local_") ? "sandbox" : t.includes("_prod_") && !t.includes("_preprod_") ? "production" : t.includes("_preprod_") || t.startsWith("inflow_preprod_") ? "preprod" : t.includes("_dev_") ? "development" : "sandbox";
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const L = ae(null);
|
|
659
|
+
function pe({
|
|
660
|
+
config: l,
|
|
661
|
+
children: t
|
|
662
|
+
}) {
|
|
663
|
+
const [n] = H(() => {
|
|
664
|
+
const r = {
|
|
665
|
+
apiKey: l.apiKey,
|
|
666
|
+
iframeUrl: l.iframeUrl,
|
|
667
|
+
timeout: l.timeout,
|
|
668
|
+
debug: l.debug
|
|
669
|
+
};
|
|
670
|
+
return new G(r);
|
|
671
|
+
});
|
|
672
|
+
return /* @__PURE__ */ V.jsx(L.Provider, { value: { sdk: n }, children: t });
|
|
673
|
+
}
|
|
674
|
+
function ge() {
|
|
675
|
+
const l = J(L);
|
|
676
|
+
if (!l)
|
|
677
|
+
throw new Error("useInflowPay must be used within InflowPayProvider");
|
|
678
|
+
return l.sdk;
|
|
679
|
+
}
|
|
680
|
+
function Ee({
|
|
681
|
+
paymentId: l,
|
|
682
|
+
onReady: t,
|
|
683
|
+
onChange: n,
|
|
684
|
+
onComplete: r,
|
|
685
|
+
onError: i,
|
|
686
|
+
buttonText: s,
|
|
687
|
+
buttonStyle: d,
|
|
688
|
+
style: h,
|
|
689
|
+
placeholders: S,
|
|
690
|
+
config: E
|
|
691
|
+
}) {
|
|
692
|
+
const p = J(L), f = K(null), g = K(null), [m, w] = H(!1), y = p?.sdk || (E ? new G({
|
|
693
|
+
apiKey: E.apiKey,
|
|
694
|
+
iframeUrl: E.iframeUrl,
|
|
695
|
+
timeout: E.timeout,
|
|
696
|
+
debug: E.debug
|
|
697
|
+
}) : null);
|
|
698
|
+
if (!y)
|
|
699
|
+
throw new Error("CardElement must be used within InflowPayProvider or have a config prop");
|
|
700
|
+
return I(() => {
|
|
701
|
+
if (!f.current || m)
|
|
702
|
+
return;
|
|
703
|
+
f.current.id || (f.current.id = `inflowpay-card-element-${Date.now()}`);
|
|
704
|
+
const b = {
|
|
705
|
+
container: f.current,
|
|
706
|
+
paymentId: l,
|
|
707
|
+
onComplete: (v) => {
|
|
708
|
+
r && r(v);
|
|
709
|
+
},
|
|
710
|
+
onError: (v) => {
|
|
711
|
+
i ? i(v) : r && r({
|
|
712
|
+
status: "PAYMENT_FAILED",
|
|
713
|
+
error: v
|
|
714
|
+
});
|
|
715
|
+
},
|
|
716
|
+
onClose: () => {
|
|
717
|
+
}
|
|
718
|
+
}, R = y.createCardElement(b);
|
|
719
|
+
if (g.current = R, R.mount(), w(!0), t) {
|
|
720
|
+
const v = setTimeout(() => {
|
|
721
|
+
t();
|
|
722
|
+
}, 100);
|
|
723
|
+
return () => clearTimeout(v);
|
|
724
|
+
}
|
|
725
|
+
}, [l, y, m, r, i, t]), I(() => {
|
|
726
|
+
n && m && n({ complete: !1 });
|
|
727
|
+
}, [m, n]), I(() => () => {
|
|
728
|
+
g.current && (g.current.destroy(), g.current = null);
|
|
729
|
+
}, []), /* @__PURE__ */ V.jsx(
|
|
730
|
+
"div",
|
|
731
|
+
{
|
|
732
|
+
ref: f,
|
|
733
|
+
style: {
|
|
734
|
+
width: "100%",
|
|
735
|
+
minHeight: "300px",
|
|
736
|
+
position: "relative",
|
|
737
|
+
...h
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
export {
|
|
743
|
+
Ee as CardElement,
|
|
744
|
+
pe as InflowPayProvider,
|
|
745
|
+
ge as useInflowPay
|
|
746
|
+
};
|
|
747
|
+
//# sourceMappingURL=react.esm.js.map
|