Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(billing): read the CHB checkout URL from checkoutUrl (#16800)

Steffen Schmitzf6e56cbb6c6c
diff --git a/web/src/__tests__/server/chbCheckoutClaim.servertest.ts b/web/src/__tests__/server/chbCheckoutClaim.servertest.ts
index 5ef0445d71..481e88060a 100644
--- a/web/src/__tests__/server/chbCheckoutClaim.servertest.ts
+++ b/web/src/__tests__/server/chbCheckoutClaim.servertest.ts
@@ -84,7 +84,7 @@ describe("chbBillingService checkout claim (postgres)", () => {
data: { id: orgId, name: "CHB Claim Test Org" },
});
vi.mocked(clientMock.createCheckoutSession).mockResolvedValue({
- url: "https://billing.clickhouse.test/checkout/abc",
+ checkoutUrl: "https://billing.clickhouse.test/checkout/abc",
organizationId: chOrganizationId,
} satisfies ChbCheckoutSession);
});
@@ -178,7 +178,7 @@ describe("chbBillingService checkout claim (postgres)", () => {
// CHB hands back a different org for a request that asked to reuse one:
// sticky routing is broken, so checkout must refuse rather than clobber.
vi.mocked(clientMock.createCheckoutSession).mockResolvedValue({
- url: "https://billing.clickhouse.test/checkout/def",
+ checkoutUrl: "https://billing.clickhouse.test/checkout/def",
organizationId: randomUUID(),
} satisfies ChbCheckoutSession);
diff --git a/web/src/__tests__/server/unit/chbApiClient.servertest.ts b/web/src/__tests__/server/unit/chbApiClient.servertest.ts
index fa98006040..a48104512a 100644
--- a/web/src/__tests__/server/unit/chbApiClient.servertest.ts
+++ b/web/src/__tests__/server/unit/chbApiClient.servertest.ts
@@ -218,7 +218,7 @@ describe("chbApiClient", () => {
onChb(
jsonResponse(200, {
- url: "https://pay.example.com/c/1",
+ checkoutUrl: "https://pay.example.com/c/1",
organizationId: CH_ORG_ID,
}),
);
@@ -371,6 +371,26 @@ describe("chbApiClient", () => {
expect(bundle.scheduled).toBeUndefined();
});
+ it("reads the checkout URL from CHB's checkoutUrl field", async () => {
+ onChb(
+ jsonResponse(200, {
+ organizationId: CH_ORG_ID,
+ checkoutUrl: "https://pay.example.com/c/1",
+ }),
+ );
+
+ await expect(
+ client().createCheckoutSession({
+ email: "[email protected]",
+ planCode: "LANGFUSE_PRO",
+ returnUrl: "https://cloud.langfuse.com/back",
+ }),
+ ).resolves.toEqual({
+ organizationId: CH_ORG_ID,
+ checkoutUrl: "https://pay.example.com/c/1",
+ });
+ });
+
it("defaults the invoice list to empty when CHB omits the key", async () => {
onChb(jsonResponse(200, {}));
@@ -387,7 +407,7 @@ describe("chbApiClient", () => {
// uuid — rejecting here keeps a bad id from ever reaching the database.
onChb(
jsonResponse(200, {
- url: "https://pay.example.com/c/1",
+ checkoutUrl: "https://pay.example.com/c/1",
organizationId: "not-a-uuid",
}),
);
diff --git a/web/src/__tests__/server/unit/chbBillingService.servertest.ts b/web/src/__tests__/server/unit/chbBillingService.servertest.ts
index 570bbfa42f..5e9c793f8b 100644
--- a/web/src/__tests__/server/unit/chbBillingService.servertest.ts
+++ b/web/src/__tests__/server/unit/chbBillingService.servertest.ts
@@ -245,7 +245,7 @@ describe("chbBillingService", () => {
describe("createCheckoutSession", () => {
const session = {
- url: "https://pay.example.com/c/1",
+ checkoutUrl: "https://pay.example.com/c/1",
organizationId: CH_ORG_ID,
};
@@ -259,7 +259,7 @@ describe("chbBillingService", () => {
"op-checkout",
);
- expect(url).toBe(session.url);
+ expect(url).toBe(session.checkoutUrl);
expect(clientMock.createCheckoutSession).toHaveBeenCalledWith({
organizationId: undefined,
@@ -336,7 +336,7 @@ describe("chbBillingService", () => {
it("refuses when a retry comes back with a different CH organization", async () => {
withOrg({ clickhouse: { organizationId: CH_ORG_ID } });
clientMock.createCheckoutSession.mockResolvedValue({
- url: session.url,
+ checkoutUrl: session.checkoutUrl,
organizationId: "11111111-2222-4333-8444-555555555555",
});
@@ -356,7 +356,7 @@ describe("chbBillingService", () => {
it("refuses to persist an id the stored schema rejects", async () => {
withOrg(null);
clientMock.createCheckoutSession.mockResolvedValue({
- url: session.url,
+ checkoutUrl: session.checkoutUrl,
organizationId: "not-a-uuid",
});
diff --git a/web/src/ee/features/billing/server/chb/chbApiClient.ts b/web/src/ee/features/billing/server/chb/chbApiClient.ts
index d07c9fe1c3..d58b64fb7a 100644
--- a/web/src/ee/features/billing/server/chb/chbApiClient.ts
+++ b/web/src/ee/features/billing/server/chb/chbApiClient.ts
@@ -76,7 +76,7 @@ const ChbBundleSchema = z.object({
export type ChbBundle = z.infer<typeof ChbBundleSchema>;
const ChbCheckoutSessionSchema = z.object({
- url: z.string(),
+ checkoutUrl: z.url(),
// ClickHouse Organization ID — persisted on the Langfuse org right away so a
// checkout retry recovers the same CH org instead of orphaning one.
organizationId: z.uuid(),
diff --git a/web/src/ee/features/billing/server/chb/chbBillingService.ts b/web/src/ee/features/billing/server/chb/chbBillingService.ts
index 122e2eb4fd..76923a39ac 100644
--- a/web/src/ee/features/billing/server/chb/chbBillingService.ts
+++ b/web/src/ee/features/billing/server/chb/chbBillingService.ts
@@ -353,7 +353,7 @@ export class ChbBillingService {
"ClickHouse Billing returned a different organization for this checkout",
});
}
- return session.url;
+ return session.checkoutUrl;
}
// First checkout for this org: the CH organization id is the one thing
@@ -414,7 +414,7 @@ export class ChbBillingService {
);
});
- return session.url;
+ return session.checkoutUrl;
}
async changePlan(orgId: string, newProductId: string, opId?: string) {