Skip to content

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

feat(billing): send the organization name on ClickHouse Billing checkout (#17867)

Steffen Reuther9450b93368f4
diff --git a/web/src/__tests__/server/unit/chbApiClient.servertest.ts b/web/src/__tests__/server/unit/chbApiClient.servertest.ts
index fc3f555856..f7b2b7a204 100644
--- a/web/src/__tests__/server/unit/chbApiClient.servertest.ts
+++ b/web/src/__tests__/server/unit/chbApiClient.servertest.ts
@@ -237,6 +237,37 @@ describe("chbApiClient", () => {
expect(generated).toMatch(/^[0-9a-f-]{36}$/);
});
+ it("sends the organization name as CHB's checkout name field", async () => {
+ const session = {
+ checkoutUrl: "https://pay.example.com/c/1",
+ organizationId: CH_ORG_ID,
+ };
+ const checkout = (name?: string) =>
+ client().createCheckoutSession({
+ name,
+ email: "[email protected]",
+ planCode: "LANGFUSE_PRO",
+ returnUrl: "https://cloud.langfuse.com/back",
+ });
+
+ onChb(jsonResponse(200, session));
+ await checkout("Acme Inc");
+ expect(JSON.parse(lastChbCall().init.body as string).name).toBe(
+ "Acme Inc",
+ );
+
+ // CHB rejects a blank name with a 400 but falls back to its own default
+ // when the field is absent. Langfuse's org-name schema does not trim, so
+ // a whitespace-only name must be omitted rather than block checkout.
+ for (const name of [undefined, "", " "]) {
+ onChb(jsonResponse(200, session));
+ await checkout(name);
+ expect(
+ JSON.parse(lastChbCall().init.body as string),
+ ).not.toHaveProperty("name");
+ }
+ });
+
it("scopes org endpoints with CH-Organization-Id and omits it elsewhere", async () => {
onChb(jsonResponse(200, { id: "plan_1" }));
await client().getAttachedPlan({ chOrganizationId: CH_ORG_ID });
diff --git a/web/src/__tests__/server/unit/chbBillingService.servertest.ts b/web/src/__tests__/server/unit/chbBillingService.servertest.ts
index d879ad4d3f..8a10fa2e0e 100644
--- a/web/src/__tests__/server/unit/chbBillingService.servertest.ts
+++ b/web/src/__tests__/server/unit/chbBillingService.servertest.ts
@@ -263,6 +263,7 @@ describe("chbBillingService", () => {
expect(url).toBe(session.checkoutUrl);
expect(clientMock.createCheckoutSession).toHaveBeenCalledWith({
organizationId: undefined,
+ name: "Org",
planCode: "LANGFUSE_PRO",
returnUrl: `https://cloud.langfuse.com/organization/${ORG_ID}/settings/billing`,
diff --git a/web/src/ee/features/billing/server/chb/chbApiClient.ts b/web/src/ee/features/billing/server/chb/chbApiClient.ts
index 047f569fbf..5ec03f6e40 100644
--- a/web/src/ee/features/billing/server/chb/chbApiClient.ts
+++ b/web/src/ee/features/billing/server/chb/chbApiClient.ts
@@ -289,11 +289,16 @@ export class ChbApiClient {
async createCheckoutSession(params: {
organizationId?: string;
+ /** Names the CH organization when checkout creates it. */
+ name?: string;
email: string;
planCode: string;
returnUrl: string;
idempotencyKey?: string;
}): Promise<ChbCheckoutSession> {
+ // CHB rejects a blank name (400) but defaults one when the field is
+ // absent, so a whitespace-only name is dropped rather than sent.
+ const name = params.name?.trim();
const body = await this.request({
operation: "chb.checkout_session.create",
method: "POST",
@@ -302,6 +307,7 @@ export class ChbApiClient {
...(params.organizationId
? { organizationId: params.organizationId }
: {}),
+ ...(name ? { name } : {}),
email: params.email,
planCode: params.planCode,
returnUrl: params.returnUrl,
diff --git a/web/src/ee/features/billing/server/chb/chbBillingService.ts b/web/src/ee/features/billing/server/chb/chbBillingService.ts
index ca537821f7..cc57064000 100644
--- a/web/src/ee/features/billing/server/chb/chbBillingService.ts
+++ b/web/src/ee/features/billing/server/chb/chbBillingService.ts
@@ -289,6 +289,9 @@ export class ChbBillingService {
// Reuse the CH organization from an earlier checkout attempt so a retry
// recovers the same org instead of orphaning one
organizationId: existingChOrgId,
+ // Names the CH organization when this call creates it, instead of the
+ // default CHB derives from the email; a reused one keeps its name
+ name: parsedOrg.name,
email,
planCode,
returnUrl: this.returnUrl(orgId),