fix(payment): properly delete refund (#12193)

**What**
- properly delete the refund record if refunding with the provider fails

---

CLOSES SUP-1398
This commit is contained in:
Frane Polić authored and GitHub committed 2025-04-16 07:57:39 +00:00
1 parent 01542f6973
commit 9851598dae
1 file changed
+9 -6
@@ -504,11 +504,14 @@ export default class PaymentModuleService
status !== PaymentSessionStatus.AUTHORIZED && status !== PaymentSessionStatus.AUTHORIZED &&
status !== PaymentSessionStatus.CAPTURED status !== PaymentSessionStatus.CAPTURED
) { ) {
await this.paymentSessionService_.update({ await this.paymentSessionService_.update(
id: session.id, {
status, id: session.id,
data, status,
}, sharedContext); data,
},
sharedContext
)
throw new MedusaError( throw new MedusaError(
MedusaError.Types.NOT_ALLOWED, MedusaError.Types.NOT_ALLOWED,
`Session: ${session.id} was not authorized with the provider.` `Session: ${session.id} was not authorized with the provider.`
@@ -770,7 +773,7 @@ export default class PaymentModuleService
try { try {
await this.refundPaymentFromProvider_(payment, refund, sharedContext) await this.refundPaymentFromProvider_(payment, refund, sharedContext)
} catch (error) { } catch (error) {
await super.deleteRefunds(data.payment_id, sharedContext) await super.deleteRefunds({ id: refund.id }, sharedContext)
throw error throw error
} }