@spot-flow/checkout-inline-js 0.2.3 → 0.2.4-dev.1
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.
|
@@ -1685,7 +1685,7 @@ const Fs = new Pl({
|
|
|
1685
1685
|
}), xe = (() => {
|
|
1686
1686
|
let n = navigator == null ? void 0 : navigator.language.split("-")[0].toLowerCase(), e = /* @__PURE__ */ new Map(), t = [], i = 0, s = [], a = !1;
|
|
1687
1687
|
const o = (f) => {
|
|
1688
|
-
n !== f && (n = f,
|
|
1688
|
+
n !== f && (n = f, a = !1, l());
|
|
1689
1689
|
}, l = () => {
|
|
1690
1690
|
t.forEach((f) => f(n));
|
|
1691
1691
|
}, c = () => {
|
|
@@ -1699,7 +1699,7 @@ const Fs = new Pl({
|
|
|
1699
1699
|
i += 1, c();
|
|
1700
1700
|
const x = Array.isArray(f) ? `[${f.join("|")}]:${w}` : `${f}:${w}`;
|
|
1701
1701
|
if (e.has(x))
|
|
1702
|
-
return e.get(x);
|
|
1702
|
+
return i -= 1, c(), e.get(x);
|
|
1703
1703
|
try {
|
|
1704
1704
|
const E = await yl({
|
|
1705
1705
|
text: f,
|
|
@@ -36328,7 +36328,12 @@ const ru = {
|
|
|
36328
36328
|
fr: "Français",
|
|
36329
36329
|
es: "Español",
|
|
36330
36330
|
pt: "Português",
|
|
36331
|
-
ar: "Arabic"
|
|
36331
|
+
ar: "Arabic",
|
|
36332
|
+
zh: "Chinese",
|
|
36333
|
+
hi: "Hindi",
|
|
36334
|
+
nl: "Dutch",
|
|
36335
|
+
et: "Estonian",
|
|
36336
|
+
pl: "Polish"
|
|
36332
36337
|
}, cu = (n) => n == null ? void 0 : n.replace(/_/g, " ");
|
|
36333
36338
|
function Po(n) {
|
|
36334
36339
|
return n.split(" ").map(
|
package/dist/checkout-inline.js
CHANGED
|
@@ -642,7 +642,7 @@
|
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
|
|
645
|
-
`,document.head.appendChild(e)}isLoading(){return this.activeSections.size>0||this.loadingElements.size>0}getLoadingSections(){return Array.from(this.activeSections)}clearAll(){this.stopGlobalLoading(),this.activeSections.clear()}}const Hs=new ir({defaultStyle:"skeleton",fadeOpacity:.5}),Ae=(()=>{let n=navigator==null?void 0:navigator.language.split("-")[0].toLowerCase(),e=new Map,t=[],i=0,s=[],o=!1;const a=f=>{n!==f&&(n=f,
|
|
645
|
+
`,document.head.appendChild(e)}isLoading(){return this.activeSections.size>0||this.loadingElements.size>0}getLoadingSections(){return Array.from(this.activeSections)}clearAll(){this.stopGlobalLoading(),this.activeSections.clear()}}const Hs=new ir({defaultStyle:"skeleton",fadeOpacity:.5}),Ae=(()=>{let n=navigator==null?void 0:navigator.language.split("-")[0].toLowerCase(),e=new Map,t=[],i=0,s=[],o=!1;const a=f=>{n!==f&&(n=f,o=!1,l())},l=()=>{t.forEach(f=>f(n))},c=()=>{s.forEach(f=>f(i>0))},p=f=>(t.push(f),()=>{t=t.filter(k=>k!==f)}),m=async(f,k=n,x="static")=>{if(o)return Array.isArray(f)?f:[f];if(k==="en"&&x==="static")return Array.isArray(f)?f:[f];i+=1,c();const M=Array.isArray(f)?`[${f.join("|")}]:${k}`:`${f}:${k}`;if(e.has(M))return i-=1,c(),e.get(M);try{const E=await za({text:f,target:k||"en"});return e.set(M,E.translatedText??(Array.isArray(f)?f:[f])),E.translatedText??(Array.isArray(f)?f:[f])}catch(E){return console.error("Translation failed:",E),a("en"),o=!0,Array.isArray(f)?f:[f]}finally{i-=1,c()}};return{setLanguage:a,getLanguage:()=>n,translate:m,translateRecord:async(f,k=n)=>{if(k==="en"||o)return f;const x=Object.keys(f),A=Object.values(f);return(await m(A,k)).reduce((D,G,Z)=>(D[x[Z]]=G,D),{})},subscribe:p,subscribeToLoading:f=>(s.push(f),()=>{s=s.filter(k=>k!==f)}),getIsLoading:()=>i>0,getTranslationError:()=>o}})(),pn=navigator==null?void 0:navigator.language.split("-")[0].toLowerCase();let Ns=pn;const it=n=>{Ns=n},R=()=>Ns,sr=(n,e)=>{const t=Ni(n,e),i=t==null?void 0:t.language,s=Ae.getTranslationError();i&&i!==pn?it(s?"en":pn):i&&i===pn?it(i):!pn&&!i&&it("en")},z=async(n,e)=>{const t=await Ae.translate(n,e,"dynamic");return typeof t=="string"?t:t[0]};let rn=Hi;const Os=async n=>(rn=await Ae.translateRecord(Hi,n),rn);let q=Ls;const Us=async n=>{q=await Ae.translateRecord(Ls,n)};let P=Ts;const Vs=async n=>{P=await Ae.translateRecord(Ts,n)};let pe=_s;const Fs=async n=>{pe=await Ae.translateRecord(_s,n)};let $e=Es;const Ks=async n=>{$e=await Ae.translateRecord(Es,n)};let Ve=Ps;const Gs=async n=>{Ve=await Ae.translateRecord(Ps,n)};let Me=Is;const js=async n=>{Me=await Ae.translateRecord(Is,n)};let Ln=Ds;const zs=async n=>{Ln=await Ae.translateRecord(Ds,n)};let Fe=Rs;const qs=async n=>{Fe=await Ae.translateRecord(Rs,n)};let Tn=Bs;const Ws=async n=>{Tn=await Ae.translateRecord(Bs,n)};function Zs(n){if(n in q)return q[n];if(n in P)return P[n];if(n in rn)return rn[n];if(n in pe)return pe[n];if(n in $e)return $e[n];if(n in Ve)return Ve[n];if(n in Me)return Me[n];if(n in Ln)return Ln[n];if(n in Tn)return Tn[n];if(n in Fe)return Fe[n]}function Oi(){document.querySelectorAll("[data-translate]").forEach(n=>{const e=n.getAttribute("data-translate");if(!e)return;const t=Zs(e);t&&(n.textContent=t)}),document.querySelectorAll("[data-translate-placeholder]").forEach(n=>{const e=n.getAttribute("data-translate-placeholder");if(!e)return;const t=Zs(e);t&&(n.placeholder=t)})}Ae.subscribe(async n=>{Hs.startSmartLoading({});try{await Promise.all([Us(n),Vs(n),Os(n),(()=>{const e=or();if(e){if(e==="card")return Fs(n);e==="transfer"?Gs(n):e==="mobile_money"?js(n):e==="eft"?zs(n):e==="opay"?Ws(n):e==="test_cards"?Ks(n):e==="stablecoin"&&qs(n)}return Promise.resolve()})()]),Oi()}catch(e){console.error("Translation error:",e),Oi()}finally{Hs.stopGlobalLoading()}Oi()});function or(){const n=Array.from(document.querySelectorAll("[data-section]")).map(e=>e.dataset.section);for(const e of n)return e;return null}class Qs{constructor(e){d(this,"container");d(this,"onAction");d(this,"cardDetailsValues");d(this,"creditCardTypes");d(this,"merchantName");d(this,"currency");this.container=e.container,this.onAction=e.onAction,this.creditCardTypes=[...As],this.cardDetailsValues={number:"",expiry:"",cvv:"",name:""},this.merchantName=e.merchantName,this.currency=e.currency}attachListener(){const e=document.querySelector("#pci-dss");e&&e.classList.remove("hidden");const t=document.querySelector('input[name="number"]'),i=document.querySelector('input[name="expiry"]'),s=document.querySelector('input[name="cvv"]'),o=document.querySelector('input[name="name"]'),a=document.querySelector(".details-form-button"),l=document.querySelector("#checkoutcard"),c=this.container.querySelector("#enter-details-text"),p=this.container.querySelector("#certified-text"),m=this.container.querySelector("#card-confirmation-text-one"),g=this.container.querySelector("#card-confirmation-text-two");c&&(c.innerHTML=pe["enter-card-details"]),p&&(p.innerHTML=pe.certified),m&&(m.innerHTML=pe["card-confirmation-one"]),g&&(g.innerHTML=pe["card-confirmation-two"]),t&&(t.setAttribute("placeholder",pe["card-number"]),t.addEventListener("input",b=>this.handleInputChange(b,a))),i&&i.addEventListener("input",b=>this.handleInputChange(b,a)),s&&s.addEventListener("input",b=>this.handleInputChange(b,a)),o&&(o.setAttribute("placeholder",pe["card-holder-name"]),o.addEventListener("input",b=>this.handleInputChange(b,a))),l&&l.addEventListener("submit",b=>{var y,w,f;b.preventDefault(),this.onAction(b)({pan:Ja(this.cardDetailsValues.number),cvv:this.cardDetailsValues.cvv,expiryMonth:(y=this.cardDetailsValues)==null?void 0:y.expiry.split("/")[0].trim(),expiryYear:(w=this.cardDetailsValues)==null?void 0:w.expiry.split("/")[1].trim(),...this.currency==="ZAR"&&{cardHolderName:(f=this.cardDetailsValues)==null?void 0:f.name}})})}validateCreditCard(e){if(e=e.replace(/\D/g,""),!e||e.length===0||e.length<13||e.length>19)return!1;const t=e.split("").map(s=>parseInt(s,10));for(let s=t.length-2;s>=0;s-=2){let o=t[s]*2;o>9&&(o-=9),t[s]=o}return t.reduce((s,o)=>s+o,0)%10===0}handleInputChange(e,t){var l,c,p;const i=e.target,{name:s,value:o}=i;let a=o;if(o.trim()===""){this.emptyCardState(i,s);return}if(s==="number"){a=Ya(o);const m=a.replace(/\s+/g,""),g=this.validateCreditCard(m);this.filterCreditCardType(o);const b=(l=this.creditCardTypes[0])==null?void 0:l.name;b&&Mn.map(y=>{if(y.name===this.currency)if(y.cardTypes.includes(b)){const w=nr[b];if(w.length>1){const f=w.some(k=>m.length===k);this.checkInputValidity(g,i,f,"card-number-invalid")}else m.length===w[0]&&this.checkInputValidity(g,i,m.length>=14&&m.length<=19,"card-number-invalid")}else this.checkInputValidity(!1,i,o.trim().length>=14&&o.trim().length<=19,"invalid-issue-card")})}else if(s==="expiry"){const m=new Date;a=$a(o);const g=a.split("/"),b=(c=g[0])==null?void 0:c.trim(),y=(p=g[1])==null?void 0:p.trim(),w=new Date().getFullYear()%100,f=m.getMonth()+1;let k=!0;(parseInt(y)===w&&parseInt(b)<f||parseInt(y)<w)&&(k=!1),(y==null?void 0:y.length)===2&&this.checkInputValidity(k,i,g.join("").length===4,"card-expired")}else s==="cvv"?a=Xa(o):s==="name"&&(a=o);if(this.cardDetailsValues={...this.cardDetailsValues,[s]:a},i.value=a,this.validateCard())t&&t.removeAttribute("disabled");else if(t){if(t.disabled)return;t.setAttribute("disabled","")}}hideCardHolderInput(){const e=document.querySelector("#card-name");this.currency==="ZAR"?e&&(e.style.display="block"):e&&(e.style.display="none")}validateCard(){if(this.cardDetailsValues.expiry.split("/").length===2){const e=this.cardDetailsValues.expiry.split("/")[1].trim();return!!this.cardDetailsValues.number&&this.cardDetailsValues.number.length>15&&!!this.cardDetailsValues.expiry&&this.cardDetailsValues.expiry.length>3&&!!this.cardDetailsValues.cvv&&this.cardDetailsValues.cvv.length>2&&e.length===2&&(this.currency==="ZAR"?this.cardDetailsValues.name.trim()!=="":!0)}}displayCardTypes(){requestAnimationFrame(()=>{const e=this.container.querySelector("#card-type");e.innerHTML="",this.creditCardTypes.length>0?this.creditCardTypes.forEach(t=>{const i=document.createElement("div");i.classList.add("card-type"),i.innerHTML=t.icon,e.appendChild(i)}):e.innerHTML=`<svg width="25" height="16" viewBox="0 0 25 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
646
646
|
<path
|
|
647
647
|
d="M24.5827 6.33333V14.6667C24.5827 14.8877 24.4554 15.0996 24.2288 15.2559C24.0022 15.4122 23.6948 15.5 23.3743 15.5H1.62435C1.30388 15.5 0.996535 15.4122 0.769928 15.2559C0.543322 15.0996 0.416016 14.8877 0.416016 14.6667V6.33333H24.5827ZM24.5827 4.66667H0.416016V1.33333C0.416016 1.11232 0.543322 0.900358 0.769928 0.744078C0.996535 0.587797 1.30388 0.5 1.62435 0.5H23.3743C23.6948 0.5 24.0022 0.587797 24.2288 0.744078C24.4554 0.900358 24.5827 1.11232 24.5827 1.33333V4.66667ZM16.1243 11.3333V13H20.9577V11.3333H16.1243Z"
|
|
648
648
|
fill="#B6B4B9" />
|
|
@@ -1843,7 +1843,7 @@ or you can use record.mirror to access the mirror instance during recording.`;le
|
|
|
1843
1843
|
payment</button>
|
|
1844
1844
|
</div>
|
|
1845
1845
|
</div>
|
|
1846
|
-
</div>`;class _c{constructor(e){d(this,"container");d(this,"selected");d(this,"secret");d(this,"onAction");d(this,"paymentService");d(this,"currency");d(this,"amount");d(this,"ussd_detail");d(this,"reference");d(this,"customer");d(this,"activeRef","");d(this,"pageLoader");d(this,"callBackUrl");d(this,"metadata");d(this,"localCurrency");d(this,"onError");this.container=e.container,this.selected=e.selected,this.onAction=e.onAction,this.secret=e.secret,this.paymentService=new ua({token:this.secret,rdtCode:e.rdtCode,url:e.url}),this.currency=e.currency,this.amount=e.amount||0,this.customer=e.customer,this.reference=e.reference,this.callBackUrl=e.callBackUrl,this.metadata=e.metadata,this.localCurrency=e.localCurrency,this.onError=e.onError??(()=>null),this.pageLoader=new ke(this.container),this.pageLoader.mountLoader("25dvh"),this.pageLoader.updateMessage("Fetching selected bank code detail")}makePayment(){var e;_.track("start_ussdProcess",{payment_method:"USSD"}),this.paymentService.createUssdPayment({amount:this.amount,currency:this.currency,channel:"ussd",customer:this.customer,bank:{code:((e=this.selected)==null?void 0:e.code)||""},reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,...this.localCurrency&&{localCurrency:this.localCurrency},isCheckout:!0}).then(({data:t,headers:i})=>{var s;if(this.ussd_detail=t.ussd,this.activeRef=t.reference||"",t.status==="failed"){this.onError(t.providerMessage||"Payment failed"),_.track("stop_ussdProcess",{payment_method:"USSD"});const o=i.get("spf-redirect-url");this.callBackUrl=o||this.callBackUrl,this.callBackUrl&&setTimeout(()=>{const a=new URL(this.callBackUrl);a.searchParams.append("status",t.status),a.searchParams.append("reference",t.reference),window.location.href=a.toString()},1800);return}else if(t.status!=="success")if(t.ussd){this.container.innerHTML=this.render();const o=this.container.querySelectorAll(".bank-dial-code"),a=this.container.querySelector("#bank-dial-code");a&&(a.innerHTML=((s=t==null?void 0:t.ussd)==null?void 0:s.paymentCode)||"");const l=this.container.querySelector("#bank-name-ussd");l&&(l.innerHTML=this.selected.name),Array.from(o).forEach(p=>{var m;p.innerHTML=((m=t==null?void 0:t.ussd)==null?void 0:m.code)||""}),this.attachListener();return}else if(t.providerMessage){this.onError(t.providerMessage);return}else{this.onError("Unable to fetch bank details");return}this.container.innerHTML=this.render(),this.attachListener()}).catch(t=>{t!=null&&t.message?this.onError(t.message):this.onError("Payment failed")})}attachListener(){const e=this.container.querySelectorAll(".copy-code-button"),t=this.container.querySelectorAll(".copy-code-button-1"),i=this.container.querySelector("#bank-completed-payment");Array.from(e).forEach(a=>{a.addEventListener("click",l=>{var c;_.track("copy_ussdCode",{payment_method:"USSD"}),window.navigator.clipboard.writeText(((c=this.ussd_detail)==null?void 0:c.code)||"")})}),Array.from(t).forEach(a=>{a.addEventListener("click",l=>{var c;_.track("copy_ussdCode",{payment_method:"USSD"}),window.navigator.clipboard.writeText(((c=this.ussd_detail)==null?void 0:c.code)||"")})}),i&&i.addEventListener("click",a=>{a.preventDefault(),this.onAction(this.selected,this.activeRef)})}renderComponent(){this.makePayment(),this.attachListener()}render(){return Tc}}var Ec=Object.defineProperty,Pc=(n,e,t,i)=>{for(var s=void 0,o=n.length-1,a;o>=0;o--)(a=n[o])&&(s=a(e,t,s)||s);return s&&Ec(e,t,s),s};class ma{constructor({container:e,onSuccess:t,secret:i,amount:s,totalAmount:o,currency:a,customer:l,reference:c,rdtCode:p,url:m,callBackUrl:g,metadata:b,localCurrency:y,hidePaymentMethods:w,showPaymentMethods:f,disablePaymentMethods:k}){d(this,"contents");d(this,"selectedCode");d(this,"secret");d(this,"amount");d(this,"totalAmount");d(this,"currency");d(this,"customer");d(this,"pageLoader");d(this,"reference");d(this,"onSuccess");d(this,"warningScreen");d(this,"bankDetail");d(this,"viewUssdCode");d(this,"_currentStep");d(this,"container");d(this,"paymentService");d(this,"successScreen");d(this,"activeRef","");d(this,"abortController");d(this,"_retry_count",10);d(this,"intervalPayment");d(this,"rdtCode");d(this,"url");d(this,"callBackUrl");d(this,"metadata");d(this,"localCurrency");d(this,"merchantDetails");d(this,"hidePaymentMethods");d(this,"showPaymentMethods");d(this,"disablePaymentMethods");this.onSuccess=t||(()=>null),this.container=e,this.secret=i,this.amount=s,this.totalAmount=o,this.currency=a,this.reference=c,this.customer=l,this.rdtCode=p,this.url=m,this.callBackUrl=g,this.metadata=b,this.localCurrency=y,this.merchantDetails={},this.hidePaymentMethods=w,this.showPaymentMethods=f,this.disablePaymentMethods=k,this.contents=this.container.querySelector("#payment-content-view"),this._currentStep=1,this.paymentService=new ua({token:this.secret,rdtCode:this.rdtCode,url:this.url}),_.track("ussd_opens",{payment_method:"USSD"})}get currentStep(){return this._currentStep}set currentStep(e){this._currentStep=e,this.renderUssdContent()}onCodeSelect(e){this.selectedCode=e||"",this.currentStep=2}validate(){let e;if(this.abortController?e=this.abortController.signal:(this.abortController=new AbortController,e=this.abortController.signal),this._retry_count<=0){clearInterval(this.intervalPayment),this.currentStep=3;return}this.paymentService.verifyPayment(this.activeRef,e||this.abortController.signal).then(({data:t,headers:i})=>{t.status==="failed"?(this.currentStep=3,clearInterval(this.intervalPayment),this.redirectTo(t,i,"failed")):["successful","failed"].includes(t.status)?t.status==="inProgress"?this._retry_count-=1:["success","successful"].includes(t.status)&&(this.currentStep=5,clearInterval(this.intervalPayment),_.track("verify_payment",{payment_method:"USSD",verification_status:"Success"}),this.redirectTo(t,i,"success")):this._retry_count-=1}).catch(t=>{t.message?this.warningScreen.setPaymentError(t.message):this.warningScreen.setPaymentError("Payment failed"),this.currentStep=3,clearInterval(this.intervalPayment),_.track("verify_payment",{payment_method:"USSD",verification_status:"Failed"})})}redirectTo(e,t,i){const s=t.get("spf-redirect-url");this.callBackUrl=s||this.callBackUrl,this.callBackUrl?setTimeout(()=>{const o=new URL(this.callBackUrl);o.searchParams.append("status",e.status),o.searchParams.append("reference",e.reference),window.location.href=o.toString()},1800):i==="success"&&this.onSuccess(e)}renderUssdContent(e){var t;if(e&&(this.merchantDetails=e),this.currentStep===3||this.currentStep===5?this.hidePaymentMethods():this.showPaymentMethods(),this.currentStep===2&&this.disablePaymentMethods("ussd"),this.currentStep!==1){const i=document.getElementById("go-back");i&&(i.classList.remove("flex","items-center","gap-2","mb-2"),i.innerHTML="")}switch(this.currentStep){case 1:this.bankDetail=new ha({container:this.contents,merchantKey:this.secret,onAction:this.onCodeSelect.bind(this),rdtCode:this.rdtCode,url:this.url,currency:this.currency,localCurrency:this.localCurrency,rate:e==null?void 0:e.rate.rate,amount:this.amount,totalAmount:this.totalAmount}),this.bankDetail.renderContent();break;case 2:this.viewUssdCode=new _c({container:this.contents,onAction:(i,s)=>{this.activeRef=s,this.currentStep=4,this.intervalPayment=setInterval(()=>{this.validate()},5e3)},selected:this.selectedCode||{},secret:this.secret,amount:this.amount,totalAmount:this.totalAmount,currency:this.currency,customer:this.customer,onError:i=>{this.currentStep=3,this.warningScreen.setPaymentError(i)},reference:this.reference,rdtCode:this.rdtCode,url:this.url,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency}),this.viewUssdCode.renderComponent();break;case 3:this.contents.innerHTML=Js,this.warningScreen=new en({container:this.contents});break;case 4:this.pageLoader=new ke(this.contents),this.pageLoader.mountLoader("25vh"),this.pageLoader.updateMessage("We are confirming transaction status. This might take a few seconds.","Please do not refresh this page");break;case 5:this.successScreen=new Fn({container:this.contents,amount:this.totalAmount,currency:this.currency,localCurrency:this.localCurrency,rate:(t=this.merchantDetails)==null?void 0:t.rate.rate}),this.successScreen.renderComponent();break;default:this.bankDetail=new ha({container:this.contents,merchantKey:this.secret,onAction:this.onCodeSelect.bind(this),rdtCode:this.rdtCode,url:this.url,currency:this.currency,localCurrency:this.localCurrency,rate:e==null?void 0:e.rate.rate,amount:this.amount,totalAmount:this.totalAmount}),this.bankDetail.renderContent();break}}handleSelectChange(e){setTimeout(()=>{this.currentStep=2},400),this.currentStep=2}}Pc([da(),da()],ma.prototype,"selectedCode");const Ic={NGN:"Nigerian Naira",USD:"US Dollar",GHS:"Ghanaian Cedi",GBP:"Pounds",ZAF:"South African Rand",USDT:"Tether",KSH:"Kenyan Shilling",EGP:"Egyptian Pound"},Dc={en:"English",fr:"Français",es:"Español",pt:"Português",ar:"Arabic"},Bc=n=>n==null?void 0:n.replace(/_/g," ");function pa(n){return n.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ")}const Rc=n=>{const e=/(\b[a-z](?!\s))/g;return n?n.toLowerCase().replace(e,t=>pa(t)):""},ui=n=>{if(n){const e=Bc(n);return pa(e)}return""},Hc=`<div>
|
|
1846
|
+
</div>`;class _c{constructor(e){d(this,"container");d(this,"selected");d(this,"secret");d(this,"onAction");d(this,"paymentService");d(this,"currency");d(this,"amount");d(this,"ussd_detail");d(this,"reference");d(this,"customer");d(this,"activeRef","");d(this,"pageLoader");d(this,"callBackUrl");d(this,"metadata");d(this,"localCurrency");d(this,"onError");this.container=e.container,this.selected=e.selected,this.onAction=e.onAction,this.secret=e.secret,this.paymentService=new ua({token:this.secret,rdtCode:e.rdtCode,url:e.url}),this.currency=e.currency,this.amount=e.amount||0,this.customer=e.customer,this.reference=e.reference,this.callBackUrl=e.callBackUrl,this.metadata=e.metadata,this.localCurrency=e.localCurrency,this.onError=e.onError??(()=>null),this.pageLoader=new ke(this.container),this.pageLoader.mountLoader("25dvh"),this.pageLoader.updateMessage("Fetching selected bank code detail")}makePayment(){var e;_.track("start_ussdProcess",{payment_method:"USSD"}),this.paymentService.createUssdPayment({amount:this.amount,currency:this.currency,channel:"ussd",customer:this.customer,bank:{code:((e=this.selected)==null?void 0:e.code)||""},reference:this.reference,callBackUrl:this.callBackUrl,metadata:this.metadata,...this.localCurrency&&{localCurrency:this.localCurrency},isCheckout:!0}).then(({data:t,headers:i})=>{var s;if(this.ussd_detail=t.ussd,this.activeRef=t.reference||"",t.status==="failed"){this.onError(t.providerMessage||"Payment failed"),_.track("stop_ussdProcess",{payment_method:"USSD"});const o=i.get("spf-redirect-url");this.callBackUrl=o||this.callBackUrl,this.callBackUrl&&setTimeout(()=>{const a=new URL(this.callBackUrl);a.searchParams.append("status",t.status),a.searchParams.append("reference",t.reference),window.location.href=a.toString()},1800);return}else if(t.status!=="success")if(t.ussd){this.container.innerHTML=this.render();const o=this.container.querySelectorAll(".bank-dial-code"),a=this.container.querySelector("#bank-dial-code");a&&(a.innerHTML=((s=t==null?void 0:t.ussd)==null?void 0:s.paymentCode)||"");const l=this.container.querySelector("#bank-name-ussd");l&&(l.innerHTML=this.selected.name),Array.from(o).forEach(p=>{var m;p.innerHTML=((m=t==null?void 0:t.ussd)==null?void 0:m.code)||""}),this.attachListener();return}else if(t.providerMessage){this.onError(t.providerMessage);return}else{this.onError("Unable to fetch bank details");return}this.container.innerHTML=this.render(),this.attachListener()}).catch(t=>{t!=null&&t.message?this.onError(t.message):this.onError("Payment failed")})}attachListener(){const e=this.container.querySelectorAll(".copy-code-button"),t=this.container.querySelectorAll(".copy-code-button-1"),i=this.container.querySelector("#bank-completed-payment");Array.from(e).forEach(a=>{a.addEventListener("click",l=>{var c;_.track("copy_ussdCode",{payment_method:"USSD"}),window.navigator.clipboard.writeText(((c=this.ussd_detail)==null?void 0:c.code)||"")})}),Array.from(t).forEach(a=>{a.addEventListener("click",l=>{var c;_.track("copy_ussdCode",{payment_method:"USSD"}),window.navigator.clipboard.writeText(((c=this.ussd_detail)==null?void 0:c.code)||"")})}),i&&i.addEventListener("click",a=>{a.preventDefault(),this.onAction(this.selected,this.activeRef)})}renderComponent(){this.makePayment(),this.attachListener()}render(){return Tc}}var Ec=Object.defineProperty,Pc=(n,e,t,i)=>{for(var s=void 0,o=n.length-1,a;o>=0;o--)(a=n[o])&&(s=a(e,t,s)||s);return s&&Ec(e,t,s),s};class ma{constructor({container:e,onSuccess:t,secret:i,amount:s,totalAmount:o,currency:a,customer:l,reference:c,rdtCode:p,url:m,callBackUrl:g,metadata:b,localCurrency:y,hidePaymentMethods:w,showPaymentMethods:f,disablePaymentMethods:k}){d(this,"contents");d(this,"selectedCode");d(this,"secret");d(this,"amount");d(this,"totalAmount");d(this,"currency");d(this,"customer");d(this,"pageLoader");d(this,"reference");d(this,"onSuccess");d(this,"warningScreen");d(this,"bankDetail");d(this,"viewUssdCode");d(this,"_currentStep");d(this,"container");d(this,"paymentService");d(this,"successScreen");d(this,"activeRef","");d(this,"abortController");d(this,"_retry_count",10);d(this,"intervalPayment");d(this,"rdtCode");d(this,"url");d(this,"callBackUrl");d(this,"metadata");d(this,"localCurrency");d(this,"merchantDetails");d(this,"hidePaymentMethods");d(this,"showPaymentMethods");d(this,"disablePaymentMethods");this.onSuccess=t||(()=>null),this.container=e,this.secret=i,this.amount=s,this.totalAmount=o,this.currency=a,this.reference=c,this.customer=l,this.rdtCode=p,this.url=m,this.callBackUrl=g,this.metadata=b,this.localCurrency=y,this.merchantDetails={},this.hidePaymentMethods=w,this.showPaymentMethods=f,this.disablePaymentMethods=k,this.contents=this.container.querySelector("#payment-content-view"),this._currentStep=1,this.paymentService=new ua({token:this.secret,rdtCode:this.rdtCode,url:this.url}),_.track("ussd_opens",{payment_method:"USSD"})}get currentStep(){return this._currentStep}set currentStep(e){this._currentStep=e,this.renderUssdContent()}onCodeSelect(e){this.selectedCode=e||"",this.currentStep=2}validate(){let e;if(this.abortController?e=this.abortController.signal:(this.abortController=new AbortController,e=this.abortController.signal),this._retry_count<=0){clearInterval(this.intervalPayment),this.currentStep=3;return}this.paymentService.verifyPayment(this.activeRef,e||this.abortController.signal).then(({data:t,headers:i})=>{t.status==="failed"?(this.currentStep=3,clearInterval(this.intervalPayment),this.redirectTo(t,i,"failed")):["successful","failed"].includes(t.status)?t.status==="inProgress"?this._retry_count-=1:["success","successful"].includes(t.status)&&(this.currentStep=5,clearInterval(this.intervalPayment),_.track("verify_payment",{payment_method:"USSD",verification_status:"Success"}),this.redirectTo(t,i,"success")):this._retry_count-=1}).catch(t=>{t.message?this.warningScreen.setPaymentError(t.message):this.warningScreen.setPaymentError("Payment failed"),this.currentStep=3,clearInterval(this.intervalPayment),_.track("verify_payment",{payment_method:"USSD",verification_status:"Failed"})})}redirectTo(e,t,i){const s=t.get("spf-redirect-url");this.callBackUrl=s||this.callBackUrl,this.callBackUrl?setTimeout(()=>{const o=new URL(this.callBackUrl);o.searchParams.append("status",e.status),o.searchParams.append("reference",e.reference),window.location.href=o.toString()},1800):i==="success"&&this.onSuccess(e)}renderUssdContent(e){var t;if(e&&(this.merchantDetails=e),this.currentStep===3||this.currentStep===5?this.hidePaymentMethods():this.showPaymentMethods(),this.currentStep===2&&this.disablePaymentMethods("ussd"),this.currentStep!==1){const i=document.getElementById("go-back");i&&(i.classList.remove("flex","items-center","gap-2","mb-2"),i.innerHTML="")}switch(this.currentStep){case 1:this.bankDetail=new ha({container:this.contents,merchantKey:this.secret,onAction:this.onCodeSelect.bind(this),rdtCode:this.rdtCode,url:this.url,currency:this.currency,localCurrency:this.localCurrency,rate:e==null?void 0:e.rate.rate,amount:this.amount,totalAmount:this.totalAmount}),this.bankDetail.renderContent();break;case 2:this.viewUssdCode=new _c({container:this.contents,onAction:(i,s)=>{this.activeRef=s,this.currentStep=4,this.intervalPayment=setInterval(()=>{this.validate()},5e3)},selected:this.selectedCode||{},secret:this.secret,amount:this.amount,totalAmount:this.totalAmount,currency:this.currency,customer:this.customer,onError:i=>{this.currentStep=3,this.warningScreen.setPaymentError(i)},reference:this.reference,rdtCode:this.rdtCode,url:this.url,callBackUrl:this.callBackUrl,metadata:this.metadata,localCurrency:this.localCurrency}),this.viewUssdCode.renderComponent();break;case 3:this.contents.innerHTML=Js,this.warningScreen=new en({container:this.contents});break;case 4:this.pageLoader=new ke(this.contents),this.pageLoader.mountLoader("25vh"),this.pageLoader.updateMessage("We are confirming transaction status. This might take a few seconds.","Please do not refresh this page");break;case 5:this.successScreen=new Fn({container:this.contents,amount:this.totalAmount,currency:this.currency,localCurrency:this.localCurrency,rate:(t=this.merchantDetails)==null?void 0:t.rate.rate}),this.successScreen.renderComponent();break;default:this.bankDetail=new ha({container:this.contents,merchantKey:this.secret,onAction:this.onCodeSelect.bind(this),rdtCode:this.rdtCode,url:this.url,currency:this.currency,localCurrency:this.localCurrency,rate:e==null?void 0:e.rate.rate,amount:this.amount,totalAmount:this.totalAmount}),this.bankDetail.renderContent();break}}handleSelectChange(e){setTimeout(()=>{this.currentStep=2},400),this.currentStep=2}}Pc([da(),da()],ma.prototype,"selectedCode");const Ic={NGN:"Nigerian Naira",USD:"US Dollar",GHS:"Ghanaian Cedi",GBP:"Pounds",ZAF:"South African Rand",USDT:"Tether",KSH:"Kenyan Shilling",EGP:"Egyptian Pound"},Dc={en:"English",fr:"Français",es:"Español",pt:"Português",ar:"Arabic",zh:"Chinese",hi:"Hindi",nl:"Dutch",et:"Estonian",pl:"Polish"},Bc=n=>n==null?void 0:n.replace(/_/g," ");function pa(n){return n.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ")}const Rc=n=>{const e=/(\b[a-z](?!\s))/g;return n?n.toLowerCase().replace(e,t=>pa(t)):""},ui=n=>{if(n){const e=Bc(n);return pa(e)}return""},Hc=`<div>
|
|
1847
1847
|
<div>
|
|
1848
1848
|
<button id="go-back" class="md:hidden" aria-label="Go back">
|
|
1849
1849
|
</button>
|