Skip to content

Commit 60e2164

Browse files
author
Frank
committed
wip: zen
1 parent 600b512 commit 60e2164

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

packages/console/core/src/billing.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Stripe } from "stripe"
2-
import { Database, eq, sql } from "./drizzle"
2+
import { and, Database, eq, sql } from "./drizzle"
33
import { BillingTable, PaymentTable, UsageTable } from "./schema/billing.sql"
44
import { Actor } from "./actor"
55
import { fn } from "./util/fn"
66
import { z } from "zod"
7-
import { User } from "./user"
87
import { Resource } from "@opencode/console-resource"
98
import { Identifier } from "./identifier"
109
import { centsToMicroCents } from "./util/price"
10+
import { UserTable } from "./schema/user.sql"
11+
import { AccountTable } from "./schema/account.sql"
1112

1213
export namespace Billing {
1314
export const CHARGE_NAME = "opencode credits"
@@ -168,10 +169,19 @@ export namespace Billing {
168169
cancelUrl: z.string(),
169170
}),
170171
async (input) => {
171-
const account = Actor.assert("user")
172+
const user = Actor.assert("user")
172173
const { successUrl, cancelUrl } = input
173174

174-
const user = await User.fromID(account.properties.userID)
175+
const email = await Database.use((tx) =>
176+
tx
177+
.select({
178+
email: AccountTable.email,
179+
})
180+
.from(UserTable)
181+
.innerJoin(AccountTable, eq(UserTable.accountID, AccountTable.id))
182+
.where(and(eq(UserTable.id, user.properties.userID), eq(UserTable.workspaceID, Actor.workspace())))
183+
.then((rows) => rows[0]?.email),
184+
)
175185
const customer = await Billing.get()
176186
const session = await Billing.stripe().checkout.sessions.create({
177187
mode: "payment",
@@ -206,7 +216,7 @@ export namespace Billing {
206216
},
207217
}
208218
: {
209-
customer_email: user.email!,
219+
customer_email: email,
210220
customer_creation: "always",
211221
}),
212222
currency: "usd",

0 commit comments

Comments
 (0)