@reevit/react 0.5.3 → 0.5.5

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.mjs CHANGED
@@ -332,7 +332,7 @@ function reevitReducer(state, action) {
332
332
  case "INIT_ERROR":
333
333
  return { ...state, status: "failed", error: action.payload };
334
334
  case "SELECT_METHOD":
335
- return { ...state, status: "method_selected", selectedMethod: action.payload, error: null };
335
+ return { ...state, status: "method_selected", selectedMethod: action.payload };
336
336
  case "PROCESS_START":
337
337
  return { ...state, status: "processing", error: null };
338
338
  case "PROCESS_SUCCESS":
@@ -423,6 +423,7 @@ function mapToPaymentIntent(response, config) {
423
423
  availableMethods: config.paymentMethods || ["card", "mobile_money"],
424
424
  reference: response.reference || response.id,
425
425
  // Use backend reference or fallback to ID
426
+ orgId: response.org_id,
426
427
  connectionId: response.connection_id,
427
428
  provider: response.provider,
428
429
  feeAmount: response.fee_amount,
@@ -624,11 +625,20 @@ function useReevit(options) {
624
625
  },
625
626
  [onError]
626
627
  );
627
- const reset = useCallback(() => {
628
+ const reset = useCallback(async () => {
629
+ if (state.paymentIntent && state.status !== "success") {
630
+ try {
631
+ const apiClient = apiClientRef.current;
632
+ if (apiClient) {
633
+ await apiClient.cancelPaymentIntent(state.paymentIntent.id);
634
+ }
635
+ } catch {
636
+ }
637
+ }
628
638
  initializingRef.current = false;
629
639
  initRequestIdRef.current += 1;
630
640
  dispatch({ type: "RESET" });
631
- }, []);
641
+ }, [state.paymentIntent, state.status]);
632
642
  const close = useCallback(async () => {
633
643
  if (state.paymentIntent && state.status !== "success") {
634
644
  try {
@@ -1128,7 +1138,6 @@ function PaystackBridge({
1128
1138
  if (!window.PaystackPop) {
1129
1139
  throw new Error("Paystack script loaded but PaystackPop not available");
1130
1140
  }
1131
- const safeMetadata = accessCode ? void 0 : metadata;
1132
1141
  const setupConfig = {
1133
1142
  key: publicKey,
1134
1143
  email,
@@ -1137,7 +1146,7 @@ function PaystackBridge({
1137
1146
  currency,
1138
1147
  ref: reference,
1139
1148
  access_code: accessCode,
1140
- metadata: safeMetadata,
1149
+ metadata,
1141
1150
  channels,
1142
1151
  callback: (response) => {
1143
1152
  console.log("[PaystackBridge] Callback received", response);
@@ -2252,10 +2261,10 @@ function ReevitCheckout({
2252
2261
  [selectMethod]
2253
2262
  );
2254
2263
  const handleProviderSelect = useCallback(
2255
- (provider) => {
2264
+ async (provider) => {
2256
2265
  if (provider === selectedProvider) {
2257
2266
  setSelectedProvider(null);
2258
- reset();
2267
+ await reset();
2259
2268
  setShowPSPBridge(false);
2260
2269
  setMomoData(null);
2261
2270
  return;
@@ -2263,7 +2272,7 @@ function ReevitCheckout({
2263
2272
  const providerMethods = providerOptions.find((option) => option.provider === provider)?.methods || paymentMethods;
2264
2273
  const methodForInit = selectedMethod && providerMethods.includes(selectedMethod) ? selectedMethod : providerMethods[0] || paymentMethods[0];
2265
2274
  setSelectedProvider(provider);
2266
- reset();
2275
+ await reset();
2267
2276
  setShowPSPBridge(false);
2268
2277
  setMomoData(null);
2269
2278
  initialize(methodForInit, { preferredProvider: provider, allowedProviders: [provider] });
@@ -2305,8 +2314,8 @@ function ReevitCheckout({
2305
2314
  const handlePSPClose = useCallback(() => {
2306
2315
  setShowPSPBridge(false);
2307
2316
  }, []);
2308
- const handleBack = useCallback(() => {
2309
- reset();
2317
+ const handleBack = useCallback(async () => {
2318
+ await reset();
2310
2319
  setMomoData(null);
2311
2320
  setShowPSPBridge(false);
2312
2321
  }, [reset]);
@@ -2395,6 +2404,7 @@ function ReevitCheckout({
2395
2404
  const pspKey = paymentIntent?.pspPublicKey || publicKey || "";
2396
2405
  const bridgeMetadata = {
2397
2406
  ...metadata,
2407
+ org_id: paymentIntent?.orgId ?? metadata?.org_id,
2398
2408
  payment_id: paymentIntent?.id,
2399
2409
  connection_id: paymentIntent?.connectionId ?? metadata?.connection_id,
2400
2410
  customer_phone: momoData?.phone || phone