fix(medusa-payment-stripe): Prevent Stripe events from retrying (#3160)

This commit is contained in:
Oliver Windall Juhl
2023-02-06 11:23:39 +01:00
committed by GitHub
parent 28697e1bd0
commit 71fdd28198
2 changed files with 18 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"medusa-payment-stripe": patch
---
fix(medusa-payment-stripe): Prevent Stripe events from retrying

View File

@@ -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