diff --git a/apps/sim/lib/auth/auth.ts b/apps/sim/lib/auth/auth.ts index 3e375dc2ef2..dfabd8f1733 100644 --- a/apps/sim/lib/auth/auth.ts +++ b/apps/sim/lib/auth/auth.ts @@ -80,6 +80,7 @@ import { isSsoCallbackPath, resolveSsoCallbackProviderId } from '@/lib/auth/sso/ import { configuredSsoPlugin } from '@/lib/auth/sso/plugin' import { assertPersonalCheckoutAllowed, + assertSelfServeCheckoutPlan, authorizeSubscriptionReference, isPersonalCheckoutRequest, } from '@/lib/billing/authorization' @@ -1212,6 +1213,7 @@ export const auth = betterAuth({ const sessionUserId = session?.user?.id if (sessionUserId) { const requestBody = ctx.body ?? {} + assertSelfServeCheckoutPlan(requestBody.plan) const referenceId = resolveCheckoutReferenceId( requestBody, sessionUserId, diff --git a/apps/sim/lib/billing/authorization.test.ts b/apps/sim/lib/billing/authorization.test.ts index 7dc0f996c93..de98327b61d 100644 --- a/apps/sim/lib/billing/authorization.test.ts +++ b/apps/sim/lib/billing/authorization.test.ts @@ -32,6 +32,7 @@ vi.mock('@/lib/billing/enterprise-outbox', () => { import { assertPersonalCheckoutAllowed, + assertSelfServeCheckoutPlan, authorizeSubscriptionReference, isPersonalCheckoutRequest, } from '@/lib/billing/authorization' @@ -115,6 +116,19 @@ describe('authorizeSubscriptionReference', () => { }) }) +describe('assertSelfServeCheckoutPlan', () => { + it('refuses a self-serve Enterprise checkout with a client error', () => { + expect(() => assertSelfServeCheckoutPlan('enterprise')).toThrow( + expect.objectContaining({ statusCode: 400 }) + ) + }) + + it('admits self-serve Pro and Team checkouts', () => { + expect(() => assertSelfServeCheckoutPlan('pro_6000')).not.toThrow() + expect(() => assertSelfServeCheckoutPlan('team_25000')).not.toThrow() + }) +}) + describe('assertPersonalCheckoutAllowed', () => { beforeEach(() => { mockGetOrganizationCoverageForMember.mockResolvedValue({ status: 'not-covered' }) diff --git a/apps/sim/lib/billing/authorization.ts b/apps/sim/lib/billing/authorization.ts index 3a255e09d2c..472a453a099 100644 --- a/apps/sim/lib/billing/authorization.ts +++ b/apps/sim/lib/billing/authorization.ts @@ -14,7 +14,7 @@ import { assertNoUnresolvedEnterpriseIssuance, EnterpriseIssuanceInProgressError, } from '@/lib/billing/enterprise-outbox' -import { isOrgPlan, isPro } from '@/lib/billing/plan-helpers' +import { isEnterprise, isOrgPlan, isPro } from '@/lib/billing/plan-helpers' import { isOrgScopedSubscription } from '@/lib/billing/subscriptions/utils' const logger = createLogger('BillingAuthorization') @@ -74,6 +74,19 @@ async function assertNotBilledThroughMarketplace(referenceId: string): Promise { const trialing = await db