fix(billing): reset usage on transition from free -> paid plan (#1397)

* fix(billing): reset usage on transition from free -> paid plan

* fixes: pro->team upgrade logic, single org server side check on invite routes

* ui improvements

* cleanup team-members code

* minor renaming

* progress

* fix pro->team upgrade to prevent double billing

* add subscription delete case handler

---------

Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
This commit is contained in:
Waleed
2025-09-22 13:58:29 -07:00
committed by GitHub
co-authored by Vikhyath Mondreti
parent aa01e7e58a
commit 8eaa83fe21
20 changed files with 7886 additions and 152 deletions
@@ -0,0 +1 @@
ALTER TABLE "user_stats" ADD COLUMN "pro_period_cost_snapshot" numeric DEFAULT '0';
File diff suppressed because it is too large Load Diff
@@ -631,6 +631,13 @@
"when": 1757805452908,
"tag": "0090_fearless_zaladane",
"breakpoints": true
},
{
"idx": 91,
"version": "7",
"when": 1758567567287,
"tag": "0091_amusing_iron_lad",
"breakpoints": true
}
]
}
+2
View File
@@ -565,6 +565,8 @@ export const userStats = pgTable('user_stats', {
// Billing period tracking
currentPeriodCost: decimal('current_period_cost').notNull().default('0'), // Usage in current billing period
lastPeriodCost: decimal('last_period_cost').default('0'), // Usage from previous billing period
// Pro usage snapshot when joining a team (to prevent double-billing)
proPeriodCostSnapshot: decimal('pro_period_cost_snapshot').default('0'), // Snapshot of Pro usage when joining team
// Copilot usage tracking
totalCopilotCost: decimal('total_copilot_cost').notNull().default('0'),
totalCopilotTokens: integer('total_copilot_tokens').notNull().default(0),