Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
refactor: change plan function
Marc Seitz8f6cef467199
diff --git a/ee/stripe/functions/get-price-id-from-plan.ts b/ee/stripe/functions/get-price-id-from-plan.tsindex a8bc861d..93e1c206 100644--- a/ee/stripe/functions/get-price-id-from-plan.ts+++ b/ee/stripe/functions/get-price-id-from-plan.ts@@ -11,24 +11,28 @@ export function getPriceIdFromPlan({isOld?: boolean;period: "monthly" | "yearly";}) {+ if (!planSlug && !planName) {+ throw new Error("Either planSlug or planName must be provided");+ }const env =process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test";- if (planSlug) {- const accountType = isOld ? "old" : isOldAccount(planSlug) ? "old" : "new";- const cleanPlanSlug = planSlug.split("+")[0];-- const priceId = PLANS.find((p) => p.slug === cleanPlanSlug)?.price[period]- .priceIds[env][accountType];- return priceId;- }+ const planIdentifier = planSlug || planName;+ const accountType = isOld+ ? "old"+ : isOldAccount(planIdentifier!)+ ? "old"+ : "new";+ const cleanPlan = planIdentifier!.split("+")[0];- if (planName) {- const accountType = isOld ? "old" : isOldAccount(planName) ? "old" : "new";- const cleanPlanName = planName.split("+")[0];+ const plan = PLANS.find((p) =>+ planSlug ? p.slug === cleanPlan : p.name === cleanPlan,+ );- const priceId = PLANS.find((p) => p.name === cleanPlanName)?.price[period]- .priceIds[env][accountType];- return priceId;+ if (!plan) {+ console.error(`Plan not found: ${cleanPlan}`);+ return undefined;}++ return plan.price[period].priceIds[env][accountType];}