@rebilly/framepay
Version:
A wrapper to load Rebilly's FramePay library and provide TypeScript types
34 lines (33 loc) • 1.49 kB
JavaScript
(function(global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.framepay = {}));
})(this, function(exports2) {
"use strict";
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);
}
});
}
exports2.loadFramepay = loadFramepay;
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
});