@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.
@@ -1,2 +1,106 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u="https://pay.flashpayweb.com",l={width:"100%",height:"600px",border:"none",borderRadius:"8px"};function f(){if(typeof document>"u")return u;const e=document.getElementsByTagName("script");for(let r=0;r<e.length;r++){const a=e[r].src||"";if(a.indexOf("/sdk/flashpay")!==-1||a.indexOf("flashpay.umd.js")!==-1)try{return new URL(a).origin}catch{}}return u}function h(e){if(!e||!e.transactionId)throw new Error("Flashpay: transactionId is required");if(!e.container)throw new Error("Flashpay: container is required");const r=typeof e.container=="string"?document.querySelector(e.container):e.container;if(!r){const t=typeof e.container=="string"?e.container:"the provided HTMLElement";throw new Error(`Flashpay: container element not found for ${t}`)}const a=Object.assign({},l,e.style||{}),o=e.origin||f(),n=document.createElement("iframe"),s=new URL(o+"/pay/"+encodeURIComponent(e.transactionId));e.showTitle&&s.searchParams.set("showTitle","true"),e.showDescription&&s.searchParams.set("showDescription","true"),e.showAmount&&s.searchParams.set("showAmount","true"),s.searchParams.set("parentOrigin",window.location.origin),n.src=s.toString(),n.title="Flashpay payment",n.setAttribute("allow","payment; popups"),n.setAttribute("loading","lazy"),Object.keys(a).forEach(t=>{n.style[t]=a[t]});function d(t){if(t.origin!==o||!t.data||t.data.type!=="flashpay:payment_status")return;const i=t.data.status,c={status:i,transactionId:t.data.transactionId,payment:t.data.payment};(i==="SUCCESSFUL"||i==="COMPLETED")&&typeof e.onSuccess=="function"?e.onSuccess(c):i==="FAILED"&&typeof e.onFailure=="function"?e.onFailure(c):(i==="CANCELLED"||i==="EXPIRED")&&typeof e.onClose=="function"&&e.onClose(c)}for(window.addEventListener("message",d);r.firstChild;)r.removeChild(r.firstChild);return r.appendChild(n),{destroy(){window.removeEventListener("message",d),n.parentNode&&n.parentNode.removeChild(n)}}}exports.checkout=h;
2
- //# sourceMappingURL=flashpay.cjs.js.map
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
@@ -1 +1 @@
1
- {"version":3,"file":"flashpay.cjs.js","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 showTitle?: boolean;\n showDescription?: boolean;\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) url.searchParams.set(\"showTitle\", \"true\");\n if (options.showDescription) url.searchParams.set(\"showDescription\", \"true\");\n if (options.showAmount) url.searchParams.set(\"showAmount\", \"true\");\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"],"names":["DEFAULT_ORIGIN","DEFAULT_STYLE","detectOrigin","scripts","i","src","checkout","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AAa,IAAI,aAAc,MAAM,EACjEA,EAAI,aAAa,IAAI,eAAgB,OAAO,SAAS,MAAM,EAE3DD,EAAO,IAAMC,EAAI,SAAA,EACjBD,EAAO,MAAQ,mBACfA,EAAO,aAAa,QAAS,iBAAiB,EAC9CA,EAAO,aAAa,UAAW,MAAM,EAErC,OAAO,KAAKF,CAAK,EAAE,QAASI,GAAQ,CACjCF,EAAO,MAAcE,CAAG,EAAKJ,EAAcI,CAAG,CACjD,CAAC,EAED,SAASC,EAAUC,EAAqB,CAEtC,GADIA,EAAM,SAAWL,GACjB,CAACK,EAAM,MAAQA,EAAM,KAAK,OAAS,0BAA2B,OAElE,MAAMC,EAASD,EAAM,KAAK,OACpBE,EAAyB,CAC7B,OAAAD,EACA,cAAeD,EAAM,KAAK,cAC1B,QAASA,EAAM,KAAK,OAAA,GAGjBC,IAAW,cAAgBA,IAAW,cAAgB,OAAOV,EAAQ,WAAc,WACtFA,EAAQ,UAAUW,CAAI,EACbD,IAAW,UAAY,OAAOV,EAAQ,WAAc,WAC7DA,EAAQ,UAAUW,CAAI,GACZD,IAAW,aAAeA,IAAW,YAAc,OAAOV,EAAQ,SAAY,YACxFA,EAAQ,QAAQW,CAAI,CAExB,CAKA,IAHA,OAAO,iBAAiB,UAAWH,CAAS,EAGrCP,EAAU,YACfA,EAAU,YAAYA,EAAU,UAAU,EAE5C,OAAAA,EAAU,YAAYI,CAAM,EAErB,CACL,SAAU,CACR,OAAO,oBAAoB,UAAWG,CAAS,EAC3CH,EAAO,YACTA,EAAO,WAAW,YAAYA,CAAM,CAExC,CAAA,CAEJ"}
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;AAAA;AAsCA,IAAM,iBAAiB;AAEvB,IAAM,gBAA8C;AAAA,EAClD,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ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,19 @@ export interface PaymentData {
8
8
  callbackUrl?: string;
9
9
  [key: string]: unknown;
10
10
  }
