Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update customer-subscription-updated.ts

Steven Teya6db5ea45f73
diff --git a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
index 83a57b6148..ceffffaaa0 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
@@ -29,6 +29,7 @@ export async function customerSubscriptionUpdated(event: Stripe.Event) {
id: true,
plan: true,
paymentFailedAt: true,
+ payoutsLimit: true,
foldersUsage: true,
users: {
select: {
@@ -58,19 +59,23 @@ export async function customerSubscriptionUpdated(event: Stripe.Event) {
return NextResponse.json({ received: true });
}
- const newPlan = plan.name.toLowerCase();
- const shouldDisableWebhooks = newPlan === "free" || newPlan === "pro";
- const shouldDeleteFolders = newPlan === "free" && workspace.foldersUsage > 0;
+ const newPlanName = plan.name.toLowerCase();
+ const shouldDisableWebhooks = newPlanName === "free" || newPlanName === "pro";
+ const shouldDeleteFolders =
+ newPlanName === "free" && workspace.foldersUsage > 0;
// If a workspace upgrades/downgrades their subscription, update their usage limit in the database.
- if (workspace.plan !== newPlan) {
+ if (
+ workspace.plan !== newPlanName ||
+ workspace.payoutsLimit !== plan.limits.payouts
+ ) {
await Promise.allSettled([
prisma.project.update({
where: {
stripeId,
},
data: {
- plan: newPlan,
+ plan: newPlanName,
usageLimit: plan.limits.clicks!,
linksLimit: plan.limits.links!,
payoutsLimit: plan.limits.payouts!,