fix(medusa-payment-stripe): Prevent Stripe events from retrying (#3160)
This commit is contained in:
committed by
GitHub
parent
28697e1bd0
commit
71fdd28198
5
.changeset/wild-ravens-press.md
Normal file
5
.changeset/wild-ravens-press.md
Normal 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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user