Skip to content

Commit a6f9ba1

Browse files
committed
Don't default to a tier when creating a subscription
1 parent 8eafcfb commit a6f9ba1

File tree

2 files changed

+11
-7
lines changed
  • web/src/app/api/stripe

2 files changed

+11
-7
lines changed

web/src/app/api/stripe/change-subscription-tier/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function POST(req: NextRequest) {
4444
const rawTier = Number(body?.tier)
4545
if (!rawTier || !(rawTier in SUBSCRIPTION_TIERS)) {
4646
return NextResponse.json(
47-
{ error: 'Invalid tier. Must be 100, 200, or 500.' },
47+
{ error: `Invalid tier. Must be one of: ${Object.keys(SUBSCRIPTION_TIERS).join(', ')}.` },
4848
{ status: 400 },
4949
)
5050
}

web/src/app/api/stripe/create-subscription/route.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ export async function POST(req: NextRequest) {
2222

2323
const userId = session.user.id
2424

25-
const body = await req.json().catch(() => ({}))
26-
const rawTier = Number(body.tier)
27-
const tier = (rawTier && rawTier in SUBSCRIPTION_TIERS
28-
? rawTier
29-
: 200) as SubscriptionTierPrice
25+
const body = await req.json().catch(() => null)
26+
const rawTier = Number(body?.tier)
27+
if (!rawTier || !(rawTier in SUBSCRIPTION_TIERS)) {
28+
return NextResponse.json(
29+
{ error: `Invalid tier. Must be one of: ${Object.keys(SUBSCRIPTION_TIERS).join(', ')}.` },
30+
{ status: 400 },
31+
)
32+
}
33+
const tier = rawTier as SubscriptionTierPrice
3034

3135
const priceId = getPriceIdFromTier(tier)
3236
if (!priceId) {
@@ -77,7 +81,7 @@ export async function POST(req: NextRequest) {
7781
type: 'strong_subscription',
7882
},
7983
subscription_data: {
80-
description: `Codebuff Strong — $${tier}/mo unlimited coding sessions`,
84+
description: `Codebuff Strong — $${tier}/mo`,
8185
metadata: {
8286
userId,
8387
},

0 commit comments

Comments
 (0)