@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 +21 -32
- package/dist/index.d.ts +21 -32
- package/dist/index.js +75 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext, useReducer, useRef, useEffect, useCallback, useState, useContext } from 'react';
|
|
2
2
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import CheckoutSdk from '@hubteljs/checkout';
|
|
3
4
|
|
|
4
5
|
// src/components/ReevitCheckout.tsx
|
|
5
6
|
|
|
@@ -804,74 +805,69 @@ function PaystackBridge({
|
|
|
804
805
|
/* @__PURE__ */ jsx("p", { children: "Connecting to Paystack..." })
|
|
805
806
|
] }) });
|
|
806
807
|
}
|
|
807
|
-
function loadHubtelScript() {
|
|
808
|
-
return new Promise((resolve, reject) => {
|
|
809
|
-
if (window.HubtelCheckout) {
|
|
810
|
-
resolve();
|
|
811
|
-
return;
|
|
812
|
-
}
|
|
813
|
-
const script = document.createElement("script");
|
|
814
|
-
script.src = "https://checkout-v3.hubtel.com/js/checkout.js";
|
|
815
|
-
script.async = true;
|
|
816
|
-
script.onload = () => resolve();
|
|
817
|
-
script.onerror = () => reject(new Error("Failed to load Hubtel script"));
|
|
818
|
-
document.head.appendChild(script);
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
808
|
function HubtelBridge({
|
|
822
809
|
merchantAccount,
|
|
823
810
|
amount,
|
|
824
|
-
currency = "GHS",
|
|
825
811
|
reference,
|
|
826
|
-
email,
|
|
827
812
|
phone,
|
|
828
813
|
description = "Payment",
|
|
814
|
+
callbackUrl,
|
|
815
|
+
basicAuth,
|
|
829
816
|
onSuccess,
|
|
830
817
|
onError,
|
|
831
818
|
onClose,
|
|
832
819
|
autoStart = true
|
|
833
820
|
}) {
|
|
834
821
|
const initialized = useRef(false);
|
|
822
|
+
const checkoutRef = useRef(null);
|
|
835
823
|
const startPayment = useCallback(async () => {
|
|
836
824
|
try {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
825
|
+
const checkout = new CheckoutSdk();
|
|
826
|
+
checkoutRef.current = checkout;
|
|
827
|
+
const purchaseInfo = {
|
|
828
|
+
amount: amount / 100,
|
|
829
|
+
// Convert from minor to major units
|
|
830
|
+
purchaseDescription: description,
|
|
831
|
+
customerPhoneNumber: phone || "",
|
|
832
|
+
clientReference: reference || `hubtel_${Date.now()}`
|
|
833
|
+
};
|
|
834
|
+
const config = {
|
|
835
|
+
branding: "enabled",
|
|
836
|
+
callbackUrl: callbackUrl || window.location.href,
|
|
837
|
+
merchantAccount: typeof merchantAccount === "string" ? parseInt(merchantAccount, 10) : merchantAccount,
|
|
838
|
+
basicAuth: basicAuth || ""
|
|
839
|
+
};
|
|
840
|
+
checkout.openModal({
|
|
841
|
+
purchaseInfo,
|
|
842
|
+
config,
|
|
843
|
+
callBacks: {
|
|
844
|
+
onInit: () => console.log("Hubtel checkout initialized"),
|
|
845
|
+
onPaymentSuccess: (data) => {
|
|
852
846
|
const result = {
|
|
853
|
-
paymentId:
|
|
854
|
-
reference:
|
|
855
|
-
amount
|
|
856
|
-
|
|
857
|
-
currency: response.currency,
|
|
847
|
+
paymentId: data.transactionId || reference || "",
|
|
848
|
+
reference: data.clientReference || reference || "",
|
|
849
|
+
amount,
|
|
850
|
+
currency: "GHS",
|
|
858
851
|
paymentMethod: "mobile_money",
|
|
859
852
|
psp: "hubtel",
|
|
860
|
-
pspReference:
|
|
853
|
+
pspReference: data.transactionId || "",
|
|
861
854
|
status: "success"
|
|
862
855
|
};
|
|
863
856
|
onSuccess(result);
|
|
864
|
-
|
|
857
|
+
checkout.closePopUp();
|
|
858
|
+
},
|
|
859
|
+
onPaymentFailure: (data) => {
|
|
865
860
|
const error = {
|
|
866
861
|
code: "PAYMENT_FAILED",
|
|
867
|
-
message:
|
|
862
|
+
message: data.message || "Payment failed",
|
|
868
863
|
recoverable: true
|
|
869
864
|
};
|
|
870
865
|
onError(error);
|
|
866
|
+
},
|
|
867
|
+
onLoad: () => console.log("Hubtel checkout loaded"),
|
|
868
|
+
onClose: () => {
|
|
869
|
+
onClose();
|
|
871
870
|
}
|
|
872
|
-
},
|
|
873
|
-
onCancel: () => {
|
|
874
|
-
onClose();
|
|
875
871
|
}
|
|
876
872
|
});
|
|
877
873
|
} catch (err) {
|
|
@@ -883,7 +879,7 @@ function HubtelBridge({
|
|
|
883
879
|
};
|
|
884
880
|
onError(error);
|
|
885
881
|
}
|
|
886
|
-
}, [merchantAccount, amount,
|
|
882
|
+
}, [merchantAccount, amount, reference, phone, description, callbackUrl, basicAuth, onSuccess, onError, onClose]);
|
|
887
883
|
useEffect(() => {
|
|
888
884
|
if (autoStart && !initialized.current) {
|
|
889
885
|
initialized.current = true;
|
|
@@ -895,6 +891,37 @@ function HubtelBridge({
|
|
|
895
891
|
/* @__PURE__ */ jsx("p", { children: "Connecting to Hubtel..." })
|
|
896
892
|
] }) });
|
|
897
893
|
}
|
|
894
|
+
function openHubtelPopup(config) {
|
|
895
|
+
const checkout = new CheckoutSdk();
|
|
896
|
+
const purchaseInfo = {
|
|
897
|
+
amount: config.amount,
|
|
898
|
+
purchaseDescription: config.description,
|
|
899
|
+
customerPhoneNumber: config.customerPhoneNumber || "",
|
|
900
|
+
clientReference: config.clientReference || `hubtel_${Date.now()}`
|
|
901
|
+
};
|
|
902
|
+
const checkoutConfig = {
|
|
903
|
+
branding: "enabled",
|
|
904
|
+
callbackUrl: config.callbackUrl || window.location.href,
|
|
905
|
+
merchantAccount: typeof config.merchantAccount === "string" ? parseInt(config.merchantAccount, 10) : config.merchantAccount,
|
|
906
|
+
basicAuth: config.basicAuth || ""
|
|
907
|
+
};
|
|
908
|
+
checkout.openModal({
|
|
909
|
+
purchaseInfo,
|
|
910
|
+
config: checkoutConfig,
|
|
911
|
+
callBacks: {
|
|
912
|
+
onPaymentSuccess: (data) => {
|
|
913
|
+
config.onSuccess?.(data);
|
|
914
|
+
checkout.closePopUp();
|
|
915
|
+
},
|
|
916
|
+
onPaymentFailure: (data) => {
|
|
917
|
+
config.onError?.(data);
|
|
918
|
+
},
|
|
919
|
+
onClose: () => {
|
|
920
|
+
config.onClose?.();
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
});
|
|
924
|
+
}
|
|
898
925
|
function loadFlutterwaveScript() {
|
|
899
926
|
return new Promise((resolve, reject) => {
|
|
900
927
|
if (window.FlutterwaveCheckout) {
|
|
@@ -1888,6 +1915,6 @@ function ReevitCheckout({
|
|
|
1888
1915
|
] });
|
|
1889
1916
|
}
|
|
1890
1917
|
|
|
1891
|
-
export { FlutterwaveBridge, HubtelBridge, MPesaBridge, MobileMoneyForm, MonnifyBridge, PaymentMethodSelector, PaystackBridge, ReevitAPIClient, ReevitCheckout, StripeBridge, createReevitClient, detectNetwork, formatAmount, formatPhone, loadFlutterwaveScript,
|
|
1918
|
+
export { FlutterwaveBridge, HubtelBridge, MPesaBridge, MobileMoneyForm, MonnifyBridge, PaymentMethodSelector, PaystackBridge, ReevitAPIClient, ReevitCheckout, StripeBridge, createReevitClient, detectNetwork, formatAmount, formatPhone, loadFlutterwaveScript, loadMonnifyScript, loadPaystackScript, loadStripeScript, openHubtelPopup, useMPesaStatusPolling, useReevit, useReevitContext, validatePhone };
|
|
1892
1919
|
//# sourceMappingURL=index.mjs.map
|
|
1893
1920
|
//# sourceMappingURL=index.mjs.map
|