diff --git a/.changeset/wild-ravens-press.md b/.changeset/wild-ravens-press.md new file mode 100644 index 0000000000..d7cc7cf73d --- /dev/null +++ b/.changeset/wild-ravens-press.md @@ -0,0 +1,5 @@ +--- +"medusa-payment-stripe": patch +--- + +fix(medusa-payment-stripe): Prevent Stripe events from retrying diff --git a/packages/medusa-payment-stripe/src/api/routes/hooks/stripe.js b/packages/medusa-payment-stripe/src/api/routes/hooks/stripe.js index 5ef9a075ec..14ff981c64 100644 --- a/packages/medusa-payment-stripe/src/api/routes/hooks/stripe.js +++ b/packages/medusa-payment-stripe/src/api/routes/hooks/stripe.js @@ -27,12 +27,20 @@ export default async (req, res) => { // handle payment intent events switch (event.type) { case "payment_intent.succeeded": - if (order && order.payment_status !== "captured") { - await manager.transaction(async (manager) => { - await orderService.withTransaction(manager).capturePayment(order.id) - }) + if (order) { + // If order is created but not captured, we attempt to do so + if (order.payment_status !== "captured") { + await manager.transaction(async (manager) => { + await orderService + .withTransaction(manager) + .capturePayment(order.id) + }) + } else { + // Otherwise, respond with 200 preventing Stripe from retrying + return res.sendStatus(200) + } } else { - // If we receive the event, before the order is created, we respond with 404 as this will trigger Stripe to resend the event later + // If order is not created, we respond with 404 to trigger Stripe retry mechanism return res.sendStatus(404) } break