Repository: freeCodeCamp/freeCodeCamp
File: api-server/src/server/boot/donate.js (JavaScript)

Code before:
          email,
          amount,
          duration,
          provider: 'stripe',
          subscriptionId,
          customerId: subscription.customer,
          startDate: new Date().toISOString()
        };
        await donatingUser.createDonation(donation);
        return res.status(200).send({ isDonating: true });
      } else {
        throw new Error('Donation failed due to a server error.');
      }
    } catch (err) {
      return res
        .status(500)
        .send({ error: 'Donation failed due to a server error.' });
    }
  }

  async function createStripePaymentIntent(req, res) {
    const { body } = req;
    const { amount, duration, email, name } = body;

    if (!validStripeForm(amount, duration, email)) {
      return res.status(500).send({
        error: 'The donation form had invalid values for this submission.'
      });
    }

    try {
      const stripeCustomer = await stripe.customers.create({
        email,
        name
      });

      const stripeSubscription = await stripe.subscriptions.create({
        customer: stripeCustomer.id,
        items: [
          {
            plan: `${donationSubscriptionConfig.duration[duration]}-donation-${amount}`
          }
        ],
        payment_behavior: 'default_incomplete',
        payment_settings: { save_default_payment_method: 'on_subscription' },
        expand: ['latest_invoice.payment_intent']
      });

      res.status(200).send({
        subscriptionId: stripeSubscription.id,
        clientSecret:

Review comment (suggestion):
```suggestion
      return res.status(400).send({
```
Definitely a bad request, not a server error.

Code after:
          email,
          amount,
          duration,
          provider: 'stripe',
          subscriptionId,
          customerId: subscription.customer,
          startDate: new Date().toISOString()
        };
        await donatingUser.createDonation(donation);
        return res.status(200).send({ isDonating: true });
      } else {
        throw new Error('Donation failed due to a server error.');
      }
    } catch (err) {
      return res
        .status(500)
        .send({ error: 'Donation failed due to a server error.' });
    }
  }

  async function createStripePaymentIntent(req, res) {
    const { body } = req;
    const { amount, duration, email, name } = body;

    if (!validStripeForm(amount, duration, email)) {
      return res.status(400).send({
        error: 'The donation form had invalid values for this submission.'
      });
    }

    try {
      const stripeCustomer = await stripe.customers.create({
        email,
        name
      });

      const stripeSubscription = await stripe.subscriptions.create({
        customer: stripeCustomer.id,
        items: [
          {
            plan: `${donationSubscriptionConfig.duration[duration]}-donation-${amount}`
          }
        ],
        payment_behavior: 'default_incomplete',
        payment_settings: { save_default_payment_method: 'on_subscription' },
        expand: ['latest_invoice.payment_intent']
      });

      res.status(200).send({
        subscriptionId: stripeSubscription.id,
        clientSecret: