From 2aad3b12110aa6f14321f749ff22cf50f034f017 Mon Sep 17 00:00:00 2001 From: comfydesigner Date: Tue, 25 Aug 2026 17:01:04 -0700 Subject: [PATCH 1/5] feat(billing): declined outcome step for a refused checkout charge --- src/locales/en/main.json | 6 ++ .../SubscriptionDeclinedWorkspace.test.ts | 49 ++++++++++++++ .../SubscriptionDeclinedWorkspace.vue | 64 +++++++++++++++++++ ...bscriptionRequiredDialogContentUnified.vue | 30 ++++++++- .../composables/useSubscriptionCheckout.ts | 19 ++++++ 5 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 src/platform/workspace/components/SubscriptionDeclinedWorkspace.test.ts create mode 100644 src/platform/workspace/components/SubscriptionDeclinedWorkspace.vue diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 25e31602975..f132cd4df1b 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -3136,6 +3136,12 @@ "addNewPaymentMethod": "Add new payment method", "alipay": "Alipay" }, + "declined": { + "title": "Payment declined", + "body": "Your card couldn't be charged. Try another card, or contact your bank if this looks wrong.", + "reasonLabel": "Stripe reasoning:", + "updatePaymentMethod": "Update payment method" + }, "success": { "allSet": "You're all set", "inviteEmailsPlaceholder": "Enter emails separated by commas", diff --git a/src/platform/workspace/components/SubscriptionDeclinedWorkspace.test.ts b/src/platform/workspace/components/SubscriptionDeclinedWorkspace.test.ts new file mode 100644 index 00000000000..31edb50b787 --- /dev/null +++ b/src/platform/workspace/components/SubscriptionDeclinedWorkspace.test.ts @@ -0,0 +1,49 @@ +import { render, screen } from '@testing-library/vue' +import userEvent from '@testing-library/user-event' +import { describe, expect, it } from 'vitest' +import { createI18n } from 'vue-i18n' + +import enMessages from '@/locales/en/main.json' + +import SubscriptionDeclinedWorkspace from './SubscriptionDeclinedWorkspace.vue' + +const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { en: enMessages } +}) + +function renderDeclined(declineReason: string | null = null) { + return render(SubscriptionDeclinedWorkspace, { + props: { declineReason }, + global: { plugins: [i18n] } + }) +} + +describe('SubscriptionDeclinedWorkspace', () => { + it('shows the Stripe reason when the API provides one', () => { + renderDeclined('Insufficient funds') + + expect(screen.getByText('Stripe reasoning:')).toBeInTheDocument() + expect(screen.getByText('Insufficient funds')).toBeInTheDocument() + }) + + it('omits the reason block entirely when there is none', () => { + renderDeclined(null) + + expect(screen.queryByText('Stripe reasoning:')).toBeNull() + expect(screen.getByText('Payment declined')).toBeInTheDocument() + }) + + it('offers a retry rather than ending the flow', async () => { + const { emitted } = renderDeclined('Card declined') + + await userEvent.click( + screen.getByRole('button', { name: 'Update payment method' }) + ) + expect(emitted().updatePayment).toBeTruthy() + + await userEvent.click(screen.getByRole('button', { name: 'Back' })) + expect(emitted().back).toBeTruthy() + }) +}) diff --git a/src/platform/workspace/components/SubscriptionDeclinedWorkspace.vue b/src/platform/workspace/components/SubscriptionDeclinedWorkspace.vue new file mode 100644 index 00000000000..c393d942058 --- /dev/null +++ b/src/platform/workspace/components/SubscriptionDeclinedWorkspace.vue @@ -0,0 +1,64 @@ + + + diff --git a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue index 76aad4c4b9c..8888dcabfad 100644 --- a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue +++ b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue @@ -12,12 +12,16 @@ // panel stays fixed; below xl the whole dialog scrolls as before. isEmbeddedPaymentStep && 'xl:h-[min(740px,90vh)] xl:gap-0 xl:overflow-hidden xl:rounded-2xl xl:p-0', - (isEmbeddedSuccessStep || isEmbeddedConfirmStep || isVerifyingStep) && + (isEmbeddedSuccessStep || + isEmbeddedConfirmStep || + isVerifyingStep || + isDeclinedStep) && 'h-[min(740px,85vh)] overflow-hidden rounded-2xl bg-base-background xl:h-[min(740px,90vh)] xl:w-[512px]', (isEmbeddedPaymentStep || isEmbeddedSuccessStep || isEmbeddedConfirmStep || - isVerifyingStep) && + isVerifyingStep || + isDeclinedStep) && 'motion-safe:xl:transition-[width] motion-safe:xl:duration-300 motion-safe:xl:ease-in-out', // The w-fit shell hugs min-content on phones; give the embedded // steps a real width floor below xl. @@ -64,7 +68,8 @@ !isEmbeddedPaymentStep && !isEmbeddedSuccessStep && !isEmbeddedConfirmStep && - !isVerifyingStep + !isVerifyingStep && + !isDeclinedStep " class="flex flex-col items-center gap-3" > @@ -221,6 +226,13 @@ @cancel-payment="handleCancelPendingPayment" /> + + checkoutStep.value === 'verifying') +const isDeclinedStep = computed(() => checkoutStep.value === 'declined') + +// The decline CTA returns to confirm and opens method collection, which is +// dialog state rather than checkout state. +function handleDeclinedUpdatePayment() { + handleUpdatePayment() + selectSavedPaymentMethod(null) +} onMounted(() => { if (!initialCheckout) return diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.ts b/src/platform/workspace/composables/useSubscriptionCheckout.ts index cfaa2a41c22..6b295616ff0 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.ts @@ -883,6 +883,22 @@ export function useSubscriptionCheckout( emit('close', true) } + // Declined is not terminal: back returns to the confirm step with the quote + // and selection intact so the same charge can be retried. + function handleDeclinedBack() { + checkoutDeclineReason.value = null + const opId = activeCheckoutOperation.value?.opId + if (opId) billingOperationStore.clearOperation(opId) + checkoutStep.value = 'preview' + } + + // "Update payment method" lands on the same confirm step; the caller decides + // to collect a new method rather than reuse the one the bank refused, since + // that selection lives with the dialog. + function handleUpdatePayment() { + handleDeclinedBack() + } + async function handleSubscription( confirmReactivation = false, confirmationToken?: string, @@ -1582,6 +1598,9 @@ export function useSubscriptionCheckout( return { checkoutStep, + checkoutDeclineReason, + handleDeclinedBack, + handleUpdatePayment, isLoadingPreview, loadingTier, isSubscribing, From 6c35adba99cdca1086cd7cd6105851150fdf373c Mon Sep 17 00:00:00 2001 From: comfydesigner Date: Tue, 25 Aug 2026 17:45:48 -0700 Subject: [PATCH 2/5] fix(billing): give the declined step the same mobile width floor as its siblings --- .../components/SubscriptionRequiredDialogContentUnified.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue index 8888dcabfad..2b1d43f1bb8 100644 --- a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue +++ b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue @@ -28,7 +28,8 @@ (isEmbeddedPaymentStep || isEmbeddedSuccessStep || isEmbeddedConfirmStep || - isVerifyingStep) && + isVerifyingStep || + isDeclinedStep) && 'max-xl:w-[min(430px,92vw)]', isEmbeddedPaymentStep && 'max-xl:h-[85vh]' ) From eae89152f0aaa72ae427e9380934914e3a4c4114 Mon Sep 17 00:00:00 2001 From: comfydesigner Date: Tue, 25 Aug 2026 17:50:35 -0700 Subject: [PATCH 3/5] fix(billing): cap the embedded payment step at the same height as its siblings below xl --- .../components/SubscriptionRequiredDialogContentUnified.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue index 2b1d43f1bb8..56b08fed1bf 100644 --- a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue +++ b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue @@ -31,7 +31,7 @@ isVerifyingStep || isDeclinedStep) && 'max-xl:w-[min(430px,92vw)]', - isEmbeddedPaymentStep && 'max-xl:h-[85vh]' + isEmbeddedPaymentStep && 'max-xl:h-[min(740px,85vh)]' ) " > From f3600d47db82b8f228031b58b62d5c49c9386804 Mon Sep 17 00:00:00 2001 From: comfydesigner Date: Wed, 2 Sep 2026 13:14:11 -0700 Subject: [PATCH 4/5] fix(billing): a recovered decline backs out to plan selection --- src/locales/en/main.json | 2 +- .../SubscriptionDeclinedWorkspace.test.ts | 4 ++-- ...bscriptionRequiredDialogContentUnified.vue | 11 ++++++--- .../useSubscriptionCheckout.test.ts | 23 +++++++++++++++++++ .../composables/useSubscriptionCheckout.ts | 15 ++++-------- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 91633a1e9c9..05f75d7fa99 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -3153,7 +3153,7 @@ "declined": { "title": "Payment declined", "body": "Your card couldn't be charged. Try another card, or contact your bank if this looks wrong.", - "reasonLabel": "Stripe reasoning:", + "reasonLabel": "What your bank said", "updatePaymentMethod": "Update payment method" }, "success": { diff --git a/src/platform/workspace/components/SubscriptionDeclinedWorkspace.test.ts b/src/platform/workspace/components/SubscriptionDeclinedWorkspace.test.ts index 31edb50b787..13a6f68dc40 100644 --- a/src/platform/workspace/components/SubscriptionDeclinedWorkspace.test.ts +++ b/src/platform/workspace/components/SubscriptionDeclinedWorkspace.test.ts @@ -24,14 +24,14 @@ describe('SubscriptionDeclinedWorkspace', () => { it('shows the Stripe reason when the API provides one', () => { renderDeclined('Insufficient funds') - expect(screen.getByText('Stripe reasoning:')).toBeInTheDocument() + expect(screen.getByText('What your bank said')).toBeInTheDocument() expect(screen.getByText('Insufficient funds')).toBeInTheDocument() }) it('omits the reason block entirely when there is none', () => { renderDeclined(null) - expect(screen.queryByText('Stripe reasoning:')).toBeNull() + expect(screen.queryByText('What your bank said')).toBeNull() expect(screen.getByText('Payment declined')).toBeInTheDocument() }) diff --git a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue index 2586c9d4953..5711e7eaf4d 100644 --- a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue +++ b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue @@ -79,7 +79,13 @@ -
+

