GeezerVison is showing github.com — wip: cloud · josephschmitt/opencode@4e629c5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: cloud/app/src/routes/gateway/v1/chat/completions.ts +264-535Lines changed: 264 additions & 535 deletions Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: cloud/app/src/routes/stripe/webhook.ts +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,8 +24,11 @@ export async function POST(input: APIEvent) { | 24 | 24 | if (!workspaceID) throw new Error("Workspace ID not found") | 25 | 25 | if (!customerID) throw new Error("Customer ID not found") | 26 | 26 | if (!amount) throw new Error("Amount not found") | | 27 | + if (amount !== 2118) throw new Error("Amount mismatch") | 27 | 28 | if (!paymentID) throw new Error("Payment ID not found") | 28 | 29 |
| | 30 | + const chargedAmount = 2000 | | 31 | + | 29 | 32 | await Actor.provide("system", { workspaceID }, async () => { | 30 | 33 | const customer = await Billing.get() | 31 | 34 | if (customer?.customerID && customer.customerID !== customerID) throw new Error("Customer ID mismatch") | @@ -50,7 +53,7 @@ export async function POST(input: APIEvent) { | 50 | 53 | await tx | 51 | 54 | .update(BillingTable) | 52 | 55 | .set({ | 53 | | - balance: sql`${BillingTable.balance} + ${centsToMicroCents(amount)}`, | | 56 | + balance: sql`${BillingTable.balance} + ${centsToMicroCents(chargedAmount)}`, | 54 | 57 | customerID, | 55 | 58 | paymentMethodID: paymentMethod.id, | 56 | 59 | paymentMethodLast4: paymentMethod.card!.last4, | @@ -59,7 +62,7 @@ export async function POST(input: APIEvent) { | 59 | 62 | await tx.insert(PaymentTable).values({ | 60 | 63 | workspaceID, | 61 | 64 | id: Identifier.create("payment"), | 62 | | - amount: centsToMicroCents(amount), | | 65 | + amount: centsToMicroCents(chargedAmount), | 63 | 66 | paymentID, | 64 | 67 | customerID, | 65 | 68 | }) | |
Collapse file Copy file name to clipboardExpand all lines: cloud/core/src/billing.ts +1-38Lines changed: 1 addition & 38 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,43 +52,6 @@ export namespace Billing { | 52 | 52 | ) | 53 | 53 | } | 54 | 54 |
| 55 | | - export const consume = fn( | 56 | | - z.object({ | 57 | | - requestID: z.string().optional(), | 58 | | - model: z.string(), | 59 | | - inputTokens: z.number(), | 60 | | - outputTokens: z.number(), | 61 | | - reasoningTokens: z.number().optional(), | 62 | | - cacheReadTokens: z.number().optional(), | 63 | | - cacheWriteTokens: z.number().optional(), | 64 | | - costInCents: z.number(), | 65 | | - }), | 66 | | - async (input) => { | 67 | | - const workspaceID = Actor.workspace() | 68 | | - const cost = centsToMicroCents(input.costInCents) | 69 | | - | 70 | | - return await Database.transaction(async (tx) => { | 71 | | - await tx.insert(UsageTable).values({ | 72 | | - workspaceID, | 73 | | - id: Identifier.create("usage"), | 74 | | - model: input.model, | 75 | | - inputTokens: input.inputTokens, | 76 | | - outputTokens: input.outputTokens, | 77 | | - reasoningTokens: input.reasoningTokens, | 78 | | - cacheReadTokens: input.cacheReadTokens, | 79 | | - cacheWriteTokens: input.cacheWriteTokens, | 80 | | - cost, | 81 | | - }) | 82 | | - await tx | 83 | | - .update(BillingTable) | 84 | | - .set({ | 85 | | - balance: sql`${BillingTable.balance} - ${cost}`, | 86 | | - }) | 87 | | - .where(eq(BillingTable.workspaceID, workspaceID)) | 88 | | - }) | 89 | | - }, | 90 | | - ) | 91 | | - | 92 | 55 | export const generateCheckoutUrl = fn( | 93 | 56 | z.object({ | 94 | 57 | successUrl: z.string(), | @@ -109,7 +72,7 @@ export namespace Billing { | 109 | 72 | product_data: { | 110 | 73 | name: "opencode credits", | 111 | 74 | }, | 112 | | - unit_amount: 2000, // $20 minimum | | 75 | + unit_amount: 2118, // $20 minimum + Stripe fee 4.4% + $0.30 | 113 | 76 | }, | 114 | 77 | quantity: 1, | 115 | 78 | }, | |
Collapse file Copy file name to clipboardExpand all lines: cloud/core/src/workspace.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,7 @@ export namespace Workspace { | 26 | 26 | await tx.insert(BillingTable).values({ | 27 | 27 | workspaceID, | 28 | 28 | id: Identifier.create("billing"), | 29 | | - balance: centsToMicroCents(100), | | 29 | + balance: 0, | 30 | 30 | }) | 31 | 31 | }) | 32 | 32 | await Actor.provide( | |
|