From 47f1adddde458d6dd76c65b02f076125d06aa13b Mon Sep 17 00:00:00 2001 From: Dante Date: Thu, 15 Oct 2026 03:04:07 +0000 Subject: [PATCH] FE-3446 fix(billing): name the pending top-up instead of an unknown error (#21056) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Why In 1.57 QA on testcloud, a 3DS top-up whose verification failed left its operation `pending` (`authentication_state: failed_retryable`). Pressing **Add credits** again in the in-app top-up dialog then showed "Purchase failed: An unknown error occurred". Nothing was charged and no request was sent, but the message gives the customer no way to know what to do. ## Root cause Before issuing a top-up, the billing SDK reads the billing status. When the server already has a top-up pending, `resubmitTarget` in `operationLifecycle.ts` refuses the new one with `OPERATION_ALREADY_PENDING` and sends no `POST /api/billing/topup`. That guard is correct (one charge at a time). The problem is `topupFailureError` in `topupOperationView.ts`: it turns every SDK refusal into `credits.topUp.unknownError`. ## How - `topupFailureError` maps `OPERATION_ALREADY_PENDING` to a new top-up message, `billingOperation.topupAlreadyPendingDetail`, with failure category `stale_operation`. `subscriptionOperationView.ts` already does the same for subscriptions. Its existing string talks about choosing a plan, so top-ups get their own. - A unit test in `topupOperationView.test.ts` checks the message, code and failure category. It fails on `main`. No backport label: the 1.57 release doesn't strictly need this. ## AS IS / TO BE Local dev server against testcloud, signed in, in-app top-up dialog: Add credits → Verify your payment → Start over → Pay. To get a pending top-up without leaving a real stuck charge on a shared account, the page answered `GET /api/billing/status` with `pending_billing_op_id` + `pending_billing_op_type: topup` and `GET /api/billing/ops/` with the payload Chae reported (`pending`, `in_progress`, `failed_retryable`). Every non-GET billing request was blocked; none was attempted. AS IS = `topupOperationView.ts` from `main`, TO BE = this branch. | AS IS | TO BE | | --- | --- | | AS IS: Purchase Failed, An unknown error
occurred | TO BE: A top-up you started earlier is still
going through | ## Plan position | Item | Ticket | PR | Status | | --- | --- | --- | --- | | Capabilities read with unified_web_session off | FE-3441 | https://github.com/Comfy-Org/ComfyUI_frontend/pull/21004 | Merged | | **Pending top-up message in the in-app dialog** | **FE-3446** | **this PR** | **In review** | ```mermaid graph LR A["FE-3441 capabilities read (PR 21004)"] B["FE-3446 pending top-up message (this PR)"] style B fill:#ffd54f,stroke:#f57f17 ``` --- src/locales/en/main.json | 1 + .../billing/sdk/topupOperationView.test.ts | 17 +++++++++++++++++ .../workspace/billing/sdk/topupOperationView.ts | 12 ++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/locales/en/main.json b/src/locales/en/main.json index f0512f75077..1cfccbf34e1 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -3020,6 +3020,7 @@ "topupSuccess": "Credits added successfully", "topupFailed": "Top-up failed", "topupTimeout": "Top-up verification timed out", + "topupAlreadyPendingDetail": "A top-up you started earlier is still going through. Finish verifying it or wait for it to complete before adding more credits.", "paymentDeclinedDetail": "Your bank declined this payment. Try another payment method or contact your bank.", "insufficientFundsDetail": "This payment method has insufficient funds. Try another payment method or contact your bank.", "expiredCardDetail": "This card has expired. Use a different payment method.", diff --git a/src/platform/workspace/billing/sdk/topupOperationView.test.ts b/src/platform/workspace/billing/sdk/topupOperationView.test.ts index 40bc237e5f6..1f619ed0f23 100644 --- a/src/platform/workspace/billing/sdk/topupOperationView.test.ts +++ b/src/platform/workspace/billing/sdk/topupOperationView.test.ts @@ -116,6 +116,23 @@ describe('projectTopupResult', () => { ) }) + it('names the earlier top-up still settling instead of an unknown error', () => { + expect(() => + projectTopupResult( + { status: 'error', code: 'OPERATION_ALREADY_PENDING' }, + 1000 + ) + ).toThrow( + expect.objectContaining({ + name: 'WorkspaceApiError', + code: 'OPERATION_ALREADY_PENDING', + failureCategory: 'stale_operation', + message: + 'A top-up you started earlier is still going through. Finish verifying it or wait for it to complete before adding more credits.' + }) + ) + }) + it('carries the HTTP status of a transport failure', () => { let thrown: unknown try { diff --git a/src/platform/workspace/billing/sdk/topupOperationView.ts b/src/platform/workspace/billing/sdk/topupOperationView.ts index 3a96a41db05..b47f9be8e69 100644 --- a/src/platform/workspace/billing/sdk/topupOperationView.ts +++ b/src/platform/workspace/billing/sdk/topupOperationView.ts @@ -90,11 +90,15 @@ export class UncreditedTopupResponse implements CreateTopupResponse { ) {} } -/** - * Most SDK refusals carry no HTTP status, which a status-less API error - * would otherwise report as a network failure, so each names its category. - */ function topupFailureError(failure: TopupFailure): WorkspaceApiError { + if (failure.code === 'OPERATION_ALREADY_PENDING') { + return new WorkspaceApiError( + t('billingOperation.topupAlreadyPendingDetail'), + undefined, + failure.code, + 'stale_operation' + ) + } const serverCode = 'serverCode' in failure ? failure.serverCode : undefined return new WorkspaceApiError( t('credits.topUp.unknownError'),