Repository: freeCodeCamp/freeCodeCamp
File: client/src/components/Donation/wallets-button.tsx (TypeScript)

Code before:
      } else if (clientSecret) {
        // confirm payment intent
        const { paymentIntent, error: confirmError } =
          await stripe.confirmCardPayment(
            clientSecret,
            { payment_method: event.paymentMethod.id },
            { handleActions: false }
          );

        if (confirmError) {
          event.complete('fail');
          displayError(t('donate.try-another-method'));
        } else {
          event.complete('success');
          if (paymentIntent.status === 'requires_action') {
            const { error } = await stripe.confirmCardPayment(clientSecret);
            if (error) {
              displayError(t('donate.try-another-method'));
            } else {
              postPayment({
                paymentProvider: PaymentProvider.Stripe,
                paymentMethodId,
                payerEmail,
                payerName,
                subscriptionId
              });
            }
          } else {
            postPayment({
              paymentProvider: PaymentProvider.Stripe,
              paymentMethodId,
              payerEmail,
              subscriptionId
            });
          }
        }
      }
    });

    void pr.canMakePayment().then(result => {
      if (result) setPaymentRequest(pr);
    });

    return () => {
      setPaymentRequest(null);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [label, amount, stripe, postPayment, handlePaymentButtonLoad]);

  const displayError = (errorMessage: string): void => {
    onDonationStateChange({

Review comment (suggestion):
```suggestion
              return displayError(t('donate.try-another-method'));
            }
```
Handle success below

Code after:
      const {
        data: { clientSecret, subscriptionId, error }
      } = await createStripePaymentIntent({
        email: payerEmail,
        name: payerName,
        amount,
        duration
      });

      if (error) {
        event.complete('fail');
        displayError(t('donate.try-another-method'));
      } else if (clientSecret) {
        // confirm payment intent
        const { paymentIntent, error: confirmError } =
          await stripe.confirmCardPayment(
            clientSecret,
            { payment_method: event.paymentMethod.id },
            { handleActions: false }
          );

        if (confirmError) {
          event.complete('fail');
          displayError(t('donate.try-another-method'));
        } else {
          event.complete('success');
          if (paymentIntent.status === 'requires_action') {
            const { error } = await stripe.confirmCardPayment(clientSecret);
            if (error) {
              return displayError(t('donate.try-another-method'));
            }
          }
          postPayment({
            paymentProvider: PaymentProvider.Stripe,
            paymentMethodId,
            payerEmail,
            payerName,
            subscriptionId
          });
        }
      }
    });

    void pr.canMakePayment().then(result => {
      if (result) setPaymentRequest(pr);
    });

    return () => {
      setPaymentRequest(null);
    };
  }, [