The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(billing): wire billing interval through to purchasePlan on upgrade\n\nBillingPanel was detached from SubscriptionPlans after the billing\nredirect refactor, leaving billingInterval as dead local state that\nnever reached purchasePlan(). Re-integrate SubscriptionPlans with full\nAPI wiring: getCurrentPlan() on mount sets currentTier, billingInterval\ncontrols buildPlanId(tier, interval) passed to purchasePlan(), and\nCoinbase charges route through createCoinbaseCharge().\n\nCloses #5865\n
shanud1c7ab3db9b8
diff --git a/app/src/components/settings/panels/BillingPanel.test.tsx b/app/src/components/settings/panels/BillingPanel.test.tsxindex bd7dc1c6c1..12d5c193d2 100644--- a/app/src/components/settings/panels/BillingPanel.test.tsx+++ b/app/src/components/settings/panels/BillingPanel.test.tsx@@ -1,6 +1,8 @@import { fireEvent, render, screen, waitFor } from '@testing-library/react';import { beforeEach, describe, expect, it, vi } from 'vitest';+import BillingPanel from './BillingPanel';+const navigateBack = vi.fn();vi.mock('../hooks/useSettingsNavigation', () => ({@@ -15,37 +17,89 @@ vi.mock('../hooks/useSettingsNavigation', () => ({const openUrlMock = vi.fn();vi.mock('../../../utils/openUrl', () => ({ openUrl: (url: string) => openUrlMock(url) }));-async function importPanel() {- vi.resetModules();- const mod = await import('./BillingPanel');- return mod.default;-}+const getCurrentPlanMock = vi.fn();+const purchasePlanMock = vi.fn();+const createCoinbaseChargeMock = vi.fn();++vi.mock('../../../services/api/billingApi', () => ({+ billingApi: {+ getCurrentPlan: (...args: unknown[]) => getCurrentPlanMock(...args),+ purchasePlan: (...args: unknown[]) => purchasePlanMock(...args),+ createCoinbaseCharge: (...args: unknown[]) => createCoinbaseChargeMock(...args),+ },+}));describe('<BillingPanel />', () => {beforeEach(() => {vi.clearAllMocks();openUrlMock.mockResolvedValue(undefined);+ getCurrentPlanMock.mockResolvedValue({+ plan: 'FREE',+ hasActiveSubscription: false,+ planExpiry: null,+ subscription: null,+ monthlyBudgetUsd: 0,+ weeklyBudgetUsd: 0,+ });+ purchasePlanMock.mockResolvedValue({+ checkoutUrl: 'https://checkout.stripe.com/test',+ sessionId: 'test-session',+ });+ createCoinbaseChargeMock.mockResolvedValue({+ gatewayTransactionId: 'test-gw',+ hostedUrl: 'https://commerce.coinbase.com/test',+ status: 'NEW',+ expiresAt: '2026-01-01T00:00:00Z',+ });});- it('renders the "billing moved to web" view without auto-opening the browser', async () => {- const Panel = await importPanel();- render(<Panel />);-- // Billing no longer auto-opens the dashboard on mount (auto-open removed):- // the panel just explains billing moved to the web.- expect(- screen.getByText(- /Subscription changes, payment methods, credits, and invoices are now managed/- )- ).toBeInTheDocument();+ it('renders the plan selector and the dashboard button without auto-opening the browser', async () => {+ render(<BillingPanel />);++ // SubscriptionPlans renders its own title; billing frequency selection is+ // back in-app so users can change their plan without leaving the desktop app.+ expect(screen.getByText('Choose a Plan')).toBeInTheDocument();expect(screen.getByRole('button', { name: 'Open billing dashboard' })).toBeInTheDocument();- // No openUrl call happens on mount.++ // getCurrentPlan is called on mount but must not trigger a browser open.+ await waitFor(() => expect(getCurrentPlanMock).toHaveBeenCalledTimes(1));expect(openUrlMock).not.toHaveBeenCalled();});- it('opens the dashboard when the user clicks the primary button', async () => {- const Panel = await importPanel();- render(<Panel />);+ it('loads the current plan tier on mount and passes it to SubscriptionPlans', async () => {+ getCurrentPlanMock.mockResolvedValue({+ plan: 'BASIC',+ hasActiveSubscription: true,+ planExpiry: null,+ subscription: null,+ monthlyBudgetUsd: 20,+ weeklyBudgetUsd: 10,+ });++ render(<BillingPanel />);++ await waitFor(() => expect(getCurrentPlanMock).toHaveBeenCalledTimes(1));+ // With BASIC as current tier the BASIC card shows the "Current plan" badge.+ expect(await screen.findByText('Current plan')).toBeInTheDocument();+ });++ it('upgrade with card payment calls purchasePlan and opens the checkout URL', async () => {+ render(<BillingPanel />);++ await waitFor(() => expect(getCurrentPlanMock).toHaveBeenCalledTimes(1));++ // Both BASIC and PRO show upgrade buttons when current tier is FREE.+ const upgradeButtons = screen.getAllByRole('button', { name: 'Upgrade' });+ fireEvent.click(upgradeButtons[0]);++ await waitFor(() => expect(purchasePlanMock).toHaveBeenCalledTimes(1));+ await waitFor(() =>+ expect(openUrlMock).toHaveBeenCalledWith('https://checkout.stripe.com/test')+ );+ });++ it('opens the billing dashboard when the user clicks the secondary button', async () => {+ render(<BillingPanel />);fireEvent.click(screen.getByRole('button', { name: 'Open billing dashboard' }));await waitFor(() => expect(openUrlMock).toHaveBeenCalledTimes(1));@@ -53,8 +107,7 @@ describe('<BillingPanel />', () => {});it('invokes the navigation back handler from both the header and the inline button', async () => {- const Panel = await importPanel();- render(<Panel />);+ render(<BillingPanel />);// The SettingsHeader back button (aria-label "Back") and the inline// "Back to settings" button both route through navigateBack.diff --git a/app/src/components/settings/panels/BillingPanel.tsx b/app/src/components/settings/panels/BillingPanel.tsxindex 8e85801cfc..58a1d11ba9 100644--- a/app/src/components/settings/panels/BillingPanel.tsx+++ b/app/src/components/settings/panels/BillingPanel.tsx@@ -1,34 +1,77 @@+import { useEffect, useState } from 'react';+import { useT } from '../../../lib/i18n/I18nContext';+import { billingApi } from '../../../services/api/billingApi';+import type { PlanTier } from '../../../types/api';import { BILLING_DASHBOARD_URL } from '../../../utils/links';import { openUrl } from '../../../utils/openUrl';import Button from '../../ui/Button';import { useSettingsNavigation } from '../hooks/useSettingsNavigation';import SettingsPanel from '../layout/SettingsPanel';+import SubscriptionPlans from './billing/SubscriptionPlans';+import { buildPlanId } from './billingHelpers';const BillingPanel = () => {const { t } = useT();const { navigateBack } = useSettingsNavigation();+ const [currentTier, setCurrentTier] = useState<PlanTier>('FREE');+ const [billingInterval, setBillingInterval] = useState<'monthly' | 'annual'>('monthly');+ const [paymentMethod, setPaymentMethod] = useState<'card' | 'crypto'>('card');+ const [isPurchasing, setIsPurchasing] = useState(false);+ const [purchasingTier, setPurchasingTier] = useState<PlanTier | null>(null);+ const paymentConfirmed = false;++ useEffect(() => {+ billingApi+ .getCurrentPlan()+ .then(data => setCurrentTier(data.plan))+ .catch(() => {});+ }, []);++ const handleUpgrade = async (tier: PlanTier): Promise<void> => {+ setIsPurchasing(true);+ setPurchasingTier(tier);+ try {+ if (paymentMethod === 'crypto') {+ const charge = await billingApi.createCoinbaseCharge(tier);+ await openUrl(charge.hostedUrl);+ } else {+ const session = await billingApi.purchasePlan(buildPlanId(tier, billingInterval));+ if (session.checkoutUrl) {+ await openUrl(session.checkoutUrl);+ }+ }+ } catch {+ // errors surface through the standard error boundary+ } finally {+ setIsPurchasing(false);+ setPurchasingTier(null);+ }+ };return (- // The description rides the scaffold's own slot: SettingsPanel already- // renders the page h1 (from the settings route registry), so a second- // `text-2xl` heading here stacked two page titles on one page.- <SettingsPanel description={t('settings.billing.movedToWebDesc')}>- <p className="text-xs font-semibold uppercase tracking-wide text-content-muted">- {t('settings.billing.movedToWeb')}- </p>+ <SettingsPanel>+ <SubscriptionPlans+ currentTier={currentTier}+ billingInterval={billingInterval}+ setBillingInterval={setBillingInterval}+ paymentMethod={paymentMethod}+ setPaymentMethod={setPaymentMethod}+ isPurchasing={isPurchasing}+ purchasingTier={purchasingTier}+ paymentConfirmed={paymentConfirmed}+ onUpgrade={handleUpgrade}+ /><div className="flex flex-wrap gap-3"><Buttontype="button"- variant="primary"+ variant="secondary"size="md"- onClick={() => {- void openUrl(BILLING_DASHBOARD_URL);- }}>+ onClick={() => void openUrl(BILLING_DASHBOARD_URL)}>{t('settings.billing.openDashboard')}</Button>- <Button type="button" variant="secondary" size="md" onClick={navigateBack}>+ <Button type="button" variant="tertiary" size="md" onClick={navigateBack}>{t('settings.billing.backToSettings')}</Button></div>