@reevit/react 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -247,49 +247,38 @@ interface PaystackBridgeProps {
247
247
  declare function loadPaystackScript(): Promise<void>;
248
248
  declare function PaystackBridge({ publicKey, email, phone, amount, currency, reference, accessCode, metadata, channels, onSuccess, onError, onClose, autoStart, }: PaystackBridgeProps): react_jsx_runtime.JSX.Element;
249
249
 
250
- declare global {
251
- interface Window {
252
- HubtelCheckout?: HubtelCheckoutInterface;
253
- }
254
- }
255
- interface HubtelCheckoutInterface {
256
- initPayment: (config: HubtelConfig) => void;
257
- }
258
- interface HubtelConfig {
259
- merchantAccount: string;
260
- basicDescription: string;
261
- totalAmount: number;
262
- currency: string;
263
- clientReference: string;
264
- customerEmail?: string;
265
- customerMsisdn?: string;
266
- callbackUrl?: string;
267
- onComplete?: (response: HubtelResponse) => void;
268
- onCancel?: () => void;
269
- }
270
- interface HubtelResponse {
271
- status: 'Success' | 'Failed' | 'Cancelled';
272
- transactionId: string;
273
- clientReference: string;
274
- amount: number;
275
- currency: string;
276
- message?: string;
277
- }
278
250
  interface HubtelBridgeProps {
279
- merchantAccount: string;
251
+ merchantAccount: string | number;
280
252
  amount: number;
281
253
  currency?: string;
282
254
  reference?: string;
283
255
  email?: string;
284
256
  phone?: string;
285
257
  description?: string;
258
+ callbackUrl?: string;
259
+ basicAuth?: string;
286
260
  onSuccess: (result: PaymentResult) => void;
287
261
  onError: (error: PaymentError) => void;
288
262
  onClose: () => void;
289
263
  autoStart?: boolean;
290
264
  }
291
- declare function loadHubtelScript(): Promise<void>;
292
- declare function HubtelBridge({ merchantAccount, amount, currency, reference, email, phone, description, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
265
+ declare function HubtelBridge({ merchantAccount, amount, reference, phone, description, callbackUrl, basicAuth, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
266
+ /**
267
+ * Opens Hubtel checkout modal directly
268
+ * Uses the @hubteljs/checkout npm package
269
+ */
270
+ declare function openHubtelPopup(config: {
271
+ merchantAccount: string | number;
272
+ description: string;
273
+ amount: number;
274
+ clientReference?: string;
275
+ callbackUrl?: string;
276
+ customerPhoneNumber?: string;
277
+ basicAuth?: string;
278
+ onSuccess?: (data: Record<string, unknown>) => void;
279
+ onError?: (data: Record<string, unknown>) => void;
280
+ onClose?: () => void;
281
+ }): void;
293
282
 
294
283
  declare global {
295
284
  interface Window {
@@ -663,4 +652,4 @@ declare function formatPhone(phone: string): string;
663
652
  */
664
653
  declare function detectNetwork(phone: string): string | null;
665
654
 
666
- export { type CheckoutState, FlutterwaveBridge, HubtelBridge, MPesaBridge, type MPesaBridgeProps, MobileMoneyForm, type MobileMoneyFormData, type MobileMoneyNetwork, MonnifyBridge, type MonnifyBridgeProps, type PaymentDetailResponse, type PaymentError, type PaymentIntent, type PaymentIntentResponse, type PaymentMethod, PaymentMethodSelector, type PaymentResult, type PaymentSource, PaystackBridge, ReevitAPIClient, type ReevitAPIClientConfig, ReevitCheckout, type ReevitCheckoutCallbacks, type ReevitCheckoutConfig, type ReevitCheckoutProps, type ReevitTheme, StripeBridge, type StripeBridgeProps, createReevitClient, detectNetwork, formatAmount, formatPhone, loadFlutterwaveScript, loadHubtelScript, loadMonnifyScript, loadPaystackScript, loadStripeScript, useMPesaStatusPolling, useReevit, useReevitContext, validatePhone };
655
+ export { type CheckoutState, FlutterwaveBridge, HubtelBridge, MPesaBridge, type MPesaBridgeProps, MobileMoneyForm, type MobileMoneyFormData, type MobileMoneyNetwork, MonnifyBridge, type MonnifyBridgeProps, type PaymentDetailResponse, type PaymentError, type PaymentIntent, type PaymentIntentResponse, type PaymentMethod, PaymentMethodSelector, type PaymentResult, type PaymentSource, PaystackBridge, ReevitAPIClient, type ReevitAPIClientConfig, ReevitCheckout, type ReevitCheckoutCallbacks, type ReevitCheckoutConfig, type ReevitCheckoutProps, type ReevitTheme, StripeBridge, type StripeBridgeProps, createReevitClient, detectNetwork, formatAmount, formatPhone, loadFlutterwaveScript, loadMonnifyScript, loadPaystackScript, loadStripeScript, openHubtelPopup, useMPesaStatusPolling, useReevit, useReevitContext, validatePhone };
package/dist/index.d.ts CHANGED
@@ -247,49 +247,38 @@ interface PaystackBridgeProps {
247
247
  declare function loadPaystackScript(): Promise<void>;
248
248
  declare function PaystackBridge({ publicKey, email, phone, amount, currency, reference, accessCode, metadata, channels, onSuccess, onError, onClose, autoStart, }: PaystackBridgeProps): react_jsx_runtime.JSX.Element;
249
249
 
250
- declare global {
251
- interface Window {
252
- HubtelCheckout?: HubtelCheckoutInterface;
253
- }
254
- }
255
- interface HubtelCheckoutInterface {
256
- initPayment: (config: HubtelConfig) => void;
257
- }
258
- interface HubtelConfig {
259
- merchantAccount: string;
260
- basicDescription: string;
261
- totalAmount: number;
262
- currency: string;
263
- clientReference: string;
264
- customerEmail?: string;
265
- customerMsisdn?: string;
266
- callbackUrl?: string;
267
- onComplete?: (response: HubtelResponse) => void;
268
- onCancel?: () => void;
269
- }
270
- interface HubtelResponse {
271
- status: 'Success' | 'Failed' | 'Cancelled';
272
- transactionId: string;
273
- clientReference: string;
274
- amount: number;
275
- currency: string;
276
- message?: string;
277
- }
278
250
  interface HubtelBridgeProps {
279
- merchantAccount: string;
251
+ merchantAccount: string | number;
280
252
  amount: number;
281
253
  currency?: string;
282
254
  reference?: string;
283
255
  email?: string;
284
256
  phone?: string;
285
257
  description?: string;
258
+ callbackUrl?: string;
259
+ basicAuth?: string;
286
260
  onSuccess: (result: PaymentResult) => void;
287
261
  onError: (error: PaymentError) => void;
288
262
  onClose: () => void;
289
263
  autoStart?: boolean;
290
264
  }
291
- declare function loadHubtelScript(): Promise<void>;
292
- declare function HubtelBridge({ merchantAccount, amount, currency, reference, email, phone, description, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
265
+ declare function HubtelBridge({ merchantAccount, amount, reference, phone, description, callbackUrl, basicAuth, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
266
+ /**
267
+ * Opens Hubtel checkout modal directly
268
+ * Uses the @hubteljs/checkout npm package
269
+ */
270
+ declare function openHubtelPopup(config: {
271
+ merchantAccount: string | number;
272
+ description: string;
273
+ amount: number;
274
+ clientReference?: string;
275
+ callbackUrl?: string;
276
+ customerPhoneNumber?: string;
277
+ basicAuth?: string;
278
+ onSuccess?: (data: Record<string, unknown>) => void;
279
+ onError?: (data: Record<string, unknown>) => void;
280
+ onClose?: () => void;
281
+ }): void;
293
282
 
294
283
  declare global {
295
284
  interface Window {
@@ -663,4 +652,4 @@ declare function formatPhone(phone: string): string;
663
652
  */
664
653
  declare function detectNetwork(phone: string): string | null;
665
654
 
666
- export { type CheckoutState, FlutterwaveBridge, HubtelBridge, MPesaBridge, type MPesaBridgeProps, MobileMoneyForm, type MobileMoneyFormData, type MobileMoneyNetwork, MonnifyBridge, type MonnifyBridgeProps, type PaymentDetailResponse, type PaymentError, type PaymentIntent, type PaymentIntentResponse, type PaymentMethod, PaymentMethodSelector, type PaymentResult, type PaymentSource, PaystackBridge, ReevitAPIClient, type ReevitAPIClientConfig, ReevitCheckout, type ReevitCheckoutCallbacks, type ReevitCheckoutConfig, type ReevitCheckoutProps, type ReevitTheme, StripeBridge, type StripeBridgeProps, createReevitClient, detectNetwork, formatAmount, formatPhone, loadFlutterwaveScript, loadHubtelScript, loadMonnifyScript, loadPaystackScript, loadStripeScript, useMPesaStatusPolling, useReevit, useReevitContext, validatePhone };
655
+ export { type CheckoutState, FlutterwaveBridge, HubtelBridge, MPesaBridge, type MPesaBridgeProps, MobileMoneyForm, type MobileMoneyFormData, type MobileMoneyNetwork, MonnifyBridge, type MonnifyBridgeProps, type PaymentDetailResponse, type PaymentError, type PaymentIntent, type PaymentIntentResponse, type PaymentMethod, PaymentMethodSelector, type PaymentResult, type PaymentSource, PaystackBridge, ReevitAPIClient, type ReevitAPIClientConfig, ReevitCheckout, type ReevitCheckoutCallbacks, type ReevitCheckoutConfig, type ReevitCheckoutProps, type ReevitTheme, StripeBridge, type StripeBridgeProps, createReevitClient, detectNetwork, formatAmount, formatPhone, loadFlutterwaveScript, loadMonnifyScript, loadPaystackScript, loadStripeScript, openHubtelPopup, useMPesaStatusPolling, useReevit, useReevitContext, validatePhone };
package/dist/index.js CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  var react = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
+ var CheckoutSdk = require('@hubteljs/checkout');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var CheckoutSdk__default = /*#__PURE__*/_interopDefault(CheckoutSdk);
5
10
 
6
11
  // src/components/ReevitCheckout.tsx
7
12
 
@@ -806,74 +811,69 @@ function PaystackBridge({
806
811
  /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Connecting to Paystack..." })
807
812
  ] }) });
808
813
  }
809
- function loadHubtelScript() {
810
- return new Promise((resolve, reject) => {
811
- if (window.HubtelCheckout) {
812
- resolve();
813
- return;
814
- }
815
- const script = document.createElement("script");
816
- script.src = "https://checkout-v3.hubtel.com/js/checkout.js";
817
- script.async = true;
818
- script.onload = () => resolve();
819
- script.onerror = () => reject(new Error("Failed to load Hubtel script"));
820
- document.head.appendChild(script);
821
- });
822
- }
823
814
  function HubtelBridge({
824
815
  merchantAccount,
825
816
  amount,
826
- currency = "GHS",
827
817
  reference,
828
- email,
829
818
  phone,
830
819
  description = "Payment",
820
+ callbackUrl,
821
+ basicAuth,
831
822
  onSuccess,
832
823
  onError,
833
824
  onClose,
834
825
  autoStart = true
835
826
  }) {
836
827
  const initialized = react.useRef(false);
828
+ const checkoutRef = react.useRef(null);
837
829
  const startPayment = react.useCallback(async () => {
838
830
  try {
839
- await loadHubtelScript();
840
- if (!window.HubtelCheckout) {
841
- throw new Error("Hubtel checkout not available");
842
- }
843
- window.HubtelCheckout.initPayment({
844
- merchantAccount,
845
- basicDescription: description,
846
- totalAmount: amount / 100,
847
- // Hubtel expects amount in major units (GHS, not pesewas)
848
- currency,
849
- clientReference: reference || `hubtel_${Date.now()}`,
850
- customerEmail: email,
851
- customerMsisdn: phone,
852
- onComplete: (response) => {
853
- if (response.status === "Success") {
831
+ const checkout = new CheckoutSdk__default.default();
832
+ checkoutRef.current = checkout;
833
+ const purchaseInfo = {
834
+ amount: amount / 100,
835
+ // Convert from minor to major units
836
+ purchaseDescription: description,
837
+ customerPhoneNumber: phone || "",
838
+ clientReference: reference || `hubtel_${Date.now()}`
839
+ };
840
+ const config = {
841
+ branding: "enabled",
842
+ callbackUrl: callbackUrl || window.location.href,
843
+ merchantAccount: typeof merchantAccount === "string" ? parseInt(merchantAccount, 10) : merchantAccount,
844
+ basicAuth: basicAuth || ""
845
+ };
846
+ checkout.openModal({
847
+ purchaseInfo,
848
+ config,
849
+ callBacks: {
850
+ onInit: () => console.log("Hubtel checkout initialized"),
851
+ onPaymentSuccess: (data) => {
854
852
  const result = {
855
- paymentId: response.transactionId,
856
- reference: response.clientReference,
857
- amount: Math.round(response.amount * 100),
858
- // Convert back to pesewas
859
- currency: response.currency,
853
+ paymentId: data.transactionId || reference || "",
854
+ reference: data.clientReference || reference || "",
855
+ amount,
856
+ currency: "GHS",
860
857
  paymentMethod: "mobile_money",
861
858
  psp: "hubtel",
862
- pspReference: response.transactionId,
859
+ pspReference: data.transactionId || "",
863
860
  status: "success"
864
861
  };
865
862
  onSuccess(result);
866
- } else {
863
+ checkout.closePopUp();
864
+ },
865
+ onPaymentFailure: (data) => {
867
866
  const error = {
868
867
  code: "PAYMENT_FAILED",
869
- message: response.message || "Payment failed",
868
+ message: data.message || "Payment failed",
870
869
  recoverable: true
871
870
  };
872
871
  onError(error);
872
+ },
873
+ onLoad: () => console.log("Hubtel checkout loaded"),
874
+ onClose: () => {
875
+ onClose();
873
876
  }
874
- },
875
- onCancel: () => {
876
- onClose();
877
877
  }
878
878
  });
879
879
  } catch (err) {
@@ -885,7 +885,7 @@ function HubtelBridge({
885
885
  };
886
886
  onError(error);
887
887
  }
888
- }, [merchantAccount, amount, currency, reference, email, phone, description, onSuccess, onError, onClose]);
888
+ }, [merchantAccount, amount, reference, phone, description, callbackUrl, basicAuth, onSuccess, onError, onClose]);
889
889
  react.useEffect(() => {
890
890
  if (autoStart && !initialized.current) {
891
891
  initialized.current = true;
@@ -897,6 +897,37 @@ function HubtelBridge({
897
897
  /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Connecting to Hubtel..." })
898
898
  ] }) });
899
899
  }
900
+ function openHubtelPopup(config) {
901
+ const checkout = new CheckoutSdk__default.default();
902
+ const purchaseInfo = {
903
+ amount: config.amount,
904
+ purchaseDescription: config.description,
905
+ customerPhoneNumber: config.customerPhoneNumber || "",
906
+ clientReference: config.clientReference || `hubtel_${Date.now()}`
907
+ };
908
+ const checkoutConfig = {
909
+ branding: "enabled",
910
+ callbackUrl: config.callbackUrl || window.location.href,
911
+ merchantAccount: typeof config.merchantAccount === "string" ? parseInt(config.merchantAccount, 10) : config.merchantAccount,
912
+ basicAuth: config.basicAuth || ""
913
+ };
914
+ checkout.openModal({
915
+ purchaseInfo,
916
+ config: checkoutConfig,
917
+ callBacks: {
918
+ onPaymentSuccess: (data) => {
919
+ config.onSuccess?.(data);
920
+ checkout.closePopUp();
921
+ },
922
+ onPaymentFailure: (data) => {
923
+ config.onError?.(data);
924
+ },
925
+ onClose: () => {
926
+ config.onClose?.();
927
+ }
928
+ }
929
+ });
930
+ }
900
931
  function loadFlutterwaveScript() {
901
932
  return new Promise((resolve, reject) => {
902
933
  if (window.FlutterwaveCheckout) {
@@ -1905,10 +1936,10 @@ exports.detectNetwork = detectNetwork;
1905
1936
  exports.formatAmount = formatAmount;
1906
1937
  exports.formatPhone = formatPhone;
1907
1938
  exports.loadFlutterwaveScript = loadFlutterwaveScript;
1908
- exports.loadHubtelScript = loadHubtelScript;
1909
1939
  exports.loadMonnifyScript = loadMonnifyScript;
1910
1940
  exports.loadPaystackScript = loadPaystackScript;
1911
1941
  exports.loadStripeScript = loadStripeScript;
1942
+ exports.openHubtelPopup = openHubtelPopup;
1912
1943
  exports.useMPesaStatusPolling = useMPesaStatusPolling;
1913
1944
  exports.useReevit = useReevit;
1914
1945
  exports.useReevitContext = useReevitContext;