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

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

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"medusa-payment-stripe": patch
---
fix(medusa-payment-stripe): Prevent Stripe events from retrying
@@ -27,12 +27,20 @@ export default async (req, res) => {
// handle payment intent events // handle payment intent events
switch (event.type) { switch (event.type) {
case "payment_intent.succeeded": case "payment_intent.succeeded":
if (order && order.payment_status !== "captured") { if (order) {
await manager.transaction(async (manager) => { // If order is created but not captured, we attempt to do so
await orderService.withTransaction(manager).capturePayment(order.id) 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 { } 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) return res.sendStatus(404)
} }
break break