Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(billing): correct license server v2 customer portal behavior

Tre Dubrava5f479c9e6847
diff --git a/backend/src/ee/services/license-v2/license-v2-service.ts b/backend/src/ee/services/license-v2/license-v2-service.ts
index cbc4137d3c..719be19b97 100644
--- a/backend/src/ee/services/license-v2/license-v2-service.ts
+++ b/backend/src/ee/services/license-v2/license-v2-service.ts
@@ -1,9 +1,10 @@
import { ForbiddenError } from "@casl/ability";
-import { OrganizationActionScope } from "@app/db/schemas";
+import { OrganizationActionScope, TableName } from "@app/db/schemas";
import { TEnvConfig } from "@app/lib/config/env";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
+import { TIdentityOrgDALFactory } from "@app/services/identity/identity-org-dal";
import { TLicenseClientFactory } from "@app/services/license-client";
import {
TCatalogProduct,
@@ -32,6 +33,7 @@ import {
type TLicenseV2ServiceFactoryDep = {
envConfig: Pick<TEnvConfig, "LICENSE_SERVER_V2_MODE">;
orgDAL: Pick<TOrgDALFactory, "findById" | "countAllOrgMembers">;
+ identityOrgMembershipDAL: Pick<TIdentityOrgDALFactory, "countAllOrgIdentities">;
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
licenseClient: Pick<
TLicenseClientFactory,
@@ -220,6 +222,7 @@ const buildCheckoutItems = (product: TCatalogProduct, cadence: "monthly" | "annu
export const licenseV2ServiceFactory = ({
envConfig,
orgDAL,
+ identityOrgMembershipDAL,
permissionService,
licenseClient
}: TLicenseV2ServiceFactoryDep) => {
@@ -328,6 +331,9 @@ export const licenseV2ServiceFactory = ({
}
const members = await orgDAL.countAllOrgMembers(orgId);
+ const identities = await identityOrgMembershipDAL.countAllOrgIdentities({
+ [`${TableName.Membership}.scopeOrgId` as "scopeOrgId"]: orgId
+ });
// Plan caps come from the license server (a null limit means genuinely unlimited). Used counts
// are overlaid here; a missing plan leaves limits unknown.
@@ -363,7 +369,7 @@ export const licenseV2ServiceFactory = ({
usage: {
members,
memberLimit,
- identities: 0,
+ identities,
identityLimit
},
payment: null,
diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.ts
index 8f80329617..01f749217f 100644
--- a/backend/src/ee/services/license/license-service.ts
+++ b/backend/src/ee/services/license/license-service.ts
@@ -67,7 +67,7 @@ type TLicenseServiceFactoryDep = {
licenseDAL: TLicenseDALFactory;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiry" | "getItem" | "deleteItem">;
projectDAL: TProjectDALFactory;
- licenseClient?: Pick<TLicenseClientFactory, "getEntitlements">;
+ licenseClient?: Pick<TLicenseClientFactory, "getEntitlements" | "getSubscription">;
licenseDualRead?: Pick<TDualReadServiceFactory, "compareInBackground">;
};
@@ -234,6 +234,21 @@ export const licenseServiceFactory = ({
throw new BadRequestError({ message: "License Server v2 entitlements are unavailable" });
}
currentPlan = projectV2ToFeatureSet(getDefaultOnPremFeatures(), entitlements);
+
+ // The entitlement projection only carries feature flags, so set the plan slug from the
+ // subscription tier; otherwise the org-level plan label can't reflect the real tier. Keep
+ // it non-fatal so a subscription read failure doesn't drop the org to the free fallback.
+ try {
+ const subscription = await licenseClient.getSubscription(rootOrgId);
+ const tiers = subscription?.items.map((item) => item.plan.toLowerCase()) ?? [];
+ if (tiers.some((tier) => tier.includes("enterprise"))) {
+ currentPlan.slug = "enterprise";
+ } else if (tiers.length > 0) {
+ currentPlan.slug = "pro";
+ }
+ } catch (error) {
+ logger.error(error, `getPlan: failed to resolve plan tier from subscription [orgId=${rootOrgId}]`);
+ }
} else {
const {
data: { currentPlan: v1Plan }
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index aa5527fefa..dd8d86964e 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -834,6 +834,7 @@ export const registerRoutes = async (
const licenseV2Service = licenseV2ServiceFactory({
envConfig,
orgDAL,
+ identityOrgMembershipDAL,
permissionService,
licenseClient
});
diff --git a/frontend/src/hooks/api/subscriptions/fns.ts b/frontend/src/hooks/api/subscriptions/fns.ts
new file mode 100644
index 0000000000..97026520ad
--- /dev/null
+++ b/frontend/src/hooks/api/subscriptions/fns.ts
@@ -0,0 +1,17 @@
+import { SubscriptionPlan, SubscriptionPlanTypes } from "./types";
+
+// Derive the plan label from the real plan slug, not feature booleans. Inferring "Enterprise" from a
+// single entitled feature (e.g. groups) mislabels Pro orgs that bought an add-on granting it.
+export const getSubscriptionPlanLabel = (subscription: SubscriptionPlan, suffix = "") => {
+ const { slug } = subscription;
+ if (
+ slug === SubscriptionPlanTypes.Enterprise ||
+ slug === SubscriptionPlanTypes.OnPremEnterprise
+ ) {
+ return `Enterprise${suffix}`;
+ }
+ if (!slug || slug === SubscriptionPlanTypes.Starter) {
+ return `Free${suffix}`;
+ }
+ return `Pro${suffix}`;
+};
diff --git a/frontend/src/hooks/api/subscriptions/index.tsx b/frontend/src/hooks/api/subscriptions/index.tsx
index 4ccfd6b155..c0dd0094a4 100644
--- a/frontend/src/hooks/api/subscriptions/index.tsx
+++ b/frontend/src/hooks/api/subscriptions/index.tsx
@@ -1 +1,2 @@
+export { getSubscriptionPlanLabel } from "./fns";
export { useGetOrgSubscription } from "./queries";
diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
index 3020b0ccf0..cb629a4d9c 100644
--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
@@ -82,8 +82,9 @@ import {
import { authKeys, selectOrganization } from "@app/hooks/api/auth/queries";
import { MfaMethod } from "@app/hooks/api/auth/types";
import { getAuthToken } from "@app/hooks/api/reactQuery";
+import { getSubscriptionPlanLabel } from "@app/hooks/api/subscriptions";
import { SubscriptionPlanTypes } from "@app/hooks/api/subscriptions/types";
-import { Organization, SubscriptionPlan } from "@app/hooks/api/types";
+import { Organization } from "@app/hooks/api/types";
import { AuthMethod } from "@app/hooks/api/users/types";
import {
ApplicationSelect,
@@ -97,12 +98,6 @@ import { NewSubOrganizationForm } from "./NewSubOrganizationForm";
import { NotificationDropdown } from "./NotificationDropdown";
import { VersionBadge } from "./VersionBadge";
-const getPlan = (subscription: SubscriptionPlan) => {
- if (subscription.groups) return "Enterprise";
- if (subscription.pitRecovery) return "Pro";
- return "Free";
-};
-
const getFormattedSupportEmailLink = (variables: {
org_id: string;
domain: string;
@@ -619,7 +614,7 @@ export const Navbar = () => {
</Tooltip>
) : (
<Badge variant="info" className="mt-[3px] mr-3 hidden md:inline-flex">
- {getPlan(subscription)}
+ {getSubscriptionPlanLabel(subscription)}
</Badge>
)}
<VersionBadge />
diff --git a/frontend/src/layouts/OrganizationLayout/components/SidebarHeader/SidebarHeader.tsx b/frontend/src/layouts/OrganizationLayout/components/SidebarHeader/SidebarHeader.tsx
index 99fe87adf4..ab924c5955 100644
--- a/frontend/src/layouts/OrganizationLayout/components/SidebarHeader/SidebarHeader.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/SidebarHeader/SidebarHeader.tsx
@@ -1,11 +1,5 @@
import { useOrganization, useSubscription } from "@app/context";
-import { SubscriptionPlan } from "@app/hooks/api/types";
-
-const getPlan = (subscription: SubscriptionPlan) => {
- if (subscription.groups) return "Enterprise Plan";
- if (subscription.pitRecovery) return "Pro Plan";
- return "Free Plan";
-};
+import { getSubscriptionPlanLabel } from "@app/hooks/api/subscriptions";
export const SidebarHeader = () => {
const { currentOrg } = useOrganization();
@@ -20,7 +14,9 @@ export const SidebarHeader = () => {
<div className="max-w-36 truncate text-sm font-medium text-ellipsis capitalize">
{currentOrg?.name}
</div>
- <div className="text-xs text-mineshaft-400">{getPlan(subscription)}</div>
+ <div className="text-xs text-mineshaft-400">
+ {getSubscriptionPlanLabel(subscription, " Plan")}
+ </div>
</div>
</div>
);
diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
index 73a420ff64..415b9846b1 100644
--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
@@ -78,12 +78,6 @@ export const BillingV2Page = () => {
const cadence = intervalToCadence(overview?.interval ?? null);
- // New customers check out; existing subscribers add/manage products via the Stripe portal.
- let sheetManageMode: "checkout" | "portal" = "portal";
- if (overview?.subState === "no-subscription") {
- sheetManageMode = "checkout";
- }
-
const close = () => setFlow(null);
const redirectToPortal = async () => {
@@ -117,24 +111,19 @@ export const BillingV2Page = () => {
redirectToPortal();
};
- // No subscription yet: send the customer to the product list to pick what they want, rather than
- // pre-selecting a product for them.
- const onGetStarted = () => {
- document
- .getElementById("billing-v2-products")
- ?.scrollIntoView({ behavior: "smooth", block: "start" });
- };
-
const onUpgrade = (productId: string) => {
setFlow({ type: "sheet", prodId: productId });
};
+ // Owned products are managed in the Stripe portal; a product the org isn't entitled to yet always
+ // goes through checkout, even when a subscription already exists.
const onSheetManage = async (productId: string) => {
- if (sheetManageMode === "checkout") {
- await redirectToCheckout(productId);
+ const isEntitled = Boolean(overview?.entitlements[productId]?.entitled);
+ if (isEntitled) {
+ await redirectToPortal();
return;
}
- await redirectToPortal();
+ await redirectToCheckout(productId);
};
const onUpdatePayment = async () => {
@@ -192,7 +181,6 @@ export const BillingV2Page = () => {
onUpdatePayment={onUpdatePayment}
onEditDetails={onEditDetails}
onContact={onContact}
- onGetStarted={onGetStarted}
onRetry={onRetry}
canManageBilling={canManageBilling}
/>
@@ -206,7 +194,6 @@ export const BillingV2Page = () => {
prod={catalogById(catalog, flow.prodId)}
entitlement={overview?.entitlements[flow.prodId]}
cadence={cadence}
- manageMode={sheetManageMode}
redirecting={sheetRedirecting}
onClose={close}
onManage={onSheetManage}
diff --git a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
index 6dced9aec7..885f94fb65 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
@@ -1,7 +1,5 @@
import { ReactNode } from "react";
import {
- faArrowRight,
- faBagShopping,
faCalendar,
faCircleExclamation,
faCircleInfo,
@@ -193,31 +191,6 @@ const ErrorPanel = ({ onRetry }: ErrorPanelProps) => (
</Card>
);
-type GetStartedProps = {
- onGetStarted: () => void;
- canManage: boolean;
-};
-
-const GetStarted = ({ onGetStarted, canManage }: GetStartedProps) => (
- <Card>
- <div className="flex flex-col items-center gap-4 px-7 py-12 text-center">
- <div className="flex size-[54px] items-center justify-center rounded-xl border border-org/25 bg-org/10 text-2xl text-org">
- <FontAwesomeIcon icon={faBagShopping} />
- </div>
- <div className="text-lg font-semibold text-foreground">Start your subscription</div>
- <div className="max-w-[42ch] text-sm text-mineshaft-300">
- Pick the products your team needs and check out securely. You can change or cancel any time.
- </div>
- {canManage && (
- <Button variant="org" size="lg" onClick={onGetStarted}>
- Get started
- <FontAwesomeIcon icon={faArrowRight} />
- </Button>
- )}
- </div>
- </Card>
-);
-
type SummaryCardProps = {
overview: BillingV2Overview;
};
@@ -549,7 +522,6 @@ export type OverviewProps = {
onUpdatePayment: () => void;
onEditDetails: () => void;
onContact: (prod: BillingV2CatalogProduct) => void;
- onGetStarted: () => void;
onRetry: () => void;
canManageBilling: boolean;
};
@@ -563,7 +535,6 @@ export const Overview = ({
onUpdatePayment,
onEditDetails,
onContact,
- onGetStarted,
onRetry,
canManageBilling
}: OverviewProps) => {
@@ -594,17 +565,14 @@ export const Overview = ({
onUpdatePayment={onUpdatePayment}
onManageSubscription={onManageSubscription}
/>
- <GetStarted onGetStarted={onGetStarted} canManage={canManageBilling} />
<UsageCard overview={overview} />
- <div id="billing-v2-products">
- <ProductsCard
- overview={overview}
- catalog={catalog}
- readOnly={productsReadOnly}
- onManage={onUpgrade}
- onContact={onContact}
- />
- </div>
+ <ProductsCard
+ overview={overview}
+ catalog={catalog}
+ readOnly={productsReadOnly}
+ onManage={onUpgrade}
+ onContact={onContact}
+ />
</div>
);
}
diff --git a/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx b/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
index 94323fc9d0..ea313a5e6e 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
@@ -82,12 +82,14 @@ type PlansViewProps = {
prod: BillingV2CatalogProduct;
entitlement?: BillingV2Entitlement;
cadence: BillingV2Cadence;
+ onContact: (prod: BillingV2CatalogProduct) => void;
};
-const PlansView = ({ prod, entitlement, cadence }: PlansViewProps) => {
+const PlansView = ({ prod, entitlement, cadence, onContact }: PlansViewProps) => {
const hasEnterprise = !!prod.enterprise;
const priceParts = proPriceParts(prod, cadence);
const entitled = Boolean(entitlement?.entitled);
+ const selfServe = Boolean(prod.pro?.planKey);
return (
<>
@@ -110,18 +112,18 @@ const PlansView = ({ prod, entitlement, cadence }: PlansViewProps) => {
<Badge variant="org">Self-serve</Badge>
)}
</div>
- {priceParts ? (
+ {priceParts && (
<div className="flex flex-wrap items-baseline gap-1.5">
<span className="text-2xl font-semibold text-foreground">{priceParts.amount}</span>
<span className="text-xs text-mineshaft-400">{priceParts.unit}</span>
</div>
- ) : null}
- {prod.pro?.proFeature ? (
+ )}
+ {prod.pro?.proFeature && (
<div className="text-xs text-mineshaft-300">{prod.pro.proFeature}</div>
- ) : null}
+ )}
</div>
- {hasEnterprise && prod.enterprise ? (
+ {hasEnterprise && prod.enterprise && (
<div className="flex flex-col gap-3.5 rounded-xl border border-border bg-card p-[18px]">
<div className="flex items-center justify-between gap-2">
<span className="text-[15px] font-semibold text-foreground">Enterprise</span>
@@ -131,11 +133,22 @@ const PlansView = ({ prod, entitlement, cadence }: PlansViewProps) => {
<span className="text-2xl font-semibold text-foreground">Custom</span>
</div>
<div className="text-xs text-mineshaft-300">{prod.enterprise.feature}</div>
+ {selfServe && (
+ <Button
+ variant="info"
+ size="sm"
+ className="mt-auto self-start"
+ onClick={() => onContact(prod)}
+ >
+ Contact sales
+ <FontAwesomeIcon icon={faArrowRight} />
+ </Button>
+ )}
</div>
- ) : null}
+ )}
</div>
- {hasEnterprise && prod.compare ? (
+ {hasEnterprise && prod.compare && (
<div>
<div className="mb-3 text-xs font-semibold tracking-wide text-mineshaft-400 uppercase">
Compare plans
@@ -159,9 +172,9 @@ const PlansView = ({ prod, entitlement, cadence }: PlansViewProps) => {
</TableBody>
</Table>
</div>
- ) : null}
+ )}
- {!(hasEnterprise && prod.compare) && prod.includes ? (
+ {!(hasEnterprise && prod.compare) && prod.includes && (
<div>
<div className="mb-3 text-xs font-semibold tracking-wide text-mineshaft-400 uppercase">
What&apos;s included
@@ -175,7 +188,7 @@ const PlansView = ({ prod, entitlement, cadence }: PlansViewProps) => {
))}
</div>
</div>
- ) : null}
+ )}
</>
);
};
@@ -185,7 +198,6 @@ type ProductSheetProps = {
prod?: BillingV2CatalogProduct;
entitlement?: BillingV2Entitlement;
cadence: BillingV2Cadence;
- manageMode: "checkout" | "portal";
redirecting?: boolean;
onClose: () => void;
onManage: (prodId: string) => void;
@@ -197,7 +209,6 @@ export const ProductSheet = ({
prod,
entitlement,
cadence,
- manageMode,
redirecting,
onClose,
onManage,
@@ -211,7 +222,7 @@ export const ProductSheet = ({
const selfServe = Boolean(prod.pro?.planKey);
let primaryCta = null;
- if (entitled || (selfServe && manageMode === "portal")) {
+ if (entitled) {
primaryCta = (
<Button variant="org" onClick={() => onManage(prodId)} isPending={redirecting}>
Manage in Stripe
@@ -261,15 +272,20 @@ export const ProductSheet = ({
<div className="min-w-0 flex-1">
<SheetTitle className="flex flex-wrap items-center gap-2 text-base">
{prod.name}
- {entitled ? <ActiveBadge /> : null}
- {prod.addon ? <Badge variant="neutral">Add-on</Badge> : null}
+ {entitled && <ActiveBadge />}
+ {prod.addon && <Badge variant="neutral">Add-on</Badge>}
</SheetTitle>
<SheetDescription className="mt-1">{prod.tagline || prod.desc}</SheetDescription>
</div>
</SheetHeader>
<div className="flex flex-1 flex-col gap-6 overflow-y-auto p-5">
- <PlansView prod={prod} entitlement={entitlement} cadence={cadence} />
+ <PlansView
+ prod={prod}
+ entitlement={entitlement}
+ cadence={cadence}
+ onContact={onContact}
+ />
</div>
<SheetFooter className="flex-row justify-end border-t">