@flash-pay/browser-sdk 0.1.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 +2 -0
- package/dist/flashpay.cjs.js.map +1 -0
- package/dist/flashpay.es.js +54 -0
- package/dist/flashpay.es.js.map +1 -0
- package/dist/flashpay.umd.js +2 -0
- package/dist/flashpay.umd.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.test.d.ts +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
@@ -0,0 +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","options","container","identifier","style","origin","iframe","url","key","onMessage","event","status","data"],"mappings":"gFAmCA,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,M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,CACR,OAAO,oBAAoB,UAAWG,CAAS,EAC3CH,EAAO,YACTA,EAAO,WAAW,YAAYA,CAAM,CAExC,CAAA,CAEJ"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const f = "https://pay.flashpayweb.com", u = {
|
|
2
|
+
width: "100%",
|
|
3
|
+
height: "600px",
|
|
4
|
+
border: "none",
|
|
5
|
+
borderRadius: "8px"
|
|
6
|
+
};
|
|
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)
|
|
13
|
+
try {
|
|
14
|
+
return new URL(a).origin;
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return f;
|
|
19
|
+
}
|
|
20
|
+
function h(e) {
|
|
21
|
+
if (!e || !e.transactionId)
|
|
22
|
+
throw new Error("Flashpay: transactionId is required");
|
|
23
|
+
if (!e.container)
|
|
24
|
+
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
|
+
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];
|
|
33
|
+
});
|
|
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
|
|
40
|
+
};
|
|
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);
|
|
42
|
+
}
|
|
43
|
+
for (window.addEventListener("message", d); r.firstChild; )
|
|
44
|
+
r.removeChild(r.firstChild);
|
|
45
|
+
return r.appendChild(n), {
|
|
46
|
+
destroy() {
|
|
47
|
+
window.removeEventListener("message", d), n.parentNode && n.parentNode.removeChild(n);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
h as checkout
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=flashpay.es.js.map
|
|
@@ -0,0 +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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,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;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
@@ -0,0 +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,G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,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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export 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
|
+
export interface PaymentEventData {
|
|
12
|
+
status: "SUCCESSFUL" | "COMPLETED" | "FAILED" | "CANCELLED" | "EXPIRED";
|
|
13
|
+
transactionId: string;
|
|
14
|
+
payment: PaymentData;
|
|
15
|
+
}
|
|
16
|
+
export interface FlashpayOptions {
|
|
17
|
+
transactionId: string;
|
|
18
|
+
container: string | HTMLElement;
|
|
19
|
+
showTitle?: boolean;
|
|
20
|
+
showDescription?: boolean;
|
|
21
|
+
showAmount?: boolean;
|
|
22
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
23
|
+
onSuccess?: (data: PaymentEventData) => void;
|
|
24
|
+
onFailure?: (data: PaymentEventData) => void;
|
|
25
|
+
onClose?: (data: PaymentEventData) => void;
|
|
26
|
+
/** Custom origin for Flashpay (e.g. for testing) */
|
|
27
|
+
origin?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface CheckoutInstance {
|
|
30
|
+
destroy: () => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Initialize a Flashpay checkout process.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Configuration options for the checkout
|
|
36
|
+
* @returns An instance that can be used to clean up the checkout
|
|
37
|
+
*/
|
|
38
|
+
export declare function checkout(options: FlashpayOptions): CheckoutInstance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flash-pay/browser-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Flashpay Browser SDK for easy payment integration",
|
|
5
|
+
"main": "./dist/flashpay.cjs.js",
|
|
6
|
+
"module": "./dist/flashpay.es.js",
|
|
7
|
+
"browser": "./dist/flashpay.umd.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"browser": "./dist/flashpay.es.js",
|
|
13
|
+
"import": "./dist/flashpay.es.js",
|
|
14
|
+
"require": "./dist/flashpay.cjs.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "vite build && cp dist/flashpay.umd.js ../../public/sdk/flashpay.js",
|
|
23
|
+
"dev": "vite build --watch",
|
|
24
|
+
"lint": "eslint src",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"flashpay",
|
|
30
|
+
"payments",
|
|
31
|
+
"sdk",
|
|
32
|
+
"checkout",
|
|
33
|
+
"browser"
|
|
34
|
+
],
|
|
35
|
+
"author": "Flashpay",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"ajv": "^8.18.0",
|
|
39
|
+
"jsdom": "^26.0.0",
|
|
40
|
+
"typescript": "^5.3.3",
|
|
41
|
+
"vite": "^7.3.1",
|
|
42
|
+
"vite-plugin-dts": "^4.5.4",
|
|
43
|
+
"vitest": "^3.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|