diff options
| author | Frank <[email protected]> | 2025-10-03 07:45:35 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-10-03 08:25:51 -0400 |
| commit | 1d58b5548287a3e32ffce3abdcf0f2db08fdb155 (patch) | |
| tree | e10c8d44e48fd6d1d2ed980c12e8008885a0c8ef /packages/console/core/src | |
| parent | aae387f7dccc6b31386592380318b2fefe27bf92 (diff) | |
| download | opencode-1d58b5548287a3e32ffce3abdcf0f2db08fdb155.tar.gz opencode-1d58b5548287a3e32ffce3abdcf0f2db08fdb155.zip | |
wip: zen
Diffstat (limited to 'packages/console/core/src')
| -rw-r--r-- | packages/console/core/src/billing.ts | 16 | ||||
| -rw-r--r-- | packages/console/core/src/user.ts | 13 |
2 files changed, 16 insertions, 13 deletions
diff --git a/packages/console/core/src/billing.ts b/packages/console/core/src/billing.ts index 34c18668e..e79e455bc 100644 --- a/packages/console/core/src/billing.ts +++ b/packages/console/core/src/billing.ts @@ -7,8 +7,7 @@ import { z } from "zod" import { Resource } from "@opencode/console-resource" import { Identifier } from "./identifier" import { centsToMicroCents } from "./util/price" -import { UserTable } from "./schema/user.sql" -import { AccountTable } from "./schema/account.sql" +import { User } from "./user" export namespace Billing { export const CHARGE_NAME = "opencode credits" @@ -172,16 +171,7 @@ export namespace Billing { const user = Actor.assert("user") const { successUrl, cancelUrl } = input - const email = await Database.use((tx) => - tx - .select({ - email: AccountTable.email, - }) - .from(UserTable) - .innerJoin(AccountTable, eq(UserTable.accountID, AccountTable.id)) - .where(and(eq(UserTable.id, user.properties.userID), eq(UserTable.workspaceID, Actor.workspace()))) - .then((rows) => rows[0]?.email), - ) + const email = await User.getAccountEmail(user.properties.userID) const customer = await Billing.get() const session = await Billing.stripe().checkout.sessions.create({ mode: "payment", @@ -216,7 +206,7 @@ export namespace Billing { }, } : { - customer_email: email, + customer_email: email!, customer_creation: "always", }), currency: "usd", diff --git a/packages/console/core/src/user.ts b/packages/console/core/src/user.ts index 8f00722e6..23612de5e 100644 --- a/packages/console/core/src/user.ts +++ b/packages/console/core/src/user.ts @@ -50,6 +50,19 @@ export namespace User { ), ) + export const getAccountEmail = fn(z.string(), (id) => + Database.use((tx) => + tx + .select({ + email: AccountTable.email, + }) + .from(UserTable) + .leftJoin(AccountTable, eq(UserTable.accountID, AccountTable.id)) + .where(and(eq(UserTable.workspaceID, Actor.workspace()), eq(UserTable.id, id))) + .then((rows) => rows[0]?.email), + ), + ) + export const invite = fn( z.object({ email: z.string(), |
