Skip to content

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

fix(billing): handle partial billing addresses and correct usage units and use dynamic icons

Scott Wilson24b30c4bdf0c
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.ts
index 5c4af8cac0..b89a403c4d 100644
--- a/backend/src/ee/routes/v1/license-v2-router.ts
+++ b/backend/src/ee/routes/v1/license-v2-router.ts
@@ -92,12 +92,13 @@ const BillingV2OverviewSchema = z.object({
email: z.string(),
address: z
.object({
- line1: z.string(),
- line2: z.string(),
- city: z.string(),
- state: z.string(),
- postalCode: z.string(),
- country: z.string()
+ // Each sub-field is nullish: Stripe/older license servers omit or null any unfilled line.
+ line1: z.string().nullish(),
+ line2: z.string().nullish(),
+ city: z.string().nullish(),
+ state: z.string().nullish(),
+ postalCode: z.string().nullish(),
+ country: z.string().nullish()
})
.nullable(),
taxIds: z.object({ type: z.string(), value: z.string() }).array()
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 4b7dd9f5f9..eee419348a 100644
--- a/backend/src/ee/services/license-v2/license-v2-service.ts
+++ b/backend/src/ee/services/license-v2/license-v2-service.ts
@@ -284,22 +284,28 @@ export const licenseV2ServiceFactory = ({
if (subscription) {
subscription.items.forEach((item) => {
- const quantityValues = Object.values(item.quantities);
+ // Surface one dimension's used count, limit, and noun together so the rendered
+ // "{used} / {limit} {unit}" always describes the same thing. "Most constraining" = the
+ // highest utilization (closest to, or furthest past, its cap), i.e. the limit the customer
+ // is likeliest to hit. Each limit is paired with its OWN quantity; taking Math.max across all
+ // quantities could otherwise report a different dimension's count than the resolved unit.
let used = 0;
- if (quantityValues.length > 0) {
- used = Math.max(...quantityValues);
- }
-
- // Surface the most constraining dimension and resolve that same dimension's noun, so the
- // count and its unit always describe the same thing.
let limit: number | null = null;
let limitKey: string | null = null;
+ let highestUtilization = -1;
// Plain for-of (not forEach): assignments inside a closure don't refine the outer
// variable's type, so after a forEach TS still sees limitKey as null and the `limitKey ?`
// branch below collapses to `never`. A same-scope loop lets control-flow keep it string|null.
- for (const [key, value] of Object.entries(item.limits)) {
- if (limit === null || value > limit) {
- limit = value;
+ for (const [key, dimensionLimit] of Object.entries(item.limits)) {
+ const dimensionUsed = item.quantities[key] ?? 0;
+ // An unlimited (<= 0) cap can't be "hit"; only a positive cap yields a real ratio.
+ const utilization =
+ // eslint-disable-next-line no-nested-ternary
+ dimensionLimit > 0 ? dimensionUsed / dimensionLimit : dimensionUsed > 0 ? Infinity : 0;
+ if (limitKey === null || utilization > highestUtilization) {
+ highestUtilization = utilization;
+ used = dimensionUsed;
+ limit = dimensionLimit;
limitKey = key;
}
}
@@ -401,25 +407,11 @@ export const licenseV2ServiceFactory = ({
const profile = await licenseClient.getBillingProfile(orgId);
if (profile) {
payment = profile.payment;
+ // name/email/address/taxIds pass straight through (address keeps its nullable sub-fields;
+ // the UI drops blank lines). The ?? null just normalizes an absent address to null, and any
+ // extra license-server keys the spread carries are stripped by the response schema.
billingDetails = profile.billingDetails
- ? {
- name: profile.billingDetails.name,
- email: profile.billingDetails.email,
- address: profile.billingDetails.address
- ? {
- line1: profile.billingDetails.address.line1,
- line2: profile.billingDetails.address.line2,
- city: profile.billingDetails.address.city,
- state: profile.billingDetails.address.state,
- postalCode: profile.billingDetails.address.postalCode,
- country: profile.billingDetails.address.country
- }
- : null,
- taxIds: profile.billingDetails.taxIds.map((taxId) => ({
- type: taxId.type,
- value: taxId.value
- }))
- }
+ ? { ...profile.billingDetails, address: profile.billingDetails.address ?? null }
: null;
invoices = profile.invoices.map((invoice) => ({
id: invoice.id,
diff --git a/backend/src/ee/services/license-v2/license-v2-types.ts b/backend/src/ee/services/license-v2/license-v2-types.ts
index 4e27b4c329..b16f5e9c16 100644
--- a/backend/src/ee/services/license-v2/license-v2-types.ts
+++ b/backend/src/ee/services/license-v2/license-v2-types.ts
@@ -89,12 +89,12 @@ export type BillingV2Overview = {
name: string;
email: string;
address: {
- line1: string;
- line2: string;
- city: string;
- state: string;
- postalCode: string;
- country: string;
+ line1?: string | null;
+ line2?: string | null;
+ city?: string | null;
+ state?: string | null;
+ postalCode?: string | null;
+ country?: string | null;
} | null;
taxIds: { type: string; value: string }[];
} | null;
diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.ts
index 825971127a..a7423f674d 100644
--- a/backend/src/services/license-client/license-client-types.ts
+++ b/backend/src/services/license-client/license-client-types.ts
@@ -144,14 +144,18 @@ const billingProfilePaymentSchema = z
})
.passthrough();
+// Stripe leaves any unfilled field null (line2/state are absent for most customers) and older
+// license servers may omit them, so every sub-field is nullish. A strict z.string() would throw on
+// a partial address; because the whole profile is parsed in one shot, that failure silently drops
+// the customer's payment method and invoices too, not just the address.
const billingProfileAddressSchema = z
.object({
- line1: z.string(),
- line2: z.string(),
- city: z.string(),
- state: z.string(),
- postalCode: z.string(),
- country: z.string()
+ line1: z.string().nullish(),
+ line2: z.string().nullish(),
+ city: z.string().nullish(),
+ state: z.string().nullish(),
+ postalCode: z.string().nullish(),
+ country: z.string().nullish()
})
.passthrough();
diff --git a/frontend/src/hooks/api/billingV2/types.ts b/frontend/src/hooks/api/billingV2/types.ts
index 35aa80661e..40c01f0f33 100644
--- a/frontend/src/hooks/api/billingV2/types.ts
+++ b/frontend/src/hooks/api/billingV2/types.ts
@@ -88,12 +88,12 @@ export type BillingV2Overview = {
name: string;
email: string;
address: {
- line1: string;
- line2: string;
- city: string;
- state: string;
- postalCode: string;
- country: string;
+ line1?: string | null;
+ line2?: string | null;
+ city?: string | null;
+ state?: string | null;
+ postalCode?: string | null;
+ country?: string | null;
} | null;
taxIds: { type: string; value: string }[];
} | null;
diff --git a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
index b357e86e58..0bfb01ad88 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
@@ -1,24 +1,20 @@
import { ReactNode } from "react";
-import {
- faCircleExclamation,
- faCircleInfo,
- faCreditCard,
- faRotate,
- faTriangleExclamation,
- faUpRightFromSquare,
- IconDefinition
-} from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
ArrowBigUpDashIcon,
Building2,
Calendar,
+ CircleAlert,
CreditCard,
+ ExternalLink,
GaugeIcon,
+ Info,
+ type LucideIcon,
Package,
ReceiptText,
+ RefreshCw,
ShieldAlert,
- ShieldCheck
+ ShieldCheck,
+ TriangleAlert
} from "lucide-react";
import {
@@ -76,7 +72,7 @@ type BannerProps = {
type Dunning = {
variant: "warning" | "danger";
- icon: IconDefinition;
+ icon: LucideIcon;
title: string;
body: string;
};
@@ -84,13 +80,13 @@ type Dunning = {
const DUNNING: Partial<Record<BillingV2RenderState, Dunning>> = {
"past-due": {
variant: "warning",
- icon: faTriangleExclamation,
+ icon: TriangleAlert,
title: "We couldn't process your last payment",
body: "Update your payment method to avoid losing access. Your products are still active while we retry."
},
suspended: {
variant: "danger",
- icon: faCircleExclamation,
+ icon: CircleAlert,
title: "Your subscription is suspended",
body: "A payment kept failing and access is paused. Complete payment to restore access to your products."
}
@@ -106,7 +102,7 @@ const Banner = ({
if (mode === "managed") {
return (
<Alert variant="info">
- <FontAwesomeIcon icon={faCircleInfo} />
+ <Info />
<AlertTitle>Your plan is managed by your account team</AlertTitle>
<AlertDescription>
Products and limits on this organization are set by contract. Contact your account manager
@@ -121,16 +117,17 @@ const Banner = ({
return null;
}
+ const DunningIcon = dunning.icon;
return (
<Alert variant={dunning.variant}>
- <FontAwesomeIcon icon={dunning.icon} />
+ <DunningIcon />
<AlertTitle>{dunning.title}</AlertTitle>
<AlertDescription>
{dunning.body}
{canManage && (
<div className="mt-3 flex flex-wrap gap-2">
<Button variant={dunning.variant} size="sm" onClick={onUpdatePayment}>
- <FontAwesomeIcon icon={faCreditCard} />
+ <CreditCard />
Update payment method
</Button>
<Button variant="outline" size="sm" onClick={onManageSubscription}>
@@ -209,7 +206,7 @@ type ErrorPanelProps = {
const ErrorPanel = ({ onRetry }: ErrorPanelProps) => (
<Card>
<div className="flex flex-col items-center gap-3 px-7 py-10 text-center">
- <FontAwesomeIcon icon={faCircleExclamation} className="text-3xl text-danger" />
+ <CircleAlert className="size-8 text-danger" />
<div className="text-base font-semibold text-foreground">
Couldn&apos;t load your subscription
</div>
@@ -217,7 +214,7 @@ const ErrorPanel = ({ onRetry }: ErrorPanelProps) => (
There was a problem reaching the billing service. Your products are unaffected.
</div>
<Button variant="outline" size="sm" onClick={onRetry}>
- <FontAwesomeIcon icon={faRotate} />
+ <RefreshCw />
Try again
</Button>
</div>
@@ -544,7 +541,8 @@ const formatAddressLines = (address: BillingAddress): string[] => {
address.line2,
regionLine,
address.country ? countryName(address.country) : ""
- ].filter(Boolean);
+ // type-guard predicate (not bare Boolean) so the nullable sub-fields narrow to string[].
+ ].filter((line): line is string => Boolean(line));
};
// Friendly labels for common Stripe tax-id types; falls back to the upper-cased raw type.
@@ -695,7 +693,7 @@ const InvoicesCard = ({ invoices }: InvoicesCardProps) => (
target="_blank"
rel="noopener noreferrer"
>
- <FontAwesomeIcon icon={faUpRightFromSquare} />
+ <ExternalLink className="size-3.5" />
PDF
</a>
) : (
diff --git a/frontend/src/pages/organization/BillingV2Page/components/shared.tsx b/frontend/src/pages/organization/BillingV2Page/components/shared.tsx
index 88dd5b158f..a7c63d177c 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/shared.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/shared.tsx
@@ -1,39 +1,8 @@
-import { Award, Box, LucideIcon, ScanLine, Shield, Zap } from "lucide-react";
+import { Box } from "lucide-react";
+import { DynamicIcon, type IconName } from "lucide-react/dynamic";
import { Badge, Label } from "@app/components/v3";
-import { getProjectLucideIcon } from "@app/helpers/project";
import { BillingV2CatalogProduct } from "@app/hooks/api";
-import { ProjectType } from "@app/hooks/api/projects/types";
-
-// Catalog products carry a free-form icon token (license-server presentation metadata), not a
-// project type. Tokens that name one of our products resolve through the shared project icon helper
-// so billing stays in sync with the rest of the app; add-on / generic tokens keep a direct glyph,
-// and anything unrecognized falls back to Box.
-const TOKEN_PROJECT_TYPE: Record<string, ProjectType> = {
- vault: ProjectType.SecretManager,
- key: ProjectType.SecretManager,
- file_key: ProjectType.CertificateManager,
- lock: ProjectType.KMS,
- scan_search: ProjectType.SecretScanning,
- radar: ProjectType.SecretScanning,
- users: ProjectType.PAM,
- terminal: ProjectType.SSH
-};
-
-const ADDON_ICON_BY_TOKEN: Record<string, LucideIcon> = {
- shield: Shield,
- award: Award,
- scan_line: ScanLine,
- zap: Zap
-};
-
-const iconForToken = (token: string): LucideIcon => {
- const projectType = TOKEN_PROJECT_TYPE[token];
- if (projectType) {
- return getProjectLucideIcon(projectType);
- }
- return ADDON_ICON_BY_TOKEN[token] ?? Box;
-};
type MeterTone = "ok" | "near" | "full";
@@ -42,13 +11,23 @@ type ProductIconProps = {
size?: number;
};
-// Tinted product icon tile. The tint is per-product brand metadata from the API, so it stays inline.
+// Shown while a product's icon chunk loads and for any token lucide doesn't recognize. Sized to half
+// the tile via CSS so it matches the resolved glyph at any tile size.
+const ProductIconFallback = () => <Box className="h-1/2 w-1/2" />;
+
+// Tinted product icon tile. Both the icon token and the tint are per-product presentation metadata
+// from the license-server catalog (the source of truth), so we render the glyph straight from the
+// token rather than mapping it to an app concept. Catalog tokens are snake_case while lucide icon
+// names are kebab-case, so we only normalize the separator before handing the name to lucide's
+// dynamic icon. Unknown or still-loading tokens fall back to a generic box glyph (the catalog's own
+// default is "box").
export const ProductIcon = ({ product, size = 36 }: ProductIconProps) => {
- const Glyph = iconForToken(product.icon);
const { color } = product;
+ const glyphSize = Math.round(size * 0.5);
+ const iconName = product.icon.replace(/_/g, "-") as IconName;
return (
<div
- className="flex shrink-0 items-center justify-center rounded-sm border transition-colors duration-200"
+ className="flex shrink-0 items-center justify-center rounded-md border transition-colors duration-200"
style={{
width: size,
height: size,
@@ -57,7 +36,7 @@ export const ProductIcon = ({ product, size = 36 }: ProductIconProps) => {
color
}}
>
- <Glyph size={Math.round(size * 0.5)} />
+ <DynamicIcon name={iconName} size={glyphSize} fallback={ProductIconFallback} />
</div>
);
};