{{ $t('credits.topUp.insufficientTitle') }}

@@ -300,7 +306,6 @@ const { checkoutStep, checkoutDeclineReason, handleDeclinedBack, - handleUpdatePayment, isCancelingPayment, cancelUnavailable, cancelUnreachable, @@ -397,7 +402,7 @@ const isDeclinedStep = computed(() => checkoutStep.value === 'declined') // The decline CTA returns to confirm and opens method collection, which is // dialog state rather than checkout state. function handleDeclinedUpdatePayment() { - handleUpdatePayment() + handleDeclinedBack() selectSavedPaymentMethod(null) } diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index ee3b25e9929..19c58f21e05 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -163,6 +163,7 @@ const { mockStartOperation, mockRetryPaymentAuthentication, mockGetOperation, + mockClearOperation, mockCancelOperation, mockSubscriptionActionOperation, mockListSavedPaymentMethods, @@ -194,6 +195,7 @@ const { mockStartOperation: vi.fn(), mockRetryPaymentAuthentication: vi.fn(), mockGetOperation: vi.fn(), + mockClearOperation: vi.fn(), mockCancelOperation: vi.fn(), mockSubscriptionActionOperation: { value: undefined as MockSubscriptionActionOperation | undefined @@ -354,6 +356,7 @@ vi.mock('@/platform/workspace/stores/billingOperationStore', () => ({ retryPaymentAuthentication: mockRetryPaymentAuthentication, getOperation: mockGetOperation, cancelOperation: mockCancelOperation, + clearOperation: mockClearOperation, get subscriptionActionOperation() { return mockSubscriptionActionOperation.value } @@ -2648,6 +2651,26 @@ describe('useSubscriptionCheckout', () => { expect(checkout.checkoutStep.value).toBe('declined') }) + it('backs out of an in-flow decline to the preserved preview', async () => { + const checkout = await setupWithApprovedPreview() + + checkout.checkoutStep.value = 'declined' + checkout.handleDeclinedBack() + + expect(checkout.checkoutStep.value).toBe('preview') + }) + + it('backs out of a recovered decline to plan selection, not a blank preview', async () => { + const checkout = await reentryOn('failed', { + errorMessage: 'Insufficient funds' + }) + + checkout.handleDeclinedBack() + + expect(checkout.checkoutStep.value).toBe('pricing') + expect(checkout.checkoutDeclineReason.value).toBeNull() + }) + it('closes on success when there is no plan selection to show', async () => { await reentryOn('succeeded') diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.ts b/src/platform/workspace/composables/useSubscriptionCheckout.ts index d2ff42cebae..3cb3e63d4ad 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.ts @@ -930,19 +930,15 @@ export function useSubscriptionCheckout( } // Declined is not terminal: back returns to the confirm step with the quote - // and selection intact so the same charge can be retried. + // and selection intact so the same charge can be retried. A decline reached + // on re-entry has no preserved quote to land on — plan selection is the only + // step that can host it. function handleDeclinedBack() { checkoutDeclineReason.value = null const opId = activeCheckoutOperation.value?.opId if (opId) billingOperationStore.clearOperation(opId) - checkoutStep.value = 'preview' - } - - // "Update payment method" lands on the same confirm step; the caller decides - // to collect a new method rather than reuse the one the bank refused, since - // that selection lives with the dialog. - function handleUpdatePayment() { - handleDeclinedBack() + activeCheckoutOperationId.value = null + checkoutStep.value = previewData.value ? 'preview' : 'pricing' } async function handleSubscription( @@ -1660,7 +1656,6 @@ export function useSubscriptionCheckout( checkoutStep, checkoutDeclineReason, handleDeclinedBack, - handleUpdatePayment, isLoadingPreview, loadingTier, isSubscribing, From e28322005f5a4f3d09b63125243004fc7b1fd8cf Mon Sep 17 00:00:00 2001 From: comfydesigner Date: Wed, 2 Sep 2026 13:22:12 -0700 Subject: [PATCH 5/5] feat(billing): the declined step and its transition live together here --- .../composables/useSubscriptionCheckout.test.ts | 4 ++-- .../workspace/composables/useSubscriptionCheckout.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 9c0a0808d03..19c58f21e05 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -2643,12 +2643,12 @@ describe('useSubscriptionCheckout', () => { return checkout } - it('returns to plan selection when the recovered charge fails', async () => { + it('reaches the declined step instead of returning to pricing', async () => { const checkout = await reentryOn('failed', { errorMessage: 'Insufficient funds' }) - expect(checkout.checkoutStep.value).toBe('pricing') + expect(checkout.checkoutStep.value).toBe('declined') }) it('backs out of an in-flow decline to the preserved preview', async () => { diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.ts b/src/platform/workspace/composables/useSubscriptionCheckout.ts index ab89fd016f3..3cb3e63d4ad 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.ts @@ -39,7 +39,7 @@ import { } from '@/platform/workspace/utils/pendingSubscriptionCheckout' import { trackWorkspaceCheckoutStarted } from '@/platform/workspace/utils/workspaceCheckoutTelemetry' -type CheckoutStep = 'pricing' | 'preview' | 'verifying' | 'success' +type CheckoutStep = 'pricing' | 'preview' | 'verifying' | 'success' | 'declined' export type CheckoutTierKey = Exclude export type SubscriptionCheckoutSelection = @@ -164,6 +164,7 @@ export function useSubscriptionCheckout( ? 'verifying' : 'pricing' ) + const checkoutDeclineReason = ref(null) const isCancelingPayment = ref(false) const cancelUnavailable = ref(false) const cancelUnreachable = ref(false) @@ -1447,10 +1448,9 @@ export function useSubscriptionCheckout( return } if (status === 'failed') { - // The declined outcome step arrives one PR up; until it does, the - // store's failure toast carries the verdict and the dialog returns - // to plan selection. - checkoutStep.value = 'pricing' + checkoutDeclineReason.value = + activeCheckoutOperation.value?.errorMessage ?? null + checkoutStep.value = 'declined' return } if (status === undefined) {