@flash-pay/browser-sdk 0.1.0 → 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/dist/flashpay.cjs.js +106 -2
- package/dist/flashpay.cjs.js.map +1 -1
- package/dist/{index.d.ts → flashpay.d.mts} +10 -5
- package/dist/flashpay.d.ts +43 -0
- package/dist/flashpay.es.js +64 -33
- package/dist/flashpay.es.js.map +1 -1
- package/dist/flashpay.umd.js +108 -2
- package/dist/flashpay.umd.js.map +1 -1
- package/package.json +7 -8
- package/dist/index.test.d.ts +0 -1
package/dist/flashpay.cjs.js
CHANGED
|
@@ -1,2 +1,106 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
checkout: () => checkout
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
var DEFAULT_ORIGIN = "https://pay.flashpayweb.com";
|
|
27
|
+
var DEFAULT_STYLE = {
|
|
28
|
+
width: "100%",
|
|
29
|
+
height: "600px",
|
|
30
|
+
border: "none",
|
|
31
|
+
borderRadius: "8px"
|
|
32
|
+
};
|
|
33
|
+
function detectOrigin() {
|
|
34
|
+
if (typeof document === "undefined") return DEFAULT_ORIGIN;
|
|
35
|
+
const scripts = document.getElementsByTagName("script");
|
|
36
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
37
|
+
const src = scripts[i].src || "";
|
|
38
|
+
if (src.indexOf("/sdk/flashpay") !== -1 || src.indexOf("flashpay.umd.js") !== -1) {
|
|
39
|
+
try {
|
|
40
|
+
const url = new URL(src);
|
|
41
|
+
return url.origin;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return DEFAULT_ORIGIN;
|
|
47
|
+
}
|
|
48
|
+
function checkout(options) {
|
|
49
|
+
if (!options || !options.transactionId) {
|
|
50
|
+
throw new Error("Flashpay: transactionId is required");
|
|
51
|
+
}
|
|
52
|
+
if (!options.container) {
|
|
53
|
+
throw new Error("Flashpay: container is required");
|
|
54
|
+
}
|
|
55
|
+
const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container;
|
|
56
|
+
if (!container) {
|
|
57
|
+
const identifier = typeof options.container === "string" ? options.container : "the provided HTMLElement";
|
|
58
|
+
throw new Error(`Flashpay: container element not found for ${identifier}`);
|
|
59
|
+
}
|
|
60
|
+
const style = Object.assign({}, DEFAULT_STYLE, options.style || {});
|
|
61
|
+
const origin = options.origin || detectOrigin();
|
|
62
|
+
const iframe = document.createElement("iframe");
|
|
63
|
+
const url = new URL(origin + "/pay/" + encodeURIComponent(options.transactionId));
|
|
64
|
+
if (options.showTitle === false) url.searchParams.set("showTitle", "false");
|
|
65
|
+
if (options.showDescription === false) url.searchParams.set("showDescription", "false");
|
|
66
|
+
if (options.showAmount === false) url.searchParams.set("showAmount", "false");
|
|
67
|
+
url.searchParams.set("parentOrigin", window.location.origin);
|
|
68
|
+
iframe.src = url.toString();
|
|
69
|
+
iframe.title = "Flashpay payment";
|
|
70
|
+
iframe.setAttribute("allow", "payment; popups");
|
|
71
|
+
iframe.setAttribute("loading", "lazy");
|
|
72
|
+
Object.keys(style).forEach((key) => {
|
|
73
|
+
iframe.style[key] = style[key];
|
|
74
|
+
});
|
|
75
|
+
function onMessage(event) {
|
|
76
|
+
if (event.origin !== origin) return;
|
|
77
|
+
if (!event.data || event.data.type !== "flashpay:payment_status") return;
|
|
78
|
+
const status = event.data.status;
|
|
79
|
+
const data = {
|
|
80
|
+
status,
|
|
81
|
+
transactionId: event.data.transactionId,
|
|
82
|
+
payment: event.data.payment
|
|
83
|
+
};
|
|
84
|
+
if ((status === "SUCCESSFUL" || status === "COMPLETED") && typeof options.onSuccess === "function") {
|
|
85
|
+
options.onSuccess(data);
|
|
86
|
+
} else if (status === "FAILED" && typeof options.onFailure === "function") {
|
|
87
|
+
options.onFailure(data);
|
|
88
|
+
} else if ((status === "CANCELLED" || status === "EXPIRED") && typeof options.onClose === "function") {
|
|
89
|
+
options.onClose(data);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
window.addEventListener("message", onMessage);
|
|
93
|
+
while (container.firstChild) {
|
|
94
|
+
container.removeChild(container.firstChild);
|
|
95
|
+
}
|
|
96
|
+
container.appendChild(iframe);
|
|
97
|
+
return {
|
|
98
|
+
destroy() {
|
|
99
|
+
window.removeEventListener("message", onMessage);
|
|
100
|
+
if (iframe.parentNode) {
|
|
101
|
+
iframe.parentNode.removeChild(iframe);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=flashpay.cjs.js.map
|
package/dist/flashpay.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface PaymentData {\n id: string;\n status: string;\n amount?: number;\n currency?: string;\n description?: string;\n destinationAccountName?: string;\n callbackUrl?: string;\n [key: string]: unknown;\n}\n\nexport interface PaymentEventData {\n status: \"SUCCESSFUL\" | \"COMPLETED\" | \"FAILED\" | \"CANCELLED\" | \"EXPIRED\";\n transactionId: string;\n payment: PaymentData;\n}\n\nexport interface FlashpayOptions {\n transactionId: string;\n container: string | HTMLElement;\n /** Whether to show the payment title. Defaults to `true`. Set to `false` to hide. */\n showTitle?: boolean;\n /** Whether to show the payment description. Defaults to `true`. Set to `false` to hide. */\n showDescription?: boolean;\n /** Whether to show the payment amount. Defaults to `true`. Set to `false` to hide. */\n showAmount?: boolean;\n style?: Partial<CSSStyleDeclaration>;\n onSuccess?: (data: PaymentEventData) => void;\n onFailure?: (data: PaymentEventData) => void;\n onClose?: (data: PaymentEventData) => void;\n /** Custom origin for Flashpay (e.g. for testing) */\n origin?: string;\n}\n\nexport interface CheckoutInstance {\n destroy: () => void;\n}\n\nconst DEFAULT_ORIGIN = \"https://pay.flashpayweb.com\";\n\nconst DEFAULT_STYLE: Partial<CSSStyleDeclaration> = {\n width: \"100%\",\n height: \"600px\",\n border: \"none\",\n borderRadius: \"8px\",\n};\n\n/**\n * Detect the Flashpay origin based on the current script src.\n * Called lazily inside checkout() so it runs after the DOM is ready.\n */\nfunction detectOrigin(): string {\n if (typeof document === \"undefined\") return DEFAULT_ORIGIN;\n\n const scripts = document.getElementsByTagName(\"script\");\n for (let i = 0; i < scripts.length; i++) {\n const src = scripts[i].src || \"\";\n if (src.indexOf(\"/sdk/flashpay\") !== -1 || src.indexOf(\"flashpay.umd.js\") !== -1) {\n try {\n const url = new URL(src);\n return url.origin;\n } catch (e) {}\n }\n }\n return DEFAULT_ORIGIN;\n}\n\n/**\n * Initialize a Flashpay checkout process.\n *\n * @param options - Configuration options for the checkout\n * @returns An instance that can be used to clean up the checkout\n */\nexport function checkout(options: FlashpayOptions): CheckoutInstance {\n if (!options || !options.transactionId) {\n throw new Error(\"Flashpay: transactionId is required\");\n }\n if (!options.container) {\n throw new Error(\"Flashpay: container is required\");\n }\n\n const container =\n typeof options.container === \"string\"\n ? document.querySelector<HTMLElement>(options.container)\n : options.container;\n\n if (!container) {\n const identifier = typeof options.container === \"string\" ? options.container : \"the provided HTMLElement\";\n throw new Error(`Flashpay: container element not found for ${identifier}`);\n }\n\n const style = Object.assign({}, DEFAULT_STYLE, options.style || {});\n const origin = options.origin || detectOrigin();\n\n const iframe = document.createElement(\"iframe\");\n const url = new URL(origin + \"/pay/\" + encodeURIComponent(options.transactionId));\n\n if (options.showTitle === false) url.searchParams.set(\"showTitle\", \"false\");\n if (options.showDescription === false) url.searchParams.set(\"showDescription\", \"false\");\n if (options.showAmount === false) url.searchParams.set(\"showAmount\", \"false\");\n url.searchParams.set(\"parentOrigin\", window.location.origin);\n\n iframe.src = url.toString();\n iframe.title = \"Flashpay payment\";\n iframe.setAttribute(\"allow\", \"payment; popups\");\n iframe.setAttribute(\"loading\", \"lazy\");\n\n Object.keys(style).forEach((key) => {\n (iframe.style as any)[key] = (style as any)[key];\n });\n\n function onMessage(event: MessageEvent) {\n if (event.origin !== origin) return;\n if (!event.data || event.data.type !== \"flashpay:payment_status\") return;\n\n const status = event.data.status as PaymentEventData[\"status\"];\n const data: PaymentEventData = {\n status,\n transactionId: event.data.transactionId,\n payment: event.data.payment,\n };\n\n if ((status === \"SUCCESSFUL\" || status === \"COMPLETED\") && typeof options.onSuccess === \"function\") {\n options.onSuccess(data);\n } else if (status === \"FAILED\" && typeof options.onFailure === \"function\") {\n options.onFailure(data);\n } else if ((status === \"CANCELLED\" || status === \"EXPIRED\") && typeof options.onClose === \"function\") {\n options.onClose(data);\n }\n }\n\n window.addEventListener(\"message\", onMessage);\n\n // Clear container using safe DOM removal instead of innerHTML\n while (container.firstChild) {\n container.removeChild(container.firstChild);\n }\n container.appendChild(iframe);\n\n return {\n destroy() {\n window.removeEventListener(\"message\", onMessage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B,WAAW,SAAS;AAC/C,UAAI,OAAO,YAAY;AACrB,eAAO,WAAW,YAAY,MAAM;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface PaymentData {
|
|
2
2
|
id: string;
|
|
3
3
|
status: string;
|
|
4
4
|
amount?: number;
|
|
@@ -8,16 +8,19 @@ export interface PaymentData {
|
|
|
8
8
|
callbackUrl?: string;
|
|
9
9
|
[key: string]: unknown;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
interface PaymentEventData {
|
|
12
12
|
status: "SUCCESSFUL" | "COMPLETED" | "FAILED" | "CANCELLED" | "EXPIRED";
|
|
13
13
|
transactionId: string;
|
|
14
14
|
payment: PaymentData;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
interface FlashpayOptions {
|
|
17
17
|
transactionId: string;
|
|
18
18
|
container: string | HTMLElement;
|
|
19
|
+
/** Whether to show the payment title. Defaults to `true`. Set to `false` to hide. */
|
|
19
20
|
showTitle?: boolean;
|
|
21
|
+
/** Whether to show the payment description. Defaults to `true`. Set to `false` to hide. */
|
|
20
22
|
showDescription?: boolean;
|
|
23
|
+
/** Whether to show the payment amount. Defaults to `true`. Set to `false` to hide. */
|
|
21
24
|
showAmount?: boolean;
|
|
22
25
|
style?: Partial<CSSStyleDeclaration>;
|
|
23
26
|
onSuccess?: (data: PaymentEventData) => void;
|
|
@@ -26,7 +29,7 @@ export interface FlashpayOptions {
|
|
|
26
29
|
/** Custom origin for Flashpay (e.g. for testing) */
|
|
27
30
|
origin?: string;
|
|
28
31
|
}
|
|
29
|
-
|
|
32
|
+
interface CheckoutInstance {
|
|
30
33
|
destroy: () => void;
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
@@ -35,4 +38,6 @@ export interface CheckoutInstance {
|
|
|
35
38
|
* @param options - Configuration options for the checkout
|
|
36
39
|
* @returns An instance that can be used to clean up the checkout
|
|
37
40
|
*/
|
|
38
|
-
|
|
41
|
+
declare function checkout(options: FlashpayOptions): CheckoutInstance;
|
|
42
|
+
|
|
43
|
+
export { type CheckoutInstance, type FlashpayOptions, type PaymentData, type PaymentEventData, checkout };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
interface PaymentData {
|
|
2
|
+
id: string;
|
|
3
|
+
status: string;
|
|
4
|
+
amount?: number;
|
|
5
|
+
currency?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
destinationAccountName?: string;
|
|
8
|
+
callbackUrl?: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
interface PaymentEventData {
|
|
12
|
+
status: "SUCCESSFUL" | "COMPLETED" | "FAILED" | "CANCELLED" | "EXPIRED";
|
|
13
|
+
transactionId: string;
|
|
14
|
+
payment: PaymentData;
|
|
15
|
+
}
|
|
16
|
+
interface FlashpayOptions {
|
|
17
|
+
transactionId: string;
|
|
18
|
+
container: string | HTMLElement;
|
|
19
|
+
/** Whether to show the payment title. Defaults to `true`. Set to `false` to hide. */
|
|
20
|
+
showTitle?: boolean;
|
|
21
|
+
/** Whether to show the payment description. Defaults to `true`. Set to `false` to hide. */
|
|
22
|
+
showDescription?: boolean;
|
|
23
|
+
/** Whether to show the payment amount. Defaults to `true`. Set to `false` to hide. */
|
|
24
|
+
showAmount?: boolean;
|
|
25
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
26
|
+
onSuccess?: (data: PaymentEventData) => void;
|
|
27
|
+
onFailure?: (data: PaymentEventData) => void;
|
|
28
|
+
onClose?: (data: PaymentEventData) => void;
|
|
29
|
+
/** Custom origin for Flashpay (e.g. for testing) */
|
|
30
|
+
origin?: string;
|
|
31
|
+
}
|
|
32
|
+
interface CheckoutInstance {
|
|
33
|
+
destroy: () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Initialize a Flashpay checkout process.
|
|
37
|
+
*
|
|
38
|
+
* @param options - Configuration options for the checkout
|
|
39
|
+
* @returns An instance that can be used to clean up the checkout
|
|
40
|
+
*/
|
|
41
|
+
declare function checkout(options: FlashpayOptions): CheckoutInstance;
|
|
42
|
+
|
|
43
|
+
export { type CheckoutInstance, type FlashpayOptions, type PaymentData, type PaymentEventData, checkout };
|
package/dist/flashpay.es.js
CHANGED
|
@@ -1,54 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var DEFAULT_ORIGIN = "https://pay.flashpayweb.com";
|
|
3
|
+
var DEFAULT_STYLE = {
|
|
2
4
|
width: "100%",
|
|
3
5
|
height: "600px",
|
|
4
6
|
border: "none",
|
|
5
7
|
borderRadius: "8px"
|
|
6
8
|
};
|
|
7
|
-
function
|
|
8
|
-
if (typeof document
|
|
9
|
-
const
|
|
10
|
-
for (let
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
9
|
+
function detectOrigin() {
|
|
10
|
+
if (typeof document === "undefined") return DEFAULT_ORIGIN;
|
|
11
|
+
const scripts = document.getElementsByTagName("script");
|
|
12
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
13
|
+
const src = scripts[i].src || "";
|
|
14
|
+
if (src.indexOf("/sdk/flashpay") !== -1 || src.indexOf("flashpay.umd.js") !== -1) {
|
|
13
15
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
const url = new URL(src);
|
|
17
|
+
return url.origin;
|
|
18
|
+
} catch (e) {
|
|
16
19
|
}
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
|
-
return
|
|
22
|
+
return DEFAULT_ORIGIN;
|
|
19
23
|
}
|
|
20
|
-
function
|
|
21
|
-
if (!
|
|
24
|
+
function checkout(options) {
|
|
25
|
+
if (!options || !options.transactionId) {
|
|
22
26
|
throw new Error("Flashpay: transactionId is required");
|
|
23
|
-
|
|
27
|
+
}
|
|
28
|
+
if (!options.container) {
|
|
24
29
|
throw new Error("Flashpay: container is required");
|
|
25
|
-
const r = typeof e.container == "string" ? document.querySelector(e.container) : e.container;
|
|
26
|
-
if (!r) {
|
|
27
|
-
const t = typeof e.container == "string" ? e.container : "the provided HTMLElement";
|
|
28
|
-
throw new Error(`Flashpay: container element not found for ${t}`);
|
|
29
30
|
}
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container;
|
|
32
|
+
if (!container) {
|
|
33
|
+
const identifier = typeof options.container === "string" ? options.container : "the provided HTMLElement";
|
|
34
|
+
throw new Error(`Flashpay: container element not found for ${identifier}`);
|
|
35
|
+
}
|
|
36
|
+
const style = Object.assign({}, DEFAULT_STYLE, options.style || {});
|
|
37
|
+
const origin = options.origin || detectOrigin();
|
|
38
|
+
const iframe = document.createElement("iframe");
|
|
39
|
+
const url = new URL(origin + "/pay/" + encodeURIComponent(options.transactionId));
|
|
40
|
+
if (options.showTitle === false) url.searchParams.set("showTitle", "false");
|
|
41
|
+
if (options.showDescription === false) url.searchParams.set("showDescription", "false");
|
|
42
|
+
if (options.showAmount === false) url.searchParams.set("showAmount", "false");
|
|
43
|
+
url.searchParams.set("parentOrigin", window.location.origin);
|
|
44
|
+
iframe.src = url.toString();
|
|
45
|
+
iframe.title = "Flashpay payment";
|
|
46
|
+
iframe.setAttribute("allow", "payment; popups");
|
|
47
|
+
iframe.setAttribute("loading", "lazy");
|
|
48
|
+
Object.keys(style).forEach((key) => {
|
|
49
|
+
iframe.style[key] = style[key];
|
|
33
50
|
});
|
|
34
|
-
function
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
function onMessage(event) {
|
|
52
|
+
if (event.origin !== origin) return;
|
|
53
|
+
if (!event.data || event.data.type !== "flashpay:payment_status") return;
|
|
54
|
+
const status = event.data.status;
|
|
55
|
+
const data = {
|
|
56
|
+
status,
|
|
57
|
+
transactionId: event.data.transactionId,
|
|
58
|
+
payment: event.data.payment
|
|
40
59
|
};
|
|
41
|
-
(
|
|
60
|
+
if ((status === "SUCCESSFUL" || status === "COMPLETED") && typeof options.onSuccess === "function") {
|
|
61
|
+
options.onSuccess(data);
|
|
62
|
+
} else if (status === "FAILED" && typeof options.onFailure === "function") {
|
|
63
|
+
options.onFailure(data);
|
|
64
|
+
} else if ((status === "CANCELLED" || status === "EXPIRED") && typeof options.onClose === "function") {
|
|
65
|
+
options.onClose(data);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
window.addEventListener("message", onMessage);
|
|
69
|
+
while (container.firstChild) {
|
|
70
|
+
container.removeChild(container.firstChild);
|
|
42
71
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return r.appendChild(n), {
|
|
72
|
+
container.appendChild(iframe);
|
|
73
|
+
return {
|
|
46
74
|
destroy() {
|
|
47
|
-
window.removeEventListener("message",
|
|
75
|
+
window.removeEventListener("message", onMessage);
|
|
76
|
+
if (iframe.parentNode) {
|
|
77
|
+
iframe.parentNode.removeChild(iframe);
|
|
78
|
+
}
|
|
48
79
|
}
|
|
49
80
|
};
|
|
50
81
|
}
|
|
51
82
|
export {
|
|
52
|
-
|
|
83
|
+
checkout
|
|
53
84
|
};
|
|
54
|
-
//# sourceMappingURL=flashpay.es.js.map
|
|
85
|
+
//# sourceMappingURL=flashpay.es.js.map
|
package/dist/flashpay.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface PaymentData {\n id: string;\n status: string;\n amount?: number;\n currency?: string;\n description?: string;\n destinationAccountName?: string;\n callbackUrl?: string;\n [key: string]: unknown;\n}\n\nexport interface PaymentEventData {\n status: \"SUCCESSFUL\" | \"COMPLETED\" | \"FAILED\" | \"CANCELLED\" | \"EXPIRED\";\n transactionId: string;\n payment: PaymentData;\n}\n\nexport interface FlashpayOptions {\n transactionId: string;\n container: string | HTMLElement;\n /** Whether to show the payment title. Defaults to `true`. Set to `false` to hide. */\n showTitle?: boolean;\n /** Whether to show the payment description. Defaults to `true`. Set to `false` to hide. */\n showDescription?: boolean;\n /** Whether to show the payment amount. Defaults to `true`. Set to `false` to hide. */\n showAmount?: boolean;\n style?: Partial<CSSStyleDeclaration>;\n onSuccess?: (data: PaymentEventData) => void;\n onFailure?: (data: PaymentEventData) => void;\n onClose?: (data: PaymentEventData) => void;\n /** Custom origin for Flashpay (e.g. for testing) */\n origin?: string;\n}\n\nexport interface CheckoutInstance {\n destroy: () => void;\n}\n\nconst DEFAULT_ORIGIN = \"https://pay.flashpayweb.com\";\n\nconst DEFAULT_STYLE: Partial<CSSStyleDeclaration> = {\n width: \"100%\",\n height: \"600px\",\n border: \"none\",\n borderRadius: \"8px\",\n};\n\n/**\n * Detect the Flashpay origin based on the current script src.\n * Called lazily inside checkout() so it runs after the DOM is ready.\n */\nfunction detectOrigin(): string {\n if (typeof document === \"undefined\") return DEFAULT_ORIGIN;\n\n const scripts = document.getElementsByTagName(\"script\");\n for (let i = 0; i < scripts.length; i++) {\n const src = scripts[i].src || \"\";\n if (src.indexOf(\"/sdk/flashpay\") !== -1 || src.indexOf(\"flashpay.umd.js\") !== -1) {\n try {\n const url = new URL(src);\n return url.origin;\n } catch (e) {}\n }\n }\n return DEFAULT_ORIGIN;\n}\n\n/**\n * Initialize a Flashpay checkout process.\n *\n * @param options - Configuration options for the checkout\n * @returns An instance that can be used to clean up the checkout\n */\nexport function checkout(options: FlashpayOptions): CheckoutInstance {\n if (!options || !options.transactionId) {\n throw new Error(\"Flashpay: transactionId is required\");\n }\n if (!options.container) {\n throw new Error(\"Flashpay: container is required\");\n }\n\n const container =\n typeof options.container === \"string\"\n ? document.querySelector<HTMLElement>(options.container)\n : options.container;\n\n if (!container) {\n const identifier = typeof options.container === \"string\" ? options.container : \"the provided HTMLElement\";\n throw new Error(`Flashpay: container element not found for ${identifier}`);\n }\n\n const style = Object.assign({}, DEFAULT_STYLE, options.style || {});\n const origin = options.origin || detectOrigin();\n\n const iframe = document.createElement(\"iframe\");\n const url = new URL(origin + \"/pay/\" + encodeURIComponent(options.transactionId));\n\n if (options.showTitle === false) url.searchParams.set(\"showTitle\", \"false\");\n if (options.showDescription === false) url.searchParams.set(\"showDescription\", \"false\");\n if (options.showAmount === false) url.searchParams.set(\"showAmount\", \"false\");\n url.searchParams.set(\"parentOrigin\", window.location.origin);\n\n iframe.src = url.toString();\n iframe.title = \"Flashpay payment\";\n iframe.setAttribute(\"allow\", \"payment; popups\");\n iframe.setAttribute(\"loading\", \"lazy\");\n\n Object.keys(style).forEach((key) => {\n (iframe.style as any)[key] = (style as any)[key];\n });\n\n function onMessage(event: MessageEvent) {\n if (event.origin !== origin) return;\n if (!event.data || event.data.type !== \"flashpay:payment_status\") return;\n\n const status = event.data.status as PaymentEventData[\"status\"];\n const data: PaymentEventData = {\n status,\n transactionId: event.data.transactionId,\n payment: event.data.payment,\n };\n\n if ((status === \"SUCCESSFUL\" || status === \"COMPLETED\") && typeof options.onSuccess === \"function\") {\n options.onSuccess(data);\n } else if (status === \"FAILED\" && typeof options.onFailure === \"function\") {\n options.onFailure(data);\n } else if ((status === \"CANCELLED\" || status === \"EXPIRED\") && typeof options.onClose === \"function\") {\n options.onClose(data);\n }\n }\n\n window.addEventListener(\"message\", onMessage);\n\n // Clear container using safe DOM removal instead of innerHTML\n while (container.firstChild) {\n container.removeChild(container.firstChild);\n }\n container.appendChild(iframe);\n\n return {\n destroy() {\n window.removeEventListener(\"message\", onMessage);\n if (iframe.parentNode) {\n iframe.parentNode.removeChild(iframe);\n }\n },\n };\n}\n"],"mappings":";AAsCA,IAAM,iBAAiB;AAEvB,IAAM,gBAA8C;AAAA,EAClD,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,cAAc;AAChB;AAMA,SAAS,eAAuB;AAC9B,MAAI,OAAO,aAAa,YAAa,QAAO;AAE5C,QAAM,UAAU,SAAS,qBAAqB,QAAQ;AACtD,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,MAAM,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C,SAAO,KAAK,KAAK,EAAE,QAAQ,CAAC,QAAQ;AAClC,IAAC,OAAO,MAAc,GAAG,IAAK,MAAc,GAAG;AAAA,EACjD,CAAC;AAED,WAAS,UAAU,OAAqB;AACtC,QAAI,MAAM,WAAW,OAAQ;AAC7B,QAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,SAAS,0BAA2B;AAElE,UAAM,SAAS,MAAM,KAAK;AAC1B,UAAM,OAAyB;AAAA,MAC7B;AAAA,MACA,eAAe,MAAM,KAAK;AAAA,MAC1B,SAAS,MAAM,KAAK;AAAA,IACtB;AAEA,SAAK,WAAW,gBAAgB,WAAW,gBAAgB,OAAO,QAAQ,cAAc,YAAY;AAClG,cAAQ,UAAU,IAAI;AAAA,IACxB,WAAW,WAAW,YAAY,OAAO,QAAQ,cAAc,YAAY;AACzE,cAAQ,UAAU,IAAI;AAAA,IACxB,YAAY,WAAW,eAAe,WAAW,cAAc,OAAO,QAAQ,YAAY,YAAY;AACpG,cAAQ,QAAQ,IAAI;AAAA,IACtB;AAAA,EACF;AAEA,SAAO,iBAAiB,WAAW,SAAS;AAG5C,SAAO,UAAU,YAAY;AAC3B,cAAU,YAAY,UAAU,UAAU;AAAA,EAC5C;AACA,YAAU,YAAY,MAAM;AAE5B,SAAO;AAAA,IACL,UAAU;AACR,aAAO,oBAAoB,WAAW,SAAS;AAC/C,UAAI,OAAO,YAAY;AACrB,eAAO,WAAW,YAAY,MAAM;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/flashpay.umd.js
CHANGED
|
@@ -1,2 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var Flashpay = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
checkout: () => checkout
|
|
25
|
+
});
|
|
26
|
+
var DEFAULT_ORIGIN = "https://pay.flashpayweb.com";
|
|
27
|
+
var DEFAULT_STYLE = {
|
|
28
|
+
width: "100%",
|
|
29
|
+
height: "600px",
|
|
30
|
+
border: "none",
|
|
31
|
+
borderRadius: "8px"
|
|
32
|
+
};
|
|
33
|
+
function detectOrigin() {
|
|
34
|
+
if (typeof document === "undefined") return DEFAULT_ORIGIN;
|
|
35
|
+
const scripts = document.getElementsByTagName("script");
|
|
36
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
37
|
+
const src = scripts[i].src || "";
|
|
38
|
+
if (src.indexOf("/sdk/flashpay") !== -1 || src.indexOf("flashpay.umd.js") !== -1) {
|
|
39
|
+
try {
|
|
40
|
+
const url = new URL(src);
|
|
41
|
+
return url.origin;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return DEFAULT_ORIGIN;
|
|
47
|
+
}
|
|
48
|
+
function checkout(options) {
|
|
49
|
+
if (!options || !options.transactionId) {
|
|
50
|
+
throw new Error("Flashpay: transactionId is required");
|
|
51
|
+
}
|
|
52
|
+
if (!options.container) {
|
|
53
|
+
throw new Error("Flashpay: container is required");
|
|
54
|
+
}
|
|
55
|
+
const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container;
|
|
56
|
+
if (!container) {
|
|
57
|
+
const identifier = typeof options.container === "string" ? options.container : "the provided HTMLElement";
|
|
58
|
+
throw new Error(`Flashpay: container element not found for ${identifier}`);
|
|
59
|
+
}
|
|
60
|
+
const style = Object.assign({}, DEFAULT_STYLE, options.style || {});
|
|
61
|
+
const origin = options.origin || detectOrigin();
|
|
62
|
+
const iframe = document.createElement("iframe");
|
|
63
|
+
const url = new URL(origin + "/pay/" + encodeURIComponent(options.transactionId));
|
|
64
|
+
if (options.showTitle === false) url.searchParams.set("showTitle", "false");
|
|
65
|
+
if (options.showDescription === false) url.searchParams.set("showDescription", "false");
|
|
66
|
+
if (options.showAmount === false) url.searchParams.set("showAmount", "false");
|
|
67
|
+
url.searchParams.set("parentOrigin", window.location.origin);
|
|
68
|
+
iframe.src = url.toString();
|
|
69
|
+
iframe.title = "Flashpay payment";
|
|
70
|
+
iframe.setAttribute("allow", "payment; popups");
|
|
71
|
+
iframe.setAttribute("loading", "lazy");
|
|
72
|
+
Object.keys(style).forEach((key) => {
|
|
73
|
+
iframe.style[key] = style[key];
|
|
74
|
+
});
|
|
75
|
+
function onMessage(event) {
|
|
76
|
+
if (event.origin !== origin) return;
|
|
77
|
+
if (!event.data || event.data.type !== "flashpay:payment_status") return;
|
|
78
|
+
const status = event.data.status;
|
|
79
|
+
const data = {
|
|
80
|
+
status,
|
|
81
|
+
transactionId: event.data.transactionId,
|
|
82
|
+
payment: event.data.payment
|
|
83
|
+
};
|
|
84
|
+
if ((status === "SUCCESSFUL" || status === "COMPLETED") && typeof options.onSuccess === "function") {
|
|
85
|
+
options.onSuccess(data);
|
|
86
|
+
} else if (status === "FAILED" && typeof options.onFailure === "function") {
|
|
87
|
+
options.onFailure(data);
|
|
88
|
+
} else if ((status === "CANCELLED" || status === "EXPIRED") && typeof options.onClose === "function") {
|
|
89
|
+
options.onClose(data);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
window.addEventListener("message", onMessage);
|
|
93
|
+
while (container.firstChild) {
|
|
94
|
+
container.removeChild(container.firstChild);
|
|
95
|
+
}
|
|
96
|
+
container.appendChild(iframe);
|
|
97
|
+
return {
|
|
98
|
+
destroy() {
|
|
99
|
+
window.removeEventListener("message", onMessage);
|
|
100
|
+
if (iframe.parentNode) {
|
|
101
|
+
iframe.parentNode.removeChild(iframe);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return __toCommonJS(src_exports);
|
|
107
|
+
})();
|
|
108
|
+
//# sourceMappingURL=flashpay.umd.js.map
|
package/dist/flashpay.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface PaymentData {\n id: string;\n status: string;\n amount?: number;\n currency?: string;\n description?: string;\n destinationAccountName?: string;\n callbackUrl?: string;\n [key: string]: unknown;\n}\n\nexport interface PaymentEventData {\n status: \"SUCCESSFUL\" | \"COMPLETED\" | \"FAILED\" | \"CANCELLED\" | \"EXPIRED\";\n transactionId: string;\n payment: PaymentData;\n}\n\nexport interface FlashpayOptions {\n transactionId: string;\n container: string | HTMLElement;\n /** Whether to show the payment title. Defaults to `true`. Set to `false` to hide. */\n showTitle?: boolean;\n /** Whether to show the payment description. Defaults to `true`. Set to `false` to hide. */\n showDescription?: boolean;\n /** Whether to show the payment amount. Defaults to `true`. Set to `false` to hide. */\n showAmount?: boolean;\n style?: Partial<CSSStyleDeclaration>;\n onSuccess?: (data: PaymentEventData) => void;\n onFailure?: (data: PaymentEventData) => void;\n onClose?: (data: PaymentEventData) => void;\n /** Custom origin for Flashpay (e.g. for testing) */\n origin?: string;\n}\n\nexport interface CheckoutInstance {\n destroy: () => void;\n}\n\nconst DEFAULT_ORIGIN = \"https://pay.flashpayweb.com\";\n\nconst DEFAULT_STYLE: Partial<CSSStyleDeclaration> = {\n width: \"100%\",\n height: \"600px\",\n border: \"none\",\n borderRadius: \"8px\",\n};\n\n/**\n * Detect the Flashpay origin based on the current script src.\n * Called lazily inside checkout() so it runs after the DOM is ready.\n */\nfunction detectOrigin(): string {\n if (typeof document === \"undefined\") return DEFAULT_ORIGIN;\n\n const scripts = document.getElementsByTagName(\"script\");\n for (let i = 0; i < scripts.length; i++) {\n const src = scripts[i].src || \"\";\n if (src.indexOf(\"/sdk/flashpay\") !== -1 || src.indexOf(\"flashpay.umd.js\") !== -1) {\n try {\n const url = new URL(src);\n return url.origin;\n } catch (e) {}\n }\n }\n return DEFAULT_ORIGIN;\n}\n\n/**\n * Initialize a Flashpay checkout process.\n *\n * @param options - Configuration options for the checkout\n * @returns An instance that can be used to clean up the checkout\n */\nexport function checkout(options: FlashpayOptions): CheckoutInstance {\n if (!options || !options.transactionId) {\n throw new Error(\"Flashpay: transactionId is required\");\n }\n if (!options.container) {\n throw new Error(\"Flashpay: container is required\");\n }\n\n const container =\n typeof options.container === \"string\"\n ? document.querySelector<HTMLElement>(options.container)\n : options.container;\n\n if (!container) {\n const identifier = typeof options.container === \"string\" ? options.container : \"the provided HTMLElement\";\n throw new Error(`Flashpay: container element not found for ${identifier}`);\n }\n\n const style = Object.assign({}, DEFAULT_STYLE, options.style || {});\n const origin = options.origin || detectOrigin();\n\n const iframe = document.createElement(\"iframe\");\n const url = new URL(origin + \"/pay/\" + encodeURIComponent(options.transactionId));\n\n if (options.showTitle === false) url.searchParams.set(\"showTitle\", \"false\");\n if (options.showDescription === false) url.searchParams.set(\"showDescription\", \"false\");\n if (options.showAmount === false) url.searchParams.set(\"showAmount\", \"false\");\n url.searchParams.set(\"parentOrigin\", window.location.origin);\n\n iframe.src = url.toString();\n iframe.title = \"Flashpay payment\";\n iframe.setAttribute(\"allow\", \"payment; popups\");\n iframe.setAttribute(\"loading\", \"lazy\");\n\n Object.keys(style).forEach((key) => {\n (iframe.style as any)[key] = (style as any)[key];\n });\n\n function onMessage(event: MessageEvent) {\n if (event.origin !== origin) return;\n if (!event.data || event.data.type !== \"flashpay:payment_status\") return;\n\n const status = event.data.status as PaymentEventData[\"status\"];\n const data: PaymentEventData = {\n status,\n transactionId: event.data.transactionId,\n payment: event.data.payment,\n };\n\n if ((status === \"SUCCESSFUL\" || status === \"COMPLETED\") && typeof options.onSuccess === \"function\") {\n options.onSuccess(data);\n } else if (status === \"FAILED\" && typeof options.onFailure === \"function\") {\n options.onFailure(data);\n } else if ((status === \"CANCELLED\" || status === \"EXPIRED\") && typeof options.onClose === \"function\") {\n options.onClose(data);\n }\n }\n\n window.addEventListener(\"message\", onMessage);\n\n // Clear container using safe DOM removal instead of innerHTML\n while (container.firstChild) {\n container.removeChild(container.firstChild);\n }\n container.appendChild(iframe);\n\n return {\n destroy() {\n window.removeEventListener(\"message\", onMessage);\n if (iframe.parentNode) {\n iframe.parentNode.removeChild(iframe);\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAsCA,MAAM,iBAAiB;AAEvB,MAAM,gBAA8C;AAAA,IAClD,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,cAAc;AAAA,EAChB;AAMA,WAAS,eAAuB;AAC9B,QAAI,OAAO,aAAa,YAAa,QAAO;AAE5C,UAAM,UAAU,SAAS,qBAAqB,QAAQ;AACtD,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,YAAM,MAAM,QAAQ,CAAC,EAAE,OAAO;AAC9B,UAAI,IAAI,QAAQ,eAAe,MAAM,MAAM,IAAI,QAAQ,iBAAiB,MAAM,IAAI;AAChF,YAAI;AACF,gBAAM,MAAM,IAAI,IAAI,GAAG;AACvB,iBAAO,IAAI;AAAA,QACb,SAAS,GAAG;AAAA,QAAC;AAAA,MACf;AAAA,IACF;A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BAA2B;AAElE,YAAM,SAAS,MAAM,KAAK;AAC1B,YAAM,OAAyB;AAAA,QAC7B;AAAA,QACA,eAAe,MAAM,KAAK;AAAA,QAC1B,SAAS,MAAM,KAAK;AAAA,MACtB;AAEA,WAAK,WAAW,gBAAgB,WAAW,gBAAgB,OAAO,QAAQ,cAAc,YAAY;AAClG,gBAAQ,UAAU,IAAI;AAAA,MACxB,WAAW,WAAW,YAAY,OAAO,QAAQ,cAAc,YAAY;AACzE,gBAAQ,UAAU,IAAI;AAAA,MACxB,YAAY,WAAW,eAAe,WAAW,cAAc,OAAO,QAAQ,YAAY,YAAY;AACpG,gBAAQ,QAAQ,IAAI;AAAA,MACtB;AAAA,IACF;AAEA,WAAO,iBAAiB,WAAW,SAAS;AAG5C,WAAO,UAAU,YAAY;AAC3B,gBAAU,YAAY,UAAU,UAAU;AAAA,IAC5C;AACA,cAAU,YAAY,MAAM;AAE5B,WAAO;AAAA,MACL,UAAU;AACR,eAAO,oBAAoB,WAAW,SAAS;AAC/C,YAAI,OAAO,YAAY;AACrB,iBAAO,WAAW,YAAY,MAAM;AAAA,QACtC;AAAA,MACF;AAAA,IACF;AAAA,EACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flash-pay/browser-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Flashpay Browser SDK for easy payment integration",
|
|
5
5
|
"main": "./dist/flashpay.cjs.js",
|
|
6
6
|
"module": "./dist/flashpay.es.js",
|
|
7
7
|
"browser": "./dist/flashpay.umd.js",
|
|
8
|
-
"types": "./dist/
|
|
8
|
+
"types": "./dist/flashpay.d.ts",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
+
"types": "./dist/flashpay.d.ts",
|
|
12
13
|
"browser": "./dist/flashpay.es.js",
|
|
13
14
|
"import": "./dist/flashpay.es.js",
|
|
14
|
-
"require": "./dist/flashpay.cjs.js"
|
|
15
|
-
"types": "./dist/index.d.ts"
|
|
15
|
+
"require": "./dist/flashpay.cjs.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "
|
|
23
|
-
"dev": "
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
24
|
"lint": "eslint src",
|
|
25
25
|
"test": "vitest run",
|
|
26
26
|
"test:watch": "vitest"
|
|
@@ -38,8 +38,7 @@
|
|
|
38
38
|
"ajv": "^8.18.0",
|
|
39
39
|
"jsdom": "^26.0.0",
|
|
40
40
|
"typescript": "^5.3.3",
|
|
41
|
-
"
|
|
42
|
-
"vite-plugin-dts": "^4.5.4",
|
|
41
|
+
"tsup": "^8.5.0",
|
|
43
42
|
"vitest": "^3.0.0"
|
|
44
43
|
}
|
|
45
44
|
}
|
package/dist/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|