@reevit/react 0.2.6 → 0.2.8
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.js +18 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -279,6 +279,7 @@ function useReevit(options) {
|
|
|
279
279
|
const { config, onSuccess, onError, onClose, onStateChange, apiBaseUrl } = options;
|
|
280
280
|
const [state, dispatch] = useReducer(reevitReducer, initialState);
|
|
281
281
|
const apiClientRef = useRef(null);
|
|
282
|
+
const initializingRef = useRef(false);
|
|
282
283
|
if (!apiClientRef.current) {
|
|
283
284
|
apiClientRef.current = new ReevitAPIClient({
|
|
284
285
|
publicKey: config.publicKey,
|
|
@@ -290,10 +291,15 @@ function useReevit(options) {
|
|
|
290
291
|
}, [state.status, onStateChange]);
|
|
291
292
|
const initialize = useCallback(
|
|
292
293
|
async (method) => {
|
|
294
|
+
if (initializingRef.current) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
initializingRef.current = true;
|
|
293
298
|
dispatch({ type: "INIT_START" });
|
|
294
299
|
try {
|
|
295
300
|
const apiClient = apiClientRef.current;
|
|
296
301
|
if (!apiClient) {
|
|
302
|
+
initializingRef.current = false;
|
|
297
303
|
throw new Error("API client not initialized");
|
|
298
304
|
}
|
|
299
305
|
const reference = config.reference || generateReference();
|
|
@@ -317,6 +323,7 @@ function useReevit(options) {
|
|
|
317
323
|
};
|
|
318
324
|
dispatch({ type: "INIT_ERROR", payload: noDataError });
|
|
319
325
|
onError?.(noDataError);
|
|
326
|
+
initializingRef.current = false;
|
|
320
327
|
return;
|
|
321
328
|
}
|
|
322
329
|
const paymentIntent = mapToPaymentIntent(data, { ...config, reference });
|
|
@@ -330,6 +337,7 @@ function useReevit(options) {
|
|
|
330
337
|
};
|
|
331
338
|
dispatch({ type: "INIT_ERROR", payload: error });
|
|
332
339
|
onError?.(error);
|
|
340
|
+
initializingRef.current = false;
|
|
333
341
|
}
|
|
334
342
|
},
|
|
335
343
|
[config, onError, apiBaseUrl]
|
|
@@ -394,6 +402,7 @@ function useReevit(options) {
|
|
|
394
402
|
[onError]
|
|
395
403
|
);
|
|
396
404
|
const reset = useCallback(() => {
|
|
405
|
+
initializingRef.current = false;
|
|
397
406
|
dispatch({ type: "RESET" });
|
|
398
407
|
}, []);
|
|
399
408
|
const close = useCallback(async () => {
|
|
@@ -886,10 +895,16 @@ function ReevitCheckout({
|
|
|
886
895
|
{
|
|
887
896
|
publicKey: pspKey,
|
|
888
897
|
email,
|
|
889
|
-
amount,
|
|
890
|
-
currency,
|
|
898
|
+
amount: paymentIntent?.amount ?? amount,
|
|
899
|
+
currency: paymentIntent?.currency ?? currency,
|
|
891
900
|
reference,
|
|
892
|
-
metadata
|
|
901
|
+
metadata: {
|
|
902
|
+
...metadata,
|
|
903
|
+
// Override with correct payment intent ID for webhook routing
|
|
904
|
+
// This ensures Paystack webhook includes the correct ID to find the payment
|
|
905
|
+
payment_id: paymentIntent?.id,
|
|
906
|
+
connection_id: paymentIntent?.connectionId ?? metadata?.connection_id
|
|
907
|
+
},
|
|
893
908
|
channels: selectedMethod === "mobile_money" ? ["mobile_money"] : ["card"],
|
|
894
909
|
onSuccess: handlePSPSuccess,
|
|
895
910
|
onError: handlePSPError,
|