An open-source, faster Devin alternative
TypeScript
fix(billing): enforce concurrent sandbox cap on free plan and show trial credits in UI (#172)
Mohamed Habibfa570eebcd07
diff --git a/internal/api/dashboard_billing.go b/internal/api/dashboard_billing.goindex daa15508..42bd7f09 100644--- a/internal/api/dashboard_billing.go+++ b/internal/api/dashboard_billing.go@@ -80,10 +80,11 @@ func (s *Server) billingGet(c echo.Context) error {// the Stripe Billing Portal instead of re-computing cost locally against a// hardcoded rate table that would diverge for grandfathered orgs.return c.JSON(http.StatusOK, map[string]interface{}{- "plan": org.Plan,- "stripeCreditCents": stripeCreditCents,- "maxConcurrentSandboxes": org.MaxConcurrentSandboxes,- "hasPaymentMethod": org.StripeCustomerID != nil,+ "plan": org.Plan,+ "stripeCreditCents": stripeCreditCents,+ "maxConcurrentSandboxes": org.MaxConcurrentSandboxes,+ "hasPaymentMethod": org.StripeCustomerID != nil,+ "freeCreditsRemainingCents": org.FreeCreditsRemainingCents,})}diff --git a/internal/api/sandbox.go b/internal/api/sandbox.goindex 1805c169..167d99d3 100644--- a/internal/api/sandbox.go+++ b/internal/api/sandbox.go@@ -44,8 +44,15 @@ func (s *Server) createSandbox(c echo.Context) error {var err errororg, err = s.store.GetOrg(ctx, orgID)if err == nil {- // Free-tier: trial credits gate instead of a concurrent-sandbox cap.- // Pro (and any other non-free plan): concurrent limit still applies.+ // Concurrent sandbox limit applies to all plans.+ count, err := s.store.CountActiveSandboxes(ctx, orgID)+ if err == nil && count >= org.MaxConcurrentSandboxes {+ return c.JSON(http.StatusTooManyRequests, map[string]string{+ "error": "concurrent sandbox limit reached",+ })+ }++ // Free-tier: trial credits gate + machine-size restriction.if org.Plan == "free" {if org.FreeCreditsRemainingCents <= 0 {return c.JSON(http.StatusPaymentRequired, map[string]string{@@ -57,13 +64,6 @@ func (s *Server) createSandbox(c echo.Context) error {"error": "upgrade to pro for larger instances",})}- } else {- count, err := s.store.CountActiveSandboxes(ctx, orgID)- if err == nil && count >= org.MaxConcurrentSandboxes {- return c.JSON(http.StatusTooManyRequests, map[string]string{- "error": "concurrent sandbox limit reached",- })- }}// Default to 4GB/1vCPU if not specified (all plans)diff --git a/web/src/api/client.ts b/web/src/api/client.tsindex 3660d4a6..50cbc5b0 100644--- a/web/src/api/client.ts+++ b/web/src/api/client.ts@@ -278,6 +278,7 @@ export interface BillingState {stripeCreditCents: numbermaxConcurrentSandboxes: numberhasPaymentMethod: boolean+ freeCreditsRemainingCents: number}export interface StripeInvoice {diff --git a/web/src/pages/Billing.tsx b/web/src/pages/Billing.tsxindex bd9d9645..d913440e 100644--- a/web/src/pages/Billing.tsx+++ b/web/src/pages/Billing.tsx@@ -7,7 +7,7 @@ import {export default function Billing() {const queryClient = useQueryClient()- const { data: billing, isLoading } = useQuery({ queryKey: ['billing'], queryFn: getBilling })+ const { data: billing, isLoading } = useQuery({ queryKey: ['billing'], queryFn: getBilling, refetchInterval: 30_000 })const { data: invoiceData } = useQuery({ queryKey: ['invoices'], queryFn: () => getBillingInvoices() })const [promoCode, setPromoCode] = useState('')@@ -73,10 +73,29 @@ export default function Billing() {</div>)}- {!isPro && (- <div style={{ marginTop: 16 }}>+ {!isPro && billing != null && (+ <div style={{ marginTop: 12 }}>+ {billing.freeCreditsRemainingCents > 0 ? (+ <div style={{+ fontSize: 14, fontWeight: 600, fontFamily: 'var(--font-mono)',+ color: 'var(--accent-emerald)', marginBottom: 12,+ }}>+ ${(billing.freeCreditsRemainingCents / 100).toFixed(2)} free trial credit remaining+ </div>+ ) : (+ <div style={{+ fontSize: 13, color: 'var(--accent-rose)', marginBottom: 12,+ display: 'flex', alignItems: 'center', gap: 6,+ }}>+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">+ <circle cx="12" cy="12" r="10" /><line x1="12" y1="8" x2="12" y2="12" /><line x1="12" y1="16" x2="12.01" y2="16" />+ </svg>+ Free trial credits exhausted — upgrade to continue using sandboxes+ </div>+ )}+<div style={{ fontSize: 13, color: 'var(--text-secondary)', marginBottom: 10 }}>- Unlock larger machine sizes and get $30 free credit+ Upgrade to Pro for an additional $30 free credit and larger machine sizes</div><buttononClick={() => setupMutation.mutate()}