Skip to content

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

feat: add unit-based pricing

Marc Seitz5dfd2db45b76
diff --git a/components/billing/upgrade-plan-modal-old.tsx b/components/billing/upgrade-plan-modal-old.tsx
index 7acbfc4a..39fd75d6 100644
--- a/components/billing/upgrade-plan-modal-old.tsx
+++ b/components/billing/upgrade-plan-modal-old.tsx
@@ -41,7 +41,7 @@ export function UpgradePlanModal({
const [period, setPeriod] = useState<"yearly" | "monthly">("yearly");
const [clicked, setClicked] = useState<boolean>(false);
const teamInfo = useTeam();
- const { plan: teamPlan, trial, isCustomer } = usePlan();
+ const { plan: teamPlan, trial, isCustomer, isOldAccount } = usePlan();
const analytics = useAnalytics();
const isTrial = !!trial;
@@ -264,7 +264,7 @@ export function UpgradePlanModal({
.then(async (res) => {
const data = await res.json();
const { id: sessionId } = data;
- const stripe = await getStripe();
+ const stripe = await getStripe(isOldAccount);
stripe?.redirectToCheckout({ sessionId });
})
.catch((err) => {
diff --git a/components/billing/upgrade-plan-modal.tsx b/components/billing/upgrade-plan-modal.tsx
index fd79d64d..2b33edb1 100644
--- a/components/billing/upgrade-plan-modal.tsx
+++ b/components/billing/upgrade-plan-modal.tsx
@@ -43,7 +43,7 @@ export function UpgradePlanModal({
const [period, setPeriod] = useState<"yearly" | "monthly">("yearly");
const [clicked, setClicked] = useState<boolean>(false);
const teamInfo = useTeam();
- const { plan: teamPlan, trial, isCustomer } = usePlan();
+ const { plan: teamPlan, trial, isCustomer, isOldAccount } = usePlan();
const analytics = useAnalytics();
const isTrial = !!trial;
@@ -215,7 +215,7 @@ export function UpgradePlanModal({
}
</p>
- <ul className="mb-6 mt-2 space-y-2 text-sm leading-6 text-gray-600 dark:text-muted-foreground dark:text-white/75">
+ <ul className="mb-6 mt-2 space-y-2 text-sm leading-6 text-gray-600 dark:text-white/75">
{planFeatures[
planOption as keyof typeof planFeatures
].features.map((feature, i) => (
@@ -263,7 +263,7 @@ export function UpgradePlanModal({
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
? "production"
: "test"
- ]
+ ][isOldAccount ? "old" : "new"]
}`,
{
method: "POST",
@@ -275,7 +275,7 @@ export function UpgradePlanModal({
.then(async (res) => {
const data = await res.json();
const { id: sessionId } = data;
- const stripe = await getStripe();
+ const stripe = await getStripe(isOldAccount);
stripe?.redirectToCheckout({ sessionId });
})
.catch((err) => {
diff --git a/lib/stripe/client.ts b/lib/stripe/client.ts
index 5bb9d701..e9a50815 100644
--- a/lib/stripe/client.ts
+++ b/lib/stripe/client.ts
@@ -3,13 +3,21 @@ import { Stripe as StripeProps, loadStripe } from "@stripe/stripe-js";
let stripePromise: Promise<StripeProps | null>;
-export const getStripe = () => {
+export const getStripe = (account: boolean = false) => {
if (!stripePromise) {
- stripePromise = loadStripe(
- process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY_LIVE ??
- process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY ??
- "",
- );
+ if (account) {
+ stripePromise = loadStripe(
+ process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY_LIVE_OLD ??
+ process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY_OLD ??
+ "",
+ );
+ } else {
+ stripePromise = loadStripe(
+ process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY_LIVE ??
+ process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY ??
+ "",
+ );
+ }
}
return stripePromise;
diff --git a/lib/stripe/index.ts b/lib/stripe/index.ts
index 2995b8d0..6ae49bd0 100644
--- a/lib/stripe/index.ts
+++ b/lib/stripe/index.ts
@@ -1,6 +1,20 @@
import Stripe from "stripe";
-export const stripe = new Stripe(
+const stripeOld = new Stripe(
+ process.env.STRIPE_SECRET_KEY_LIVE_OLD ??
+ process.env.STRIPE_SECRET_KEY_OLD ??
+ "",
+ {
+ apiVersion: "2024-06-20",
+ appInfo: {
+ name: "Papermark.io",
+ version: "0.1.0",
+ },
+ typescript: true,
+ },
+);
+
+const stripeNew = new Stripe(
process.env.STRIPE_SECRET_KEY_LIVE ?? process.env.STRIPE_SECRET_KEY ?? "",
{
apiVersion: "2024-06-20",
@@ -12,10 +26,18 @@ export const stripe = new Stripe(
},
);
-export async function cancelSubscription(customer?: string) {
+export const stripeInstance = (account: boolean = false) => {
+ return account ? stripeOld : stripeNew;
+};
+
+export async function cancelSubscription(
+ customer?: string,
+ isOldAccount: boolean = false,
+) {
if (!customer) return;
try {
+ const stripe = stripeInstance(isOldAccount);
const subscriptionId = await stripe.subscriptions
.list({
customer,
diff --git a/lib/stripe/utils.ts b/lib/stripe/utils.ts
index 7d75878d..28d44ffc 100644
--- a/lib/stripe/utils.ts
+++ b/lib/stripe/utils.ts
@@ -1,12 +1,16 @@
import Stripe from "stripe";
-export function getPlanFromPriceId(priceId: string) {
+export function getPlanFromPriceId(
+ priceId: string,
+ isOldAccount: boolean = false,
+) {
const env =
process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test";
+ const accountType = isOldAccount ? "old" : "new";
return PLANS.find(
(plan) =>
- plan.price.monthly.priceIds[env] === priceId ||
- plan.price.yearly.priceIds[env] === priceId,
+ plan.price.monthly.priceIds[env][accountType] === priceId ||
+ plan.price.yearly.priceIds[env][accountType] === priceId,
)!;
}
@@ -49,99 +53,92 @@ export const PLANS = [
{
name: "Pro",
slug: "pro",
+ minQuantity: 2,
price: {
monthly: {
amount: 39,
+ unitPrice: 1950,
priceIds: {
- test: "price_1Q3bcHFJyGSZ96lhElXBA5C1",
- production: "price_1P3FK4FJyGSZ96lhD67yF3lj",
+ test: {
+ old: "price_1Q3bcHFJyGSZ96lhElXBA5C1",
+ new: "price_1Q8aUBBYvhH6u7U7LPIVxYpz",
+ },
+ production: { old: "price_1P3FK4FJyGSZ96lhD67yF3lj", new: "" },
},
},
yearly: {
amount: 29,
+ unitPrice: 1450,
priceIds: {
- test: "price_1Q3bV9FJyGSZ96lhCYWIcmg5",
- production: "price_1Q3gfNFJyGSZ96lh2jGhEadm",
+ test: {
+ old: "price_1Q3bV9FJyGSZ96lhCYWIcmg5",
+ new: "price_1Q8aTkBYvhH6u7U7kUiNTSLX",
+ },
+ production: { old: "price_1Q3gfNFJyGSZ96lh2jGhEadm", new: "" },
},
},
},
},
- // {
- // name: "Pro with Custom Domain",
- // price: {
- // monthly: {
- // amount: 59,
- // priceIds: {
- // test: "price_1Q05u4FJyGSZ96lhDFRzhFgj",
- // production: "price_prod_id_pro_custom_domain_monthly",
- // },
- // },
- // yearly: {
- // amount: 49,
- // priceIds: {
- // test: "price_1Q16E9FJyGSZ96lhhepSttFn",
- // production: "price_prod_id_pro_custom_domain_yearly",
- // },
- // },
- // },
- // },
{
name: "Business",
slug: "business",
+ minQuantity: 3,
price: {
monthly: {
amount: 79,
+ unitPrice: 2633,
priceIds: {
- test: "price_1Q3bPhFJyGSZ96lhnxpiJMwz",
- production: "price_1Q3gbVFJyGSZ96lhf7hsZciQ",
+ test: {
+ old: "price_1Q3bPhFJyGSZ96lhnxpiJMwz",
+ new: "price_1Q8aWlBYvhH6u7U7gTeKJJ0Y",
+ },
+ production: { old: "price_1Q3gbVFJyGSZ96lhf7hsZciQ", new: "" },
},
},
yearly: {
amount: 59,
+ unitPrice: 1967,
priceIds: {
- test: "price_1Q3bQ5FJyGSZ96lhoS8QbYXr",
- production: "price_1Q3gbVFJyGSZ96lhqqLhBNDv",
+ test: {
+ old: "price_1Q3bQ5FJyGSZ96lhoS8QbYXr",
+ new: "price_1Q8aVSBYvhH6u7U72mn6iPfK",
+ },
+ production: { old: "price_1Q3gbVFJyGSZ96lhqqLhBNDv", new: "" },
},
},
},
},
- // {
- // name: "Business with Custom Domain",
- // price: {
- // monthly: {
- // amount: 109,
- // priceIds: {
- // test: "price_1Q16CLFJyGSZ96lhYxMLSJm0",
- // production: "price_prod_id_pro_custom_domain_monthly",
- // },
- // },
- // yearly: {
- // amount: 79,
- // priceIds: {
- // test: "price_1Q16DHFJyGSZ96lhDxFnXdNh",
- // production: "price_prod_id_pro_custom_domain_yearly",
- // },
- // },
- // },
- // },
{
name: "Data Rooms",
slug: "datarooms",
+ minQuantity: 3,
price: {
monthly: {
amount: 149,
+ unitPrice: 4967,
priceIds: {
- test: "price_1Q3bHPFJyGSZ96lhpQD0lMdU",
- production: "price_1Q3gbbFJyGSZ96lhvmEwjZtm",
+ test: {
+ old: "price_1Q3bHPFJyGSZ96lhpQD0lMdU",
+ new: "price_1Q8aYLBYvhH6u7U7RUqHnsBh",
+ },
+ production: { old: "price_1Q3gbbFJyGSZ96lhvmEwjZtm", new: "" },
},
},
yearly: {
amount: 99,
+ unitPrice: 3300,
priceIds: {
- test: "price_1Q3bJUFJyGSZ96lhLiEJlXlt",
- production: "price_1Q3gbbFJyGSZ96lhnk1CtnIZ",
+ test: {
+ old: "price_1Q3bJUFJyGSZ96lhLiEJlXlt",
+ new: "price_1Q8aXWBYvhH6u7U7unPGTnfy",
+ },
+ production: { old: "price_1Q3gbbFJyGSZ96lhnk1CtnIZ", new: "" },
},
},
},
},
];
+
+export const isOldAccount = (plan: string) => {
+ return plan.includes("old");
+};
diff --git a/lib/stripe/webhooks/checkout-session-completed.ts b/lib/stripe/webhooks/checkout-session-completed.ts
index d924a97b..33bf5585 100644
--- a/lib/stripe/webhooks/checkout-session-completed.ts
+++ b/lib/stripe/webhooks/checkout-session-completed.ts
@@ -7,12 +7,15 @@ import Stripe from "stripe";
import { sendUpgradePlanEmail } from "@/lib/emails/send-upgrade-plan";
import prisma from "@/lib/prisma";
-import { stripe } from "@/lib/stripe";
+import { stripeInstance } from "@/lib/stripe";
import { log } from "@/lib/utils";
import { getPlanFromPriceId } from "../utils";
-export async function checkoutSessionCompleted(event: Stripe.Event) {
+export async function checkoutSessionCompleted(
+ event: Stripe.Event,
+ isOldAccount: boolean = false,
+) {
const checkoutSession = event.data.object as Stripe.Checkout.Session;
if (
@@ -26,6 +29,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
return;
}
+ const stripe = stripeInstance(isOldAccount);
const subscription = await stripe.subscriptions.retrieve(
checkoutSession.subscription as string,
);
@@ -33,8 +37,12 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
const subscriptionId = subscription.id;
const subscriptionStart = new Date(subscription.current_period_start * 1000);
const subscriptionEnd = new Date(subscription.current_period_end * 1000);
+ const quantity = subscription.items.data[0].quantity;
- const plan = getPlanFromPriceId(priceId);
+ console.log("subscription", subscription);
+ console.log("subscription items", subscription.items.data);
+
+ const plan = getPlanFromPriceId(priceId, isOldAccount);
if (!plan) {
await log({
@@ -59,6 +67,10 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
planLimits = structuredClone(DATAROOMS_PLAN_LIMITS);
}
+ // Update the user limit in planLimits based on the subscription quantity
+ planLimits.users =
+ typeof quantity === "number" && quantity > 1 ? quantity : planLimits.users;
+
// Update the user with the subscription information and stripeId
const team = await prisma.team.update({
where: {
diff --git a/lib/stripe/webhooks/customer-subscription-updated.ts b/lib/stripe/webhooks/customer-subscription-updated.ts
index fded8c16..4c23e8c4 100644
--- a/lib/stripe/webhooks/customer-subscription-updated.ts
+++ b/lib/stripe/webhooks/customer-subscription-updated.ts
@@ -15,11 +15,12 @@ import { getPlanFromPriceId } from "../utils";
export async function customerSubsciptionUpdated(
event: Stripe.Event,
res: NextApiResponse,
+ isOldAccount: boolean = false,
) {
const subscriptionUpdated = event.data.object as Stripe.Subscription;
const priceId = subscriptionUpdated.items.data[0].price.id;
- const plan = getPlanFromPriceId(priceId);
+ const plan = getPlanFromPriceId(priceId, isOldAccount);
if (!plan) {
await log({
@@ -50,6 +51,7 @@ export async function customerSubsciptionUpdated(
const subscriptionId = subscriptionUpdated.id;
const startsAt = new Date(subscriptionUpdated.current_period_start * 1000);
const endsAt = new Date(subscriptionUpdated.current_period_end * 1000);
+ const quantity = subscriptionUpdated.items.data[0].quantity;
// If a team upgrades/downgrades their subscription, update their plan
if (team.plan !== newPlan) {
@@ -66,6 +68,12 @@ export async function customerSubsciptionUpdated(
planLimits = structuredClone(DATAROOMS_PLAN_LIMITS);
}
+ // Update the user limit in planLimits based on the subscription quantity
+ planLimits.users =
+ typeof quantity === "number" && quantity > 1
+ ? quantity
+ : planLimits.users;
+
// Update the user with the subscription information and stripeId
await prisma.team.update({
where: { stripeId },
diff --git a/lib/swr/use-billing.ts b/lib/swr/use-billing.ts
index 5173d004..f243321b 100644
--- a/lib/swr/use-billing.ts
+++ b/lib/swr/use-billing.ts
@@ -45,25 +45,28 @@ export type BasePlan =
| "business"
| "datarooms";
type PlanWithTrial = `${BasePlan}+drtrial`;
+type PlanWithOld = `${BasePlan}+old` | `${BasePlan}+drtrial+old`;
type PlanResponse = {
- plan: BasePlan | PlanWithTrial;
+ plan: BasePlan | PlanWithTrial | PlanWithOld;
isCustomer: boolean;
};
interface PlanDetails {
plan: BasePlan | null;
trial: string | null;
+ old: boolean;
}
-function parsePlan(plan: BasePlan | PlanWithTrial): PlanDetails {
- if (!plan) return { plan: null, trial: null };
+function parsePlan(plan: BasePlan | PlanWithTrial | PlanWithOld): PlanDetails {
+ if (!plan) return { plan: null, trial: null, old: false };
// Split the plan on '+'
const parts = plan.split("+");
return {
plan: parts[0] as BasePlan, // Always the base plan
- trial: parts.length > 1 ? parts[1] : null, // 'drtrial' if present, otherwise null
+ trial: parts.includes("drtrial") ? parts[1] : null, // 'drtrial' if present, otherwise null
+ old: parts.includes("old"), // true if 'old' is present, otherwise false
};
}
@@ -77,11 +80,14 @@ export function usePlan() {
);
// Parse the plan using the parsing function
- const parsedPlan = plan ? parsePlan(plan.plan) : { plan: null, trial: null };
+ const parsedPlan = plan
+ ? parsePlan(plan.plan)
+ : { plan: null, trial: null, old: false };
return {
plan: parsedPlan.plan,
trial: parsedPlan.trial,
+ isOldAccount: parsedPlan.old,
isCustomer: plan?.isCustomer,
loading: !plan && !error,
error,
diff --git a/pages/api/stripe/webhook-old.ts b/pages/api/stripe/webhook-old.ts
new file mode 100644
index 00000000..b043c3f4
--- /dev/null
+++ b/pages/api/stripe/webhook-old.ts
@@ -0,0 +1,83 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import { Readable } from "node:stream";
+import type Stripe from "stripe";
+
+import { stripeInstance } from "@/lib/stripe";
+import { checkoutSessionCompleted } from "@/lib/stripe/webhooks/checkout-session-completed";
+import { customerSubscriptionDeleted } from "@/lib/stripe/webhooks/customer-subscription-deleted";
+import { customerSubsciptionUpdated } from "@/lib/stripe/webhooks/customer-subscription-updated";
+import { log } from "@/lib/utils";
+
+// Stripe requires the raw body to construct the event.
+export const config = {
+ api: {
+ bodyParser: false,
+ },
+};
+
+async function buffer(readable: Readable) {
+ const chunks: Buffer[] = [];
+ for await (const chunk of readable) {
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
+ }
+ return Buffer.concat(chunks);
+}
+
+const relevantEvents = new Set([
+ "checkout.session.completed",
+ "customer.subscription.updated",
+ "customer.subscription.deleted",
+]);
+
+export default async function webhookHandler(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ // POST /api/stripe/webhook-old – listen to Stripe webhooks
+ if (req.method === "POST") {
+ const buf = await buffer(req);
+ const sig = req.headers["stripe-signature"];
+ const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET_OLD;
+ let event: Stripe.Event;
+ try {
+ if (!sig || !webhookSecret) return;
+ const stripe = stripeInstance(true);
+ event = stripe.webhooks.constructEvent(buf, sig, webhookSecret);
+ } catch (err: any) {
+ return res.status(400).send(`Webhook Error: ${err.message}`);
+ }
+
+ // Ignore unsupported events
+ if (!relevantEvents.has(event.type)) {
+ return res.status(400).send(`Unhandled event type: ${event.type}`);
+ }
+
+ try {
+ switch (event.type) {
+ case "checkout.session.completed":
+ await checkoutSessionCompleted(event, true);
+ break;
+ case "customer.subscription.updated":
+ await customerSubsciptionUpdated(event, res, true);
+ break;
+ case "customer.subscription.deleted":
+ await customerSubscriptionDeleted(event, res);
+ break;
+ }
+ } catch (error) {
+ await log({
+ message: `Stripe webhook failed. Error: ${error}`,
+ type: "error",
+ });
+ return res
+ .status(400)
+ .send("Webhook error: Webhook handler failed. View logs.");
+ }
+
+ return res.status(200).json({ received: true });
+ } else {
+ res.setHeader("Allow", ["POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/stripe/webhook.ts b/pages/api/stripe/webhook.ts
index a798c691..d013c78c 100644
--- a/pages/api/stripe/webhook.ts
+++ b/pages/api/stripe/webhook.ts
@@ -3,7 +3,7 @@ import { NextApiRequest, NextApiResponse } from "next";
import { Readable } from "node:stream";
import type Stripe from "stripe";
-import { stripe } from "@/lib/stripe";
+import { stripeInstance } from "@/lib/stripe";
import { checkoutSessionCompleted } from "@/lib/stripe/webhooks/checkout-session-completed";
import { customerSubscriptionDeleted } from "@/lib/stripe/webhooks/customer-subscription-deleted";
import { customerSubsciptionUpdated } from "@/lib/stripe/webhooks/customer-subscription-updated";
@@ -42,6 +42,7 @@ export default async function webhookHandler(
let event: Stripe.Event;
try {
if (!sig || !webhookSecret) return;
+ const stripe = stripeInstance();
event = stripe.webhooks.constructEvent(buf, sig, webhookSecret);
} catch (err: any) {
return res.status(400).send(`Webhook Error: ${err.message}`);
diff --git a/pages/api/teams/[teamId]/billing/manage.ts b/pages/api/teams/[teamId]/billing/manage.ts
index 2819327e..3546e647 100644
--- a/pages/api/teams/[teamId]/billing/manage.ts
+++ b/pages/api/teams/[teamId]/billing/manage.ts
@@ -4,7 +4,8 @@ import { getServerSession } from "next-auth/next";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
-import { stripe } from "@/lib/stripe";
+import { stripeInstance } from "@/lib/stripe";
+import { isOldAccount } from "@/lib/stripe/utils";
import { CustomUser } from "@/lib/types";
import { authOptions } from "../../../auth/[...nextauth]";
@@ -34,6 +35,7 @@ export default async function handle(
},
select: {
stripeId: true,
+ plan: true,
},
});
@@ -44,6 +46,7 @@ export default async function handle(
return res.status(400).json({ error: "No Stripe customer ID" });
}
+ const stripe = stripeInstance(isOldAccount(team.plan));
const { url } = await stripe.billingPortal.sessions.create({
customer: team.stripeId,
return_url: `${process.env.NEXTAUTH_URL}/settings/billing`,
diff --git a/pages/api/teams/[teamId]/billing/upgrade.ts b/pages/api/teams/[teamId]/billing/upgrade.ts
index 9df33d97..466c75ac 100644
--- a/pages/api/teams/[teamId]/billing/upgrade.ts
+++ b/pages/api/teams/[teamId]/billing/upgrade.ts
@@ -4,7 +4,8 @@ import { getServerSession } from "next-auth/next";
import { identifyUser, trackAnalytics } from "@/lib/analytics";
import prisma from "@/lib/prisma";
-import { stripe } from "@/lib/stripe";
+import { stripeInstance } from "@/lib/stripe";
+import { getPlanFromPriceId, isOldAccount } from "@/lib/stripe/utils";
import { CustomUser } from "@/lib/types";
import { authOptions } from "../../../auth/[...nextauth]";
@@ -37,7 +38,7 @@ export default async function handle(
},
},
},
- select: { stripeId: true },
+ select: { stripeId: true, plan: true },
});
if (!team) {
@@ -45,8 +46,25 @@ export default async function handle(
return;
}
+ const oldAccount = isOldAccount(team.plan);
+ const plan = getPlanFromPriceId(priceId, oldAccount);
+ const minimumQuantity = plan.minQuantity;
+
let stripeSession;
+ const lineItem = {
+ price: priceId,
+ quantity: oldAccount ? 1 : minimumQuantity,
+ ...(!oldAccount && {
+ adjustable_quantity: {
+ enabled: true,
+ minimum: minimumQuantity,
+ maximum: 99,
+ },
+ }),
+ };
+
+ const stripe = stripeInstance(oldAccount);
if (team.stripeId) {
// if the team already has a stripeId (i.e. is a customer) let's use as a customer
stripeSession = await stripe.checkout.sessions.create({
@@ -55,7 +73,7 @@ export default async function handle(
billing_address_collection: "required",
success_url: `${process.env.NEXTAUTH_URL}/settings/billing?success=true`,
cancel_url: `${process.env.NEXTAUTH_URL}/settings/billing?cancel=true`,
- line_items: [{ price: priceId, quantity: 1 }],
+ line_items: [lineItem],
automatic_tax: {
enabled: true,
},
@@ -73,7 +91,7 @@ export default async function handle(
billing_address_collection: "required",
success_url: `${process.env.NEXTAUTH_URL}/settings/billing?success=true`,
cancel_url: `${process.env.NEXTAUTH_URL}/settings/billing?cancel=true`,
- line_items: [{ price: priceId, quantity: 1 }],
+ line_items: [lineItem],
automatic_tax: {
enabled: true,
},
diff --git a/pages/api/teams/[teamId]/index.ts b/pages/api/teams/[teamId]/index.ts
index 20f88032..8c31af7c 100644
--- a/pages/api/teams/[teamId]/index.ts
+++ b/pages/api/teams/[teamId]/index.ts
@@ -8,6 +8,7 @@ import { errorhandler } from "@/lib/errorHandler";
import { deleteFiles } from "@/lib/files/delete-team-files-server";
import prisma from "@/lib/prisma";
import { cancelSubscription } from "@/lib/stripe";
+import { isOldAccount } from "@/lib/stripe/utils";
import { CustomUser } from "@/lib/types";
import { authOptions } from "../../auth/[...nextauth]";
@@ -212,7 +213,8 @@ export default async function handle(
// delete domains, if exists on team
team.domains && domainPromises,
// delete subscription, if exists on team
- team.stripeId && cancelSubscription(team.stripeId),
+ team.stripeId &&
+ cancelSubscription(team.stripeId, isOldAccount(team.plan)),
// delete user, if no other teams
userTeams.length === 1 &&
prisma.user.delete({
diff --git a/pages/settings/upgrade.tsx b/pages/settings/upgrade.tsx
index fdcf9cf4..0b82dbd1 100644
--- a/pages/settings/upgrade.tsx
+++ b/pages/settings/upgrade.tsx
@@ -20,7 +20,7 @@ export default function UpgradePage() {
const [period, setPeriod] = useState<"yearly" | "monthly">("yearly");
const [clicked, setClicked] = useState<boolean>(false);
const teamInfo = useTeam();
- const { plan: teamPlan, trial, isCustomer } = usePlan();
+ const { plan: teamPlan, trial, isCustomer, isOldAccount } = usePlan();
const analytics = useAnalytics();
const planFeatures = useMemo(
@@ -122,7 +122,9 @@ export default function UpgradePage() {
<div className="mb-2 text-balance text-4xl font-medium tabular-nums text-foreground">
€{PLANS.find((p) => p.name === planOption)!.price[period].amount}
- <span className="text-base font-normal dark:text-white/75">/month</span>
+ <span className="text-base font-normal dark:text-white/75">
+ /month
+ </span>
</div>
<p className="mt-4 text-sm text-gray-600 dark:text-white">
{
@@ -131,7 +133,7 @@ export default function UpgradePage() {
}
</p>
- <ul className="mb-4 mt-4 space-y-3 text-sm leading-6 text-gray-600 dark:text-muted-foreground dark:text-white/75">
+ <ul className="mb-4 mt-4 space-y-3 text-sm leading-6 text-gray-600 dark:text-white/75">
{planFeatures[
planOption as keyof typeof planFeatures
].features.map((feature, i) => (
@@ -177,7 +179,7 @@ export default function UpgradePage() {
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
? "production"
: "test"
- ]
+ ][isOldAccount ? "old" : "new"]
}`,
{
method: "POST",
@@ -189,7 +191,7 @@ export default function UpgradePage() {
.then(async (res) => {
const data = await res.json();
const { id: sessionId } = data;
- const stripe = await getStripe();
+ const stripe = await getStripe(isOldAccount);
stripe?.redirectToCheckout({ sessionId });
})
.catch((err) => {