diff options
| author | Frank <[email protected]> | 2026-01-25 17:46:14 -0500 |
|---|---|---|
| committer | Frank <[email protected]> | 2026-01-25 17:46:18 -0500 |
| commit | 57532326f7b3526348b14e82bb61ecd41ac7d480 (patch) | |
| tree | 94c06cca929cd6009d7d66d8189b9bb0b2dcc045 /packages/console/core/src | |
| parent | 045c30acf34b48cfc6f12b77b61995560fbddead (diff) | |
| download | opencode-57532326f7b3526348b14e82bb61ecd41ac7d480.tar.gz opencode-57532326f7b3526348b14e82bb61ecd41ac7d480.zip | |
zen: handle subscription payment failure
Diffstat (limited to 'packages/console/core/src')
| -rw-r--r-- | packages/console/core/src/billing.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/console/core/src/billing.ts b/packages/console/core/src/billing.ts index 44f12db9e..2c1cdb068 100644 --- a/packages/console/core/src/billing.ts +++ b/packages/console/core/src/billing.ts @@ -335,4 +335,29 @@ export namespace Billing { return subscription.id }, ) + + export const unsubscribe = fn( + z.object({ + subscriptionID: z.string(), + }), + async ({ subscriptionID }) => { + const workspaceID = await Database.use((tx) => + tx + .select({ workspaceID: BillingTable.workspaceID }) + .from(BillingTable) + .where(eq(BillingTable.subscriptionID, subscriptionID)) + .then((rows) => rows[0]?.workspaceID), + ) + if (!workspaceID) throw new Error("Workspace ID not found for subscription") + + await Database.transaction(async (tx) => { + await tx + .update(BillingTable) + .set({ subscriptionID: null, subscription: null }) + .where(eq(BillingTable.workspaceID, workspaceID)) + + await tx.delete(SubscriptionTable).where(eq(SubscriptionTable.workspaceID, workspaceID)) + }) + }, + ) } |
