UNPKG

@juspay/blaze-sdk-web

Version:

SDK for integrating Breeze 1CCO into your Web Application

2 lines (1 loc) 2.31 kB
let t=[],e=[],n=null,a=!1;function o(a){if("object"==typeof window.BlazeSDK&&"function"==typeof window.BlazeSDK.initiate&&"function"==typeof window.BlazeSDK.process){if(t.length>0&&(window.BlazeSDK.initiate(t.at(0),a,n),t=[]),e.length>0){const t=e;e=[],t.forEach(t=>{window.BlazeSDK.process(t)})}return!0}{let t=0;const e=setInterval(()=>{t>5&&clearInterval(e);o(a)&&clearInterval(e),t++})}return!1}function i(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}var r={initiate:function(e,r,s=null){try{const l=document.getElementById("breeze-script-tag"),c=l instanceof HTMLScriptElement?l:document.createElement("script");c.type="module",c.id="breeze-script-tag",c.async=!0,t.push(e);const d=i(e)&&i(e.payload)?e.payload:{},p="string"==typeof d.merchantId?d.merchantId:null,u="string"==typeof d.shopUrl?d.shopUrl:null,f="string"==typeof d.shopId?d.shopId:null,b="string"==typeof d.platform?d.platform:null;let y,m;switch(d.environment){case"smbBeta":case"smbRelease":m="https://sdk.breezesdk.store/electron/241.0.3/index.js",y="smbBeta"===d.environment?"beta":"release";break;default:m="https://sdk.breeze.in/electron/241.0.3/index.js",y="beta"===d.environment?"beta":"release"}c.src=m,null!==p&&c.setAttribute("data-merchantid",p),null!==u&&c.setAttribute("data-shopurl",u),null!==f&&c.setAttribute("data-shopid",f),null!==b&&c.setAttribute("data-platform",b),c.setAttribute("data-environment",y),c.setAttribute("data-disable-overlay-events","true"),c.setAttribute("data-app-version","v2"),c.onload=()=>{try{const t=document.createElement("breeze-button");t.style.display="none",document.body.appendChild(t),o(r),a=!0}catch(t){console.error("Error creating Breeze button",t)}},n=s,a&&o(r),l instanceof HTMLScriptElement||document.body.appendChild(c)}catch{}},process:function(t){"object"==typeof window.BlazeSDK&&"function"==typeof window.BlazeSDK.process?window.BlazeSDK.process(t):e.push(t)},terminate:function(){"object"==typeof window.BlazeSDK&&"function"==typeof window.BlazeSDK.terminate&&window.BlazeSDK.terminate(),t=[],e=[],n=null}};class s{static initiatePayload;static callback;static processPayload;static initiate(t,e,n=null){this.callback=e,this.initiatePayload=t,r.initiate(t,e,n)}static process(t){this.processPayload=t,r.process(t)}static terminate(){r.terminate()}}export{s as default};