@reevit/vue 0.3.4 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridges/index.d.ts +0 -1
- package/dist/bridges/loaders.d.ts +4 -3
- package/dist/components/MobileMoneyForm.vue.d.ts +0 -1
- package/dist/components/PaymentMethodSelector.vue.d.ts +0 -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 +101 -1
- package/dist/index.mjs +601 -371
- package/package.json +3 -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
|
|
@@ -66,7 +66,8 @@ interface StripeCardElement {
|
|
|
66
66
|
*/
|
|
67
67
|
export declare function loadPaystackScript(): Promise<void>;
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* Hubtel now uses npm package @hubteljs/checkout
|
|
70
|
+
* No script loading needed
|
|
70
71
|
*/
|
|
71
72
|
export declare function loadHubtelScript(): Promise<void>;
|
|
72
73
|
/**
|
|
@@ -101,6 +102,7 @@ export interface HubtelConfig {
|
|
|
101
102
|
callbackUrl?: string;
|
|
102
103
|
customerPhone?: string;
|
|
103
104
|
customerEmail?: string;
|
|
105
|
+
basicAuth?: string;
|
|
104
106
|
onSuccess: (response: Record<string, unknown>) => void;
|
|
105
107
|
onClose: () => void;
|
|
106
108
|
}
|
|
@@ -183,7 +185,7 @@ export interface MPesaConfig {
|
|
|
183
185
|
*/
|
|
184
186
|
export declare function openPaystackPopup(config: PaystackConfig): Promise<void>;
|
|
185
187
|
/**
|
|
186
|
-
* Opens Hubtel popup
|
|
188
|
+
* Opens Hubtel popup using the @hubteljs/checkout npm package
|
|
187
189
|
*/
|
|
188
190
|
export declare function openHubtelPopup(config: HubtelConfig): Promise<void>;
|
|
189
191
|
/**
|
|
@@ -221,4 +223,3 @@ export interface MPesaSTKPushResult {
|
|
|
221
223
|
*/
|
|
222
224
|
export declare function initiateMPesaSTKPush(config: MPesaConfig, apiEndpoint: string): Promise<MPesaSTKPushResult>;
|
|
223
225
|
export {};
|
|
224
|
-
//# 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
|
|
@@ -11,4 +11,3 @@ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {
|
|
|
11
11
|
onSelect?: ((method: PaymentMethod) => any) | undefined;
|
|
12
12
|
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
13
13
|
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 +1,101 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),d=require("@reevit/core");function X(t){const s=t.toLowerCase();return s.includes("paystack")?"paystack":s.includes("hubtel")?"hubtel":s.includes("flutterwave")?"flutterwave":"paystack"}function Z(t,s){return{id:t.id,clientSecret:t.client_secret,pspPublicKey:t.psp_public_key,amount:t.amount,currency:t.currency,status:t.status,recommendedPsp:X(t.provider),availableMethods:s.paymentMethods||["card","mobile_money"],reference:t.reference||s.reference,connectionId:t.connection_id,provider:t.provider,feeAmount:t.fee_amount,feeCurrency:t.fee_currency,netAmount:t.net_amount,metadata:s.metadata}}function F(t){const{config:s,onSuccess:n,onError:i,onClose:p,onStateChange:l,apiBaseUrl:u}=t,a=e.ref(d.createInitialState());if(s.initialPaymentIntent){const r=s.initialPaymentIntent;a.value={...a.value,status:"ready",paymentIntent:r,selectedMethod:r.availableMethods?.length===1?r.availableMethods[0]:null}}const b=new d.ReevitAPIClient({publicKey:s.publicKey,baseUrl:u}),m=r=>{a.value=d.reevitReducer(a.value,r)};e.watch(()=>a.value.status,r=>{l?.(r)});const y=async r=>{m({type:"INIT_START"});try{const o=s.reference||d.generateReference(),c=d.detectCountryFromCurrency(s.currency),E=r||s.paymentMethods?.[0]||"card",{data:f,error:O}=await b.createPaymentIntent({...s,reference:o},E,c);if(O){m({type:"INIT_ERROR",payload:O}),i?.(O);return}if(!f){const $={code:"INIT_FAILED",message:"No data received from API",recoverable:!0};m({type:"INIT_ERROR",payload:$}),i?.($);return}const W=Z(f,{...s,reference:o});m({type:"INIT_SUCCESS",payload:W})}catch(o){const c={code:"INIT_FAILED",message:o instanceof Error?o.message:"Failed to initialize checkout",recoverable:!0,originalError:o};m({type:"INIT_ERROR",payload:c}),i?.(c)}},h=r=>{m({type:"SELECT_METHOD",payload:r})},k=async r=>{if(!(!a.value.paymentIntent||!a.value.selectedMethod)){m({type:"PROCESS_START"});try{let o;if(a.value.paymentIntent.clientSecret){const{data:E,error:f}=await b.confirmPaymentIntent(a.value.paymentIntent.id,a.value.paymentIntent.clientSecret);if(f){m({type:"PROCESS_ERROR",payload:f}),i?.(f);return}o=E}else{const{data:E,error:f}=await b.confirmPayment(a.value.paymentIntent.id);if(f){m({type:"PROCESS_ERROR",payload:f}),i?.(f);return}o=E}const c={paymentId:a.value.paymentIntent.id,reference:r.reference||a.value.paymentIntent.reference||a.value.paymentIntent.metadata?.reference||"",amount:a.value.paymentIntent.amount,currency:a.value.paymentIntent.currency,paymentMethod:a.value.selectedMethod,psp:a.value.paymentIntent.recommendedPsp,pspReference:r.pspReference||o?.provider_ref_id||"",status:"success",metadata:r};m({type:"PROCESS_SUCCESS",payload:c}),n?.(c)}catch(o){const c={code:"PAYMENT_FAILED",message:o instanceof Error?o.message:"Payment failed",recoverable:!0,originalError:o};m({type:"PROCESS_ERROR",payload:c}),i?.(c)}}},S=async r=>{await k(r)},V=r=>{m({type:"PROCESS_ERROR",payload:r}),i?.(r)},P=()=>{m({type:"RESET"})},M=async()=>{if(a.value.paymentIntent&&a.value.status!=="success")try{await b.cancelPaymentIntent(a.value.paymentIntent.id)}catch{}m({type:"CLOSE"}),p?.()},w=e.computed(()=>a.value.status),B=e.computed(()=>a.value.paymentIntent),C=e.computed(()=>a.value.selectedMethod),g=e.computed(()=>a.value.error),v=e.computed(()=>a.value.result),R=e.computed(()=>a.value.status==="loading"||a.value.status==="processing"),_=e.computed(()=>a.value.status==="ready"||a.value.status==="method_selected"||a.value.status==="processing"),N=e.computed(()=>a.value.status==="success"),T=e.computed(()=>a.value.error?.recoverable??!1);return{status:e.readonly(w),paymentIntent:e.readonly(B),selectedMethod:e.readonly(C),error:e.readonly(g),result:e.readonly(v),initialize:y,selectMethod:h,processPayment:k,handlePspSuccess:S,handlePspError:V,reset:P,close:M,isLoading:e.readonly(R),isReady:e.readonly(_),isComplete:e.readonly(N),canRetry:e.readonly(T)}}const ee={class:"reevit-method-selector"},te={class:"reevit-amount-display"},ne={class:"reevit-methods-grid"},oe=["onClick"],ae={class:"reevit-method-icon"},re={class:"reevit-method-info"},se={class:"reevit-method-name"},le={class:"reevit-method-description"},ce={class:"reevit-method-radio"},ie={key:0,class:"reevit-radio-inner"},K=e.defineComponent({__name:"PaymentMethodSelector",props:{methods:{},selected:{},amount:{},currency:{}},emits:["select"],setup(t,{emit:s}){const n=t,i=s,p=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(l=>n.methods.includes(l.id)));return(l,u)=>(e.openBlock(),e.createElementBlock("div",ee,[u[0]||(u[0]=e.createElementVNode("h3",{class:"reevit-section-title"},"Select Payment Method",-1)),e.createElementVNode("p",te," Pay "+e.toDisplayString(e.unref(d.formatAmount)(t.amount,t.currency)),1),e.createElementVNode("div",ne,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,a=>(e.openBlock(),e.createElementBlock("button",{key:a.id,type:"button",class:e.normalizeClass(e.unref(d.cn)("reevit-method-card",t.selected===a.id&&"reevit-method-card--selected")),onClick:b=>i("select",a.id)},[e.createElementVNode("span",ae,e.toDisplayString(a.icon),1),e.createElementVNode("div",re,[e.createElementVNode("span",se,e.toDisplayString(a.name),1),e.createElementVNode("span",le,e.toDisplayString(a.description),1)]),e.createElementVNode("div",ce,[t.selected===a.id?(e.openBlock(),e.createElementBlock("div",ie)):e.createCommentVNode("",!0)])],10,oe))),128))])]))}}),ue={class:"reevit-form-group"},de=["disabled"],me={class:"reevit-network-selector"},pe={class:"reevit-networks-grid"},ye=["onClick","disabled"],ve={key:0,class:"reevit-error-message"},he=["disabled"],fe={key:0,class:"reevit-spinner"},be={key:1},j=e.defineComponent({__name:"MobileMoneyForm",props:{initialPhone:{},loading:{type:Boolean}},emits:["submit"],setup(t,{emit:s}){const n=t,i=s,p=e.ref(n.initialPhone||""),l=e.ref(null),u=e.ref(null);e.watch(p,m=>{const y=d.detectNetwork(m);y&&(l.value=y),u.value&&(u.value=null)});const a=()=>{if(!d.validatePhone(p.value)){u.value="Please enter a valid phone number";return}if(!l.value){u.value="Please select your mobile network";return}i("submit",{phone:p.value,network:l.value})},b=[{id:"mtn",name:"MTN",color:"#FFCC00"},{id:"vodafone",name:"Vodafone",color:"#E60000"},{id:"airteltigo",name:"AirtelTigo",color:"#005596"}];return(m,y)=>(e.openBlock(),e.createElementBlock("form",{class:"reevit-momo-form",onSubmit:e.withModifiers(a,["prevent"])},[e.createElementVNode("div",ue,[y[1]||(y[1]=e.createElementVNode("label",{class:"reevit-label",for:"reevit-phone"},"Phone Number",-1)),e.withDirectives(e.createElementVNode("input",{id:"reevit-phone","onUpdate:modelValue":y[0]||(y[0]=h=>p.value=h),type:"tel",class:e.normalizeClass(["reevit-input",{"reevit-input--error":u.value&&!e.unref(d.validatePhone)(p.value)}]),placeholder:"e.g. 024 123 4567",disabled:t.loading,autocomplete:"tel"},null,10,de),[[e.vModelText,p.value]])]),e.createElementVNode("div",me,[y[2]||(y[2]=e.createElementVNode("label",{class:"reevit-label"},"Select Network",-1)),e.createElementVNode("div",pe,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(b,h=>e.createElementVNode("button",{key:h.id,type:"button",class:e.normalizeClass(e.unref(d.cn)("reevit-network-btn",l.value===h.id&&"reevit-network-btn--selected")),onClick:k=>l.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,ye)),64))])]),u.value?(e.openBlock(),e.createElementBlock("p",ve,e.toDisplayString(u.value),1)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"submit",class:"reevit-submit-btn",disabled:t.loading||!p.value},[t.loading?(e.openBlock(),e.createElementBlock("span",fe)):(e.openBlock(),e.createElementBlock("span",be,"Continue"))],8,he),y[3]||(y[3]=e.createElementVNode("p",{class:"reevit-secure-text"}," 🔒 Secure mobile money payment via Reevit ",-1))],32))}}),D=new Map;function I(t,s){const n=D.get(s);if(n)return n;const i=new Promise((p,l)=>{if(document.getElementById(s)){p();return}const u=document.createElement("script");u.id=s,u.src=t,u.async=!0,u.onload=()=>p(),u.onerror=()=>l(new Error(`Failed to load ${s} script`)),document.head.appendChild(u)});return D.set(s,i),i}function A(){return I("https://js.paystack.co/v1/inline.js","paystack-script")}function L(){return I("https://checkout-v3.hubtel.com/js/checkout.js","hubtel-script")}function U(){return I("https://checkout.flutterwave.com/v3.js","flutterwave-script")}function z(){return I("https://js.stripe.com/v3/","stripe-script")}function x(){return I("https://sdk.monnify.com/plugin/monnify.js","monnify-script")}async function H(t){if(await A(),!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 q(t){if(await L(),!window.HubtelCheckout)throw new Error("Hubtel script not loaded");window.HubtelCheckout.initPay({clientId:t.clientId,purchaseDescription:t.purchaseDescription,amount:t.amount,callbackUrl:t.callbackUrl,customerPhone:t.customerPhone,customerEmail:t.customerEmail,onSuccess:t.onSuccess,onClose:t.onClose})}async function Y(t){if(await U(),!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 G(t){if(await z(),!window.Stripe)throw new Error("Stripe.js not loaded");return window.Stripe(t)}async function ke(t){const n=await(await G(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 J(t){if(await x(),!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:s=>{s.status==="SUCCESS"?t.onSuccess({transactionReference:s.transactionReference,paymentReference:s.paymentReference,...s}):t.onError?.({message:s.message||"Payment failed"})},onClose:t.onClose})}async function Q(t,s){t.onInitiated();try{const n=await fetch(s,{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 l=(await n.json().catch(()=>({}))).message||"Failed to initiate M-Pesa payment";return t.onError({message:l}),{status:"failed",message:l}}const i=await n.json();return{status:"initiated",message:"Please check your phone and enter your M-Pesa PIN to complete the payment.",transactionId:i.checkout_request_id||i.transaction_id}}catch(n){const i=n instanceof Error?n.message:"Network error";return t.onError({message:i}),{status:"failed",message:i}}}const Ee=["disabled"],Pe={key:0,class:"reevit-spinner"},Se={class:"reevit-modal-body"},we={key:0,class:"reevit-loading-state"},Ce={key:1,class:"reevit-error-state"},_e={key:2,class:"reevit-success-state"},Ne={key:1,class:"reevit-method-form-container"},Ie={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:s}){const n=t,i=s,{status:p,paymentIntent:l,selectedMethod:u,error:a,isLoading:b,isReady:m,initialize:y,selectMethod:h,handlePspSuccess:k,handlePspError:S,close:V}=F({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:r=>i("success",r),onError:r=>i("error",r),onClose:()=>i("close")}),P=e.ref(n.isOpen??!1);e.watch(()=>n.isOpen,r=>{r!==void 0&&(P.value=r)});const M=()=>{P.value=!0,!l.value&&p.value==="idle"&&y()};e.watch([P,l,u],([r,o,c])=>{r&&o&&c&&c==="card"&&C(null)});const w=()=>{P.value=!1,V()},B=r=>{h(r)},C=async r=>{if(!l.value)return;const o=l.value.recommendedPsp;try{if(o==="paystack")await H({key:n.publicKey,email:n.email||"",amount:n.amount,currency:n.currency,ref:l.value.id,onSuccess:c=>k(c),onClose:()=>{}});else if(o==="hubtel")await q({clientId:n.publicKey,purchaseDescription:`Payment for ${n.amount} ${n.currency}`,amount:n.amount,customerPhone:r?.phone||n.phone,customerEmail:n.email,onSuccess:c=>k(c),onClose:()=>{}});else if(o==="flutterwave")await Y({public_key:n.publicKey,tx_ref:l.value.id,amount:n.amount,currency:n.currency,customer:{email:n.email||"",phone_number:r?.phone||n.phone},callback:c=>k(c),onclose:()=>{}});else if(o==="monnify")await J({apiKey:l.value.pspPublicKey||n.publicKey,contractCode:n.metadata?.contract_code||n.publicKey,amount:n.amount,currency:n.currency,reference:l.value.reference||l.value.id,customerName:n.metadata?.customer_name||n.email||"",customerEmail:n.email||"",customerPhone:r?.phone||n.phone,metadata:n.metadata,onSuccess:c=>k(c),onClose:()=>{}});else if(o==="mpesa"){const c=`${n.apiBaseUrl||"https://api.reevit.io"}/v1/payments/${l.value.id}/mpesa`;await Q({phoneNumber:r?.phone||n.phone||"",amount:n.amount,reference:l.value.reference||l.value.id,description:`Payment ${l.value.reference||""}`,onInitiated:()=>{},onSuccess:E=>k(E),onError:E=>S({code:"MPESA_ERROR",message:E.message})},c)}else S(o==="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 "${o}" is not supported in this checkout.`})}catch(c){S({code:"BRIDGE_ERROR",message:c instanceof Error?c.message:"Failed to open payment gateway"})}},g=e.computed(()=>d.createThemeVariables(n.theme||{}));e.watch(P,r=>{r?document.body.style.overflow="hidden":document.body.style.overflow=""}),e.onUnmounted(()=>{document.body.style.overflow=""});const v=e.computed(()=>p.value),R=e.computed(()=>a.value),_=e.computed(()=>u.value),N=e.computed(()=>b.value),T=e.computed(()=>m.value);return(r,o)=>(e.openBlock(),e.createElementBlock("div",{class:"reevit-sdk-container",style:e.normalizeStyle(g.value)},[e.renderSlot(r.$slots,"default",{open:M,isLoading:N.value},()=>[e.createElementVNode("button",{type:"button",class:"reevit-pay-button",onClick:M,disabled:N.value},[N.value?(e.openBlock(),e.createElementBlock("span",Pe)):e.renderSlot(r.$slots,"button-text",{key:1},()=>[o[1]||(o[1]=e.createTextVNode("Pay Now",-1))])],8,Ee)]),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[P.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"reevit-modal-overlay",onClick:e.withModifiers(w,["self"])},[e.createElementVNode("div",{class:e.normalizeClass(["reevit-modal-content",{"reevit-modal--dark":n.theme?.darkMode}])},[e.createElementVNode("button",{class:"reevit-modal-close",onClick:w,"aria-label":"Close"}," × "),o[9]||(o[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",Se,[v.value==="loading"?(e.openBlock(),e.createElementBlock("div",we,[...o[2]||(o[2]=[e.createElementVNode("div",{class:"reevit-spinner reevit-spinner--large"},null,-1),e.createElementVNode("p",null,"Initializing payment...",-1)])])):v.value==="failed"&&R.value?(e.openBlock(),e.createElementBlock("div",Ce,[o[3]||(o[3]=e.createElementVNode("div",{class:"reevit-error-icon"},"⚠️",-1)),o[4]||(o[4]=e.createElementVNode("h3",null,"Payment Failed",-1)),e.createElementVNode("p",null,e.toDisplayString(R.value.message),1),e.createElementVNode("button",{class:"reevit-retry-btn",onClick:o[0]||(o[0]=c=>e.unref(y)())},"Retry")])):v.value==="success"?(e.openBlock(),e.createElementBlock("div",_e,[o[5]||(o[5]=e.createElementVNode("div",{class:"reevit-success-icon"},"✅",-1)),o[6]||(o[6]=e.createElementVNode("h3",null,"Payment Successful",-1)),o[7]||(o[7]=e.createElementVNode("p",null,"Thank you for your payment.",-1)),e.createElementVNode("button",{class:"reevit-done-btn",onClick:w},"Done")])):T.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[v.value==="ready"||v.value==="method_selected"||v.value==="processing"?(e.openBlock(),e.createBlock(K,{key:0,methods:n.paymentMethods||["card","mobile_money"],selected:_.value,amount:n.amount,currency:n.currency,onSelect:B},null,8,["methods","selected","amount","currency"])):e.createCommentVNode("",!0),(v.value==="method_selected"||v.value==="processing")&&_.value==="mobile_money"?(e.openBlock(),e.createElementBlock("div",Ne,[e.createVNode(j,{"initial-phone":n.phone,loading:v.value==="processing",onSubmit:C},null,8,["initial-phone","loading"])])):e.createCommentVNode("",!0),(v.value==="method_selected"||v.value==="processing")&&_.value==="card"?(e.openBlock(),e.createElementBlock("div",Ie,[o[8]||(o[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:C,disabled:v.value==="processing"},[v.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)]),o[10]||(o[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:()=>d.ReevitAPIClient});Object.defineProperty(exports,"cn",{enumerable:!0,get:()=>d.cn});Object.defineProperty(exports,"createReevitClient",{enumerable:!0,get:()=>d.createReevitClient});Object.defineProperty(exports,"detectCountryFromCurrency",{enumerable:!0,get:()=>d.detectCountryFromCurrency});Object.defineProperty(exports,"detectNetwork",{enumerable:!0,get:()=>d.detectNetwork});Object.defineProperty(exports,"formatAmount",{enumerable:!0,get:()=>d.formatAmount});Object.defineProperty(exports,"formatPhone",{enumerable:!0,get:()=>d.formatPhone});Object.defineProperty(exports,"validatePhone",{enumerable:!0,get:()=>d.validatePhone});exports.MobileMoneyForm=j;exports.PaymentMethodSelector=K;exports.ReevitCheckout=Be;exports.confirmStripePayment=ke;exports.createStripeInstance=G;exports.initiateMPesaSTKPush=Q;exports.loadFlutterwaveScript=U;exports.loadHubtelScript=L;exports.loadMonnifyScript=x;exports.loadPaystackScript=A;exports.loadStripeScript=z;exports.openFlutterwaveModal=Y;exports.openHubtelPopup=q;exports.openMonnifyModal=J;exports.openPaystackPopup=H;exports.useReevit=F;
|
|
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,pspCredentials:t.psp_credentials,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:l,onClose:a,onStateChange:u,apiBaseUrl:d}=t,r=e.ref(v.createInitialState());if(o.initialPaymentIntent){const c=o.initialPaymentIntent;r.value={...r.value,status:"ready",paymentIntent:c,selectedMethod:c.availableMethods?.length===1?c.availableMethods[0]:null}}const y=new v.ReevitAPIClient({publicKey:o.publicKey,baseUrl:d}),m=c=>{r.value=v.reevitReducer(r.value,c)};e.watch(()=>r.value.status,c=>{u?.(c)});const i=async c=>{m({type:"INIT_START"});try{const s=o.reference||v.generateReference(),p=v.detectCountryFromCurrency(o.currency),f=c||o.paymentMethods?.[0]||"card",{data:E,error:T}=await y.createPaymentIntent({...o,reference:s},f,p);if(T){m({type:"INIT_ERROR",payload:T}),l?.(T);return}if(!E){const O={code:"INIT_FAILED",message:"No data received from API",recoverable:!0};m({type:"INIT_ERROR",payload:O}),l?.(O);return}const J=X(E,{...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}),l?.(p)}},h=c=>{m({type:"SELECT_METHOD",payload:c})},k=async c=>{if(!(!r.value.paymentIntent||!r.value.selectedMethod)){m({type:"PROCESS_START"});try{let s;if(r.value.paymentIntent.clientSecret){const{data:f,error:E}=await y.confirmPaymentIntent(r.value.paymentIntent.id,r.value.paymentIntent.clientSecret);if(E){m({type:"PROCESS_ERROR",payload:E}),l?.(E);return}s=f}else{const{data:f,error:E}=await y.confirmPayment(r.value.paymentIntent.id);if(E){m({type:"PROCESS_ERROR",payload:E}),l?.(E);return}s=f}const p={paymentId:r.value.paymentIntent.id,reference:c.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:c.pspReference||s?.provider_ref_id||"",status:"success",metadata:c};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}),l?.(p)}}},w=async c=>{await k(c)},R=c=>{m({type:"PROCESS_ERROR",payload:c}),l?.(c)},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),b=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(b),initialize:i,selectMethod:h,processPayment:k,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,l=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(u=>n.methods.includes(u.id)));return(u,d)=>(e.openBlock(),e.createElementBlock("div",Z,[d[0]||(d[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=>l("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,l=o,a=e.ref(n.initialPhone||""),u=e.ref(null),d=e.ref(null);e.watch(a,m=>{const i=v.detectNetwork(m);i&&(u.value=i),d.value&&(d.value=null)});const r=()=>{if(!v.validatePhone(a.value)){d.value="Please enter a valid phone number";return}if(!u.value){d.value="Please select your mobile network";return}l("submit",{phone:a.value,network:u.value})},y=[{id:"mtn",name:"MTN",color:"#FFCC00"},{id:"vodafone",name:"Vodafone",color:"#E60000"},{id:"airteltigo",name:"AirtelTigo",color:"#005596"}];return(m,i)=>(e.openBlock(),e.createElementBlock("form",{class:"reevit-momo-form",onSubmit:e.withModifiers(r,["prevent"])},[e.createElementVNode("div",ce,[i[1]||(i[1]=e.createElementVNode("label",{class:"reevit-label",for:"reevit-phone"},"Phone Number",-1)),e.withDirectives(e.createElementVNode("input",{id:"reevit-phone","onUpdate:modelValue":i[0]||(i[0]=h=>a.value=h),type:"tel",class:e.normalizeClass(["reevit-input",{"reevit-input--error":d.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,[i[2]||(i[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",u.value===h.id&&"reevit-network-btn--selected")),onClick:k=>u.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))])]),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:t.loading||!a.value},[t.loading?(e.openBlock(),e.createElementBlock("span",he)):(e.openBlock(),e.createElementBlock("span",fe,"Continue"))],8,ve),i[3]||(i[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 l=this.createCheckoutUrl(o,n),a=window.open(l);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:l,iframeStyle:a}){var u,d,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 i=document.createElement("iframe");i.setAttribute("id","hubtel-iframe-element"),i.src=this.createCheckoutUrl(o,l),i.style.display="none",i.style.width=(u=a?.width)!==null&&u!==void 0?u:"100%",i.style.height=(d=a?.height)!==null&&d!==void 0?d:"100%",i.style.minHeight=a?.minHeight||"400px",i.style.border=(r=a?.border)!==null&&r!==void 0?r:"none",i.onload=()=>{var h;y.removeChild(m),i.style.display="block",(h=n.onLoad)===null||h===void 0||h.call(n)},y.appendChild(i)}openModal({purchaseInfo:o,callBacks:n,config:l}){this.injectStyles(),this.createIframe(),this.handleBackButton(),this.registerEvents(n),this.renderWebpageInPopup(this.createCheckoutUrl(o,l),n.onClose,n.onLoad)}createCheckoutUrl(o,n){const l=Object.assign(Object.assign({},o),n),a=Object.keys(l).reduce((m,i)=>(l[i]!==null&&l[i]!==void 0&&(m[i]=l[i]),m),{}),u=Object.keys(a).map(m=>`${m}=${encodeURIComponent(a[m])}`).join("&"),d=this.encodeBase64(u),r=encodeURIComponent(d);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=l=>{var a,u,d,r,y,m;if(l.origin!==this.baseUrl)return;const{data:i}=l;if(i.success===!0)(a=o.onPaymentSuccess)===null||a===void 0||a.call(o,i);else if(i.success===!1)(u=o.onPaymentFailure)===null||u===void 0||u.call(o,i);else if(i.initialized)(d=o.init)===null||d===void 0||d.call(o,i),(r=o.onInit)===null||r===void 0||r.call(o,i);else if(i.feesChanged)(y=o.onFeesChanged)===null||y===void 0||y.call(o,i.fees);else if(i.resize){const h=document.getElementById("hubtel-iframe-element");h&&(h.style.height=i.height+"px"),(m=o?.onResize)===null||m===void 0||m.call(o,i)}};this.messageHandler=n,window.addEventListener("message",n,!1)}destroy(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler,!1),this.messageHandler=null)}renderWebpageInPopup(o,n,l){const a=document.createElement("div");a.classList.add("checkout-modal");const u=document.createElement("div");u.setAttribute("id","checkout-close-icon"),u.innerHTML="×",u.classList.add("close-icon"),u.addEventListener("click",()=>{this.closePopUp(),n?.()}),a.appendChild(u);const d=document.createElement("iframe");d.src=o,history.pushState({modalOpen:!0},""),d.classList.add("iframe"),a.appendChild(d),document.body.appendChild(a),a.style.opacity="0",d.addEventListener("load",()=>{a.style.opacity="1",l?.()})}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=`
|
|
2
|
+
.backdrop {
|
|
3
|
+
position: fixed;
|
|
4
|
+
left: 0;
|
|
5
|
+
top: 0;
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 100%;
|
|
8
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
9
|
+
z-index: 999998;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.loader {
|
|
13
|
+
position: fixed;
|
|
14
|
+
top: 50%;
|
|
15
|
+
left: 50%;
|
|
16
|
+
transform: translate(-50%, -50%);
|
|
17
|
+
z-index: 999999;
|
|
18
|
+
/* Your loader styles */
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.checkout-modal {
|
|
22
|
+
position: fixed;
|
|
23
|
+
top: 50%;
|
|
24
|
+
left: 50%;
|
|
25
|
+
transform: translate(-50%, -50%);
|
|
26
|
+
width: 90%;
|
|
27
|
+
height: 90%;
|
|
28
|
+
padding-top: 20px;
|
|
29
|
+
max-width: 480px;
|
|
30
|
+
background-color: #fff;
|
|
31
|
+
border-radius: 10px;
|
|
32
|
+
z-index: 1000000;
|
|
33
|
+
transition: opacity 0.5s ease, transform 0.5s ease;
|
|
34
|
+
opacity: 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.close-icon {
|
|
38
|
+
position: absolute;
|
|
39
|
+
top: 10px;
|
|
40
|
+
width: 25px;
|
|
41
|
+
height: 25px;
|
|
42
|
+
font-size: 20px;
|
|
43
|
+
right: 10px;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
color: #fff;
|
|
46
|
+
background-color: #000;
|
|
47
|
+
text-align: center;
|
|
48
|
+
border-radius: 50%;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.iframe {
|
|
52
|
+
width: 100%;
|
|
53
|
+
height: calc(100% - 20px);
|
|
54
|
+
border: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.checkout-loader {
|
|
58
|
+
width: 30px;
|
|
59
|
+
height: 30px;
|
|
60
|
+
border: 3px solid #FFF;
|
|
61
|
+
border-bottom-color: #42b883;
|
|
62
|
+
border-radius: 50%;
|
|
63
|
+
display: inline-block;
|
|
64
|
+
box-sizing: border-box;
|
|
65
|
+
position : fixed;
|
|
66
|
+
top : 50%;
|
|
67
|
+
left : 50%;
|
|
68
|
+
transform : translate(-50%, -50%);
|
|
69
|
+
z-index : 999999;
|
|
70
|
+
animation: rotation 1s linear infinite;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@keyframes rotation {
|
|
74
|
+
0% {
|
|
75
|
+
transform: rotate(0deg);
|
|
76
|
+
}
|
|
77
|
+
100% {
|
|
78
|
+
transform: rotate(360deg);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@media screen and (max-width: 600px) {
|
|
83
|
+
.checkout-modal {
|
|
84
|
+
width: 100%;
|
|
85
|
+
height: 100%;
|
|
86
|
+
border-radius: 0;
|
|
87
|
+
padding-bottom: 0px;
|
|
88
|
+
padding-top: 0px;
|
|
89
|
+
}
|
|
90
|
+
.close-icon{
|
|
91
|
+
top: 10px;
|
|
92
|
+
right: 15px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.iframe {
|
|
96
|
+
|
|
97
|
+
height: 100%;
|
|
98
|
+
|
|
99
|
+
}
|
|
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 l=new Promise((a,u)=>{if(document.getElementById(o)){a();return}const d=document.createElement("script");d.id=o,d.src=t,d.async=!0,d.onload=()=>a(),d.onerror=()=>u(new Error(`Failed to load ${o} script`)),document.head.appendChild(d)});return $.set(o,l),l}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()}`},l={branding:"enabled",callbackUrl:t.callbackUrl||(typeof window<"u"?window.location.href:""),merchantAccount:typeof t.clientId=="string"?parseInt(t.clientId,10):t.clientId,basicAuth:t.basicAuth||""};o.openModal({purchaseInfo:n,config:l,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 u=(await n.json().catch(()=>({}))).message||"Failed to initiate M-Pesa payment";return t.onError({message:u}),{status:"failed",message:u}}const l=await n.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(n){const l=n instanceof Error?n.message:"Network error";return t.onError({message:l}),{status:"failed",message:l}}}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,l=o,{status:a,paymentIntent:u,selectedMethod:d,error:r,isLoading:y,isReady:m,initialize:i,selectMethod:h,handlePspSuccess:k,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:c=>l("success",c),onError:c=>l("error",c),onClose:()=>l("close")}),P=e.ref(n.isOpen??!1);e.watch(()=>n.isOpen,c=>{c!==void 0&&(P.value=c)});const I=()=>{P.value=!0,!u.value&&a.value==="idle"&&i()};e.watch([P,u,d],([c,s,p])=>{c&&s&&p&&p==="card"&&S(null)});const C=()=>{P.value=!1,R()},V=c=>{h(c)},S=async c=>{const s=u.value;if(!s)return;const p=s.recommendedPsp;try{if(p==="paystack")await K({key:n.publicKey,email:n.email||"",amount:n.amount,currency:n.currency,ref:s.id,onSuccess:f=>k(f),onClose:()=>{}});else if(p==="hubtel")await H({clientId:s.pspCredentials?.merchantAccount||n.publicKey,purchaseDescription:`Payment for ${n.amount} ${n.currency}`,amount:n.amount,customerPhone:c?.phone||n.phone,customerEmail:n.email,basicAuth:s.pspCredentials?.basicAuth,onSuccess:f=>k(f),onClose:()=>{}});else if(p==="flutterwave")await q({public_key:n.publicKey,tx_ref:s.id,amount:n.amount,currency:n.currency,customer:{email:n.email||"",phone_number:c?.phone||n.phone},callback:f=>k(f),onclose:()=>{}});else if(p==="monnify")await W({apiKey:s.pspPublicKey||n.publicKey,contractCode:n.metadata?.contract_code||n.publicKey,amount:n.amount,currency:n.currency,reference:s.reference||s.id,customerName:n.metadata?.customer_name||n.email||"",customerEmail:n.email||"",customerPhone:c?.phone||n.phone,metadata:n.metadata,onSuccess:f=>k(f),onClose:()=>{}});else if(p==="mpesa"){const f=`${n.apiBaseUrl||"https://api.reevit.io"}/v1/payments/${s.id}/mpesa`;await G({phoneNumber:c?.phone||n.phone||"",amount:n.amount,reference:s.reference||s.id,description:`Payment ${s.reference||""}`,onInitiated:()=>{},onSuccess:E=>k(E),onError:E=>w({code:"MPESA_ERROR",message:E.message})},f)}else w(p==="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 "${p}" is not supported in this checkout.`})}catch(f){w({code:"BRIDGE_ERROR",message:f instanceof Error?f.message:"Failed to open payment gateway"})}},B=e.computed(()=>v.createThemeVariables(n.theme||{}));e.watch(P,c=>{c?document.body.style.overflow="hidden":document.body.style.overflow=""}),e.onUnmounted(()=>{document.body.style.overflow=""});const b=e.computed(()=>a.value),N=e.computed(()=>r.value),g=e.computed(()=>d.value),_=e.computed(()=>y.value),x=e.computed(()=>m.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:_.value},()=>[e.createElementVNode("button",{type:"button",class:"reevit-pay-button",onClick:I,disabled:_.value},[_.value?(e.openBlock(),e.createElementBlock("span",we)):e.renderSlot(c.$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,[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",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(i)())},"Retry")])):b.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},[b.value==="ready"||b.value==="method_selected"||b.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),(b.value==="method_selected"||b.value==="processing")&&g.value==="mobile_money"?(e.openBlock(),e.createElementBlock("div",Ie,[e.createVNode(L,{"initial-phone":n.phone,loading:b.value==="processing",onSubmit:S},null,8,["initial-phone","loading"])])):e.createCommentVNode("",!0),(b.value==="method_selected"||b.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: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=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;
|