summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFrank <[email protected]>2026-01-13 19:46:14 -0500
committerFrank <[email protected]>2026-01-13 19:46:14 -0500
commit82319bbd836762ac485f911409267d004b1599b9 (patch)
tree1a8f9f543de27092cfe3ef41dc933c2fade85c4d
parent45fa4eda15f3a066618357e0832b290405a395ca (diff)
downloadopencode-82319bbd836762ac485f911409267d004b1599b9.tar.gz
opencode-82319bbd836762ac485f911409267d004b1599b9.zip
wip: black
-rw-r--r--packages/console/app/src/routes/black/subscribe/[plan].tsx44
1 files 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 (
<div data-slot="failure">
- <p data-slot="title">Uh oh, something went wrong</p>
- <p data-slot="message">{props.message}</p>
+ <p data-slot="message">Uh oh! {props.message}</p>
</div>
)
}
@@ -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