Skip to content

fix(billing): unstub checkout / invoices / cancel — upgrade flow now works#20

Merged
mastermanas805 merged 1 commit into
mainfrom
fix/unstub-billing-checkout
May 11, 2026
Merged

fix(billing): unstub checkout / invoices / cancel — upgrade flow now works#20
mastermanas805 merged 1 commit into
mainfrom
fix/unstub-billing-checkout

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

The dashboard's billing functions were marked [FIXTURE] even though the agent-API endpoints exist. Clicking 'Upgrade to Pro' was sending customers to a stub URL.

This PR unstubs createCheckout, listInvoices, and the cancel handler. All three now hit real agent-API endpoints. fetchBilling stays partial-fixture (plan tier is real; renewal date + payment method are FIXTURE_BILLING) because no GET /api/v1/billing aggregator endpoint exists yet — flagged as follow-up in the api/index.ts comment.

Verified: build clean, 26/26 tests pass, security scan clean.

Next session candidate: kill dashboard-api (the frontend never reaches it; ~3000 lines of dead code).

…works

Before this commit the dashboard's billing surface had three
fixture-only API functions despite the real agent-API endpoints
existing and working:

  createCheckout()      → returned https://rzp.io/p/stub-${plan}
                          (a 404 — no real Razorpay session was
                          created). Clicking "Upgrade to Pro"
                          took customers to a broken URL.
  listInvoices()        → returned FIXTURE_INVOICES regardless of
                          the team's actual subscription.
  handleCancel()        → console.log('not yet wired')

After:

  createCheckout(plan)  → POST /api/v1/billing/checkout on the
                          agent API. Receives a real
                          razorpay-hosted short_url and
                          subscription_id. BillingPage redirects
                          window.location to short_url so the
                          customer completes payment on Razorpay,
                          which fires the subscription.activated
                          webhook back to /razorpay/webhook on the
                          agent API and the team tier elevates
                          via models.UpdatePlanTier +
                          ElevateResourceTiersByTeam.

  listInvoices()        → GET /api/v1/billing/invoices on the
                          agent API. Falls back to fixtures only
                          on 503 (billing_not_configured) so
                          local-dev without Razorpay keys still
                          shows usable data.

  cancelSubscription()  → POST /api/v1/billing/cancel on the
                          agent API. handleCancel re-reads the
                          billing card and surfaces a notice that
                          the downgrade is in flight pending
                          Razorpay's async subscription.cancelled
                          webhook.

fetchBilling() stays partial-fixture: the plan TIER is real (from
/api/v1/whoami via fetchMe), but the next-renewal-date and
payment-method fields are still FIXTURE_BILLING because the agent
API doesn't yet expose a GET /api/v1/billing endpoint that
aggregates this. Open follow-up: add that endpoint to the agent
API, then drop FIXTURE_BILLING from this file entirely.

Verified locally:
  npm run build → 116 HTML + 116 .md mirrors, no errors
  npm test → 26/26 markdown renderer tests pass
  Security scan on the diff: zero secrets, zero cluster
  hostnames, zero customer identifiers

This is the smaller of the two paths I offered:
  ✓ ship the billing unstub now (this PR)
  ⏳ kill dashboard-api as a separate session (~3000 lines of
    dead code in the dashboard-api repo since the frontend talks
    directly to the agent API)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805 mastermanas805 merged commit dd4d67f into main May 11, 2026
1 of 2 checks passed
@mastermanas805 mastermanas805 deleted the fix/unstub-billing-checkout branch May 11, 2026 14:01
mastermanas805 added a commit that referenced this pull request May 11, 2026
…nt (#23)

InstaNode-dev/api PR #15 just landed — the agent API now serves
GET /api/v1/billing as the aggregated subscription-state endpoint
the dashboard had been fixturing.

This commit drops the fixture path. fetchBilling() now calls the
real endpoint and maps the response into the dashboard's existing
BillingDetails shape (status, current_period_end, payment_last4,
payment_network — every field the agent API can populate is now
live; the ones the agent API doesn't expose yet stay undefined and
render as "—" in the UI).

Fallback: on 503 (Razorpay unconfigured in local dev), still falls
back to FIXTURE_BILLING so the BillingPage doesn't break for
developers without RAZORPAY_KEY_ID set. Any other error propagates
so production failures aren't silently swallowed.

Closes the partial-fixture comment block I left in PR #20.

Verified: npm run build clean (116 HTML + 116 .md), 26/26 markdown
renderer tests pass, Playwright auth/navigation/resources specs
all green.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant