diff --git a/packages/billing/src/api/webhookHandler.ts b/packages/billing/src/api/webhookHandler.ts index 077dc3e53..b553a3e87 100644 --- a/packages/billing/src/api/webhookHandler.ts +++ b/packages/billing/src/api/webhookHandler.ts @@ -73,7 +73,7 @@ export const webhookHandler = async ( workspaceId, userId: m.userId, data: { - prevPlan: workspace.plan, + prevPlan: Plan.FREE, plan, }, })), @@ -229,14 +229,16 @@ export const webhookHandler = async ( (invoice) => invoice.amount_due > prices["PRO"] * 100, ); - const workspaceExist = - (await prisma.workspace.count({ - where: { - stripeId: subscription.customer as string, - }, - })) > 0; + const existingWorkspace = await prisma.workspace.findFirst({ + where: { + stripeId: subscription.customer as string, + }, + select: { + plan: true, + }, + }); - if (!workspaceExist) + if (!existingWorkspace) return res.send({ message: "Workspace not found, skipping..." }); const workspace = await prisma.workspace.update({ @@ -266,7 +268,7 @@ export const webhookHandler = async ( workspaceId: workspace.id, userId: m.userId, data: { - prevPlan: workspace.plan, + prevPlan: existingWorkspace.plan, plan: Plan.FREE, }, })),