From 83885db249ab132095d8a03e228932793c488454 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 26 Aug 2026 18:42:45 +0000 Subject: [PATCH 1/7] fix(billing): stop claiming a saved card exists in the top-up confirm step The confirm step always showed 'Your saved payment method is charged immediately', even for workspaces with no payment method on file (caught in 1.51 workspace-switcher QA). Resolve the note from the server's payment-method list: when none is saved, tell the user payment details will be collected instead. Unknown/failed lookups keep the existing copy. --- src/locales/en/main.json | 1 + ...TopUpCreditsDialogContentWorkspace.test.ts | 61 +++++++++++++++++++ .../TopUpCreditsDialogContentWorkspace.vue | 11 +++- .../useHasSavedPaymentMethod.test.ts | 56 +++++++++++++++++ .../composables/useHasSavedPaymentMethod.ts | 21 +++++++ 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts create mode 100644 src/platform/workspace/composables/useHasSavedPaymentMethod.ts diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 1774969d2f7..72a60f01db2 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -2687,6 +2687,7 @@ "insufficientWorkflowMessage": "You don't have enough credits to run this workflow.", "creditsDescription": "Credits are used to run workflows or partner nodes.", "chargedImmediatelyNote": "Your saved payment method is charged immediately.", + "paymentDetailsRequiredNote": "You'll be asked to add a payment method to complete this purchase.", "confirmSubtitle": "Credits are added to this workspace as soon as payment completes.", "confirmTitle": "Confirm", "howManyCredits": "How many credits would you like to add?", diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index 5e1c58aa455..e3aa30a16ac 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -27,6 +27,23 @@ const mockDistributionTypes = vi.hoisted(() => ({ isCloud: true })) vi.mock('@/platform/distribution/types', () => mockDistributionTypes) +const mockHasSavedPaymentMethod = vi.hoisted(() => ({ + ref: undefined as { value: boolean | null } | undefined +})) + +vi.mock( + '@/platform/workspace/composables/useHasSavedPaymentMethod', + async () => { + const { ref } = await import('vue') + mockHasSavedPaymentMethod.ref = ref(null) + return { + useHasSavedPaymentMethod: () => ({ + hasSavedPaymentMethod: mockHasSavedPaymentMethod.ref + }) + } + } +) + interface MockTopupOperation { opId: string status: 'pending' | 'reconciliation_needed' @@ -145,6 +162,8 @@ const i18n = createI18n({ viewPricing: 'View pricing', insufficientWorkflowMessage: 'Insufficient credits', chargedImmediatelyNote: 'Your saved card is charged immediately.', + paymentDetailsRequiredNote: + "You'll be asked to add a payment method to complete this purchase.", confirmSubtitle: 'Credits are added to this workspace as soon as payment completes.', confirmTitle: 'Confirm', @@ -209,6 +228,13 @@ function setTopupActionOperation(operation: MockTopupOperation | undefined) { mockBillingOperationState.topupActionOperation.value = operation } +function setHasSavedPaymentMethod(value: boolean | null) { + if (!mockHasSavedPaymentMethod.ref) { + throw new Error('Payment method mock not initialized') + } + mockHasSavedPaymentMethod.ref.value = value +} + async function clickAddCredits() { const user = userEvent.setup() await user.click(screen.getByRole('button', { name: 'Add credits' })) @@ -222,6 +248,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { setTopupActionOperation(undefined) mockFetchBalance.mockResolvedValue(undefined) mockFetchStatus.mockResolvedValue(undefined) + setHasSavedPaymentMethod(true) mockStartOperation.mockImplementation(() => { setIsAddingCredits(true) return new Promise(() => {}) @@ -286,6 +313,40 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockTopup).not.toHaveBeenCalled() }) + it('shows the saved-card note when a payment method is on file', async () => { + renderDialog() + + await clickAddCredits() + + expect( + await screen.findByText('Your saved card is charged immediately.') + ).toBeInTheDocument() + }) + + it('asks for payment details when no payment method is saved', async () => { + setHasSavedPaymentMethod(false) + + renderDialog() + await clickAddCredits() + + expect( + await screen.findByText( + "You'll be asked to add a payment method to complete this purchase." + ) + ).toBeInTheDocument() + }) + + it('keeps the saved-card note when the payment method lookup fails', async () => { + setHasSavedPaymentMethod(null) + + renderDialog() + await clickAddCredits() + + expect( + await screen.findByText('Your saved card is charged immediately.') + ).toBeInTheDocument() + }) + it('allows returning to amount selection before payment', async () => { renderDialog() await clickAddCredits() diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue index c6ce2593618..a5262ea17d7 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue @@ -66,7 +66,7 @@

- {{ $t('credits.topUp.chargedImmediatelyNote') }} + {{ paymentNote }}

