wip: black

This commit is contained in:
Frank
2026-01-08 23:44:11 -05:00
parent 8b062ed621
commit dd5ec26c8c
9 changed files with 2632 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
import { Billing } from "@opencode-ai/console-core/billing.js" import { Billing } from "@opencode-ai/console-core/billing.js"
import { query, action, useParams, createAsync, useAction } from "@solidjs/router" import { query, action, useParams, createAsync, useAction } from "@solidjs/router"
import { For, Show } from "solid-js" import { For, Match, Show, Switch } from "solid-js"
import { withActor } from "~/context/auth.withActor" import { withActor } from "~/context/auth.withActor"
import { formatDateUTC, formatDateForTable } from "../../common" import { formatDateUTC, formatDateForTable } from "../../common"
import styles from "./payment-section.module.css" import styles from "./payment-section.module.css"
@@ -77,7 +77,8 @@ export function PaymentSection() {
<For each={payments()!}> <For each={payments()!}>
{(payment) => { {(payment) => {
const date = new Date(payment.timeCreated) const date = new Date(payment.timeCreated)
const isCredit = !payment.paymentID const amount =
payment.enrichment?.type === "subscription" && payment.enrichment.couponID ? 0 : payment.amount
return ( return (
<tr> <tr>
<td data-slot="payment-date" title={formatDateUTC(date)}> <td data-slot="payment-date" title={formatDateUTC(date)}>
@@ -85,13 +86,14 @@ export function PaymentSection() {
</td> </td>
<td data-slot="payment-id">{payment.id}</td> <td data-slot="payment-id">{payment.id}</td>
<td data-slot="payment-amount" data-refunded={!!payment.timeRefunded}> <td data-slot="payment-amount" data-refunded={!!payment.timeRefunded}>
${((payment.amount ?? 0) / 100000000).toFixed(2)} ${((amount ?? 0) / 100000000).toFixed(2)}
{isCredit ? " (credit)" : ""} <Switch>
<Match when={payment.enrichment?.type === "credit"}> (credit)</Match>
<Match when={payment.enrichment?.type === "subscription"}> (subscription)</Match>
</Switch>
</td> </td>
<td data-slot="payment-receipt"> <td data-slot="payment-receipt">
{isCredit ? ( {payment.paymentID ? (
<span>-</span>
) : (
<button <button
onClick={async () => { onClick={async () => {
const receiptUrl = await downloadReceiptAction(params.id!, payment.paymentID!) const receiptUrl = await downloadReceiptAction(params.id!, payment.paymentID!)
@@ -103,6 +105,8 @@ export function PaymentSection() {
> >
View View
</button> </button>
) : (
<span>-</span>
)} )}
</td> </td>
</tr> </tr>

View File

@@ -0,0 +1 @@
ALTER TABLE `billing` ADD `subscription_coupon_id` varchar(28);

View File

@@ -0,0 +1 @@
ALTER TABLE `payment` ADD `enrichment` json;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -344,6 +344,20 @@
"when": 1767917785224, "when": 1767917785224,
"tag": "0048_mean_frank_castle", "tag": "0048_mean_frank_castle",
"breakpoints": true "breakpoints": true
},
{
"idx": 49,
"version": "5",
"when": 1767922954153,
"tag": "0049_noisy_domino",
"breakpoints": true
},
{
"idx": 50,
"version": "5",
"when": 1767931290031,
"tag": "0050_bumpy_mephistopheles",
"breakpoints": true
} }
] ]
} }

View File

@@ -39,6 +39,9 @@ if (amountInCents !== 20000) {
process.exit(1) process.exit(1)
} }
const subscriptionData = await Billing.stripe().subscriptions.retrieve(subscription.id, { expand: ["discounts"] })
const couponID = subscriptionData.discounts[0]?.coupon?.id
// Check if subscription is already tied to another workspace // Check if subscription is already tied to another workspace
const existingSubscription = await Database.use((tx) => const existingSubscription = await Database.use((tx) =>
tx tx
@@ -122,6 +125,7 @@ await Database.transaction(async (tx) => {
.set({ .set({
customerID, customerID,
subscriptionID, subscriptionID,
subscriptionCouponID: couponID,
paymentMethodID, paymentMethodID,
paymentMethodLast4, paymentMethodLast4,
paymentMethodType, paymentMethodType,
@@ -143,6 +147,10 @@ await Database.transaction(async (tx) => {
customerID, customerID,
invoiceID, invoiceID,
paymentID, paymentID,
enrichment: {
type: "subscription",
couponID,
},
}) })
}) })

View File

@@ -171,6 +171,9 @@ export namespace Billing {
workspaceID, workspaceID,
id: Identifier.create("payment"), id: Identifier.create("payment"),
amount: amountInMicroCents, amount: amountInMicroCents,
enrichment: {
type: "credit",
},
}) })
}) })
return amountInMicroCents return amountInMicroCents

View File

@@ -22,6 +22,7 @@ export const BillingTable = mysqlTable(
timeReloadError: utc("time_reload_error"), timeReloadError: utc("time_reload_error"),
timeReloadLockedTill: utc("time_reload_locked_till"), timeReloadLockedTill: utc("time_reload_locked_till"),
subscriptionID: varchar("subscription_id", { length: 28 }), subscriptionID: varchar("subscription_id", { length: 28 }),
subscriptionCouponID: varchar("subscription_coupon_id", { length: 28 }),
}, },
(table) => [ (table) => [
...workspaceIndexes(table), ...workspaceIndexes(table),
@@ -54,6 +55,15 @@ export const PaymentTable = mysqlTable(
paymentID: varchar("payment_id", { length: 255 }), paymentID: varchar("payment_id", { length: 255 }),
amount: bigint("amount", { mode: "number" }).notNull(), amount: bigint("amount", { mode: "number" }).notNull(),
timeRefunded: utc("time_refunded"), timeRefunded: utc("time_refunded"),
enrichment: json("enrichment").$type<
| {
type: "subscription"
couponID?: string
}
| {
type: "credit"
}
>(),
}, },
(table) => [...workspaceIndexes(table)], (table) => [...workspaceIndexes(table)],
) )