@square/web-sdk
Version:
Square Web SDK
2 lines (1 loc) • 1.52 kB
JavaScript
var l=(r,t,e)=>new Promise((n,i)=>{var p=o=>{try{c(e.next(o))}catch(a){i(a)}},m=o=>{try{c(e.throw(o))}catch(a){i(a)}},c=o=>o.done?n(o.value):Promise.resolve(o.value).then(p,m);c((e=e.apply(r,t)).next())});function f(r){return document.querySelector(`script[src="${r}"]`)}function w(r){let t=document.head||document.body;if(!t)throw new Error("Square.js requires a <body> or <head> element.");let e=document.createElement("script");return e.src=r,t.appendChild(e),e}var s=null;function d(r){return s!==null||(s=new Promise((t,e)=>{if(typeof window=="undefined"){t(null);return}if(window.Square){t(window.Square);return}try{let n=f(r);n||(n=w(r)),n.addEventListener("load",()=>{window.Square?t(window.Square):e(new Error("Square.js failed to load properly."))}),n.addEventListener("error",()=>{e(new Error("Error occurred while loading Square.js"))})}catch(n){e(n)}})),s}var S="v1",u=class r extends Error{constructor(t="The Payment 'applicationId' option is not in the correct format."){super(t),this.name="InvalidApplicationIdError",Object.setPrototypeOf(this,r.prototype)}};function y(r){let t="";if(typeof r!="string"||r===null)throw new u;if(r.startsWith("sq0idp-")&&(t="https://web.squarecdn.com/"),r.startsWith("sandbox-sq0idb-")&&(t="https://sandbox.web.squarecdn.com/"),t.length===0)throw new u;return t+=`${S}/square.js`,t}function E(r,t,e){return l(this,null,function*(){let n=(e==null?void 0:e.scriptSrc)===void 0?y(r):e.scriptSrc,i=yield d(n);return i===null?null:i.payments(r,t)})}export{E as payments};