@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
2 lines (1 loc) • 1.82 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");let c=null;function f(){const o=n.ref(null),a=r=>{const e=document.createElement("script");e.src=r,e.defer=!0,e.onload=()=>{},e.onerror=()=>{console.error("Failed to load Spotflow Inline SDK script.")},document.head.appendChild(e)},l=(r=1e4)=>c||(c=new Promise((e,t)=>{if(window.SpotflowCheckout)return e(window.SpotflowCheckout);const u=Date.now(),d=setInterval(()=>{window.SpotflowCheckout?(clearInterval(d),e(window.SpotflowCheckout)):Date.now()-u>r&&(clearInterval(d),t(new Error("SpotflowCheckout SDK not loaded after "+r+"ms. Ensure the CDN script is in your HTML.")))},50)}),c),s=async r=>{if(await a("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 l();try{if(window.SpotflowCheckout){const t=window.SpotflowCheckout;o.value=new t.CheckoutForm,o.value.setup(r)}else throw console.error("try to load popup error"),new Error("SpotflowCheckout SDK is not loaded")}catch(t){console.error("Error loading popup:",t)}},i=()=>{o.value&&typeof o.value.destroy=="function"&&o.value.destroy(),o.value=null};return n.onUnmounted(i),s}const w=["disabled"],p=n.defineComponent({inheritAttrs:!1,__name:"spotflow",props:{config:{},disabled:{type:Boolean,default:!1},class:{},style:{}},setup(o,{expose:a}){const l=o,s=n.ref(null),i=f(),r=n.computed(()=>l.class),e=async t=>{l.disabled||(t.preventDefault(),await i(l.config))};return a({buttonRef:s}),(t,u)=>(n.openBlock(),n.createElementBlock("button",n.mergeProps({ref_key:"buttonRef",ref:s},t.$attrs,{disabled:o.disabled,class:r.value,style:o.style,onClick:e}),[n.renderSlot(t.$slots,"default")],16,w))}});exports.SpotflowButton=p;exports.useSpotflowPayment=f;