From 82319bbd836762ac485f911409267d004b1599b9 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 13 Jan 2026 19:46:14 -0500 Subject: [PATCH] wip: black --- .../app/src/routes/black/subscribe/[plan].tsx | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/packages/console/app/src/routes/black/subscribe/[plan].tsx b/packages/console/app/src/routes/black/subscribe/[plan].tsx index b78d9138d..5e13799dd 100644 --- a/packages/console/app/src/routes/black/subscribe/[plan].tsx +++ b/packages/console/app/src/routes/black/subscribe/[plan].tsx @@ -1,4 +1,4 @@ -import { A, action, createAsync, json, query, redirect, useParams } from "@solidjs/router" +import { A, createAsync, query, redirect, useParams } from "@solidjs/router" import { Title } from "@solidjs/meta" import { createEffect, createSignal, For, Match, Show, Switch } from "solid-js" import { type Stripe, type PaymentMethod, loadStripe } from "@stripe/stripe-js" @@ -35,6 +35,7 @@ const getWorkspaces = query(async () => { paymentMethodType: BillingTable.paymentMethodType, paymentMethodLast4: BillingTable.paymentMethodLast4, subscriptionID: BillingTable.subscriptionID, + timeSubscriptionBooked: BillingTable.timeSubscriptionBooked, }, }) .from(UserTable) @@ -86,6 +87,14 @@ const createSetupIntent = async (input: { plan: string; workspaceID: string }) = }, }) customerID = customer.id + await Database.use((tx) => + tx + .update(BillingTable) + .set({ + customerID, + }) + .where(eq(BillingTable.workspaceID, workspaceID)), + ) } const intent = await Billing.stripe().setupIntents.create({ @@ -135,8 +144,7 @@ interface SuccessData { function Failure(props: { message: string }) { return (
-

Uh oh, something went wrong

-

{props.message}

+

Uh oh! {props.message}

) } @@ -197,7 +205,7 @@ function IntentForm(props: { plan: PlanID; workspaceID: string; onSuccess: (data const { error: confirmError, setupIntent } = await stripe()!.confirmSetup({ elements: elements()!, confirmParams: { - expand: ["setup_intent.payment_method"], + expand: ["payment_method"], payment_method_data: { allow_redisplay: "always", }, @@ -211,6 +219,8 @@ function IntentForm(props: { plan: PlanID; workspaceID: string; onSuccess: (data return } + // TODO + console.log(setupIntent) if (setupIntent?.status === "succeeded") { const pm = setupIntent.payment_method as PaymentMethod @@ -274,7 +284,7 @@ export default function BlackSubscribe() { }) // Fetch setup intent when workspace is selected (unless workspace already has payment method) - createEffect(() => { + createEffect(async () => { const id = selectedWorkspace() if (!id) return @@ -284,6 +294,15 @@ export default function BlackSubscribe() { return } if (ws?.billing?.paymentMethodID) { + if (!ws?.billing?.timeSubscriptionBooked) { + await bookSubscription({ + workspaceID: id, + plan: planData.id, + paymentMethodID: ws.billing.paymentMethodID!, + paymentMethodType: ws.billing.paymentMethodType!, + paymentMethodLast4: ws.billing.paymentMethodLast4 ?? undefined, + }) + } setSuccess({ plan: planData.id, paymentMethodType: ws.billing.paymentMethodType!, @@ -292,15 +311,12 @@ export default function BlackSubscribe() { return } - createSetupIntent({ plan, workspaceID: id }) - .then((data) => { - if (data.error) { - setFailure(data.error) - } else if ("clientSecret" in data) { - setClientSecret(data.clientSecret) - } - }) - .catch(() => setFailure("Failed to initialize payment")) + const result = await createSetupIntent({ plan, workspaceID: id }) + if (result.error) { + setFailure(result.error) + } else if ("clientSecret" in result) { + setClientSecret(result.clientSecret) + } }) // Keyboard navigation for workspace picker