:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(billing): align startup desktop limit cap (#88223)
Pawel Cebula3bc1955ee9c3
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 321fe940941a..356cfd797464 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -8197,9 +8197,9 @@ snapshots:scenes-other-billing-product--billing-product-post-hog-code-limit-editing--light:hash: v1.k794b7964.a3bbef49716d1ea6fa9b92b79005af056f34f2040c224961d804f85596acc784.JGw5-GTbeq_p8KyjdiTeoX1jkN190GqFI9xV9JzgdmEscenes-other-billing-product--billing-product-post-hog-code-limit-next-period-capped--dark:- hash: v1.k794b7964.9fde77b3e5aa2b9c585fd6b0ffcfd7310ee410804924ea2fdc7fa12e25dfa77d.CDr-pD-AT0ystYMo2yHqfqGU7fJKGdViAcVlhKE6JtI+ hash: v1.k794b7964.f8583bd447708da6fa012fe9313d71600433bed0d03e5d41848cedecf5ab9d21.ZAHv0DJs7KHJ2Zdcp2-liP6z5Ubb22aqd1F91FZSXowscenes-other-billing-product--billing-product-post-hog-code-limit-next-period-capped--light:- hash: v1.k794b7964.bdca13fc394cc1a4dafa1046b520bca6d8ee0fd4592c7461d34269d349065a25.opatfCwjLk4ajx1oBTypxiFqZTLgLzC6Huv1Pe3feEA+ hash: v1.k794b7964.c6c64e9653af75c621864353c2cdb6596fc3c016b0ffbecfac348ea78d567826.BbDTCv01DzFXPbewlxtb5wsW5YECFnZ2E4KgCgniHBUscenes-other-billing-product--billing-product-temporarily-free--dark:hash: v1.k794b7964.17457ea2e809235689317d9e0feb224c18f8d5a81c8adf04b314e4d0c7b6f7d4.l_BpJhV7_FHvsDrKy34afdUPZvjK2sjH2OizL4u6SnIscenes-other-billing-product--billing-product-temporarily-free--light:diff --git a/frontend/src/scenes/billing/BillingProduct.stories.tsx b/frontend/src/scenes/billing/BillingProduct.stories.tsxindex d21e63d39d92..b3db087a0fe5 100644--- a/frontend/src/scenes/billing/BillingProduct.stories.tsx+++ b/frontend/src/scenes/billing/BillingProduct.stories.tsx@@ -8,7 +8,7 @@ import { makeBillingWithPlatformAddons } from '~/mocks/fixtures/_billing_platforimport preflightJson from '~/mocks/fixtures/_preflight.json'import { BillingProductV2Type, BillingType, StartupProgramLabel } from '~/types'-import { POSTHOG_CODE_USAGE_PRODUCT_KEY, STARTUP_PROGRAM_BILLING_LIMIT_MAX } from './billingLimitConfig'+import { POSTHOG_CODE_USAGE_PRODUCT_KEY, STARTUP_PROGRAM_BILLING_LIMIT_MAX_BY_PRODUCT } from './billingLimitConfig'import { BillingProduct } from './BillingProduct'const meta: Meta = {@@ -34,6 +34,9 @@ export default metatype Story = StoryObj<{}>+const POSTHOG_CODE_USAGE_STARTUP_PROGRAM_BILLING_LIMIT_MAX =+ STARTUP_PROGRAM_BILLING_LIMIT_MAX_BY_PRODUCT[POSTHOG_CODE_USAGE_PRODUCT_KEY]+const BillingProductStoryFrame = ({ children }: { children: JSX.Element }): JSX.Element => (<div className="w-[960px] max-w-full">{children}</div>)@@ -48,6 +51,9 @@ const makePostHogCodeUsageBilling = ({const sourceProduct = billingJson.products.find((product) => product.type === 'feature_flags') as BillingProductV2Type+ const isAboveStartupCap = currentLimitUsd > POSTHOG_CODE_USAGE_STARTUP_PROGRAM_BILLING_LIMIT_MAX+ const currentAmountUsd = isAboveStartupCap ? currentLimitUsd : 25+ const projectedAmountUsd = isAboveStartupCap ? currentLimitUsd + 150 : 75const product: BillingProductV2Type = {...sourceProduct,name: 'PostHog Desktop (usage-based)',@@ -58,9 +64,9 @@ const makePostHogCodeUsageBilling = ({docs_url: 'https://posthog.com/docs/posthog-desktop',subscribed: true,type: POSTHOG_CODE_USAGE_PRODUCT_KEY,- current_amount_usd: currentLimitUsd > STARTUP_PROGRAM_BILLING_LIMIT_MAX ? '3750.00' : '25.00',- projected_amount_usd: currentLimitUsd > STARTUP_PROGRAM_BILLING_LIMIT_MAX ? '4100.00' : '75.00',- projected_amount_usd_with_limit: currentLimitUsd > STARTUP_PROGRAM_BILLING_LIMIT_MAX ? '3750.00' : '75.00',+ current_amount_usd: currentAmountUsd.toFixed(2),+ projected_amount_usd: projectedAmountUsd.toFixed(2),+ projected_amount_usd_with_limit: isAboveStartupCap ? currentAmountUsd.toFixed(2) : '75.00',plans: sourceProduct.plans.map((plan) => ({...plan,initial_billing_limit: 50,@@ -174,8 +180,8 @@ export const BillingProductPostHogCodeLimitEditing: Story = {export const BillingProductPostHogCodeLimitNextPeriodCapped: Story = {render: () =>renderPostHogCodeUsageBillingProduct({- currentLimitUsd: 3750,- nextPeriodLimitUsd: 3000,+ currentLimitUsd: 750,+ nextPeriodLimitUsd: POSTHOG_CODE_USAGE_STARTUP_PROGRAM_BILLING_LIMIT_MAX,}),}diff --git a/frontend/src/scenes/billing/billingLimitConfig.test.ts b/frontend/src/scenes/billing/billingLimitConfig.test.tsindex 7dafff5c11d4..e5a6cfca1ba3 100644--- a/frontend/src/scenes/billing/billingLimitConfig.test.ts+++ b/frontend/src/scenes/billing/billingLimitConfig.test.ts@@ -6,7 +6,6 @@ import {MAX_BILLING_LIMIT,POSTHOG_CODE_USAGE_PRODUCT_KEY,REPLAY_VISION_PRODUCT_KEY,- STARTUP_PROGRAM_BILLING_LIMIT_MAX,} from './billingLimitConfig'describe('getBillingLimitConfig', () => {@@ -23,14 +22,16 @@ describe('getBillingLimitConfig', () => {})it.each([- [POSTHOG_CODE_USAGE_PRODUCT_KEY, 'Desktop'],- [REPLAY_VISION_PRODUCT_KEY, 'Replay vision'],- ])('caps %s for startup program customers and explains why', (productType, productName) => {+ [POSTHOG_CODE_USAGE_PRODUCT_KEY, 'Desktop', 500],+ [REPLAY_VISION_PRODUCT_KEY, 'Replay vision', 3000],+ ])('caps %s for startup program customers and explains why', (productType, productName, cap) => {const config = getConfig(productType, StartupProgramLabel.YC)- expect(config.max).toBe(STARTUP_PROGRAM_BILLING_LIMIT_MAX)+ expect(config.max).toBe(cap)expect(config.removalDisabledReason).toBeTruthy()expect(config.help).toContain(`${productName} billing limits`)+ expect(config.help).toContain(`$${cap.toLocaleString()}`)expect(config.maxExceededError).toContain(`${productName} billing limits`)+ expect(config.maxExceededError).toContain(`$${cap.toLocaleString()}`)})it.each(['posthog_code_usage', 'replay_vision', 'product_analytics'])(@@ -44,18 +45,21 @@ describe('getBillingLimitConfig', () => {)it.each([- [3750, 2000, true],- [3750, 5000, false],- [null, 2000, false],+ [POSTHOG_CODE_USAGE_PRODUCT_KEY, 750, 500, 'The $500 limit starts next period.'],+ [POSTHOG_CODE_USAGE_PRODUCT_KEY, 750, null, 'future edits must be $500 or less.'],+ [POSTHOG_CODE_USAGE_PRODUCT_KEY, 750, 600, 'future edits must be $500 or less.'],+ [REPLAY_VISION_PRODUCT_KEY, 3750, 2000, 'The $2,000 limit starts next period.'],+ [REPLAY_VISION_PRODUCT_KEY, 3750, 5000, 'future edits must be $3,000 or less.'],+ [REPLAY_VISION_PRODUCT_KEY, null, 2000, null],])(- 'with current limit %p and next period limit %p, above-cap notice shown: %p',- (customLimitUsd, billingLimitNextPeriod, noticeShown) => {- const config = getConfig('replay_vision', StartupProgramLabel.YC, {+ 'for %s with current limit %p and next period limit %p, above-cap notice includes %p',+ (productType, customLimitUsd, billingLimitNextPeriod, expectedNotice) => {+ const config = getConfig(productType, StartupProgramLabel.YC, {customLimitUsd,billingLimitNextPeriod,})- if (noticeShown) {- expect(config.currentAboveMaxNotice).toContain('next period')+ if (expectedNotice) {+ expect(config.currentAboveMaxNotice).toContain(expectedNotice)} else {expect(config.currentAboveMaxNotice).toBeNull()}diff --git a/frontend/src/scenes/billing/billingLimitConfig.ts b/frontend/src/scenes/billing/billingLimitConfig.tsindex ef8f1f380193..cddb2383e956 100644--- a/frontend/src/scenes/billing/billingLimitConfig.ts+++ b/frontend/src/scenes/billing/billingLimitConfig.ts@@ -4,7 +4,10 @@ export const MAX_BILLING_LIMIT: number = 50000export const POSTHOG_CODE_USAGE_PRODUCT_KEY = 'posthog_code_usage'export const REPLAY_VISION_PRODUCT_KEY = 'replay_vision'-export const STARTUP_PROGRAM_BILLING_LIMIT_MAX: number = 3000+export const STARTUP_PROGRAM_BILLING_LIMIT_MAX_BY_PRODUCT = {+ [POSTHOG_CODE_USAGE_PRODUCT_KEY]: 500,+ [REPLAY_VISION_PRODUCT_KEY]: 3000,+} as const satisfies Record<string, number>export type BillingLimitConfig = {max: number@@ -31,35 +34,56 @@ const DEFAULT_BILLING_LIMIT_CONFIG: BillingLimitConfig = {type BillingLimitConfigResolver = (context: BillingLimitConfigContext) => Partial<BillingLimitConfig> | null+const currentAboveStartupCapNotice = (+ productName: string,+ cap: number,+ customLimitUsd: number | null,+ billingLimitNextPeriod: number | null+): string | null => {+ if (customLimitUsd === null || customLimitUsd <= cap) {+ return null+ }++ if (billingLimitNextPeriod !== null && billingLimitNextPeriod <= cap) {+ return `This period's ${productName} billing limit is above the startup program cap, so it stays at $${customLimitUsd.toLocaleString()}. The $${billingLimitNextPeriod.toLocaleString()} limit starts next period.`+ }++ return `This period's ${productName} billing limit is above the startup program cap, so future edits must be $${cap.toLocaleString()} or less.`+}+// Mirrors the caps the billing service enforces for startup-program customers, so the form// rejects out-of-range limits before the API does. The billing API product names are too// verbose for copy (e.g. "PostHog Desktop (usage-based)").-const startupProgramCapResolver = (productName: string): BillingLimitConfigResolver => {+const startupProgramCapResolver = (productName: string, cap: number): BillingLimitConfigResolver => {return ({ billing, customLimitUsd, billingLimitNextPeriod }) => {if (!billing?.startup_program_label) {return null}- const cap = STARTUP_PROGRAM_BILLING_LIMIT_MAXreturn {max: cap,help: `While your organization is in the startup program, ${productName} billing limits can be set from $0 to $${cap.toLocaleString()} per month.`,removalDisabledReason: `While your organization is in the startup program, ${productName} billing limits can't be removed. Set the limit to $0 instead.`,maxExceededError: `While your organization is in the startup program, ${productName} billing limits can't exceed $${cap.toLocaleString()} per month.`,- currentAboveMaxNotice:- customLimitUsd !== null &&- customLimitUsd > cap &&- billingLimitNextPeriod !== null &&- billingLimitNextPeriod <= cap- ? `Current usage is already above the startup program cap, so this period's limit stays at $${customLimitUsd.toLocaleString()}. The $${billingLimitNextPeriod.toLocaleString()} limit starts next period.`- : null,+ currentAboveMaxNotice: currentAboveStartupCapNotice(+ productName,+ cap,+ customLimitUsd,+ billingLimitNextPeriod+ ),}}}const BILLING_LIMIT_CONFIG_BY_PRODUCT: Record<string, BillingLimitConfigResolver> = {- [POSTHOG_CODE_USAGE_PRODUCT_KEY]: startupProgramCapResolver('Desktop'),- [REPLAY_VISION_PRODUCT_KEY]: startupProgramCapResolver('Replay vision'),+ [POSTHOG_CODE_USAGE_PRODUCT_KEY]: startupProgramCapResolver(+ 'Desktop',+ STARTUP_PROGRAM_BILLING_LIMIT_MAX_BY_PRODUCT[POSTHOG_CODE_USAGE_PRODUCT_KEY]+ ),+ [REPLAY_VISION_PRODUCT_KEY]: startupProgramCapResolver(+ 'Replay vision',+ STARTUP_PROGRAM_BILLING_LIMIT_MAX_BY_PRODUCT[REPLAY_VISION_PRODUCT_KEY]+ ),}export const getBillingLimitConfig = (context: BillingLimitConfigContext): BillingLimitConfig => {diff --git a/products/replay_vision/frontend/utils/startupCap.ts b/products/replay_vision/frontend/utils/startupCap.tsindex 95f5c9d3c75c..94aec7092159 100644--- a/products/replay_vision/frontend/utils/startupCap.ts+++ b/products/replay_vision/frontend/utils/startupCap.ts@@ -1,10 +1,15 @@-import { STARTUP_PROGRAM_BILLING_LIMIT_MAX } from 'scenes/billing/billingLimitConfig'+import {+ REPLAY_VISION_PRODUCT_KEY,+ STARTUP_PROGRAM_BILLING_LIMIT_MAX_BY_PRODUCT,+} from 'scenes/billing/billingLimitConfig'import type { BillingType } from '~/types'import type { VisionQuotaApi } from '../generated/api.schemas'import { CREDITS_PER_DOLLAR } from './credits'+const STARTUP_PROGRAM_BILLING_LIMIT_MAX = STARTUP_PROGRAM_BILLING_LIMIT_MAX_BY_PRODUCT[REPLAY_VISION_PRODUCT_KEY]+/** Billing enforces this same ceiling server-side, in dollars. */export const STARTUP_CAP_CREDITS: number = STARTUP_PROGRAM_BILLING_LIMIT_MAX * CREDITS_PER_DOLLAR