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。

feat(billing): 支持恢复已取消订阅

liugaoweibbb1bb0367ab
diff --git a/apps/desktop/src/main/billing/__tests__/index.test.ts b/apps/desktop/src/main/billing/__tests__/index.test.ts
index aa0204b4e3..86b7cc202e 100644
--- a/apps/desktop/src/main/billing/__tests__/index.test.ts
+++ b/apps/desktop/src/main/billing/__tests__/index.test.ts
@@ -280,6 +280,48 @@ describe('billing IPC', () => {
});
});
+ it('resumes the current subscription through one fixed provider-neutral POST', async () => {
+ const { call, fetch } = harness();
+ const resumed = {
+ subscriptionId: 'subscription_1',
+ status: 'ACTIVE',
+ currentPeriodStartAt: '2026-07-01T00:00:00.000Z',
+ currentPeriodEndAt: '2026-08-01T00:00:00.000Z',
+ entitlementValidUntil: '2026-08-02T00:00:00.000Z',
+ cancelAtPeriodEnd: false,
+ resumable: false,
+ effectivePlan: null,
+ purchaseAttemptId: null,
+ paymentAction: null,
+ };
+ fetch.mockResolvedValueOnce(resumed);
+
+ await expect(call(BILLING_INVOKE.RESUME_CURRENT_SUBSCRIPTION)).resolves.toEqual(resumed);
+ expect(fetch).toHaveBeenCalledWith('/api/billing/subscription/resume', {
+ baseUrl: expect.any(Function),
+ timeoutMs: 20_000,
+ redactErrorDetails: true,
+ method: 'POST',
+ allowedRedactedErrorCodes: ['RESUME_NOT_AVAILABLE'],
+ });
+ });
+
+ it('preserves the safe subscription-resume rejection code across IPC', async () => {
+ const { call, fetch } = harness();
+ fetch.mockRejectedValueOnce(
+ new ServerApiError(
+ 'RESUME_NOT_AVAILABLE',
+ 409,
+ 'upstream detail must not reach the renderer',
+ ),
+ );
+
+ await expect(call(BILLING_INVOKE.RESUME_CURRENT_SUBSCRIPTION)).rejects.toMatchObject({
+ code: 'RESUME_NOT_AVAILABLE',
+ message: '[RESUME_NOT_AVAILABLE] subscription is not resumable',
+ });
+ });
+
it('rejects non-main-window senders before network access', async () => {
const { call, fetch } = harness();
await expect(call(BILLING_INVOKE.GET_CATALOG, undefined, { id: 2 })).rejects.toMatchObject({
diff --git a/apps/desktop/src/main/billing/__tests__/projection.test.ts b/apps/desktop/src/main/billing/__tests__/projection.test.ts
index dc552c701e..0d2b309cab 100644
--- a/apps/desktop/src/main/billing/__tests__/projection.test.ts
+++ b/apps/desktop/src/main/billing/__tests__/projection.test.ts
@@ -729,6 +729,39 @@ describe('billing response projection', () => {
});
expect(projected.subscription).not.toHaveProperty('mandate');
});
+
+ it('passes resumable through when the server sends it and omits it otherwise', () => {
+ const withResumable = projectBillingCurrentSubscription({
+ subscription: {
+ subscriptionId: 'subscription_1',
+ status: 'ACTIVE',
+ currentPeriodStartAt: null,
+ currentPeriodEndAt: null,
+ entitlementValidUntil: null,
+ cancelAtPeriodEnd: true,
+ resumable: true,
+ effectivePlan: null,
+ purchaseAttemptId: null,
+ paymentAction: null,
+ },
+ });
+ expect(withResumable.subscription).toMatchObject({ resumable: true });
+
+ const withoutResumable = projectBillingCurrentSubscription({
+ subscription: {
+ subscriptionId: 'subscription_1',
+ status: 'ACTIVE',
+ currentPeriodStartAt: null,
+ currentPeriodEndAt: null,
+ entitlementValidUntil: null,
+ cancelAtPeriodEnd: true,
+ effectivePlan: null,
+ purchaseAttemptId: null,
+ paymentAction: null,
+ },
+ });
+ expect(withoutResumable.subscription).not.toHaveProperty('resumable');
+ });
});
describe('plan change projection', () => {
diff --git a/apps/desktop/src/main/billing/index.ts b/apps/desktop/src/main/billing/index.ts
index e6f3c3644d..a6a2fec42c 100644
--- a/apps/desktop/src/main/billing/index.ts
+++ b/apps/desktop/src/main/billing/index.ts
@@ -62,6 +62,9 @@ function throwBillingFetchError(error: unknown): never {
if (error.code === 'PLAN_CHANGE_NOT_AVAILABLE') {
throwIpcError('PLAN_CHANGE_NOT_AVAILABLE', 'target plan is not available');
}
+ if (error.code === 'RESUME_NOT_AVAILABLE') {
+ throwIpcError('RESUME_NOT_AVAILABLE', 'subscription is not resumable');
+ }
if (error.statusCode === 400) {
throwIpcError('INVALID_PARAMS', 'billing request was rejected');
}
@@ -365,6 +368,18 @@ export function createBillingHandlers(
projectBillingSubscription,
);
}),
+ [BILLING_INVOKE.RESUME_CURRENT_SUBSCRIPTION]: protect(async (raw) => {
+ if (raw !== undefined) {
+ throwIpcError('INVALID_PARAMS', 'subscription resume does not accept a payload');
+ }
+ return projectResponse(
+ await invoke<unknown>('/api/billing/subscription/resume', {
+ method: 'POST',
+ allowedRedactedErrorCodes: ['RESUME_NOT_AVAILABLE'],
+ }),
+ projectBillingSubscription,
+ );
+ }),
[BILLING_INVOKE.REFRESH_SUBSCRIPTION_PURCHASE]: protect(async (raw) => {
const { purchaseAttemptId } = parseIdPayload(raw, 'purchaseAttemptId');
return projectResponse(
diff --git a/apps/desktop/src/main/billing/projection.ts b/apps/desktop/src/main/billing/projection.ts
index 1d319969fd..717d2bfac5 100644
--- a/apps/desktop/src/main/billing/projection.ts
+++ b/apps/desktop/src/main/billing/projection.ts
@@ -858,6 +858,7 @@ export function projectBillingSubscription(value: unknown): BillingSubscription
currentPeriodEndAt,
entitlementValidUntil,
cancelAtPeriodEnd: value.cancelAtPeriodEnd,
+ ...(typeof value.resumable === 'boolean' ? { resumable: value.resumable } : {}),
effectivePlan: value.effectivePlan === null ? null : projectEffectivePlan(value.effectivePlan),
purchaseAttemptId,
paymentAction: projectPaymentAction(value.paymentAction),
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index ca092116ea..b083f82437 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -2258,6 +2258,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
ipcRenderer.invoke(BILLING_INVOKE.CREATE_SUBSCRIPTION, payload),
getCurrentSubscription: () => ipcRenderer.invoke(BILLING_INVOKE.GET_CURRENT_SUBSCRIPTION),
cancelCurrentSubscription: () => ipcRenderer.invoke(BILLING_INVOKE.CANCEL_CURRENT_SUBSCRIPTION),
+ resumeCurrentSubscription: () => ipcRenderer.invoke(BILLING_INVOKE.RESUME_CURRENT_SUBSCRIPTION),
refreshSubscriptionPurchase: (payload) =>
ipcRenderer.invoke(BILLING_INVOKE.REFRESH_SUBSCRIPTION_PURCHASE, payload),
quotePlanChange: (payload) => ipcRenderer.invoke(BILLING_INVOKE.QUOTE_PLAN_CHANGE, payload),
diff --git a/apps/desktop/src/renderer/features/billing/BillingPage.tsx b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
index 7c1d3d93bc..fc90d9d4ef 100644
--- a/apps/desktop/src/renderer/features/billing/BillingPage.tsx
+++ b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
@@ -84,6 +84,7 @@ type CurrentPlanFacts = {
includedCredits: string | null;
periodEndAt: string | null;
cancelAtPeriodEnd: boolean;
+ resumable: boolean;
};
const SUPPORTED_BILLING_PROVIDERS = new Set<SupportedBillingProvider>(['alipay', 'stripe']);
@@ -319,6 +320,7 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
const [loadingSubscription, setLoadingSubscription] = useState(true);
const [subscriptionError, setSubscriptionError] = useState(false);
const [cancelingSubscription, setCancelingSubscription] = useState(false);
+ const [resumingSubscription, setResumingSubscription] = useState(false);
const [openingSubscriptionPortal, setOpeningSubscriptionPortal] = useState(false);
const [creditUsage, setCreditUsage] = useState<ModelAccessCreditUsage | null>(null);
const [balance, setBalance] = useState<ModelAccessBalance | null>(null);
@@ -339,6 +341,7 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
const checkout = useBillingCheckout(accountId);
const previousCheckoutPhaseRef = useRef(checkout.state.phase);
const cancelSubscriptionLockRef = useRef(false);
+ const resumeSubscriptionLockRef = useRef(false);
const subscriptionPortalLockRef = useRef(false);
const subscriptionPortalRefreshPendingRef = useRef(false);
// 取消订阅的 DELETE 不带 subscriptionId,服务端按「请求时已认证的账号」执行。
@@ -746,6 +749,7 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
: null,
periodEndAt: formatBillingDate(currentSubscription.currentPeriodEndAt, billingLocale),
cancelAtPeriodEnd: currentSubscription.cancelAtPeriodEnd,
+ resumable: currentSubscription.resumable === true,
};
}, [billingLocale, currentSubscription, planNameOf, t]);
@@ -796,7 +800,7 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
});
if (!confirmed) return;
// 确认期间账号被换掉(或本 section 已卸载)就放弃:再发请求会取消到另一个账号
- // 的订阅,而取消不可撤销。
+ // 的订阅状态。
if (!sectionMountedRef.current || accountIdRef.current !== confirmingAccountId) return;
setCancelingSubscription(true);
@@ -825,6 +829,53 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
}
}, [billingLocale, confirm, currentPlanFacts?.periodEndAt, currentSubscription, t]);
+ const resumeCurrentSubscription = useCallback(async () => {
+ if (
+ resumeSubscriptionLockRef.current ||
+ !currentSubscription ||
+ !currentSubscription.cancelAtPeriodEnd ||
+ currentSubscription.resumable !== true
+ ) {
+ return;
+ }
+ resumeSubscriptionLockRef.current = true;
+ try {
+ const confirmingAccountId = accountIdRef.current;
+ const confirmed = await confirm({
+ title: t('billing.settings.subscriptionCard.resumeConfirmTitle'),
+ description: t('billing.settings.subscriptionCard.resumeConfirmDescription'),
+ confirmText: t('billing.settings.subscriptionCard.resumeConfirmAction'),
+ cancelText: t('commonUi.confirmDialog.cancel'),
+ });
+ if (!confirmed) return;
+ // 确认期间账号被换掉(或本 section 已卸载)就放弃:恢复会作用到另一个账号的订阅。
+ if (!sectionMountedRef.current || accountIdRef.current !== confirmingAccountId) return;
+
+ setResumingSubscription(true);
+ try {
+ const resumed = await billingApi.resumeCurrentSubscription();
+ setCurrentSubscription(resumed);
+ setSubscriptionError(false);
+ toast.success(t('billing.settings.subscriptionCard.resumeSuccess'));
+ } catch (error) {
+ const ipcError = extractIpcError(error);
+ if (ipcError?.code === 'RESUME_NOT_AVAILABLE') {
+ // 服务端已否定当前投影,立即重拉,避免继续展示过期的恢复入口。
+ void loadSubscription();
+ }
+ toast.error(
+ ipcError?.code === 'RESUME_NOT_AVAILABLE'
+ ? t('billing.settings.subscriptionCard.resumeNotAvailable')
+ : t('billing.settings.subscriptionCard.resumeFailed'),
+ );
+ } finally {
+ setResumingSubscription(false);
+ }
+ } finally {
+ resumeSubscriptionLockRef.current = false;
+ }
+ }, [confirm, currentSubscription, loadSubscription, t]);
+
// The server quote remains authoritative for business reachability. Until
// that contract supports cross-interval/provider changes, keep those two
// client-side compatibility gates so the dialog cannot offer known-invalid
@@ -974,6 +1025,7 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
loadingSubscription ||
loadingBalance ||
cancelingSubscription ||
+ resumingSubscription ||
openingSubscriptionPortal
}
className="inline-flex h-8 shrink-0 items-center gap-2 rounded-full border border-[var(--border-default)] px-3.5 text-12 font-medium text-[var(--text-secondary)] transition-colors hover:bg-[var(--surface-hover-soft)] disabled:opacity-45"
@@ -996,16 +1048,19 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
showPlanChangeEntry={showPlanChangeEntry}
showPortalEntry={currentSubscription?.provider === 'stripe'}
canceling={cancelingSubscription}
+ resuming={resumingSubscription}
openingPortal={openingSubscriptionPortal}
actionDisabled={
loadingSubscription ||
subscriptionError ||
cancelingSubscription ||
+ resumingSubscription ||
openingSubscriptionPortal
}
pendingPlanChange={pendingPlanChange}
pendingTargetName={planNameOf(pendingPlanChange?.targetPlan?.product.code)}
onCancelSubscription={() => void cancelCurrentSubscription()}
+ onResumeSubscription={() => void resumeCurrentSubscription()}
onOpenPortal={() => void openSubscriptionPortal()}
onChangePlan={openPlanChange}
onPurchase={() => openPurchaseDialog('SUBSCRIPTION')}
@@ -1165,11 +1220,13 @@ function SubscriptionOverviewCard({
showPlanChangeEntry,
showPortalEntry,
canceling,
+ resuming,
openingPortal,
actionDisabled,
pendingPlanChange,
pendingTargetName,
onCancelSubscription,
+ onResumeSubscription,
onOpenPortal,
onChangePlan,
onPurchase,
@@ -1181,11 +1238,13 @@ function SubscriptionOverviewCard({
showPlanChangeEntry: boolean;
showPortalEntry: boolean;
canceling: boolean;
+ resuming: boolean;
openingPortal: boolean;
actionDisabled: boolean;
pendingPlanChange: BillingPendingPlanChange | null;
pendingTargetName: string | null;
onCancelSubscription: () => void;
+ onResumeSubscription: () => void;
onOpenPortal: () => void;
onChangePlan: () => void;
onPurchase: () => void;
@@ -1268,7 +1327,7 @@ function SubscriptionOverviewCard({
className="group inline-flex h-8 min-w-[9.5rem] select-none items-center justify-center gap-1.5 rounded-full border border-[var(--border-default)] px-3.5 text-12 font-medium text-[var(--text-primary)] transition-colors hover:bg-[var(--surface-hover-soft)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)] data-[state=open]:bg-[var(--surface-chip)] disabled:cursor-not-allowed disabled:opacity-40"
>
{t('billing.settings.subscriptionCard.manageAction')}
- {canceling || openingPortal ? (
+ {canceling || resuming || openingPortal ? (
<Spinner size={13} />
) : (
<ChevronDown
@@ -1321,6 +1380,22 @@ function SubscriptionOverviewCard({
</DropdownMenuItem>
</>
)}
+ {facts.cancelAtPeriodEnd && facts.resumable && (
+ <>
+ <DropdownMenuSeparator className="mx-2 my-1 h-px bg-[var(--border-default)]" />
+ <DropdownMenuItem
+ onSelect={onResumeSubscription}
+ disabled={actionDisabled}
+ className="h-9 rounded-lg px-3 text-12 focus:bg-[var(--surface-hover)] focus:text-[var(--text-primary)]"
+ >
+ {resuming ? (
+ <Spinner size={13} />
+ ) : (
+ t('billing.settings.subscriptionCard.resumeAction')
+ )}
+ </DropdownMenuItem>
+ </>
+ )}
</DropdownMenuContent>
</DropdownMenu>
) : (
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 b3fdd98614..e4accaf279 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
+++ b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
@@ -1774,6 +1774,7 @@ describe('BillingPage plan change', () => {
),
listOrders: vi.fn(async () => ({ orders: [], nextCursor: null })),
cancelCurrentSubscription: vi.fn(),
+ resumeCurrentSubscription: vi.fn(),
quotePlanChange: vi.fn(),
confirmPlanChange: vi.fn(),
refreshPlanChange: vi.fn(),
@@ -2529,6 +2530,93 @@ describe('BillingPage plan change', () => {
expect(screen.queryByText(/purchaseBlockedUntilPeriodEnd/)).toBeNull();
});
+ it('shows the resume action only for resumable canceled subscriptions', async () => {
+ const billing = billingMocks();
+ billing.getCurrentSubscription = vi.fn(async () => ({
+ subscription: { ...activeSubscription(null, 'MONTH', 'ACTIVE', true), resumable: true },
+ }));
+ install(billing);
+
+ render(<BillingPage />);
+
+ await openSubscriptionManagementMenu();
+ expect(screen.getByText('billing.settings.subscriptionCard.resumeAction')).toBeTruthy();
+ expect(screen.queryByText('billing.settings.subscriptionCard.cancelAction')).toBeNull();
+ });
+
+ it('confirms a provider-neutral resume and replaces the canceled subscription projection', async () => {
+ const billing = billingMocks();
+ const canceled = {
+ ...activeSubscription(null, 'MONTH', 'ACTIVE', true),
+ resumable: true,
+ };
+ billing.getCurrentSubscription = vi.fn(async () => ({ subscription: canceled }));
+ billing.resumeCurrentSubscription.mockResolvedValue({
+ ...canceled,
+ cancelAtPeriodEnd: false,
+ resumable: false,
+ });
+ install(billing);
+ uiMocks.confirm.mockResolvedValueOnce(true);
+
+ render(<BillingPage />);
+ await selectSubscriptionManagementAction('billing.settings.subscriptionCard.resumeAction');
+
+ await waitFor(() => expect(billing.resumeCurrentSubscription).toHaveBeenCalledWith());
+ expect(uiMocks.confirm).toHaveBeenCalledWith(
+ expect.objectContaining({
+ title: 'billing.settings.subscriptionCard.resumeConfirmTitle',
+ confirmText: 'billing.settings.subscriptionCard.resumeConfirmAction',
+ }),
+ );
+ expect(uiMocks.toastSuccess).toHaveBeenCalledWith(
+ 'billing.settings.subscriptionCard.resumeSuccess',
+ );
+ await openSubscriptionManagementMenu();
+ expect(
+ screen.queryByRole('menuitem', { name: 'billing.settings.subscriptionCard.resumeAction' }),
+ ).toBeNull();
+ expect(
+ screen.getByRole('menuitem', { name: 'billing.settings.subscriptionCard.cancelAction' }),
+ ).toBeTruthy();
+ });
+
+ it('explains when the server no longer allows subscription resume', async () => {
+ const billing = billingMocks();
+ billing.getCurrentSubscription = vi.fn(async () => ({
+ subscription: { ...activeSubscription(null, 'MONTH', 'ACTIVE', true), resumable: true },
+ }));
+ billing.resumeCurrentSubscription.mockRejectedValue(
+ new Error('[RESUME_NOT_AVAILABLE] subscription is not resumable'),
+ );
+ install(billing);
+ uiMocks.confirm.mockResolvedValueOnce(true);
+
+ render(<BillingPage />);
+ await selectSubscriptionManagementAction('billing.settings.subscriptionCard.resumeAction');
+
+ await waitFor(() =>
+ expect(uiMocks.toastError).toHaveBeenCalledWith(
+ 'billing.settings.subscriptionCard.resumeNotAvailable',
+ ),
+ );
+ await waitFor(() => expect(billing.getCurrentSubscription).toHaveBeenCalledTimes(2));
+ });
+
+ it('hides the resume action when the server marks the subscription not resumable', async () => {
+ const billing = billingMocks();
+ billing.getCurrentSubscription = vi.fn(async () => ({
+ subscription: { ...activeSubscription(null, 'MONTH', 'ACTIVE', true), resumable: false },
+ }));
+ install(billing);
+
+ render(<BillingPage />);
+
+ await openSubscriptionManagementMenu();
+ expect(screen.queryByText('billing.settings.subscriptionCard.resumeAction')).toBeNull();
+ expect(screen.queryByText('billing.settings.subscriptionCard.cancelAction')).toBeNull();
+ });
+
it('explains a rejected quote and returns to the candidate list', async () => {
const billing = install(billingMocks());
billing.quotePlanChange.mockRejectedValue(
diff --git a/apps/desktop/src/renderer/features/billing/api.ts b/apps/desktop/src/renderer/features/billing/api.ts
index ffc1b7a40e..49fb16a7d7 100644
--- a/apps/desktop/src/renderer/features/billing/api.ts
+++ b/apps/desktop/src/renderer/features/billing/api.ts
@@ -54,6 +54,9 @@ export const billingApi = {
cancelCurrentSubscription(): Promise<BillingSubscription> {
return window.electronAPI.billing.cancelCurrentSubscription();
},
+ resumeCurrentSubscription(): Promise<BillingSubscription> {
+ return window.electronAPI.billing.resumeCurrentSubscription();
+ },
refreshSubscriptionPurchase(purchaseAttemptId: string): Promise<BillingSubscription> {
return window.electronAPI.billing.refreshSubscriptionPurchase({ purchaseAttemptId });
},
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 1b9d23ee7b..93fef00a5c 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -9357,13 +9357,20 @@
"endsAt": "Plan ends {{date}}",
"cancelAction": "Cancel Subscription",
"cancelConfirmTitle": "Cancel Your Current Subscription?",
- "cancelConfirmDescription": "This action does not issue a refund or immediately change your balance. Your current plan stays available through {{date}}, then it will not renew. Cancellation cannot be undone in the app, and you cannot purchase a new plan until this billing period ends.",
- "cancelConfirmDescriptionWithoutDate": "This action does not issue a refund or immediately change your balance. Your current plan stays available through the end of this billing period, then it will not renew. Cancellation cannot be undone in the app, and you cannot purchase a new plan until this billing period ends.",
+ "cancelConfirmDescription": "This action does not issue a refund or immediately change your balance. Your current plan stays available through {{date}}, then it will not renew. If the subscription remains eligible, you can resume it before this billing period ends; you cannot purchase a new plan until it ends.",
+ "cancelConfirmDescriptionWithoutDate": "This action does not issue a refund or immediately change your balance. Your current plan stays available until this billing period ends, then it will not renew. If the subscription remains eligible, you can resume it before this billing period ends; you cannot purchase a new plan until it ends.",
"cancelConfirmAction": "Confirm Cancellation",
"cancelSuccess": "Auto-renewal is canceled. Your current plan remains available through {{date}}.",
"cancelSuccessWithoutDate": "Auto-renewal is canceled. Your current plan will end after this billing period.",
"cancelNotSupported": "This subscription cannot be canceled yet.",
- "cancelFailed": "Could not cancel the subscription. Try again later."
+ "cancelFailed": "Could not cancel the subscription. Try again later.",
+ "resumeAction": "Resume Subscription",
+ "resumeConfirmTitle": "Resume Your Current Subscription?",
+ "resumeConfirmDescription": "Your plan will renew automatically on the renewal date.",
+ "resumeConfirmAction": "Resume Subscription",
+ "resumeSuccess": "Subscription resumed. It will renew as planned.",
+ "resumeNotAvailable": "This subscription cannot be resumed. Check its latest status before trying again.",
+ "resumeFailed": "Could not resume the subscription. Try again later."
},
"topupCard": {
"action": "Add Funds"
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index cabdde1ca6..f812c302ee 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -9343,13 +9343,20 @@
"endsAt": "{{date}} にプラン終了",
"cancelAction": "サブスクリプションを解約",
"cancelConfirmTitle": "現在のサブスクリプションを解約しますか?",
- "cancelConfirmDescription": "この操作による返金や残高の即時変更はありません。現在のプランは {{date}} まで利用でき、その後は更新されません。キャンセルはアプリ内では元に戻せません。また、この請求期間が終了するまで新しいプランは購入できません。",
- "cancelConfirmDescriptionWithoutDate": "この操作による返金や残高の即時変更はありません。現在のプランは請求期間の終了まで利用でき、その後は更新されません。キャンセルはアプリ内では元に戻せません。また、この請求期間が終了するまで新しいプランは購入できません。",
+ "cancelConfirmDescription": "この操作による返金や残高の即時変更はありません。現在のプランは {{date}} まで利用でき、その後は更新されません。再開可能な状態であれば、この請求期間が終了するまで再開できますが、新しいプランの購入はできません。",
+ "cancelConfirmDescriptionWithoutDate": "この操作による返金や残高の即時変更はありません。現在のプランはこの請求期間が終了するまで利用でき、その後は更新されません。再開可能な状態であれば、この請求期間が終了するまで再開できますが、新しいプランの購入はできません。",
"cancelConfirmAction": "解約を確定",
"cancelSuccess": "自動更新を停止しました。現在のプランは {{date}} まで利用できます。",
"cancelSuccessWithoutDate": "自動更新を停止しました。現在のプランはこの請求期間の終了後に終了します。",
"cancelNotSupported": "このサブスクリプションは現在解約できません。",
- "cancelFailed": "サブスクリプションを解約できませんでした。しばらくしてからもう一度お試しください。"
+ "cancelFailed": "サブスクリプションを解約できませんでした。しばらくしてからもう一度お試しください。",
+ "resumeAction": "サブスクリプションを再開",
+ "resumeConfirmTitle": "現在のサブスクリプションを再開しますか?",
+ "resumeConfirmDescription": "再開すると、更新日に自動更新されます。",
+ "resumeConfirmAction": "サブスクリプションを再開",
+ "resumeSuccess": "サブスクリプションを再開しました。予定どおり自動更新されます。",
+ "resumeNotAvailable": "このサブスクリプションは再開できません。最新の状態を確認してから、もう一度お試しください。",
+ "resumeFailed": "サブスクリプションを再開できませんでした。しばらくしてからもう一度お試しください。"
},
"topupCard": {
"action": "残高チャージ"
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 8d1801380a..0ebfdcf565 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -9343,13 +9343,20 @@
"endsAt": "{{date}}에 요금제 종료",
"cancelAction": "구독 취소",
"cancelConfirmTitle": "현재 구독을 취소할까요?",
- "cancelConfirmDescription": "이 작업으로 환불되거나 잔액이 즉시 변경되지 않습니다. 현재 요금제는 {{date}}까지 사용할 수 있으며 이후에는 갱신되지 않습니다. 취소는 앱에서 되돌릴 수 없으며, 이번 결제 기간이 끝날 때까지 새 요금제를 구매할 수 없습니다.",
- "cancelConfirmDescriptionWithoutDate": "이 작업으로 환불되거나 잔액이 즉시 변경되지 않습니다. 현재 요금제는 이번 결제 기간이 끝날 때까지 사용할 수 있으며 이후에는 갱신되지 않습니다. 취소는 앱에서 되돌릴 수 없으며, 이번 결제 기간이 끝날 때까지 새 요금제를 구매할 수 없습니다.",
+ "cancelConfirmDescription": "이 작업으로 환불되거나 잔액이 즉시 변경되지 않습니다. 현재 요금제는 {{date}}까지 사용할 수 있으며 이후에는 갱신되지 않습니다. 구독을 재개할 수 있는 상태라면 이번 결제 기간이 끝나기 전까지 재개할 수 있지만, 새 요금제는 구매할 수 없습니다.",
+ "cancelConfirmDescriptionWithoutDate": "이 작업으로 환불되거나 잔액이 즉시 변경되지 않습니다. 현재 요금제는 이번 결제 기간이 끝날 때까지 사용할 수 있으며 이후에는 갱신되지 않습니다. 구독을 재개할 수 있는 상태라면 이번 결제 기간이 끝나기 전까지 재개할 수 있지만, 새 요금제는 구매할 수 없습니다.",
"cancelConfirmAction": "취소 확인",
"cancelSuccess": "자동 갱신을 취소했습니다. 현재 요금제는 {{date}}까지 사용할 수 있습니다.",
"cancelSuccessWithoutDate": "자동 갱신을 취소했습니다. 현재 요금제는 이번 결제 기간이 끝난 후 종료됩니다.",
"cancelNotSupported": "현재 이 구독은 취소할 수 없습니다.",
- "cancelFailed": "구독을 취소하지 못했습니다. 잠시 후 다시 시도해 주세요."
+ "cancelFailed": "구독을 취소하지 못했습니다. 잠시 후 다시 시도해 주세요.",
+ "resumeAction": "구독 재개",
+ "resumeConfirmTitle": "현재 구독을 재개할까요?",
+ "resumeConfirmDescription": "재개하면 갱신일에 자동 갱신됩니다.",
+ "resumeConfirmAction": "구독 재개",
+ "resumeSuccess": "구독을 재개했습니다. 예정대로 자동 갱신됩니다.",
+ "resumeNotAvailable": "이 구독은 재개할 수 없습니다. 최신 구독 상태를 확인한 후 다시 시도해 주세요.",
+ "resumeFailed": "구독을 재개하지 못했습니다. 잠시 후 다시 시도해 주세요."
},
"topupCard": {
"action": "잔액 충전"
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 b19a4a6f7b..04ce465f5a 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -9343,13 +9343,20 @@
"endsAt": "套餐将于 {{date}} 结束",
"cancelAction": "取消订阅",
"cancelConfirmTitle": "取消当前订阅?",
- "cancelConfirmDescription": "本次操作不会退款,也不会立即调整余额。当前套餐权益可继续使用至 {{date}},之后不再续费。取消后无法在应用内恢复,本计费周期结束前也无法购买新套餐。",
- "cancelConfirmDescriptionWithoutDate": "本次操作不会退款,也不会立即调整余额。当前套餐权益可继续使用至本计费周期结束,之后不再续费。取消后无法在应用内恢复,本计费周期结束前也无法购买新套餐。",
+ "cancelConfirmDescription": "本次操作不会退款,也不会立即调整余额。当前套餐权益可继续使用至 {{date}},之后不再续费。若订阅仍支持恢复,可在本计费周期结束前恢复;本计费周期结束前也无法购买新套餐。",
+ "cancelConfirmDescriptionWithoutDate": "本次操作不会退款,也不会立即调整余额。当前套餐权益可继续使用至本计费周期结束,之后不再续费。若订阅仍支持恢复,可在本计费周期结束前恢复;本计费周期结束前也无法购买新套餐。",
"cancelConfirmAction": "确认取消",
"cancelSuccess": "已取消自动续费,当前套餐可使用至 {{date}}。",
"cancelSuccessWithoutDate": "已取消自动续费,当前套餐将在本计费周期结束后到期。",
"cancelNotSupported": "当前订阅暂不支持取消。",
- "cancelFailed": "取消订阅失败,请稍后重试。"
+ "cancelFailed": "取消订阅失败,请稍后重试。",
+ "resumeAction": "恢复订阅",
+ "resumeConfirmTitle": "恢复当前订阅?",
+ "resumeConfirmDescription": "恢复后将在续费日自动续费。",
+ "resumeConfirmAction": "恢复订阅",
+ "resumeSuccess": "已恢复订阅,将按原计划自动续费。",
+ "resumeNotAvailable": "当前订阅暂不支持恢复,请查看最新订阅状态后重试。",
+ "resumeFailed": "未能恢复订阅,请稍后重试。"
},
"topupCard": {
"action": "余额充值"
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index e364f4c800..ca197ac552 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -9343,13 +9343,20 @@
"endsAt": "套餐將於 {{date}} 結束",
"cancelAction": "取消訂閱",
"cancelConfirmTitle": "取消當前訂閱?",
- "cancelConfirmDescription": "本次操作不會退款,也不會立即調整餘額。當前套餐權益可繼續使用至 {{date}},之後不再續費。取消後無法在應用內恢復,本計費週期結束前也無法購買新套餐。",
- "cancelConfirmDescriptionWithoutDate": "本次操作不會退款,也不會立即調整餘額。當前套餐權益可繼續使用至本計費週期結束,之後不再續費。取消後無法在應用內恢復,本計費週期結束前也無法購買新套餐。",
+ "cancelConfirmDescription": "本次操作不會退款,也不會立即調整餘額。當前套餐權益可繼續使用至 {{date}},之後不再續費。若訂閱仍支援恢復,可在本計費週期結束前恢復;本計費週期結束前也無法購買新套餐。",
+ "cancelConfirmDescriptionWithoutDate": "本次操作不會退款,也不會立即調整餘額。當前套餐權益可繼續使用至本計費週期結束,之後不再續費。若訂閱仍支援恢復,可在本計費週期結束前恢復;本計費週期結束前也無法購買新套餐。",
"cancelConfirmAction": "確認取消",
"cancelSuccess": "已取消自動續費,當前套餐可使用至 {{date}}。",
"cancelSuccessWithoutDate": "已取消自動續費,當前套餐將在本計費週期結束後到期。",
"cancelNotSupported": "當前訂閱暫不支援取消。",
- "cancelFailed": "取消訂閱失敗,請稍後重試。"
+ "cancelFailed": "取消訂閱失敗,請稍後重試。",
+ "resumeAction": "恢復訂閱",
+ "resumeConfirmTitle": "恢復目前訂閱?",
+ "resumeConfirmDescription": "恢復後將在續費日自動續費。",
+ "resumeConfirmAction": "恢復訂閱",
+ "resumeSuccess": "已恢復訂閱,將按原計畫自動續費。",
+ "resumeNotAvailable": "目前訂閱暫不支援恢復,請查看最新訂閱狀態後重試。",
+ "resumeFailed": "未能恢復訂閱,請稍後重試。"
},
"topupCard": {
"action": "餘額充值"
diff --git a/apps/desktop/src/shared/billing.ts b/apps/desktop/src/shared/billing.ts
index 202296ee7f..186b99948d 100644
--- a/apps/desktop/src/shared/billing.ts
+++ b/apps/desktop/src/shared/billing.ts
@@ -20,6 +20,7 @@ export const BILLING_INVOKE = {
CREATE_SUBSCRIPTION: 'billing:create-subscription',
GET_CURRENT_SUBSCRIPTION: 'billing:get-current-subscription',
CANCEL_CURRENT_SUBSCRIPTION: 'billing:cancel-current-subscription',
+ RESUME_CURRENT_SUBSCRIPTION: 'billing:resume-current-subscription',
REFRESH_SUBSCRIPTION_PURCHASE: 'billing:refresh-subscription-purchase',
QUOTE_PLAN_CHANGE: 'billing:quote-plan-change',
CONFIRM_PLAN_CHANGE: 'billing:confirm-plan-change',
@@ -165,6 +166,8 @@ export type BillingSubscription = {
currentPeriodEndAt: string | null;
entitlementValidUntil: string | null;
cancelAtPeriodEnd: boolean;
+ /** 取消待到期且账期未过的订阅是否可恢复(服务端下发;旧服务端无此字段)。 */
+ resumable?: boolean;
effectivePlan: {
version: 1;
product: {
@@ -236,6 +239,7 @@ export interface BillingRendererApi {
}) => Promise<BillingSubscription>;
getCurrentSubscription: () => Promise<BillingCurrentSubscription>;
cancelCurrentSubscription: () => Promise<BillingSubscription>;
+ resumeCurrentSubscription: () => Promise<BillingSubscription>;
refreshSubscriptionPurchase: (payload: {
purchaseAttemptId: string;
}) => Promise<BillingSubscription>;
diff --git a/apps/desktop/src/shared/ipc-errors.ts b/apps/desktop/src/shared/ipc-errors.ts
index fb9f3c5c25..279fc41912 100644
--- a/apps/desktop/src/shared/ipc-errors.ts
+++ b/apps/desktop/src/shared/ipc-errors.ts
@@ -176,6 +176,7 @@ export type IpcErrorCode =
| 'MODEL_ACCESS_UNSUPPORTED' // 企业未接入(403)——XD 网关不可用,不重试
| 'MODEL_CATALOG_FETCH_DISABLED' // 模型目录远程拉取被禁用(dev 缺省禁网/XDT_DISABLE_MODELS_FETCH),未发起请求
| 'PLAN_CHANGE_NOT_AVAILABLE' // 当前订阅不能切换到目标套餐,可返回候选列表重选
+ | 'RESUME_NOT_AVAILABLE' // 当前订阅已到期、渠道协议失效或状态不可恢复
// 钉钉机器人连接
| 'DINGTALK_AUTH_FAILED' // Client ID / Client Secret 被钉钉拒绝
| 'DINGTALK_NETWORK_FAILED' // 钉钉凭证校验接口不可达
@@ -360,6 +361,7 @@ const IPC_ERROR_CODES: ReadonlySet<IpcErrorCode> = new Set<IpcErrorCode>([
'MODEL_ACCESS_UNSUPPORTED',
'MODEL_CATALOG_FETCH_DISABLED',
'PLAN_CHANGE_NOT_AVAILABLE',
+ 'RESUME_NOT_AVAILABLE',
'DINGTALK_AUTH_FAILED',
'DINGTALK_NETWORK_FAILED',
'DINGTALK_STREAM_CONNECTION_FAILED',