UNPKG

@spot-flow/vue-spotflow-checkout

Version:

This **Spotflow Vue.js library** wraps around the [inline library](https://github.com/Spotflow-One/spotflow-checkout-inline), which enables users to make payments seamlessly. It integrates smoothly into your Vue.js application, providing a streamlined ch

68 lines (67 loc) 2.3 kB
import { ref as d, onUnmounted as f, defineComponent as p, computed as w, createElementBlock as h, openBlock as k, mergeProps as S, renderSlot as m } from "vue"; let c = null; function y() { const e = d(null), s = (n) => { const o = document.createElement("script"); o.src = n, o.defer = !0, o.onload = () => { }, o.onerror = () => { console.error("Failed to load Spotflow Inline SDK script."); }, document.head.appendChild(o); }, r = (n = 1e4) => c || (c = new Promise((o, t) => { if (window.SpotflowCheckout) return o(window.SpotflowCheckout); const i = Date.now(), u = setInterval(() => { window.SpotflowCheckout ? (clearInterval(u), o(window.SpotflowCheckout)) : Date.now() - i > n && (clearInterval(u), t(new Error( "SpotflowCheckout SDK not loaded after " + n + "ms. Ensure the CDN script is in your HTML." ))); }, 50); }), c), l = async (n) => { if (await s("https://v1.inline-checkout.spotflow.one/dist/checkout-inline.js"), typeof window > "u") throw new Error("SpotflowCheckout is not available in the window object"); await r(); try { if (window.SpotflowCheckout) { const t = window.SpotflowCheckout; e.value = new t.CheckoutForm(), e.value.setup(n); } else throw console.error("try to load popup error"), new Error("SpotflowCheckout SDK is not loaded"); } catch (t) { console.error("Error loading popup:", t); } }; return f(() => { e.value && typeof e.value.destroy == "function" && e.value.destroy(), e.value = null; }), l; } const C = ["disabled"], b = /* @__PURE__ */ p({ inheritAttrs: !1, __name: "spotflow", props: { config: {}, disabled: { type: Boolean, default: !1 }, class: {}, style: {} }, setup(e, { expose: s }) { const r = e, l = d(null), a = y(), n = w(() => r.class), o = async (t) => { r.disabled || (t.preventDefault(), await a(r.config)); }; return s({ buttonRef: l }), (t, i) => (k(), h("button", S({ ref_key: "buttonRef", ref: l }, t.$attrs, { disabled: e.disabled, class: n.value, style: e.style, onClick: o }), [ m(t.$slots, "default") ], 16, C)); } }); export { b as SpotflowButton, y as useSpotflowPayment };