Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: addressed review comments
=dcd49aa30c89
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.tsindex 0e00560ed7..753c4cd58c 100644--- a/backend/src/ee/routes/v1/license-v2-router.ts+++ b/backend/src/ee/routes/v1/license-v2-router.ts@@ -128,6 +128,7 @@ const BillingV2EntitlementSchema = z.object({trialPlanEndsAt: z.string().nullable().optional(),trialPlanDaysLeft: z.number().nullable().optional(),trialPaymentDueAt: z.string().nullable().optional(),+ trialPlanPaymentDueAt: z.string().nullable().optional(),renewsOn: z.string().nullable().optional(),deprecation: BillingV2DeprecationSchema.extend({kind: z.enum(["product", "plan"])@@ -787,13 +788,13 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {schema: {operationId: "confirmBillingTrialPayment",description:- "Open a Stripe Checkout where the customer approves a trial conversion charge their bank is holding (for example 3D Secure). The trial converts once the checkout completes.",+ "Get the page where the customer approves a trial conversion charge their bank is holding (for example 3D Secure): a Stripe Checkout for a trial on the free tier, or the invoice of the held change for an upgrade trial. The trial converts once it is paid.",params: z.object({ organizationId: z.string().trim().uuid() }),body: z.object({ returnPath: ReturnPathSchema }),response: {200: z.object({- outcome: z.literal("checkout_created"),- checkoutUrl: z.string()+ outcome: z.enum(["checkout_created", "payment_action_required"]),+ redirectUrl: z.string()})}},diff --git a/backend/src/ee/services/license-v2/license-v2-service.ts b/backend/src/ee/services/license-v2/license-v2-service.tsindex 3fd175dd30..a860a9927a 100644--- a/backend/src/ee/services/license-v2/license-v2-service.ts+++ b/backend/src/ee/services/license-v2/license-v2-service.ts@@ -683,7 +683,8 @@ export const licenseV2ServiceFactory = ({trialPlanName:catalogProduct?.plans.find((candidate) => candidate.tier === item.trialPlan)?.name ?? item.trialPlan,trialPlanEndsAt: formatDate(item.trialPlanEndsAt),- trialPlanDaysLeft: daysUntil(item.trialPlanEndsAt)+ trialPlanDaysLeft: item.trialPlanPaymentDueAt ? null : daysUntil(item.trialPlanEndsAt),+ trialPlanPaymentDueAt: formatDate(item.trialPlanPaymentDueAt)}: {}),trialPaymentDueAt: formatDate(item.trialPaymentDueAt),@@ -862,9 +863,10 @@ export const licenseV2ServiceFactory = ({nextCharge};- const itemsAwaitingPayment = (subscription?.items ?? []).flatMap((item) =>- item.trialPaymentDueAt ? [{ productId: item.productId, dueAt: item.trialPaymentDueAt }] : []- );+ const itemsAwaitingPayment = (subscription?.items ?? []).flatMap((item) => {+ const dueAt = item.trialPaymentDueAt ?? item.trialPlanPaymentDueAt;+ return dueAt ? [{ productId: item.productId, dueAt }] : [];+ });const trialPaymentDue =itemsAwaitingPayment.length > 0? {@@ -1452,13 +1454,17 @@ export const licenseV2ServiceFactory = ({return { outcome: result.outcome };};- // Hands back a Stripe Checkout that runs the bank's approval step for a trial conversion charge. The- // trial converts via webhook once it completes, so the revalidation window is held open like checkout.+ // The trial converts via webhook once the customer approves, so the revalidation window is held open+ // like checkout.const confirmTrialPayment = async ({ orgId, actor, returnPath }: TConfirmBillingV2TrialPaymentDTO) => {await ensureManageBilling(orgId, actor);const result = await licenseClient.confirmTrialPayment(orgId, { returnUrl: buildReturnUrl(orgId, returnPath) });+ if (result.outcome === "payment_action_required") {+ const { paymentUrl } = await paymentActionRequired(orgId, result.paymentUrl);+ return { outcome: result.outcome, redirectUrl: paymentUrl };+ }await licenseClient.markEntitlementsStale(orgId, { checkout: true });- return { outcome: result.outcome, checkoutUrl: result.checkoutUrl };+ return { outcome: result.outcome, redirectUrl: result.checkoutUrl };};// Remove a single product from a multi-product subscription, the operation the Stripe Customerdiff --git a/backend/src/ee/services/license-v2/license-v2-types.ts b/backend/src/ee/services/license-v2/license-v2-types.tsindex 5879c5392b..dd417f79c7 100644--- a/backend/src/ee/services/license-v2/license-v2-types.ts+++ b/backend/src/ee/services/license-v2/license-v2-types.ts@@ -145,6 +145,7 @@ export type BillingV2Entitlement = {trialPlanEndsAt?: string | null;trialPlanDaysLeft?: number | null;trialPaymentDueAt?: string | null;+ trialPlanPaymentDueAt?: string | null;// Formatted date this product's soonest line renews (each product bills on its own cycle); null when// the product has no dated line (e.g. feature-only entitlements).renewsOn?: string | null;diff --git a/backend/src/services/license-client/license-client-backends.test.ts b/backend/src/services/license-client/license-client-backends.test.tsindex 770a92aac5..970347c29e 100644--- a/backend/src/services/license-client/license-client-backends.test.ts+++ b/backend/src/services/license-client/license-client-backends.test.ts@@ -96,6 +96,29 @@ describe("licenseServerBackend confirmTrialPayment", () => {expect(readBody(fetchMock)).toEqual({ returnUrl: "https://app.infisical.com/organizations/org-1/billing" });expect(result).toMatchObject({ outcome: "checkout_created", checkoutUrl: "https://checkout.stripe.com/c/1" });});++ test("accepts an upgrade trial's held change and its payment URL", async () => {+ vi.stubGlobal(+ "fetch",+ mockFetchReturning({ outcome: "payment_action_required", paymentUrl: "https://invoice.stripe.com/i/1" })+ );++ const result = await licenseServerBackend(SERVER_URL, "key").confirmTrialPayment(ORG_ID, {+ returnUrl: "https://app.infisical.com/organizations/org-1/billing"+ });++ expect(result).toMatchObject({ outcome: "payment_action_required", paymentUrl: "https://invoice.stripe.com/i/1" });+ });++ test("rejects an outcome without the URL it needs", async () => {+ vi.stubGlobal("fetch", mockFetchReturning({ outcome: "payment_action_required" }));++ await expect(+ licenseServerBackend(SERVER_URL, "key").confirmTrialPayment(ORG_ID, {+ returnUrl: "https://app.infisical.com/organizations/org-1/billing"+ })+ ).rejects.toThrow();+ });});describe("licenseServerBackend payment_action_required", () => {@@ -137,3 +160,35 @@ describe("licenseServerBackend payment_action_required", () => {expect(result.outcome).toBe("payment_action_required");});});++describe("licenseServerBackend rejected billing requests", () => {+ afterEach(() => {+ vi.unstubAllGlobals();+ });++ const rejecting = (body: unknown) =>+ vi.fn(async () => ({+ ok: false,+ status: 409,+ headers: new Headers({ "x-request-id": "req-1" }),+ json: async () => body+ })) as unknown as typeof fetch;++ test.each([+ {+ code: "change_awaiting_payment",+ want: "You have a payment waiting for your bank's approval. Complete it from the banner above before making another change."+ },+ { code: "lock_held", want: "Another billing change is in progress. Please try again in a moment." }+ ])("$code is shown as customer copy, not the server's wording", async ({ code, want }) => {+ vi.stubGlobal("fetch", rejecting({ error: "BadRequest", message: "server wording", details: { code } }));++ await expect(+ licenseServerBackend(SERVER_URL, "key").upgradeProduct(ORG_ID, {+ productId: "boost",+ plan: "enterprise",+ expectedPlanVersionId: "v1"+ })+ ).rejects.toThrow(want);+ });+});diff --git a/backend/src/services/license-client/license-client-backends.ts b/backend/src/services/license-client/license-client-backends.tsindex 3d0934cdc3..e56ef41a80 100644--- a/backend/src/services/license-client/license-client-backends.ts+++ b/backend/src/services/license-client/license-client-backends.ts@@ -100,7 +100,10 @@ const BILLING_ERROR_MESSAGES: Record<string, string> = {no_payment_method: "Add a payment method before making this change.",subscription_syncing: "Your billing details are still syncing. Please try again in a moment.",plan_deprecated: "This plan is being retired and is no longer available.",- no_trial_awaiting_payment: "There's no trial payment waiting to be completed. It may have already gone through."+ no_trial_awaiting_payment: "There's no trial payment waiting to be completed. It may have already gone through.",+ change_awaiting_payment:+ "You have a payment waiting for your bank's approval. Complete it from the banner above before making another change.",+ lock_held: "Another billing change is in progress. Please try again in a moment."};const throwIfResponseError = async (res: Response): Promise<void> => {diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.tsindex 89a12427e9..d124def7ed 100644--- a/backend/src/services/license-client/license-client-types.ts+++ b/backend/src/services/license-client/license-client-types.ts@@ -170,6 +170,8 @@ const subscriptionItemSchema = ztrialPlan: z.string().nullish(),trialPlanEndsAt: z.number().nullish(),trialPaymentDueAt: z.number().nullish(),+ // An upgrade trial held for the customer's payment approval: trialPlan stays live until then.+ trialPlanPaymentDueAt: z.number().nullish(),// Present only when this item's product OR plan is deprecated (product supersedes plan). The item// keeps working; this carries the contract-specific message (the sunset date comes from the catalog).deprecation: z.object({ reason: z.string().nullish(), nextSteps: z.string().nullish() }).nullish(),@@ -225,7 +227,7 @@ export const subscriptionResponseSchema = zcurrentPeriodEnd: z.number().nullish(),recurringTotal: z.number().nullish(),billing: subscriptionBillingSchema.nullish(),- payment: z.object({ state: z.string(), actionUrl: z.string() }).passthrough().nullish(),+ payment: z.object({ state: z.string().nullish(), actionUrl: z.string().nullish() }).passthrough().nullish(),tier: z.string().optional(),items: z.array(subscriptionItemSchema)})@@ -480,19 +482,20 @@ export type TConfirmTrialPaymentPayload = {returnUrl: string;};-// A Stripe Checkout that runs the bank's approval step for a trial conversion charge. 409+const httpUrlSchema = z+ .string()+ .url()+ .refine((val) => val.startsWith("http://") || val.startsWith("https://"), {+ message: "URL must start with http:// or https://"+ });++// Where the customer approves a trial conversion charge their bank held: a Stripe Checkout for a+// free-tier trial, or the invoice of a change Stripe holds for an upgrade trial. 409// no_trial_awaiting_payment when nothing is waiting.-const confirmTrialPaymentResultSchema = z- .object({- outcome: z.literal("checkout_created"),- checkoutUrl: z- .string()- .url()- .refine((val) => val.startsWith("http://") || val.startsWith("https://"), {- message: "URL must start with http:// or https://"- })- })- .passthrough();+const confirmTrialPaymentResultSchema = z.discriminatedUnion("outcome", [+ z.object({ outcome: z.literal("checkout_created"), checkoutUrl: httpUrlSchema }).passthrough(),+ z.object({ outcome: z.literal("payment_action_required"), paymentUrl: httpUrlSchema }).passthrough()+]);export type TConfirmTrialPaymentResult = z.infer<typeof confirmTrialPaymentResultSchema>;export { confirmTrialPaymentResultSchema };diff --git a/frontend/src/hooks/api/billingV2/types.ts b/frontend/src/hooks/api/billingV2/types.tsindex 34825df897..e8c890fe07 100644--- a/frontend/src/hooks/api/billingV2/types.ts+++ b/frontend/src/hooks/api/billingV2/types.ts@@ -146,6 +146,7 @@ export type BillingV2Entitlement = {// Formatted grace deadline while the trial's conversion charge waits on the customer's bank. The// product stays trialing and usable until then, even though trialEndsAt has passed.trialPaymentDueAt?: string | null;+ trialPlanPaymentDueAt?: string | null;// Formatted date this product's soonest line renews (each product bills on its own cycle); null when// the product has no dated line.renewsOn?: string | null;@@ -372,8 +373,8 @@ export type TConfirmBillingV2TrialPaymentDTO = {};export type BillingV2ConfirmTrialPaymentResult = {- outcome: "checkout_created";- checkoutUrl: string;+ outcome: "checkout_created" | "payment_action_required";+ redirectUrl: string;};// License-server machine codes the billing UI branches on (read from the error's details.code).diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsxindex f6ccea033b..e6c978ab9e 100644--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx@@ -192,8 +192,13 @@ export const BillingV2Page = () => {returnPath: window.location.pathname},{- onSuccess: ({ checkoutUrl }) => {- window.location.href = checkoutUrl;+ onSuccess: ({ outcome, redirectUrl }) => {+ // A Stripe hosted invoice never redirects back, so it opens beside the app.+ if (outcome === "payment_action_required") {+ window.open(redirectUrl, "_blank", "noopener,noreferrer");+ return;+ }+ window.location.href = redirectUrl;}});diff --git a/frontend/src/pages/organization/BillingV2Page/components/Banner.tsx b/frontend/src/pages/organization/BillingV2Page/components/Banner.tsxindex 434e3afd5a..ee2f1df81f 100644--- a/frontend/src/pages/organization/BillingV2Page/components/Banner.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/Banner.tsx@@ -50,7 +50,7 @@ const PAYMENT_ALERT: Record<needs_action: {variant: "warning",icon: TriangleAlert,- title: "Your bank needs you to approve your renewal payment",+ title: "Your bank needs you to approve a payment",body: "Approve the payment to keep your products active.",actionLabel: "Approve Payment"},diff --git a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsxindex bab1dea55d..00f477cdf3 100644--- a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx@@ -82,6 +82,7 @@ const ActiveProductCard = ({const trialDaysLeft = entitlement?.trialPlanDaysLeft;// Past trialEndsAt but still usable: the conversion charge is waiting on the customer's bank.const trialPaymentDueAt = entitlement?.trialPaymentDueAt;+ const trialPlanPaymentDueAt = entitlement?.trialPlanPaymentDueAt;// The headline figure steps down a size when a second amount line shares the block.const priceLines = [annualCommitted > 0, monthlyRecurring > 0, onDemand > 0].filter(@@ -172,10 +173,10 @@ const ActiveProductCard = ({<Clock className="size-3.5 shrink-0 text-warning" />Trialing {trialPlanName}</span>- {trialPaymentDueAt && (+ {trialPlanPaymentDueAt && (<span className="shrink-0 text-xs font-medium text-warning">Payment needed</span>)}- {!trialPaymentDueAt && trialDaysLeft !== null && trialDaysLeft !== undefined && (+ {!trialPlanPaymentDueAt && trialDaysLeft !== null && trialDaysLeft !== undefined && (<span className="shrink-0 text-xs font-medium text-warning tabular-nums">{trialDaysLeft === 0? "Ends today"@@ -184,9 +185,9 @@ const ActiveProductCard = ({)}</div><span className="text-[11px] text-muted">- {trialPaymentDueAt ? (+ {trialPlanPaymentDueAt ? (<>- Access until {trialPaymentDueAt} · confirm payment to upgrade to {trialPlanName}+ Access until {trialPlanPaymentDueAt} · confirm payment to upgrade to {trialPlanName}</>) : (<>