@spot-flow/checkout-inline-js 0.1.32-dev.5 → 0.1.32-dev.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35530,7 +35530,7 @@ class uu {
35530
35530
  this.email,
35531
35531
  this.amount,
35532
35532
  this.currency
35533
- ), this.cleanup(), this.switchTab(""), this.showPaymentMethods(), this.enablePaymentMethods(), this.renderPaymentMethodContent(), P.track("retry_payment");
35533
+ ), this.cleanup(), this.switchTab(""), this.showPaymentMethods(), this.setupPaymentMethodButtons(), this.renderPaymentMethodContent(), P.track("retry_payment");
35534
35534
  }
35535
35535
  defaultToEmptyContainer() {
35536
35536
  const e = document.querySelector(
@@ -35565,11 +35565,14 @@ class uu {
35565
35565
  }
35566
35566
  enablePaymentMethods() {
35567
35567
  const e = document.querySelectorAll(".tab-button");
35568
- e.forEach((t) => t.removeAttribute("disabled"));
35568
+ e.forEach((t) => {
35569
+ const s = t.getAttribute("data-name");
35570
+ s && !this.disabledChannels.includes(s) && t.removeAttribute("disabled");
35571
+ });
35569
35572
  const i = Array.from(e).find(
35570
35573
  (t) => t.getAttribute("data-name") === this.currentPaymentMethod
35571
35574
  );
35572
- i && i.removeAttribute("disabled");
35575
+ i && !this.disabledChannels.includes(this.currentPaymentMethod) && i.removeAttribute("disabled");
35573
35576
  }
35574
35577
  hidePaymentMethods() {
35575
35578
  const e = document.querySelector("#payment-methods-container");
@@ -35785,7 +35788,7 @@ class gu {
35785
35788
  merchant: this.merchantPlanDetail.merchantName
35786
35789
  }), P.track("checkout_opens");
35787
35790
  const { validChannels: t, disabledChannels: s } = this.getAvailableChannels();
35788
- if (t.length === 0) {
35791
+ if (t.length === 0 || t[0] === "ussd") {
35789
35792
  const r = new hu(this.mainLayout);
35790
35793
  this.mainError = r;
35791
35794
  let l = 0;
@@ -1376,7 +1376,7 @@ or you can use record.mirror to access the mirror instance during recording.`;le
1376
1376
  </svg>
1377
1377
  <span class="text-tone-100 font-semibold">
1378
1378
  Go back
1379
- </span>`),i&&(i.innerHTML="Selected")):(e&&(e.classList.remove("flex","items-center","gap-2","mb-2"),e.innerHTML=""),i&&(i.innerHTML="Select your preferred")))}closeBTN(e){(()=>{this.cleanup(),e?(P.track("checkout_closes"),this.closeModal()):this.closePayment()})()}updatePaymentMethodView(e,i,t,o){switch(this.currentPaymentMethod){case"card":return this.card=new Ir({container:this.modalContainer,amount:t,currency:o,token:e,email:i,planId:this.planId,rdtCode:this.rdtCode,url:this.url,reference:this.reference,encryption:this.encryption,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,switchTab:()=>this.switchTab("card"),hidePaymentMethods:this.hidePaymentMethods.bind(this),showPaymentMethods:this.showPaymentMethods.bind(this),onClose:s=>{this.closeBTN.bind(this)(s)},restartTransactionProcess:this.setToDefaultEmptyContainer.bind(this),retryingPayment:this.retryingPayment});case"bank_transfer":return this.transfer=new Gr({amount:t,currency:o,closeModal:this.closeModal.bind(this),token:e,container:this.modalContainer,email:i,rdtCode:this.rdtCode,url:this.url,reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,disablePaymentMethods:s=>{this.disablePaymentMethods.bind(this)(s)},restartTransactionProcess:this.setToDefaultEmptyContainer.bind(this),hidePaymentMethods:this.hidePaymentMethods.bind(this),retryingPayment:this.retryingPayment});case"ussd":return this.ussd=new qo({container:this.modalContainer,amount:t,currency:o,secret:this.merchantKey,rdtCode:this.rdtCode,url:this.url,email:this.email,reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,closeModal:()=>this.closeModal(),switchTab:s=>this.switchTab.bind(s),hidePaymentMethods:this.hidePaymentMethods.bind(this),showPaymentMethods:this.showPaymentMethods.bind(this),disablePaymentMethods:s=>{this.disablePaymentMethods.bind(this)(s)}});case"mobile_money":return this.mobileMoney=new cl({container:this.modalContainer,email:this.email,currency:o,rdtCode:this.rdtCode,url:this.url,token:e,amount:this.amount,metadata:this.metadata,localCurrency:this.localCurrency,phoneNumber:this.phoneNumber,code:this.code,callBackUrl:this.callBackUrl,merchantKey:this.merchantKey,reference:this.reference,closeModal:()=>this.closeModal(),hidePaymentMethods:this.hidePaymentMethods.bind(this),showPaymentMethods:this.showPaymentMethods.bind(this),disablePaymentMethods:s=>{this.disablePaymentMethods.bind(this)(s)},onClose:s=>{this.closeBTN.bind(this)(s)},restartTransactionProcess:this.setToDefaultEmptyContainer.bind(this),retryingPayment:this.retryingPayment});case"eft":return this.eft=new ml({container:this.modalContainer,amount:t,currency:o,token:e,email:i,rdtCode:this.rdtCode,url:this.url,reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,switchTab:()=>this.switchTab("eft"),hidePaymentMethods:this.hidePaymentMethods.bind(this),showPaymentMethods:this.showPaymentMethods.bind(this),onClose:s=>{this.closeBTN.bind(this)(s)},restartTransactionProcess:this.setToDefaultEmptyContainer.bind(this),retryingPayment:this.retryingPayment});default:return null}}renderPaymentMethodContent(){return(()=>{switch(this.currentPaymentMethod){case"card":return this.card.renderCardContent(this.merchantPlanDetail);case"bank_transfer":return this.transfer.renderTransferContent(this.merchantPlanDetail);case"ussd":return this.ussd.renderUssdContent(this.merchantPlanDetail);case"mobile_money":return this.mobileMoney.renderMobileMoneyContent(this.merchantPlanDetail);case"eft":return this.eft.renderEftContent(this.merchantPlanDetail);default:return this.defaultToEmptyContainer()}})()}setCurrentPaymentMethod(e){this.currentPaymentMethod=e;const i=document.querySelectorAll(".tab-button");i.forEach(o=>o.classList.remove("active"));const t=Array.from(i).find(o=>o.getAttribute("data-name")===e);t&&t.classList.add("active")}setToDefaultEmptyContainer(){this.currentPaymentMethod="",this.retryingPayment=!0,this.updatePaymentMethodView(this.merchantKey,this.email,this.amount,this.currency),this.cleanup(),this.switchTab(""),this.showPaymentMethods(),this.enablePaymentMethods(),this.renderPaymentMethodContent(),P.track("retry_payment")}defaultToEmptyContainer(){const e=document.querySelector("#payment-content-view");e.innerHTML=""}switchTab(e){this.currentPaymentMethod===e&&e!==""||(this.currentPaymentMethod==="bank_transfer"&&this.currentPaymentMethod!==e&&this.setToDefaultEmptyContainer(),this.setCurrentPaymentMethod(e),this.updatePaymentMethodView(this.merchantKey,this.email,this.amount,this.currency),this.cleanup(),this.showPaymentMethods(),this.renderPaymentMethodContent(),this.attachListeners(),this.isMobile&&(document.querySelectorAll(".tab-button").forEach(t=>{const o=t.getAttribute("data-name");this.disabledChannels.includes(o)||t.removeAttribute("disabled")}),e?document.querySelectorAll(".tab-button").forEach(o=>{o.getAttribute("data-name")!==e&&o.classList.add("hidden")}):document.querySelectorAll(".tab-button").forEach(o=>{const s=o.getAttribute("data-name");[...this.validChannels,...this.disabledChannels].includes(s)&&o.classList.remove("hidden")})))}disablePaymentMethods(e){this.currentPaymentMethod=e;const i=document.querySelectorAll(".tab-button");i.forEach(o=>o.setAttribute("disabled","true"));const t=Array.from(i).find(o=>o.getAttribute("data-name")===e);t&&t.removeAttribute("disabled")}enablePaymentMethods(){const e=document.querySelectorAll(".tab-button");e.forEach(t=>t.removeAttribute("disabled"));const i=Array.from(e).find(t=>t.getAttribute("data-name")===this.currentPaymentMethod);i&&i.removeAttribute("disabled")}hidePaymentMethods(){const e=document.querySelector("#payment-methods-container");e&&e.classList.add("hidden")}showPaymentMethods(){const e=document.querySelector("#payment-methods-container");e&&e.classList.remove("hidden")}cleanup(){this.transfer&&this.transfer.destroyTimer()}closeModal(e){this.modalContainer&&this.modalContainer.parentNode&&document.body.removeChild(this.modalContainer),e&&e()}setupParent(e){e&&e()}render(){return vs}}class Zo{constructor(e){m(this,"container");this.container=e}renderContent(e){var t;this.container.innerHTML=this.render();const i=document.getElementById("error-action-container");e&&i&&(i.classList.remove("hidden"),(t=i.querySelector("#go-back"))==null||t.addEventListener("click",()=>{window.location.href=e}))}render(){return`
1379
+ </span>`),i&&(i.innerHTML="Selected")):(e&&(e.classList.remove("flex","items-center","gap-2","mb-2"),e.innerHTML=""),i&&(i.innerHTML="Select your preferred")))}closeBTN(e){(()=>{this.cleanup(),e?(P.track("checkout_closes"),this.closeModal()):this.closePayment()})()}updatePaymentMethodView(e,i,t,o){switch(this.currentPaymentMethod){case"card":return this.card=new Ir({container:this.modalContainer,amount:t,currency:o,token:e,email:i,planId:this.planId,rdtCode:this.rdtCode,url:this.url,reference:this.reference,encryption:this.encryption,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,switchTab:()=>this.switchTab("card"),hidePaymentMethods:this.hidePaymentMethods.bind(this),showPaymentMethods:this.showPaymentMethods.bind(this),onClose:s=>{this.closeBTN.bind(this)(s)},restartTransactionProcess:this.setToDefaultEmptyContainer.bind(this),retryingPayment:this.retryingPayment});case"bank_transfer":return this.transfer=new Gr({amount:t,currency:o,closeModal:this.closeModal.bind(this),token:e,container:this.modalContainer,email:i,rdtCode:this.rdtCode,url:this.url,reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,disablePaymentMethods:s=>{this.disablePaymentMethods.bind(this)(s)},restartTransactionProcess:this.setToDefaultEmptyContainer.bind(this),hidePaymentMethods:this.hidePaymentMethods.bind(this),retryingPayment:this.retryingPayment});case"ussd":return this.ussd=new qo({container:this.modalContainer,amount:t,currency:o,secret:this.merchantKey,rdtCode:this.rdtCode,url:this.url,email:this.email,reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,closeModal:()=>this.closeModal(),switchTab:s=>this.switchTab.bind(s),hidePaymentMethods:this.hidePaymentMethods.bind(this),showPaymentMethods:this.showPaymentMethods.bind(this),disablePaymentMethods:s=>{this.disablePaymentMethods.bind(this)(s)}});case"mobile_money":return this.mobileMoney=new cl({container:this.modalContainer,email:this.email,currency:o,rdtCode:this.rdtCode,url:this.url,token:e,amount:this.amount,metadata:this.metadata,localCurrency:this.localCurrency,phoneNumber:this.phoneNumber,code:this.code,callBackUrl:this.callBackUrl,merchantKey:this.merchantKey,reference:this.reference,closeModal:()=>this.closeModal(),hidePaymentMethods:this.hidePaymentMethods.bind(this),showPaymentMethods:this.showPaymentMethods.bind(this),disablePaymentMethods:s=>{this.disablePaymentMethods.bind(this)(s)},onClose:s=>{this.closeBTN.bind(this)(s)},restartTransactionProcess:this.setToDefaultEmptyContainer.bind(this),retryingPayment:this.retryingPayment});case"eft":return this.eft=new ml({container:this.modalContainer,amount:t,currency:o,token:e,email:i,rdtCode:this.rdtCode,url:this.url,reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,switchTab:()=>this.switchTab("eft"),hidePaymentMethods:this.hidePaymentMethods.bind(this),showPaymentMethods:this.showPaymentMethods.bind(this),onClose:s=>{this.closeBTN.bind(this)(s)},restartTransactionProcess:this.setToDefaultEmptyContainer.bind(this),retryingPayment:this.retryingPayment});default:return null}}renderPaymentMethodContent(){return(()=>{switch(this.currentPaymentMethod){case"card":return this.card.renderCardContent(this.merchantPlanDetail);case"bank_transfer":return this.transfer.renderTransferContent(this.merchantPlanDetail);case"ussd":return this.ussd.renderUssdContent(this.merchantPlanDetail);case"mobile_money":return this.mobileMoney.renderMobileMoneyContent(this.merchantPlanDetail);case"eft":return this.eft.renderEftContent(this.merchantPlanDetail);default:return this.defaultToEmptyContainer()}})()}setCurrentPaymentMethod(e){this.currentPaymentMethod=e;const i=document.querySelectorAll(".tab-button");i.forEach(o=>o.classList.remove("active"));const t=Array.from(i).find(o=>o.getAttribute("data-name")===e);t&&t.classList.add("active")}setToDefaultEmptyContainer(){this.currentPaymentMethod="",this.retryingPayment=!0,this.updatePaymentMethodView(this.merchantKey,this.email,this.amount,this.currency),this.cleanup(),this.switchTab(""),this.showPaymentMethods(),this.setupPaymentMethodButtons(),this.renderPaymentMethodContent(),P.track("retry_payment")}defaultToEmptyContainer(){const e=document.querySelector("#payment-content-view");e.innerHTML=""}switchTab(e){this.currentPaymentMethod===e&&e!==""||(this.currentPaymentMethod==="bank_transfer"&&this.currentPaymentMethod!==e&&this.setToDefaultEmptyContainer(),this.setCurrentPaymentMethod(e),this.updatePaymentMethodView(this.merchantKey,this.email,this.amount,this.currency),this.cleanup(),this.showPaymentMethods(),this.renderPaymentMethodContent(),this.attachListeners(),this.isMobile&&(document.querySelectorAll(".tab-button").forEach(t=>{const o=t.getAttribute("data-name");this.disabledChannels.includes(o)||t.removeAttribute("disabled")}),e?document.querySelectorAll(".tab-button").forEach(o=>{o.getAttribute("data-name")!==e&&o.classList.add("hidden")}):document.querySelectorAll(".tab-button").forEach(o=>{const s=o.getAttribute("data-name");[...this.validChannels,...this.disabledChannels].includes(s)&&o.classList.remove("hidden")})))}disablePaymentMethods(e){this.currentPaymentMethod=e;const i=document.querySelectorAll(".tab-button");i.forEach(o=>o.setAttribute("disabled","true"));const t=Array.from(i).find(o=>o.getAttribute("data-name")===e);t&&t.removeAttribute("disabled")}enablePaymentMethods(){const e=document.querySelectorAll(".tab-button");e.forEach(t=>{const o=t.getAttribute("data-name");o&&!this.disabledChannels.includes(o)&&t.removeAttribute("disabled")});const i=Array.from(e).find(t=>t.getAttribute("data-name")===this.currentPaymentMethod);i&&!this.disabledChannels.includes(this.currentPaymentMethod)&&i.removeAttribute("disabled")}hidePaymentMethods(){const e=document.querySelector("#payment-methods-container");e&&e.classList.add("hidden")}showPaymentMethods(){const e=document.querySelector("#payment-methods-container");e&&e.classList.remove("hidden")}cleanup(){this.transfer&&this.transfer.destroyTimer()}closeModal(e){this.modalContainer&&this.modalContainer.parentNode&&document.body.removeChild(this.modalContainer),e&&e()}setupParent(e){e&&e()}render(){return vs}}class Zo{constructor(e){m(this,"container");this.container=e}renderContent(e){var t;this.container.innerHTML=this.render();const i=document.getElementById("error-action-container");e&&i&&(i.classList.remove("hidden"),(t=i.querySelector("#go-back"))==null||t.addEventListener("click",()=>{window.location.href=e}))}render(){return`
1380
1380
  <div class="box-container">
1381
1381
 
1382
1382
  <div class="container-center h-[40vh] hidden mx-auto" id="shared-error-container">
@@ -1410,4 +1410,4 @@ or you can use record.mirror to access the mirror instance during recording.`;le
1410
1410
 
1411
1411
  </div>
1412
1412
  </div>
1413
- `}}class vl{constructor(){m(this,"modalContainer");m(this,"mainLayout");m(this,"encryption");m(this,"mainScreen");m(this,"merchantConfigService");m(this,"mainError");m(this,"mainLoader");m(this,"merchantPlanDetail",{});m(this,"merchantKey");m(this,"planId");m(this,"email");m(this,"amount");m(this,"rdtCode");m(this,"url");m(this,"phoneNumber");m(this,"code");m(this,"reference");m(this,"currency");m(this,"callBackUrl");m(this,"metadata");m(this,"localCurrency");this.merchantKey="",this.email="",this.amount=0,this.planId="",this.encryption="",this.phoneNumber="",this.code="",this.modalContainer=document.createElement("div"),this.rdtCode="",this.reference="",this.currency="",this.url="",this.callBackUrl="",this.metadata={},this.localCurrency="",this.modalContainer.innerHTML=Ln,P.init("11162d9a0801daeaf786f1200cd3112b",{debug:!1}),document.body.appendChild(this.modalContainer);const i=document.getElementById("main-layout-container-screen");if(!i)throw new Error("SDK Layout not available");this.mainLayout=i}closePayment(){const e={reference:this.reference};ks(this.merchantKey,e,this.rdtCode,this.url).then(({headers:t})=>{const o=t.get("spf-redirect-url");this.callBackUrl=o||this.callBackUrl,this.callBackUrl?setTimeout(()=>{const s=new URL(this.callBackUrl);s.searchParams.append("status","cancelled"),s.searchParams.append("reference",this.reference),window.location.href=s.toString()},1800):this.closeModal(),P.track("canel_payment",{verification_status:"Cancelled"}),P.track("checkout_closes")}).catch(t=>{li.showToast(t.message,"error")})}getDeviceType(){const e=navigator.userAgent;return/mobile/i.test(e)?"Mobile":/tablet/i.test(e)?"Tablet":"Desktop"}setup(e){const{email:i,encryptionKey:t,merchantKey:o,planId:s,amount:r,rdtCode:l,reference:c,currency:b,url:p,callBackUrl:g,metadata:f,localCurrency:y}=e;if(this.merchantKey=o||"",this.email=i||"",this.amount=r||0,this.encryption=t||"",this.planId=s||"",this.rdtCode=l||"",this.reference=c||_s(),this.url=p||"",this.callBackUrl=g||"",this.metadata=f||{},!o||!i)throw this.mainError=new Zo(this.mainLayout),this.mainError.renderContent(this.callBackUrl),this.showErrorIcon(),new Error("Merchant key or email is required");this.currency=b||"",this.merchantConfigService=new Vr({token:this.merchantKey,rdtCode:this.rdtCode,url:this.url}),this.localCurrency=y||"",this.mainScreen=new hl({container:this.mainLayout,modalContainer:this.modalContainer,merchantKey:o,email:i,encryption:this.encryption,planId:this.planId,amount:this.amount,rdtCode:this.rdtCode,url:this.url,phoneNumber:this.phoneNumber,code:this.code,reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,closePayment:this.closePayment.bind(this)}),this.mainLoader=new Ie(this.mainLayout),this.mainError=new Zo(this.mainLayout),this.mainLoader.mountLoader(),this.getPlanDetails()}getAvailableChannels(){var s,r;const e=((s=this.merchantPlanDetail)==null?void 0:s.paymentMethods)??[],i=((r=this.merchantPlanDetail)==null?void 0:r.limits)??[],t=[],o=[];return e.forEach(l=>{const c=i.find(b=>b.channel===l);!c||this.amount<=c.amount?t.push(l):o.push(l)}),{validChannels:t,disabledChannels:o}}async getPlanDetails(){const e=this.currency==="USD"?this.localCurrency:this.currency;this.merchantConfigService.getMerchantConfig(this.planId,e).then(i=>{var s;this.merchantPlanDetail=i,P.register({device_type:this.getDeviceType(),session_id:this.reference,env:"Test",checkout_env:this.rdtCode?"Redirect":"SDK",merchant:this.merchantPlanDetail.merchantName}),P.track("checkout_opens");const{validChannels:t,disabledChannels:o}=this.getAvailableChannels();if(t.length===0){const r=new bl(this.mainLayout);this.mainError=r;let l=0;throw(s=this.merchantPlanDetail)!=null&&s.limits&&this.merchantPlanDetail.limits.length>0&&(l=Math.max(...this.merchantPlanDetail.limits.map(c=>c.amount))),r.setLimitInfo(e,l),this.mainError.renderContent(this.callBackUrl),this.showErrorIcon(),new Error("Transaction limit reached")}i.rate?this.mainScreen.mountScreen(this.merchantPlanDetail,this.currency,t,o):(this.mainError.renderContent(this.callBackUrl),this.showErrorIcon())}).catch(i=>{throw this.mainError.renderContent(this.callBackUrl),this.showErrorIcon(),new Error(i)})}showErrorIcon(){var i;const e=this.mainLayout.querySelector("#shared-error-container");e&&(e.classList.remove("hidden"),e.parentElement.classList.add("mx-auto"),e.classList.add("flex","flex-col","items-center","gap-2"),(i=e.querySelector("img"))==null||i.setAttribute("src",pl))}closeModal(){this.modalContainer&&this.modalContainer.parentNode&&document.body.removeChild(this.modalContainer),this.mainScreen.closeModal()}}Ne.CheckoutForm=vl,Object.defineProperty(Ne,Symbol.toStringTag,{value:"Module"})});
1413
+ `}}class vl{constructor(){m(this,"modalContainer");m(this,"mainLayout");m(this,"encryption");m(this,"mainScreen");m(this,"merchantConfigService");m(this,"mainError");m(this,"mainLoader");m(this,"merchantPlanDetail",{});m(this,"merchantKey");m(this,"planId");m(this,"email");m(this,"amount");m(this,"rdtCode");m(this,"url");m(this,"phoneNumber");m(this,"code");m(this,"reference");m(this,"currency");m(this,"callBackUrl");m(this,"metadata");m(this,"localCurrency");this.merchantKey="",this.email="",this.amount=0,this.planId="",this.encryption="",this.phoneNumber="",this.code="",this.modalContainer=document.createElement("div"),this.rdtCode="",this.reference="",this.currency="",this.url="",this.callBackUrl="",this.metadata={},this.localCurrency="",this.modalContainer.innerHTML=Ln,P.init("11162d9a0801daeaf786f1200cd3112b",{debug:!1}),document.body.appendChild(this.modalContainer);const i=document.getElementById("main-layout-container-screen");if(!i)throw new Error("SDK Layout not available");this.mainLayout=i}closePayment(){const e={reference:this.reference};ks(this.merchantKey,e,this.rdtCode,this.url).then(({headers:t})=>{const o=t.get("spf-redirect-url");this.callBackUrl=o||this.callBackUrl,this.callBackUrl?setTimeout(()=>{const s=new URL(this.callBackUrl);s.searchParams.append("status","cancelled"),s.searchParams.append("reference",this.reference),window.location.href=s.toString()},1800):this.closeModal(),P.track("canel_payment",{verification_status:"Cancelled"}),P.track("checkout_closes")}).catch(t=>{li.showToast(t.message,"error")})}getDeviceType(){const e=navigator.userAgent;return/mobile/i.test(e)?"Mobile":/tablet/i.test(e)?"Tablet":"Desktop"}setup(e){const{email:i,encryptionKey:t,merchantKey:o,planId:s,amount:r,rdtCode:l,reference:c,currency:b,url:p,callBackUrl:g,metadata:f,localCurrency:y}=e;if(this.merchantKey=o||"",this.email=i||"",this.amount=r||0,this.encryption=t||"",this.planId=s||"",this.rdtCode=l||"",this.reference=c||_s(),this.url=p||"",this.callBackUrl=g||"",this.metadata=f||{},!o||!i)throw this.mainError=new Zo(this.mainLayout),this.mainError.renderContent(this.callBackUrl),this.showErrorIcon(),new Error("Merchant key or email is required");this.currency=b||"",this.merchantConfigService=new Vr({token:this.merchantKey,rdtCode:this.rdtCode,url:this.url}),this.localCurrency=y||"",this.mainScreen=new hl({container:this.mainLayout,modalContainer:this.modalContainer,merchantKey:o,email:i,encryption:this.encryption,planId:this.planId,amount:this.amount,rdtCode:this.rdtCode,url:this.url,phoneNumber:this.phoneNumber,code:this.code,reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency,closePayment:this.closePayment.bind(this)}),this.mainLoader=new Ie(this.mainLayout),this.mainError=new Zo(this.mainLayout),this.mainLoader.mountLoader(),this.getPlanDetails()}getAvailableChannels(){var s,r;const e=((s=this.merchantPlanDetail)==null?void 0:s.paymentMethods)??[],i=((r=this.merchantPlanDetail)==null?void 0:r.limits)??[],t=[],o=[];return e.forEach(l=>{const c=i.find(b=>b.channel===l);!c||this.amount<=c.amount?t.push(l):o.push(l)}),{validChannels:t,disabledChannels:o}}async getPlanDetails(){const e=this.currency==="USD"?this.localCurrency:this.currency;this.merchantConfigService.getMerchantConfig(this.planId,e).then(i=>{var s;this.merchantPlanDetail=i,P.register({device_type:this.getDeviceType(),session_id:this.reference,env:"Test",checkout_env:this.rdtCode?"Redirect":"SDK",merchant:this.merchantPlanDetail.merchantName}),P.track("checkout_opens");const{validChannels:t,disabledChannels:o}=this.getAvailableChannels();if(t.length===0||t[0]==="ussd"){const r=new bl(this.mainLayout);this.mainError=r;let l=0;throw(s=this.merchantPlanDetail)!=null&&s.limits&&this.merchantPlanDetail.limits.length>0&&(l=Math.max(...this.merchantPlanDetail.limits.map(c=>c.amount))),r.setLimitInfo(e,l),this.mainError.renderContent(this.callBackUrl),this.showErrorIcon(),new Error("Transaction limit reached")}i.rate?this.mainScreen.mountScreen(this.merchantPlanDetail,this.currency,t,o):(this.mainError.renderContent(this.callBackUrl),this.showErrorIcon())}).catch(i=>{throw this.mainError.renderContent(this.callBackUrl),this.showErrorIcon(),new Error(i)})}showErrorIcon(){var i;const e=this.mainLayout.querySelector("#shared-error-container");e&&(e.classList.remove("hidden"),e.parentElement.classList.add("mx-auto"),e.classList.add("flex","flex-col","items-center","gap-2"),(i=e.querySelector("img"))==null||i.setAttribute("src",pl))}closeModal(){this.modalContainer&&this.modalContainer.parentNode&&document.body.removeChild(this.modalContainer),this.mainScreen.closeModal()}}Ne.CheckoutForm=vl,Object.defineProperty(Ne,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spot-flow/checkout-inline-js",
3
- "version": "0.1.32-dev.5",
3
+ "version": "0.1.32-dev.7",
4
4
  "description": "",
5
5
  "main": "dist/checkout-inline.js",
6
6
  "module": "dist/checkout-inline.es.js",