@reevit/react 0.3.5 → 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/index.d.mts CHANGED
@@ -115,6 +115,15 @@ interface PaymentIntent {
115
115
  clientSecret: string;
116
116
  /** PSP's public key for client-side SDK initialization */
117
117
  pspPublicKey?: string;
118
+ /** PSP-specific credentials for client-side checkout (e.g., Hubtel's merchantAccount, basicAuth) */
119
+ pspCredentials?: {
120
+ /** Hubtel merchant account number */
121
+ merchantAccount?: string | number;
122
+ /** Hubtel basic auth header value */
123
+ basicAuth?: string;
124
+ /** Any other PSP-specific credential fields */
125
+ [key: string]: unknown;
126
+ };
118
127
  /** Amount in smallest currency unit */
119
128
  amount: number;
120
129
  /** Currency code */
@@ -247,49 +256,38 @@ interface PaystackBridgeProps {
247
256
  declare function loadPaystackScript(): Promise<void>;
248
257
  declare function PaystackBridge({ publicKey, email, phone, amount, currency, reference, accessCode, metadata, channels, onSuccess, onError, onClose, autoStart, }: PaystackBridgeProps): react_jsx_runtime.JSX.Element;
249
258
 
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
259
  interface HubtelBridgeProps {
279
- merchantAccount: string;
260
+ merchantAccount: string | number;
280
261
  amount: number;
281
262
  currency?: string;
282
263
  reference?: string;
283
264
  email?: string;
284
265
  phone?: string;
285
266
  description?: string;
267
+ callbackUrl?: string;
268
+ basicAuth?: string;
286
269
  onSuccess: (result: PaymentResult) => void;
287
270
  onError: (error: PaymentError) => void;
288
271
  onClose: () => void;
289
272
  autoStart?: boolean;
290
273
  }
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;
274
+ declare function HubtelBridge({ merchantAccount, amount, reference, phone, description, callbackUrl, basicAuth, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
275
+ /**
276
+ * Opens Hubtel checkout modal directly
277
+ * Uses the @hubteljs/checkout npm package
278
+ */
279
+ declare function openHubtelPopup(config: {
280
+ merchantAccount: string | number;
281
+ description: string;
282
+ amount: number;
283
+ clientReference?: string;
284
+ callbackUrl?: string;
285
+ customerPhoneNumber?: string;
286
+ basicAuth?: string;
287
+ onSuccess?: (data: Record<string, unknown>) => void;
288
+ onError?: (data: Record<string, unknown>) => void;
289
+ onClose?: () => void;
290
+ }): void;
293
291
 
294
292
  declare global {
295
293
  interface Window {
@@ -663,4 +661,4 @@ declare function formatPhone(phone: string): string;
663
661
  */
664
662
  declare function detectNetwork(phone: string): string | null;
665
663
 
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 };
664
+ 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
@@ -115,6 +115,15 @@ interface PaymentIntent {
115
115
  clientSecret: string;
116
116
  /** PSP's public key for client-side SDK initialization */
117
117
  pspPublicKey?: string;
118
+ /** PSP-specific credentials for client-side checkout (e.g., Hubtel's merchantAccount, basicAuth) */
119
+ pspCredentials?: {
120
+ /** Hubtel merchant account number */
121
+ merchantAccount?: string | number;
122
+ /** Hubtel basic auth header value */
123
+ basicAuth?: string;
124
+ /** Any other PSP-specific credential fields */
125
+ [key: string]: unknown;
126
+ };
118
127
  /** Amount in smallest currency unit */
119
128
  amount: number;
120
129
  /** Currency code */
@@ -247,49 +256,38 @@ interface PaystackBridgeProps {
247
256
  declare function loadPaystackScript(): Promise<void>;
248
257
  declare function PaystackBridge({ publicKey, email, phone, amount, currency, reference, accessCode, metadata, channels, onSuccess, onError, onClose, autoStart, }: PaystackBridgeProps): react_jsx_runtime.JSX.Element;
249
258
 
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
259
  interface HubtelBridgeProps {
279
- merchantAccount: string;
260
+ merchantAccount: string | number;
280
261
  amount: number;
281
262
  currency?: string;
282
263
  reference?: string;
283
264
  email?: string;
284
265
  phone?: string;
285
266
  description?: string;
267
+ callbackUrl?: string;
268
+ basicAuth?: string;
286
269
  onSuccess: (result: PaymentResult) => void;
287
270
  onError: (error: PaymentError) => void;
288
271
  onClose: () => void;
289
272
  autoStart?: boolean;
290
273
  }
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;
274
+ declare function HubtelBridge({ merchantAccount, amount, reference, phone, description, callbackUrl, basicAuth, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
275
+ /**
276
+ * Opens Hubtel checkout modal directly
277
+ * Uses the @hubteljs/checkout npm package
278
+ */
279
+ declare function openHubtelPopup(config: {
280
+ merchantAccount: string | number;
281
+ description: string;
282
+ amount: number;
283
+ clientReference?: string;
284
+ callbackUrl?: string;
285
+ customerPhoneNumber?: string;
286
+ basicAuth?: string;
287
+ onSuccess?: (data: Record<string, unknown>) => void;
288
+ onError?: (data: Record<string, unknown>) => void;
289
+ onClose?: () => void;
290
+ }): void;
293
291
 
294
292
  declare global {
295
293
  interface Window {
@@ -663,4 +661,4 @@ declare function formatPhone(phone: string): string;
663
661
  */
664
662
  declare function detectNetwork(phone: string): string | null;
665
663
 
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 };
664
+ 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) {
@@ -1690,13 +1721,14 @@ function ReevitCheckout({
1690
1721
  return /* @__PURE__ */ jsxRuntime.jsx(
1691
1722
  HubtelBridge,
1692
1723
  {
1693
- merchantAccount: pspKey,
1724
+ merchantAccount: paymentIntent?.pspCredentials?.merchantAccount || pspKey,
1694
1725
  amount: paymentIntent?.amount ?? amount,
1695
1726
  currency: paymentIntent?.currency ?? currency,
1696
1727
  reference: paymentIntent?.reference || reference,
1697
1728
  email,
1698
1729
  phone: momoData?.phone || phone,
1699
1730
  description: `Payment ${paymentIntent?.reference || reference || ""}`,
1731
+ basicAuth: paymentIntent?.pspCredentials?.basicAuth,
1700
1732
  onSuccess: handlePSPSuccess,
1701
1733
  onError: (err) => handlePSPError(err),
1702
1734
  onClose: handlePSPClose
@@ -1905,10 +1937,10 @@ exports.detectNetwork = detectNetwork;
1905
1937
  exports.formatAmount = formatAmount;
1906
1938
  exports.formatPhone = formatPhone;
1907
1939
  exports.loadFlutterwaveScript = loadFlutterwaveScript;
1908
- exports.loadHubtelScript = loadHubtelScript;
1909
1940
  exports.loadMonnifyScript = loadMonnifyScript;
1910
1941
  exports.loadPaystackScript = loadPaystackScript;
1911
1942
  exports.loadStripeScript = loadStripeScript;
1943
+ exports.openHubtelPopup = openHubtelPopup;
1912
1944
  exports.useMPesaStatusPolling = useMPesaStatusPolling;
1913
1945
  exports.useReevit = useReevit;
1914
1946
  exports.useReevitContext = useReevitContext;