Skip to content

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

fix: resolved upgrade error

=54c8a53565f4
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.ts
index 753c4cd58c..0df2266c9a 100644
--- a/backend/src/ee/routes/v1/license-v2-router.ts
+++ b/backend/src/ee/routes/v1/license-v2-router.ts
@@ -788,13 +788,13 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {
schema: {
operationId: "confirmBillingTrialPayment",
description:
- "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.",
+ "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. Returns 'upgraded' with no redirect when the charge went through without needing approval.",
params: z.object({ organizationId: z.string().trim().uuid() }),
body: z.object({ returnPath: ReturnPathSchema }),
response: {
200: z.object({
- outcome: z.enum(["checkout_created", "payment_action_required"]),
- redirectUrl: z.string()
+ outcome: z.enum(["checkout_created", "payment_action_required", "upgraded"]),
+ redirectUrl: z.string().optional()
})
}
},
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 a860a9927a..d46646c27c 100644
--- a/backend/src/ee/services/license-v2/license-v2-service.ts
+++ b/backend/src/ee/services/license-v2/license-v2-service.ts
@@ -1463,6 +1463,10 @@ export const licenseV2ServiceFactory = ({
const { paymentUrl } = await paymentActionRequired(orgId, result.paymentUrl);
return { outcome: result.outcome, redirectUrl: paymentUrl };
}
+ if (result.outcome === "upgraded") {
+ await licenseClient.markEntitlementsStale(orgId);
+ return { outcome: result.outcome };
+ }
await licenseClient.markEntitlementsStale(orgId, { checkout: true });
return { outcome: result.outcome, redirectUrl: result.checkoutUrl };
};
diff --git a/backend/src/services/license-client/license-client-backends.test.ts b/backend/src/services/license-client/license-client-backends.test.ts
index 970347c29e..592ffcd5f4 100644
--- a/backend/src/services/license-client/license-client-backends.test.ts
+++ b/backend/src/services/license-client/license-client-backends.test.ts
@@ -119,6 +119,16 @@ describe("licenseServerBackend confirmTrialPayment", () => {
})
).rejects.toThrow();
});
+
+ test("accepts an upgrade trial that converted without needing approval", async () => {
+ vi.stubGlobal("fetch", mockFetchReturning({ outcome: "upgraded" }));
+
+ const result = await licenseServerBackend(SERVER_URL, "key").confirmTrialPayment(ORG_ID, {
+ returnUrl: "https://app.infisical.com/organizations/org-1/billing"
+ });
+
+ expect(result.outcome).toBe("upgraded");
+ });
});
describe("licenseServerBackend payment_action_required", () => {
diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.ts
index d124def7ed..d5b7f25baf 100644
--- a/backend/src/services/license-client/license-client-types.ts
+++ b/backend/src/services/license-client/license-client-types.ts
@@ -494,7 +494,8 @@ const httpUrlSchema = z
// no_trial_awaiting_payment when nothing is waiting.
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()
+ z.object({ outcome: z.literal("payment_action_required"), paymentUrl: httpUrlSchema }).passthrough(),
+ z.object({ outcome: z.literal("upgraded") }).passthrough()
]);
export type TConfirmTrialPaymentResult = z.infer<typeof confirmTrialPaymentResultSchema>;
export { confirmTrialPaymentResultSchema };
diff --git a/frontend/src/hooks/api/billingV2/mutations.tsx b/frontend/src/hooks/api/billingV2/mutations.tsx
index c00ad71cc8..51c36295c2 100644
--- a/frontend/src/hooks/api/billingV2/mutations.tsx
+++ b/frontend/src/hooks/api/billingV2/mutations.tsx
@@ -203,6 +203,11 @@ export const useConfirmBillingV2TrialPayment = () => {
return data;
},
+ onSuccess: (data, { orgId }) => {
+ if (data.outcome === "upgraded") {
+ invalidateBillingV2(queryClient, orgId);
+ }
+ },
onError: (error, { orgId }) => {
if (
axios.isAxiosError<{ details?: { code?: string } }>(error) &&
diff --git a/frontend/src/hooks/api/billingV2/types.ts b/frontend/src/hooks/api/billingV2/types.ts
index e8c890fe07..60818772d2 100644
--- a/frontend/src/hooks/api/billingV2/types.ts
+++ b/frontend/src/hooks/api/billingV2/types.ts
@@ -372,10 +372,9 @@ export type TConfirmBillingV2TrialPaymentDTO = {
returnPath?: string;
};
-export type BillingV2ConfirmTrialPaymentResult = {
- outcome: "checkout_created" | "payment_action_required";
- redirectUrl: string;
-};
+export type BillingV2ConfirmTrialPaymentResult =
+ | { outcome: "checkout_created" | "payment_action_required"; redirectUrl: string }
+ | { outcome: "upgraded" };
// License-server machine codes the billing UI branches on (read from the error's details.code).
export const BillingV2ErrorCode = {
diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
index 3247b8f31f..022e08a8d4 100644
--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
@@ -195,12 +195,19 @@ export const BillingV2Page = () => {
returnPath: window.location.pathname
},
{
- onSuccess: ({ outcome, redirectUrl }) => {
- if (outcome === "payment_action_required") {
- setTrialApproval({ orgId: orgIdAtRequest, url: redirectUrl });
+ onSuccess: (result) => {
+ if (result.outcome === "upgraded") {
+ createNotification({
+ type: "success",
+ text: "Payment confirmed. It may take a moment for your plan to update here."
+ });
return;
}
- window.location.href = redirectUrl;
+ if (result.outcome === "payment_action_required") {
+ setTrialApproval({ orgId: orgIdAtRequest, url: result.redirectUrl });
+ return;
+ }
+ window.location.href = result.redirectUrl;
}
}
);