Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix subscription.updated logic

Steven Tey9d0cf9a3d198
diff --git a/apps/web/app/(ee)/api/stripe/webhook/utils.ts b/apps/web/app/(ee)/api/stripe/webhook/utils.ts
index 6158ee70cf..5734da24c6 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/utils.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/utils.ts
@@ -4,7 +4,8 @@ import { WorkspaceProps } from "@/lib/types";
import { webhookCache } from "@/lib/webhook/cache";
import { sendEmail } from "@dub/email";
import { prisma } from "@dub/prisma";
-import { getPlanFromPriceId, LEGACY_PRICE_IDS } from "@dub/utils";
+import { getPlanFromPriceId } from "@dub/utils";
+import { NEW_BUSINESS_PRICE_IDS } from "@dub/utils/src";
import Stripe from "stripe";
const cancellationReasonMap = {
@@ -71,12 +72,12 @@ export async function updateWorkspacePlan({
newPlanName === "free" && workspace.foldersUsage > 0;
// If a workspace upgrades/downgrades their subscription
- // or if the payouts limit changes and the new plan is not a legacy plan
+ // or if the payouts limit increases and the updated price ID is a new business price ID
// update their usage limit in the database
if (
workspace.plan !== newPlanName ||
- (workspace.payoutsLimit !== plan.limits.payouts &&
- !LEGACY_PRICE_IDS.includes(priceId))
+ (workspace.payoutsLimit < plan.limits.payouts &&
+ NEW_BUSINESS_PRICE_IDS.includes(priceId))
) {
await Promise.allSettled([
prisma.project.update({
diff --git a/packages/utils/src/constants/pricing.tsx b/packages/utils/src/constants/pricing.tsx
index 3e5553323b..7bb7e61852 100644
--- a/packages/utils/src/constants/pricing.tsx
+++ b/packages/utils/src/constants/pricing.tsx
@@ -10,7 +10,7 @@ export type PlanFeature = {
};
};
-export const LEGACY_PRO_PRICE_IDS = [
+const LEGACY_PRO_PRICE_IDS = [
"price_1LodNLAlJJEpqkPVQSrt33Lc", // old monthly
"price_1LodNLAlJJEpqkPVRxUyCQgZ", // old yearly
"price_1OTcQBAlJJEpqkPViGtGEsbb", // new monthly (test)
@@ -19,7 +19,15 @@ export const LEGACY_PRO_PRICE_IDS = [
"price_1OYJeBAlJJEpqkPVnPGEZeb0", // new yearly (prod)
];
-export const LEGACY_BUSINESS_PRICE_IDS = [
+// 2025 pricing
+const NEW_PRO_PRICE_IDS = [
+ "price_1R8XtyAlJJEpqkPV5WZ4c0jF", // yearly
+ "price_1R8XtEAlJJEpqkPV4opVvVPq", // monthly
+ "price_1R8XxZAlJJEpqkPVqGi0wOqD", // yearly (test),
+ "price_1R7oeBAlJJEpqkPVh6q5q3h8", // monthly (test),
+];
+
+const LEGACY_BUSINESS_PRICE_IDS = [
"price_1LodLoAlJJEpqkPV9rD0rlNL", // old monthly
"price_1LodLoAlJJEpqkPVJdwv5zrG", // oldest yearly
"price_1OZgmnAlJJEpqkPVOj4kV64R", // old yearly
@@ -29,9 +37,12 @@ export const LEGACY_BUSINESS_PRICE_IDS = [
"price_1OzOXMAlJJEpqkPV9ERrjjbw", // new yearly (prod)
];
-export const LEGACY_PRICE_IDS = [
- ...LEGACY_PRO_PRICE_IDS,
- ...LEGACY_BUSINESS_PRICE_IDS,
+// 2025 pricing
+export const NEW_BUSINESS_PRICE_IDS = [
+ "price_1R3j01AlJJEpqkPVXuG1eNzm", // yearly
+ "price_1R6JedAlJJEpqkPVMUkfjch4", // monthly
+ "price_1R8XypAlJJEpqkPVdjzOcYUC", // yearly (test),
+ "price_1R7ofLAlJJEpqkPV3MlgDpyx", // monthly (test),
];
export const PLANS = [
@@ -61,14 +72,7 @@ export const PLANS = [
price: {
monthly: 30,
yearly: 25,
- ids: [
- ...LEGACY_PRO_PRICE_IDS,
- // 2025 pricing
- "price_1R8XtyAlJJEpqkPV5WZ4c0jF", // yearly
- "price_1R8XtEAlJJEpqkPV4opVvVPq", // monthly
- "price_1R8XxZAlJJEpqkPVqGi0wOqD", // yearly (test),
- "price_1R7oeBAlJJEpqkPVh6q5q3h8", // monthly (test),
- ],
+ ids: [...LEGACY_PRO_PRICE_IDS, ...NEW_PRO_PRICE_IDS],
},
limits: {
links: 1_000,
@@ -142,14 +146,7 @@ export const PLANS = [
price: {
monthly: 90,
yearly: 75,
- ids: [
- ...LEGACY_BUSINESS_PRICE_IDS,
- // 2025 pricing
- "price_1R3j01AlJJEpqkPVXuG1eNzm", // yearly
- "price_1R6JedAlJJEpqkPVMUkfjch4", // monthly
- "price_1R8XypAlJJEpqkPVdjzOcYUC", // yearly (test),
- "price_1R7ofLAlJJEpqkPV3MlgDpyx", // monthly (test),
- ],
+ ids: [...LEGACY_BUSINESS_PRICE_IDS, ...NEW_BUSINESS_PRICE_IDS],
},
limits: {
links: 10_000,