Skip to content

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

feat(billing): populate v2 overview payment, billing details, and invoices

Tre Dubravafa0d318b9feb
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 bfaec3a16d..b2577486b7 100644
--- a/backend/src/ee/services/license-v2/license-v2-service.ts
+++ b/backend/src/ee/services/license-v2/license-v2-service.ts
@@ -37,7 +37,13 @@ type TLicenseV2ServiceFactoryDep = {
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
licenseClient: Pick<
TLicenseClientFactory,
- "getEntitlements" | "getCatalog" | "getSubscription" | "getCloudPlan" | "createCheckout" | "createPortal"
+ | "getEntitlements"
+ | "getCatalog"
+ | "getSubscription"
+ | "getCloudPlan"
+ | "getBillingProfile"
+ | "createCheckout"
+ | "createPortal"
>;
};
@@ -358,6 +364,29 @@ export const licenseV2ServiceFactory = ({
}
}
+ // Payment method, billing identity, and invoices come from the org's Stripe customer. A
+ // failure (or unconfigured backend) degrades to the empty state rather than failing the page.
+ let payment: BillingV2Overview["payment"] = null;
+ let billingDetails: BillingV2Overview["billingDetails"] = null;
+ let invoices: BillingV2Overview["invoices"] = [];
+ try {
+ const profile = await licenseClient.getBillingProfile(orgId);
+ if (profile) {
+ payment = profile.payment;
+ billingDetails = profile.billingDetails;
+ invoices = profile.invoices.map((invoice) => ({
+ id: invoice.id,
+ number: invoice.number,
+ date: formatDate(invoice.date) ?? "",
+ amount: centsToDollars(invoice.amount),
+ paid: invoice.paid,
+ pdfUrl: invoice.pdfUrl ?? ""
+ }));
+ }
+ } catch (error) {
+ logger.error(error, `billing-v2: failed to read billing profile [orgId=${orgId}]`);
+ }
+
const overview: BillingV2Overview = {
isCloud: true,
mode: "self-serve",
@@ -372,9 +401,9 @@ export const licenseV2ServiceFactory = ({
identities,
identityLimit
},
- payment: null,
- billingDetails: null,
- invoices: [],
+ payment,
+ billingDetails,
+ invoices,
entitlements: await buildEntitlements(orgId, subscription)
};
diff --git a/backend/src/services/license-client/license-client-backends.ts b/backend/src/services/license-client/license-client-backends.ts
index 903532789b..ae7e698d28 100644
--- a/backend/src/services/license-client/license-client-backends.ts
+++ b/backend/src/services/license-client/license-client-backends.ts
@@ -1,12 +1,14 @@
import jwt from "jsonwebtoken";
import {
+ billingProfileResponseSchema,
catalogResponseSchema,
checkoutResultSchema,
cloudPlanResponseSchema,
entitlementsResponseSchema,
sessionResponseSchema,
subscriptionResponseSchema,
+ TBillingProfileResponse,
TCatalogResponse,
TCheckoutResult,
TCloudPlanResponse,
@@ -22,6 +24,7 @@ const ENTITLEMENTS_PATH = "/v1/entitlements";
const PRODUCTS_PATH = "/v1/products";
const SUBSCRIPTION_PATH = "/v1/subscription";
const CLOUD_PLAN_PATH = "/v1/cloud-plan";
+const BILLING_PROFILE_PATH = "/v1/billing/profile";
const CHECKOUT_SESSION_PATH = "/v1/billing/checkout-session";
const PORTAL_SESSION_PATH = "/v1/billing/portal-session";
@@ -121,6 +124,26 @@ export const licenseServerBackend = (serverUrl: string, signingKey: string): TLi
return cloudPlanResponseSchema.parse(body);
},
+ // The server returns 200 with everything empty when the org has no Stripe customer yet; a 404
+ // means the org has no license at all (same as /v1/subscription), so degrade to "no profile".
+ fetchBillingProfile: async (orgId: string): Promise<TBillingProfileResponse | null> => {
+ const url = new URL(BILLING_PROFILE_PATH, serverUrl);
+ url.searchParams.set("org_id", orgId);
+ const res = await fetch(url, {
+ method: "GET",
+ headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}` },
+ redirect: "manual"
+ });
+ if (res.status === 404) {
+ return null;
+ }
+ if (!res.ok) {
+ throw new Error(`license server responded with ${res.status}`);
+ }
+ const body: unknown = await res.json();
+ return billingProfileResponseSchema.parse(body);
+ },
+
createCheckoutSession: async (orgId: string, payload: TCreateCheckoutPayload): Promise<TCheckoutResult> => {
const url = new URL(CHECKOUT_SESSION_PATH, serverUrl);
url.searchParams.set("org_id", orgId);
diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.ts
index 203c5863a9..a6e0e5b7fd 100644
--- a/backend/src/services/license-client/license-client-types.ts
+++ b/backend/src/services/license-client/license-client-types.ts
@@ -132,6 +132,44 @@ export const cloudPlanResponseSchema = z
})
.passthrough();
+// Billing profile: the org's Stripe payment method, billing identity, and recent invoices. Every
+// field is null/empty when the org has no Stripe customer yet (the server returns 200, not 404).
+// Invoice amounts are cents and dates are Unix seconds, matching /v1/subscription.
+const billingProfilePaymentSchema = z
+ .object({
+ brand: z.string(),
+ last4: z.string(),
+ expMonth: z.number(),
+ expYear: z.number()
+ })
+ .passthrough();
+
+const billingProfileDetailsSchema = z
+ .object({
+ name: z.string(),
+ email: z.string()
+ })
+ .passthrough();
+
+const billingProfileInvoiceSchema = z
+ .object({
+ id: z.string(),
+ number: z.string(),
+ date: z.number().nullish(),
+ amount: z.number(),
+ paid: z.boolean(),
+ pdfUrl: z.string().nullish()
+ })
+ .passthrough();
+
+export const billingProfileResponseSchema = z
+ .object({
+ payment: billingProfilePaymentSchema.nullable(),
+ billingDetails: billingProfileDetailsSchema.nullable(),
+ invoices: z.array(billingProfileInvoiceSchema).default([])
+ })
+ .passthrough();
+
export type TEntitlementFeature = z.infer<typeof entitlementFeatureSchema>;
export type TEntitlementsResponse = z.infer<typeof entitlementsResponseSchema>;
export type TCatalogProduct = z.infer<typeof catalogProductSchema>;
@@ -141,6 +179,7 @@ export type TSubscriptionResponse = z.infer<typeof subscriptionResponseSchema>;
export type TSessionResponse = z.infer<typeof sessionResponseSchema>;
export type TCheckoutResult = z.infer<typeof checkoutResultSchema>;
export type TCloudPlanResponse = z.infer<typeof cloudPlanResponseSchema>;
+export type TBillingProfileResponse = z.infer<typeof billingProfileResponseSchema>;
export type TCheckoutLineItem = {
productId: string;
@@ -164,6 +203,7 @@ export type TLicenseClientBackend = {
fetchCatalog: () => Promise<TCatalogResponse>;
fetchSubscription: (orgId: string) => Promise<TSubscriptionResponse | null>;
fetchCloudPlan: (orgId: string) => Promise<TCloudPlanResponse | null>;
+ fetchBillingProfile: (orgId: string) => Promise<TBillingProfileResponse | null>;
createCheckoutSession: (orgId: string, payload: TCreateCheckoutPayload) => Promise<TCheckoutResult>;
createPortalSession: (orgId: string, payload: TCreatePortalPayload) => Promise<TSessionResponse>;
};
diff --git a/backend/src/services/license-client/license-client.ts b/backend/src/services/license-client/license-client.ts
index d00bb04a8c..bf749e5736 100644
--- a/backend/src/services/license-client/license-client.ts
+++ b/backend/src/services/license-client/license-client.ts
@@ -79,6 +79,13 @@ export const licenseClientFactory = ({ envConfig, keyStore }: TLicenseClientFact
return backend.fetchCloudPlan(orgId);
};
+ const getBillingProfile = async (orgId: string) => {
+ if (!backend) {
+ return null;
+ }
+ return backend.fetchBillingProfile(orgId);
+ };
+
const createCheckout = async (orgId: string, payload: TCreateCheckoutPayload) => {
if (!backend) {
throw new Error("license client backend is not configured");
@@ -99,6 +106,7 @@ export const licenseClientFactory = ({ envConfig, keyStore }: TLicenseClientFact
getCatalog,
getSubscription,
getCloudPlan,
+ getBillingProfile,
createCheckout,
createPortal
};