@inflow_pay/sdk 1.1.0 → 1.2.0-beta.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 +111 -15
- package/dist/payment-sdk-DhJS0NRo.js +169 -0
- package/dist/payment-sdk-DhJS0NRo.js.map +1 -0
- package/dist/payment-sdk-DqfuWSo1.mjs +661 -0
- package/dist/payment-sdk-DqfuWSo1.mjs.map +1 -0
- package/dist/react/index.d.ts +52 -19
- package/dist/react.cjs +1 -2
- package/dist/react.esm.js +2 -11
- package/dist/react.umd.js +57 -73
- package/dist/react.umd.js.map +1 -1
- package/dist/sdk.cjs +2 -2
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.d.ts +50 -18
- package/dist/sdk.esm.js +48 -65
- package/dist/sdk.esm.js.map +1 -1
- package/dist/sdk.umd.js +56 -88
- package/dist/sdk.umd.js.map +1 -1
- package/package.json +7 -2
- package/dist/payment-sdk-CC-mm-nt.js +0 -169
- package/dist/payment-sdk-CC-mm-nt.js.map +0 -1
- package/dist/payment-sdk-oRqgQSx5.mjs +0 -821
- package/dist/payment-sdk-oRqgQSx5.mjs.map +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.esm.js.map +0 -1
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
import { createContext as e, useContext as t, useEffect as n, useRef as r, useState as i } from "react";
|
|
2
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
3
|
+
//#region src/types.ts
|
|
4
|
+
var o = /* @__PURE__ */ function(e) {
|
|
5
|
+
return e.SUCCESS = "SUCCESS", e.FAILED = "FAILED", e;
|
|
6
|
+
}({}), s = /* @__PURE__ */ function(e) {
|
|
7
|
+
return e.THREE_DS_FAILED = "THREE_DS_FAILED", e.PAYMENT_PROCESSING_ERROR = "PAYMENT_PROCESSING_ERROR", e;
|
|
8
|
+
}({}), c = e(null);
|
|
9
|
+
function l({ config: e, children: t }) {
|
|
10
|
+
let [n] = i(() => new Z({
|
|
11
|
+
publicKey: e.publicKey,
|
|
12
|
+
locale: e.locale
|
|
13
|
+
}));
|
|
14
|
+
return /* @__PURE__ */ a(c.Provider, {
|
|
15
|
+
value: { sdk: n },
|
|
16
|
+
children: t
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function u() {
|
|
20
|
+
let e = t(c);
|
|
21
|
+
if (!e) throw Error("useInflowPay must be used within InflowPayProvider");
|
|
22
|
+
return e.sdk;
|
|
23
|
+
}
|
|
24
|
+
function d(e) {
|
|
25
|
+
let { paymentId: s, setupId: l, onReady: u, onChange: d, onComplete: f, onError: p, style: m, buttonText: h, placeholders: g, showDefaultSuccessUI: _, config: v } = e, y = t(c), b = r(null), x = r(null), [S, C] = i(!1), w = y?.sdk || (v ? new Z({
|
|
26
|
+
publicKey: v.publicKey,
|
|
27
|
+
locale: v.locale
|
|
28
|
+
}) : null);
|
|
29
|
+
if (!w) throw Error("CardElement must be used within InflowPayProvider or have a config prop");
|
|
30
|
+
return n(() => {
|
|
31
|
+
if (!b.current) return;
|
|
32
|
+
b.current.id || (b.current.id = `inflowpay-card-element-${Date.now()}`);
|
|
33
|
+
let e = {
|
|
34
|
+
container: b.current,
|
|
35
|
+
...s && { paymentId: s },
|
|
36
|
+
...l && { setupId: l },
|
|
37
|
+
...m && { style: m },
|
|
38
|
+
...h && { buttonText: h },
|
|
39
|
+
...g && { placeholders: g },
|
|
40
|
+
..._ !== void 0 && { showDefaultSuccessUI: _ },
|
|
41
|
+
onComplete: (e) => {
|
|
42
|
+
f && f(e);
|
|
43
|
+
},
|
|
44
|
+
onError: (e) => {
|
|
45
|
+
p ? p(e) : f && f(l ? {
|
|
46
|
+
status: o.FAILED,
|
|
47
|
+
setupId: l,
|
|
48
|
+
error: e
|
|
49
|
+
} : {
|
|
50
|
+
status: o.FAILED,
|
|
51
|
+
paymentId: s,
|
|
52
|
+
error: e
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
onClose: () => {}
|
|
56
|
+
}, t = w.createCardElement(e);
|
|
57
|
+
if (x.current = t, t.mount(), C(!0), u) {
|
|
58
|
+
let e = setTimeout(() => {
|
|
59
|
+
u();
|
|
60
|
+
}, 100);
|
|
61
|
+
return () => clearTimeout(e);
|
|
62
|
+
}
|
|
63
|
+
}, [
|
|
64
|
+
s,
|
|
65
|
+
l,
|
|
66
|
+
w,
|
|
67
|
+
f,
|
|
68
|
+
p,
|
|
69
|
+
u,
|
|
70
|
+
m,
|
|
71
|
+
h,
|
|
72
|
+
g,
|
|
73
|
+
_
|
|
74
|
+
]), n(() => {
|
|
75
|
+
d && S && d({ complete: !1 });
|
|
76
|
+
}, [S, d]), n(() => () => {
|
|
77
|
+
x.current && (x.current.destroy(), x.current = null);
|
|
78
|
+
}, []), /* @__PURE__ */ a("div", {
|
|
79
|
+
ref: b,
|
|
80
|
+
style: { width: m?.fillParent ? "100%" : "344px" }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/constants/sdk-constants.ts
|
|
85
|
+
var f = {
|
|
86
|
+
OVERLAY: 999999,
|
|
87
|
+
MODAL: 1e6,
|
|
88
|
+
LOADER: 1e3
|
|
89
|
+
}, p = {
|
|
90
|
+
MIN_HEIGHT: 196,
|
|
91
|
+
CONTAINER_MAX_WIDTH: "500px",
|
|
92
|
+
CONTAINER_WIDTH_PERCENT: "90%",
|
|
93
|
+
CONTAINER_HEIGHT_PERCENT: "90%",
|
|
94
|
+
CONTAINER_MAX_HEIGHT: "600px",
|
|
95
|
+
BUTTON_SIZE: 30,
|
|
96
|
+
DEFAULT_IFRAME_WIDTH: "344px"
|
|
97
|
+
}, m = [
|
|
98
|
+
"https://dev.api.inflowpay.xyz",
|
|
99
|
+
"https://pre-prod.api.inflowpay.xyz",
|
|
100
|
+
"https://api.inflowpay.xyz"
|
|
101
|
+
], h = {
|
|
102
|
+
OVERLAY: "inflowpay-sdk-overlay",
|
|
103
|
+
LOADER: "inflowpay-loader",
|
|
104
|
+
LOADER_STYLES: "inflowpay-loader-styles",
|
|
105
|
+
THREE_DS_OVERLAY: "inflowpay-3ds-overlay",
|
|
106
|
+
THREE_DS_CLOSE: "inflowpay-3ds-close"
|
|
107
|
+
}, g = {
|
|
108
|
+
PRODUCTION: "https://iframe.inflowpay.com/iframe/checkout",
|
|
109
|
+
PREPROD: "https://preprod.iframe.inflowpay.com/iframe/checkout",
|
|
110
|
+
DEVELOPMENT: "https://dev.iframe.inflowpay.com/iframe/checkout",
|
|
111
|
+
LOCAL: "http://localhost:3010/iframe/checkout"
|
|
112
|
+
};
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/ui/styles.ts
|
|
115
|
+
function _(e) {
|
|
116
|
+
return {
|
|
117
|
+
inputBgColor: e ? "#2d2d2d" : "#F5F5F5",
|
|
118
|
+
shimmerBase: e ? "#3d3d3d" : "#E5E5E5",
|
|
119
|
+
shimmerLight: e ? "#4d4d4d" : "#F0F0F0"
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function v(e) {
|
|
123
|
+
return `linear-gradient(90deg, ${e.shimmerBase} 25%, ${e.shimmerLight} 50%, ${e.shimmerBase} 75%)`;
|
|
124
|
+
}
|
|
125
|
+
function y() {
|
|
126
|
+
return `
|
|
127
|
+
position: fixed;
|
|
128
|
+
top: 0;
|
|
129
|
+
left: 0;
|
|
130
|
+
width: 100%;
|
|
131
|
+
height: 100%;
|
|
132
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
133
|
+
display: flex;
|
|
134
|
+
align-items: center;
|
|
135
|
+
justify-content: center;
|
|
136
|
+
z-index: ${f.OVERLAY};
|
|
137
|
+
`;
|
|
138
|
+
}
|
|
139
|
+
function b() {
|
|
140
|
+
return `
|
|
141
|
+
position: relative;
|
|
142
|
+
width: ${p.CONTAINER_WIDTH_PERCENT};
|
|
143
|
+
max-width: ${p.CONTAINER_MAX_WIDTH};
|
|
144
|
+
height: ${p.CONTAINER_HEIGHT_PERCENT};
|
|
145
|
+
max-height: ${p.CONTAINER_MAX_HEIGHT};
|
|
146
|
+
background: white;
|
|
147
|
+
border-radius: 8px;
|
|
148
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
151
|
+
function x() {
|
|
152
|
+
return `
|
|
153
|
+
position: absolute;
|
|
154
|
+
top: 10px;
|
|
155
|
+
right: 10px;
|
|
156
|
+
width: ${p.BUTTON_SIZE}px;
|
|
157
|
+
height: ${p.BUTTON_SIZE}px;
|
|
158
|
+
border: none;
|
|
159
|
+
background: transparent;
|
|
160
|
+
font-size: 24px;
|
|
161
|
+
cursor: pointer;
|
|
162
|
+
z-index: ${f.MODAL};
|
|
163
|
+
color: #333;
|
|
164
|
+
display: flex;
|
|
165
|
+
align-items: center;
|
|
166
|
+
justify-content: center;
|
|
167
|
+
`;
|
|
168
|
+
}
|
|
169
|
+
function S() {
|
|
170
|
+
return "\n width: 100%;\n height: 100%;\n border: none;\n border-radius: 8px;\n ";
|
|
171
|
+
}
|
|
172
|
+
function C(e) {
|
|
173
|
+
return `
|
|
174
|
+
width: ${e ? "100%" : p.DEFAULT_IFRAME_WIDTH};
|
|
175
|
+
max-width: ${e ? "none" : "100%"};
|
|
176
|
+
height: ${p.MIN_HEIGHT}px;
|
|
177
|
+
min-height: ${p.MIN_HEIGHT}px;
|
|
178
|
+
border: none;
|
|
179
|
+
display: block;
|
|
180
|
+
transition: height 0.2s ease;
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
function w() {
|
|
184
|
+
return `
|
|
185
|
+
position: absolute;
|
|
186
|
+
top: 0;
|
|
187
|
+
left: 0;
|
|
188
|
+
width: 100%;
|
|
189
|
+
height: 100%;
|
|
190
|
+
z-index: ${f.LOADER};
|
|
191
|
+
padding: 20px;
|
|
192
|
+
box-sizing: border-box;
|
|
193
|
+
display: flex;
|
|
194
|
+
flex-direction: column;
|
|
195
|
+
align-items: center;
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
function T(e) {
|
|
199
|
+
return `
|
|
200
|
+
width: ${e ? "100%" : p.DEFAULT_IFRAME_WIDTH};
|
|
201
|
+
max-width: 100%;
|
|
202
|
+
margin: 0 auto;
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
function E(e) {
|
|
206
|
+
return `
|
|
207
|
+
display: flex;
|
|
208
|
+
align-items: center;
|
|
209
|
+
justify-content: center;
|
|
210
|
+
gap: 6px;
|
|
211
|
+
background-color: ${e};
|
|
212
|
+
padding: 8px;
|
|
213
|
+
border-radius: 8px;
|
|
214
|
+
margin-bottom: 20px;
|
|
215
|
+
`;
|
|
216
|
+
}
|
|
217
|
+
function D(e) {
|
|
218
|
+
return `
|
|
219
|
+
background: ${e};
|
|
220
|
+
background-size: 200% 100%;
|
|
221
|
+
animation: inflowpay-shimmer 1.5s infinite;
|
|
222
|
+
`;
|
|
223
|
+
}
|
|
224
|
+
function O(e) {
|
|
225
|
+
return `
|
|
226
|
+
flex: 1;
|
|
227
|
+
min-width: 0;
|
|
228
|
+
height: 32px;
|
|
229
|
+
border-radius: 6px;
|
|
230
|
+
${D(e)}
|
|
231
|
+
`;
|
|
232
|
+
}
|
|
233
|
+
function k(e) {
|
|
234
|
+
return `
|
|
235
|
+
width: 21.5%;
|
|
236
|
+
flex-shrink: 0;
|
|
237
|
+
height: 32px;
|
|
238
|
+
border-radius: 6px;
|
|
239
|
+
${D(e)}
|
|
240
|
+
`;
|
|
241
|
+
}
|
|
242
|
+
function A(e) {
|
|
243
|
+
return `
|
|
244
|
+
width: 17.5%;
|
|
245
|
+
flex-shrink: 0;
|
|
246
|
+
height: 32px;
|
|
247
|
+
border-radius: 6px;
|
|
248
|
+
${D(e)}
|
|
249
|
+
`;
|
|
250
|
+
}
|
|
251
|
+
function j(e) {
|
|
252
|
+
return `
|
|
253
|
+
width: 100%;
|
|
254
|
+
height: 42px;
|
|
255
|
+
border-radius: 8px;
|
|
256
|
+
${D(e)}
|
|
257
|
+
margin-bottom: 16px;
|
|
258
|
+
`;
|
|
259
|
+
}
|
|
260
|
+
function M() {
|
|
261
|
+
return "\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 4px;\n width: 100%;\n margin-top: 16px;\n ";
|
|
262
|
+
}
|
|
263
|
+
function N(e) {
|
|
264
|
+
return `
|
|
265
|
+
width: 10px;
|
|
266
|
+
height: 10px;
|
|
267
|
+
border-radius: 50%;
|
|
268
|
+
${D(e)}
|
|
269
|
+
`;
|
|
270
|
+
}
|
|
271
|
+
function P(e) {
|
|
272
|
+
return `
|
|
273
|
+
width: 80%;
|
|
274
|
+
height: 16px;
|
|
275
|
+
border-radius: 4px;
|
|
276
|
+
${D(e)}
|
|
277
|
+
`;
|
|
278
|
+
}
|
|
279
|
+
var F = "\n @keyframes inflowpay-shimmer {\n 0% {\n background-position: -200% 0;\n }\n 100% {\n background-position: 200% 0;\n }\n }\n";
|
|
280
|
+
function I() {
|
|
281
|
+
return `
|
|
282
|
+
position: fixed;
|
|
283
|
+
top: 0;
|
|
284
|
+
left: 0;
|
|
285
|
+
width: 100%;
|
|
286
|
+
height: 100%;
|
|
287
|
+
background-color: rgba(0, 0, 0, 0.7);
|
|
288
|
+
display: flex;
|
|
289
|
+
align-items: center;
|
|
290
|
+
justify-content: center;
|
|
291
|
+
z-index: ${f.OVERLAY};
|
|
292
|
+
`;
|
|
293
|
+
}
|
|
294
|
+
function L() {
|
|
295
|
+
return `
|
|
296
|
+
position: relative;
|
|
297
|
+
width: ${p.CONTAINER_WIDTH_PERCENT};
|
|
298
|
+
max-width: ${p.CONTAINER_MAX_WIDTH};
|
|
299
|
+
height: ${p.CONTAINER_HEIGHT_PERCENT};
|
|
300
|
+
max-height: ${p.CONTAINER_MAX_HEIGHT};
|
|
301
|
+
background: white;
|
|
302
|
+
border-radius: 16px;
|
|
303
|
+
overflow: hidden;
|
|
304
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
|
|
305
|
+
display: flex;
|
|
306
|
+
flex-direction: column;
|
|
307
|
+
`;
|
|
308
|
+
}
|
|
309
|
+
function R() {
|
|
310
|
+
return "\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 15px 20px;\n border-bottom: 1px solid #e5e5e5;\n ";
|
|
311
|
+
}
|
|
312
|
+
function z() {
|
|
313
|
+
return "\n flex: 1;\n position: relative;\n overflow-y: auto;\n overflow-x: hidden;\n ";
|
|
314
|
+
}
|
|
315
|
+
function B() {
|
|
316
|
+
return "\n width: 100%;\n height: 100%;\n border: none;\n ";
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/ui/loader-manager.ts
|
|
320
|
+
var V = class {
|
|
321
|
+
constructor(e, t = {}) {
|
|
322
|
+
this.loaderElement = null, this.container = e, this.config = t;
|
|
323
|
+
}
|
|
324
|
+
show(e) {
|
|
325
|
+
e && (e.style.display = "none");
|
|
326
|
+
let t = _(window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches), n = v(t), r = document.createElement("div");
|
|
327
|
+
r.id = h.LOADER, r.style.cssText = w();
|
|
328
|
+
let i = document.createElement("div");
|
|
329
|
+
i.style.cssText = T(this.config.fillParent || !1);
|
|
330
|
+
let a = document.createElement("div");
|
|
331
|
+
a.style.cssText = E(t.inputBgColor);
|
|
332
|
+
let o = document.createElement("div");
|
|
333
|
+
o.className = "inflowpay-skeleton", o.style.cssText = O(n);
|
|
334
|
+
let s = document.createElement("div");
|
|
335
|
+
s.className = "inflowpay-skeleton", s.style.cssText = k(n);
|
|
336
|
+
let c = document.createElement("div");
|
|
337
|
+
c.className = "inflowpay-skeleton", c.style.cssText = A(n), a.appendChild(o), a.appendChild(s), a.appendChild(c);
|
|
338
|
+
let l = document.createElement("div");
|
|
339
|
+
l.className = "inflowpay-skeleton", l.style.cssText = j(n);
|
|
340
|
+
let u = document.createElement("div");
|
|
341
|
+
u.style.cssText = M();
|
|
342
|
+
let d = document.createElement("div");
|
|
343
|
+
d.className = "inflowpay-skeleton", d.style.cssText = N(n);
|
|
344
|
+
let f = document.createElement("div");
|
|
345
|
+
f.className = "inflowpay-skeleton", f.style.cssText = P(n), u.appendChild(d), u.appendChild(f), i.appendChild(a), i.appendChild(l), i.appendChild(u), r.appendChild(i), this.injectShimmerStyles(), this.container.appendChild(r), this.loaderElement = r;
|
|
346
|
+
}
|
|
347
|
+
hide(e) {
|
|
348
|
+
let t = document.getElementById(h.LOADER);
|
|
349
|
+
t && t.remove(), this.loaderElement = null, e && (e.style.display = "");
|
|
350
|
+
}
|
|
351
|
+
injectShimmerStyles() {
|
|
352
|
+
if (!document.getElementById(h.LOADER_STYLES)) {
|
|
353
|
+
let e = document.createElement("style");
|
|
354
|
+
e.id = h.LOADER_STYLES, e.textContent = F, document.head.appendChild(e);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}, H, U = class e {
|
|
358
|
+
constructor(e) {
|
|
359
|
+
this.config = e;
|
|
360
|
+
}
|
|
361
|
+
open(t, n, r) {
|
|
362
|
+
return this.config.debug && (console.log("[SDK] open3DSModal called with URL:", t), console.log("[SDK] Session ID:", n, "Payment ID:", r)), e.activeModal && (console.warn("[SDK] Closing existing modal before opening new one"), e.activeModal.overlay.remove(), e.activeModal = null), new Promise((i) => {
|
|
363
|
+
let a = document.createElement("div");
|
|
364
|
+
a.id = h.THREE_DS_OVERLAY, a.style.cssText = I();
|
|
365
|
+
let o = document.createElement("div");
|
|
366
|
+
o.style.cssText = L();
|
|
367
|
+
let s = document.createElement("div");
|
|
368
|
+
s.style.cssText = R(), s.innerHTML = "\n <h3 style=\"margin: 0; font-size: 18px; font-weight: 600;\">Secure Payment Authentication</h3>\n ";
|
|
369
|
+
let c = document.createElement("div");
|
|
370
|
+
c.style.cssText = z();
|
|
371
|
+
let l = document.createElement("iframe");
|
|
372
|
+
l.src = t, l.style.cssText = B(), l.setAttribute("allow", "payment"), l.setAttribute("sandbox", "allow-forms allow-scripts allow-same-origin allow-popups"), c.appendChild(l), o.appendChild(s), o.appendChild(c), a.appendChild(o), document.body.appendChild(a), e.activeModal = {
|
|
373
|
+
overlay: a,
|
|
374
|
+
sessionId: n,
|
|
375
|
+
paymentId: r
|
|
376
|
+
};
|
|
377
|
+
let u = (e) => {
|
|
378
|
+
if (!e.data) return;
|
|
379
|
+
if (!this.isAllowedOrigin(e.origin)) {
|
|
380
|
+
this.config.debug && console.warn("[SDK] Rejected 3DS message from unauthorized origin:", e.origin);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
let t = e.data, n = t.type === "THREE_DS_COMPLETE" || t.type === "3ds-complete", r = t.status === "success", o = t.status === "failed" || t.status === "failure";
|
|
384
|
+
if (n && r) {
|
|
385
|
+
a.remove(), window.removeEventListener("message", u), i(!0);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (r && !n) {
|
|
389
|
+
a.remove(), window.removeEventListener("message", u), i(!0);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (n && o || t.type === "3ds-failed" || o) {
|
|
393
|
+
a.remove(), window.removeEventListener("message", u), i(!1);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
window.addEventListener("message", u);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
static close(t) {
|
|
401
|
+
if (!e.activeModal) {
|
|
402
|
+
console.log("[SDK] No active modal to close");
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (t && e.activeModal.sessionId !== t) {
|
|
406
|
+
console.warn(`[SDK] Session ID mismatch: webhook for ${t}, but modal is for ${e.activeModal.sessionId}. Ignoring close request.`);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
console.log("[SDK] Closing modal for session:", t || e.activeModal.sessionId), e.activeModal.overlay.remove(), e.activeModal = null;
|
|
410
|
+
}
|
|
411
|
+
static isModalOpen() {
|
|
412
|
+
return e.activeModal !== null;
|
|
413
|
+
}
|
|
414
|
+
static getCurrentSessionId() {
|
|
415
|
+
return e.activeModal?.sessionId || null;
|
|
416
|
+
}
|
|
417
|
+
isAllowedOrigin(e) {
|
|
418
|
+
return !!(m.includes(e) || (this.config.environment === "sandbox" || this.config.environment === "development") && (e.includes("localhost") || e.includes("127.0.0.1")));
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
H = U, H.activeModal = null;
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/ui/overlay-manager.ts
|
|
424
|
+
var W = class {
|
|
425
|
+
static createOverlay(e, t) {
|
|
426
|
+
let n = document.createElement("div");
|
|
427
|
+
n.id = h.OVERLAY, n.style.cssText = y();
|
|
428
|
+
let r = document.createElement("div");
|
|
429
|
+
r.style.cssText = b();
|
|
430
|
+
let i = document.createElement("button");
|
|
431
|
+
i.innerHTML = "×", i.style.cssText = x(), i.onclick = t;
|
|
432
|
+
let a = document.createElement("iframe");
|
|
433
|
+
return a.src = e, a.style.cssText = S(), a.setAttribute("allow", "payment"), r.appendChild(i), r.appendChild(a), n.appendChild(r), n.addEventListener("click", (e) => {
|
|
434
|
+
e.target === n && t();
|
|
435
|
+
}), {
|
|
436
|
+
overlay: n,
|
|
437
|
+
container: r,
|
|
438
|
+
iframe: a
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
static removeOverlay() {
|
|
442
|
+
let e = document.getElementById(h.OVERLAY);
|
|
443
|
+
e && e.remove();
|
|
444
|
+
}
|
|
445
|
+
}, G = [
|
|
446
|
+
"en",
|
|
447
|
+
"de",
|
|
448
|
+
"es",
|
|
449
|
+
"fr",
|
|
450
|
+
"it",
|
|
451
|
+
"nl",
|
|
452
|
+
"pl",
|
|
453
|
+
"pt"
|
|
454
|
+
];
|
|
455
|
+
function K() {
|
|
456
|
+
if (typeof window > "u") return "en";
|
|
457
|
+
try {
|
|
458
|
+
let e = (navigator.language || navigator.userLanguage || "").split("-")[0].toLowerCase();
|
|
459
|
+
if (G.includes(e)) return e;
|
|
460
|
+
} catch {}
|
|
461
|
+
return "en";
|
|
462
|
+
}
|
|
463
|
+
function q(e) {
|
|
464
|
+
return e.includes("_local_") || e.startsWith("inflow_local_") ? "sandbox" : e.includes("_prod_") && !e.includes("_preprod_") ? "production" : e.includes("_preprod_") || e.startsWith("inflow_preprod_") ? "preprod" : e.includes("_dev_") ? "development" : "sandbox";
|
|
465
|
+
}
|
|
466
|
+
function J(e) {
|
|
467
|
+
switch (q(e)) {
|
|
468
|
+
case "production": return g.PRODUCTION;
|
|
469
|
+
case "preprod": return g.PREPROD;
|
|
470
|
+
case "development": return g.DEVELOPMENT;
|
|
471
|
+
default: return g.LOCAL;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/sdk.ts
|
|
476
|
+
var Y = class {
|
|
477
|
+
constructor(e) {
|
|
478
|
+
if (this.iframe = null, this.messageListener = null, this.containerElement = null, this.loaderManager = null, this.config = e, this.iframeUrl = e.iframeUrl || J(e.publicKey || ""), this.environment = q(e.publicKey || ""), this.usePopup = !e.container, e.container) if (typeof e.container == "string") {
|
|
479
|
+
if (this.containerElement = document.querySelector(e.container), !this.containerElement) throw Error(`Container not found: ${e.container}`);
|
|
480
|
+
} else this.containerElement = e.container;
|
|
481
|
+
this.modalManager = new U({
|
|
482
|
+
environment: this.environment,
|
|
483
|
+
debug: this.config.debug
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
init() {
|
|
487
|
+
this.iframe || (this.createIframe(), this.addMessageListener());
|
|
488
|
+
}
|
|
489
|
+
createIframe() {
|
|
490
|
+
let e = new URL(this.iframeUrl);
|
|
491
|
+
this.config.publicKey && e.searchParams.set("publicKey", this.config.publicKey), this.config.config?.paymentId && e.searchParams.set("paymentId", this.config.config.paymentId), this.config.config?.setupId && e.searchParams.set("setupId", this.config.config.setupId), this.config.locale && e.searchParams.set("locale", this.config.locale);
|
|
492
|
+
let t = e.toString();
|
|
493
|
+
if (this.usePopup) {
|
|
494
|
+
let { overlay: e, container: n, iframe: r } = W.createOverlay(t, () => this.close());
|
|
495
|
+
this.iframe = r, document.body.appendChild(e), this.loaderManager = new V(n, { fillParent: this.config.config?.style?.fillParent }), this.loaderManager.show(this.iframe);
|
|
496
|
+
} else {
|
|
497
|
+
if (!this.containerElement) throw Error("Container element is required for inline mode");
|
|
498
|
+
if (this.containerElement.innerHTML = "", this.containerElement instanceof HTMLElement) {
|
|
499
|
+
let e = this.containerElement.getAttribute("style") || "";
|
|
500
|
+
e.includes("min-height") || (this.containerElement.style.minHeight = `${p.MIN_HEIGHT}px`), e.includes("position") || (this.containerElement.style.position = "relative"), e.includes("overflow") || (this.containerElement.style.overflow = "hidden");
|
|
501
|
+
}
|
|
502
|
+
this.iframe = document.createElement("iframe"), this.iframe.src = t, this.iframe.style.cssText = C(this.config.config?.style?.fillParent || !1), this.iframe.setAttribute("allow", "payment"), this.containerElement.appendChild(this.iframe), this.loaderManager = new V(this.containerElement, { fillParent: this.config.config?.style?.fillParent }), this.loaderManager.show(this.iframe);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
addMessageListener() {
|
|
506
|
+
this.messageListener = (e) => {
|
|
507
|
+
let t = new URL(this.iframeUrl).origin, n = e.origin === t;
|
|
508
|
+
if (n || ((this.environment === "sandbox" || this.environment === "development") && (n = (e.origin.includes("localhost") || e.origin.includes("127.0.0.1")) && (t.includes("localhost") || t.includes("127.0.0.1"))), n || (n = e.origin === "https://dev.iframe.inflowpay.com" || e.origin === "https://pre-prod.iframe.inflowpay.xyz" || e.origin === "https://iframe.inflowpay.xyz")), !n) {
|
|
509
|
+
this.config.debug && console.warn("[SDK] Rejected message from unauthorized origin:", e.origin);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
let r = e.data;
|
|
513
|
+
if (!(!r || !r.type)) switch (r.type) {
|
|
514
|
+
case "iframe-ready":
|
|
515
|
+
this.loaderManager && this.loaderManager.hide(this.iframe || void 0), this.sendConfigToIframe();
|
|
516
|
+
break;
|
|
517
|
+
case "content-height":
|
|
518
|
+
r.height && this.iframe && (this.iframe.style.height = `${r.height}px`, this.containerElement && (this.containerElement.style.minHeight = `${r.height}px`));
|
|
519
|
+
break;
|
|
520
|
+
case "close":
|
|
521
|
+
this.close();
|
|
522
|
+
break;
|
|
523
|
+
case "success":
|
|
524
|
+
this.config.onSuccess && this.config.onSuccess(r.data);
|
|
525
|
+
break;
|
|
526
|
+
case "error":
|
|
527
|
+
this.config.onError && this.config.onError(r.data);
|
|
528
|
+
break;
|
|
529
|
+
case "3ds-required":
|
|
530
|
+
if (this.config.debug && (console.log("[SDK] Received 3DS request:", r.threeDsSessionUrl), console.log("[SDK] Session ID:", r.sessionId)), r.threeDsSessionUrl) {
|
|
531
|
+
let e = r.sessionId, t = r.paymentId || r.setupId || this.config.config?.paymentId || this.config.config?.setupId || "";
|
|
532
|
+
r.sessionId || console.warn("[SDK] No session ID provided by iframe"), this.config.debug && console.log("[SDK] Opening 3DS modal with session ID:", e), this.modalManager.open(r.threeDsSessionUrl, e, t).then((e) => {
|
|
533
|
+
this.config.debug && console.log("[SDK] 3DS modal closed, result:", e);
|
|
534
|
+
});
|
|
535
|
+
} else this.config.debug && console.error("[SDK] 3DS required but no threeDsSessionUrl provided");
|
|
536
|
+
break;
|
|
537
|
+
case "3ds-success":
|
|
538
|
+
this.config.debug && (console.log("[SDK] 3DS completed, closing modal..."), console.log("[SDK] Session ID from webhook:", r.sessionId)), U.close(r.sessionId);
|
|
539
|
+
break;
|
|
540
|
+
case "3ds-failed":
|
|
541
|
+
this.config.debug && (console.log("[SDK] 3DS failed, closing modal..."), console.log("[SDK] Session ID from webhook:", r.sessionId)), U.close(r.sessionId);
|
|
542
|
+
break;
|
|
543
|
+
default: this.config.debug && console.log("SDK: Received message:", r);
|
|
544
|
+
}
|
|
545
|
+
}, window.addEventListener("message", this.messageListener);
|
|
546
|
+
}
|
|
547
|
+
sendConfigToIframe() {
|
|
548
|
+
if (!this.iframe || !this.iframe.contentWindow) {
|
|
549
|
+
this.iframe && (this.iframe.onload = () => {
|
|
550
|
+
this.sendConfigToIframe();
|
|
551
|
+
});
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
let e = {
|
|
555
|
+
type: "sdkData",
|
|
556
|
+
config: {
|
|
557
|
+
...this.config.config || {},
|
|
558
|
+
paymentId: this.config.config?.paymentId,
|
|
559
|
+
setupId: this.config.config?.setupId
|
|
560
|
+
},
|
|
561
|
+
data: { publicKey: this.config.publicKey }
|
|
562
|
+
}, t = this.getTargetOrigin();
|
|
563
|
+
this.iframe.contentWindow.postMessage(e, t);
|
|
564
|
+
}
|
|
565
|
+
close() {
|
|
566
|
+
this.config.onClose && this.config.onClose(), this.loaderManager && (this.loaderManager.hide(this.iframe || void 0), this.loaderManager = null), this.messageListener && (window.removeEventListener("message", this.messageListener), this.messageListener = null), this.usePopup ? W.removeOverlay() : this.containerElement && (this.containerElement.innerHTML = ""), this.iframe = null;
|
|
567
|
+
}
|
|
568
|
+
switchToSuccessState(e) {
|
|
569
|
+
if (this.loaderManager && (this.loaderManager.hide(this.iframe || void 0), this.loaderManager = null), this.usePopup) {
|
|
570
|
+
this.messageListener && (window.removeEventListener("message", this.messageListener), this.messageListener = null), W.removeOverlay(), this.iframe = null;
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
!(this.config.config?.showDefaultSuccessUI ?? !0) && this.containerElement && (this.containerElement.innerHTML = "", this.iframe = null);
|
|
574
|
+
}
|
|
575
|
+
getTargetOrigin() {
|
|
576
|
+
return this.environment === "production" || this.environment === "preprod" ? new URL(this.iframeUrl).origin : "*";
|
|
577
|
+
}
|
|
578
|
+
destroy() {
|
|
579
|
+
this.close();
|
|
580
|
+
}
|
|
581
|
+
}, X = class {
|
|
582
|
+
constructor(e, t) {
|
|
583
|
+
if (this.mounted = !1, !t.paymentId && !t.setupId) throw Error("CardElement: paymentId or setupId is required");
|
|
584
|
+
if (t.paymentId && t.setupId) throw Error("CardElement: paymentId and setupId are mutually exclusive");
|
|
585
|
+
let n;
|
|
586
|
+
if (typeof t.container == "string") {
|
|
587
|
+
if (n = document.querySelector(t.container), !n) throw Error(`Container not found: ${t.container}`);
|
|
588
|
+
} else n = t.container;
|
|
589
|
+
this.container = n;
|
|
590
|
+
let r = !!t.setupId;
|
|
591
|
+
this.sdk = new Y({
|
|
592
|
+
publicKey: e.publicKey,
|
|
593
|
+
container: this.container,
|
|
594
|
+
locale: e.locale ?? K(),
|
|
595
|
+
config: {
|
|
596
|
+
...t.paymentId && { paymentId: t.paymentId },
|
|
597
|
+
...t.setupId && { setupId: t.setupId },
|
|
598
|
+
...t.style && { style: t.style },
|
|
599
|
+
...t.buttonText && { buttonText: t.buttonText },
|
|
600
|
+
...t.placeholders && { placeholders: t.placeholders },
|
|
601
|
+
...t.showDefaultSuccessUI !== void 0 && { showDefaultSuccessUI: t.showDefaultSuccessUI }
|
|
602
|
+
},
|
|
603
|
+
onSuccess: (e) => {
|
|
604
|
+
t.onComplete && (r ? t.onComplete({
|
|
605
|
+
status: o.SUCCESS,
|
|
606
|
+
setupId: t.setupId
|
|
607
|
+
}) : t.onComplete({
|
|
608
|
+
status: o.SUCCESS,
|
|
609
|
+
paymentId: t.paymentId
|
|
610
|
+
})), this.sdk.switchToSuccessState(e);
|
|
611
|
+
},
|
|
612
|
+
onError: (e) => {
|
|
613
|
+
t.onError ? t.onError(e) : t.onComplete && (r ? t.onComplete({
|
|
614
|
+
status: o.FAILED,
|
|
615
|
+
setupId: t.setupId,
|
|
616
|
+
error: e
|
|
617
|
+
}) : t.onComplete({
|
|
618
|
+
status: o.FAILED,
|
|
619
|
+
paymentId: t.paymentId,
|
|
620
|
+
error: e
|
|
621
|
+
}));
|
|
622
|
+
},
|
|
623
|
+
onClose: () => {
|
|
624
|
+
t.onClose && t.onClose();
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
mount() {
|
|
629
|
+
if (this.mounted) throw Error("CardElement is already mounted");
|
|
630
|
+
this.sdk.init(), this.mounted = !0;
|
|
631
|
+
}
|
|
632
|
+
destroy() {
|
|
633
|
+
this.mounted && (this.sdk.destroy(), this.mounted = !1);
|
|
634
|
+
}
|
|
635
|
+
}, Z = class {
|
|
636
|
+
constructor(e) {
|
|
637
|
+
if (!e.publicKey || typeof e.publicKey != "string") throw Error("API key is required");
|
|
638
|
+
this.config = e, this.timeout = 3e4, this.iframeUrl = J(e.publicKey);
|
|
639
|
+
let t = q(e.publicKey);
|
|
640
|
+
this.debug = t === "sandbox" || t === "development";
|
|
641
|
+
}
|
|
642
|
+
createCardElement(e) {
|
|
643
|
+
return new X({
|
|
644
|
+
publicKey: this.config.publicKey,
|
|
645
|
+
iframeUrl: this.iframeUrl,
|
|
646
|
+
timeout: this.timeout,
|
|
647
|
+
debug: this.debug,
|
|
648
|
+
locale: this.config.locale
|
|
649
|
+
}, e);
|
|
650
|
+
}
|
|
651
|
+
getIframeUrl() {
|
|
652
|
+
return this.iframeUrl;
|
|
653
|
+
}
|
|
654
|
+
getApiKey() {
|
|
655
|
+
return this.config.publicKey;
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
//#endregion
|
|
659
|
+
export { u as a, l as i, X as n, s as o, d as r, o as s, Z as t };
|
|
660
|
+
|
|
661
|
+
//# sourceMappingURL=payment-sdk-DqfuWSo1.mjs.map
|