Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add new plan

Marc Seitzeabbeebf4610
diff --git a/components/billing/pro-annual-banner.tsx b/components/billing/pro-annual-banner.tsx
index 06529bed..6af3699e 100644
--- a/components/billing/pro-annual-banner.tsx
+++ b/components/billing/pro-annual-banner.tsx
@@ -3,6 +3,7 @@ import { useRouter } from "next/router";
import { Dispatch, SetStateAction, useState } from "react";
import { useTeam } from "@/context/team-context";
+import { getPriceIdFromPlan } from "@/ee/stripe/functions/get-price-id-from-plan";
import Cookies from "js-cookie";
import { usePlausible } from "next-plausible";
import { toast } from "sonner";
@@ -56,12 +57,17 @@ export default function ProAnnualBanner({
onClick={() => {
if (isCustomer && teamPlan === "pro") {
setIsLoading(true);
- fetch(
- `/api/teams/${teamInfo?.currentTeam?.id}/billing/manage?proAnnualBanner=true`,
- {
- method: "POST",
+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/billing/manage`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
},
- )
+ body: JSON.stringify({
+ priceId: getPriceIdFromPlan("Pro", "yearly"),
+ upgradePlan: true,
+ proAnnualBanner: true,
+ }),
+ })
.then(async (res) => {
const url = await res.json();
router.push(url);
diff --git a/components/billing/upgrade-plan-modal.tsx b/components/billing/upgrade-plan-modal.tsx
index 6e44f5fb..b728c154 100644
--- a/components/billing/upgrade-plan-modal.tsx
+++ b/components/billing/upgrade-plan-modal.tsx
@@ -7,6 +7,7 @@ import React from "react";
import { useTeam } from "@/context/team-context";
import { getStripe } from "@/ee/stripe/client";
import { Feature, PlanEnum, getPlanFeatures } from "@/ee/stripe/constants";
+import { getPriceIdFromPlan } from "@/ee/stripe/functions/get-price-id-from-plan";
import { PLANS } from "@/ee/stripe/utils";
import { CheckIcon, Users2Icon } from "lucide-react";
@@ -277,10 +278,22 @@ export function UpgradePlanModal({
loading={selectedPlan === planOption}
disabled={selectedPlan !== null}
onClick={() => {
+ const priceId = getPriceIdFromPlan(
+ displayPlanName,
+ period,
+ );
+
setSelectedPlan(planOption);
if (isCustomer && teamPlan !== "free") {
fetch(`/api/teams/${teamId}/billing/manage`, {
method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ priceId,
+ upgradePlan: true,
+ }),
})
.then(async (res) => {
const url = await res.json();
@@ -293,13 +306,7 @@ export function UpgradePlanModal({
} else {
fetch(
`/api/teams/${teamId}/billing/upgrade?priceId=${
- PLANS.find((p) => p.name === displayPlanName)!
- .price[period].priceIds[
- process.env.NEXT_PUBLIC_VERCEL_ENV ===
- "production"
- ? "production"
- : "test"
- ][isOldAccount ? "old" : "new"]
+ priceId
}`,
{
method: "POST",
diff --git a/ee/limits/constants.ts b/ee/limits/constants.ts
index fb6c4e49..773cd493 100644
--- a/ee/limits/constants.ts
+++ b/ee/limits/constants.ts
@@ -39,7 +39,7 @@ export const BUSINESS_PLAN_LIMITS = {
links: null,
documents: null,
domains: 5,
- datarooms: 1,
+ datarooms: 100,
customDomainOnPro: true,
customDomainInDataroom: false,
advancedLinkControlsOnPro: false,
@@ -55,3 +55,14 @@ export const DATAROOMS_PLAN_LIMITS = {
customDomainInDataroom: true,
advancedLinkControlsOnPro: false,
};
+
+export const DATAROOMS_PLUS_PLAN_LIMITS = {
+ users: 5,
+ links: null,
+ documents: null,
+ domains: 1000,
+ datarooms: 1000,
+ customDomainOnPro: true,
+ customDomainInDataroom: true,
+ advancedLinkControlsOnPro: false,
+};
diff --git a/ee/limits/server.ts b/ee/limits/server.ts
index a047903d..a0e643c1 100644
--- a/ee/limits/server.ts
+++ b/ee/limits/server.ts
@@ -5,6 +5,7 @@ import prisma from "@/lib/prisma";
import {
BUSINESS_PLAN_LIMITS,
DATAROOMS_PLAN_LIMITS,
+ DATAROOMS_PLUS_PLAN_LIMITS,
FREE_PLAN_LIMITS,
PRO_PLAN_LIMITS,
TPlanLimits,
@@ -21,6 +22,7 @@ const planLimitsMap: Record<string, TPlanLimits> = {
pro: PRO_PLAN_LIMITS,
business: BUSINESS_PLAN_LIMITS,
datarooms: DATAROOMS_PLAN_LIMITS,
+ "datarooms-plus": DATAROOMS_PLUS_PLAN_LIMITS,
};
const configSchema = z.object({
diff --git a/ee/stripe/functions/get-price-id-from-plan.ts b/ee/stripe/functions/get-price-id-from-plan.ts
index ba42220c..53addba3 100644
--- a/ee/stripe/functions/get-price-id-from-plan.ts
+++ b/ee/stripe/functions/get-price-id-from-plan.ts
@@ -9,7 +9,9 @@ export function getPriceIdFromPlan(
const accountType = isOldAccount(planName) ? "old" : "new";
const cleanPlanName = planName.split("+")[0];
- return PLANS.find((p) => p.name === cleanPlanName)?.price[period].priceIds[
- env
- ][accountType];
+
+ const priceId = PLANS.find((p) => p.name === cleanPlanName)?.price[period]
+ .priceIds[env][accountType];
+ console.log("priceId", priceId);
+ return priceId;
}
diff --git a/ee/stripe/functions/get-quantity-from-plan.ts b/ee/stripe/functions/get-quantity-from-plan.ts
new file mode 100644
index 00000000..07ae5d37
--- /dev/null
+++ b/ee/stripe/functions/get-quantity-from-plan.ts
@@ -0,0 +1,9 @@
+import { PLANS, getPlanFromPriceId } from "../utils";
+
+export function getQuantityFromPriceId(priceId?: string) {
+ if (!priceId) {
+ return 1;
+ }
+ const plan = getPlanFromPriceId(priceId);
+ return plan.minQuantity ?? 1;
+}
diff --git a/ee/stripe/utils.ts b/ee/stripe/utils.ts
index eaf95fe7..4fc064d5 100644
--- a/ee/stripe/utils.ts
+++ b/ee/stripe/utils.ts
@@ -165,30 +165,30 @@ export const PLANS = [
minQuantity: 5,
price: {
monthly: {
- amount: 399,
+ amount: 249,
unitPrice: 4967,
priceIds: {
test: {
old: "price_1QojZuFJyGSZ96lhNwiD1y2r",
- new: "price_1QojT3BYvhH6u7U7quP5CAXv",
+ new: "price_1Qw63uBYvhH6u7U7dHVZ0kWZ",
},
production: {
- old: "price_1QojcVFJyGSZ96lhZFAJBCaJ",
- new: "price_1QojXJBYvhH6u7U7Jd3sVnMY",
+ old: "price_1Qw6nDFJyGSZ96lhLrtONCCG",
+ new: "price_1Qw6lGBYvhH6u7U7yjSR0uOV",
},
},
},
yearly: {
- amount: 249,
+ amount: 199,
unitPrice: 3300,
priceIds: {
test: {
old: "price_1QojaPFJyGSZ96lhods9TOxh",
- new: "price_1QojT3BYvhH6u7U7VNseK7Fw",
+ new: "price_1Qw63ABYvhH6u7U7MXK3UOJF",
},
production: {
- old: "price_1QojcVFJyGSZ96lhhlR7qR4C",
- new: "price_1QojXJBYvhH6u7U7AFd0GxkA",
+ old: "price_1Qw6neFJyGSZ96lh6ka3Gjyg",
+ new: "price_1Qw6kzBYvhH6u7U7Cujel6bW",
},
},
},
diff --git a/ee/stripe/webhooks/checkout-session-completed.ts b/ee/stripe/webhooks/checkout-session-completed.ts
index e54421af..dfb671e3 100644
--- a/ee/stripe/webhooks/checkout-session-completed.ts
+++ b/ee/stripe/webhooks/checkout-session-completed.ts
@@ -1,6 +1,7 @@
import {
BUSINESS_PLAN_LIMITS,
DATAROOMS_PLAN_LIMITS,
+ DATAROOMS_PLUS_PLAN_LIMITS,
PRO_PLAN_LIMITS,
} from "@/ee/limits/constants";
import { stripeInstance } from "@/ee/stripe";
@@ -58,13 +59,16 @@ export async function checkoutSessionCompleted(
let planLimits:
| typeof PRO_PLAN_LIMITS
| typeof BUSINESS_PLAN_LIMITS
- | typeof DATAROOMS_PLAN_LIMITS = structuredClone(PRO_PLAN_LIMITS);
+ | typeof DATAROOMS_PLAN_LIMITS
+ | typeof DATAROOMS_PLUS_PLAN_LIMITS = 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);
+ } else if (plan.slug === "datarooms-plus") {
+ planLimits = structuredClone(DATAROOMS_PLUS_PLAN_LIMITS);
}
// Update the user limit in planLimits based on the subscription quantity
diff --git a/ee/stripe/webhooks/customer-subscription-updated.ts b/ee/stripe/webhooks/customer-subscription-updated.ts
index a2587776..7c8099a8 100644
--- a/ee/stripe/webhooks/customer-subscription-updated.ts
+++ b/ee/stripe/webhooks/customer-subscription-updated.ts
@@ -3,6 +3,7 @@ import { NextApiResponse } from "next";
import {
BUSINESS_PLAN_LIMITS,
DATAROOMS_PLAN_LIMITS,
+ DATAROOMS_PLUS_PLAN_LIMITS,
PRO_PLAN_LIMITS,
} from "@/ee/limits/constants";
import Stripe from "stripe";
@@ -64,13 +65,16 @@ export async function customerSubsciptionUpdated(
let planLimits:
| typeof PRO_PLAN_LIMITS
| typeof BUSINESS_PLAN_LIMITS
- | typeof DATAROOMS_PLAN_LIMITS = structuredClone(PRO_PLAN_LIMITS);
+ | typeof DATAROOMS_PLAN_LIMITS
+ | typeof DATAROOMS_PLUS_PLAN_LIMITS = 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);
+ } else if (plan.slug === "datarooms-plus") {
+ planLimits = structuredClone(DATAROOMS_PLUS_PLAN_LIMITS);
}
// Update the user limit in planLimits based on the subscription quantity
diff --git a/pages/api/teams/[teamId]/billing/manage.ts b/pages/api/teams/[teamId]/billing/manage.ts
index d3502eb7..ab2edf86 100644
--- a/pages/api/teams/[teamId]/billing/manage.ts
+++ b/pages/api/teams/[teamId]/billing/manage.ts
@@ -2,6 +2,7 @@ import { NextApiRequest, NextApiResponse } from "next";
import { stripeInstance } from "@/ee/stripe";
import { getPriceIdFromPlan } from "@/ee/stripe/functions/get-price-id-from-plan";
+import { getQuantityFromPriceId } from "@/ee/stripe/functions/get-quantity-from-plan";
import getSubscriptionItem from "@/ee/stripe/functions/get-subscription-item";
import { PLANS, isOldAccount } from "@/ee/stripe/utils";
import { waitUntil } from "@vercel/functions";
@@ -31,12 +32,15 @@ export default async function handle(
return;
}
- const { teamId, proAnnualBanner } = req.query as {
- teamId: string;
- proAnnualBanner?: string;
- };
const userId = (session.user as CustomUser).id;
const userEmail = (session.user as CustomUser).email;
+
+ const { teamId } = req.query as { teamId: string };
+ const { priceId, upgradePlan, proAnnualBanner } = req.body as {
+ priceId: string;
+ upgradePlan: boolean;
+ proAnnualBanner?: boolean;
+ };
try {
const team = await prisma.team.findUnique({
where: {
@@ -65,22 +69,18 @@ export default async function handle(
return res.status(400).json({ error: "No subscription ID" });
}
- let priceId: string | undefined;
- let subscriptionItemId: string | undefined;
- if (!!proAnnualBanner) {
- priceId = getPriceIdFromPlan(team.plan, "yearly");
+ const subscriptionItemId = await getSubscriptionItem(
+ team.subscriptionId,
+ isOldAccount(team.plan),
+ );
- subscriptionItemId = await getSubscriptionItem(
- team.subscriptionId,
- isOldAccount(team.plan),
- );
- }
+ const minQuantity = getQuantityFromPriceId(priceId);
const stripe = stripeInstance(isOldAccount(team.plan));
const { url } = await stripe.billingPortal.sessions.create({
customer: team.stripeId,
return_url: `${process.env.NEXTAUTH_URL}/settings/billing?cancel=true`,
- ...(!!proAnnualBanner &&
+ ...(upgradePlan &&
subscriptionItemId && {
flow_data: {
type: "subscription_update_confirm",
@@ -89,7 +89,7 @@ export default async function handle(
items: [
{
id: subscriptionItemId,
- quantity: 1,
+ quantity: isOldAccount(team.plan) ? 1 : minQuantity,
price: priceId,
},
],
@@ -109,7 +109,7 @@ export default async function handle(
trackAnalytics({
event: "Stripe Billing Portal Clicked",
teamId,
- action: !!proAnnualBanner ? "pro-annual-banner" : undefined,
+ action: proAnnualBanner ? "pro-annual-banner" : undefined,
}),
);