Repository navigation
fix(devpass): keep billing usable after plan ends #3445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,14 @@ export const devPlans = new OpenAPIHono<ServerTypes>(); | |
| // lease this old cannot still have an upgrade charge in flight. | ||
| const STALE_TIER_CHANGE_CLAIM_MS = 15 * 60 * 1000; | ||
|
|
||
| // Transaction types that surface as invoices on the DevPass billing page. | ||
| const DEV_PLAN_INVOICE_TYPES = [ | ||
| "dev_plan_start", | ||
| "dev_plan_renewal", | ||
| "dev_plan_upgrade", | ||
| "dev_plan_reset_pass", | ||
| ] as const; | ||
|
|
||
| // A failed release is swallowed: the lease then simply expires via the | ||
| // staleness window instead of blocking upgrades until renewal. | ||
| async function releaseTierChangeLease(organizationId: string) { | ||
|
|
@@ -1708,6 +1716,10 @@ const getStatus = createRoute({ | |
| "application/json": { | ||
| schema: z.object({ | ||
| hasPersonalOrg: z.boolean(), | ||
| // Whether the org ever produced a DevPass invoice. Stays true | ||
| // after a plan ends, so the dashboard keeps showing billing to | ||
| // past subscribers (invoices, receipts, Reset Pass refunds). | ||
| hasBillingHistory: z.boolean(), | ||
| devPlan: z.enum(["none", "lite", "pro", "max"]), | ||
| devPlanPendingTier: z.enum(["lite", "pro", "max"]).nullable(), | ||
| devPlanCycle: z.enum(["monthly", "annual"]), | ||
|
|
@@ -1773,6 +1785,7 @@ devPlans.openapi(getStatus, async (c) => { | |
| if (!personalOrg) { | ||
| return c.json({ | ||
| hasPersonalOrg: false, | ||
| hasBillingHistory: false, | ||
| devPlan: "none" as const, | ||
| devPlanPendingTier: null, | ||
| devPlanCycle: "monthly" as const, | ||
|
|
@@ -1802,6 +1815,17 @@ devPlans.openapi(getStatus, async (c) => { | |
| const creditsLimit = parseFloat(personalOrg.devPlanCreditsLimit); | ||
| const creditsRemaining = Math.max(0, creditsLimit - creditsUsed); | ||
|
|
||
| // Ending a dev plan clears every devPlan* column on the org, so the billing | ||
| // transactions are the only lasting record that the user was ever a | ||
| // subscriber — and the dashboard needs it to keep the billing page reachable. | ||
| const billingTransaction = await db.query.transaction.findFirst({ | ||
| where: { | ||
| organizationId: { eq: personalOrg.id }, | ||
| type: { in: [...DEV_PLAN_INVOICE_TYPES] }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 1b846c8 — good catch. |
||
| }, | ||
| columns: { id: true }, | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| // Weekly premium fair-use allowance, computed with the same helpers the | ||
| // gateway uses for enforcement. An expired window reports zero usage and no | ||
| // reset date — the full allowance is already available again. | ||
|
|
@@ -1856,6 +1880,7 @@ devPlans.openapi(getStatus, async (c) => { | |
|
|
||
| return c.json({ | ||
| hasPersonalOrg: true, | ||
| hasBillingHistory: Boolean(billingTransaction), | ||
| devPlan: personalOrg.devPlan, | ||
| devPlanPendingTier: personalOrg.devPlanPendingTier, | ||
| devPlanCycle: personalOrg.devPlanCycle, | ||
|
|
@@ -2329,12 +2354,7 @@ devPlans.openapi(getInvoices, async (c) => { | |
|
|
||
| const invoices = transactions | ||
| .filter((t) => | ||
| [ | ||
| "dev_plan_start", | ||
| "dev_plan_renewal", | ||
| "dev_plan_upgrade", | ||
| "dev_plan_reset_pass", | ||
| ].includes(t.type), | ||
| (DEV_PLAN_INVOICE_TYPES as readonly string[]).includes(t.type), | ||
| ) | ||
| .map((t) => ({ | ||
| id: t.id, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.