Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: minimum quantity error
Marc Seitzb78061537a28
diff --git a/ee/stripe/functions/get-quantity-from-plan.ts b/ee/stripe/functions/get-quantity-from-plan.tsindex 07ae5d37..a5e161d5 100644--- a/ee/stripe/functions/get-quantity-from-plan.ts+++ b/ee/stripe/functions/get-quantity-from-plan.ts@@ -1,9 +1,14 @@-import { PLANS, getPlanFromPriceId } from "../utils";+import { getPlanFromPriceId } from "../utils";export function getQuantityFromPriceId(priceId?: string) {if (!priceId) {return 1;}- const plan = getPlanFromPriceId(priceId);- return plan.minQuantity ?? 1;+ try {+ const plan = getPlanFromPriceId(priceId);+ return plan.minQuantity ?? 1;+ } catch (error) {+ console.error(`Error getting quantity for priceId: ${priceId}`, error);+ return 1;+ }}diff --git a/ee/stripe/utils.ts b/ee/stripe/utils.tsindex 0ff0f31a..429bb84b 100644--- a/ee/stripe/utils.ts+++ b/ee/stripe/utils.ts@@ -7,11 +7,37 @@ export function getPlanFromPriceId(const env =process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test";const accountType = isOldAccount ? "old" : "new";- return PLANS.find(+ const plan = PLANS.find((plan) =>plan.price.monthly.priceIds[env][accountType] === priceId ||plan.price.yearly.priceIds[env][accountType] === priceId,- )!;+ );++ if (!plan) {+ console.error(+ `Plan not found for priceId: ${priceId}, isOldAccount: ${isOldAccount}, env: ${env}`,+ );+ // Return a default plan object for old accounts to prevent crashes+ return {+ name: "Free",+ slug: "free",+ minQuantity: 1,+ price: {+ monthly: {+ amount: 0,+ unitPrice: 0,+ priceIds: { [env]: { [accountType]: priceId } },+ },+ yearly: {+ amount: 0,+ unitPrice: 0,+ priceIds: { [env]: { [accountType]: priceId } },+ },+ },+ };+ }++ return plan;}// custom type coercion because Stripe's types are wrong