@@ -281,6 +281,7 @@ import { clearTopupTracking } from '@/platform/telemetry/topupTracker' import { categorizeBillingApiError } from '@/platform/telemetry/utils/billingFailureCategory' import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog' import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' +import { useHasSavedPaymentMethod } from '@/platform/workspace/composables/useHasSavedPaymentMethod' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' import { useDialogStore } from '@/stores/dialogStore' import { cn } from '@comfyorg/tailwind-utils' @@ -334,11 +335,19 @@ const step = ref<'amount' | 'confirm' | 'verifying'>( topupOperation.value && canTopUp.value ? 'verifying' : 'amount' ) +const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() + // Computed const pricingUrl = computed(() => buildDocsUrl(docsPaths.partnerNodesPricing, { includeLocale: true }) ) +const paymentNote = computed(() => + hasSavedPaymentMethod.value === false + ? t('credits.topUp.paymentDetailsRequiredNote') + : t('credits.topUp.chargedImmediatelyNote') +) + const creditsModel = computed({ get: () => usdToCredits(payAmount.value), set: (newCredits: number) => { diff --git a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts new file mode 100644 index 00000000000..5ba8c976c4b --- /dev/null +++ b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts @@ -0,0 +1,56 @@ +import { describe, expect, it, vi } from 'vitest' +import { nextTick } from 'vue' + +import { useHasSavedPaymentMethod } from './useHasSavedPaymentMethod' + +const mockListSavedPaymentMethods = vi.hoisted(() => + vi.fn<() => Promise<{ id: string }[]>>() +) + +vi.mock('@/platform/workspace/api/workspaceApi', () => ({ + workspaceApi: { + listSavedPaymentMethods: mockListSavedPaymentMethods + } +})) + +async function flushLookup() { + await Promise.resolve() + await nextTick() +} + +describe('useHasSavedPaymentMethod', () => { + it('starts unknown before the lookup resolves', () => { + mockListSavedPaymentMethods.mockResolvedValue([]) + + const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() + + expect(hasSavedPaymentMethod.value).toBeNull() + }) + + it('resolves true when a payment method is on file', async () => { + mockListSavedPaymentMethods.mockResolvedValue([{ id: 'pm-1' }]) + + const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() + await flushLookup() + + expect(hasSavedPaymentMethod.value).toBe(true) + }) + + it('resolves false when no payment methods are saved', async () => { + mockListSavedPaymentMethods.mockResolvedValue([]) + + const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() + await flushLookup() + + expect(hasSavedPaymentMethod.value).toBe(false) + }) + + it('stays unknown when the lookup fails', async () => { + mockListSavedPaymentMethods.mockRejectedValue(new Error('network')) + + const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() + await flushLookup() + + expect(hasSavedPaymentMethod.value).toBeNull() + }) +}) diff --git a/src/platform/workspace/composables/useHasSavedPaymentMethod.ts b/src/platform/workspace/composables/useHasSavedPaymentMethod.ts new file mode 100644 index 00000000000..f047b351cf3 --- /dev/null +++ b/src/platform/workspace/composables/useHasSavedPaymentMethod.ts @@ -0,0 +1,21 @@ +import { ref } from 'vue' + +import { workspaceApi } from '@/platform/workspace/api/workspaceApi' + +/** + * Reports whether the active workspace has a saved payment method. + * `null` until the lookup resolves, and stays `null` when it fails so + * callers fall back to their default copy instead of claiming certainty. + */ +export function useHasSavedPaymentMethod() { + const hasSavedPaymentMethod = ref(null) + void workspaceApi + .listSavedPaymentMethods() + .then((methods) => { + hasSavedPaymentMethod.value = methods.length > 0 + }) + .catch(() => { + hasSavedPaymentMethod.value = null + }) + return { hasSavedPaymentMethod } +} From ec10c814eda155dff63835d04ccd1954f465c6cf Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 26 Aug 2026 18:53:53 +0000 Subject: [PATCH 2/7] feat(billing): guide users to add a payment method before top-up When no payment method is saved, the confirm step now links straight to Manage billing (opens the payment portal), and a refused purchase (NO_PAYMENT_METHOD) explains where to add one instead of echoing the raw server error. Requested by QA in the 1.51 workspace-switcher pass (FE-1908). --- src/locales/en/main.json | 1 + ...TopUpCreditsDialogContentWorkspace.test.ts | 43 +++++++++++++++++++ .../TopUpCreditsDialogContentWorkspace.vue | 29 ++++++++++--- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 72a60f01db2..7f3f3fc6f2c 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -2688,6 +2688,7 @@ "creditsDescription": "Credits are used to run workflows or partner nodes.", "chargedImmediatelyNote": "Your saved payment method is charged immediately.", "paymentDetailsRequiredNote": "You'll be asked to add a payment method to complete this purchase.", + "noPaymentMethodError": "No payment method is saved for this workspace. Add one via Settings → Plan & Credits → Manage billing, then retry the top-up.", "confirmSubtitle": "Credits are added to this workspace as soon as payment completes.", "confirmTitle": "Confirm", "howManyCredits": "How many credits would you like to add?", diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index e3aa30a16ac..d01c82458d5 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -11,6 +11,7 @@ import TopUpCreditsDialogContentWorkspace from './TopUpCreditsDialogContentWorks const mockFetchBalance = vi.fn() const mockFetchStatus = vi.fn() +const mockManageSubscription = vi.fn() const mockTopup = vi.fn<(amountCents: number) => Promise>() const mockStartOperation = vi.fn() @@ -65,6 +66,7 @@ vi.mock('@/composables/billing/useBillingContext', () => ({ useBillingContext: () => ({ fetchBalance: mockFetchBalance, fetchStatus: mockFetchStatus, + manageSubscription: mockManageSubscription, topup: (amountCents: number) => mockTopup(amountCents) }) })) @@ -139,6 +141,7 @@ const i18n = createI18n({ g: { back: 'Back', close: 'Close' }, subscription: { addCredits: 'Add credits', + manageBilling: 'Manage billing', preview: { completeVerification: 'Complete verification', totalDueToday: 'Total due today' @@ -164,6 +167,8 @@ const i18n = createI18n({ chargedImmediatelyNote: 'Your saved card is charged immediately.', paymentDetailsRequiredNote: "You'll be asked to add a payment method to complete this purchase.", + noPaymentMethodError: + 'No payment method is saved for this workspace. Add one via Manage billing, then retry.', confirmSubtitle: 'Credits are added to this workspace as soon as payment completes.', confirmTitle: 'Confirm', @@ -336,6 +341,44 @@ describe('TopUpCreditsDialogContentWorkspace', () => { ).toBeInTheDocument() }) + it('opens the billing portal from the no-payment-method note', async () => { + setHasSavedPaymentMethod(false) + mockManageSubscription.mockResolvedValue(undefined) + + renderDialog() + await clickAddCredits() + + await userEvent.click( + await screen.findByRole('button', { name: 'Manage billing' }) + ) + + expect(mockManageSubscription).toHaveBeenCalledTimes(1) + }) + + it('explains how to add a payment method when the purchase is refused', async () => { + setHasSavedPaymentMethod(false) + mockTopup.mockRejectedValue( + new WorkspaceApiError( + 'No default payment method is selected.', + 400, + 'NO_PAYMENT_METHOD' + ) + ) + + renderDialog() + await clickAddCredits() + await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) + + await waitFor(() => + expect(mockToastAdd).toHaveBeenCalledWith( + expect.objectContaining({ + detail: + 'No payment method is saved for this workspace. Add one via Manage billing, then retry.' + }) + ) + ) + }) + it('keeps the saved-card note when the payment method lookup fails', async () => { setHasSavedPaymentMethod(null) diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue index a5262ea17d7..b3c49859c50 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue @@ -67,6 +67,13 @@

