Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat(stripe): add price id function
Marc Seitz66d22f4c8bef
diff --git a/ee/stripe/functions/get-price-id-from-plan.ts b/ee/stripe/functions/get-price-id-from-plan.tsnew file mode 100644index 00000000..ba42220c--- /dev/null+++ b/ee/stripe/functions/get-price-id-from-plan.ts@@ -0,0 +1,15 @@+import { PLANS, isOldAccount } from "../utils";++export function getPriceIdFromPlan(+ planName: string,+ period: "monthly" | "yearly",+) {+ const env =+ process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test";+ const accountType = isOldAccount(planName) ? "old" : "new";+ const cleanPlanName = planName.split("+")[0];++ return PLANS.find((p) => p.name === cleanPlanName)?.price[period].priceIds[+ env+ ][accountType];+}diff --git a/pages/api/teams/[teamId]/billing/manage.ts b/pages/api/teams/[teamId]/billing/manage.tsindex 60ee008d..d3502eb7 100644--- a/pages/api/teams/[teamId]/billing/manage.ts+++ b/pages/api/teams/[teamId]/billing/manage.ts@@ -1,6 +1,7 @@import { NextApiRequest, NextApiResponse } from "next";import { stripeInstance } from "@/ee/stripe";+import { getPriceIdFromPlan } from "@/ee/stripe/functions/get-price-id-from-plan";import getSubscriptionItem from "@/ee/stripe/functions/get-subscription-item";import { PLANS, isOldAccount } from "@/ee/stripe/utils";import { waitUntil } from "@vercel/functions";@@ -67,11 +68,7 @@ export default async function handle(let priceId: string | undefined;let subscriptionItemId: string | undefined;if (!!proAnnualBanner) {- priceId = PLANS.find((p) => p.name === "Pro")?.price.yearly.priceIds[- process.env.NEXT_PUBLIC_VERCEL_ENV === "production"- ? "production"- : "test"- ][isOldAccount(team.plan) ? "old" : "new"];+ priceId = getPriceIdFromPlan(team.plan, "yearly");subscriptionItemId = await getSubscriptionItem(team.subscriptionId,