@reevit/react 0.2.9 → 0.3.0
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 +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +60 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -138,7 +138,7 @@ interface ReevitContextValue {
|
|
|
138
138
|
currency: string;
|
|
139
139
|
}
|
|
140
140
|
declare function useReevitContext(): ReevitContextValue;
|
|
141
|
-
declare function ReevitCheckout({ publicKey, amount, currency, email, phone, reference, metadata, paymentMethods, onSuccess, onError, onClose, onStateChange, children, autoOpen, isOpen: controlledIsOpen, onOpenChange, theme, apiBaseUrl, }: ReevitCheckoutProps): react_jsx_runtime.JSX.Element;
|
|
141
|
+
declare function ReevitCheckout({ publicKey, amount, currency, email, phone, reference, metadata, paymentMethods, initialPaymentIntent, onSuccess, onError, onClose, onStateChange, children, autoOpen, isOpen: controlledIsOpen, onOpenChange, theme, apiBaseUrl, }: ReevitCheckoutProps): react_jsx_runtime.JSX.Element;
|
|
142
142
|
|
|
143
143
|
interface PaymentMethodSelectorProps {
|
|
144
144
|
methods: PaymentMethod[];
|
|
@@ -202,6 +202,7 @@ interface PaystackPopupInterface {
|
|
|
202
202
|
interface PaystackConfig {
|
|
203
203
|
key: string;
|
|
204
204
|
email: string;
|
|
205
|
+
phone?: string;
|
|
205
206
|
amount: number;
|
|
206
207
|
currency?: string;
|
|
207
208
|
ref?: string;
|
|
@@ -221,6 +222,7 @@ interface PaystackResponse {
|
|
|
221
222
|
interface PaystackBridgeProps {
|
|
222
223
|
publicKey: string;
|
|
223
224
|
email: string;
|
|
225
|
+
phone?: string;
|
|
224
226
|
amount: number;
|
|
225
227
|
currency?: string;
|
|
226
228
|
reference?: string;
|
|
@@ -232,7 +234,7 @@ interface PaystackBridgeProps {
|
|
|
232
234
|
autoStart?: boolean;
|
|
233
235
|
}
|
|
234
236
|
declare function loadPaystackScript(): Promise<void>;
|
|
235
|
-
declare function PaystackBridge({ publicKey, email, amount, currency, reference, metadata, channels, onSuccess, onError, onClose, autoStart, }: PaystackBridgeProps): react_jsx_runtime.JSX.Element;
|
|
237
|
+
declare function PaystackBridge({ publicKey, email, phone, amount, currency, reference, metadata, channels, onSuccess, onError, onClose, autoStart, }: PaystackBridgeProps): react_jsx_runtime.JSX.Element;
|
|
236
238
|
|
|
237
239
|
declare global {
|
|
238
240
|
interface Window {
|
package/dist/index.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ interface ReevitContextValue {
|
|
|
138
138
|
currency: string;
|
|
139
139
|
}
|
|
140
140
|
declare function useReevitContext(): ReevitContextValue;
|
|
141
|
-
declare function ReevitCheckout({ publicKey, amount, currency, email, phone, reference, metadata, paymentMethods, onSuccess, onError, onClose, onStateChange, children, autoOpen, isOpen: controlledIsOpen, onOpenChange, theme, apiBaseUrl, }: ReevitCheckoutProps): react_jsx_runtime.JSX.Element;
|
|
141
|
+
declare function ReevitCheckout({ publicKey, amount, currency, email, phone, reference, metadata, paymentMethods, initialPaymentIntent, onSuccess, onError, onClose, onStateChange, children, autoOpen, isOpen: controlledIsOpen, onOpenChange, theme, apiBaseUrl, }: ReevitCheckoutProps): react_jsx_runtime.JSX.Element;
|
|
142
142
|
|
|
143
143
|
interface PaymentMethodSelectorProps {
|
|
144
144
|
methods: PaymentMethod[];
|
|
@@ -202,6 +202,7 @@ interface PaystackPopupInterface {
|
|
|
202
202
|
interface PaystackConfig {
|
|
203
203
|
key: string;
|
|
204
204
|
email: string;
|
|
205
|
+
phone?: string;
|
|
205
206
|
amount: number;
|
|
206
207
|
currency?: string;
|
|
207
208
|
ref?: string;
|
|
@@ -221,6 +222,7 @@ interface PaystackResponse {
|
|
|
221
222
|
interface PaystackBridgeProps {
|
|
222
223
|
publicKey: string;
|
|
223
224
|
email: string;
|
|
225
|
+
phone?: string;
|
|
224
226
|
amount: number;
|
|
225
227
|
currency?: string;
|
|
226
228
|
reference?: string;
|
|
@@ -232,7 +234,7 @@ interface PaystackBridgeProps {
|
|
|
232
234
|
autoStart?: boolean;
|
|
233
235
|
}
|
|
234
236
|
declare function loadPaystackScript(): Promise<void>;
|
|
235
|
-
declare function PaystackBridge({ publicKey, email, amount, currency, reference, metadata, channels, onSuccess, onError, onClose, autoStart, }: PaystackBridgeProps): react_jsx_runtime.JSX.Element;
|
|
237
|
+
declare function PaystackBridge({ publicKey, email, phone, amount, currency, reference, metadata, channels, onSuccess, onError, onClose, autoStart, }: PaystackBridgeProps): react_jsx_runtime.JSX.Element;
|
|
236
238
|
|
|
237
239
|
declare global {
|
|
238
240
|
interface Window {
|
package/dist/index.js
CHANGED
|
@@ -178,6 +178,7 @@ var ReevitAPIClient = class {
|
|
|
178
178
|
method: this.mapPaymentMethod(method),
|
|
179
179
|
country,
|
|
180
180
|
customer_id: config.email || config.metadata?.customerId,
|
|
181
|
+
phone: config.phone,
|
|
181
182
|
metadata
|
|
182
183
|
};
|
|
183
184
|
return this.request("POST", "/v1/payments/intents", request);
|
|
@@ -233,7 +234,12 @@ function reevitReducer(state, action) {
|
|
|
233
234
|
case "INIT_START":
|
|
234
235
|
return { ...state, status: "loading", error: null };
|
|
235
236
|
case "INIT_SUCCESS":
|
|
236
|
-
return {
|
|
237
|
+
return {
|
|
238
|
+
...state,
|
|
239
|
+
status: "ready",
|
|
240
|
+
paymentIntent: action.payload,
|
|
241
|
+
selectedMethod: action.payload.availableMethods?.length === 1 ? action.payload.availableMethods[0] : state.selectedMethod
|
|
242
|
+
};
|
|
237
243
|
case "INIT_ERROR":
|
|
238
244
|
return { ...state, status: "failed", error: action.payload };
|
|
239
245
|
case "SELECT_METHOD":
|
|
@@ -282,14 +288,17 @@ function useReevit(options) {
|
|
|
282
288
|
const [state, dispatch] = react.useReducer(reevitReducer, {
|
|
283
289
|
...initialState,
|
|
284
290
|
status: config.initialPaymentIntent ? "ready" : "idle",
|
|
285
|
-
paymentIntent: config.initialPaymentIntent || null
|
|
291
|
+
paymentIntent: config.initialPaymentIntent || null,
|
|
292
|
+
selectedMethod: config.initialPaymentIntent?.availableMethods?.length === 1 ? config.initialPaymentIntent.availableMethods[0] : null
|
|
286
293
|
});
|
|
287
294
|
const apiClientRef = react.useRef(null);
|
|
288
295
|
const initializingRef = react.useRef(!!config.initialPaymentIntent);
|
|
289
296
|
react.useEffect(() => {
|
|
290
|
-
if (config.initialPaymentIntent
|
|
291
|
-
|
|
292
|
-
|
|
297
|
+
if (config.initialPaymentIntent) {
|
|
298
|
+
if (!state.paymentIntent || state.paymentIntent.id !== config.initialPaymentIntent.id) {
|
|
299
|
+
dispatch({ type: "INIT_SUCCESS", payload: config.initialPaymentIntent });
|
|
300
|
+
initializingRef.current = true;
|
|
301
|
+
}
|
|
293
302
|
}
|
|
294
303
|
}, [config.initialPaymentIntent, state.paymentIntent?.id]);
|
|
295
304
|
if (!apiClientRef.current) {
|
|
@@ -382,11 +391,16 @@ function useReevit(options) {
|
|
|
382
391
|
paymentMethod: state.selectedMethod,
|
|
383
392
|
psp: state.paymentIntent.recommendedPsp,
|
|
384
393
|
pspReference: paymentData.pspReference || data?.provider_ref_id || "",
|
|
385
|
-
status: "success",
|
|
394
|
+
status: data?.status === "succeeded" ? "success" : "pending",
|
|
386
395
|
metadata: paymentData
|
|
387
396
|
};
|
|
388
|
-
|
|
389
|
-
|
|
397
|
+
if (result.status === "success") {
|
|
398
|
+
dispatch({ type: "PROCESS_SUCCESS", payload: result });
|
|
399
|
+
onSuccess?.(result);
|
|
400
|
+
} else {
|
|
401
|
+
dispatch({ type: "PROCESS_SUCCESS", payload: result });
|
|
402
|
+
onSuccess?.(result);
|
|
403
|
+
}
|
|
390
404
|
} catch (err) {
|
|
391
405
|
const error = {
|
|
392
406
|
code: "PAYMENT_FAILED",
|
|
@@ -676,6 +690,7 @@ function loadPaystackScript() {
|
|
|
676
690
|
function PaystackBridge({
|
|
677
691
|
publicKey,
|
|
678
692
|
email,
|
|
693
|
+
phone,
|
|
679
694
|
amount,
|
|
680
695
|
currency = "GHS",
|
|
681
696
|
reference,
|
|
@@ -705,6 +720,7 @@ function PaystackBridge({
|
|
|
705
720
|
const handler = window.PaystackPop.setup({
|
|
706
721
|
key: publicKey,
|
|
707
722
|
email,
|
|
723
|
+
phone,
|
|
708
724
|
amount,
|
|
709
725
|
// Paystack expects amount in kobo/pesewas (smallest unit)
|
|
710
726
|
currency,
|
|
@@ -712,13 +728,18 @@ function PaystackBridge({
|
|
|
712
728
|
metadata,
|
|
713
729
|
channels,
|
|
714
730
|
callback: (response) => {
|
|
731
|
+
let usedMethod = "card";
|
|
732
|
+
if (channels && channels.length === 1) {
|
|
733
|
+
usedMethod = channels[0];
|
|
734
|
+
} else if (response.message?.toLowerCase().includes("mobile money")) {
|
|
735
|
+
usedMethod = "mobile_money";
|
|
736
|
+
}
|
|
715
737
|
const result = {
|
|
716
738
|
paymentId: response.transaction,
|
|
717
739
|
reference: response.reference,
|
|
718
740
|
amount,
|
|
719
741
|
currency,
|
|
720
|
-
paymentMethod:
|
|
721
|
-
// Paystack handles this internally
|
|
742
|
+
paymentMethod: usedMethod,
|
|
722
743
|
psp: "paystack",
|
|
723
744
|
pspReference: response.trans,
|
|
724
745
|
status: response.status === "success" ? "success" : "pending",
|
|
@@ -771,6 +792,7 @@ function ReevitCheckout({
|
|
|
771
792
|
reference,
|
|
772
793
|
metadata,
|
|
773
794
|
paymentMethods = ["card", "mobile_money"],
|
|
795
|
+
initialPaymentIntent,
|
|
774
796
|
// Callbacks
|
|
775
797
|
onSuccess,
|
|
776
798
|
onError,
|
|
@@ -812,7 +834,17 @@ function ReevitCheckout({
|
|
|
812
834
|
isLoading,
|
|
813
835
|
isComplete
|
|
814
836
|
} = useReevit({
|
|
815
|
-
config: {
|
|
837
|
+
config: {
|
|
838
|
+
publicKey,
|
|
839
|
+
amount,
|
|
840
|
+
currency,
|
|
841
|
+
email,
|
|
842
|
+
phone,
|
|
843
|
+
reference,
|
|
844
|
+
metadata,
|
|
845
|
+
paymentMethods,
|
|
846
|
+
initialPaymentIntent
|
|
847
|
+
},
|
|
816
848
|
apiBaseUrl,
|
|
817
849
|
onSuccess: (result2) => {
|
|
818
850
|
onSuccess?.(result2);
|
|
@@ -828,10 +860,19 @@ function ReevitCheckout({
|
|
|
828
860
|
onStateChange
|
|
829
861
|
});
|
|
830
862
|
react.useEffect(() => {
|
|
831
|
-
if (isOpen && status === "idle") {
|
|
863
|
+
if (isOpen && status === "idle" && !initialPaymentIntent) {
|
|
832
864
|
initialize();
|
|
833
865
|
}
|
|
834
|
-
}, [isOpen, status, initialize]);
|
|
866
|
+
}, [isOpen, status, initialize, initialPaymentIntent]);
|
|
867
|
+
react.useEffect(() => {
|
|
868
|
+
if (isOpen && (selectedMethod === "card" || selectedMethod === "mobile_money") && !showPSPBridge) {
|
|
869
|
+
if (selectedMethod === "card" && paymentIntent) {
|
|
870
|
+
setShowPSPBridge(true);
|
|
871
|
+
} else if (selectedMethod === "mobile_money" && paymentIntent && (momoData?.phone || phone)) {
|
|
872
|
+
setShowPSPBridge(true);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}, [isOpen, selectedMethod, showPSPBridge, paymentIntent, momoData, phone]);
|
|
835
876
|
const handleOpen = react.useCallback(() => {
|
|
836
877
|
if (controlledIsOpen !== void 0) return;
|
|
837
878
|
setIsOpen(true);
|
|
@@ -885,10 +926,11 @@ function ReevitCheckout({
|
|
|
885
926
|
setShowPSPBridge(false);
|
|
886
927
|
}, [reset]);
|
|
887
928
|
const themeStyles = theme ? createThemeVariables(theme) : {};
|
|
888
|
-
const
|
|
929
|
+
const isControlled = controlledIsOpen !== void 0;
|
|
930
|
+
const trigger = children ? /* @__PURE__ */ jsxRuntime.jsx("span", { onClick: isControlled ? void 0 : handleOpen, role: isControlled ? void 0 : "button", tabIndex: isControlled ? void 0 : 0, children }) : !isControlled ? /* @__PURE__ */ jsxRuntime.jsxs("button", { className: "reevit-trigger-btn", onClick: handleOpen, children: [
|
|
889
931
|
"Pay ",
|
|
890
932
|
formatAmount(amount, currency)
|
|
891
|
-
] });
|
|
933
|
+
] }) : null;
|
|
892
934
|
const renderContent = () => {
|
|
893
935
|
if (status === "loading") {
|
|
894
936
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "reevit-loading", children: [
|
|
@@ -921,6 +963,7 @@ function ReevitCheckout({
|
|
|
921
963
|
{
|
|
922
964
|
publicKey: pspKey,
|
|
923
965
|
email,
|
|
966
|
+
phone: momoData?.phone || phone,
|
|
924
967
|
amount: paymentIntent?.amount ?? amount,
|
|
925
968
|
currency: paymentIntent?.currency ?? currency,
|
|
926
969
|
reference,
|
|
@@ -929,7 +972,8 @@ function ReevitCheckout({
|
|
|
929
972
|
// Override with correct payment intent ID for webhook routing
|
|
930
973
|
// This ensures Paystack webhook includes the correct ID to find the payment
|
|
931
974
|
payment_id: paymentIntent?.id,
|
|
932
|
-
connection_id: paymentIntent?.connectionId ?? metadata?.connection_id
|
|
975
|
+
connection_id: paymentIntent?.connectionId ?? metadata?.connection_id,
|
|
976
|
+
customer_phone: momoData?.phone || phone
|
|
933
977
|
},
|
|
934
978
|
channels: selectedMethod === "mobile_money" ? ["mobile_money"] : ["card"],
|
|
935
979
|
onSuccess: handlePSPSuccess,
|