Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 补充后台支付恢复入口

liugaowei79405af01c10
diff --git a/apps/desktop/src/renderer/features/billing/BillingPage.tsx b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
index 7ae192782b..6393b2456a 100644
--- a/apps/desktop/src/renderer/features/billing/BillingPage.tsx
+++ b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
@@ -294,6 +294,13 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
[loadBillingState, loadSubscription],
);
const planChange = usePlanChange(accountId, handlePlanChangeSettled);
+ const hasRecoverableFailedIntent =
+ !checkout.state.open &&
+ checkout.state.phase === 'FAILED' &&
+ checkout.state.error &&
+ checkout.state.intent !== null &&
+ checkout.state.order === null &&
+ checkout.state.subscription === null;
const offers = useMemo<PurchasableOffer[]>(() => {
if (!catalog) return [];
@@ -580,12 +587,15 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
{!checkout.recovering &&
(checkout.recoverables.topups.length > 0 ||
- checkout.recoverables.subscription !== null) && (
+ checkout.recoverables.subscription !== null ||
+ hasRecoverableFailedIntent) && (
<BillingRecoveryNotice
topups={checkout.recoverables.topups}
subscription={checkout.recoverables.subscription}
+ failedIntent={hasRecoverableFailedIntent}
onResumeTopup={checkout.resumeTopup}
onResumeSubscription={checkout.resumeSubscription}
+ onResumeFailed={checkout.resumeFailed}
/>
)}
@@ -691,13 +701,17 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
function BillingRecoveryNotice({
topups,
subscription,
+ failedIntent,
onResumeTopup,
onResumeSubscription,
+ onResumeFailed,
}: {
topups: BillingPaymentOrder[];
subscription: BillingSubscription | null;
+ failedIntent: boolean;
onResumeTopup: (order: BillingPaymentOrder) => void;
onResumeSubscription: (subscription: BillingSubscription) => void;
+ onResumeFailed: () => void;
}) {
const { t } = useTranslation();
return (
@@ -730,6 +744,15 @@ function BillingRecoveryNotice({
{t('billing.recovery.continueSubscription')}
</button>
)}
+ {failedIntent && (
+ <button
+ type="button"
+ onClick={onResumeFailed}
+ className="select-none rounded-full border border-[var(--border-default)] px-3 py-1.5 text-12 font-medium transition-colors hover:bg-[var(--surface-hover-soft)]"
+ >
+ {t('billing.recovery.continueFailed')}
+ </button>
+ )}
</div>
</section>
);
diff --git a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
index a23ff44ed6..38362af6bc 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
+++ b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
@@ -28,6 +28,7 @@ const checkout = {
close: vi.fn(),
resumeTopup: vi.fn(),
resumeSubscription: vi.fn(),
+ resumeFailed: vi.fn(),
};
vi.mock('react-i18next', () => ({
@@ -81,6 +82,7 @@ describe('BillingPage remote catalog rendering', () => {
checkout.close.mockClear();
checkout.resumeTopup.mockClear();
checkout.resumeSubscription.mockClear();
+ checkout.resumeFailed.mockClear();
checkout.recoverables.topups = [];
checkout.recoverables.subscription = null;
checkout.recovering = false;
@@ -408,6 +410,40 @@ describe('BillingPage remote catalog rendering', () => {
expect(checkout.resumeTopup).toHaveBeenCalledWith(order);
});
+ it('offers a user-initiated retry entry after background recovery fails', async () => {
+ Object.assign(checkout.state, {
+ open: false,
+ kind: 'TOPUP',
+ phase: 'FAILED',
+ intent: {
+ version: 1,
+ kind: 'TOPUP',
+ idempotencyKey: 'desktop:topup:uncertain',
+ request: {
+ offerCode: 'credit_topup_custom',
+ amount: '10',
+ purchaseOptionId: 'listing_alipay',
+ },
+ orderId: null,
+ createdAt: '2026-07-24T00:00:00.000Z',
+ },
+ order: null,
+ subscription: null,
+ error: true,
+ });
+
+ render(<BillingPage />);
+
+ const resume = screen.getByText('billing.recovery.continueFailed');
+ const balanceTitle = await screen.findByText('billing.balance.title');
+ expect(resume.compareDocumentPosition(balanceTitle) & Node.DOCUMENT_POSITION_FOLLOWING).toBe(
+ Node.DOCUMENT_POSITION_FOLLOWING,
+ );
+ fireEvent.click(resume);
+ expect(checkout.resumeFailed).toHaveBeenCalledTimes(1);
+ expect(checkout.retry).not.toHaveBeenCalled();
+ });
+
it('shows usage progress and each promotional grant with its own state and expiry', async () => {
window.electronAPI.billing.getCreditUsage = vi.fn(async () => ({
available: '66',
diff --git a/apps/desktop/src/renderer/features/billing/__tests__/useBillingCheckout.test.ts b/apps/desktop/src/renderer/features/billing/__tests__/useBillingCheckout.test.ts
index c5c5706fe3..80d3523ad9 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/useBillingCheckout.test.ts
+++ b/apps/desktop/src/renderer/features/billing/__tests__/useBillingCheckout.test.ts
@@ -453,6 +453,14 @@ describe('billing checkout phase projection', () => {
error: true,
});
expect(readBillingCheckoutIntent(ACCOUNT_ID)).toEqual(intent);
+
+ act(() => result.current.resumeFailed());
+ expect(result.current.state).toMatchObject({
+ open: true,
+ phase: 'FAILED',
+ intent,
+ error: true,
+ });
expect(readBillingCheckoutIntent(ACCOUNT_ID)).toEqual(intent);
});
diff --git a/apps/desktop/src/renderer/features/billing/useBillingCheckout.ts b/apps/desktop/src/renderer/features/billing/useBillingCheckout.ts
index 3496a2045e..02632fdc95 100644
--- a/apps/desktop/src/renderer/features/billing/useBillingCheckout.ts
+++ b/apps/desktop/src/renderer/features/billing/useBillingCheckout.ts
@@ -461,6 +461,22 @@ export function useBillingCheckout(accountId: string | null) {
[applySubscription],
);
+ const resumeFailed = useCallback(() => {
+ setState((current) => {
+ if (
+ current.open ||
+ current.phase !== 'FAILED' ||
+ !current.error ||
+ !current.intent ||
+ current.order ||
+ current.subscription
+ ) {
+ return current;
+ }
+ return { ...current, open: true };
+ });
+ }, []);
+
useEffect(() => {
mountedRef.current = true;
if (!accountId) {
@@ -589,6 +605,7 @@ export function useBillingCheckout(accountId: string | null) {
close,
resumeTopup,
resumeSubscription,
+ resumeFailed,
};
}
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 97cabddf57..87949ca663 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -6937,8 +6937,8 @@
"unnamedPlan": "Subscription plan",
"unavailable": "Subscription status is temporarily unavailable. Refresh to try again.",
"action": "View plans",
- "changeAction": "Change Plan",
- "purchaseAnother": "Buy New Subscription",
+ "changeAction": "Change plan",
+ "purchaseAnother": "Buy new subscription",
"priceInterval": "{{price}} / {{interval}}",
"includedCredits": "Includes {{amount}} credits per {{interval}}",
"renewsAt": "Renews {{date}}",
@@ -7105,7 +7105,8 @@
"title": "Unfinished payment found",
"description": "Continue the previous payment and confirm its latest state with the server.",
"continueTopup": "Continue {{amount}} payment",
- "continueSubscription": "Continue subscription payment"
+ "continueSubscription": "Continue subscription payment",
+ "continueFailed": "Continue interrupted payment"
},
"checkout": {
"creatingTitle": "Creating payment",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 3067f7a876..d753fa399d 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -7094,7 +7094,8 @@
"title": "未完了の支払いがあります",
"description": "前回の支払いを続け、最新状態をサーバーで確認できます。",
"continueTopup": "{{amount}}の支払いを続ける",
- "continueSubscription": "サブスクリプションの支払いを続ける"
+ "continueSubscription": "サブスクリプションの支払いを続ける",
+ "continueFailed": "中断した支払いを続ける"
},
"checkout": {
"creatingTitle": "支払いを作成中",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index e490e382a0..8d37e129e7 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -7094,7 +7094,8 @@
"title": "완료되지 않은 결제가 있습니다",
"description": "이전 결제를 계속하고 서버에서 최신 상태를 확인할 수 있습니다.",
"continueTopup": "{{amount}} 결제 계속",
- "continueSubscription": "구독 결제 계속"
+ "continueSubscription": "구독 결제 계속",
+ "continueFailed": "중단된 결제 계속"
},
"checkout": {
"creatingTitle": "결제 생성 중",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index be170e0cc0..708c52269b 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -7094,7 +7094,8 @@
"title": "发现未完成的支付",
"description": "你可以继续上次的支付,状态将从服务端重新确认。",
"continueTopup": "继续支付 {{amount}}",
- "continueSubscription": "继续订阅支付"
+ "continueSubscription": "继续订阅支付",
+ "continueFailed": "继续未完成的支付"
},
"checkout": {
"creatingTitle": "正在创建支付",