@reevit/vue 0.3.6 → 0.3.8
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/bridges/index.d.ts +0 -1
- package/dist/bridges/loaders.d.ts +1 -1
- package/dist/components/MobileMoneyForm.vue.d.ts +0 -1
- package/dist/components/PaymentMethodSelector.vue.d.ts +1 -1
- package/dist/components/ReevitCheckout.vue.d.ts +0 -1
- package/dist/composables/index.d.ts +0 -1
- package/dist/composables/useReevit.d.ts +10 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +451 -431
- package/package.json +2 -2
- package/dist/bridges/index.d.ts.map +0 -1
- package/dist/bridges/loaders.d.ts.map +0 -1
- package/dist/components/MobileMoneyForm.vue.d.ts.map +0 -1
- package/dist/components/PaymentMethodSelector.vue.d.ts.map +0 -1
- package/dist/components/ReevitCheckout.vue.d.ts.map +0 -1
- package/dist/composables/index.d.ts.map +0 -1
- package/dist/composables/useReevit.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/dist/bridges/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
export { loadPaystackScript, loadHubtelScript, loadFlutterwaveScript, loadStripeScript, loadMonnifyScript, openPaystackPopup, openHubtelPopup, openFlutterwaveModal, createStripeInstance, confirmStripePayment, openMonnifyModal, initiateMPesaSTKPush, type PaystackConfig, type HubtelConfig, type FlutterwaveConfig, type StripeConfig, type MonnifyConfig, type MPesaConfig, type MPesaSTKPushResult, } from './loaders';
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -102,6 +102,7 @@ export interface HubtelConfig {
|
|
|
102
102
|
callbackUrl?: string;
|
|
103
103
|
customerPhone?: string;
|
|
104
104
|
customerEmail?: string;
|
|
105
|
+
basicAuth?: string;
|
|
105
106
|
onSuccess: (response: Record<string, unknown>) => void;
|
|
106
107
|
onClose: () => void;
|
|
107
108
|
}
|
|
@@ -222,4 +223,3 @@ export interface MPesaSTKPushResult {
|
|
|
222
223
|
*/
|
|
223
224
|
export declare function initiateMPesaSTKPush(config: MPesaConfig, apiEndpoint: string): Promise<MPesaSTKPushResult>;
|
|
224
225
|
export {};
|
|
225
|
-
//# sourceMappingURL=loaders.d.ts.map
|
|
@@ -9,4 +9,3 @@ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {
|
|
|
9
9
|
onSubmit?: ((data: MobileMoneyFormData) => any) | undefined;
|
|
10
10
|
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLFormElement>;
|
|
11
11
|
export default _default;
|
|
12
|
-
//# sourceMappingURL=MobileMoneyForm.vue.d.ts.map
|
|
@@ -4,6 +4,7 @@ type __VLS_Props = {
|
|
|
4
4
|
selected: PaymentMethod | null;
|
|
5
5
|
amount: number;
|
|
6
6
|
currency: string;
|
|
7
|
+
provider?: string;
|
|
7
8
|
};
|
|
8
9
|
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
9
10
|
select: (method: PaymentMethod) => any;
|
|
@@ -11,4 +12,3 @@ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {
|
|
|
11
12
|
onSelect?: ((method: PaymentMethod) => any) | undefined;
|
|
12
13
|
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
13
14
|
export default _default;
|
|
14
|
-
//# sourceMappingURL=PaymentMethodSelector.vue.d.ts.map
|
|
@@ -13,6 +13,11 @@ export declare function useReevit(options: UseReevitOptions): {
|
|
|
13
13
|
readonly id: string;
|
|
14
14
|
readonly clientSecret: string;
|
|
15
15
|
readonly pspPublicKey?: string | undefined;
|
|
16
|
+
readonly pspCredentials?: {
|
|
17
|
+
readonly [x: string]: Readonly<unknown>;
|
|
18
|
+
readonly merchantAccount?: string | number | undefined;
|
|
19
|
+
readonly basicAuth?: string | undefined;
|
|
20
|
+
} | undefined;
|
|
16
21
|
readonly amount: number;
|
|
17
22
|
readonly currency: string;
|
|
18
23
|
readonly status: "pending" | "processing" | "succeeded" | "failed" | "cancelled";
|
|
@@ -31,6 +36,11 @@ export declare function useReevit(options: UseReevitOptions): {
|
|
|
31
36
|
readonly id: string;
|
|
32
37
|
readonly clientSecret: string;
|
|
33
38
|
readonly pspPublicKey?: string | undefined;
|
|
39
|
+
readonly pspCredentials?: {
|
|
40
|
+
readonly [x: string]: Readonly<unknown>;
|
|
41
|
+
readonly merchantAccount?: string | number | undefined;
|
|
42
|
+
readonly basicAuth?: string | undefined;
|
|
43
|
+
} | undefined;
|
|
34
44
|
readonly amount: number;
|
|
35
45
|
readonly currency: string;
|
|
36
46
|
readonly status: "pending" | "processing" | "succeeded" | "failed" | "cancelled";
|
|
@@ -108,4 +118,3 @@ export declare function useReevit(options: UseReevitOptions): {
|
|
|
108
118
|
canRetry: Readonly<import('vue').Ref<boolean, boolean>>;
|
|
109
119
|
};
|
|
110
120
|
export {};
|
|
111
|
-
//# sourceMappingURL=useReevit.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,3 @@ export { useReevit } from './composables';
|
|
|
5
5
|
export type { PaymentMethod, MobileMoneyNetwork, ReevitCheckoutConfig, ReevitCheckoutCallbacks, CheckoutState, PaymentResult, PaymentError, ReevitTheme, MobileMoneyFormData, PaymentIntent, PSPType, PaymentSource, } from '../../core/src/index.ts';
|
|
6
6
|
export { formatAmount, validatePhone, detectNetwork, formatPhone, detectCountryFromCurrency, cn, ReevitAPIClient, createReevitClient, } from '../../core/src/index.ts';
|
|
7
7
|
export { loadPaystackScript, loadHubtelScript, loadFlutterwaveScript, loadStripeScript, loadMonnifyScript, openPaystackPopup, openHubtelPopup, openFlutterwaveModal, createStripeInstance, confirmStripePayment, openMonnifyModal, initiateMPesaSTKPush, type PaystackConfig, type HubtelConfig, type FlutterwaveConfig, type StripeConfig, type MonnifyConfig, type MPesaConfig, type MPesaSTKPushResult, } from './bridges';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
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(t){const o=t.toLowerCase();return o.includes("paystack")?"paystack":o.includes("hubtel")?"hubtel":o.includes("flutterwave")?"flutterwave":"paystack"}function X(t,o){return{id:t.id,clientSecret:t.client_secret,pspPublicKey:t.psp_public_key,amount:t.amount,currency:t.currency,status:t.status,recommendedPsp:Q(t.provider),availableMethods:o.paymentMethods||["card","mobile_money"],reference:t.reference||o.reference,connectionId:t.connection_id,provider:t.provider,feeAmount:t.fee_amount,feeCurrency:t.fee_currency,netAmount:t.net_amount,metadata:o.metadata}}function U(t){const{config:o,onSuccess:n,onError:c,onClose:a,onStateChange:i,apiBaseUrl:u}=t,r=e.ref(v.createInitialState());if(o.initialPaymentIntent){const d=o.initialPaymentIntent;r.value={...r.value,status:"ready",paymentIntent:d,selectedMethod:d.availableMethods?.length===1?d.availableMethods[0]:null}}const y=new v.ReevitAPIClient({publicKey:o.publicKey,baseUrl:u}),m=d=>{r.value=v.reevitReducer(r.value,d)};e.watch(()=>r.value.status,d=>{i?.(d)});const l=async d=>{m({type:"INIT_START"});try{const s=o.reference||v.generateReference(),p=v.detectCountryFromCurrency(o.currency),k=d||o.paymentMethods?.[0]||"card",{data:b,error:T}=await y.createPaymentIntent({...o,reference:s},k,p);if(T){m({type:"INIT_ERROR",payload:T}),c?.(T);return}if(!b){const O={code:"INIT_FAILED",message:"No data received from API",recoverable:!0};m({type:"INIT_ERROR",payload:O}),c?.(O);return}const J=X(b,{...o,reference:s});m({type:"INIT_SUCCESS",payload:J})}catch(s){const p={code:"INIT_FAILED",message:s instanceof Error?s.message:"Failed to initialize checkout",recoverable:!0,originalError:s};m({type:"INIT_ERROR",payload:p}),c?.(p)}},h=d=>{m({type:"SELECT_METHOD",payload:d})},E=async d=>{if(!(!r.value.paymentIntent||!r.value.selectedMethod)){m({type:"PROCESS_START"});try{let s;if(r.value.paymentIntent.clientSecret){const{data:k,error:b}=await y.confirmPaymentIntent(r.value.paymentIntent.id,r.value.paymentIntent.clientSecret);if(b){m({type:"PROCESS_ERROR",payload:b}),c?.(b);return}s=k}else{const{data:k,error:b}=await y.confirmPayment(r.value.paymentIntent.id);if(b){m({type:"PROCESS_ERROR",payload:b}),c?.(b);return}s=k}const p={paymentId:r.value.paymentIntent.id,reference:d.reference||r.value.paymentIntent.reference||r.value.paymentIntent.metadata?.reference||"",amount:r.value.paymentIntent.amount,currency:r.value.paymentIntent.currency,paymentMethod:r.value.selectedMethod,psp:r.value.paymentIntent.recommendedPsp,pspReference:d.pspReference||s?.provider_ref_id||"",status:"success",metadata:d};m({type:"PROCESS_SUCCESS",payload:p}),n?.(p)}catch(s){const p={code:"PAYMENT_FAILED",message:s instanceof Error?s.message:"Payment failed",recoverable:!0,originalError:s};m({type:"PROCESS_ERROR",payload:p}),c?.(p)}}},w=async d=>{await E(d)},R=d=>{m({type:"PROCESS_ERROR",payload:d}),c?.(d)},P=()=>{m({type:"RESET"})},I=async()=>{if(r.value.paymentIntent&&r.value.status!=="success")try{await y.cancelPaymentIntent(r.value.paymentIntent.id)}catch{}m({type:"CLOSE"}),a?.()},C=e.computed(()=>r.value.status),V=e.computed(()=>r.value.paymentIntent),S=e.computed(()=>r.value.selectedMethod),B=e.computed(()=>r.value.error),f=e.computed(()=>r.value.result),N=e.computed(()=>r.value.status==="loading"||r.value.status==="processing"),g=e.computed(()=>r.value.status==="ready"||r.value.status==="method_selected"||r.value.status==="processing"),_=e.computed(()=>r.value.status==="success"),x=e.computed(()=>r.value.error?.recoverable??!1);return{status:e.readonly(C),paymentIntent:e.readonly(V),selectedMethod:e.readonly(S),error:e.readonly(B),result:e.readonly(f),initialize:l,selectMethod:h,processPayment:E,handlePspSuccess:w,handlePspError:R,reset:P,close:I,isLoading:e.readonly(N),isReady:e.readonly(g),isComplete:e.readonly(_),canRetry:e.readonly(x)}}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:{}},emits:["select"],setup(t,{emit:o}){const n=t,c=o,a=e.computed(()=>[{id:"card",name:"Card",description:"Visa, Mastercard, Maestro",icon:"💳"},{id:"mobile_money",name:"Mobile Money",description:"MTN, Vodafone, AirtelTigo",icon:"📱"},{id:"bank_transfer",name:"Bank Transfer",description:"Transfer directly from your bank",icon:"🏦"}].filter(i=>n.methods.includes(i.id)));return(i,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)(t.amount,t.currency)),1),e.createElementVNode("div",te,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.value,r=>(e.openBlock(),e.createElementBlock("button",{key:r.id,type:"button",class:e.normalizeClass(e.unref(v.cn)("reevit-method-card",t.selected===r.id&&"reevit-method-card--selected")),onClick:y=>c("select",r.id)},[e.createElementVNode("span",oe,e.toDisplayString(r.icon),1),e.createElementVNode("div",re,[e.createElementVNode("span",ae,e.toDisplayString(r.name),1),e.createElementVNode("span",se,e.toDisplayString(r.description),1)]),e.createElementVNode("div",ie,[t.selected===r.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},L=e.defineComponent({__name:"MobileMoneyForm",props:{initialPhone:{},loading:{type:Boolean}},emits:["submit"],setup(t,{emit:o}){const n=t,c=o,a=e.ref(n.initialPhone||""),i=e.ref(null),u=e.ref(null);e.watch(a,m=>{const l=v.detectNetwork(m);l&&(i.value=l),u.value&&(u.value=null)});const r=()=>{if(!v.validatePhone(a.value)){u.value="Please enter a valid phone number";return}if(!i.value){u.value="Please select your mobile network";return}c("submit",{phone:a.value,network:i.value})},y=[{id:"mtn",name:"MTN",color:"#FFCC00"},{id:"vodafone",name:"Vodafone",color:"#E60000"},{id:"airteltigo",name:"AirtelTigo",color:"#005596"}];return(m,l)=>(e.openBlock(),e.createElementBlock("form",{class:"reevit-momo-form",onSubmit:e.withModifiers(r,["prevent"])},[e.createElementVNode("div",ce,[l[1]||(l[1]=e.createElementVNode("label",{class:"reevit-label",for:"reevit-phone"},"Phone Number",-1)),e.withDirectives(e.createElementVNode("input",{id:"reevit-phone","onUpdate:modelValue":l[0]||(l[0]=h=>a.value=h),type:"tel",class:e.normalizeClass(["reevit-input",{"reevit-input--error":u.value&&!e.unref(v.validatePhone)(a.value)}]),placeholder:"e.g. 024 123 4567",disabled:t.loading,autocomplete:"tel"},null,10,de),[[e.vModelText,a.value]])]),e.createElementVNode("div",ue,[l[2]||(l[2]=e.createElementVNode("label",{class:"reevit-label"},"Select Network",-1)),e.createElementVNode("div",me,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(y,h=>e.createElementVNode("button",{key:h.id,type:"button",class:e.normalizeClass(e.unref(v.cn)("reevit-network-btn",i.value===h.id&&"reevit-network-btn--selected")),onClick:E=>i.value=h.id,disabled:t.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))])]),u.value?(e.openBlock(),e.createElementBlock("p",ye,e.toDisplayString(u.value),1)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"submit",class:"reevit-submit-btn",disabled:t.loading||!a.value},[t.loading?(e.openBlock(),e.createElementBlock("span",he)):(e.openBlock(),e.createElementBlock("span",fe,"Continue"))],8,ve),l[3]||(l[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:n}){const c=this.createCheckoutUrl(o,n),a=window.open(c);if(!a||a.closed||typeof a.closed>"u")throw new Error("Popup was blocked by the browser. Please allow popups for this site.")}initIframe({purchaseInfo:o,callBacks:n,config:c,iframeStyle:a}){var i,u,r;this.registerEvents(n);const y=document.getElementById("hubtel-checkout-iframe");if(!y)throw new Error('Container element with id "hubtel-checkout-iframe" not found in the DOM.');y.innerHTML="";const m=document.createElement("div");m.textContent="Loading...",y.appendChild(m);const l=document.createElement("iframe");l.setAttribute("id","hubtel-iframe-element"),l.src=this.createCheckoutUrl(o,c),l.style.display="none",l.style.width=(i=a?.width)!==null&&i!==void 0?i:"100%",l.style.height=(u=a?.height)!==null&&u!==void 0?u:"100%",l.style.minHeight=a?.minHeight||"400px",l.style.border=(r=a?.border)!==null&&r!==void 0?r:"none",l.onload=()=>{var h;y.removeChild(m),l.style.display="block",(h=n.onLoad)===null||h===void 0||h.call(n)},y.appendChild(l)}openModal({purchaseInfo:o,callBacks:n,config:c}){this.injectStyles(),this.createIframe(),this.handleBackButton(),this.registerEvents(n),this.renderWebpageInPopup(this.createCheckoutUrl(o,c),n.onClose,n.onLoad)}createCheckoutUrl(o,n){const c=Object.assign(Object.assign({},o),n),a=Object.keys(c).reduce((m,l)=>(c[l]!==null&&c[l]!==void 0&&(m[l]=c[l]),m),{}),i=Object.keys(a).map(m=>`${m}=${encodeURIComponent(a[m])}`).join("&"),u=this.encodeBase64(i),r=encodeURIComponent(u);return`${a?.branding==="disabled"?`${this.baseUrl}/pay/direct`:`${this.baseUrl}/pay`}?p=${r}`}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 n=document.createElement("span");n.classList.add("checkout-loader"),o.appendChild(n),document.body.appendChild(o)}registerEvents(o){this.messageHandler&&window.removeEventListener("message",this.messageHandler,!1);const n=c=>{var a,i,u,r,y,m;if(c.origin!==this.baseUrl)return;const{data:l}=c;if(l.success===!0)(a=o.onPaymentSuccess)===null||a===void 0||a.call(o,l);else if(l.success===!1)(i=o.onPaymentFailure)===null||i===void 0||i.call(o,l);else if(l.initialized)(u=o.init)===null||u===void 0||u.call(o,l),(r=o.onInit)===null||r===void 0||r.call(o,l);else if(l.feesChanged)(y=o.onFeesChanged)===null||y===void 0||y.call(o,l.fees);else if(l.resize){const h=document.getElementById("hubtel-iframe-element");h&&(h.style.height=l.height+"px"),(m=o?.onResize)===null||m===void 0||m.call(o,l)}};this.messageHandler=n,window.addEventListener("message",n,!1)}destroy(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler,!1),this.messageHandler=null)}renderWebpageInPopup(o,n,c){const a=document.createElement("div");a.classList.add("checkout-modal");const i=document.createElement("div");i.setAttribute("id","checkout-close-icon"),i.innerHTML="×",i.classList.add("close-icon"),i.addEventListener("click",()=>{this.closePopUp(),n?.()}),a.appendChild(i);const u=document.createElement("iframe");u.src=o,history.pushState({modalOpen:!0},""),u.classList.add("iframe"),a.appendChild(u),document.body.appendChild(a),a.style.opacity="0",u.addEventListener("load",()=>{a.style.opacity="1",c?.()})}closePopUp(){const o=document.querySelector(".backdrop"),n=document.querySelector(".checkout-modal");o&&document.body.removeChild(o),n&&document.body.removeChild(n),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":"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;
|
|
@@ -98,4 +98,4 @@
|
|
|
98
98
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
`,document.head.appendChild(o),this.stylesInjected=!0}}const $=new Map;function M(t,o){const n=$.get(o);if(n)return n;const c=new Promise((a,i)=>{if(document.getElementById(o)){a();return}const u=document.createElement("script");u.id=o,u.src=t,u.async=!0,u.onload=()=>a(),u.onerror=()=>i(new Error(`Failed to load ${o} script`)),document.head.appendChild(u)});return $.set(o,c),c}function F(){return M("https://js.paystack.co/v1/inline.js","paystack-script")}function Ee(){return Promise.resolve()}function j(){return M("https://checkout.flutterwave.com/v3.js","flutterwave-script")}function A(){return M("https://js.stripe.com/v3/","stripe-script")}function z(){return M("https://sdk.monnify.com/plugin/monnify.js","monnify-script")}async function K(t){if(await F(),!window.PaystackPop)throw new Error("Paystack script not loaded");window.PaystackPop.setup({key:t.key,email:t.email,amount:t.amount,currency:t.currency,ref:t.ref,metadata:t.metadata,callback:t.onSuccess,onClose:t.onClose}).openIframe()}async function H(t){const o=new be,n={amount:t.amount,purchaseDescription:t.purchaseDescription,customerPhoneNumber:t.customerPhone||"",clientReference:`hubtel_${Date.now()}`},c={branding:"enabled",callbackUrl:t.callbackUrl||(typeof window<"u"?window.location.href:""),merchantAccount:typeof t.clientId=="string"?parseInt(t.clientId,10):t.clientId,basicAuth:""};o.openModal({purchaseInfo:n,config:c,callBacks:{onPaymentSuccess:a=>{t.onSuccess(a),o.closePopUp()},onPaymentFailure:()=>{t.onClose()},onClose:()=>{t.onClose()}}})}async function q(t){if(await j(),!window.FlutterwaveCheckout)throw new Error("Flutterwave script not loaded");window.FlutterwaveCheckout({public_key:t.public_key,tx_ref:t.tx_ref,amount:t.amount,currency:t.currency,customer:t.customer,payment_options:t.payment_options,customizations:t.customizations,callback:t.callback,onclose:t.onclose})}async function Y(t){if(await A(),!window.Stripe)throw new Error("Stripe.js not loaded");return window.Stripe(t)}async function ke(t){const n=await(await Y(t.publishableKey)).confirmPayment({elements:t.elements,clientSecret:t.clientSecret,redirect:"if_required"});n.error?t.onError({message:n.error.message||"Payment failed"}):n.paymentIntent&&t.onSuccess({paymentIntentId:n.paymentIntent.id,status:n.paymentIntent.status})}async function W(t){if(await z(),!window.MonnifySDK)throw new Error("Monnify SDK not loaded");window.MonnifySDK.initialize({amount:t.amount,currency:t.currency,reference:t.reference,customerName:t.customerName,customerEmail:t.customerEmail,customerMobileNumber:t.customerPhone,apiKey:t.apiKey,contractCode:t.contractCode,paymentDescription:t.paymentDescription||"Payment",isTestMode:t.isTestMode??!1,metadata:t.metadata,onComplete:o=>{o.status==="SUCCESS"?t.onSuccess({transactionReference:o.transactionReference,paymentReference:o.paymentReference,...o}):t.onError?.({message:o.message||"Payment failed"})},onClose:t.onClose})}async function G(t,o){t.onInitiated();try{const n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({phone_number:t.phoneNumber,amount:t.amount,reference:t.reference,description:t.description})});if(!n.ok){const i=(await n.json().catch(()=>({}))).message||"Failed to initiate M-Pesa payment";return t.onError({message:i}),{status:"failed",message:i}}const c=await n.json();return{status:"initiated",message:"Please check your phone and enter your M-Pesa PIN to complete the payment.",transactionId:c.checkout_request_id||c.transaction_id}}catch(n){const c=n instanceof Error?n.message:"Network error";return t.onError({message:c}),{status:"failed",message:c}}}const Pe=["disabled"],we={key:0,class:"reevit-spinner"},Ce={class:"reevit-modal-body"},Se={key:0,class:"reevit-loading-state"},ge={key:1,class:"reevit-error-state"},_e={key:2,class:"reevit-success-state"},Ie={key:1,class:"reevit-method-form-container"},Ne={key:2,class:"reevit-card-info"},Me=["disabled"],Re={key:0,class:"reevit-spinner"},Ve={key:1},Be=e.defineComponent({__name:"ReevitCheckout",props:{publicKey:{},amount:{},currency:{},email:{},phone:{},reference:{},metadata:{},paymentMethods:{},theme:{},isOpen:{type:Boolean},apiBaseUrl:{},initialPaymentIntent:{}},emits:["success","error","close"],setup(t,{emit:o}){const n=t,c=o,{status:a,paymentIntent:i,selectedMethod:u,error:r,isLoading:y,isReady:m,initialize:l,selectMethod:h,handlePspSuccess:E,handlePspError:w,close:R}=U({config:{publicKey:n.publicKey,amount:n.amount,currency:n.currency,email:n.email,phone:n.phone,reference:n.reference,metadata:n.metadata,paymentMethods:n.paymentMethods,initialPaymentIntent:n.initialPaymentIntent},apiBaseUrl:n.apiBaseUrl,onSuccess:d=>c("success",d),onError:d=>c("error",d),onClose:()=>c("close")}),P=e.ref(n.isOpen??!1);e.watch(()=>n.isOpen,d=>{d!==void 0&&(P.value=d)});const I=()=>{P.value=!0,!i.value&&a.value==="idle"&&l()};e.watch([P,i,u],([d,s,p])=>{d&&s&&p&&p==="card"&&S(null)});const C=()=>{P.value=!1,R()},V=d=>{h(d)},S=async d=>{if(!i.value)return;const s=i.value.recommendedPsp;try{if(s==="paystack")await K({key:n.publicKey,email:n.email||"",amount:n.amount,currency:n.currency,ref:i.value.id,onSuccess:p=>E(p),onClose:()=>{}});else if(s==="hubtel")await H({clientId:n.publicKey,purchaseDescription:`Payment for ${n.amount} ${n.currency}`,amount:n.amount,customerPhone:d?.phone||n.phone,customerEmail:n.email,onSuccess:p=>E(p),onClose:()=>{}});else if(s==="flutterwave")await q({public_key:n.publicKey,tx_ref:i.value.id,amount:n.amount,currency:n.currency,customer:{email:n.email||"",phone_number:d?.phone||n.phone},callback:p=>E(p),onclose:()=>{}});else if(s==="monnify")await W({apiKey:i.value.pspPublicKey||n.publicKey,contractCode:n.metadata?.contract_code||n.publicKey,amount:n.amount,currency:n.currency,reference:i.value.reference||i.value.id,customerName:n.metadata?.customer_name||n.email||"",customerEmail:n.email||"",customerPhone:d?.phone||n.phone,metadata:n.metadata,onSuccess:p=>E(p),onClose:()=>{}});else if(s==="mpesa"){const p=`${n.apiBaseUrl||"https://api.reevit.io"}/v1/payments/${i.value.id}/mpesa`;await G({phoneNumber:d?.phone||n.phone||"",amount:n.amount,reference:i.value.reference||i.value.id,description:`Payment ${i.value.reference||""}`,onInitiated:()=>{},onSuccess:k=>E(k),onError:k=>w({code:"MPESA_ERROR",message:k.message})},p)}else w(s==="stripe"?{code:"STRIPE_NOT_IMPLEMENTED",message:"Stripe integration requires custom Elements setup. Please use the React SDK or implement custom Stripe Elements."}:{code:"UNSUPPORTED_PSP",message:`Payment provider "${s}" is not supported in this checkout.`})}catch(p){w({code:"BRIDGE_ERROR",message:p instanceof Error?p.message:"Failed to open payment gateway"})}},B=e.computed(()=>v.createThemeVariables(n.theme||{}));e.watch(P,d=>{d?document.body.style.overflow="hidden":document.body.style.overflow=""}),e.onUnmounted(()=>{document.body.style.overflow=""});const f=e.computed(()=>a.value),N=e.computed(()=>r.value),g=e.computed(()=>u.value),_=e.computed(()=>y.value),x=e.computed(()=>m.value);return(d,s)=>(e.openBlock(),e.createElementBlock("div",{class:"reevit-sdk-container",style:e.normalizeStyle(B.value)},[e.renderSlot(d.$slots,"default",{open:I,isLoading:_.value},()=>[e.createElementVNode("button",{type:"button",class:"reevit-pay-button",onClick:I,disabled:_.value},[_.value?(e.openBlock(),e.createElementBlock("span",we)):e.renderSlot(d.$slots,"button-text",{key:1},()=>[s[1]||(s[1]=e.createTextVNode("Pay Now",-1))])],8,Pe)]),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[P.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"reevit-modal-overlay",onClick:e.withModifiers(C,["self"])},[e.createElementVNode("div",{class:e.normalizeClass(["reevit-modal-content",{"reevit-modal--dark":n.theme?.darkMode}])},[e.createElementVNode("button",{class:"reevit-modal-close",onClick:C,"aria-label":"Close"}," × "),s[9]||(s[9]=e.createElementVNode("div",{class:"reevit-modal-header"},[e.createElementVNode("img",{src:"https://i.imgur.com/bzUR5Lm.png",alt:"Reevit",class:"reevit-modal__logo"})],-1)),e.createElementVNode("div",Ce,[f.value==="loading"?(e.openBlock(),e.createElementBlock("div",Se,[...s[2]||(s[2]=[e.createElementVNode("div",{class:"reevit-spinner reevit-spinner--large"},null,-1),e.createElementVNode("p",null,"Initializing payment...",-1)])])):f.value==="failed"&&N.value?(e.openBlock(),e.createElementBlock("div",ge,[s[3]||(s[3]=e.createElementVNode("div",{class:"reevit-error-icon"},"⚠️",-1)),s[4]||(s[4]=e.createElementVNode("h3",null,"Payment Failed",-1)),e.createElementVNode("p",null,e.toDisplayString(N.value.message),1),e.createElementVNode("button",{class:"reevit-retry-btn",onClick:s[0]||(s[0]=p=>e.unref(l)())},"Retry")])):f.value==="success"?(e.openBlock(),e.createElementBlock("div",_e,[s[5]||(s[5]=e.createElementVNode("div",{class:"reevit-success-icon"},"✅",-1)),s[6]||(s[6]=e.createElementVNode("h3",null,"Payment Successful",-1)),s[7]||(s[7]=e.createElementVNode("p",null,"Thank you for your payment.",-1)),e.createElementVNode("button",{class:"reevit-done-btn",onClick:C},"Done")])):x.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[f.value==="ready"||f.value==="method_selected"||f.value==="processing"?(e.openBlock(),e.createBlock(D,{key:0,methods:n.paymentMethods||["card","mobile_money"],selected:g.value,amount:n.amount,currency:n.currency,onSelect:V},null,8,["methods","selected","amount","currency"])):e.createCommentVNode("",!0),(f.value==="method_selected"||f.value==="processing")&&g.value==="mobile_money"?(e.openBlock(),e.createElementBlock("div",Ie,[e.createVNode(L,{"initial-phone":n.phone,loading:f.value==="processing",onSubmit:S},null,8,["initial-phone","loading"])])):e.createCommentVNode("",!0),(f.value==="method_selected"||f.value==="processing")&&g.value==="card"?(e.openBlock(),e.createElementBlock("div",Ne,[s[8]||(s[8]=e.createElementVNode("p",{class:"reevit-info-text"},"You will be redirected to our secure payment partner to complete your card payment.",-1)),e.createElementVNode("button",{class:"reevit-submit-btn",onClick:S,disabled:f.value==="processing"},[f.value==="processing"?(e.openBlock(),e.createElementBlock("span",Re)):(e.openBlock(),e.createElementBlock("span",Ve,"Proceed to Card Payment"))],8,Me)])):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0)]),s[10]||(s[10]=e.createElementVNode("div",{class:"reevit-modal-footer"},[e.createElementVNode("div",{class:"reevit-trust-badges"},[e.createElementVNode("span",null,"PCI DSS Compliant"),e.createElementVNode("span",null,"•"),e.createElementVNode("span",null,"SSL Secure")])],-1))],2)])):e.createCommentVNode("",!0)]))],4))}});Object.defineProperty(exports,"ReevitAPIClient",{enumerable:!0,get:()=>v.ReevitAPIClient});Object.defineProperty(exports,"cn",{enumerable:!0,get:()=>v.cn});Object.defineProperty(exports,"createReevitClient",{enumerable:!0,get:()=>v.createReevitClient});Object.defineProperty(exports,"detectCountryFromCurrency",{enumerable:!0,get:()=>v.detectCountryFromCurrency});Object.defineProperty(exports,"detectNetwork",{enumerable:!0,get:()=>v.detectNetwork});Object.defineProperty(exports,"formatAmount",{enumerable:!0,get:()=>v.formatAmount});Object.defineProperty(exports,"formatPhone",{enumerable:!0,get:()=>v.formatPhone});Object.defineProperty(exports,"validatePhone",{enumerable:!0,get:()=>v.validatePhone});exports.MobileMoneyForm=L;exports.PaymentMethodSelector=D;exports.ReevitCheckout=Be;exports.confirmStripePayment=ke;exports.createStripeInstance=Y;exports.initiateMPesaSTKPush=G;exports.loadFlutterwaveScript=j;exports.loadHubtelScript=Ee;exports.loadMonnifyScript=z;exports.loadPaystackScript=F;exports.loadStripeScript=A;exports.openFlutterwaveModal=q;exports.openHubtelPopup=H;exports.openMonnifyModal=W;exports.openPaystackPopup=K;exports.useReevit=U;
|
|
101
|
+
`,document.head.appendChild(o),this.stylesInjected=!0}}const O=new Map;function M(n,o){const t=O.get(o);if(t)return t;const l=new Promise((r,m)=>{if(document.getElementById(o)){r();return}const d=document.createElement("script");d.id=o,d.src=n,d.async=!0,d.onload=()=>r(),d.onerror=()=>m(new Error(`Failed to load ${o} script`)),document.head.appendChild(d)});return O.set(o,l),l}function F(){return M("https://js.paystack.co/v1/inline.js","paystack-script")}function ke(){return Promise.resolve()}function j(){return M("https://checkout.flutterwave.com/v3.js","flutterwave-script")}function A(){return M("https://js.stripe.com/v3/","stripe-script")}function z(){return M("https://sdk.monnify.com/plugin/monnify.js","monnify-script")}async function K(n){if(await F(),!window.PaystackPop)throw new Error("Paystack script not loaded");window.PaystackPop.setup({key:n.key,email:n.email,amount:n.amount,currency:n.currency,ref:n.ref,metadata:n.metadata,callback:n.onSuccess,onClose:n.onClose}).openIframe()}async function H(n){const o=new be,t={amount:n.amount,purchaseDescription:n.purchaseDescription,customerPhoneNumber:n.customerPhone||"",clientReference:`hubtel_${Date.now()}`},l={branding:"enabled",callbackUrl:n.callbackUrl||(typeof window<"u"?window.location.href:""),merchantAccount:typeof n.clientId=="string"?parseInt(n.clientId,10):n.clientId,basicAuth:n.basicAuth||""};o.openModal({purchaseInfo:t,config:l,callBacks:{onPaymentSuccess:r=>{n.onSuccess(r),o.closePopUp()},onPaymentFailure:()=>{n.onClose()},onClose:()=>{n.onClose()}}})}async function q(n){if(await j(),!window.FlutterwaveCheckout)throw new Error("Flutterwave script not loaded");window.FlutterwaveCheckout({public_key:n.public_key,tx_ref:n.tx_ref,amount:n.amount,currency:n.currency,customer:n.customer,payment_options:n.payment_options,customizations:n.customizations,callback:n.callback,onclose:n.onclose})}async function Y(n){if(await A(),!window.Stripe)throw new Error("Stripe.js not loaded");return window.Stripe(n)}async function Ee(n){const t=await(await Y(n.publishableKey)).confirmPayment({elements:n.elements,clientSecret:n.clientSecret,redirect:"if_required"});t.error?n.onError({message:t.error.message||"Payment failed"}):t.paymentIntent&&n.onSuccess({paymentIntentId:t.paymentIntent.id,status:t.paymentIntent.status})}async function W(n){if(await z(),!window.MonnifySDK)throw new Error("Monnify SDK not loaded");window.MonnifySDK.initialize({amount:n.amount,currency:n.currency,reference:n.reference,customerName:n.customerName,customerEmail:n.customerEmail,customerMobileNumber:n.customerPhone,apiKey:n.apiKey,contractCode:n.contractCode,paymentDescription:n.paymentDescription||"Payment",isTestMode:n.isTestMode??!1,metadata:n.metadata,onComplete:o=>{o.status==="SUCCESS"?n.onSuccess({transactionReference:o.transactionReference,paymentReference:o.paymentReference,...o}):n.onError?.({message:o.message||"Payment failed"})},onClose:n.onClose})}async function G(n,o){n.onInitiated();try{const t=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({phone_number:n.phoneNumber,amount:n.amount,reference:n.reference,description:n.description})});if(!t.ok){const m=(await t.json().catch(()=>({}))).message||"Failed to initiate M-Pesa payment";return n.onError({message:m}),{status:"failed",message:m}}const l=await t.json();return{status:"initiated",message:"Please check your phone and enter your M-Pesa PIN to complete the payment.",transactionId:l.checkout_request_id||l.transaction_id}}catch(t){const l=t instanceof Error?t.message:"Network error";return n.onError({message:l}),{status:"failed",message:l}}}const we=["disabled"],Pe={key:0,class:"reevit-spinner"},Ce={class:"reevit-modal-body"},Se={key:0,class:"reevit-loading-state"},_e={key:1,class:"reevit-error-state"},ge={key:2,class:"reevit-success-state"},Ie={key:1,class:"reevit-method-form-container"},Ne={key:2,class:"reevit-card-info"},Me=["disabled"],Re={key:0,class:"reevit-spinner"},Ve={key:1},Be=e.defineComponent({__name:"ReevitCheckout",props:{publicKey:{},amount:{},currency:{},email:{},phone:{},reference:{},metadata:{},paymentMethods:{},theme:{},isOpen:{type:Boolean},apiBaseUrl:{},initialPaymentIntent:{}},emits:["success","error","close"],setup(n,{emit:o}){const t=n,l=o,{status:r,paymentIntent:m,selectedMethod:d,error:i,isLoading:p,isReady:u,initialize:a,selectMethod:h,handlePspSuccess:E,handlePspError:P,close:R}=L({config:{publicKey:t.publicKey,amount:t.amount,currency:t.currency,email:t.email,phone:t.phone,reference:t.reference,metadata:t.metadata,paymentMethods:t.paymentMethods,initialPaymentIntent:t.initialPaymentIntent},apiBaseUrl:t.apiBaseUrl,onSuccess:c=>l("success",c),onError:c=>l("error",c),onClose:()=>l("close")}),w=e.ref(t.isOpen??!1);e.watch(()=>t.isOpen,c=>{c!==void 0&&(w.value=c)});const I=()=>{w.value=!0,!m.value&&r.value==="idle"&&a()};e.watch([w,m,d],([c,s,y])=>{c&&s&&y&&y==="card"&&S(null)});const C=()=>{w.value=!1,R()},V=c=>{h(c)},S=async c=>{const s=m.value;if(!s)return;const y=s.recommendedPsp;try{if(y==="paystack")await K({key:t.publicKey,email:t.email||"",amount:t.amount,currency:t.currency,ref:s.id,onSuccess:f=>E(f),onClose:()=>{}});else if(y==="hubtel")await H({clientId:s.pspCredentials?.merchantAccount||t.publicKey,purchaseDescription:`Payment for ${t.amount} ${t.currency}`,amount:t.amount,customerPhone:c?.phone||t.phone,customerEmail:t.email,basicAuth:s.pspCredentials?.basicAuth,onSuccess:f=>E(f),onClose:()=>{}});else if(y==="flutterwave")await q({public_key:t.publicKey,tx_ref:s.id,amount:t.amount,currency:t.currency,customer:{email:t.email||"",phone_number:c?.phone||t.phone},callback:f=>E(f),onclose:()=>{}});else if(y==="monnify")await W({apiKey:s.pspPublicKey||t.publicKey,contractCode:t.metadata?.contract_code||t.publicKey,amount:t.amount,currency:t.currency,reference:s.reference||s.id,customerName:t.metadata?.customer_name||t.email||"",customerEmail:t.email||"",customerPhone:c?.phone||t.phone,metadata:t.metadata,onSuccess:f=>E(f),onClose:()=>{}});else if(y==="mpesa"){const f=`${t.apiBaseUrl||"https://api.reevit.io"}/v1/payments/${s.id}/mpesa`;await G({phoneNumber:c?.phone||t.phone||"",amount:t.amount,reference:s.reference||s.id,description:`Payment ${s.reference||""}`,onInitiated:()=>{},onSuccess:k=>E(k),onError:k=>P({code:"MPESA_ERROR",message:k.message})},f)}else P(y==="stripe"?{code:"STRIPE_NOT_IMPLEMENTED",message:"Stripe integration requires custom Elements setup. Please use the React SDK or implement custom Stripe Elements."}:{code:"UNSUPPORTED_PSP",message:`Payment provider "${y}" is not supported in this checkout.`})}catch(f){P({code:"BRIDGE_ERROR",message:f instanceof Error?f.message:"Failed to open payment gateway"})}},B=e.computed(()=>v.createThemeVariables(t.theme||{}));e.watch(w,c=>{c?document.body.style.overflow="hidden":document.body.style.overflow=""}),e.onUnmounted(()=>{document.body.style.overflow=""});const b=e.computed(()=>r.value),N=e.computed(()=>i.value),_=e.computed(()=>d.value),g=e.computed(()=>p.value),T=e.computed(()=>u.value);return(c,s)=>(e.openBlock(),e.createElementBlock("div",{class:"reevit-sdk-container",style:e.normalizeStyle(B.value)},[e.renderSlot(c.$slots,"default",{open:I,isLoading:g.value},()=>[e.createElementVNode("button",{type:"button",class:"reevit-pay-button",onClick:I,disabled:g.value},[g.value?(e.openBlock(),e.createElementBlock("span",Pe)):e.renderSlot(c.$slots,"button-text",{key:1},()=>[s[1]||(s[1]=e.createTextVNode("Pay Now",-1))])],8,we)]),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[w.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"reevit-modal-overlay",onClick:e.withModifiers(C,["self"])},[e.createElementVNode("div",{class:e.normalizeClass(["reevit-modal-content",{"reevit-modal--dark":t.theme?.darkMode}])},[e.createElementVNode("button",{class:"reevit-modal-close",onClick:C,"aria-label":"Close"}," × "),s[9]||(s[9]=e.createElementVNode("div",{class:"reevit-modal-header"},[e.createElementVNode("img",{src:"https://i.imgur.com/bzUR5Lm.png",alt:"Reevit",class:"reevit-modal__logo"})],-1)),e.createElementVNode("div",Ce,[b.value==="loading"?(e.openBlock(),e.createElementBlock("div",Se,[...s[2]||(s[2]=[e.createElementVNode("div",{class:"reevit-spinner reevit-spinner--large"},null,-1),e.createElementVNode("p",null,"Initializing payment...",-1)])])):b.value==="failed"&&N.value?(e.openBlock(),e.createElementBlock("div",_e,[s[3]||(s[3]=e.createElementVNode("div",{class:"reevit-error-icon"},"⚠️",-1)),s[4]||(s[4]=e.createElementVNode("h3",null,"Payment Failed",-1)),e.createElementVNode("p",null,e.toDisplayString(N.value.message),1),e.createElementVNode("button",{class:"reevit-retry-btn",onClick:s[0]||(s[0]=y=>e.unref(a)())},"Retry")])):b.value==="success"?(e.openBlock(),e.createElementBlock("div",ge,[s[5]||(s[5]=e.createElementVNode("div",{class:"reevit-success-icon"},"✅",-1)),s[6]||(s[6]=e.createElementVNode("h3",null,"Payment Successful",-1)),s[7]||(s[7]=e.createElementVNode("p",null,"Thank you for your payment.",-1)),e.createElementVNode("button",{class:"reevit-done-btn",onClick:C},"Done")])):T.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[b.value==="ready"||b.value==="method_selected"||b.value==="processing"?(e.openBlock(),e.createBlock(D,{key:0,methods:t.paymentMethods||["card","mobile_money"],selected:_.value,amount:t.amount,currency:t.currency,provider:c.psp,onSelect:V},null,8,["methods","selected","amount","currency","provider"])):e.createCommentVNode("",!0),(b.value==="method_selected"||b.value==="processing")&&_.value==="mobile_money"?(e.openBlock(),e.createElementBlock("div",Ie,[e.createVNode(U,{"initial-phone":t.phone,loading:b.value==="processing",onSubmit:S},null,8,["initial-phone","loading"])])):e.createCommentVNode("",!0),(b.value==="method_selected"||b.value==="processing")&&_.value==="card"?(e.openBlock(),e.createElementBlock("div",Ne,[s[8]||(s[8]=e.createElementVNode("p",{class:"reevit-info-text"},"You will be redirected to our secure payment partner to complete your card payment.",-1)),e.createElementVNode("button",{class:"reevit-submit-btn",onClick:S,disabled:b.value==="processing"},[b.value==="processing"?(e.openBlock(),e.createElementBlock("span",Re)):(e.openBlock(),e.createElementBlock("span",Ve,"Proceed to Card Payment"))],8,Me)])):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0)]),s[10]||(s[10]=e.createElementVNode("div",{class:"reevit-modal-footer"},[e.createElementVNode("div",{class:"reevit-trust-badges"},[e.createElementVNode("span",null,"PCI DSS Compliant"),e.createElementVNode("span",null,"•"),e.createElementVNode("span",null,"SSL Secure")])],-1))],2)])):e.createCommentVNode("",!0)]))],4))}});Object.defineProperty(exports,"ReevitAPIClient",{enumerable:!0,get:()=>v.ReevitAPIClient});Object.defineProperty(exports,"cn",{enumerable:!0,get:()=>v.cn});Object.defineProperty(exports,"createReevitClient",{enumerable:!0,get:()=>v.createReevitClient});Object.defineProperty(exports,"detectCountryFromCurrency",{enumerable:!0,get:()=>v.detectCountryFromCurrency});Object.defineProperty(exports,"detectNetwork",{enumerable:!0,get:()=>v.detectNetwork});Object.defineProperty(exports,"formatAmount",{enumerable:!0,get:()=>v.formatAmount});Object.defineProperty(exports,"formatPhone",{enumerable:!0,get:()=>v.formatPhone});Object.defineProperty(exports,"validatePhone",{enumerable:!0,get:()=>v.validatePhone});exports.MobileMoneyForm=U;exports.PaymentMethodSelector=D;exports.ReevitCheckout=Be;exports.confirmStripePayment=Ee;exports.createStripeInstance=Y;exports.initiateMPesaSTKPush=G;exports.loadFlutterwaveScript=j;exports.loadHubtelScript=ke;exports.loadMonnifyScript=z;exports.loadPaystackScript=F;exports.loadStripeScript=A;exports.openFlutterwaveModal=q;exports.openHubtelPopup=H;exports.openMonnifyModal=W;exports.openPaystackPopup=K;exports.useReevit=L;
|