mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-19 21:04:33 +08:00
📈 Fix prevPlan retrieve logic in Stripe webhooks
This commit is contained in:
parent
806158541f
commit
09bbe1df41
@ -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,
|
||||
},
|
||||
})),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user