Skip to content

Commit 557ff88

Browse files
improve plan update
1 parent 3c00765 commit 557ff88

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

packages/api/src/router/stripe/webhook.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
workspace,
1414
} from "@openstatus/db/src/schema";
1515

16-
import type { addons } from "@openstatus/db/src/schema/plan/schema";
1716
import {
1817
getLimits,
1918
updateAddonInLimits,
@@ -66,39 +65,18 @@ export const webhookRouter = createTRPCRouter({
6665
const oldPlan = ws.plan;
6766

6867
let detectedPlan: ReturnType<typeof getPlanFromPriceId> = undefined;
69-
const detectedFeatures: Array<{ feature: (typeof addons)[number] }> = [];
7068

7169
for (const item of subscription.items.data) {
7270
const plan = getPlanFromPriceId(item.price.id);
7371
if (plan) {
7472
detectedPlan = plan;
75-
continue;
73+
break;
7674
}
77-
78-
const feature = getFeatureFromPriceId(item.price.id);
79-
if (feature) {
80-
detectedFeatures.push(feature);
81-
continue;
82-
}
83-
84-
console.warn(`Unknown price ID in subscription: ${item.price.id}`);
8575
}
8676

87-
let finalLimits = detectedPlan
77+
const finalLimits = detectedPlan
8878
? getLimits(detectedPlan.plan)
89-
: { ...ws.limits };
90-
91-
for (const feature of detectedFeatures) {
92-
const currentValue = finalLimits[feature.feature];
93-
const newValue =
94-
typeof currentValue === "boolean"
95-
? true
96-
: typeof currentValue === "number"
97-
? currentValue + 1
98-
: currentValue;
99-
100-
finalLimits = updateAddonInLimits(finalLimits, feature.feature, newValue);
101-
}
79+
: ws.limits;
10280

10381
await opts.ctx.db
10482
.update(workspace)

0 commit comments

Comments
 (0)