@reevit/vue 0.3.8 → 0.3.9

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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),v=require("@reevit/core");function Q(n){const o=n.toLowerCase();return o.includes("paystack")?"paystack":o.includes("hubtel")?"hubtel":o.includes("flutterwave")?"flutterwave":"paystack"}function X(n,o){return{id:n.id,clientSecret:n.client_secret,pspPublicKey:n.psp_public_key,pspCredentials:n.psp_credentials,amount:n.amount,currency:n.currency,status:n.status,recommendedPsp:Q(n.provider),availableMethods:o.paymentMethods||["card","mobile_money"],reference:n.reference||o.reference,connectionId:n.connection_id,provider:n.provider,feeAmount:n.fee_amount,feeCurrency:n.fee_currency,netAmount:n.net_amount,metadata:o.metadata}}function L(n){const{config:o,onSuccess:t,onError:l,onClose:r,onStateChange:m,apiBaseUrl:d}=n,i=e.ref(v.createInitialState());if(o.initialPaymentIntent){const c=o.initialPaymentIntent;i.value={...i.value,status:"ready",paymentIntent:c,selectedMethod:c.availableMethods?.length===1?c.availableMethods[0]:null}}const p=new v.ReevitAPIClient({publicKey:o.publicKey,baseUrl:d}),u=c=>{i.value=v.reevitReducer(i.value,c)};e.watch(()=>i.value.status,c=>{m?.(c)});const a=async c=>{u({type:"INIT_START"});try{const s=o.reference||v.generateReference(),y=v.detectCountryFromCurrency(o.currency),f=c||o.paymentMethods?.[0]||"card",{data:k,error:x}=await p.createPaymentIntent({...o,reference:s},f,y);if(x){u({type:"INIT_ERROR",payload:x}),l?.(x);return}if(!k){const $={code:"INIT_FAILED",message:"No data received from API",recoverable:!0};u({type:"INIT_ERROR",payload:$}),l?.($);return}const J=X(k,{...o,reference:s});u({type:"INIT_SUCCESS",payload:J})}catch(s){const y={code:"INIT_FAILED",message:s instanceof Error?s.message:"Failed to initialize checkout",recoverable:!0,originalError:s};u({type:"INIT_ERROR",payload:y}),l?.(y)}},h=c=>{u({type:"SELECT_METHOD",payload:c})},E=async c=>{if(!(!i.value.paymentIntent||!i.value.selectedMethod)){u({type:"PROCESS_START"});try{let s;if(i.value.paymentIntent.clientSecret){const{data:f,error:k}=await p.confirmPaymentIntent(i.value.paymentIntent.id,i.value.paymentIntent.clientSecret);if(k){u({type:"PROCESS_ERROR",payload:k}),l?.(k);return}s=f}else{const{data:f,error:k}=await p.confirmPayment(i.value.paymentIntent.id);if(k){u({type:"PROCESS_ERROR",payload:k}),l?.(k);return}s=f}const y={paymentId:i.value.paymentIntent.id,reference:c.reference||i.value.paymentIntent.reference||i.value.paymentIntent.metadata?.reference||"",amount:i.value.paymentIntent.amount,currency:i.value.paymentIntent.currency,paymentMethod:i.value.selectedMethod,psp:i.value.paymentIntent.recommendedPsp,pspReference:c.pspReference||s?.provider_ref_id||"",status:"success",metadata:c};u({type:"PROCESS_SUCCESS",payload:y}),t?.(y)}catch(s){const y={code:"PAYMENT_FAILED",message:s instanceof Error?s.message:"Payment failed",recoverable:!0,originalError:s};u({type:"PROCESS_ERROR",payload:y}),l?.(y)}}},P=async c=>{await E(c)},R=c=>{u({type:"PROCESS_ERROR",payload:c}),l?.(c)},w=()=>{u({type:"RESET"})},I=async()=>{if(i.value.paymentIntent&&i.value.status!=="success")try{await p.cancelPaymentIntent(i.value.paymentIntent.id)}catch{}u({type:"CLOSE"}),r?.()},C=e.computed(()=>i.value.status),V=e.computed(()=>i.value.paymentIntent),S=e.computed(()=>i.value.selectedMethod),B=e.computed(()=>i.value.error),b=e.computed(()=>i.value.result),N=e.computed(()=>i.value.status==="loading"||i.value.status==="processing"),_=e.computed(()=>i.value.status==="ready"||i.value.status==="method_selected"||i.value.status==="processing"),g=e.computed(()=>i.value.status==="success"),T=e.computed(()=>i.value.error?.recoverable??!1);return{status:e.readonly(C),paymentIntent:e.readonly(V),selectedMethod:e.readonly(S),error:e.readonly(B),result:e.readonly(b),initialize:a,selectMethod:h,processPayment:E,handlePspSuccess:P,handlePspError:R,reset:w,close:I,isLoading:e.readonly(N),isReady:e.readonly(_),isComplete:e.readonly(g),canRetry:e.readonly(T)}}const Z={class:"reevit-method-selector"},ee={class:"reevit-amount-display"},te={class:"reevit-methods-grid"},ne=["onClick"],oe={class:"reevit-method-icon"},re={class:"reevit-method-info"},ae={class:"reevit-method-name"},se={class:"reevit-method-description"},ie={class:"reevit-method-radio"},le={key:0,class:"reevit-radio-inner"},D=e.defineComponent({__name:"PaymentMethodSelector",props:{methods:{},selected:{},amount:{},currency:{},provider:{}},emits:["select"],setup(n,{emit:o}){const t=n,l=o,r={hubtel:"Hubtel",paystack:"Paystack",flutterwave:"Flutterwave",monnify:"Monnify",mpesa:"M-Pesa",stripe:"Stripe"},m=p=>t.provider?.toLowerCase().includes("hubtel")&&p==="mobile_money"?`Pay with ${r[t.provider.toLowerCase()]||"Hubtel"}`:{card:"Card",mobile_money:"Mobile Money",bank_transfer:"Bank Transfer"}[p],d=p=>t.provider?.toLowerCase().includes("hubtel")?"Card, Mobile Money, and Bank Transfer":{card:"Visa, Mastercard, Maestro",mobile_money:"MTN, Vodafone, AirtelTigo",bank_transfer:"Transfer directly from your bank"}[p],i=e.computed(()=>[{id:"card",name:m("card"),description:d("card"),icon:"💳"},{id:"mobile_money",name:m("mobile_money"),description:d("mobile_money"),icon:"📱"},{id:"bank_transfer",name:m("bank_transfer"),description:d("bank_transfer"),icon:"🏦"}].filter(p=>t.methods.includes(p.id)));return(p,u)=>(e.openBlock(),e.createElementBlock("div",Z,[u[0]||(u[0]=e.createElementVNode("h3",{class:"reevit-section-title"},"Select Payment Method",-1)),e.createElementVNode("p",ee," Pay "+e.toDisplayString(e.unref(v.formatAmount)(n.amount,n.currency)),1),e.createElementVNode("div",te,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.value,a=>(e.openBlock(),e.createElementBlock("button",{key:a.id,type:"button",class:e.normalizeClass(e.unref(v.cn)("reevit-method-card",n.selected===a.id&&"reevit-method-card--selected")),onClick:h=>l("select",a.id)},[e.createElementVNode("span",oe,e.toDisplayString(a.icon),1),e.createElementVNode("div",re,[e.createElementVNode("span",ae,e.toDisplayString(a.name),1),e.createElementVNode("span",se,e.toDisplayString(a.description),1)]),e.createElementVNode("div",ie,[n.selected===a.id?(e.openBlock(),e.createElementBlock("div",le)):e.createCommentVNode("",!0)])],10,ne))),128))])]))}}),ce={class:"reevit-form-group"},de=["disabled"],ue={class:"reevit-network-selector"},me={class:"reevit-networks-grid"},pe=["onClick","disabled"],ye={key:0,class:"reevit-error-message"},ve=["disabled"],he={key:0,class:"reevit-spinner"},fe={key:1},U=e.defineComponent({__name:"MobileMoneyForm",props:{initialPhone:{},loading:{type:Boolean}},emits:["submit"],setup(n,{emit:o}){const t=n,l=o,r=e.ref(t.initialPhone||""),m=e.ref(null),d=e.ref(null);e.watch(r,u=>{const a=v.detectNetwork(u);a&&(m.value=a),d.value&&(d.value=null)});const i=()=>{if(!v.validatePhone(r.value)){d.value="Please enter a valid phone number";return}if(!m.value){d.value="Please select your mobile network";return}l("submit",{phone:r.value,network:m.value})},p=[{id:"mtn",name:"MTN",color:"#FFCC00"},{id:"vodafone",name:"Vodafone",color:"#E60000"},{id:"airteltigo",name:"AirtelTigo",color:"#005596"}];return(u,a)=>(e.openBlock(),e.createElementBlock("form",{class:"reevit-momo-form",onSubmit:e.withModifiers(i,["prevent"])},[e.createElementVNode("div",ce,[a[1]||(a[1]=e.createElementVNode("label",{class:"reevit-label",for:"reevit-phone"},"Phone Number",-1)),e.withDirectives(e.createElementVNode("input",{id:"reevit-phone","onUpdate:modelValue":a[0]||(a[0]=h=>r.value=h),type:"tel",class:e.normalizeClass(["reevit-input",{"reevit-input--error":d.value&&!e.unref(v.validatePhone)(r.value)}]),placeholder:"e.g. 024 123 4567",disabled:n.loading,autocomplete:"tel"},null,10,de),[[e.vModelText,r.value]])]),e.createElementVNode("div",ue,[a[2]||(a[2]=e.createElementVNode("label",{class:"reevit-label"},"Select Network",-1)),e.createElementVNode("div",me,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(p,h=>e.createElementVNode("button",{key:h.id,type:"button",class:e.normalizeClass(e.unref(v.cn)("reevit-network-btn",m.value===h.id&&"reevit-network-btn--selected")),onClick:E=>m.value=h.id,disabled:n.loading},[e.createElementVNode("div",{class:"reevit-network-dot",style:e.normalizeStyle({backgroundColor:h.color})},null,4),e.createTextVNode(" "+e.toDisplayString(h.name),1)],10,pe)),64))])]),d.value?(e.openBlock(),e.createElementBlock("p",ye,e.toDisplayString(d.value),1)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"submit",class:"reevit-submit-btn",disabled:n.loading||!r.value},[n.loading?(e.openBlock(),e.createElementBlock("span",he)):(e.openBlock(),e.createElementBlock("span",fe,"Continue"))],8,ve),a[3]||(a[3]=e.createElementVNode("p",{class:"reevit-secure-text"}," 🔒 Secure mobile money payment via Reevit ",-1))],32))}});class be{constructor(o){this.baseUrl="https://unified-pay.hubtel.com",this.messageHandler=null,this.stylesInjected=!1,o&&(this.baseUrl=o)}redirect({purchaseInfo:o,config:t}){const l=this.createCheckoutUrl(o,t),r=window.open(l);if(!r||r.closed||typeof r.closed>"u")throw new Error("Popup was blocked by the browser. Please allow popups for this site.")}initIframe({purchaseInfo:o,callBacks:t,config:l,iframeStyle:r}){var m,d,i;this.registerEvents(t);const p=document.getElementById("hubtel-checkout-iframe");if(!p)throw new Error('Container element with id "hubtel-checkout-iframe" not found in the DOM.');p.innerHTML="";const u=document.createElement("div");u.textContent="Loading...",p.appendChild(u);const a=document.createElement("iframe");a.setAttribute("id","hubtel-iframe-element"),a.src=this.createCheckoutUrl(o,l),a.style.display="none",a.style.width=(m=r?.width)!==null&&m!==void 0?m:"100%",a.style.height=(d=r?.height)!==null&&d!==void 0?d:"100%",a.style.minHeight=r?.minHeight||"400px",a.style.border=(i=r?.border)!==null&&i!==void 0?i:"none",a.onload=()=>{var h;p.removeChild(u),a.style.display="block",(h=t.onLoad)===null||h===void 0||h.call(t)},p.appendChild(a)}openModal({purchaseInfo:o,callBacks:t,config:l}){this.injectStyles(),this.createIframe(),this.handleBackButton(),this.registerEvents(t),this.renderWebpageInPopup(this.createCheckoutUrl(o,l),t.onClose,t.onLoad)}createCheckoutUrl(o,t){const l=Object.assign(Object.assign({},o),t),r=Object.keys(l).reduce((u,a)=>(l[a]!==null&&l[a]!==void 0&&(u[a]=l[a]),u),{}),m=Object.keys(r).map(u=>`${u}=${encodeURIComponent(r[u])}`).join("&"),d=this.encodeBase64(m),i=encodeURIComponent(d);return`${r?.branding==="disabled"?`${this.baseUrl}/pay/direct`:`${this.baseUrl}/pay`}?p=${i}`}encodeBase64(o){return btoa(unescape(encodeURIComponent(o)))}handleBackButton(){window.addEventListener("popstate",()=>{this.closePopUp()})}createIframe(){const o=document.createElement("div");o.setAttribute("id","backdrop"),o.classList.add("backdrop");const t=document.createElement("span");t.classList.add("checkout-loader"),o.appendChild(t),document.body.appendChild(o)}registerEvents(o){this.messageHandler&&window.removeEventListener("message",this.messageHandler,!1);const t=l=>{var r,m,d,i,p,u;if(l.origin!==this.baseUrl)return;const{data:a}=l;if(a.success===!0)(r=o.onPaymentSuccess)===null||r===void 0||r.call(o,a);else if(a.success===!1)(m=o.onPaymentFailure)===null||m===void 0||m.call(o,a);else if(a.initialized)(d=o.init)===null||d===void 0||d.call(o,a),(i=o.onInit)===null||i===void 0||i.call(o,a);else if(a.feesChanged)(p=o.onFeesChanged)===null||p===void 0||p.call(o,a.fees);else if(a.resize){const h=document.getElementById("hubtel-iframe-element");h&&(h.style.height=a.height+"px"),(u=o?.onResize)===null||u===void 0||u.call(o,a)}};this.messageHandler=t,window.addEventListener("message",t,!1)}destroy(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler,!1),this.messageHandler=null)}renderWebpageInPopup(o,t,l){const r=document.createElement("div");r.classList.add("checkout-modal");const m=document.createElement("div");m.setAttribute("id","checkout-close-icon"),m.innerHTML="×",m.classList.add("close-icon"),m.addEventListener("click",()=>{this.closePopUp(),t?.()}),r.appendChild(m);const d=document.createElement("iframe");d.src=o,history.pushState({modalOpen:!0},""),d.classList.add("iframe"),r.appendChild(d),document.body.appendChild(r),r.style.opacity="0",d.addEventListener("load",()=>{r.style.opacity="1",l?.()})}closePopUp(){const o=document.querySelector(".backdrop"),t=document.querySelector(".checkout-modal");o&&document.body.removeChild(o),t&&document.body.removeChild(t),history.replaceState(null,""),window.removeEventListener("popstate",this.closePopUp)}injectStyles(){if(this.stylesInjected)return;const o=document.createElement("style");o.type="text/css",o.setAttribute("data-hubtel-checkout","true"),o.innerHTML=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),v=require("@reevit/core");function Q(n){const o=n.toLowerCase();return o.includes("paystack")?"paystack":o.includes("hubtel")?"hubtel":o.includes("flutterwave")?"flutterwave":o.includes("stripe")?"stripe":o.includes("monnify")?"monnify":o.includes("mpesa")||o.includes("m-pesa")?"mpesa":"paystack"}function X(n,o){return{id:n.id,clientSecret:n.client_secret,pspPublicKey:n.psp_public_key,pspCredentials:n.psp_credentials,amount:n.amount,currency:n.currency,status:n.status,recommendedPsp:Q(n.provider),availableMethods:o.paymentMethods||["card","mobile_money"],reference:n.reference||o.reference,connectionId:n.connection_id,provider:n.provider,feeAmount:n.fee_amount,feeCurrency:n.fee_currency,netAmount:n.net_amount,metadata:o.metadata}}function L(n){const{config:o,onSuccess:t,onError:l,onClose:r,onStateChange:m,apiBaseUrl:d}=n,i=e.ref(v.createInitialState());if(o.initialPaymentIntent){const c=o.initialPaymentIntent;i.value={...i.value,status:"ready",paymentIntent:c,selectedMethod:c.availableMethods?.length===1?c.availableMethods[0]:null}}const p=new v.ReevitAPIClient({publicKey:o.publicKey,baseUrl:d}),u=c=>{i.value=v.reevitReducer(i.value,c)};e.watch(()=>i.value.status,c=>{m?.(c)});const a=async c=>{u({type:"INIT_START"});try{const s=o.reference||v.generateReference(),y=v.detectCountryFromCurrency(o.currency),f=c||o.paymentMethods?.[0]||"card",{data:k,error:x}=await p.createPaymentIntent({...o,reference:s},f,y);if(x){u({type:"INIT_ERROR",payload:x}),l?.(x);return}if(!k){const $={code:"INIT_FAILED",message:"No data received from API",recoverable:!0};u({type:"INIT_ERROR",payload:$}),l?.($);return}const J=X(k,{...o,reference:s});u({type:"INIT_SUCCESS",payload:J})}catch(s){const y={code:"INIT_FAILED",message:s instanceof Error?s.message:"Failed to initialize checkout",recoverable:!0,originalError:s};u({type:"INIT_ERROR",payload:y}),l?.(y)}},h=c=>{u({type:"SELECT_METHOD",payload:c})},E=async c=>{if(!(!i.value.paymentIntent||!i.value.selectedMethod)){u({type:"PROCESS_START"});try{let s;if(i.value.paymentIntent.clientSecret){const{data:f,error:k}=await p.confirmPaymentIntent(i.value.paymentIntent.id,i.value.paymentIntent.clientSecret);if(k){u({type:"PROCESS_ERROR",payload:k}),l?.(k);return}s=f}else{const{data:f,error:k}=await p.confirmPayment(i.value.paymentIntent.id);if(k){u({type:"PROCESS_ERROR",payload:k}),l?.(k);return}s=f}const y={paymentId:i.value.paymentIntent.id,reference:c.reference||i.value.paymentIntent.reference||i.value.paymentIntent.metadata?.reference||"",amount:i.value.paymentIntent.amount,currency:i.value.paymentIntent.currency,paymentMethod:i.value.selectedMethod,psp:i.value.paymentIntent.recommendedPsp,pspReference:c.pspReference||s?.provider_ref_id||"",status:"success",metadata:c};u({type:"PROCESS_SUCCESS",payload:y}),t?.(y)}catch(s){const y={code:"PAYMENT_FAILED",message:s instanceof Error?s.message:"Payment failed",recoverable:!0,originalError:s};u({type:"PROCESS_ERROR",payload:y}),l?.(y)}}},P=async c=>{await E(c)},R=c=>{u({type:"PROCESS_ERROR",payload:c}),l?.(c)},w=()=>{u({type:"RESET"})},I=async()=>{if(i.value.paymentIntent&&i.value.status!=="success")try{await p.cancelPaymentIntent(i.value.paymentIntent.id)}catch{}u({type:"CLOSE"}),r?.()},C=e.computed(()=>i.value.status),V=e.computed(()=>i.value.paymentIntent),S=e.computed(()=>i.value.selectedMethod),B=e.computed(()=>i.value.error),b=e.computed(()=>i.value.result),N=e.computed(()=>i.value.status==="loading"||i.value.status==="processing"),_=e.computed(()=>i.value.status==="ready"||i.value.status==="method_selected"||i.value.status==="processing"),g=e.computed(()=>i.value.status==="success"),T=e.computed(()=>i.value.error?.recoverable??!1);return{status:e.readonly(C),paymentIntent:e.readonly(V),selectedMethod:e.readonly(S),error:e.readonly(B),result:e.readonly(b),initialize:a,selectMethod:h,processPayment:E,handlePspSuccess:P,handlePspError:R,reset:w,close:I,isLoading:e.readonly(N),isReady:e.readonly(_),isComplete:e.readonly(g),canRetry:e.readonly(T)}}const Z={class:"reevit-method-selector"},ee={class:"reevit-amount-display"},te={class:"reevit-methods-grid"},ne=["onClick"],oe={class:"reevit-method-icon"},re={class:"reevit-method-info"},ae={class:"reevit-method-name"},se={class:"reevit-method-description"},ie={class:"reevit-method-radio"},le={key:0,class:"reevit-radio-inner"},D=e.defineComponent({__name:"PaymentMethodSelector",props:{methods:{},selected:{},amount:{},currency:{},provider:{}},emits:["select"],setup(n,{emit:o}){const t=n,l=o,r={hubtel:"Hubtel",paystack:"Paystack",flutterwave:"Flutterwave",monnify:"Monnify",mpesa:"M-Pesa",stripe:"Stripe"},m=p=>t.provider?.toLowerCase().includes("hubtel")&&p==="mobile_money"?`Pay with ${r[t.provider.toLowerCase()]||"Hubtel"}`:{card:"Card",mobile_money:"Mobile Money",bank_transfer:"Bank Transfer"}[p],d=p=>t.provider?.toLowerCase().includes("hubtel")?"Card, Mobile Money, and Bank Transfer":{card:"Visa, Mastercard, Maestro",mobile_money:"MTN, Vodafone, AirtelTigo",bank_transfer:"Transfer directly from your bank"}[p],i=e.computed(()=>[{id:"card",name:m("card"),description:d("card"),icon:"💳"},{id:"mobile_money",name:m("mobile_money"),description:d("mobile_money"),icon:"📱"},{id:"bank_transfer",name:m("bank_transfer"),description:d("bank_transfer"),icon:"🏦"}].filter(p=>t.methods.includes(p.id)));return(p,u)=>(e.openBlock(),e.createElementBlock("div",Z,[u[0]||(u[0]=e.createElementVNode("h3",{class:"reevit-section-title"},"Select Payment Method",-1)),e.createElementVNode("p",ee," Pay "+e.toDisplayString(e.unref(v.formatAmount)(n.amount,n.currency)),1),e.createElementVNode("div",te,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.value,a=>(e.openBlock(),e.createElementBlock("button",{key:a.id,type:"button",class:e.normalizeClass(e.unref(v.cn)("reevit-method-card",n.selected===a.id&&"reevit-method-card--selected")),onClick:h=>l("select",a.id)},[e.createElementVNode("span",oe,e.toDisplayString(a.icon),1),e.createElementVNode("div",re,[e.createElementVNode("span",ae,e.toDisplayString(a.name),1),e.createElementVNode("span",se,e.toDisplayString(a.description),1)]),e.createElementVNode("div",ie,[n.selected===a.id?(e.openBlock(),e.createElementBlock("div",le)):e.createCommentVNode("",!0)])],10,ne))),128))])]))}}),ce={class:"reevit-form-group"},de=["disabled"],ue={class:"reevit-network-selector"},me={class:"reevit-networks-grid"},pe=["onClick","disabled"],ye={key:0,class:"reevit-error-message"},ve=["disabled"],he={key:0,class:"reevit-spinner"},fe={key:1},U=e.defineComponent({__name:"MobileMoneyForm",props:{initialPhone:{},loading:{type:Boolean}},emits:["submit"],setup(n,{emit:o}){const t=n,l=o,r=e.ref(t.initialPhone||""),m=e.ref(null),d=e.ref(null);e.watch(r,u=>{const a=v.detectNetwork(u);a&&(m.value=a),d.value&&(d.value=null)});const i=()=>{if(!v.validatePhone(r.value)){d.value="Please enter a valid phone number";return}if(!m.value){d.value="Please select your mobile network";return}l("submit",{phone:r.value,network:m.value})},p=[{id:"mtn",name:"MTN",color:"#FFCC00"},{id:"vodafone",name:"Vodafone",color:"#E60000"},{id:"airteltigo",name:"AirtelTigo",color:"#005596"}];return(u,a)=>(e.openBlock(),e.createElementBlock("form",{class:"reevit-momo-form",onSubmit:e.withModifiers(i,["prevent"])},[e.createElementVNode("div",ce,[a[1]||(a[1]=e.createElementVNode("label",{class:"reevit-label",for:"reevit-phone"},"Phone Number",-1)),e.withDirectives(e.createElementVNode("input",{id:"reevit-phone","onUpdate:modelValue":a[0]||(a[0]=h=>r.value=h),type:"tel",class:e.normalizeClass(["reevit-input",{"reevit-input--error":d.value&&!e.unref(v.validatePhone)(r.value)}]),placeholder:"e.g. 024 123 4567",disabled:n.loading,autocomplete:"tel"},null,10,de),[[e.vModelText,r.value]])]),e.createElementVNode("div",ue,[a[2]||(a[2]=e.createElementVNode("label",{class:"reevit-label"},"Select Network",-1)),e.createElementVNode("div",me,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(p,h=>e.createElementVNode("button",{key:h.id,type:"button",class:e.normalizeClass(e.unref(v.cn)("reevit-network-btn",m.value===h.id&&"reevit-network-btn--selected")),onClick:E=>m.value=h.id,disabled:n.loading},[e.createElementVNode("div",{class:"reevit-network-dot",style:e.normalizeStyle({backgroundColor:h.color})},null,4),e.createTextVNode(" "+e.toDisplayString(h.name),1)],10,pe)),64))])]),d.value?(e.openBlock(),e.createElementBlock("p",ye,e.toDisplayString(d.value),1)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"submit",class:"reevit-submit-btn",disabled:n.loading||!r.value},[n.loading?(e.openBlock(),e.createElementBlock("span",he)):(e.openBlock(),e.createElementBlock("span",fe,"Continue"))],8,ve),a[3]||(a[3]=e.createElementVNode("p",{class:"reevit-secure-text"}," 🔒 Secure mobile money payment via Reevit ",-1))],32))}});class be{constructor(o){this.baseUrl="https://unified-pay.hubtel.com",this.messageHandler=null,this.stylesInjected=!1,o&&(this.baseUrl=o)}redirect({purchaseInfo:o,config:t}){const l=this.createCheckoutUrl(o,t),r=window.open(l);if(!r||r.closed||typeof r.closed>"u")throw new Error("Popup was blocked by the browser. Please allow popups for this site.")}initIframe({purchaseInfo:o,callBacks:t,config:l,iframeStyle:r}){var m,d,i;this.registerEvents(t);const p=document.getElementById("hubtel-checkout-iframe");if(!p)throw new Error('Container element with id "hubtel-checkout-iframe" not found in the DOM.');p.innerHTML="";const u=document.createElement("div");u.textContent="Loading...",p.appendChild(u);const a=document.createElement("iframe");a.setAttribute("id","hubtel-iframe-element"),a.src=this.createCheckoutUrl(o,l),a.style.display="none",a.style.width=(m=r?.width)!==null&&m!==void 0?m:"100%",a.style.height=(d=r?.height)!==null&&d!==void 0?d:"100%",a.style.minHeight=r?.minHeight||"400px",a.style.border=(i=r?.border)!==null&&i!==void 0?i:"none",a.onload=()=>{var h;p.removeChild(u),a.style.display="block",(h=t.onLoad)===null||h===void 0||h.call(t)},p.appendChild(a)}openModal({purchaseInfo:o,callBacks:t,config:l}){this.injectStyles(),this.createIframe(),this.handleBackButton(),this.registerEvents(t),this.renderWebpageInPopup(this.createCheckoutUrl(o,l),t.onClose,t.onLoad)}createCheckoutUrl(o,t){const l=Object.assign(Object.assign({},o),t),r=Object.keys(l).reduce((u,a)=>(l[a]!==null&&l[a]!==void 0&&(u[a]=l[a]),u),{}),m=Object.keys(r).map(u=>`${u}=${encodeURIComponent(r[u])}`).join("&"),d=this.encodeBase64(m),i=encodeURIComponent(d);return`${r?.branding==="disabled"?`${this.baseUrl}/pay/direct`:`${this.baseUrl}/pay`}?p=${i}`}encodeBase64(o){return btoa(unescape(encodeURIComponent(o)))}handleBackButton(){window.addEventListener("popstate",()=>{this.closePopUp()})}createIframe(){const o=document.createElement("div");o.setAttribute("id","backdrop"),o.classList.add("backdrop");const t=document.createElement("span");t.classList.add("checkout-loader"),o.appendChild(t),document.body.appendChild(o)}registerEvents(o){this.messageHandler&&window.removeEventListener("message",this.messageHandler,!1);const t=l=>{var r,m,d,i,p,u;if(l.origin!==this.baseUrl)return;const{data:a}=l;if(a.success===!0)(r=o.onPaymentSuccess)===null||r===void 0||r.call(o,a);else if(a.success===!1)(m=o.onPaymentFailure)===null||m===void 0||m.call(o,a);else if(a.initialized)(d=o.init)===null||d===void 0||d.call(o,a),(i=o.onInit)===null||i===void 0||i.call(o,a);else if(a.feesChanged)(p=o.onFeesChanged)===null||p===void 0||p.call(o,a.fees);else if(a.resize){const h=document.getElementById("hubtel-iframe-element");h&&(h.style.height=a.height+"px"),(u=o?.onResize)===null||u===void 0||u.call(o,a)}};this.messageHandler=t,window.addEventListener("message",t,!1)}destroy(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler,!1),this.messageHandler=null)}renderWebpageInPopup(o,t,l){const r=document.createElement("div");r.classList.add("checkout-modal");const m=document.createElement("div");m.setAttribute("id","checkout-close-icon"),m.innerHTML="×",m.classList.add("close-icon"),m.addEventListener("click",()=>{this.closePopUp(),t?.()}),r.appendChild(m);const d=document.createElement("iframe");d.src=o,history.pushState({modalOpen:!0},""),d.classList.add("iframe"),r.appendChild(d),document.body.appendChild(r),r.style.opacity="0",d.addEventListener("load",()=>{r.style.opacity="1",l?.()})}closePopUp(){const o=document.querySelector(".backdrop"),t=document.querySelector(".checkout-modal");o&&document.body.removeChild(o),t&&document.body.removeChild(t),history.replaceState(null,""),window.removeEventListener("popstate",this.closePopUp)}injectStyles(){if(this.stylesInjected)return;const o=document.createElement("style");o.type="text/css",o.setAttribute("data-hubtel-checkout","true"),o.innerHTML=`
2
2
  .backdrop {
3
3
  position: fixed;
4
4
  left: 0;
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { createInitialState as le, ReevitAPIClient as ce, generateReference as d
3
3
  import { ReevitAPIClient as vt, cn as ht, createReevitClient as ft, detectCountryFromCurrency as bt, detectNetwork as wt, formatAmount as kt, formatPhone as Pt, validatePhone as Ct } from "@reevit/core";
4
4
  function he(t) {
5
5
  const n = t.toLowerCase();
6
- return n.includes("paystack") ? "paystack" : n.includes("hubtel") ? "hubtel" : n.includes("flutterwave") ? "flutterwave" : "paystack";
6
+ return n.includes("paystack") ? "paystack" : n.includes("hubtel") ? "hubtel" : n.includes("flutterwave") ? "flutterwave" : n.includes("stripe") ? "stripe" : n.includes("monnify") ? "monnify" : n.includes("mpesa") || n.includes("m-pesa") ? "mpesa" : "paystack";
7
7
  }
8
8
  function fe(t, n) {
9
9
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reevit/vue",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "Unified Payment Widget for Vue 3 Applications",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",