Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
fix(portal): recognise already-applied billing returns
pulse-triage[bot]8a59a8df7fad
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.mdindex ba5c2adec7..7c99da74fe 100644--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md@@ -3494,7 +3494,11 @@ paid plan appears, the panel gives conditional follow-up instead of claimingpayment or activation. Manual Apply uses the same running-plan confirmationbefore updating the view. The panel never reloads the page. Manage billing returns to`?provider_msp_checkout=billing`, and the panel checks the licence twice so a-plan changed in the Stripe billing portal applies without a click. Regression+plan changed in the Stripe billing portal applies without a click. It also+accepts a matching paid plan already applied by the background refresher+without requiring a second restart; an unchanged visit stays silent. A stale+panel is replaced only after the refreshed running plan is confirmed, never+because the billing return URL says a change was made. Regressioncoverage:`TestLoadConfig_ProviderHostedMSPPrefersRenewedLicense` in`internal/cloudcp/config_test.go`,diff --git a/internal/cloudcp/portal/dist/build_manifest.json b/internal/cloudcp/portal/dist/build_manifest.jsonindex 303ecaeff2..90c44f8d4e 100644--- a/internal/cloudcp/portal/dist/build_manifest.json+++ b/internal/cloudcp/portal/dist/build_manifest.json@@ -1,5 +1,5 @@{- "source_hash": "5a72090fb4e236e040f29fae0e7685c1e5ce21499deaa6cb92f24181562738fd",+ "source_hash": "294e2ef873914caeb1132876df403b0ef2b101262f00cdaf34fb13d0b3d22c29","build_inputs": ["package.json","tsconfig.json",diff --git a/internal/cloudcp/portal/dist/portal_app.js b/internal/cloudcp/portal/dist/portal_app.jsindex f71c9b7a7f..68a7103de2 100644--- a/internal/cloudcp/portal/dist/portal_app.js+++ b/internal/cloudcp/portal/dist/portal_app.js@@ -2831,14 +2831,20 @@function isApplied(plan, target) {return !plan.evaluation && !!target.plan_version && plan.plan_version === target.plan_version && (!target.license_id || plan.license_id === target.license_id) && (!target.expires_at || plan.expires_at === target.expires_at);}- function finishApplying(plan) {+ function sameRunningPlan(left, right) {+ return left.evaluation === right.evaluation && left.plan_version === right.plan_version && left.license_id === right.license_id && left.expires_at === right.expires_at;+ }+ function acceptRunningPlan(plan, announce) {applying = null;planEpoch += 1;view.plan = plan;view.error = "";- view.notice = "Your " + providerPlanName(plan.plan_version) + " plan is active.";+ if (announce) view.notice = "Your " + providerPlanName(plan.plan_version) + " plan is active.";render();}+ function finishApplying(plan) {+ acceptRunningPlan(plan, true);+ }function account() {var bootstrap = deps.store.getBootstrap();if (bootstrap.provider_hosted_mode !== true || !bootstrap.authenticated) return null;@@ -2909,7 +2915,7 @@waitForAppliedPlan(target, 0);}, RESTART_SETTLE_MS);}- async function refresh(manual, confirmCurrent = false) {+ async function refresh(manual, confirmCurrent = false, billingReturn = false) {var current = account();if (!current) return false;view.busy = "refresh";@@ -2923,6 +2929,13 @@if (confirmCurrent && result.status === "active" && result.plan_version) {var plan = await deps.api.fetchPlan(current.id);if (isApplied(plan, result)) {+ if (billingReturn) {+ if (!view.plan) {+ acceptRunningPlan(plan, false);+ return true;+ }+ if (sameRunningPlan(view.plan, plan)) return false;+ }finishApplying(plan);return true;}@@ -2953,7 +2966,7 @@});}function checkAfterBillingReturn(attempt) {- void refresh(false).then(function(applied) {+ void refresh(false, true, true).then(function(applied) {if (applied || attempt + 1 >= BILLING_RETURN_ATTEMPTS) return;later(function() {checkAfterBillingReturn(attempt + 1);diff --git a/internal/cloudcp/portal/frontend/src/provider_plan.test.ts b/internal/cloudcp/portal/frontend/src/provider_plan.test.tsindex d19d9badd7..45a59b6d31 100644--- a/internal/cloudcp/portal/frontend/src/provider_plan.test.ts+++ b/internal/cloudcp/portal/frontend/src/provider_plan.test.ts@@ -365,6 +365,87 @@ describe('installProviderPlan', () => {expect(toast).not.toHaveBeenCalled();});+ it('confirms a paid plan already applied by the background refresh on a billing return', async () => {+ const oldPlan = evaluationPlan({+ plan_version: 'msp_solo', evaluation: false, license_id: 'lic_old',+ workspace_limit: 3, expires_at: '2026-10-10T00:00:00Z',+ });+ const newPlan = evaluationPlan({+ plan_version: 'msp_starter', evaluation: false, license_id: 'lic_new',+ workspace_limit: 5, expires_at: '2026-11-10T00:00:00Z',+ });+ let resolveRefresh!: (result: Awaited<ReturnType<ProviderPlanAPI['refreshLicense']>>) => void;+ api.refreshLicense = vi.fn().mockImplementation(() => new Promise((resolve) => { resolveRefresh = resolve; }));+ api.fetchPlan = vi.fn().mockResolvedValueOnce(oldPlan).mockResolvedValueOnce(newPlan);+ const { controller } = install(providerBootstrap(), '?provider_msp_checkout=billing');+ await controller.load();+ expect(controller.view().plan).toEqual(oldPlan);+ expect(controller.view().notice).toBe('');++ resolveRefresh({+ status: 'active', changed: false, restart_scheduled: false,+ plan_version: newPlan.plan_version, license_id: newPlan.license_id, expires_at: newPlan.expires_at,+ });+ await flush();+ expect(controller.view().plan).toEqual(newPlan);+ expect(controller.view().notice).toBe('Your Starter plan is active.');+ expect(timers).toHaveLength(0);+ expect(toast).not.toHaveBeenCalled();+ });++ it('does not announce an unchanged paid plan from a Manage billing visit', async () => {+ const paid = evaluationPlan({+ plan_version: 'msp_solo', evaluation: false, license_id: 'lic_paid', workspace_limit: 3,+ });+ api.fetchPlan = vi.fn().mockResolvedValue(paid);+ api.refreshLicense = vi.fn().mockResolvedValue({+ status: 'active', changed: false, restart_scheduled: false,+ plan_version: paid.plan_version, license_id: paid.license_id, expires_at: paid.expires_at,+ });+ const { controller } = install(providerBootstrap(), '?provider_msp_checkout=billing');+ await controller.load();+ await flush();+ expect(controller.view().notice).toBe('');+ expect(timers).toHaveLength(1);+ timers.shift()!();+ await flush();+ expect(controller.view().notice).toBe('');+ expect(controller.view().plan).toEqual(paid);+ expect(timers).toHaveLength(0);+ });++ it('confirms a renewed paid period but not an unmatched refresh on a billing return', async () => {+ const oldPlan = evaluationPlan({+ plan_version: 'msp_solo', evaluation: false, license_id: 'lic_paid',+ workspace_limit: 3, expires_at: '2026-10-10T00:00:00Z',+ });+ const renewed = { ...oldPlan, expires_at: '2026-11-10T00:00:00Z' };+ let served = oldPlan;+ api.fetchPlan = vi.fn().mockImplementation(() => Promise.resolve(served));+ let resolveRefresh!: (result: Awaited<ReturnType<ProviderPlanAPI['refreshLicense']>>) => void;+ api.refreshLicense = vi.fn().mockImplementationOnce(() => new Promise((resolve) => { resolveRefresh = resolve; }))+ .mockResolvedValue({+ status: 'active', changed: false, restart_scheduled: false,+ plan_version: renewed.plan_version, license_id: renewed.license_id, expires_at: renewed.expires_at,+ });+ const { controller } = install(providerBootstrap(), '?provider_msp_checkout=billing');+ await controller.load();+ resolveRefresh({+ status: 'active', changed: false, restart_scheduled: false,+ plan_version: renewed.plan_version, license_id: renewed.license_id, expires_at: renewed.expires_at,+ });+ await flush();+ expect(controller.view().plan).toEqual(oldPlan);+ expect(controller.view().notice).toBe('');+ expect(timers).toHaveLength(1);+ served = renewed;+ timers.shift()!();+ await flush();+ expect(controller.view().plan).toEqual(renewed);+ expect(controller.view().notice).toBe('Your Solo plan is active.');+ expect(timers).toHaveLength(0);+ });+it('checks a Manage billing return only twice when nothing changed', async () => {api.refreshLicense = vi.fn().mockResolvedValue({ status: 'active', changed: false });const { controller } = install(providerBootstrap(), '?provider_msp_checkout=billing');diff --git a/internal/cloudcp/portal/frontend/src/provider_plan.ts b/internal/cloudcp/portal/frontend/src/provider_plan.tsindex 384a2f6bd6..47a19f735d 100644--- a/internal/cloudcp/portal/frontend/src/provider_plan.ts+++ b/internal/cloudcp/portal/frontend/src/provider_plan.ts@@ -259,15 +259,24 @@ export function installProviderPlan(deps: ProviderPlanDeps): ProviderPlanControl(!target.expires_at || plan.expires_at === target.expires_at);}- function finishApplying(plan: ProviderPlanState) {+ function sameRunningPlan(left: ProviderPlanState, right: ProviderPlanState): boolean {+ return left.evaluation === right.evaluation && left.plan_version === right.plan_version &&+ left.license_id === right.license_id && left.expires_at === right.expires_at;+ }++ function acceptRunningPlan(plan: ProviderPlanState, announce: boolean) {applying = null;- planEpoch += 1; // Ignore plan requests started before the restart completed.+ planEpoch += 1; // Ignore requests started before this confirmed plan was served.view.plan = plan;view.error = '';- view.notice = 'Your ' + providerPlanName(plan.plan_version) + ' plan is active.';+ if (announce) view.notice = 'Your ' + providerPlanName(plan.plan_version) + ' plan is active.';render();}+ function finishApplying(plan: ProviderPlanState) {+ acceptRunningPlan(plan, true);+ }+function account(): PortalAccountSummary | null {var bootstrap = deps.store.getBootstrap();if (bootstrap.provider_hosted_mode !== true || !bootstrap.authenticated) return null;@@ -339,7 +348,7 @@ export function installProviderPlan(deps: ProviderPlanDeps): ProviderPlanControllater(function() { waitForAppliedPlan(target, 0); }, RESTART_SETTLE_MS);}- async function refresh(manual: boolean, confirmCurrent = false): Promise<boolean> {+ async function refresh(manual: boolean, confirmCurrent = false, billingReturn = false): Promise<boolean> {var current = account();if (!current) return false;view.busy = 'refresh';@@ -356,6 +365,16 @@ export function installProviderPlan(deps: ProviderPlanDeps): ProviderPlanControlif (confirmCurrent && result.status === 'active' && result.plan_version) {var plan = await deps.api.fetchPlan(current.id);if (isApplied(plan, result)) {+ // A visit to Manage billing is not itself a change. If the+ // background refresher applied a new licence before this check,+ // replace the older panel; otherwise keep the visit silent.+ if (billingReturn) {+ if (!view.plan) {+ acceptRunningPlan(plan, false);+ return true;+ }+ if (sameRunningPlan(view.plan, plan)) return false;+ }finishApplying(plan);return true;}@@ -388,7 +407,7 @@ export function installProviderPlan(deps: ProviderPlanDeps): ProviderPlanControl}function checkAfterBillingReturn(attempt: number) {- void refresh(false).then(function(applied) {+ void refresh(false, true, true).then(function(applied) {if (applied || attempt + 1 >= BILLING_RETURN_ATTEMPTS) return;later(function() { checkAfterBillingReturn(attempt + 1); }, APPLY_POLL_MS);});