@reevit/react 0.5.4 → 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
@@ -264,7 +264,7 @@ declare function useReevit(options: UseReevitOptions): {
264
264
  processPayment: (paymentData: Record<string, unknown>) => Promise<void>;
265
265
  handlePspSuccess: (pspData: Record<string, unknown>) => Promise<void>;
266
266
  handlePspError: (error: PaymentError) => void;
267
- reset: () => void;
267
+ reset: () => Promise<void>;
268
268
  close: () => Promise<void>;
269
269
  isLoading: boolean;
270
270
  isReady: boolean;
package/dist/index.d.ts CHANGED
@@ -264,7 +264,7 @@ declare function useReevit(options: UseReevitOptions): {
264
264
  processPayment: (paymentData: Record<string, unknown>) => Promise<void>;
265
265
  handlePspSuccess: (pspData: Record<string, unknown>) => Promise<void>;
266
266
  handlePspError: (error: PaymentError) => void;
267
- reset: () => void;
267
+ reset: () => Promise<void>;
268
268
  close: () => Promise<void>;
269
269
  isLoading: boolean;
270
270
  isReady: boolean;
package/dist/index.js CHANGED
@@ -631,11 +631,20 @@ function useReevit(options) {
631
631
  },
632
632
  [onError]
633
633
  );
634
- 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
+ }
635
644
  initializingRef.current = false;
636
645
  initRequestIdRef.current += 1;
637
646
  dispatch({ type: "RESET" });
638
- }, []);
647
+ }, [state.paymentIntent, state.status]);
639
648
  const close = react.useCallback(async () => {
640
649
  if (state.paymentIntent && state.status !== "success") {
641
650
  try {
@@ -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]);