fix(medusa-payment-stripe): Prevent Stripe events from retrying (#3160)
This commit is contained in:
1 parent
28697e1bd0
commit
71fdd28198
2 files changed
+16
-3
No files matched your search
@@ -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) {
|
||||||
|
// If order is created but not captured, we attempt to do so
|
||||||
|
if (order.payment_status !== "captured") {
|
||||||
await manager.transaction(async (manager) => {
|
await manager.transaction(async (manager) => {
|
||||||
await orderService.withTransaction(manager).capturePayment(order.id)
|
await orderService
|
||||||
|
.withTransaction(manager)
|
||||||
|
.capturePayment(order.id)
|
||||||
})
|
})
|
||||||
} 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
|
// Otherwise, respond with 200 preventing Stripe from retrying
|
||||||
|
return res.sendStatus(200)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If order is not created, we respond with 404 to trigger Stripe retry mechanism
|
||||||
return res.sendStatus(404)
|
return res.sendStatus(404)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in new issue
Block a user