diff --git a/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts b/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts index 8961c770fb8..ec6f9facded 100644 --- a/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts +++ b/browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts @@ -1,20 +1,14 @@ 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' /** * 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). + * 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 @@ -32,25 +26,13 @@ test.describe('Top-up without a saved payment method', () => { return topUpDialog } - test('offers Manage billing and explains a refused purchase', async ({ - comfyPage - }) => { + test('explains a refused purchase', async ({ comfyPage }) => { const page = comfyPage.page - await page.route('**/api/billing/payment-methods', (route) => - 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' }) - ) + const paymentMethodReads: string[] = [] + await page.route('**/api/billing/payment-methods', (route) => { + paymentMethodReads.push(route.request().url()) + return route.fulfill({ json: [] }) + }) await page.route('**/api/billing/topup', (route) => route.fulfill({ status: 400, @@ -68,18 +50,7 @@ test.describe('Top-up without a saved payment method', () => { .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() - const [portalPage] = await Promise.all([ - page.context().waitForEvent('page'), - topUpDialog.root.getByRole('button', { name: 'Manage billing' }).click() - ]) - await expect(portalPage).toHaveURL('https://billing.example/portal') - await portalPage.close() - + expect(paymentMethodReads).toHaveLength(0) await topUpDialog.root.getByRole('button', { name: 'Pay $50.00' }).click() await expect( @@ -88,38 +59,4 @@ test.describe('Top-up without a saved payment method', () => { .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', - type: 'card', - brand: 'visa', - last4: '4242', - is_default: true - } - ] satisfies SavedPaymentMethod[] - }) - ) - - 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) - }) }) diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 1c35cd22d3a..a69ed605559 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -2742,10 +2742,7 @@ "addMoreCreditsToRun": "Add more credits to run", "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.", "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 b2f4144e93f..3d794d8902c 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -27,13 +27,6 @@ import TopUpCreditsDialogContentWorkspace from './TopUpCreditsDialogContentWorks const mockFetchBalance = vi.fn() const mockFetchStatus = vi.fn() -const mockManageSubscription = vi.fn<() => Promise>() -const mockReportError = vi.hoisted(() => vi.fn()) - -vi.mock('@/platform/telemetry/reportError', () => ({ - reportError: mockReportError -})) - vi.mock(import('firebase/auth'), { spy: true }) const mockTopup = vi.fn<(amountCents: number) => Promise>() @@ -60,23 +53,6 @@ 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' @@ -98,7 +74,6 @@ vi.mock('@/composables/billing/useBillingContext', () => ({ useBillingContext: () => ({ fetchBalance: mockFetchBalance, fetchStatus: mockFetchStatus, - manageSubscription: mockManageSubscription, topup: (amountCents: number) => mockTopup(amountCents) }) })) @@ -221,13 +196,6 @@ 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' })) @@ -251,7 +219,6 @@ describe('TopUpCreditsDialogContentWorkspace', () => { setTopupActionOperation(undefined) mockFetchBalance.mockResolvedValue(undefined) mockFetchStatus.mockResolvedValue(undefined) - setHasSavedPaymentMethod(true) mockStartOperation.mockImplementation(() => { setIsAddingCredits(true) return new Promise(() => {}) @@ -393,71 +360,7 @@ 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 payment method 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('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('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( new WorkspaceApiError( 'No default payment method is selected.', diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue index 82d11f14f96..4a325c95241 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue @@ -65,19 +65,6 @@ {{ displayTotal }} -

- {{ paymentNote }} - -

@@ -300,10 +287,8 @@ import { isCloud } from '@/platform/distribution/types' import type { CheckoutJourneyPhaseEvent } from '@/platform/telemetry/types' 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' import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { @@ -330,8 +315,7 @@ const settingsDialog = useSettingsDialog() const telemetry = useTelemetry() const toast = useToast() const { buildDocsUrl, docsPaths } = useExternalLink() -const { fetchBalance, fetchStatus, manageSubscription, topup } = - useBillingContext() +const { fetchBalance, fetchStatus, topup } = useBillingContext() const { canTopUp } = useBillingCapabilities() const billingOperationStore = useBillingOperationStore() @@ -403,19 +387,11 @@ 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 - ? t('credits.topUp.chargedImmediatelyNote') - : t('credits.topUp.paymentDetailsRequiredNote') -) - const creditsModel = computed({ get: () => usdToCredits(payAmount.value), set: (newCredits: number) => { @@ -498,17 +474,6 @@ function handlePrimaryAction() { void handleBuy() } -function openManageBilling() { - void manageSubscription().catch((error) => { - reportError(error, { errorType: 'billing_portal_open_failure' }) - toast.add({ - severity: 'error', - summary: t('credits.topUp.manageBillingError'), - life: 5000 - }) - }) -} - function openTopupVerification() { if (!topupActionUrl.value) return window.open(topupActionUrl.value, '_blank', 'noopener,noreferrer') diff --git a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts b/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts deleted file mode 100644 index ff1e20590cc..00000000000 --- a/src/platform/workspace/composables/useHasSavedPaymentMethod.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -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' - -const mockListSavedPaymentMethods = vi.hoisted(() => - vi.fn<() => Promise>() -) -const mockReportError = vi.hoisted(() => vi.fn()) - -vi.mock('@/platform/workspace/api/workspaceApi', () => ({ - workspaceApi: { - listSavedPaymentMethods: mockListSavedPaymentMethods - } -})) - -vi.mock('@/platform/telemetry/reportError', () => ({ - reportError: mockReportError -})) - -async function flushLookup() { - await Promise.resolve() - 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', type: 'card', is_default: true } - ]) - - const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() - await flushLookup() - - expect(hasSavedPaymentMethod.value).toBe(true) - }) - - it('resolves false when only non-default methods are saved', async () => { - mockListSavedPaymentMethods.mockResolvedValue([ - { id: 'pm-1', type: 'card', is_default: false } - ]) - - const { hasSavedPaymentMethod } = useHasSavedPaymentMethod() - await flushLookup() - - expect(hasSavedPaymentMethod.value).toBe(false) - }) - - 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 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 deleted file mode 100644 index 2f904cecdc6..00000000000 --- a/src/platform/workspace/composables/useHasSavedPaymentMethod.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { useAsyncState } from '@vueuse/core' -import { computed } from 'vue' - -import { reportError } from '@/platform/telemetry/reportError' -import { workspaceApi } from '@/platform/workspace/api/workspaceApi' - -/** - * Reports whether the active workspace has a usable (default) saved payment - * method — the same predicate the top-up endpoint enforces. It is `null` - * until the lookup resolves, and stays `null` when it fails so callers can - * withhold payment-method claims instead of asserting one. - */ -export function useHasSavedPaymentMethod() { - 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.some((method) => method.is_default) - ) - return { hasSavedPaymentMethod, error, isLoading, isReady, refresh: execute } -}