Skip to content

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

feat: don't default to free plan

Marc Seitzc2ffe9cc362a
diff --git a/ee/stripe/utils.ts b/ee/stripe/utils.ts
index 429bb84b..79103078 100644
--- a/ee/stripe/utils.ts
+++ b/ee/stripe/utils.ts
@@ -1,5 +1,39 @@
import Stripe from "stripe";
+// Historical price IDs that are no longer in the main PLANS configuration
+// but still need to be supported for existing subscriptions
+const HISTORICAL_PRICE_IDS: Record<string, Record<string, string>> = {
+ production: {
+ // Business plan historical prices
+ price_1OuYeIFJyGSZ96lhwH58Y1kU: "business", // Old business plan
+ // Add more historical price IDs here as needed
+ },
+ test: {
+ // Add test environment historical price IDs if needed
+ },
+};
+
+function getHistoricalPlanFromPriceId(priceId: string, env: string) {
+ const planSlug = HISTORICAL_PRICE_IDS[env]?.[priceId];
+ if (!planSlug) {
+ return null;
+ }
+
+ // Find the current plan configuration for this slug
+ const currentPlan = PLANS.find((plan) => plan.slug === planSlug);
+ if (!currentPlan) {
+ return null;
+ }
+
+ // Return a plan object that maintains the current plan structure
+ // but indicates it's from a historical price ID
+ return {
+ ...currentPlan,
+ // Mark this as a historical price for logging purposes
+ _historical: true,
+ };
+}
+
export function getPlanFromPriceId(
priceId: string,
isOldAccount: boolean = false,
@@ -14,27 +48,20 @@ export function getPlanFromPriceId(
);
if (!plan) {
+ // Check historical price IDs for known legacy prices
+ const historicalPlan = getHistoricalPlanFromPriceId(priceId, env);
+ if (historicalPlan) {
+ console.log(
+ `Found historical plan mapping for priceId: ${priceId} -> ${historicalPlan.slug}`,
+ );
+ return historicalPlan;
+ }
+
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 null instead of a fake free plan to prevent unintended downgrades
+ return null;
}
return plan;
diff --git a/ee/stripe/webhooks/checkout-session-completed.ts b/ee/stripe/webhooks/checkout-session-completed.ts
index 27ed69e9..74aded70 100644
--- a/ee/stripe/webhooks/checkout-session-completed.ts
+++ b/ee/stripe/webhooks/checkout-session-completed.ts
@@ -47,7 +47,7 @@ export async function checkoutSessionCompleted(
if (!plan) {
await log({
- message: `Invalid price ID in checkout.session.completed event: ${priceId}`,
+ message: `Invalid price ID in checkout.session.completed event: ${priceId}, isOldAccount: ${isOldAccount}. Skipping webhook processing to prevent unintended plan changes.`,
type: "error",
});
return;
diff --git a/ee/stripe/webhooks/customer-subscription-updated.ts b/ee/stripe/webhooks/customer-subscription-updated.ts
index c484a7e3..fbc2f4d0 100644
--- a/ee/stripe/webhooks/customer-subscription-updated.ts
+++ b/ee/stripe/webhooks/customer-subscription-updated.ts
@@ -25,10 +25,10 @@ export async function customerSubsciptionUpdated(
if (!plan) {
await log({
- message: `Invalid price ID in customer.subscription.updated event: ${priceId}`,
+ message: `Invalid price ID in customer.subscription.updated event: ${priceId}, isOldAccount: ${isOldAccount}. Skipping webhook processing to prevent unintended plan changes.`,
type: "error",
});
- return;
+ return res.status(200).json({ received: true });
}
const stripeId = subscriptionUpdated.customer.toString();