🐛 (billing) Fix webhook calls when workspace was deleted

This commit is contained in:
Baptiste Arnaud
2024-02-13 10:23:13 +01:00
parent 63dc2e062b
commit 191aeb0214
3 changed files with 30 additions and 2 deletions

View File

@@ -234,6 +234,17 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => {
outstandingInvoices.data.filter(
(invoice) => invoice.amount_due > prices['PRO'] * 100
)
const workspaceExist =
(await prisma.workspace.count({
where: {
stripeId: subscription.customer as string,
},
})) > 0
if (!workspaceExist)
return res.send({ message: 'Workspace not found, skipping...' })
const workspace = await prisma.workspace.update({
where: {
stripeId: subscription.customer as string,