feat(billing): Automatic top-up toggle in profile settings

Merged
SW
5mo ago
+261-0

Summary

Chat slice of #1861 — a user-facing kill switch for automatic credit top-up, so opting out of off-session charges is a setting instead of a support ticket (or removing your card).

  • BillingSection — a divided Billing section in the Account (Profile) modal: labeled Switch + helper text stating exactly what gets charged ($5 for 500 credits) and that disabling never removes the card. Applies instantly via PATCH (visually separated from the save-to-apply form); mutation failures surface as a toast. (Supersedes the original AutoTopUpMenuItem dropdown checkbox — moved per review 2026-07-09: a billing-consent control needs explanation a menu item can't carry; see the redesign comment for screenshots.)
  • useAutoRecharge — react-query hook (query + mutation) following the useCredits pattern: Privy bearer from the provider, account from useUserProvider, cache updated from the PATCH response.
  • lib/recoup/getAutoRechargeSetting / updateAutoRechargeSetting — fetch helpers mirroring getAccountCredits, hitting GET/PATCH /api/accounts/{id}/auto-recharge (api#769, contract in docs#270).

The toggle renders the live Stripe-read state from the api (the setting lives on the Stripe customer record) — never a cached local flag — per the #1861 design decision.

Merge order

docs#270 → api#769 → this. The toggle 404s against an api without #769, so this merges last.

Verification

  • TDD: fetch-helper tests were RED (module not found) before implementation, GREEN after — 35 files / 130 tests pass.
  • eslint + tsc --noEmit clean on all touched files (next lint itself is broken in Next 16 — build is the gate).
  • pnpm build compiles successfully, 43/43 static pages generated.
  • Live end-to-end toggle verification happens against the api preview (results will be posted on api#769).

🤖 Generated with Claude Code


Summary by cubic

Adds an Automatic top-up toggle in the Account modal’s Billing section so users can opt out of off-session credit top-ups (Linear #1861). The switch reads and updates the live Stripe-backed setting via GET/PATCH /api/accounts/{id}/auto-recharge so the UI matches actual charge consent.

  • New Features

    • Labeled “Automatic top-up” Switch with helper text ($5 for 500 credits; disabling doesn’t remove the card); applies instantly on flip.
    • useAutoRecharge (@tanstack/react-query) loads/updates with a Privy bearer, updates cache from the PATCH response, and shows a toast on failure.
  • Dependencies

    • Requires api#769 (contract in docs#270); merge order: docs#270 → api#769 → this.