{{ paymentNote }} +

@@ -280,6 +287,7 @@ import { isCloud } from '@/platform/distribution/types' import { clearTopupTracking } from '@/platform/telemetry/topupTracker' import { categorizeBillingApiError } from '@/platform/telemetry/utils/billingFailureCategory' import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog' +import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi' import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' import { useHasSavedPaymentMethod } from '@/platform/workspace/composables/useHasSavedPaymentMethod' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' @@ -296,7 +304,8 @@ const settingsDialog = useSettingsDialog() const telemetry = useTelemetry() const toast = useToast() const { buildDocsUrl, docsPaths } = useExternalLink() -const { fetchBalance, fetchStatus, topup } = useBillingContext() +const { fetchBalance, fetchStatus, manageSubscription, topup } = + useBillingContext() const { canTopUp } = useBillingCapabilities() const billingOperationStore = useBillingOperationStore() @@ -433,6 +442,10 @@ function handlePrimaryAction() { void handleBuy() } +function openManageBilling() { + void manageSubscription().catch(() => {}) +} + function openTopupVerification() { if (!topupActionUrl.value) return window.open(topupActionUrl.value, '_blank', 'noopener,noreferrer') @@ -591,13 +604,19 @@ function reportPurchaseError( error === undefined ? 'unknown' : categorizeBillingApiError(error), duration_ms: Date.now() - attemptStartedAt }) + const missingPaymentMethod = + error instanceof WorkspaceApiError && error.code === 'NO_PAYMENT_METHOD' toast.add({ severity: 'error', summary: t('credits.topUp.purchaseError'), - detail: t('credits.topUp.purchaseErrorDetail', { - error: - error instanceof Error ? error.message : t('credits.topUp.unknownError') - }) + detail: missingPaymentMethod + ? t('credits.topUp.noPaymentMethodError') + : t('credits.topUp.purchaseErrorDetail', { + error: + error instanceof Error + ? error.message + : t('credits.topUp.unknownError') + }) }) } From 70f1f1bf578d84b402b7b9f0bdd720fdcb9b4d82 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 26 Aug 2026 19:47:41 +0000 Subject: [PATCH 3/7] test(e2e): cover top-up without a saved payment method Pins the FE-1908 flow on the workspace rail: the confirm step offers Manage billing instead of claiming a saved card, and a NO_PAYMENT_METHOD refusal explains where to add one. --- .../dialogs/topUpNoPaymentMethod.spec.ts | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts diff --git a/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts b/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts new file mode 100644 index 00000000000..de9c99dfaef --- /dev/null +++ b/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts @@ -0,0 +1,97 @@ +import { expect } from '@playwright/test' +import type { Page } from '@playwright/test' + +import { TopUpCreditsDialog } from '@e2e/fixtures/components/TopUpCreditsDialog' +import { TestIds } from '@e2e/fixtures/selectors' +import { workspaceRailAuthFixture as test } from '@e2e/fixtures/workspaceRailAuthFixture' + +/** + * Regression coverage for the 1.51 QA finding: with no payment method saved, + * the confirm step claimed "Your saved payment method is charged immediately" + * and a refused purchase surfaced the raw NO_PAYMENT_METHOD server error with + * no path forward (FE-1908). + * + * Entered through the user popover like a real user: workspace-rail routing + * needs the billing context loaded before the dialog opens, and the popover's + * Add credits button only renders once it is. + */ +test.describe('Top-up without a saved payment method', () => { + async function openTopUpDialog(page: Page) { + const topUpDialog = new TopUpCreditsDialog(page) + await page.getByTestId(TestIds.user.currentUserButton).click() + await page + .getByTestId(TestIds.user.currentUserPopover) + .getByTestId('add-credits-button') + .click() + await expect(topUpDialog.heading).toBeVisible() + return topUpDialog + } + + test('offers Manage billing and explains a refused purchase', async ({ + comfyPage + }) => { + const page = comfyPage.page + await page.route('**/api/billing/payment-methods', (route) => + route.fulfill({ json: [] }) + ) + await page.route('**/api/billing/topup', (route) => + route.fulfill({ + status: 400, + json: { + code: 'NO_PAYMENT_METHOD', + message: + 'No default payment method is selected. Please select one in the payment portal.' + } + }) + ) + + const topUpDialog = await openTopUpDialog(page) + + await topUpDialog.root + .getByRole('button', { name: 'Add credits', exact: true }) + .click() + + await expect( + topUpDialog.root.getByText( + "You'll be asked to add a payment method to complete this purchase." + ) + ).toBeVisible() + await expect( + topUpDialog.root.getByRole('button', { name: 'Manage billing' }) + ).toBeVisible() + + await topUpDialog.root.getByRole('button', { name: 'Pay $50.00' }).click() + + await expect( + page + .locator('.p-toast-message.p-toast-message-error') + .getByText(/Add one via Settings → Plan & Credits → Manage billing/) + ).toBeVisible() + }) + + test('keeps the saved-card note when a payment method is on file', async ({ + comfyPage + }) => { + const page = comfyPage.page + await page.route('**/api/billing/payment-methods', (route) => + route.fulfill({ + json: [{ id: 'pm-1', brand: 'visa', last4: '4242', is_default: true }] + }) + ) + + const topUpDialog = await openTopUpDialog(page) + + await topUpDialog.root + .getByRole('button', { name: 'Add credits', exact: true }) + .click() + + await expect( + topUpDialog.root.getByText( + 'Your saved payment method is charged immediately.' + ) + ).toBeVisible() + await expect( + topUpDialog.root.getByRole('button', { name: 'Manage billing' }) + ).toHaveCount(0) + }) +}) From f18d73946c5619c70ffbf5222a82c5d644efd7e5 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 26 Aug 2026 20:17:26 +0000 Subject: [PATCH 4/7] =?UTF-8?q?fix(billing):=20address=20review=20?= =?UTF-8?q?=E2=80=94=20observability=20and=20typed=20test=20fixtures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Report saved-payment-method lookup and billing-portal open failures via reportError with user-facing feedback; align the component test locale with the production guidance copy; type e2e payloads with ingest-types and verify the Manage billing click opens the portal. --- .../dialogs/topUpNoPaymentMethod.spec.ts | 38 ++++++++++++++++--- src/locales/en/main.json | 1 + ...TopUpCreditsDialogContentWorkspace.test.ts | 4 +- .../TopUpCreditsDialogContentWorkspace.vue | 10 ++++- .../useHasSavedPaymentMethod.test.ts | 21 ++++++++-- .../composables/useHasSavedPaymentMethod.ts | 6 ++- 6 files changed, 67 insertions(+), 13 deletions(-) diff --git a/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts b/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts index de9c99dfaef..19220090ab7 100644 --- a/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts +++ b/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts @@ -1,6 +1,11 @@ import { expect } from '@playwright/test' import type { Page } from '@playwright/test' +import type { + PaymentPortalResponse, + SavedPaymentMethod +} from '@comfyorg/ingest-types' + import { TopUpCreditsDialog } from '@e2e/fixtures/components/TopUpCreditsDialog' import { TestIds } from '@e2e/fixtures/selectors' import { workspaceRailAuthFixture as test } from '@e2e/fixtures/workspaceRailAuthFixture' @@ -32,8 +37,20 @@ test.describe('Top-up without a saved payment method', () => { }) => { const page = comfyPage.page await page.route('**/api/billing/payment-methods', (route) => - route.fulfill({ json: [] }) + route.fulfill({ json: [] satisfies SavedPaymentMethod[] }) + ) + await page.route('**/api/billing/payment-portal', (route) => + route.fulfill({ + json: { + url: 'https://billing.example/portal' + } satisfies PaymentPortalResponse + }) ) + await page + .context() + .route('https://billing.example/**', (route) => + route.fulfill({ contentType: 'text/html', body: 'portal stub' }) + ) await page.route('**/api/billing/topup', (route) => route.fulfill({ status: 400, @@ -56,9 +73,12 @@ test.describe('Top-up without a saved payment method', () => { "You'll be asked to add a payment method to complete this purchase." ) ).toBeVisible() - await expect( - topUpDialog.root.getByRole('button', { name: 'Manage billing' }) - ).toBeVisible() + const [portalPage] = await Promise.all([ + page.context().waitForEvent('page'), + topUpDialog.root.getByRole('button', { name: 'Manage billing' }).click() + ]) + expect(portalPage.url()).toBe('https://billing.example/portal') + await portalPage.close() await topUpDialog.root.getByRole('button', { name: 'Pay $50.00' }).click() @@ -75,7 +95,15 @@ test.describe('Top-up without a saved payment method', () => { const page = comfyPage.page await page.route('**/api/billing/payment-methods', (route) => route.fulfill({ - json: [{ id: 'pm-1', brand: 'visa', last4: '4242', is_default: true }] + json: [ + { + id: 'pm-1', + type: 'card', + brand: 'visa', + last4: '4242', + is_default: true + } + ] satisfies SavedPaymentMethod[] }) ) diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 7f3f3fc6f2c..e27692e65ba 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -2689,6 +2689,7 @@ "chargedImmediatelyNote": "Your saved payment method is charged immediately.", "paymentDetailsRequiredNote": "You'll be asked to add a payment method to complete this purchase.", "noPaymentMethodError": "No payment method is saved for this workspace. Add one via Settings → Plan & Credits → Manage billing, then retry the top-up.", + "manageBillingError": "Failed to open the billing portal. Please try again.", "confirmSubtitle": "Credits are added to this workspace as soon as payment completes.", "confirmTitle": "Confirm", "howManyCredits": "How many credits would you like to add?", diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index d01c82458d5..e471b4ba206 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -168,7 +168,7 @@ const i18n = createI18n({ paymentDetailsRequiredNote: "You'll be asked to add a payment method to complete this purchase.", noPaymentMethodError: - 'No payment method is saved for this workspace. Add one via Manage billing, then retry.', + 'No payment method is saved for this workspace. Add one via Settings → Plan & Credits → Manage billing, then retry the top-up.', confirmSubtitle: 'Credits are added to this workspace as soon as payment completes.', confirmTitle: 'Confirm', @@ -373,7 +373,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ detail: - 'No payment method is saved for this workspace. Add one via Manage billing, then retry.' + 'No payment method is saved for this workspace. Add one via Settings → Plan & Credits → Manage billing, then retry the top-up.' }) ) ) diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue index b3c49859c50..3635d8b646a 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue @@ -287,6 +287,7 @@ import { isCloud } from '@/platform/distribution/types' import { clearTopupTracking } from '@/platform/telemetry/topupTracker' import { categorizeBillingApiError } from '@/platform/telemetry/utils/billingFailureCategory' import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog' +import { reportError } from '@/platform/telemetry/reportError' import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi' import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' import { useHasSavedPaymentMethod } from '@/platform/workspace/composables/useHasSavedPaymentMethod' @@ -443,7 +444,14 @@ function handlePrimaryAction() { } function openManageBilling() { - void manageSubscription().catch(() => {}) + void manageSubscription().catch((error) => { + reportError(error, { errorType: 'billing_portal_open_failure' }) + toast.add({ + severity: 'error', + summary: t('credits.topUp.manageBillingError'), + life: 5000 + }) + }) } function openTopupVerification() { diff --git a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts index 5ba8c976c4b..2eecd379361 100644 --- a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts +++ b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts @@ -1,11 +1,14 @@ import { describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' +import type { SavedPaymentMethod } from '@/platform/workspace/api/workspaceApi' + import { useHasSavedPaymentMethod } from './useHasSavedPaymentMethod' const mockListSavedPaymentMethods = vi.hoisted(() => - vi.fn<() => Promise<{ id: string }[]>>() + vi.fn<() => Promise>() ) +const mockReportError = vi.hoisted(() => vi.fn()) vi.mock('@/platform/workspace/api/workspaceApi', () => ({ workspaceApi: { @@ -13,6 +16,10 @@ vi.mock('@/platform/workspace/api/workspaceApi', () => ({ } })) +vi.mock('@/platform/telemetry/reportError', () => ({ + reportError: mockReportError +})) + async function flushLookup() { await Promise.resolve() await nextTick() @@ -28,7 +35,9 @@ describe('useHasSavedPaymentMethod', () => { }) it('resolves true when a payment method is on file', async () => { - mockListSavedPaymentMethods.mockResolvedValue([{ id: 'pm-1' }]) + mockListSavedPaymentMethods.mockResolvedValue([ + { id: 'pm-1', type: 'card', is_default: true } + ]) const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() await flushLookup() @@ -45,12 +54,16 @@ describe('useHasSavedPaymentMethod', () => { expect(hasSavedPaymentMethod.value).toBe(false) }) - it('stays unknown when the lookup fails', async () => { - mockListSavedPaymentMethods.mockRejectedValue(new Error('network')) + it('stays unknown and reports when the lookup fails', async () => { + const failure = new Error('network') + mockListSavedPaymentMethods.mockRejectedValue(failure) const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() await flushLookup() expect(hasSavedPaymentMethod.value).toBeNull() + expect(mockReportError).toHaveBeenCalledWith(failure, { + errorType: 'saved_payment_methods_read_failure' + }) }) }) diff --git a/src/platform/workspace/composables/useHasSavedPaymentMethod.ts b/src/platform/workspace/composables/useHasSavedPaymentMethod.ts index f047b351cf3..2ab83b887bb 100644 --- a/src/platform/workspace/composables/useHasSavedPaymentMethod.ts +++ b/src/platform/workspace/composables/useHasSavedPaymentMethod.ts @@ -1,6 +1,7 @@ import { ref } from 'vue' import { workspaceApi } from '@/platform/workspace/api/workspaceApi' +import { reportError } from '@/platform/telemetry/reportError' /** * Reports whether the active workspace has a saved payment method. @@ -14,7 +15,10 @@ export function useHasSavedPaymentMethod() { .then((methods) => { hasSavedPaymentMethod.value = methods.length > 0 }) - .catch(() => { + .catch((error) => { + reportError(error, { + errorType: 'saved_payment_methods_read_failure' + }) hasSavedPaymentMethod.value = null }) return { hasSavedPaymentMethod } From 495cdd14a1a74d16ce17ab32ad149ed29ffeeb7a Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 26 Aug 2026 20:49:15 +0000 Subject: [PATCH 5/7] =?UTF-8?q?test(billing):=20address=20review=20?= =?UTF-8?q?=E2=80=94=20portal=20failure=20coverage=20and=20typed=20mocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wait for popup navigation with toHaveURL; cover the billing-portal open failure (reportError + localized toast) in the component test; type the reportError mock from the production signature. --- .../dialogs/topUpNoPaymentMethod.spec.ts | 2 +- ...TopUpCreditsDialogContentWorkspace.test.ts | 33 ++++++++++++++++++- .../useHasSavedPaymentMethod.test.ts | 3 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts b/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts index 19220090ab7..8961c770fb8 100644 --- a/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts +++ b/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts @@ -77,7 +77,7 @@ test.describe('Top-up without a saved payment method', () => { page.context().waitForEvent('page'), topUpDialog.root.getByRole('button', { name: 'Manage billing' }).click() ]) - expect(portalPage.url()).toBe('https://billing.example/portal') + await expect(portalPage).toHaveURL('https://billing.example/portal') await portalPage.close() await topUpDialog.root.getByRole('button', { name: 'Pay $50.00' }).click() diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index e471b4ba206..9f0aedaf13a 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -11,7 +11,12 @@ import TopUpCreditsDialogContentWorkspace from './TopUpCreditsDialogContentWorks const mockFetchBalance = vi.fn() const mockFetchStatus = vi.fn() -const mockManageSubscription = vi.fn() +const mockManageSubscription = vi.fn<() => Promise>() +const mockReportError = vi.hoisted(() => vi.fn()) + +vi.mock('@/platform/telemetry/reportError', () => ({ + reportError: mockReportError +})) const mockTopup = vi.fn<(amountCents: number) => Promise>() const mockStartOperation = vi.fn() @@ -169,6 +174,8 @@ const i18n = createI18n({ "You'll be asked to add a payment method to complete this purchase.", noPaymentMethodError: 'No payment method is saved for this workspace. Add one via Settings → Plan & Credits → Manage billing, then retry the top-up.', + manageBillingError: + 'Failed to open the billing portal. Please try again.', confirmSubtitle: 'Credits are added to this workspace as soon as payment completes.', confirmTitle: 'Confirm', @@ -355,6 +362,30 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockManageSubscription).toHaveBeenCalledTimes(1) }) + it('reports and surfaces a billing-portal opening failure', async () => { + setHasSavedPaymentMethod(false) + const failure = new Error('portal down') + mockManageSubscription.mockRejectedValue(failure) + + renderDialog() + await clickAddCredits() + + await userEvent.click( + await screen.findByRole('button', { name: 'Manage billing' }) + ) + + await waitFor(() => + expect(mockReportError).toHaveBeenCalledWith(failure, { + errorType: 'billing_portal_open_failure' + }) + ) + expect(mockToastAdd).toHaveBeenCalledWith( + expect.objectContaining({ + summary: 'Failed to open the billing portal. Please try again.' + }) + ) + }) + it('explains how to add a payment method when the purchase is refused', async () => { setHasSavedPaymentMethod(false) mockTopup.mockRejectedValue( diff --git a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts index 2eecd379361..377be2ea1a1 100644 --- a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts +++ b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' +import type { reportError } from '@/platform/telemetry/reportError' import type { SavedPaymentMethod } from '@/platform/workspace/api/workspaceApi' import { useHasSavedPaymentMethod } from './useHasSavedPaymentMethod' @@ -8,7 +9,7 @@ import { useHasSavedPaymentMethod } from './useHasSavedPaymentMethod' const mockListSavedPaymentMethods = vi.hoisted(() => vi.fn<() => Promise>() ) -const mockReportError = vi.hoisted(() => vi.fn()) +const mockReportError = vi.hoisted(() => vi.fn()) vi.mock('@/platform/workspace/api/workspaceApi', () => ({ workspaceApi: { From dd0a85119a9a80e0ac7ba4e21cccb52db6a79f00 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 26 Aug 2026 22:24:11 +0000 Subject: [PATCH 6/7] refactor(billing): adopt useAsyncState and the real locale dict in tests useHasSavedPaymentMethod now wraps the lookup in useAsyncState so callers get error/isLoading/isReady/refresh alongside the tri-state flag. The component test renders the production en dict instead of a hand-written fixture, so copy drift now fails the test. --- ...TopUpCreditsDialogContentWorkspace.test.ts | 67 +++---------------- .../useHasSavedPaymentMethod.test.ts | 1 + .../composables/useHasSavedPaymentMethod.ts | 37 +++++----- 3 files changed, 32 insertions(+), 73 deletions(-) diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index 9f0aedaf13a..9f5955901de 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -4,6 +4,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' +import enMessages from '@/locales/en/main.json' with { type: 'json' } + import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi' import type { CreateTopupResponse } from '@/platform/workspace/api/workspaceApi' @@ -141,58 +143,7 @@ vi.mock('@/base/credits/comfyCredits', () => ({ const i18n = createI18n({ legacy: false, locale: 'en', - messages: { - en: { - g: { back: 'Back', close: 'Close' }, - subscription: { - addCredits: 'Add credits', - manageBilling: 'Manage billing', - preview: { - completeVerification: 'Complete verification', - totalDueToday: 'Total due today' - } - }, - credits: { - topUp: { - addMoreCredits: 'Add more credits', - addMoreCreditsToRun: 'Add more credits to run', - selectAmount: 'Select amount', - youPay: 'You pay', - youGet: 'You get', - purchaseSuccess: 'Credits added successfully!', - purchaseError: 'Purchase Failed', - purchaseErrorDetail: 'Failed to purchase credits: {error}', - unknownError: 'An unknown error occurred', - minRequired: 'Minimum required', - maxAllowed: 'Maximum allowed', - needMore: 'Need more?', - contactUs: 'Contact us', - viewPricing: 'View pricing', - insufficientWorkflowMessage: 'Insufficient credits', - chargedImmediatelyNote: 'Your saved card is charged immediately.', - paymentDetailsRequiredNote: - "You'll be asked to add a payment method to complete this purchase.", - noPaymentMethodError: - 'No payment method is saved for this workspace. Add one via Settings → Plan & Credits → Manage billing, then retry the top-up.', - manageBillingError: - 'Failed to open the billing portal. Please try again.', - confirmSubtitle: - 'Credits are added to this workspace as soon as payment completes.', - confirmTitle: 'Confirm', - payAmount: 'Pay {amount}', - verifyBody: - 'Your bank requires additional verification to complete this payment.', - verifyTitle: 'Verify your payment' - } - }, - billingOperation: { - authenticationFailedDetail: 'Verification failed.', - authenticationManagerRequired: 'Ask a workspace manager for help.', - retryVerification: 'Try verification again', - reconciliationDetail: 'Contact support with operation ID' - } - } - } + messages: { en: enMessages } }) function topupResponse( @@ -331,7 +282,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await clickAddCredits() expect( - await screen.findByText('Your saved card is charged immediately.') + await screen.findByText( + 'Your saved payment method is charged immediately.' + ) ).toBeInTheDocument() }) @@ -417,7 +370,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await clickAddCredits() expect( - await screen.findByText('Your saved card is charged immediately.') + await screen.findByText( + 'Your saved payment method is charged immediately.' + ) ).toBeInTheDocument() }) @@ -524,7 +479,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { screen.getByText('Your bank rejected the verification.') ).toBeInTheDocument() await userEvent.click( - screen.getByRole('button', { name: 'Try verification again' }) + screen.getByRole('button', { name: 'Retry verification' }) ) expect(mockRetryPaymentAuthentication).toHaveBeenCalledWith('op-retry') }) @@ -539,7 +494,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { renderDialog() expect( - screen.getByText('Contact support with operation ID') + screen.getByText(/Contact support and include this operation ID/) ).toBeInTheDocument() expect(screen.getByText('op-reconcile')).toBeInTheDocument() expect( diff --git a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts index 377be2ea1a1..edcdf41c66e 100644 --- a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts +++ b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts @@ -22,6 +22,7 @@ vi.mock('@/platform/telemetry/reportError', () => ({ })) async function flushLookup() { + await Promise.resolve() await Promise.resolve() await nextTick() } diff --git a/src/platform/workspace/composables/useHasSavedPaymentMethod.ts b/src/platform/workspace/composables/useHasSavedPaymentMethod.ts index 2ab83b887bb..7880a410946 100644 --- a/src/platform/workspace/composables/useHasSavedPaymentMethod.ts +++ b/src/platform/workspace/composables/useHasSavedPaymentMethod.ts @@ -1,25 +1,28 @@ -import { ref } from 'vue' +import { useAsyncState } from '@vueuse/core' +import { computed } from 'vue' -import { workspaceApi } from '@/platform/workspace/api/workspaceApi' import { reportError } from '@/platform/telemetry/reportError' +import { workspaceApi } from '@/platform/workspace/api/workspaceApi' /** * Reports whether the active workspace has a saved payment method. - * `null` until the lookup resolves, and stays `null` when it fails so - * callers fall back to their default copy instead of claiming certainty. + * `hasSavedPaymentMethod` is `null` until the lookup resolves, and stays + * `null` when it fails so callers fall back to their default copy instead + * of claiming certainty. */ export function useHasSavedPaymentMethod() { - const hasSavedPaymentMethod = ref(null) - void workspaceApi - .listSavedPaymentMethods() - .then((methods) => { - hasSavedPaymentMethod.value = methods.length > 0 - }) - .catch((error) => { - reportError(error, { - errorType: 'saved_payment_methods_read_failure' - }) - hasSavedPaymentMethod.value = null - }) - return { hasSavedPaymentMethod } + const { state, error, isLoading, isReady, execute } = useAsyncState( + () => workspaceApi.listSavedPaymentMethods(), + null, + { + onError: (lookupError) => + reportError(lookupError, { + errorType: 'saved_payment_methods_read_failure' + }) + } + ) + const hasSavedPaymentMethod = computed(() => + state.value === null ? null : state.value.length > 0 + ) + return { hasSavedPaymentMethod, error, isLoading, isReady, refresh: execute } } From dcce3fb9b8e234c456cadb49ce79ed55f325a39b Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 27 Aug 2026 18:07:31 +0000 Subject: [PATCH 7/7] fix(billing): gate the saved-card claim on a usable default method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hasSavedPaymentMethod now mirrors the top-up endpoint's predicate — a default method must exist, not just any saved method — and the confirm step withholds the payment-method note entirely while the lookup is unresolved instead of asserting a saved card without evidence. --- .../TopUpCreditsDialogContentWorkspace.test.ts | 13 ------------- .../TopUpCreditsDialogContentWorkspace.vue | 11 +++++++---- .../composables/useHasSavedPaymentMethod.test.ts | 11 +++++++++++ .../composables/useHasSavedPaymentMethod.ts | 12 +++++++----- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index 9f5955901de..1ec9222b7c2 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -363,19 +363,6 @@ describe('TopUpCreditsDialogContentWorkspace', () => { ) }) - it('keeps the saved-card note when the payment method lookup fails', async () => { - setHasSavedPaymentMethod(null) - - renderDialog() - await clickAddCredits() - - expect( - await screen.findByText( - 'Your saved payment method is charged immediately.' - ) - ).toBeInTheDocument() - }) - it('allows returning to amount selection before payment', async () => { renderDialog() await clickAddCredits() diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue index 3635d8b646a..cb03419f815 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue @@ -65,7 +65,10 @@ {{ displayTotal }} -

+

{{ paymentNote }}