Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
75a228f
Initial backend impl
jahooma Jan 28, 2026
00af124
Review fixes
jahooma Jan 28, 2026
8e31469
Plans to tiered subscription. Don't store plan name/tier in db
jahooma Jan 28, 2026
66463e9
Extract getUserByStripeCustomerId helper
jahooma Jan 28, 2026
b807cfa
migrateUnusedCredits: remove filter on free/referral
jahooma Jan 28, 2026
8976298
Add .env.example for stripe price id
jahooma Jan 28, 2026
ed2a1d9
Remove subscription_count. Add more stripe status enums
jahooma Jan 28, 2026
31db66e
cleanup
jahooma Jan 28, 2026
458616a
Generate migration
jahooma Jan 28, 2026
c39155b
More reviewer improvments
jahooma Jan 28, 2026
cba210d
Update migrateUnusedCredits query
jahooma Jan 28, 2026
40a0b2e
Rename Flex to Strong
jahooma Jan 28, 2026
76f71c4
Add subscription tiers. Extract util getStripeId
jahooma Jan 28, 2026
9184aa2
Web routes to cancel, change tier, create subscription, or get subscr…
jahooma Jan 28, 2026
3f81504
Web subscription UI
jahooma Jan 28, 2026
5e9b314
Fix billing test to mock subscription endpoint
jahooma Jan 28, 2026
7f5e135
Remove subscription client UI (moved to subscription-client branch)
jahooma Jan 28, 2026
7059836
Add subscription grant type to usage-display for typecheck compatibility
jahooma Jan 28, 2026
1509a09
Update tier usage limits (1x, 3x, 8x)
jahooma Jan 29, 2026
1b1176c
Fixes from reviewer
jahooma Jan 29, 2026
f95faaa
Cleanup tier mapping code
jahooma Jan 29, 2026
f114adf
Tweaks and don't downgrade tier immediately if switch plans
jahooma Jan 29, 2026
8eafcfb
scheduled_tier used for downgrade
jahooma Jan 29, 2026
a6f9ba1
Don't default to a tier when creating a subscription
jahooma Jan 29, 2026
40921f7
Unit subscription.ts with DI patterns and unit tests
jahooma Jan 29, 2026
1fe1966
Update description of row of migrated credits
jahooma Jan 29, 2026
4a6d7c0
Simplify getStripeId. Move null checks into callers
jahooma Jan 29, 2026
f00eeb4
Split try catch in two
jahooma Jan 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/src/constants/analytics-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export enum AnalyticsEvent {
ADVISORY_LOCK_CONTENTION = 'backend.advisory_lock_contention',
TRANSACTION_RETRY_THRESHOLD_EXCEEDED = 'backend.transaction_retry_threshold_exceeded',

// Backend - Subscription
SUBSCRIPTION_CREATED = 'backend.subscription_created',
SUBSCRIPTION_CANCELED = 'backend.subscription_canceled',
SUBSCRIPTION_PAYMENT_FAILED = 'backend.subscription_payment_failed',
SUBSCRIPTION_BLOCK_CREATED = 'backend.subscription_block_created',
SUBSCRIPTION_BLOCK_LIMIT_HIT = 'backend.subscription_block_limit_hit',
SUBSCRIPTION_WEEKLY_LIMIT_HIT = 'backend.subscription_weekly_limit_hit',
SUBSCRIPTION_CREDITS_MIGRATED = 'backend.subscription_credits_migrated',

// Web
SIGNUP = 'web.signup',

Expand Down
1 change: 1 addition & 0 deletions common/src/constants/grant-priorities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GrantType } from '@codebuff/common/types/grant'

export const GRANT_PRIORITIES: Record<GrantType, number> = {
subscription: 10,
free: 20,
referral: 30,
ad: 40,
Expand Down
26 changes: 26 additions & 0 deletions common/src/constants/subscription-plans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const PLAN_NAMES = ['pro'] as const
export type PlanName = (typeof PLAN_NAMES)[number]

export interface PlanConfig {
name: PlanName
displayName: string
monthlyPrice: number
creditsPerBlock: number
blockDurationHours: number
weeklyCreditsLimit: number
}

export const PLANS = {
pro: {
name: 'pro',
displayName: 'Pro',
monthlyPrice: 200,
creditsPerBlock: 1250,
blockDurationHours: 5,
weeklyCreditsLimit: 15000,
},
} as const satisfies Record<PlanName, PlanConfig>

export function isPlanName(name: string): name is PlanName {
return (PLAN_NAMES as readonly string[]).includes(name)
}
2 changes: 2 additions & 0 deletions common/src/types/grant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type GrantType =
| 'free'
| 'referral'
| 'subscription'
| 'purchase'
| 'admin'
| 'organization'
Expand All @@ -9,6 +10,7 @@ export type GrantType =
export const GrantTypeValues = [
'free',
'referral',
'subscription',
'purchase',
'admin',
'organization',
Expand Down
4 changes: 2 additions & 2 deletions packages/billing/src/__tests__/usage-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const mockBalance = {
totalRemaining: 1000,
totalDebt: 0,
netBalance: 1000,
breakdown: { free: 500, paid: 500, referral: 0, purchase: 0, admin: 0, organization: 0, ad: 0 },
principals: { free: 500, paid: 500, referral: 0, purchase: 0, admin: 0, organization: 0, ad: 0 },
breakdown: { free: 500, referral: 0, subscription: 0, purchase: 500, admin: 0, organization: 0, ad: 0 },
principals: { free: 500, referral: 0, subscription: 0, purchase: 500, admin: 0, organization: 0, ad: 0 },
}

describe('usage-service', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/billing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ export * from './usage-service'
// Credit delegation
export * from './credit-delegation'

// Subscription
export * from './subscription'

// Subscription webhooks
export * from './subscription-webhooks'

// Utilities
export * from './utils'
Loading