expressstripe-paymentswebhooks

Best practice return status code for stripe webhook application error


In my webhook for checkout.session.completed, I do some validation for the received metadata, i.e. whether an organisation exists. If I do come across an application error, i.e. the organisationId given does not in fact exist, should I be returning a status code of 200 to indicate it has been acknowledged, or should I be returning 400 or 500 to indicate that it has failed?

if (!organisation) {
  // Return 200, 400 or 500?
  return res.status(200).send({ code: 'code', message: 'message' });
}

Solution

  • You should return a 200 to Stripe. Otherwise, Stripe will continue to retry sending the event to your endpoint.