kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: WIP stripe billing refactor update for 2025
rodzic
78d8e13250
commit
7bc65beba4
|
@ -15,7 +15,8 @@ import { parseZodSchema } from '@/lib/utils'
|
||||||
import { consumerIdParamsSchema } from './schemas'
|
import { consumerIdParamsSchema } from './schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: "Updates a consumer's subscription to a project.",
|
description:
|
||||||
|
"Updates a consumer's subscription to a different deployment or pricing plan.",
|
||||||
tags: ['consumers'],
|
tags: ['consumers'],
|
||||||
operationId: 'updateConsumer',
|
operationId: 'updateConsumer',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
|
|
|
@ -60,9 +60,9 @@ export function registerV1ProjectsCreateProject(
|
||||||
.insert(schema.projects)
|
.insert(schema.projects)
|
||||||
.values({
|
.values({
|
||||||
...body,
|
...body,
|
||||||
|
id,
|
||||||
teamId: teamMember?.teamId,
|
teamId: teamMember?.teamId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
id,
|
|
||||||
_secret: sha256(),
|
_secret: sha256(),
|
||||||
_providerToken: createProviderToken({ id })
|
_providerToken: createProviderToken({ id })
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import type { AuthenticatedEnv } from '@/lib/types'
|
import type { AuthenticatedEnv } from '@/lib/types'
|
||||||
import { db, eq, schema } from '@/db'
|
import { db, eq, schema } from '@/db'
|
||||||
|
import { acl } from '@/lib/acl'
|
||||||
import {
|
import {
|
||||||
openapiAuthenticatedSecuritySchemas,
|
openapiAuthenticatedSecuritySchemas,
|
||||||
openapiErrorResponse404,
|
openapiErrorResponse404,
|
||||||
|
@ -50,7 +51,15 @@ export function registerV1ProjectsUpdateProject(
|
||||||
const { projectId } = c.req.valid('param')
|
const { projectId } = c.req.valid('param')
|
||||||
const body = c.req.valid('json')
|
const body = c.req.valid('json')
|
||||||
|
|
||||||
const [project] = await db
|
// First ensure the project exists and the user has access to it
|
||||||
|
let project = await db.query.projects.findFirst({
|
||||||
|
where: eq(schema.projects.id, projectId)
|
||||||
|
})
|
||||||
|
assert(project, 404, `Project not found "${projectId}"`)
|
||||||
|
await acl(c, project, { label: 'Project' })
|
||||||
|
|
||||||
|
// Update the project
|
||||||
|
;[project] = await db
|
||||||
.update(schema.projects)
|
.update(schema.projects)
|
||||||
.set(body)
|
.set(body)
|
||||||
.where(eq(schema.projects.id, projectId))
|
.where(eq(schema.projects.id, projectId))
|
||||||
|
|
|
@ -78,7 +78,7 @@ export function registerV1TeamsMembersCreateTeamMember(
|
||||||
})
|
})
|
||||||
assert(
|
assert(
|
||||||
teamMember,
|
teamMember,
|
||||||
400,
|
500,
|
||||||
`Failed to create team member "${body.userId}"for team "${teamSlug}"`
|
`Failed to create team member "${body.userId}"for team "${teamSlug}"`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ export function registerV1TeamsMembersDeleteTeamMember(
|
||||||
.returning()
|
.returning()
|
||||||
assert(
|
assert(
|
||||||
teamMember,
|
teamMember,
|
||||||
404,
|
400,
|
||||||
`Failed to update team member "${userId}" for team "${teamSlug}"`
|
`Failed to update team member "${userId}" for team "${teamSlug}"`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ export async function upsertConsumer(
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
assert(consumerId || deploymentId, 400, 'Missing required "deploymentId"')
|
assert(consumerId || deploymentId, 400, 'Missing required "deploymentId"')
|
||||||
|
const logger = c.get('logger')
|
||||||
const userId = c.get('userId')
|
const userId = c.get('userId')
|
||||||
let projectId: string | undefined
|
let projectId: string | undefined
|
||||||
|
|
||||||
|
@ -147,7 +148,6 @@ export async function upsertConsumer(
|
||||||
// consumer._stripeAccount = project._stripeAccount
|
// consumer._stripeAccount = project._stripeAccount
|
||||||
await upsertStripeConnectCustomer({ stripeCustomer, consumer, project })
|
await upsertStripeConnectCustomer({ stripeCustomer, consumer, project })
|
||||||
|
|
||||||
const logger = c.get('logger')
|
|
||||||
logger.info('SUBSCRIPTION', existingConsumer ? 'UPDATE' : 'CREATE', {
|
logger.info('SUBSCRIPTION', existingConsumer ? 'UPDATE' : 'CREATE', {
|
||||||
project,
|
project,
|
||||||
deployment,
|
deployment,
|
||||||
|
|
|
@ -18,6 +18,6 @@ export async function ensureUniqueTeamSlug(slug: string) {
|
||||||
assert(
|
assert(
|
||||||
!existingUser && !existingTeam,
|
!existingUser && !existingTeam,
|
||||||
409,
|
409,
|
||||||
`Team slug [${slug}] is not available`
|
`Team slug "${slug}" is not available`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue