From 9b8313b4366a3c0ab3bc2ef23db1776812788084 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Thu, 10 Jul 2025 00:26:16 +0530 Subject: [PATCH 1/2] Update charge-failed.ts --- .../web/app/(ee)/api/stripe/webhook/charge-failed.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts index dce73529fa3..2251d03de8d 100644 --- a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts +++ b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts @@ -53,6 +53,18 @@ export async function chargeFailed(event: Stripe.Event) { }, }); + // Reduce the payoutsUsage by the invoice amount since the charge failed + await prisma.project.update({ + where: { + id: invoice.workspaceId, + }, + data: { + payoutsUsage: { + decrement: invoice.amount, + }, + }, + }); + const workspace = await prisma.project.findUniqueOrThrow({ where: { id: invoice.workspaceId, From f0249b1133e8d3624533d77c935bf1b9486ec59a Mon Sep 17 00:00:00 2001 From: Steven Tey Date: Wed, 9 Jul 2025 11:58:30 -0700 Subject: [PATCH 2/2] combine into 1 call --- apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts index 2251d03de8d..56f95b67c90 100644 --- a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts +++ b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts @@ -53,22 +53,16 @@ export async function chargeFailed(event: Stripe.Event) { }, }); - // Reduce the payoutsUsage by the invoice amount since the charge failed - await prisma.project.update({ + const workspace = await prisma.project.update({ where: { id: invoice.workspaceId, }, + // Reduce the payoutsUsage by the invoice amount since the charge failed data: { payoutsUsage: { decrement: invoice.amount, }, }, - }); - - const workspace = await prisma.project.findUniqueOrThrow({ - where: { - id: invoice.workspaceId, - }, include: { users: { select: {