Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat(ee): add limits to plan once upgraded
Marc Seitzc2bc0e033c74
diff --git a/ee/limits/constants.ts b/ee/limits/constants.tsnew file mode 100644index 00000000..c122a7ce--- /dev/null+++ b/ee/limits/constants.ts@@ -0,0 +1,31 @@+export const FREE_PLAN_LIMITS = {+ users: 1,+ domains: 0,+ datarooms: 0,+ customDomainOnPro: false,+ customDomainInDataroom: false,+};++export const PRO_PLAN_LIMITS = {+ users: 2,+ domains: 5,+ datarooms: 0,+ customDomainOnPro: false,+ customDomainInDataroom: false,+};++export const BUSINESS_PLAN_LIMITS = {+ users: 3,+ domains: 5,+ datarooms: 1,+ customDomainOnPro: true,+ customDomainInDataroom: false,+};++export const DATAROOMS_PLAN_LIMITS = {+ users: 5,+ domains: 10,+ datarooms: 100,+ customDomainOnPro: true,+ customDomainInDataroom: true,+};diff --git a/pages/api/stripe/webhook.ts b/pages/api/stripe/webhook.tsindex 19c5b701..bb0069ee 100644--- a/pages/api/stripe/webhook.ts+++ b/pages/api/stripe/webhook.ts@@ -12,6 +12,12 @@ import {isUpgradedCustomer,} from "@/lib/stripe/utils";import { log } from "@/lib/utils";+import {+ BUSINESS_PLAN_LIMITS,+ DATAROOMS_PLAN_LIMITS,+ FREE_PLAN_LIMITS,+ PRO_PLAN_LIMITS,+} from "@/ee/limits/constants";// Stripe requires the raw body to construct the event.export const config = {@@ -90,6 +96,15 @@ export default async function webhookHandler(const { plan, subscriptionId, startsAt, endsAt, newCustomer } =pendingUpdate as SubscriptionInfo;+ let planLimits = structuredClone(PRO_PLAN_LIMITS);+ if (plan.slug === "pro") {+ planLimits = structuredClone(PRO_PLAN_LIMITS);+ } else if (plan.slug === "business") {+ planLimits = structuredClone(BUSINESS_PLAN_LIMITS);+ } else if (plan.slug === "datarooms") {+ planLimits = structuredClone(DATAROOMS_PLAN_LIMITS);+ }+// Update the user with the subscription information and stripeIdconst team = await prisma.team.update({where: {@@ -101,6 +116,7 @@ export default async function webhookHandler(subscriptionId,startsAt,endsAt,+ limits: planLimits,},select: {id: true,@@ -156,6 +172,15 @@ export default async function webhookHandler(newCustomer,});+ let planLimits = structuredClone(PRO_PLAN_LIMITS);+ if (plan.slug === "pro") {+ planLimits = structuredClone(PRO_PLAN_LIMITS);+ } else if (plan.slug === "business") {+ planLimits = structuredClone(BUSINESS_PLAN_LIMITS);+ } else if (plan.slug === "datarooms") {+ planLimits = structuredClone(DATAROOMS_PLAN_LIMITS);+ }+// if user upgrades from Pro to Business, checkout event won't be fired// so we need to update the user immediatelyif (upgradedCustomer && !newCustomer) {@@ -168,6 +193,7 @@ export default async function webhookHandler(subscriptionId,startsAt,endsAt,+ limits: planLimits,},select: {id: true,@@ -184,8 +210,9 @@ export default async function webhookHandler(const stripeId = subscriptionDeleted.customer.toString();const subscriptionId = subscriptionDeleted.id;- // If a project deletes their subscription, reset their usage limit in the database to 1000.- // Also remove the root domain redirect for all their domains from Redis.+ // reset the plan limits to free+ const planlimits = structuredClone(FREE_PLAN_LIMITS);+const team = await prisma.team.update({where: {stripeId,@@ -196,6 +223,7 @@ export default async function webhookHandler(subscriptionId: null,endsAt: null,startsAt: null,+ limits: planlimits,},select: { id: true },});