11
- export interface PaymentEventData {
11
+ interface PaymentEventData {
12
12
  status: "SUCCESSFUL" | "COMPLETED" | "FAILED" | "CANCELLED" | "EXPIRED";
13
13
  transactionId: string;
14
14
  payment: PaymentData;
15
15
  }
16
- export interface FlashpayOptions {
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
- export interface CheckoutInstance {
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
- export declare function checkout(options: FlashpayOptions): CheckoutInstance;
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 };
@@ -1,54 +1,85 @@
1
- const f = "https://pay.flashpayweb.com", u = {
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 l() {
8
- if (typeof document > "u") return f;
9
- const e = document.getElementsByTagName("script");
10
- for (let r = 0; r < e.length; r++) {
11
- const a = e[r].src || "";
12
- if (a.indexOf("/sdk/flashpay") !== -1 || a.indexOf("flashpay.umd.js") !== -1)
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
- return new URL(a).origin;
15
- } catch {
16
+ const url = new URL(src);
17
+ return url.origin;
18
+ } catch (e) {
16
19
  }
20
+ }
17
21
  }
18
- return f;
22
+ return DEFAULT_ORIGIN;
19
23
  }
20
- function h(e) {
21
- if (!e || !e.transactionId)
24
+ function checkout(options) {
25
+ if (!options || !options.transactionId) {
22
26
  throw new Error("Flashpay: transactionId is required");
23
- if (!e.container)
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 a = Object.assign({}, u, e.style || {}), o = e.origin || l(), n = document.createElement("iframe"), s = new URL(o + "/pay/" + encodeURIComponent(e.transactionId));
31
- e.showTitle && s.searchParams.set("showTitle", "true"), e.showDescription && s.searchParams.set("showDescription", "true"), e.showAmount && s.searchParams.set("showAmount", "true"), s.searchParams.set("parentOrigin", window.location.origin), n.src = s.toString(), n.title = "Flashpay payment", n.setAttribute("allow", "payment; popups"), n.setAttribute("loading", "lazy"), Object.keys(a).forEach((t) => {
32
- n.style[t] = a[t];
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 d(t) {
35
- if (t.origin !== o || !t.data || t.data.type !== "flashpay:payment_status") return;
36
- const i = t.data.status, c = {
37
- status: i,
38
- transactionId: t.data.transactionId,
39
- payment: t.data.payment
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
- (i === "SUCCESSFUL" || i === "COMPLETED") && typeof e.onSuccess == "function" ? e.onSuccess(c) : i === "FAILED" && typeof e.onFailure == "function" ? e.onFailure(c) : (i === "CANCELLED" || i === "EXPIRED") && typeof e.onClose == "function" && e.onClose(c);
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
- for (window.addEventListener("message", d); r.firstChild; )
44
- r.removeChild(r.firstChild);
45
- return r.appendChild(n), {
72
+ container.appendChild(iframe);
73
+ return {
46
74
  destroy() {
47
- window.removeEventListener("message", d), n.parentNode && n.parentNode.removeChild(n);
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
- h as checkout
83
+ checkout
53
84
  };
54
- //# sourceMappingURL=flashpay.es.js.map
85
+ //# sourceMappingURL=flashpay.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"flashpay.es.js","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 showTitle?: boolean;\n showDescription?: boolean;\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) url.searchParams.set(\"showTitle\", \"true\");\n if (options.showDescription) url.searchParams.set(\"showDescription\", \"true\");\n if (options.showAmount) url.searchParams.set(\"showAmount\", \"true\");\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"],"names":["DEFAULT_ORIGIN","DEFAULT_STYLE","detectOrigin","scripts","i","src","checkout","options","container","identifier","style","origin","iframe","url","key","onMessage","event","status","data"],"mappings":"AAmCA,MAAMA,IAAiB,+BAEjBC,IAA8C;AAAA,EAClD,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,cAAc;AAChB;AAMA,SAASC,IAAuB;AAC9B,MAAI,OAAO,WAAa,IAAa,QAAOF;AAE5C,QAAMG,IAAU,SAAS,qBAAqB,QAAQ;AACtD,WAASC,IAAI,GAAGA,IAAID,EAAQ,QAAQC,KAAK;AACvC,UAAMC,IAAMF,EAAQC,CAAC,EAAE,OAAO;AAC9B,QAAIC,EAAI,QAAQ,eAAe,MAAM,MAAMA,EAAI,QAAQ,iBAAiB,MAAM;AAC5E,UAAI;AAEF,eADY,IAAI,IAAIA,CAAG,EACZ;AAAA,MACb,QAAY;AAAA,MAAC;AAAA,EAEjB;AACA,SAAOL;AACT;AAQO,SAASM,EAASC,GAA4C;AACnE,MAAI,CAACA,KAAW,CAACA,EAAQ;AACvB,UAAM,IAAI,MAAM,qCAAqC;AAEvD,MAAI,CAACA,EAAQ;AACX,UAAM,IAAI,MAAM,iCAAiC;AAGnD,QAAMC,IACJ,OAAOD,EAAQ,aAAc,WACzB,SAAS,cAA2BA,EAAQ,SAAS,IACrDA,EAAQ;AAEd,MAAI,CAACC,GAAW;AACd,UAAMC,IAAa,OAAOF,EAAQ,aAAc,WAAWA,EAAQ,YAAY;AAC/E,UAAM,IAAI,MAAM,6CAA6CE,CAAU,EAAE;AAAA,EAC3E;AAEA,QAAMC,IAAQ,OAAO,OAAO,CAAA,GAAIT,GAAeM,EAAQ,SAAS,EAAE,GAC5DI,IAASJ,EAAQ,UAAUL,EAAA,GAE3BU,IAAS,SAAS,cAAc,QAAQ,GACxCC,IAAM,IAAI,IAAIF,IAAS,UAAU,mBAAmBJ,EAAQ,aAAa,CAAC;AAEhF,EAAIA,EAAQ,aAAWM,EAAI,aAAa,IAAI,aAAa,MAAM,GAC3DN,EAAQ,mBAAiBM,EAAI,aAAa,IAAI,mBAAmB,MAAM,GACvEN,EAAQ,cAAYM,EAAI,aAAa,IAAI,cAAc,MAAM,GACjEA,EAAI,aAAa,IAAI,gBAAgB,OAAO,SAAS,MAAM,GAE3DD,EAAO,MAAMC,EAAI,SAAA,GACjBD,EAAO,QAAQ,oBACfA,EAAO,aAAa,SAAS,iBAAiB,GAC9CA,EAAO,aAAa,WAAW,MAAM,GAErC,OAAO,KAAKF,CAAK,EAAE,QAAQ,CAACI,MAAQ;AACjC,IAAAF,EAAO,MAAcE,CAAG,IAAKJ,EAAcI,CAAG;AAAA,EACjD,CAAC;AAED,WAASC,EAAUC,GAAqB;AAEtC,QADIA,EAAM,WAAWL,KACjB,CAACK,EAAM,QAAQA,EAAM,KAAK,SAAS,0BAA2B;AAElE,UAAMC,IAASD,EAAM,KAAK,QACpBE,IAAyB;AAAA,MAC7B,QAAAD;AAAA,MACA,eAAeD,EAAM,KAAK;AAAA,MAC1B,SAASA,EAAM,KAAK;AAAA,IAAA;AAGtB,KAAKC,MAAW,gBAAgBA,MAAW,gBAAgB,OAAOV,EAAQ,aAAc,aACtFA,EAAQ,UAAUW,CAAI,IACbD,MAAW,YAAY,OAAOV,EAAQ,aAAc,aAC7DA,EAAQ,UAAUW,CAAI,KACZD,MAAW,eAAeA,MAAW,cAAc,OAAOV,EAAQ,WAAY,cACxFA,EAAQ,QAAQW,CAAI;AAAA,EAExB;AAKA,OAHA,OAAO,iBAAiB,WAAWH,CAAS,GAGrCP,EAAU;AACf,IAAAA,EAAU,YAAYA,EAAU,UAAU;AAE5C,SAAAA,EAAU,YAAYI,CAAM,GAErB;AAAA,IACL,UAAU;AACR,aAAO,oBAAoB,WAAWG,CAAS,GAC3CH,EAAO,cACTA,EAAO,WAAW,YAAYA,CAAM;AAAA,IAExC;AAAA,EAAA;AAEJ;"}
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":";AA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2 +1,108 @@
1
- (function(a,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(a=typeof globalThis<"u"?globalThis:a||self,i(a.Flashpay={}))})(this,(function(a){"use strict";const i="https://pay.flashpayweb.com",l={width:"100%",height:"600px",border:"none",borderRadius:"8px"};function h(){if(typeof document>"u")return i;const e=document.getElementsByTagName("script");for(let n=0;n<e.length;n++){const s=e[n].src||"";if(s.indexOf("/sdk/flashpay")!==-1||s.indexOf("flashpay.umd.js")!==-1)try{return new URL(s).origin}catch{}}return i}function y(e){if(!e||!e.transactionId)throw new Error("Flashpay: transactionId is required");if(!e.container)throw new Error("Flashpay: container is required");const n=typeof e.container=="string"?document.querySelector(e.container):e.container;if(!n){const t=typeof e.container=="string"?e.container:"the provided HTMLElement";throw new Error(`Flashpay: container element not found for ${t}`)}const s=Object.assign({},l,e.style||{}),d=e.origin||h(),r=document.createElement("iframe"),c=new URL(d+"/pay/"+encodeURIComponent(e.transactionId));e.showTitle&&c.searchParams.set("showTitle","true"),e.showDescription&&c.searchParams.set("showDescription","true"),e.showAmount&&c.searchParams.set("showAmount","true"),c.searchParams.set("parentOrigin",window.location.origin),r.src=c.toString(),r.title="Flashpay payment",r.setAttribute("allow","payment; popups"),r.setAttribute("loading","lazy"),Object.keys(s).forEach(t=>{r.style[t]=s[t]});function u(t){if(t.origin!==d||!t.data||t.data.type!=="flashpay:payment_status")return;const o=t.data.status,f={status:o,transactionId:t.data.transactionId,payment:t.data.payment};(o==="SUCCESSFUL"||o==="COMPLETED")&&typeof e.onSuccess=="function"?e.onSuccess(f):o==="FAILED"&&typeof e.onFailure=="function"?e.onFailure(f):(o==="CANCELLED"||o==="EXPIRED")&&typeof e.onClose=="function"&&e.onClose(f)}for(window.addEventListener("message",u);n.firstChild;)n.removeChild(n.firstChild);return n.appendChild(r),{destroy(){window.removeEventListener("message",u),r.parentNode&&r.parentNode.removeChild(r)}}}a.checkout=y,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
2
- //# sourceMappingURL=flashpay.umd.js.map
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
@@ -1 +1 @@
1
- {"version":3,"file":"flashpay.umd.js","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 showTitle?: boolean;\n showDescription?: boolean;\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) url.searchParams.set(\"showTitle\", \"true\");\n if (options.showDescription) url.searchParams.set(\"showDescription\", \"true\");\n if (options.showAmount) url.searchParams.set(\"showAmount\", \"true\");\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"],"names":["DEFAULT_ORIGIN","DEFAULT_STYLE","detectOrigin","scripts","i","src","checkout","options","container","identifier","style","origin","iframe","url","key","onMessage","event","status","data"],"mappings":"iOAmCA,MAAMA,EAAiB,8BAEjBC,EAA8C,CAClD,MAAO,OACP,OAAQ,QACR,OAAQ,OACR,aAAc,KAChB,EAMA,SAASC,GAAuB,CAC9B,GAAI,OAAO,SAAa,IAAa,OAAOF,EAE5C,MAAMG,EAAU,SAAS,qBAAqB,QAAQ,EACtD,QAASC,EAAI,EAAGA,EAAID,EAAQ,OAAQC,IAAK,CACvC,MAAMC,EAAMF,EAAQC,CAAC,EAAE,KAAO,GAC9B,GAAIC,EAAI,QAAQ,eAAe,IAAM,IAAMA,EAAI,QAAQ,iBAAiB,IAAM,GAC5E,GAAI,CAEF,OADY,IAAI,IAAIA,CAAG,EACZ,MACb,MAAY,CAAC,CAEjB,CACA,OAAOL,CACT,CAQO,SAASM,EAASC,EAA4C,CACnE,GAAI,CAACA,GAAW,CAACA,EAAQ,cACvB,MAAM,IAAI,MAAM,qCAAqC,EAEvD,GAAI,CAACA,EAAQ,UACX,MAAM,IAAI,MAAM,iCAAiC,EAGnD,MAAMC,EACJ,OAAOD,EAAQ,WAAc,SACzB,SAAS,cAA2BA,EAAQ,SAAS,EACrDA,EAAQ,UAEd,GAAI,CAACC,EAAW,CACd,MAAMC,EAAa,OAAOF,EAAQ,WAAc,SAAWA,EAAQ,UAAY,2BAC/E,MAAM,IAAI,MAAM,6CAA6CE,CAAU,EAAE,CAC3E,CAEA,MAAMC,EAAQ,OAAO,OAAO,CAAA,EAAIT,EAAeM,EAAQ,OAAS,EAAE,EAC5DI,EAASJ,EAAQ,QAAUL,EAAA,EAE3BU,EAAS,SAAS,cAAc,QAAQ,EACxCC,EAAM,IAAI,IAAIF,EAAS,QAAU,mBAAmBJ,EAAQ,aAAa,CAAC,EAE5EA,EAAQ,WAAWM,EAAI,aAAa,IAAI,YAAa,MAAM,EAC3DN,EAAQ,iBAAiBM,EAAI,aAAa,IAAI,kBAAmB,MAAM,EACvEN,EAAQ,YAAYM,EAAI,aAAa,IAAI,aAAc,MAAM,EACjEA,EAAI,aAAa,IAAI,eAAgB,OAAO,SAAS,MAAM,EAE3DD,EAAO,IAAMC,EAAI,SAAA,EACjBD,EAAO,MAAQ,mBACfA,EAAO,aAAa,QAAS,iBAAiB,EAC9CA,EAAO,aAAa,UAAW,MAAM,EAErC,OAAO,KAAKF,CAAK,EAAE,QAASI,GAAQ,CACjCF,EAAO,MAAcE,CAAG,EAAKJ,EAAcI,CAAG,CACjD,CAAC,EAED,SAASC,EAAUC,EAAqB,CAEtC,GADIA,EAAM,SAAWL,GACjB,CAACK,EAAM,MAAQA,EAAM,KAAK,OAAS,0BAA2B,OAElE,MAAMC,EAASD,EAAM,KAAK,OACpBE,EAAyB,CAC7B,OAAAD,EACA,cAAeD,EAAM,KAAK,cAC1B,QAASA,EAAM,KAAK,OAAA,GAGjBC,IAAW,cAAgBA,IAAW,cAAgB,OAAOV,EAAQ,WAAc,WACtFA,EAAQ,UAAUW,CAAI,EACbD,IAAW,UAAY,OAAOV,EAAQ,WAAc,WAC7DA,EAAQ,UAAUW,CAAI,GACZD,IAAW,aAAeA,IAAW,YAAc,OAAOV,EAAQ,SAAY,YACxFA,EAAQ,QAAQW,CAAI,CAExB,CAKA,IAHA,OAAO,iBAAiB,UAAWH,CAAS,EAGrCP,EAAU,YACfA,EAAU,YAAYA,EAAU,UAAU,EAE5C,OAAAA,EAAU,YAAYI,CAAM,EAErB,CACL,SAAU,CACR,OAAO,oBAAoB,UAAWG,CAAS,EAC3CH,EAAO,YACTA,EAAO,WAAW,YAAYA,CAAM,CAExC,CAAA,CAEJ"}
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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-sdk",
3
- "version": "0.1.0",
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/index.d.ts",
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": "vite build && cp dist/flashpay.umd.js ../../public/sdk/flashpay.js",
23
- "dev": "vite build --watch",
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
- "vite": "^7.3.1",
42
- "vite-plugin-dts": "^4.5.4",
41
+ "tsup": "^8.5.0",
43
42
  "vitest": "^3.0.0"
44
43
  }
45
44
  }
@@ -1 +0,0 @@
1
- export {};