UNPKG

@rebilly/framepay

Version:

A wrapper to load Rebilly's FramePay library and provide TypeScript types

30 lines (29 loc) 1 kB
const DEFAULT_SCRIPT_LINK = "https://framepay.rebilly.com/framepay.js"; const DEFAULT_STYLE_LINK = "https://framepay.rebilly.com/framepay.css"; async function loadFramepay({ scriptLink, styleLink } = {}) { return new Promise((resolve, reject) => { if (window.Framepay) { resolve(window.Framepay); } else { const framepayStyle = document.createElement("link"); framepayStyle.setAttribute("href", styleLink || DEFAULT_STYLE_LINK); framepayStyle.setAttribute("rel", "stylesheet"); document.head.prepend(framepayStyle); const framepayScript = document.createElement("script"); framepayScript.setAttribute("src", scriptLink || DEFAULT_SCRIPT_LINK); framepayScript.onload = () => resolve(window.Framepay); framepayScript.onerror = () => reject( new Error( "@rebilly/framepay npm package: Failed to load FramePay script" ) ); document.head.append(framepayScript); } }); } export { loadFramepay };