@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.d.mts CHANGED
@@ -179,6 +179,8 @@ interface PaymentIntent {
179
179
  availableMethods: PaymentMethod[];
180
180
  /** Reference provided or generated */
181
181
  reference?: string;
182
+ /** Organization ID (from Reevit backend, required for webhook routing) */
183
+ orgId?: string;
182
184
  /** Connection ID (from Reevit backend) */
183
185
  connectionId?: string;
184
186
  /** Provider name (from backend) */
@@ -262,7 +264,7 @@ declare function useReevit(options: UseReevitOptions): {
262
264
  processPayment: (paymentData: Record<string, unknown>) => Promise<void>;
263
265
  handlePspSuccess: (pspData: Record<string, unknown>) => Promise<void>;
264
266
  handlePspError: (error: PaymentError) => void;
265
- reset: () => void;
267
+ reset: () => Promise<void>;
266
268
  close: () => Promise<void>;
267
269
  isLoading: boolean;
268
270
  isReady: boolean;
@@ -612,6 +614,7 @@ declare function useMPesaStatusPolling(statusEndpoint: string, checkoutRequestId
612
614
 
613
615
  interface PaymentIntentResponse {
614
616
  id: string;
617
+ org_id?: string;
615
618
  connection_id: string;
616
619
  provider: string;
617
620
  status: string;
package/dist/index.d.ts CHANGED
@@ -179,6 +179,8 @@ interface PaymentIntent {
179
179
  availableMethods: PaymentMethod[];
180
180
  /** Reference provided or generated */
181
181
  reference?: string;
182
+ /** Organization ID (from Reevit backend, required for webhook routing) */
183
+ orgId?: string;
182
184
  /** Connection ID (from Reevit backend) */
183
185
  connectionId?: string;
184
186
  /** Provider name (from backend) */
@@ -262,7 +264,7 @@ declare function useReevit(options: UseReevitOptions): {
262
264
  processPayment: (paymentData: Record<string, unknown>) => Promise<void>;
263
265
  handlePspSuccess: (pspData: Record<string, unknown>) => Promise<void>;
264
266
  handlePspError: (error: PaymentError) => void;
265
- reset: () => void;
267
+ reset: () => Promise<void>;
266
268
  close: () => Promise<void>;
267
269
  isLoading: boolean;
268
270
  isReady: boolean;
@@ -612,6 +614,7 @@ declare function useMPesaStatusPolling(statusEndpoint: string, checkoutRequestId
612
614
 
613
615
  interface PaymentIntentResponse {
614
616
  id: string;
617
+ org_id?: string;
615
618
  connection_id: string;
616
619
  provider: string;
617
620
  status: string;
package/dist/index.js CHANGED
@@ -338,7 +338,7 @@ function reevitReducer(state, action) {
338
338
  case "INIT_ERROR":
339
339
  return { ...state, status: "failed", error: action.payload };
340
340
  case "SELECT_METHOD":
341
- return { ...state, status: "method_selected", selectedMethod: action.payload, error: null };
341
+ return { ...state, status: "method_selected", selectedMethod: action.payload };
342
342
  case "PROCESS_START":
343
343
  return { ...state, status: "processing", error: null };
344
344
  case "PROCESS_SUCCESS":
@@ -429,6 +429,7 @@ function mapToPaymentIntent(response, config) {
429
429
  availableMethods: config.paymentMethods || ["card", "mobile_money"],
430
430
  reference: response.reference || response.id,
431
431
  // Use backend reference or fallback to ID
432
+ orgId: response.org_id,
432
433
  connectionId: response.connection_id,
433
434
  provider: response.provider,
434
435
  feeAmount: response.fee_amount,
@@ -630,11 +631,20 @@ function useReevit(options) {
630
631
  },
631
632
  [onError]
632
633
  );
633
- const reset = react.useCallback(() => {
634
+ const reset = react.useCallback(async () => {
635
+ if (state.paymentIntent && state.status !== "success") {
636
+ try {
637
+ const apiClient = apiClientRef.current;
638
+ if (apiClient) {
639
+ await apiClient.cancelPaymentIntent(state.paymentIntent.id);
640
+ }
641
+ } catch {
642
+ }
643
+ }
634
644
  initializingRef.current = false;
635
645
  initRequestIdRef.current += 1;
636
646
  dispatch({ type: "RESET" });
637
- }, []);
647
+ }, [state.paymentIntent, state.status]);
638
648
  const close = react.useCallback(async () => {
639
649
  if (state.paymentIntent && state.status !== "success") {
640
650
  try {
@@ -1134,7 +1144,6 @@ function PaystackBridge({
1134
1144
  if (!window.PaystackPop) {
1135
1145
  throw new Error("Paystack script loaded but PaystackPop not available");
1136
1146
  }
1137
- const safeMetadata = accessCode ? void 0 : metadata;
1138
1147
  const setupConfig = {
1139
1148
  key: publicKey,
1140
1149
  email,
@@ -1143,7 +1152,7 @@ function PaystackBridge({
1143
1152
  currency,
1144
1153
  ref: reference,
1145
1154
  access_code: accessCode,
1146
- metadata: safeMetadata,
1155
+ metadata,
1147
1156
  channels,
1148
1157
  callback: (response) => {
1149
1158
  console.log("[PaystackBridge] Callback received", response);
@@ -2258,10 +2267,10 @@ function ReevitCheckout({
2258
2267
  [selectMethod]
2259
2268
  );
2260
2269
  const handleProviderSelect = react.useCallback(
2261
- (provider) => {
2270
+ async (provider) => {
2262
2271
  if (provider === selectedProvider) {
2263
2272
  setSelectedProvider(null);
2264
- reset();
2273
+ await reset();
2265
2274
  setShowPSPBridge(false);
2266
2275
  setMomoData(null);
2267
2276
  return;
@@ -2269,7 +2278,7 @@ function ReevitCheckout({
2269
2278
  const providerMethods = providerOptions.find((option) => option.provider === provider)?.methods || paymentMethods;
2270
2279
  const methodForInit = selectedMethod && providerMethods.includes(selectedMethod) ? selectedMethod : providerMethods[0] || paymentMethods[0];
2271
2280
  setSelectedProvider(provider);
2272
- reset();
2281
+ await reset();
2273
2282
  setShowPSPBridge(false);
2274
2283
  setMomoData(null);
2275
2284
  initialize(methodForInit, { preferredProvider: provider, allowedProviders: [provider] });
@@ -2311,8 +2320,8 @@ function ReevitCheckout({
2311
2320
  const handlePSPClose = react.useCallback(() => {
2312
2321
  setShowPSPBridge(false);
2313
2322
  }, []);
2314
- const handleBack = react.useCallback(() => {
2315
- reset();
2323
+ const handleBack = react.useCallback(async () => {
2324
+ await reset();
2316
2325
  setMomoData(null);
2317
2326
  setShowPSPBridge(false);
2318
2327
  }, [reset]);
@@ -2401,6 +2410,7 @@ function ReevitCheckout({
2401
2410
  const pspKey = paymentIntent?.pspPublicKey || publicKey || "";
2402
2411
  const bridgeMetadata = {
2403
2412
  ...metadata,
2413
+ org_id: paymentIntent?.orgId ?? metadata?.org_id,
2404
2414
  payment_id: paymentIntent?.id,
2405
2415
  connection_id: paymentIntent?.connectionId ?? metadata?.connection_id,
2406
2416
  customer_phone: momoData?.phone || phone