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