Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
refactor: change price id retrieval function
Marc Seitz114e27cde00e
diff --git a/components/billing/add-seat-modal.tsx b/components/billing/add-seat-modal.tsxindex 4b85506f..fe6319cc 100644--- a/components/billing/add-seat-modal.tsx+++ b/components/billing/add-seat-modal.tsx@@ -37,17 +37,18 @@ export function AddSeatModal({const teamInfo = useTeam();const teamId = teamInfo?.currentTeam?.id;const analytics = useAnalytics();- const { plan: userPlan, planName, isAnnualPlan } = usePlan();+ const { plan: userPlan, planName, isAnnualPlan, isOldAccount } = usePlan();const { limits } = useLimits();const [quantity, setQuantity] = useState<number>(1);const [loading, setLoading] = useState<boolean>(false);// Get the minimum quantity for the current plan- const priceId = getPriceIdFromPlan(- planName,- isAnnualPlan ? "yearly" : "monthly",- );+ const priceId = getPriceIdFromPlan({+ planSlug: userPlan,+ isOld: isOldAccount,+ period: isAnnualPlan ? "yearly" : "monthly",+ });const minQuantity = getQuantityFromPriceId(priceId);// Set initial quantity to 1 (adding one seat)diff --git a/components/billing/pro-annual-banner.tsx b/components/billing/pro-annual-banner.tsxindex 6af3699e..5b5f8561 100644--- a/components/billing/pro-annual-banner.tsx+++ b/components/billing/pro-annual-banner.tsx@@ -8,11 +8,11 @@ import Cookies from "js-cookie";import { usePlausible } from "next-plausible";import { toast } from "sonner";+import { usePlan } from "@/lib/swr/use-billing";+import X from "@/components/shared/icons/x";import { Button } from "@/components/ui/button";-import { usePlan } from "@/lib/swr/use-billing";-export default function ProAnnualBanner({setShowProAnnualBanner,}: {@@ -63,7 +63,11 @@ export default function ProAnnualBanner({"Content-Type": "application/json",},body: JSON.stringify({- priceId: getPriceIdFromPlan("Pro", "yearly"),+ priceId: getPriceIdFromPlan({+ planSlug: "pro",+ isOld: isOldAccount,+ period: "yearly",+ }),upgradePlan: true,proAnnualBanner: true,}),diff --git a/components/billing/upgrade-plan-modal.tsx b/components/billing/upgrade-plan-modal.tsxindex 4ad1f236..699a4e2a 100644--- a/components/billing/upgrade-plan-modal.tsx+++ b/components/billing/upgrade-plan-modal.tsx@@ -312,10 +312,11 @@ export function UpgradePlanModal({loading={selectedPlan === planOption}disabled={selectedPlan !== null}onClick={() => {- const priceId = getPriceIdFromPlan(- displayPlanName,+ const priceId = getPriceIdFromPlan({+ planName: displayPlanName,period,- );+ isOld: isOldAccount,+ });setSelectedPlan(planOption);if (isCustomer && teamPlan !== "free") {diff --git a/ee/stripe/functions/get-price-id-from-plan.ts b/ee/stripe/functions/get-price-id-from-plan.tsindex 4e539fa2..a8bc861d 100644--- a/ee/stripe/functions/get-price-id-from-plan.ts+++ b/ee/stripe/functions/get-price-id-from-plan.ts@@ -1,15 +1,34 @@import { PLANS, isOldAccount } from "../utils";-export function getPriceIdFromPlan(- planName: string,- period: "monthly" | "yearly",-) {+export function getPriceIdFromPlan({+ planSlug,+ planName,+ isOld,+ period,+}: {+ planSlug?: string;+ planName?: string;+ isOld?: boolean;+ 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];- const priceId = PLANS.find((p) => p.name === cleanPlanName)?.price[period]- .priceIds[env][accountType];- return priceId;+ 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;+ }++ if (planName) {+ const accountType = isOld ? "old" : isOldAccount(planName) ? "old" : "new";+ const cleanPlanName = planName.split("+")[0];++ const priceId = PLANS.find((p) => p.name === cleanPlanName)?.price[period]+ .priceIds[env][accountType];+ return priceId;+ }}