Skip to content

: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.

chore(frontend): move billingLogic into the shell layer (#126845)

Paul D'Ambra8c076e05bb86
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index 08e9f9f22811..6bc2016b85ea 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -91,10 +91,10 @@ const ROOTS = [
// file that builds a schema. Move the zod-free code of that file into its own module, as
// sqlEditorDraftCleanup does for sqlEditorDraftStorage.
'node_modules/zod/',
- // Billing is for logged-in users, and billingLogic pulls in eventUsageLogic and the credit
- // purchase UI. A hit means a module on the App path imports billingLogic. Read billing values
- // from a logic or component that only logged-in pages load.
- 'src/scenes/billing/billingLogic.tsx',
+ // Billing is for logged-in users, and billingLogic pulls in eventUsageLogic. A hit means a
+ // module on the App path imports billingLogic. Read billing values from a logic or component
+ // that only logged-in pages load.
+ 'src/lib/logic/billing/billingLogic.tsx',
// Product setup statuses need a logged-in team, so AuthenticatedShell mounts the preload.
'src/lib/components/ProductEmptyState/productSetupPreloadLogic.ts',
],
diff --git a/frontend/bin/layer-baseline.txt b/frontend/bin/layer-baseline.txt
index d9f16b6015ab..de8ec7feb74d 100644
--- a/frontend/bin/layer-baseline.txt
+++ b/frontend/bin/layer-baseline.txt
@@ -19,13 +19,11 @@ frontend/src/layout/InternalFeedback/internalFeedbackLogic.ts -> frontend/src/to
frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivitySubscribeMenu.tsx -> frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts
frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx -> products/notifications/frontend/resourceEditedLogic.ts
frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsx -> frontend/src/scenes/max/maxLogic.tsx
-frontend/src/layout/navigation-3000/sidepanel/panels/support/SidePanelSupport.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/layout/navigation-3000/sidepanel/panels/support/SidePanelSupport.tsx -> products/conversations/frontend/components/SidePanel/SidePanelTickets.tsx
frontend/src/layout/navigation-3000/sidepanel/panels/support/SidePanelSupport.tsx -> products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts
frontend/src/layout/navigation-3000/sidepanel/sidePanelTabs.tsx -> products/conversations/frontend/components/SidePanel/SidePanelSupportIcon.tsx
frontend/src/layout/navigation/projectNoticeLogic.tsx -> frontend/src/scenes/activity/live/liveEventsLogic.tsx
frontend/src/layout/navigation/projectNoticeLogic.tsx -> frontend/src/scenes/authentication/verify-email/verifyEmailLogic.ts
-frontend/src/layout/navigation/projectNoticeLogic.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/layout/navigation/projectNoticeLogic.tsx -> frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts
frontend/src/layout/navigation/projectNoticeLogic.tsx -> frontend/src/scenes/welcome/productBranding.ts
frontend/src/layout/panel-layout/DatabaseTree/DatabaseTree.tsx -> frontend/src/scenes/data-warehouse/editor/ConnectionSelector.tsx
@@ -76,10 +74,8 @@ frontend/src/layout/today/TodaySessionRow.tsx -> products/posthog_ai/frontend/ap
frontend/src/layout/today/TodaySettingsSidebar.tsx -> frontend/src/scenes/settings/settingsLogic.ts
frontend/src/layout/today/TodaySettingsSidebar.tsx -> frontend/src/scenes/settings/settingsNavTree.ts
frontend/src/layout/today/TodaySettingsSidebar.tsx -> frontend/src/scenes/settings/types.ts
-frontend/src/layout/today/TodaySupportPanel.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/layout/today/TodaySupportPanel.tsx -> products/conversations/frontend/components/QuillSidePanel/QuillSupportTickets.tsx
frontend/src/layout/today/TodaySupportPanel.tsx -> products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts
-frontend/src/layout/today/TodaySupportResponseTimes.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/layout/today/todayAiChatLogic.ts -> frontend/src/scenes/max/mainFocusUrl.ts
frontend/src/layout/today/todayAiChatLogic.ts -> frontend/src/scenes/max/maxLogic.tsx
frontend/src/layout/today/todayAnalyticsLogic.ts -> frontend/src/scenes/analytics/analyticsPinnedLogic.ts
@@ -93,12 +89,10 @@ frontend/src/layout/today/todayObjectGlances.ts -> frontend/src/scenes/library/l
frontend/src/layout/today/todayObjectGlances.ts -> frontend/src/scenes/project-homepage/today/todayNumbers.ts
frontend/src/layout/today/todayObjectGlances.ts -> products/experiments/frontend/experimentStatus.ts
frontend/src/layout/today/todayObjectGlances.ts -> products/feature_flags/frontend/featureFlagConfigFormat.ts
-frontend/src/layout/today/todayOrgMenuLogic.ts -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/layout/today/todayPaneSearch.ts -> frontend/src/scenes/analytics/analyticsUtils.ts
frontend/src/layout/today/todayPanelTaskLogic.ts -> products/posthog_ai/frontend/api/logics.ts
frontend/src/layout/today/todayPreviewCards.ts -> frontend/src/scenes/library/libraryUtils.ts
frontend/src/layout/today/todayPreviewCards.ts -> products/posthog_ai/frontend/api/taskSource.ts
-frontend/src/layout/today/todayRailStatusLogic.ts -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/layout/today/todayShellLogic.ts -> frontend/src/scenes/analytics/analyticsUtils.ts
frontend/src/layout/today/todayShellLogic.ts -> frontend/src/scenes/library/libraryUtils.ts
frontend/src/layout/today/todayShellLogic.ts -> frontend/src/scenes/settings/settingsSectionScenes.ts
@@ -112,8 +106,6 @@ frontend/src/lib/api.ts -> frontend/src/lib/apiRequestTiming.ts
frontend/src/lib/api.ts -> frontend/src/lib/logic/apiStatusLogic.ts
frontend/src/lib/api.ts -> frontend/src/queries/utils.ts
frontend/src/lib/api.ts -> frontend/src/scenes/surveys/constants.tsx
-frontend/src/lib/components/Account/AccountMenu.tsx -> frontend/src/scenes/billing/billingLogic.tsx
-frontend/src/lib/components/Account/NewAccountMenu.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/lib/components/Account/ProjectFreshnessIndicator.tsx -> frontend/src/scenes/onboarding/shared/utils.tsx
frontend/src/lib/components/ActivityLog/ActivityLogSubscribeMenu.tsx -> frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts
frontend/src/lib/components/ActivityLog/activityDescriptions/tagActivityDescriber.tsx -> frontend/src/scenes/insights/utils.tsx
@@ -132,7 +124,6 @@ frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.ts -> fro
frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.ts -> frontend/src/scenes/insights/insightVizDataLogic.ts
frontend/src/lib/components/AppMetrics/appMetricsLogic.ts -> frontend/src/queries/utils.ts
frontend/src/lib/components/AuthorizedUrlList/authorizedUrlListLogic.ts -> frontend/src/queries/utils.ts
-frontend/src/lib/components/BillingUpgradeCTA.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/lib/components/Cards/InsightCard/DashboardInsightDisplayOptions.tsx -> products/product_analytics/frontend/insights/editor/InsightDisplayOptionsPanel.tsx
frontend/src/lib/components/Cards/InsightCard/DashboardSqlDisplayOptions.tsx -> frontend/src/queries/nodes/DataVisualization/Components/DisplayTab.tsx
frontend/src/lib/components/Cards/InsightCard/DashboardSqlDisplayOptions.tsx -> frontend/src/queries/nodes/DataVisualization/Components/TableDisplay.tsx
@@ -223,7 +214,6 @@ frontend/src/lib/components/FlagCalledRebuildBanner/flagCalledRebuildBannerLogic
frontend/src/lib/components/HedgehogMode/HedgehogMode.tsx -> frontend/src/toolbar/shared/toolbarConfigLogic.ts
frontend/src/lib/components/HedgehogMode/hedgehogModeLogic.ts -> frontend/src/toolbar/shared/toolbarConfigLogic.ts
frontend/src/lib/components/HedgehogMode/hedgehogModeLogic.ts -> frontend/src/toolbar/shared/toolbarFetch.ts
-frontend/src/lib/components/HelpMenu/HelpMenu.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/lib/components/HighlightedJSONViewer.tsx -> products/ai_observability/frontend/ConversationDisplay/HighlightedContentWrapper.tsx
frontend/src/lib/components/HogQLDropdown/HogQLDropdown.tsx -> frontend/src/queries/utils.ts
frontend/src/lib/components/HogQLEditor/HogQLEditor.tsx -> frontend/src/queries/utils.ts
@@ -255,9 +245,7 @@ frontend/src/lib/components/NotFound/index.tsx -> frontend/src/scenes/activity/e
frontend/src/lib/components/NotFound/index.tsx -> frontend/src/scenes/notebooks/Nodes/NotebookNodeContext.ts
frontend/src/lib/components/PathCleanFilters/PathRegexModal.tsx -> frontend/src/scenes/session-recordings/components/AiRegexHelper/AiRegexHelper.tsx
frontend/src/lib/components/PayGateMini/PayGateButton.tsx -> frontend/src/scenes/billing/paymentEntryLogic.ts
-frontend/src/lib/components/PayGateMini/PayGateMini.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/lib/components/PayGateMini/PayGateMini.tsx -> frontend/src/scenes/onboarding/shared/utils.tsx
-frontend/src/lib/components/PayGateMini/payGateMiniLogic.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/lib/components/ProductEmptyState/ProductEmptyState.tsx -> frontend/src/scenes/onboarding/shared/useWizardCommand.ts
frontend/src/lib/components/PropertiesTable/PropertiesTable.tsx -> products/persons/frontend/components/NewProperty.tsx
frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx -> frontend/src/scenes/cohorts/CohortFilters/CohortCriteriaRowBuilder.tsx
@@ -287,7 +275,6 @@ frontend/src/lib/components/Scenes/SceneMenuBarAddToNotebook.tsx -> frontend/src
frontend/src/lib/components/Scenes/SceneMenuBarPinItem.tsx -> frontend/src/scenes/analytics/analyticsPinnedLogic.ts
frontend/src/lib/components/Scenes/SceneMenuBarPinItem.tsx -> frontend/src/scenes/analytics/analyticsUtils.ts
frontend/src/lib/components/Search/searchItems.tsx -> products/customer_analytics/frontend/components/Accounts/accountStatusTags.ts
-frontend/src/lib/components/Search/searchListsLogic.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/lib/components/Search/searchListsLogic.tsx -> frontend/src/scenes/settings/flagGating.ts
frontend/src/lib/components/Search/searchListsLogic.tsx -> frontend/src/scenes/settings/organization/organizationIntegrationsLogic.ts
frontend/src/lib/components/Search/searchListsLogic.tsx -> frontend/src/scenes/settings/settingsSearch.ts
@@ -307,7 +294,6 @@ frontend/src/lib/components/SmoothingFilter/SmoothingFilter.tsx -> frontend/src/
frontend/src/lib/components/SmoothingFilter/SmoothingFilter.tsx -> frontend/src/scenes/insights/insightVizDataLogic.ts
frontend/src/lib/components/SmoothingFilter/SmoothingFilter.tsx -> products/product_analytics/frontend/insights/trends/trendsDataLogic.ts
frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx -> frontend/src/scenes/authentication/shared/passkeyLogic.ts
-frontend/src/lib/components/Superpowers/buildFakeBillingAlert.ts -> frontend/src/scenes/billing/billing-utils.ts
frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx -> frontend/src/scenes/surveys/hooks/useSurveyResponseColumns.tsx
frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx -> frontend/src/scenes/surveys/surveyLogic.tsx
frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx -> frontend/src/scenes/surveys/utils.ts
@@ -333,7 +319,6 @@ frontend/src/lib/components/UnitPicker/UnitPicker.tsx -> frontend/src/scenes/ins
frontend/src/lib/components/UnitPicker/UnitPicker.tsx -> frontend/src/scenes/insights/insightLogic.tsx
frontend/src/lib/components/UnitPicker/UnitPicker.tsx -> frontend/src/scenes/insights/insightVizDataLogic.ts
frontend/src/lib/components/UniversalFilters/universalFiltersLogic.ts -> frontend/src/scenes/session-recordings/filters/sessionRecordingSavedFiltersLogic.ts
-frontend/src/lib/components/UpgradeModal/upgradeModalLogic.ts -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx -> frontend/src/scenes/session-recordings/player/modal/sessionPlayerModalLogic.ts
frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx -> frontend/src/scenes/session-recordings/playlist/UnwatchedIndicator.tsx
frontend/src/lib/components/heatmaps/heatmapDataLogic.ts -> frontend/src/toolbar/shared/toolbarConfigLogic.ts
@@ -556,7 +541,6 @@ frontend/src/queries/nodes/WebVitals/WebVitals.tsx -> frontend/src/scenes/web-an
frontend/src/queries/nodes/WebVitals/WebVitalsContent.tsx -> frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
frontend/src/queries/nodes/WebVitals/WebVitalsPathBreakdown.tsx -> frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
frontend/src/queries/query.ts -> frontend/src/exporter/exporterViewLogic.ts
-frontend/src/scenes/AuthenticatedShell.tsx -> frontend/src/scenes/billing/billingLogic.tsx
frontend/src/scenes/AuthenticatedShell.tsx -> frontend/src/scenes/onboarding/shared/wizard-sync/WizardHandoffDialog.tsx
frontend/src/scenes/AuthenticatedShell.tsx -> frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncDebugPanel.tsx
frontend/src/scenes/AuthenticatedShell.tsx -> products/webmcp/frontend/logics/webmcpLogic.ts
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/support/SidePanelSupport.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/support/SidePanelSupport.tsx
index 88ef3c205ca8..50acdeda4a88 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/panels/support/SidePanelSupport.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/support/SidePanelSupport.tsx
@@ -8,9 +8,9 @@ import { incidentStatusLogic } from 'lib/components/HelpMenu/incidentStatusLogic
import { DEFAULT_PAID_RESPONSE_TIME, getSupportPlanRows } from 'lib/components/Support/supportResponseTime'
import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/src/layout/navigation/projectNoticeLogic.test.tsx b/frontend/src/layout/navigation/projectNoticeLogic.test.tsx
index 70375b38dd68..f997a460d89b 100644
--- a/frontend/src/layout/navigation/projectNoticeLogic.test.tsx
+++ b/frontend/src/layout/navigation/projectNoticeLogic.test.tsx
@@ -11,10 +11,10 @@ import { reverseProxyCheckerLogic } from 'lib/components/ReverseProxyChecker/rev
import { FEATURE_FLAGS } from 'lib/constants'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { apiStatusLogic } from 'lib/logic/apiStatusLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { verifyEmailLogic } from 'scenes/authentication/verify-email/verifyEmailLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
diff --git a/frontend/src/layout/navigation/projectNoticeLogic.tsx b/frontend/src/layout/navigation/projectNoticeLogic.tsx
index 398001c3560c..19440a935e6e 100644
--- a/frontend/src/layout/navigation/projectNoticeLogic.tsx
+++ b/frontend/src/layout/navigation/projectNoticeLogic.tsx
@@ -13,6 +13,7 @@ import { LemonBannerProps } from 'lib/lemon-ui/LemonBanner/LemonBanner'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { Link } from 'lib/lemon-ui/Link'
import { apiStatusLogic } from 'lib/logic/apiStatusLogic'
+import { billingLogic, BillingAlertConfig } from 'lib/logic/billing/billingLogic'
import { eventIngestionRestrictionLogic } from 'lib/logic/eventIngestionRestrictionLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { inviteLogic } from 'lib/logic/inviteLogic'
@@ -20,7 +21,6 @@ import { preflightLogic } from 'lib/logic/preflightLogic'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { liveEventsLogic } from 'scenes/activity/live/liveEventsLogic'
import { verifyEmailLogic } from 'scenes/authentication/verify-email/verifyEmailLogic'
-import { billingLogic, BillingAlertConfig } from 'scenes/billing/billingLogic'
import { sampleDataStateLogic } from 'scenes/insights/EmptyStates/sampleDataStateLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { sceneLogic } from 'scenes/sceneLogic'
diff --git a/frontend/src/layout/today/TodaySupportPanel.tsx b/frontend/src/layout/today/TodaySupportPanel.tsx
index 333b9721db6d..f14299ac3231 100644
--- a/frontend/src/layout/today/TodaySupportPanel.tsx
+++ b/frontend/src/layout/today/TodaySupportPanel.tsx
@@ -5,9 +5,9 @@ import { Button, Heading, Skeleton, Text, cn } from '@posthog/quill'
import { FEATURE_FLAGS } from 'lib/constants'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { urls } from 'scenes/urls'
import { ProductKey } from '~/queries/schema/schema-general'
diff --git a/frontend/src/layout/today/TodaySupportResponseTimes.tsx b/frontend/src/layout/today/TodaySupportResponseTimes.tsx
index 1345ae5386f2..ed2563b66bc8 100644
--- a/frontend/src/layout/today/TodaySupportResponseTimes.tsx
+++ b/frontend/src/layout/today/TodaySupportResponseTimes.tsx
@@ -4,7 +4,7 @@ import { Table, TableBody, TableCell, TableRow, Text } from '@posthog/quill'
import { DEFAULT_PAID_RESPONSE_TIME, getSupportPlanRows } from 'lib/components/Support/supportResponseTime'
import { dayjs } from 'lib/dayjs'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { userLogic } from 'scenes/userLogic'
export function TodaySupportResponseTimes(): JSX.Element {
diff --git a/frontend/src/layout/today/todayOrgMenuLogic.ts b/frontend/src/layout/today/todayOrgMenuLogic.ts
index f630ac671648..b0115e056132 100644
--- a/frontend/src/layout/today/todayOrgMenuLogic.ts
+++ b/frontend/src/layout/today/todayOrgMenuLogic.ts
@@ -4,10 +4,10 @@ import { router } from 'kea-router'
import { matchesSwitcherSearch, newAccountMenuLogic } from 'lib/components/Account/newAccountMenuLogic'
import { pendingInvitesLogic } from 'lib/components/Account/pendingInvitesLogic'
import { upgradeModalLogic } from 'lib/components/UpgradeModal/upgradeModalLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { inviteLogic } from 'lib/logic/inviteLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/src/layout/today/todayRailSeverity.test.ts b/frontend/src/layout/today/todayRailSeverity.test.ts
index c1d8dde1e277..ede3bf181680 100644
--- a/frontend/src/layout/today/todayRailSeverity.test.ts
+++ b/frontend/src/layout/today/todayRailSeverity.test.ts
@@ -1,4 +1,4 @@
-import type { BillingAlertConfig } from 'scenes/billing/billingLogic'
+import type { BillingAlertConfig } from 'lib/logic/billing/billingLogic'
import { TodayRailSeverity, severityFromBillingAlert, worstSeverity } from './todayRailSeverity'
diff --git a/frontend/src/layout/today/todayRailSeverity.ts b/frontend/src/layout/today/todayRailSeverity.ts
index 5df2e0964dd8..0d8804a29c1d 100644
--- a/frontend/src/layout/today/todayRailSeverity.ts
+++ b/frontend/src/layout/today/todayRailSeverity.ts
@@ -1,4 +1,4 @@
-import type { BillingAlertConfig } from 'scenes/billing/billingLogic'
+import type { BillingAlertConfig } from 'lib/logic/billing/billingLogic'
/**
* How much a rail signal needs attention. `ok` is a healthy reading worth showing in green,
diff --git a/frontend/src/layout/today/todayRailStatusLogic.ts b/frontend/src/layout/today/todayRailStatusLogic.ts
index f266ac3e6d2b..41eac43846db 100644
--- a/frontend/src/layout/today/todayRailStatusLogic.ts
+++ b/frontend/src/layout/today/todayRailStatusLogic.ts
@@ -5,8 +5,8 @@ import { healthSummaryLabel } from 'lib/components/HelpMenu/healthSummaryLabel'
import { healthSummaryLogic } from 'lib/components/HelpMenu/healthSummaryLogic'
import { helpMenuLogic } from 'lib/components/HelpMenu/helpMenuLogic'
import { posthogStatusLogic } from 'lib/components/HelpMenu/posthogStatusLogic'
+import { BillingAlertConfig, billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { BillingAlertConfig, billingLogic } from 'scenes/billing/billingLogic'
import type { HelpBadgeStatus } from '../../lib/components/HelpMenu/helpMenuLogic'
import type { PostHogStatusBadgeStatus } from '../../lib/components/HelpMenu/posthogStatusLogic'
diff --git a/frontend/src/lib/components/Account/AccountMenu.tsx b/frontend/src/lib/components/Account/AccountMenu.tsx
index ffc469d3b209..9c001d6d645b 100644
--- a/frontend/src/lib/components/Account/AccountMenu.tsx
+++ b/frontend/src/lib/components/Account/AccountMenu.tsx
@@ -29,6 +29,7 @@ import { LemonTag } from 'lib/lemon-ui/LemonTag/LemonTag'
import { Link } from 'lib/lemon-ui/Link/Link'
import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture/ProfilePicture'
import { UploadedLogo } from 'lib/lemon-ui/UploadedLogo/UploadedLogo'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { inviteLogic } from 'lib/logic/inviteLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
@@ -49,7 +50,6 @@ import { Label } from 'lib/ui/Label/Label'
import { MenuOpenIndicator } from 'lib/ui/Menus/Menus'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/src/lib/components/Account/NewAccountMenu.tsx b/frontend/src/lib/components/Account/NewAccountMenu.tsx
index c86dd149c235..4c445e0e73c5 100644
--- a/frontend/src/lib/components/Account/NewAccountMenu.tsx
+++ b/frontend/src/lib/components/Account/NewAccountMenu.tsx
@@ -18,6 +18,7 @@ import { Link } from 'lib/lemon-ui/Link/Link'
import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture/ProfilePicture'
import { ScrollableShadows } from 'lib/lemon-ui/ScrollableShadows/ScrollableShadows'
import { UploadedLogo } from 'lib/lemon-ui/UploadedLogo/UploadedLogo'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { inviteLogic } from 'lib/logic/inviteLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
@@ -27,7 +28,6 @@ import { MenuOpenIndicator } from 'lib/ui/Menus/Menus'
import { useSubmenuSafeTriangle } from 'lib/ui/Menus/useSubmenuSafeTriangle'
import { cn } from 'lib/utils/css-classes'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { projectLogic } from 'scenes/projectLogic'
import { isAuthenticatedTeam, teamLogic } from 'scenes/teamLogic'
diff --git a/frontend/src/lib/components/BillingUpgradeCTA.tsx b/frontend/src/lib/components/BillingUpgradeCTA.tsx
index 6fd44691fd73..612084471972 100644
--- a/frontend/src/lib/components/BillingUpgradeCTA.tsx
+++ b/frontend/src/lib/components/BillingUpgradeCTA.tsx
@@ -2,8 +2,8 @@ import { useActions, useValues } from 'kea'
import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { LemonButton, LemonButtonProps } from 'lib/lemon-ui/LemonButton'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
export function BillingUpgradeCTA({ children, disabledReason, ...props }: LemonButtonProps): JSX.Element {
const { reportBillingCTAShown } = useActions(eventUsageLogic)
diff --git a/frontend/src/lib/components/HelpMenu/HelpMenu.tsx b/frontend/src/lib/components/HelpMenu/HelpMenu.tsx
index 6069a6ac7163..c5a16d5670cd 100644
--- a/frontend/src/lib/components/HelpMenu/HelpMenu.tsx
+++ b/frontend/src/lib/components/HelpMenu/HelpMenu.tsx
@@ -9,13 +9,13 @@ import { KeyboardShortcut } from 'lib/lemon-ui/KeyboardShortcut/KeyboardShortcut
import { LemonBadge } from 'lib/lemon-ui/LemonBadge/LemonBadge'
import { Link } from 'lib/lemon-ui/Link/Link'
import { ScrollableShadows } from 'lib/lemon-ui/ScrollableShadows/ScrollableShadows'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
import { Label } from 'lib/ui/Label/Label'
import { MenuOpenIndicator } from 'lib/ui/Menus/Menus'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/src/lib/components/PayGateMini/PayGateMini.tsx b/frontend/src/lib/components/PayGateMini/PayGateMini.tsx
index 34407e36b236..54c9b4de1708 100644
--- a/frontend/src/lib/components/PayGateMini/PayGateMini.tsx
+++ b/frontend/src/lib/components/PayGateMini/PayGateMini.tsx
@@ -6,8 +6,8 @@ import { useEffect } from 'react'
import { IconInfo, IconOpenSidebar, IconUnlock } from '@posthog/icons'
import { LemonButton, LemonSkeleton, Link, Tooltip } from '@posthog/lemon-ui'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { getProductIcon } from 'scenes/onboarding/shared/utils'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/src/lib/components/PayGateMini/payGateMiniLogic.test.ts b/frontend/src/lib/components/PayGateMini/payGateMiniLogic.test.ts
index bbe6e34fece7..d4a7cc445de2 100644
--- a/frontend/src/lib/components/PayGateMini/payGateMiniLogic.test.ts
+++ b/frontend/src/lib/components/PayGateMini/payGateMiniLogic.test.ts
@@ -1,8 +1,8 @@
/* oxlint-disable react-hooks/rules-of-hooks -- useMocks is a test helper, not a React hook */
import { expectLogic } from 'kea-test-utils'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { billingJson } from '~/mocks/fixtures/_billing'
import preflightJson from '~/mocks/fixtures/_preflight.json'
diff --git a/frontend/src/lib/components/PayGateMini/payGateMiniLogic.tsx b/frontend/src/lib/components/PayGateMini/payGateMiniLogic.tsx
index 4a42d1749532..13499cecd4a7 100644
--- a/frontend/src/lib/components/PayGateMini/payGateMiniLogic.tsx
+++ b/frontend/src/lib/components/PayGateMini/payGateMiniLogic.tsx
@@ -1,7 +1,7 @@
import { MakeLogicType, actions, connect, kea, key, path, props, reducers, selectors } from 'kea'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { userLogic } from 'scenes/userLogic'
import { AvailableFeature, BillingProductV2AddonType, BillingProductV2Type } from '~/types'
diff --git a/frontend/src/lib/components/Search/searchListsLogic.tsx b/frontend/src/lib/components/Search/searchListsLogic.tsx
index a8f4193d6002..0f2af191681d 100644
--- a/frontend/src/lib/components/Search/searchListsLogic.tsx
+++ b/frontend/src/lib/components/Search/searchListsLogic.tsx
@@ -12,6 +12,7 @@ import {
} from '@posthog/icons'
import { FEATURE_FLAGS } from 'lib/constants'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import type { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
@@ -21,7 +22,6 @@ import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { PLACEHOLDER_HREF } from 'lib/utils/navigateToHref'
import { newInternalTab } from 'lib/utils/newInternalTab'
import { toSentenceCase } from 'lib/utils/strings'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationIntegrationsLogic } from 'scenes/settings/organization/organizationIntegrationsLogic'
import { terminalDockLogic } from 'scenes/terminal/terminalDockLogic'
import { urls } from 'scenes/urls'
diff --git a/frontend/src/lib/components/Superpowers/buildFakeBillingAlert.ts b/frontend/src/lib/components/Superpowers/buildFakeBillingAlert.ts
index 6811a22e646d..730a3fe68a41 100644
--- a/frontend/src/lib/components/Superpowers/buildFakeBillingAlert.ts
+++ b/frontend/src/lib/components/Superpowers/buildFakeBillingAlert.ts
@@ -1,5 +1,5 @@
-import { buildUsageLimitApproachingMessage, buildUsageLimitReachedMessage } from 'scenes/billing/billing-utils'
-import type { BillingAlertConfig } from 'scenes/billing/billingLogic'
+import type { BillingAlertConfig } from 'lib/logic/billing/billingLogic'
+import { buildUsageLimitApproachingMessage, buildUsageLimitReachedMessage } from 'lib/logic/billing/usageLimits'
import type { FakeBillingAlert } from './superpowersLogic'
diff --git a/frontend/src/lib/components/UpgradeModal/upgradeModalLogic.ts b/frontend/src/lib/components/UpgradeModal/upgradeModalLogic.ts
index 656e182adf13..a2d6bba1b873 100644
--- a/frontend/src/lib/components/UpgradeModal/upgradeModalLogic.ts
+++ b/frontend/src/lib/components/UpgradeModal/upgradeModalLogic.ts
@@ -1,8 +1,8 @@
import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'
import posthog from 'posthog-js'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { userLogic } from 'scenes/userLogic'
import { AvailableFeature } from '~/types'
diff --git a/frontend/src/lib/logic/billing/billingAccess.test.ts b/frontend/src/lib/logic/billing/billingAccess.test.ts
new file mode 100644
index 000000000000..02b6a79b807d
--- /dev/null
+++ b/frontend/src/lib/logic/billing/billingAccess.test.ts
@@ -0,0 +1,85 @@
+import { FEATURE_FLAGS, OrganizationMembershipLevel } from 'lib/constants'
+import type { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
+
+import {
+ canAccessBilling,
+ canViewUsageAndSpend,
+ getMinimumBillingAccessLevel,
+ getMinimumUsageSpendReadAccessLevel,
+ isMemberUsageSpendReadAccessEnabled,
+} from './billingAccess'
+
+describe('getMinimumBillingAccessLevel', () => {
+ it('returns Admin when ownerOnlyBilling is false', () => {
+ expect(getMinimumBillingAccessLevel(false)).toBe(OrganizationMembershipLevel.Admin)
+ })
+
+ it('returns Owner when ownerOnlyBilling is true', () => {
+ expect(getMinimumBillingAccessLevel(true)).toBe(OrganizationMembershipLevel.Owner)
+ })
+})
+
+describe('canAccessBilling', () => {
+ it.each([
+ { level: OrganizationMembershipLevel.Owner, ownerOnly: false, expected: true },
+ { level: OrganizationMembershipLevel.Owner, ownerOnly: true, expected: true },
+ { level: OrganizationMembershipLevel.Admin, ownerOnly: false, expected: true },
+ { level: OrganizationMembershipLevel.Admin, ownerOnly: true, expected: false },
+ { level: OrganizationMembershipLevel.Member, ownerOnly: false, expected: false },
+ { level: OrganizationMembershipLevel.Member, ownerOnly: true, expected: false },
+ { level: null, ownerOnly: false, expected: false },
+ { level: null, ownerOnly: true, expected: false },
+ ])('returns $expected for level=$level, ownerOnly=$ownerOnly', ({ level, ownerOnly, expected }) => {
+ expect(canAccessBilling(level, ownerOnly)).toBe(expected)
+ })
+})
+
+describe('getMinimumUsageSpendReadAccessLevel', () => {
+ it.each([
+ { memberAccess: false, ownerOnly: false, expected: OrganizationMembershipLevel.Admin },
+ { memberAccess: true, ownerOnly: false, expected: OrganizationMembershipLevel.Member },
+ { memberAccess: false, ownerOnly: true, expected: OrganizationMembershipLevel.Owner },
+ // owner-only-billing wins over member-billing-usage-spend-read-access
+ { memberAccess: true, ownerOnly: true, expected: OrganizationMembershipLevel.Owner },
+ ])(
+ 'returns $expected for memberAccess=$memberAccess, ownerOnly=$ownerOnly',
+ ({ memberAccess, ownerOnly, expected }) => {
+ expect(getMinimumUsageSpendReadAccessLevel(memberAccess, ownerOnly)).toBe(expected)
+ }
+ )
+})
+
+describe('canViewUsageAndSpend', () => {
+ it.each([
+ { level: OrganizationMembershipLevel.Member, memberAccess: true, ownerOnly: false, expected: true },
+ { level: OrganizationMembershipLevel.Member, memberAccess: true, ownerOnly: true, expected: false },
+ { level: OrganizationMembershipLevel.Member, memberAccess: false, ownerOnly: false, expected: false },
+ { level: OrganizationMembershipLevel.Admin, memberAccess: false, ownerOnly: false, expected: true },
+ { level: OrganizationMembershipLevel.Admin, memberAccess: true, ownerOnly: true, expected: false },
+ { level: OrganizationMembershipLevel.Owner, memberAccess: false, ownerOnly: true, expected: true },
+ { level: null, memberAccess: true, ownerOnly: false, expected: false },
+ ])(
+ 'returns $expected for level=$level, memberAccess=$memberAccess, ownerOnly=$ownerOnly',
+ ({ level, memberAccess, ownerOnly, expected }) => {
+ expect(canViewUsageAndSpend(level, memberAccess, ownerOnly)).toBe(expected)
+ }
+ )
+})
+
+describe('isMemberUsageSpendReadAccessEnabled', () => {
+ it.each<{ case: string; featureFlags: FeatureFlagsSet; expected: boolean }>([
+ {
+ case: 'the grant is on',
+ featureFlags: { [FEATURE_FLAGS.MEMBER_BILLING_USAGE_SPEND_READ_ACCESS]: true },
+ expected: true,
+ },
+ {
+ case: 'the grant is off',
+ featureFlags: { [FEATURE_FLAGS.MEMBER_BILLING_USAGE_SPEND_READ_ACCESS]: false },
+ expected: false,
+ },
+ { case: 'the flag is not present', featureFlags: {}, expected: false },
+ ])('returns $expected when $case', ({ featureFlags, expected }) => {
+ expect(isMemberUsageSpendReadAccessEnabled(featureFlags)).toBe(expected)
+ })
+})
diff --git a/frontend/src/lib/logic/billing/billingAccess.ts b/frontend/src/lib/logic/billing/billingAccess.ts
new file mode 100644
index 000000000000..82b364d50e16
--- /dev/null
+++ b/frontend/src/lib/logic/billing/billingAccess.ts
@@ -0,0 +1,53 @@
+import { FEATURE_FLAGS, OrganizationMembershipLevel } from 'lib/constants'
+import type { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
+
+/**
+ * Returns the minimum membership level required to access billing.
+ * When ownerOnlyBilling is true (via the owner-only-billing feature flag), only org owners can access billing.
+ */
+export function getMinimumBillingAccessLevel(ownerOnlyBilling: boolean): OrganizationMembershipLevel {
+ return ownerOnlyBilling ? OrganizationMembershipLevel.Owner : OrganizationMembershipLevel.Admin
+}
+
+/**
+ * Determines if the user has sufficient permissions to access billing based on their org membership level.
+ */
+export function canAccessBilling(membershipLevel: number | null | undefined, ownerOnlyBilling: boolean): boolean {
+ if (!membershipLevel) {
+ return false
+ }
+ return membershipLevel >= getMinimumBillingAccessLevel(ownerOnlyBilling)
+}
+
+/** Whether the member-level read grant for usage and spend is in effect. */
+export function isMemberUsageSpendReadAccessEnabled(featureFlags: FeatureFlagsSet): boolean {
+ return !!featureFlags[FEATURE_FLAGS.MEMBER_BILLING_USAGE_SPEND_READ_ACCESS]
+}
+
+/**
+ * Returns the minimum membership level required for read-only access to the billing usage/spend tabs.
+ * The member-billing-usage-spend-read-access feature flag lowers it to Member, but owner-only-billing takes precedence.
+ */
+export function getMinimumUsageSpendReadAccessLevel(
+ memberUsageSpendReadAccess: boolean,
+ ownerOnlyBilling: boolean
+): OrganizationMembershipLevel {
+ if (ownerOnlyBilling) {
+ return OrganizationMembershipLevel.Owner
+ }
+ return memberUsageSpendReadAccess ? OrganizationMembershipLevel.Member : OrganizationMembershipLevel.Admin
+}
+
+/**
+ * Determines if the user can view the read-only billing usage/spend tabs based on their org membership level.
+ */
+export function canViewUsageAndSpend(
+ membershipLevel: number | null | undefined,
+ memberUsageSpendReadAccess: boolean,
+ ownerOnlyBilling: boolean
+): boolean {
+ if (!membershipLevel) {
+ return false
+ }
+ return membershipLevel >= getMinimumUsageSpendReadAccessLevel(memberUsageSpendReadAccess, ownerOnlyBilling)
+}
diff --git a/frontend/src/scenes/billing/billingLogic.test.ts b/frontend/src/lib/logic/billing/billingLogic.test.ts
similarity index 99%
rename from frontend/src/scenes/billing/billingLogic.test.ts
rename to frontend/src/lib/logic/billing/billingLogic.test.ts
index 0f28dabc7893..a67b2d3b7a43 100644
--- a/frontend/src/scenes/billing/billingLogic.test.ts
+++ b/frontend/src/lib/logic/billing/billingLogic.test.ts
@@ -7,9 +7,9 @@ import posthog from 'posthog-js'
import { FEATURE_FLAGS, OrganizationMembershipLevel } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
+import { BillingAPIErrorCodes, billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { BillingAPIErrorCodes, billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/src/scenes/billing/billingLogic.tsx b/frontend/src/lib/logic/billing/billingLogic.tsx
similarity index 99%
rename from frontend/src/scenes/billing/billingLogic.tsx
rename to frontend/src/lib/logic/billing/billingLogic.tsx
index b28aaa795d2c..f9ec6f4ace9d 100644
--- a/frontend/src/scenes/billing/billingLogic.tsx
+++ b/frontend/src/lib/logic/billing/billingLogic.tsx
@@ -16,7 +16,7 @@ import { dayjs } from 'lib/dayjs'
import { LemonBannerAction } from 'lib/lemon-ui/LemonBanner/LemonBanner'
import { lemonBannerLogic } from 'lib/lemon-ui/LemonBanner/lemonBannerLogic'
import { LemonButtonPropsBase } from 'lib/lemon-ui/LemonButton'
-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { pluralize } from 'lib/utils/strings'
@@ -33,24 +33,27 @@ import {
BillingProductV2Type,
BillingProvider,
BillingType,
+ OrganizationType,
+ PreflightStatus,
StartupProgramLabel,
} from '~/types'
-import type { FeatureFlagsSet } from '../../lib/logic/featureFlagLogic'
-import type { OrganizationType, PreflightStatus } from '../../types'
import {
- buildUsageLimitApproachingMessage,
- buildUsageLimitReachedMessage,
canAccessBilling as canAccessBillingUtil,
canViewUsageAndSpend as canViewUsageAndSpendUtil,
getMinimumBillingAccessLevel,
getMinimumUsageSpendReadAccessLevel,
- isCompanionProduct,
+ isMemberUsageSpendReadAccessEnabled,
+} from './billingAccess'
+import { isCompanionProduct } from './companionProducts'
+import {
+ buildUsageLimitApproachingMessage,
+ buildUsageLimitReachedMessage,
isUsageApproachingLimit,
isUsageAtOrOverLimit,
- isMemberUsageSpendReadAccessEnabled,
-} from './billing-utils'
-import { DEFAULT_ESTIMATED_MONTHLY_CREDIT_AMOUNT_USD } from './CreditCTAHero'
+} from './usageLimits'
+
+export const DEFAULT_ESTIMATED_MONTHLY_CREDIT_AMOUNT_USD = 500
export const ALLOCATION_THRESHOLD_ALERT = 0.8 // Threshold to show warning of event usage near limit (aligned with the 80% billing warning email)
export const ALLOCATION_THRESHOLD_BLOCK = 1.2 // Threshold to block usage
@@ -755,6 +758,7 @@ export type billingLogicType = MakeLogicType<
>
export const billingLogic = kea<billingLogicType>([
+ // pinned: the persisted isCreditCTAHeroDismissed reducer derives its localStorage key from this path
path(['scenes', 'billing', 'billingLogic']),
actions({
setProductSpecificAlert: (productSpecificAlert: BillingAlertConfig | null) => ({ productSpecificAlert }),
diff --git a/frontend/src/scenes/billing/billingProductDisplayName.ts b/frontend/src/lib/logic/billing/billingProductDisplayName.ts
similarity index 100%
rename from frontend/src/scenes/billing/billingProductDisplayName.ts
rename to frontend/src/lib/logic/billing/billingProductDisplayName.ts
diff --git a/frontend/src/scenes/billing/billing-companions.test.ts b/frontend/src/lib/logic/billing/companionProducts.test.ts
similarity index 98%
rename from frontend/src/scenes/billing/billing-companions.test.ts
rename to frontend/src/lib/logic/billing/companionProducts.test.ts
index 2be15b57e862..7c33058b8ad9 100644
--- a/frontend/src/scenes/billing/billing-companions.test.ts
+++ b/frontend/src/lib/logic/billing/companionProducts.test.ts
@@ -1,7 +1,7 @@
import { billingJson } from '~/mocks/fixtures/_billing'
import { BillingProductV2Type } from '~/types'
-import { getHeldCompanions, isCompanionHeld, isCompanionProduct } from './billing-utils'
+import { getHeldCompanions, isCompanionHeld, isCompanionProduct } from './companionProducts'
describe('companion products', () => {
const productAnalytics = billingJson.products.find((p) => p.type === 'product_analytics') as BillingProductV2Type
diff --git a/frontend/src/lib/logic/billing/companionProducts.ts b/frontend/src/lib/logic/billing/companionProducts.ts
new file mode 100644
index 000000000000..1db7bb49afe6
--- /dev/null
+++ b/frontend/src/lib/logic/billing/companionProducts.ts
@@ -0,0 +1,14 @@
+import { BillingProductV2Type } from '~/types'
+
+export const isCompanionProduct = (product: BillingProductV2Type): boolean => !!product.companion_of
+
+// After the parent leaves a priced plan, billing keeps the companion on its plan with `subscribed: false`,
+// and it still bills.
+export const isCompanionHeld = (product: BillingProductV2Type): boolean =>
+ !!product.subscribed || !!product.plans?.some((plan) => plan.current_plan)
+
+export const getHeldCompanions = (
+ products: BillingProductV2Type[] | null | undefined,
+ parentType: string
+): BillingProductV2Type[] =>
+ products?.filter((product) => product.companion_of === parentType && isCompanionHeld(product)) ?? []
diff --git a/frontend/src/lib/logic/billing/usageLimits.test.ts b/frontend/src/lib/logic/billing/usageLimits.test.ts
new file mode 100644
index 000000000000..c166932e59f0
--- /dev/null
+++ b/frontend/src/lib/logic/billing/usageLimits.test.ts
@@ -0,0 +1,279 @@
+import { OrganizationMembershipLevel } from 'lib/constants'
+
+import {
+ buildUsageLimitApproachingMessage,
+ buildUsageLimitReachedMessage,
+ formatProductNames,
+ getUsageLimitConsequence,
+ isUsageApproachingLimit,
+ isUsageAtOrOverLimit,
+} from './usageLimits'
+
+describe('usage limit thresholds', () => {
+ it('treats exactly 100% usage as at the limit', () => {
+ expect(isUsageAtOrOverLimit(null)).toBe(false)
+ expect(isUsageAtOrOverLimit(undefined)).toBe(false)
+ expect(isUsageAtOrOverLimit(0.99)).toBe(false)
+ expect(isUsageAtOrOverLimit(1)).toBe(true)
+ expect(isUsageAtOrOverLimit(1.01)).toBe(true)
+ })
+
+ it('only treats usage below 100% as approaching the limit', () => {
+ expect(isUsageApproachingLimit(0.8, 0.8)).toBe(false)
+ expect(isUsageApproachingLimit(0.81, 0.8)).toBe(true)
+ expect(isUsageApproachingLimit(1, 0.8)).toBe(false)
+ expect(isUsageApproachingLimit(1.01, 0.8)).toBe(false)
+ })
+})
+
+describe('formatProductNames', () => {
+ it('should return empty string for empty array', () => {
+ expect(formatProductNames([])).toEqual('')
+ })
+
+ it('should return single product name as-is', () => {
+ expect(formatProductNames(['Session replay'])).toEqual('Session replay')
+ })
+
+ it('should join two products with "and"', () => {
+ expect(formatProductNames(['Session replay', 'Feature flags & Experiments'])).toEqual(
+ 'Session replay and Feature flags & Experiments'
+ )
+ })
+
+ it('should join three or more products with commas and "and"', () => {
+ expect(formatProductNames(['Product analytics', 'Session replay', 'Feature flags & Experiments'])).toEqual(
+ 'Product analytics, Session replay and Feature flags & Experiments'
+ )
+ })
+})
+
+describe('getUsageLimitConsequence', () => {
+ it.each(['Data warehouse', 'Sources'])('should return the sync consequence for %s', (name) => {
+ expect(getUsageLimitConsequence(name)).toEqual('data will not be synced')
+ })
+
+ it('should return specific message for Feature flags & Experiments', () => {
+ expect(getUsageLimitConsequence('Feature flags & Experiments')).toEqual('feature flags will not evaluate')
+ })
+
+ it('should return specific message for PostHog AI', () => {
+ expect(getUsageLimitConsequence('PostHog AI')).toEqual('PostHog AI will be unavailable')
+ })
+
+ it('should return specific message for the self-driving inbox', () => {
+ expect(getUsageLimitConsequence('Self-driving inbox')).toEqual('self-driving agents will be paused')
+ })
+
+ it('should return generic message for other products', () => {
+ expect(getUsageLimitConsequence('Session replay')).toEqual('data loss may occur')
+ expect(getUsageLimitConsequence('Product analytics')).toEqual('data loss may occur')
+ expect(getUsageLimitConsequence('Surveys')).toEqual('data loss may occur')
+ })
+})
+
+describe('buildUsageLimitReachedMessage', () => {
+ it('should return empty strings for empty array', () => {
+ expect(buildUsageLimitReachedMessage([])).toEqual({ title: '', message: '' })
+ })
+
+ it('should build message for single subscribed product', () => {
+ const result = buildUsageLimitReachedMessage([{ name: 'Session replay', subscribed: true }])
+ expect(result.title).toEqual('Usage limit reached')
+ expect(result.message).toEqual(
+ 'You have reached the usage limit for Session replay. Please increase your billing limit or data loss may occur.'
+ )
+ })
+
+ it('should build message for single unsubscribed product', () => {
+ const result = buildUsageLimitReachedMessage([{ name: 'Session replay', subscribed: false }])
+ expect(result.message).toContain('upgrade your plan')
+ })
+
+ it.each(['Data warehouse', 'Sources'])('should explain stopped syncing for %s at its usage limit', (name) => {
+ const result = buildUsageLimitReachedMessage([{ type: 'data_warehouse', name, subscribed: true }])
+ expect(result.message).toEqual(
+ `You have reached the usage limit for ${name}. Please increase your billing limit or data will not be synced.`
+ )
+ })
+
+ it('should build message for multiple products with unique consequences', () => {
+ const result = buildUsageLimitReachedMessage([
+ { name: 'Session replay', subscribed: true },
+ { name: 'Feature flags & Experiments', subscribed: true },
+ ])
+ expect(result.title).toEqual('Usage limits reached')
+ expect(result.message).toEqual(
+ 'You have reached the usage limit for Session replay and Feature flags & Experiments. Please increase your billing limit or data loss may occur and feature flags will not evaluate.'
+ )
+ })
+
+ it('should build message for PostHog AI with specific consequence', () => {
+ const result = buildUsageLimitReachedMessage([{ name: 'PostHog AI', subscribed: true }])
+ expect(result.title).toEqual('Usage limit reached')
+ expect(result.message).toEqual(
+ 'You have reached the usage limit for PostHog AI. Please increase your billing limit or PostHog AI will be unavailable.'
+ )
+ })
+
+ it('should name the self-driving inbox by its app name, not its billing name', () => {
+ const result = buildUsageLimitReachedMessage([{ type: 'inbox', name: 'Inbox', subscribed: true }])
+ expect(result.title).toEqual('Usage limit reached')
+ expect(result.message).toEqual(
+ 'You have reached the usage limit for Self-driving inbox. Please increase your billing limit or self-driving agents will be paused.'
+ )
+ })
+
+ it('should build message for PostHog AI with other products', () => {
+ const result = buildUsageLimitReachedMessage([
+ { name: 'PostHog AI', subscribed: true },
+ { name: 'Session replay', subscribed: true },
+ ])
+ expect(result.title).toEqual('Usage limits reached')
+ expect(result.message).toEqual(
+ 'You have reached the usage limit for PostHog AI and Session replay. Please increase your billing limit or PostHog AI will be unavailable and data loss may occur.'
+ )
+ })
+
+ it('should deduplicate consequences for products with same consequence', () => {
+ const result = buildUsageLimitReachedMessage([
+ { name: 'Session replay', subscribed: true },
+ { name: 'Product analytics', subscribed: true },
+ ])
+ expect(result.message).toEqual(
+ 'You have reached the usage limit for Session replay and Product analytics. Please increase your billing limit or data loss may occur.'
+ )
+ })
+
+ it('should use upgrade message when any product is not subscribed', () => {
+ const result = buildUsageLimitReachedMessage([
+ { name: 'Session replay', subscribed: true },
+ { name: 'Feature flags & Experiments', subscribed: false },
+ ])
+ expect(result.message).toContain('upgrade your plan')
+ })
+
+ it.each([
+ {
+ hasBillingAccess: true,
+ subscribed: true,
+ expected: 'increase your billing limit',
+ },
+ {
+ hasBillingAccess: true,
+ subscribed: false,
+ expected: 'upgrade your plan',
+ },
+ {
+ hasBillingAccess: false,
+ subscribed: true,
+ expected: 'ask an organization admin to increase the billing limit',
+ },
+ {
+ hasBillingAccess: false,
+ subscribed: false,
+ expected: 'ask an organization admin to upgrade the plan',
+ },
+ ])(
+ 'should use "$expected" when hasBillingAccess=$hasBillingAccess and subscribed=$subscribed',
+ ({ hasBillingAccess, subscribed, expected }) => {
+ const result = buildUsageLimitReachedMessage([{ name: 'Session replay', subscribed }], hasBillingAccess)
+ expect(result.message).toContain(expected)
+ }
+ )
+
+ it('should say "owner" when minimumBillingAccessLevel is Owner and user has no billing access', () => {
+ const result = buildUsageLimitReachedMessage(
+ [{ name: 'Session replay', subscribed: true }],
+ false,
+ OrganizationMembershipLevel.Owner
+ )
+ expect(result.message).toContain('ask an organization owner')
+ })
+
+ it('should default to admin message when hasBillingAccess is not provided', () => {
+ const result = buildUsageLimitReachedMessage([{ name: 'Session replay', subscribed: true }])
+ expect(result.message).toContain('increase your billing limit')
+ })
+})
+
+describe('buildUsageLimitApproachingMessage', () => {
+ it('should return empty strings for empty array', () => {
+ expect(buildUsageLimitApproachingMessage([])).toEqual({ title: '', message: '' })
+ })
+
+ it('should build message for single product', () => {
+ const result = buildUsageLimitApproachingMessage([
+ { name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' },
+ ])
+ expect(result.title).toEqual('You will soon hit your usage limit')
+ expect(result.message).toEqual('You have currently used 90% of your Session replay allocation.')
+ })
+
+ it('should build message for multiple products', () => {
+ const result = buildUsageLimitApproachingMessage([
+ { name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' },
+ { name: 'Feature flags & Experiments', percentage_usage: 0.87, usage_key: 'feature_flag_requests' },
+ ])
+ expect(result.title).toEqual('You will soon hit your usage limits')
+ expect(result.message).toEqual(
+ 'You are approaching your usage limits: 90% of your Session replay allocation, 87% of your Feature flags & Experiments allocation.'
+ )
+ })
+
+ it.each([
+ { name: 'Session replay', usage_key: undefined, expected: 'Session replay allocation' },
+ { name: '', usage_key: 'signals_credits', expected: 'signals_credits allocation' },
+ { name: '', usage_key: undefined, expected: 'usage allocation' },
+ ])('should resolve label to "$expected" (name="$name", usage_key=$usage_key)', ({ name, usage_key, expected }) => {
+ const result = buildUsageLimitApproachingMessage([{ name, percentage_usage: 0.9, usage_key }])
+ expect(result.message).toContain(expected)
+ })
+
+ it('should format percentage with up to 2 decimal places', () => {
+ const result = buildUsageLimitApproachingMessage([
+ { name: 'Session replay', percentage_usage: 0.8567, usage_key: 'recordings' },
+ ])
+ expect(result.message).toContain('85.67%')
+ })
+
+ it.each([
+ {
+ hasBillingAccess: true,
+ expectedSuffix: false,
+ },
+ {
+ hasBillingAccess: false,
+ expectedSuffix: true,
+ },
+ ])(
+ 'should include admin contact message when hasBillingAccess=$hasBillingAccess',
+ ({ hasBillingAccess, expectedSuffix }) => {
+ const result = buildUsageLimitApproachingMessage(
+ [{ name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' }],
+ hasBillingAccess
+ )
+ if (expectedSuffix) {
+ expect(result.message).toContain('Please ask an organization admin to increase the billing limit.')
+ } else {
+ expect(result.message).not.toContain('organization admin')
+ }
+ }
+ )
+
+ it('should say "owner" when minimumBillingAccessLevel is Owner and user has no billing access', () => {
+ const result = buildUsageLimitApproachingMessage(
+ [{ name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' }],
+ false,
+ OrganizationMembershipLevel.Owner
+ )
+ expect(result.message).toContain('ask an organization owner')
+ })
+
+ it('should default to no admin suffix when hasBillingAccess is not provided', () => {
+ const result = buildUsageLimitApproachingMessage([
+ { name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' },
+ ])
+ expect(result.message).not.toContain('organization admin')
+ })
+})
diff --git a/frontend/src/lib/logic/billing/usageLimits.ts b/frontend/src/lib/logic/billing/usageLimits.ts
new file mode 100644
index 000000000000..1ebc81194698
--- /dev/null
+++ b/frontend/src/lib/logic/billing/usageLimits.ts
@@ -0,0 +1,131 @@
+import { OrganizationMembershipLevel } from 'lib/constants'
+import { membershipLevelToName } from 'lib/utils/permissioning'
+import { capitalizeFirstLetter } from 'lib/utils/strings'
+
+import { billingProductDisplayName } from './billingProductDisplayName'
+
+export const isUsageAtOrOverLimit = (percentageUsage: number | null | undefined): boolean => {
+ return (percentageUsage ?? 0) >= 1
+}
+
+export const isUsageApproachingLimit = (percentageUsage: number | null | undefined, threshold: number): boolean => {
+ return (percentageUsage ?? 0) > threshold && !isUsageAtOrOverLimit(percentageUsage)
+}
+
+/**
+ * Build a human-readable list of product names (e.g., "A, B and C")
+ */
+export function formatProductNames(names: string[]): string {
+ if (names.length === 0) {
+ return ''
+ }
+ if (names.length === 1) {
+ return names[0]
+ }
+ return names.slice(0, -1).join(', ') + ' and ' + names[names.length - 1]
+}
+
+/**
+ * Get the consequence message for a product when it reaches its usage limit
+ */
+export function getUsageLimitConsequence(productName: string): string {
+ if (productName === 'Data warehouse' || productName === 'Sources') {
+ return 'data will not be synced'
+ }
+ if (productName === 'Feature flags & Experiments') {
+ return 'feature flags will not evaluate'
+ }
+ if (productName === 'PostHog AI') {
+ return 'PostHog AI will be unavailable'
+ }
+ if (productName === 'Self-driving inbox') {
+ return 'self-driving agents will be paused'
+ }
+ return 'data loss may occur'
+}
+
+/**
+ * Build a consolidated message for products that have reached their usage limits
+ */
+export function buildUsageLimitReachedMessage(
+ products: Array<{ type?: string | null; name: string; subscribed: boolean | null }>,
+ hasBillingAccess: boolean = true,
+ minimumBillingAccessLevel: OrganizationMembershipLevel = OrganizationMembershipLevel.Admin,
+ selfServeBillingNotice: string | null = null
+): {
+ title: string
+ message: string
+} {
+ if (products.length === 0) {
+ return { title: '', message: '' }
+ }
+
+ const productNames = products.map(billingProductDisplayName)
+ const allSubscribed = products.every((p) => p.subscribed === true)
+
+ // Build consequence message, deduplicating common consequences
+ const consequences = [...new Set(productNames.map(getUsageLimitConsequence))]
+
+ const productListText = formatProductNames(productNames)
+ const consequenceText = consequences.join(' and ')
+ const title = products.length === 1 ? 'Usage limit reached' : 'Usage limits reached'
+
+ if (selfServeBillingNotice && !allSubscribed) {
+ return {
+ title,
+ message: `You have reached the usage limit for ${productListText}. ${capitalizeFirstLetter(consequenceText)}. ${selfServeBillingNotice}`,
+ }
+ }
+
+ let actionText: string
+ if (hasBillingAccess) {
+ actionText = allSubscribed ? 'increase your billing limit' : 'upgrade your plan'
+ } else {
+ const roleName = membershipLevelToName.get(minimumBillingAccessLevel)
+ actionText = allSubscribed
+ ? `ask an organization ${roleName} to increase the billing limit`
+ : `ask an organization ${roleName} to upgrade the plan`
+ }
+
+ return {
+ title,
+ message: `You have reached the usage limit for ${productListText}. Please ${actionText} or ${consequenceText}.`,
+ }
+}
+
+/**
+ * Build a consolidated message for products approaching their usage limits
+ */
+export function buildUsageLimitApproachingMessage(
+ products: Array<{
+ type?: string | null
+ name: string
+ percentage_usage: number
+ usage_key?: string | null
+ }>,
+ hasBillingAccess: boolean = true,
+ minimumBillingAccessLevel: OrganizationMembershipLevel = OrganizationMembershipLevel.Admin
+): { title: string; message: string } {
+ if (products.length === 0) {
+ return { title: '', message: '' }
+ }
+
+ const usageDetails = products.map((p) => {
+ const percentage = parseFloat((p.percentage_usage * 100).toFixed(2))
+ const productName = (p.name && billingProductDisplayName(p)) || p.usage_key?.toLowerCase() || 'usage'
+ return `${percentage}% of your ${productName} allocation`
+ })
+
+ const roleName = membershipLevelToName.get(minimumBillingAccessLevel)
+ const adminSuffix = hasBillingAccess ? '' : ` Please ask an organization ${roleName} to increase the billing limit.`
+
+ const message =
+ products.length === 1
+ ? `You have currently used ${usageDetails[0]}.${adminSuffix}`
+ : `You are approaching your usage limits: ${usageDetails.join(', ')}.${adminSuffix}`
+
+ return {
+ title: products.length === 1 ? 'You will soon hit your usage limit' : 'You will soon hit your usage limits',
+ message,
+ }
+}
diff --git a/frontend/src/scenes/AuthenticatedShell.tsx b/frontend/src/scenes/AuthenticatedShell.tsx
index a312dc280b23..349544232c96 100644
--- a/frontend/src/scenes/AuthenticatedShell.tsx
+++ b/frontend/src/scenes/AuthenticatedShell.tsx
@@ -8,11 +8,11 @@ import { globalSetupLogic, useSetupHighlight } from 'lib/components/ProductSetup
import { FEATURE_FLAGS } from 'lib/constants'
import { ToastCloseButton } from 'lib/lemon-ui/LemonToast/LemonToast'
import { apiStatusLogic } from 'lib/logic/apiStatusLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { eventIngestionRestrictionLogic } from 'lib/logic/eventIngestionRestrictionLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { isEmbeddedPageFrame } from 'lib/utils/embeddedPageFrame'
import { lazyWithRetry } from 'lib/utils/retryImport'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { ChunkLoadErrorBoundary } from 'scenes/ChunkLoadErrorBoundary'
import { WizardHandoffDialog } from 'scenes/onboarding/shared/wizard-sync/WizardHandoffDialog'
import { WizardSyncDebugPanel } from 'scenes/onboarding/shared/wizard-sync/WizardSyncDebugPanel'
diff --git a/frontend/src/scenes/billing/AddonFeatureLossNotice.tsx b/frontend/src/scenes/billing/AddonFeatureLossNotice.tsx
index 37b80f8edb5c..4cf0473d15e8 100644
--- a/frontend/src/scenes/billing/AddonFeatureLossNotice.tsx
+++ b/frontend/src/scenes/billing/AddonFeatureLossNotice.tsx
@@ -5,12 +5,12 @@ import { useState } from 'react'
import { LemonBanner } from '@posthog/lemon-ui'
import { AnimatedCollapsible } from 'lib/components/AnimatedCollapsible'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { ProductKey } from '~/queries/schema/schema-general'
import { BillingProductV2AddonType, BillingProductV2Type } from '~/types'
import { BillingAddonFeaturesList } from './BillingAddonFeaturesList'
-import { billingLogic } from './billingLogic'
interface AddonFeatureLossNoticeProps {
product: BillingProductV2Type | BillingProductV2AddonType
diff --git a/frontend/src/scenes/billing/Billing.tsx b/frontend/src/scenes/billing/Billing.tsx
index 660a112a35c9..13341c0bff57 100644
--- a/frontend/src/scenes/billing/Billing.tsx
+++ b/frontend/src/scenes/billing/Billing.tsx
@@ -17,6 +17,8 @@ import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { SpinnerOverlay } from 'lib/lemon-ui/Spinner/Spinner'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+import { isCompanionProduct } from 'lib/logic/billing/companionProducts'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { toSentenceCase } from 'lib/utils/strings'
@@ -28,9 +30,7 @@ import { membersLogic } from '~/models/membersLogic'
import { ProductKey } from '~/queries/schema/schema-general'
import { BillingProductV2Type } from '~/types'
-import { isCompanionProduct } from './billing-utils'
import { BillingHero } from './BillingHero'
-import { billingLogic } from './billingLogic'
import { BillingNoAccess } from './BillingNoAccess'
import { BillingProduct } from './BillingProduct'
import { BillingSummary } from './BillingSummary'
diff --git a/frontend/src/scenes/billing/BillingCompanionSection.test.tsx b/frontend/src/scenes/billing/BillingCompanionSection.test.tsx
index 16c1ff0c3c17..a75ce7db956c 100644
--- a/frontend/src/scenes/billing/BillingCompanionSection.test.tsx
+++ b/frontend/src/scenes/billing/BillingCompanionSection.test.tsx
@@ -6,6 +6,7 @@ import userEvent from '@testing-library/user-event'
import { Provider } from 'kea'
import { expectLogic } from 'kea-test-utils'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { billingJson } from '~/mocks/fixtures/_billing'
@@ -15,7 +16,6 @@ import { BillingProductV2Type, BillingType } from '~/types'
import { Billing } from './Billing'
import { BillingCompanionSection } from './BillingCompanionSection'
-import { billingLogic } from './billingLogic'
import { BillingProduct } from './BillingProduct'
import { PlanComparison } from './PlanComparison'
diff --git a/frontend/src/scenes/billing/BillingCompanionSection.tsx b/frontend/src/scenes/billing/BillingCompanionSection.tsx
index efee0d244335..959717df4d1e 100644
--- a/frontend/src/scenes/billing/BillingCompanionSection.tsx
+++ b/frontend/src/scenes/billing/BillingCompanionSection.tsx
@@ -3,6 +3,8 @@ import { useActions, useValues } from 'kea'
import { IconChevronDown, IconChevronRight } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+import { billingProductDisplayName, billingProductRowDisplayName } from 'lib/logic/billing/billingProductDisplayName'
import { humanFriendlyCurrency } from 'lib/utils/numbers'
import { capitalizeFirstLetter } from 'lib/utils/strings'
@@ -10,8 +12,6 @@ import { BillingProductV2Type } from '~/types'
import { createGaugeItems, isBillingLimitShown } from './billing-utils'
import { BillingGauge } from './BillingGauge'
-import { billingLogic } from './billingLogic'
-import { billingProductDisplayName, billingProductRowDisplayName } from './billingProductDisplayName'
import { billingProductLogic } from './billingProductLogic'
import { BillingProductPricingTable } from './BillingProductPricingTable'
diff --git a/frontend/src/scenes/billing/BillingGauge.tsx b/frontend/src/scenes/billing/BillingGauge.tsx
index adaee8c30893..7161c0c05f23 100644
--- a/frontend/src/scenes/billing/BillingGauge.tsx
+++ b/frontend/src/scenes/billing/BillingGauge.tsx
@@ -4,15 +4,11 @@ import clsx from 'clsx'
import { useMemo } from 'react'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { isUsageAtOrOverLimit } from 'lib/logic/billing/usageLimits'
import { BillingProductV2AddonType, BillingProductV2Type } from '~/types'
-import {
- createProductValueFormatter,
- formatDisplayUsage,
- hasDisplayFormatting,
- isUsageAtOrOverLimit,
-} from './billing-utils'
+import { createProductValueFormatter, formatDisplayUsage, hasDisplayFormatting } from './billing-utils'
import { BillingGaugeItemType } from './types'
/*
diff --git a/frontend/src/scenes/billing/BillingHero.tsx b/frontend/src/scenes/billing/BillingHero.tsx
index ea56055af400..3178fe141067 100644
--- a/frontend/src/scenes/billing/BillingHero.tsx
+++ b/frontend/src/scenes/billing/BillingHero.tsx
@@ -6,6 +6,7 @@ import { Link } from '@posthog/lemon-ui'
import { BillingUpgradeCTA } from 'lib/components/BillingUpgradeCTA'
import { Dayjs } from 'lib/dayjs'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+import { YcCreditsState, billingLogic } from 'lib/logic/billing/billingLogic'
import { BillingPlan, BillingProductV2Type, StartupProgramLabel } from '~/types'
@@ -16,7 +17,6 @@ import planStartup from 'public/plan_startup.svg'
import planTeams from 'public/plan_teams.png'
import planYc from 'public/plan_yc.svg'
-import { YcCreditsState, billingLogic } from './billingLogic'
import { billingProductLogic } from './billingProductLogic'
import { paymentEntryLogic } from './paymentEntryLogic'
import { PlanComparisonModal } from './PlanComparison'
diff --git a/frontend/src/scenes/billing/BillingLimit.test.tsx b/frontend/src/scenes/billing/BillingLimit.test.tsx
index f3a62fbf25d7..1d24a2c2f463 100644
--- a/frontend/src/scenes/billing/BillingLimit.test.tsx
+++ b/frontend/src/scenes/billing/BillingLimit.test.tsx
@@ -6,13 +6,14 @@ import userEvent from '@testing-library/user-event'
import { Provider } from 'kea'
import { expectLogic } from 'kea-test-utils'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+
import { billingJson } from '~/mocks/fixtures/_billing'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { BillingProductV2Type, BillingType } from '~/types'
import { BillingLimit } from './BillingLimit'
-import { billingLogic } from './billingLogic'
// Zero out current/projected usage so submitting never triggers the below-usage warning
// dialog — this test is about the Save/Remove button wiring, not that branch.
diff --git a/frontend/src/scenes/billing/BillingLimit.tsx b/frontend/src/scenes/billing/BillingLimit.tsx
index 1c7c22a781b9..b7476fe23a6c 100644
--- a/frontend/src/scenes/billing/BillingLimit.tsx
+++ b/frontend/src/scenes/billing/BillingLimit.tsx
@@ -6,12 +6,12 @@ import { LemonButton, LemonInput } from '@posthog/lemon-ui'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+import { billingProductDisplayName } from 'lib/logic/billing/billingProductDisplayName'
import { BillingProductV2Type } from '~/types'
import { isBillingLimitShown } from './billing-utils'
-import { billingLogic } from './billingLogic'
-import { billingProductDisplayName } from './billingProductDisplayName'
import { billingProductLogic } from './billingProductLogic'
export const BillingLimit = ({ product }: { product: BillingProductV2Type }): JSX.Element | null => {
diff --git a/frontend/src/scenes/billing/BillingProduct.tsx b/frontend/src/scenes/billing/BillingProduct.tsx
index b8670a19f123..960831b7efed 100644
--- a/frontend/src/scenes/billing/BillingProduct.tsx
+++ b/frontend/src/scenes/billing/BillingProduct.tsx
@@ -12,6 +12,9 @@ import { useResizeBreakpoints } from 'lib/hooks/useResizeObserver'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { More } from 'lib/lemon-ui/LemonButton/More'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+import { billingProductDisplayName } from 'lib/logic/billing/billingProductDisplayName'
+import { isUsageAtOrOverLimit } from 'lib/logic/billing/usageLimits'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { humanFriendlyCurrency } from 'lib/utils/numbers'
import { capitalizeFirstLetter } from 'lib/utils/strings'
@@ -24,15 +27,12 @@ import {
createGaugeItems,
createProductValueFormatter,
getProductUnitLabel,
- isUsageAtOrOverLimit,
isProductVariantPrimary,
} from './billing-utils'
import { BillingCompanionSection } from './BillingCompanionSection'
import { BillingGauge } from './BillingGauge'
import { BillingLimit } from './BillingLimit'
-import { billingLogic } from './billingLogic'
import { BillingProductAddon } from './BillingProductAddon'
-import { billingProductDisplayName } from './billingProductDisplayName'
import { billingProductLogic } from './billingProductLogic'
import { BillingProductPricingTable } from './BillingProductPricingTable'
import { DesktopUsageBreakdown } from './DesktopUsageBreakdown'
diff --git a/frontend/src/scenes/billing/BillingProductAddon.tsx b/frontend/src/scenes/billing/BillingProductAddon.tsx
index dc737238426c..ce5a4fb26ac5 100644
--- a/frontend/src/scenes/billing/BillingProductAddon.tsx
+++ b/frontend/src/scenes/billing/BillingProductAddon.tsx
@@ -5,6 +5,7 @@ import { ReactNode, useRef } from 'react'
import { IconCheckCircle, IconInfo } from '@posthog/icons'
import { LemonSelectOptions, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { humanFriendlyCurrency } from 'lib/utils/numbers'
import { getProductIcon } from 'scenes/onboarding/shared/utils'
@@ -12,7 +13,6 @@ import { BillingProductV2AddonType } from '~/types'
import { isProductVariantSecondary } from './billing-utils'
import { BillingAddonFeaturesList } from './BillingAddonFeaturesList'
-import { billingLogic } from './billingLogic'
import { BillingProductAddonActions } from './BillingProductAddonActions'
import { billingProductLogic } from './billingProductLogic'
import { DATA_PIPELINES_CUTOFF_DATE } from './constants'
diff --git a/frontend/src/scenes/billing/BillingProductAddonActions.tsx b/frontend/src/scenes/billing/BillingProductAddonActions.tsx
index db16111f1971..fdc4eae931a9 100644
--- a/frontend/src/scenes/billing/BillingProductAddonActions.tsx
+++ b/frontend/src/scenes/billing/BillingProductAddonActions.tsx
@@ -7,11 +7,11 @@ import { LemonButton, LemonButtonProps, LemonTag } from '@posthog/lemon-ui'
import { TRIAL_CANCELLATION_SURVEY_ID, UNSUBSCRIBE_SURVEY_ID } from 'lib/constants'
import { More } from 'lib/lemon-ui/LemonButton/More'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { BillingProductV2AddonType } from '~/types'
-import { billingLogic } from './billingLogic'
import { formatFlatRate } from './BillingProductAddon'
import { billingProductLogic } from './billingProductLogic'
import { ConfirmDowngradeModal } from './ConfirmDowngradeModal'
diff --git a/frontend/src/scenes/billing/BillingProductPricingTable.tsx b/frontend/src/scenes/billing/BillingProductPricingTable.tsx
index 8267021f0135..401028619953 100644
--- a/frontend/src/scenes/billing/BillingProductPricingTable.tsx
+++ b/frontend/src/scenes/billing/BillingProductPricingTable.tsx
@@ -3,6 +3,8 @@ import { useValues } from 'kea'
import { IconArrowRightDown, IconInfo } from '@posthog/icons'
import { LemonBanner, LemonTable, LemonTableColumns, Tooltip } from '@posthog/lemon-ui'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+
import {
BillingProductV2AddonType,
BillingProductV2Type,
@@ -16,7 +18,6 @@ import {
hasDisplayFormatting,
isProductVariantPrimary,
} from './billing-utils'
-import { billingLogic } from './billingLogic'
import { getTierDescription } from './BillingProduct'
import { billingProductLogic } from './billingProductLogic'
diff --git a/frontend/src/scenes/billing/BillingSection.tsx b/frontend/src/scenes/billing/BillingSection.tsx
index 8dfd19972d9d..868b7d41266c 100644
--- a/frontend/src/scenes/billing/BillingSection.tsx
+++ b/frontend/src/scenes/billing/BillingSection.tsx
@@ -7,6 +7,7 @@ import { Suspense, useEffect } from 'react'
import { LemonTabs, Spinner } from '@posthog/lemon-ui'
import { FEATURE_FLAGS } from 'lib/constants'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { lazyWithRetry } from 'lib/utils/retryImport'
import { SceneExport } from 'scenes/sceneTypes'
@@ -16,7 +17,6 @@ import { urls } from 'scenes/urls'
import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { Billing } from './Billing'
-import { billingLogic } from './billingLogic'
import { BillingSpendView } from './BillingSpendView'
import { BillingUsage } from './BillingUsage'
import { BillingSectionId } from './types'
diff --git a/frontend/src/scenes/billing/BillingSpendView.tsx b/frontend/src/scenes/billing/BillingSpendView.tsx
index 380a45ddc70f..db5cd7214484 100644
--- a/frontend/src/scenes/billing/BillingSpendView.tsx
+++ b/frontend/src/scenes/billing/BillingSpendView.tsx
@@ -12,6 +12,7 @@ import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { LemonInputSelect } from 'lib/lemon-ui/LemonInputSelect/LemonInputSelect'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel/LemonLabel'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { AccessControlLevel, AccessControlResourceType } from '~/types'
@@ -26,7 +27,6 @@ import { BillingChart } from './BillingChart'
import { BillingDataTable } from './BillingDataTable'
import { BillingEarlyAccessBanner } from './BillingEarlyAccessBanner'
import { BillingEmptyState } from './BillingEmptyState'
-import { billingLogic } from './billingLogic'
import { BillingNoAccess } from './BillingNoAccess'
import { billingSpendLogic } from './billingSpendLogic'
import { TOP_PROJECTS_OPTIONS } from './constants'
diff --git a/frontend/src/scenes/billing/BillingSummary.tsx b/frontend/src/scenes/billing/BillingSummary.tsx
index 615f414f88d9..d69072fb4302 100644
--- a/frontend/src/scenes/billing/BillingSummary.tsx
+++ b/frontend/src/scenes/billing/BillingSummary.tsx
@@ -2,9 +2,9 @@ import { useValues } from 'kea'
import { dayjs } from 'lib/dayjs'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel/LemonLabel'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { humanFriendlyCurrency } from 'lib/utils/numbers'
-import { billingLogic } from './billingLogic'
import { StripePortalButton } from './StripePortalButton'
export const BillingSummary = (): JSX.Element => {
diff --git a/frontend/src/scenes/billing/BillingUsage.tsx b/frontend/src/scenes/billing/BillingUsage.tsx
index 44bf91941dbd..bc818c35e3e7 100644
--- a/frontend/src/scenes/billing/BillingUsage.tsx
+++ b/frontend/src/scenes/billing/BillingUsage.tsx
@@ -11,6 +11,7 @@ import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { LemonInputSelect } from 'lib/lemon-ui/LemonInputSelect/LemonInputSelect'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel/LemonLabel'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { AccessControlLevel, AccessControlResourceType } from '~/types'
@@ -20,7 +21,6 @@ import { BillingChart } from './BillingChart'
import { BillingDataTable } from './BillingDataTable'
import { BillingEarlyAccessBanner } from './BillingEarlyAccessBanner'
import { BillingEmptyState } from './BillingEmptyState'
-import { billingLogic } from './billingLogic'
import { BillingNoAccess } from './BillingNoAccess'
import { billingUsageLogic } from './billingUsageLogic'
import { TOP_PROJECTS_OPTIONS } from './constants'
diff --git a/frontend/src/scenes/billing/ConfirmDowngradeModal.tsx b/frontend/src/scenes/billing/ConfirmDowngradeModal.tsx
index 79b9095432d1..5dc0585dc51d 100644
--- a/frontend/src/scenes/billing/ConfirmDowngradeModal.tsx
+++ b/frontend/src/scenes/billing/ConfirmDowngradeModal.tsx
@@ -4,11 +4,11 @@ import { LemonButton, LemonModal, LemonTable, LemonTableColumns, Link } from '@p
import { supportLogic } from 'lib/components/Support/supportLogic'
import { dayjs } from 'lib/dayjs'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { BillingInvoiceItemRow, BillingProductV2AddonType } from '~/types'
import { AddonFeatureLossNotice } from './AddonFeatureLossNotice'
-import { billingLogic } from './billingLogic'
import { billingProductLogic } from './billingProductLogic'
export function ConfirmDowngradeModal({ product }: { product: BillingProductV2AddonType }): JSX.Element | null {
diff --git a/frontend/src/scenes/billing/ConfirmPurchaseModal.tsx b/frontend/src/scenes/billing/ConfirmPurchaseModal.tsx
index 30a99ee80fb5..4058db31ec3b 100644
--- a/frontend/src/scenes/billing/ConfirmPurchaseModal.tsx
+++ b/frontend/src/scenes/billing/ConfirmPurchaseModal.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { dayjs } from 'lib/dayjs'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { billingProductLogic } from 'scenes/billing/billingProductLogic'
import { BillingInvoiceItemRow, BillingProductV2AddonType } from '~/types'
diff --git a/frontend/src/scenes/billing/ConfirmUpgradeModal.tsx b/frontend/src/scenes/billing/ConfirmUpgradeModal.tsx
index d194d82fc5f7..9dcf15c5e09e 100644
--- a/frontend/src/scenes/billing/ConfirmUpgradeModal.tsx
+++ b/frontend/src/scenes/billing/ConfirmUpgradeModal.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { dayjs } from 'lib/dayjs'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { billingProductLogic } from 'scenes/billing/billingProductLogic'
import { BillingInvoiceItemRow, BillingProductV2AddonType } from '~/types'
diff --git a/frontend/src/scenes/billing/CreditCTAHero.tsx b/frontend/src/scenes/billing/CreditCTAHero.tsx
index dc866ae0fe83..829ca151bb34 100644
--- a/frontend/src/scenes/billing/CreditCTAHero.tsx
+++ b/frontend/src/scenes/billing/CreditCTAHero.tsx
@@ -5,14 +5,12 @@ import { IconX } from '@posthog/icons'
import { LemonButton, LemonDivider, LemonSkeleton } from '@posthog/lemon-ui'
import { pngHoggie } from 'lib/brand/hoggies'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
-import { billingLogic } from './billingLogic'
import { PurchaseCreditsModal } from './PurchaseCreditsModal'
const HedgehogBurningMoney = pngHoggie(burningMoneyHogPng)
-export const DEFAULT_ESTIMATED_MONTHLY_CREDIT_AMOUNT_USD = 500
-
export const CreditCTAHero = (): JSX.Element | null => {
const {
billing,
diff --git a/frontend/src/scenes/billing/InitialBillingLimitNotice.tsx b/frontend/src/scenes/billing/InitialBillingLimitNotice.tsx
index 9342e5f6df8f..022fc71d031a 100644
--- a/frontend/src/scenes/billing/InitialBillingLimitNotice.tsx
+++ b/frontend/src/scenes/billing/InitialBillingLimitNotice.tsx
@@ -1,12 +1,12 @@
import { useValues } from 'kea'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { urls } from 'scenes/urls'
import { ProductKey } from '~/queries/schema/schema-general'
import { BillingProductV2Type } from '~/types'
-import { billingLogic } from './billingLogic'
import { billingProductLogic } from './billingProductLogic'
const InitialBillingLimitNoticeContents = ({ product }: { product: BillingProductV2Type }): JSX.Element | null => {
diff --git a/frontend/src/scenes/billing/PlanComparison.tsx b/frontend/src/scenes/billing/PlanComparison.tsx
index 3b30dda80cd2..c7b55ff7260a 100644
--- a/frontend/src/scenes/billing/PlanComparison.tsx
+++ b/frontend/src/scenes/billing/PlanComparison.tsx
@@ -10,6 +10,8 @@ import { LemonModal, LemonTag, Link } from '@posthog/lemon-ui'
import { FEATURE_FLAGS } from 'lib/constants'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+import { isCompanionProduct } from 'lib/logic/billing/companionProducts'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { getProductIcon } from 'scenes/onboarding/shared/utils'
@@ -21,8 +23,7 @@ import {
BillingProductV2Type,
} from '~/types'
-import { convertLargeNumberToWords, getProration, isCompanionProduct } from './billing-utils'
-import { billingLogic } from './billingLogic'
+import { convertLargeNumberToWords, getProration } from './billing-utils'
import { billingProductLogic } from './billingProductLogic'
import { UnsubscribeSurveyModal } from './UnsubscribeSurveyModal'
diff --git a/frontend/src/scenes/billing/PlatformAddonComparison.test.tsx b/frontend/src/scenes/billing/PlatformAddonComparison.test.tsx
index 45130b9521bb..ba040028d1b4 100644
--- a/frontend/src/scenes/billing/PlatformAddonComparison.test.tsx
+++ b/frontend/src/scenes/billing/PlatformAddonComparison.test.tsx
@@ -5,13 +5,14 @@ import { cleanup, render } from '@testing-library/react'
import { Provider } from 'kea'
import { expectLogic } from 'kea-test-utils'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+
import { billingJson } from '~/mocks/fixtures/_billing'
import { makeBillingWithPlatformAddons } from '~/mocks/fixtures/_billing_platform_addons'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { BillingProductV2Type } from '~/types'
-import { billingLogic } from './billingLogic'
import { PlatformAddonComparison } from './PlatformAddonComparison'
describe('PlatformAddonComparison', () => {
diff --git a/frontend/src/scenes/billing/PlatformAddonComparison.tsx b/frontend/src/scenes/billing/PlatformAddonComparison.tsx
index 249c31ae533b..73e0c1a3543e 100644
--- a/frontend/src/scenes/billing/PlatformAddonComparison.tsx
+++ b/frontend/src/scenes/billing/PlatformAddonComparison.tsx
@@ -21,12 +21,12 @@ import { UNSUBSCRIBE_SURVEY_ID } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { More } from 'lib/lemon-ui/LemonButton/More'
import { LemonCollapse } from 'lib/lemon-ui/LemonCollapse'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { humanFriendlyCurrency } from 'lib/utils/numbers'
import { toSentenceCase } from 'lib/utils/strings'
import { BillingFeatureType, BillingPlan, BillingProductV2AddonType, BillingProductV2Type } from '~/types'
-import { billingLogic } from './billingLogic'
import { BillingProductAddonActions } from './BillingProductAddonActions'
import { billingProductLogic } from './billingProductLogic'
import { UnsubscribeSurveyModal } from './UnsubscribeSurveyModal'
diff --git a/frontend/src/scenes/billing/PurchaseCreditsModal.tsx b/frontend/src/scenes/billing/PurchaseCreditsModal.tsx
index 3793e6a42acd..ed14e21854b0 100644
--- a/frontend/src/scenes/billing/PurchaseCreditsModal.tsx
+++ b/frontend/src/scenes/billing/PurchaseCreditsModal.tsx
@@ -7,9 +7,9 @@ import { LemonButton, LemonDivider, LemonInput, LemonModal, LemonTable, Link } f
import { supportLogic } from 'lib/components/Support/supportLogic'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonRadio } from 'lib/lemon-ui/LemonRadio'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { BillingGauge } from './BillingGauge'
-import { billingLogic } from './billingLogic'
import { BillingGaugeItemKind } from './types'
function floatDiscountToText(discount: number): string {
diff --git a/frontend/src/scenes/billing/StripePortalButton.test.tsx b/frontend/src/scenes/billing/StripePortalButton.test.tsx
index f7003c4b6222..b9b02b14dc8d 100644
--- a/frontend/src/scenes/billing/StripePortalButton.test.tsx
+++ b/frontend/src/scenes/billing/StripePortalButton.test.tsx
@@ -5,12 +5,13 @@ import { cleanup, render, screen } from '@testing-library/react'
import { Provider } from 'kea'
import { expectLogic } from 'kea-test-utils'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+
import { billingJson } from '~/mocks/fixtures/_billing'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { BillingProvider, BillingType } from '~/types'
-import { billingLogic } from './billingLogic'
import { StripePortalButton } from './StripePortalButton'
const EXTERNAL_INVOICES_URL = 'https://vercel.com/example-team/~/integrations/posthog/icfg_example/invoices'
diff --git a/frontend/src/scenes/billing/StripePortalButton.tsx b/frontend/src/scenes/billing/StripePortalButton.tsx
index bdd733117f7b..1c1996cb192c 100644
--- a/frontend/src/scenes/billing/StripePortalButton.tsx
+++ b/frontend/src/scenes/billing/StripePortalButton.tsx
@@ -2,7 +2,7 @@ import { useValues } from 'kea'
import { LemonButton } from '@posthog/lemon-ui'
-import { billingLogic } from './billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
export const StripePortalButton = (): JSX.Element | null => {
const { billing, isExternallyBilled, isBillingManagedByPartner } = useValues(billingLogic)
diff --git a/frontend/src/scenes/billing/UnsubscribeSurveyModal.tsx b/frontend/src/scenes/billing/UnsubscribeSurveyModal.tsx
index 3150f757547f..09590e4c5855 100644
--- a/frontend/src/scenes/billing/UnsubscribeSurveyModal.tsx
+++ b/frontend/src/scenes/billing/UnsubscribeSurveyModal.tsx
@@ -20,14 +20,14 @@ import {
import { pngHoggie } from 'lib/brand/hoggies'
import { useHogfetti } from 'lib/components/Hogfetti/Hogfetti'
import { supportLogic } from 'lib/components/Support/supportLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+import { billingProductDisplayName } from 'lib/logic/billing/billingProductDisplayName'
import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'
import { humanFriendlyCurrency } from 'lib/utils/numbers'
import { BillingProductV2AddonType, BillingProductV2Type } from '~/types'
import { AddonFeatureLossNotice } from './AddonFeatureLossNotice'
-import { billingLogic } from './billingLogic'
-import { billingProductDisplayName } from './billingProductDisplayName'
import {
UNSUBSCRIBE_REASONS,
billingProductLogic,
diff --git a/frontend/src/scenes/billing/billing-utils.spec.ts b/frontend/src/scenes/billing/billing-utils.spec.ts
index 6976c01a9541..bbf3bc67d16c 100644
--- a/frontend/src/scenes/billing/billing-utils.spec.ts
+++ b/frontend/src/scenes/billing/billing-utils.spec.ts
@@ -1,32 +1,19 @@
import tk from 'timekeeper'
-import { FEATURE_FLAGS, OrganizationMembershipLevel } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
-import type { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
import { billingJson } from '~/mocks/fixtures/_billing'
import billingJsonWithFlatFee from '~/mocks/fixtures/_billing_with_flat_fee.json'
import type { BillingProductV2Type } from '~/types'
import {
- buildUsageLimitApproachingMessage,
- buildUsageLimitReachedMessage,
- canAccessBilling,
- canViewUsageAndSpend,
convertAmountToUsage,
convertLargeNumberToWords,
convertUsageToAmount,
formatDisplayUsage,
- formatProductNames,
formatTierPrice,
formatWithDecimals,
- getMinimumBillingAccessLevel,
- getMinimumUsageSpendReadAccessLevel,
getProration,
- getUsageLimitConsequence,
- isMemberUsageSpendReadAccessEnabled,
- isUsageApproachingLimit,
- isUsageAtOrOverLimit,
projectUsage,
summarizeUsage,
selectionCoversEveryProject,
@@ -45,23 +32,6 @@ describe('summarizeUsage', () => {
})
})
-describe('usage limit thresholds', () => {
- it('treats exactly 100% usage as at the limit', () => {
- expect(isUsageAtOrOverLimit(null)).toBe(false)
- expect(isUsageAtOrOverLimit(undefined)).toBe(false)
- expect(isUsageAtOrOverLimit(0.99)).toBe(false)
- expect(isUsageAtOrOverLimit(1)).toBe(true)
- expect(isUsageAtOrOverLimit(1.01)).toBe(true)
- })
-
- it('only treats usage below 100% as approaching the limit', () => {
- expect(isUsageApproachingLimit(0.8, 0.8)).toBe(false)
- expect(isUsageApproachingLimit(0.81, 0.8)).toBe(true)
- expect(isUsageApproachingLimit(1, 0.8)).toBe(false)
- expect(isUsageApproachingLimit(1.01, 0.8)).toBe(false)
- })
-})
-
describe('projectUsage', () => {
beforeEach(() => {
tk.freeze(new Date('2022-01-01'))
@@ -453,333 +423,6 @@ describe('formatDisplayUsage', () => {
})
})
-describe('formatProductNames', () => {
- it('should return empty string for empty array', () => {
- expect(formatProductNames([])).toEqual('')
- })
-
- it('should return single product name as-is', () => {
- expect(formatProductNames(['Session replay'])).toEqual('Session replay')
- })
-
- it('should join two products with "and"', () => {
- expect(formatProductNames(['Session replay', 'Feature flags & Experiments'])).toEqual(
- 'Session replay and Feature flags & Experiments'
- )
- })
-
- it('should join three or more products with commas and "and"', () => {
- expect(formatProductNames(['Product analytics', 'Session replay', 'Feature flags & Experiments'])).toEqual(
- 'Product analytics, Session replay and Feature flags & Experiments'
- )
- })
-})
-
-describe('getUsageLimitConsequence', () => {
- it.each(['Data warehouse', 'Sources'])('should return the sync consequence for %s', (name) => {
- expect(getUsageLimitConsequence(name)).toEqual('data will not be synced')
- })
-
- it('should return specific message for Feature flags & Experiments', () => {
- expect(getUsageLimitConsequence('Feature flags & Experiments')).toEqual('feature flags will not evaluate')
- })
-
- it('should return specific message for PostHog AI', () => {
- expect(getUsageLimitConsequence('PostHog AI')).toEqual('PostHog AI will be unavailable')
- })
-
- it('should return specific message for the self-driving inbox', () => {
- expect(getUsageLimitConsequence('Self-driving inbox')).toEqual('self-driving agents will be paused')
- })
-
- it('should return generic message for other products', () => {
- expect(getUsageLimitConsequence('Session replay')).toEqual('data loss may occur')
- expect(getUsageLimitConsequence('Product analytics')).toEqual('data loss may occur')
- expect(getUsageLimitConsequence('Surveys')).toEqual('data loss may occur')
- })
-})
-
-describe('buildUsageLimitReachedMessage', () => {
- it('should return empty strings for empty array', () => {
- expect(buildUsageLimitReachedMessage([])).toEqual({ title: '', message: '' })
- })
-
- it('should build message for single subscribed product', () => {
- const result = buildUsageLimitReachedMessage([{ name: 'Session replay', subscribed: true }])
- expect(result.title).toEqual('Usage limit reached')
- expect(result.message).toEqual(
- 'You have reached the usage limit for Session replay. Please increase your billing limit or data loss may occur.'
- )
- })
-
- it('should build message for single unsubscribed product', () => {
- const result = buildUsageLimitReachedMessage([{ name: 'Session replay', subscribed: false }])
- expect(result.message).toContain('upgrade your plan')
- })
-
- it.each(['Data warehouse', 'Sources'])('should explain stopped syncing for %s at its usage limit', (name) => {
- const result = buildUsageLimitReachedMessage([{ type: 'data_warehouse', name, subscribed: true }])
- expect(result.message).toEqual(
- `You have reached the usage limit for ${name}. Please increase your billing limit or data will not be synced.`
- )
- })
-
- it('should build message for multiple products with unique consequences', () => {
- const result = buildUsageLimitReachedMessage([
- { name: 'Session replay', subscribed: true },
- { name: 'Feature flags & Experiments', subscribed: true },
- ])
- expect(result.title).toEqual('Usage limits reached')
- expect(result.message).toEqual(
- 'You have reached the usage limit for Session replay and Feature flags & Experiments. Please increase your billing limit or data loss may occur and feature flags will not evaluate.'
- )
- })
-
- it('should build message for PostHog AI with specific consequence', () => {
- const result = buildUsageLimitReachedMessage([{ name: 'PostHog AI', subscribed: true }])
- expect(result.title).toEqual('Usage limit reached')
- expect(result.message).toEqual(
- 'You have reached the usage limit for PostHog AI. Please increase your billing limit or PostHog AI will be unavailable.'
- )
- })
-
- it('should name the self-driving inbox by its app name, not its billing name', () => {
- const result = buildUsageLimitReachedMessage([{ type: 'inbox', name: 'Inbox', subscribed: true }])
- expect(result.title).toEqual('Usage limit reached')
- expect(result.message).toEqual(
- 'You have reached the usage limit for Self-driving inbox. Please increase your billing limit or self-driving agents will be paused.'
- )
- })
-
- it('should build message for PostHog AI with other products', () => {
- const result = buildUsageLimitReachedMessage([
- { name: 'PostHog AI', subscribed: true },
- { name: 'Session replay', subscribed: true },
- ])
- expect(result.title).toEqual('Usage limits reached')
- expect(result.message).toEqual(
- 'You have reached the usage limit for PostHog AI and Session replay. Please increase your billing limit or PostHog AI will be unavailable and data loss may occur.'
- )
- })
-
- it('should deduplicate consequences for products with same consequence', () => {
- const result = buildUsageLimitReachedMessage([
- { name: 'Session replay', subscribed: true },
- { name: 'Product analytics', subscribed: true },
- ])
- expect(result.message).toEqual(
- 'You have reached the usage limit for Session replay and Product analytics. Please increase your billing limit or data loss may occur.'
- )
- })
-
- it('should use upgrade message when any product is not subscribed', () => {
- const result = buildUsageLimitReachedMessage([
- { name: 'Session replay', subscribed: true },
- { name: 'Feature flags & Experiments', subscribed: false },
- ])
- expect(result.message).toContain('upgrade your plan')
- })
-
- it.each([
- {
- hasBillingAccess: true,
- subscribed: true,
- expected: 'increase your billing limit',
- },
- {
- hasBillingAccess: true,
- subscribed: false,
- expected: 'upgrade your plan',
- },
- {
- hasBillingAccess: false,
- subscribed: true,
- expected: 'ask an organization admin to increase the billing limit',
- },
- {
- hasBillingAccess: false,
- subscribed: false,
- expected: 'ask an organization admin to upgrade the plan',
- },
- ])(
- 'should use "$expected" when hasBillingAccess=$hasBillingAccess and subscribed=$subscribed',
- ({ hasBillingAccess, subscribed, expected }) => {
- const result = buildUsageLimitReachedMessage([{ name: 'Session replay', subscribed }], hasBillingAccess)
- expect(result.message).toContain(expected)
- }
- )
-
- it('should say "owner" when minimumBillingAccessLevel is Owner and user has no billing access', () => {
- const result = buildUsageLimitReachedMessage(
- [{ name: 'Session replay', subscribed: true }],
- false,
- OrganizationMembershipLevel.Owner
- )
- expect(result.message).toContain('ask an organization owner')
- })
-
- it('should default to admin message when hasBillingAccess is not provided', () => {
- const result = buildUsageLimitReachedMessage([{ name: 'Session replay', subscribed: true }])
- expect(result.message).toContain('increase your billing limit')
- })
-})
-
-describe('buildUsageLimitApproachingMessage', () => {
- it('should return empty strings for empty array', () => {
- expect(buildUsageLimitApproachingMessage([])).toEqual({ title: '', message: '' })
- })
-
- it('should build message for single product', () => {
- const result = buildUsageLimitApproachingMessage([
- { name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' },
- ])
- expect(result.title).toEqual('You will soon hit your usage limit')
- expect(result.message).toEqual('You have currently used 90% of your Session replay allocation.')
- })
-
- it('should build message for multiple products', () => {
- const result = buildUsageLimitApproachingMessage([
- { name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' },
- { name: 'Feature flags & Experiments', percentage_usage: 0.87, usage_key: 'feature_flag_requests' },
- ])
- expect(result.title).toEqual('You will soon hit your usage limits')
- expect(result.message).toEqual(
- 'You are approaching your usage limits: 90% of your Session replay allocation, 87% of your Feature flags & Experiments allocation.'
- )
- })
-
- it.each([
- { name: 'Session replay', usage_key: undefined, expected: 'Session replay allocation' },
- { name: '', usage_key: 'signals_credits', expected: 'signals_credits allocation' },
- { name: '', usage_key: undefined, expected: 'usage allocation' },
- ])('should resolve label to "$expected" (name="$name", usage_key=$usage_key)', ({ name, usage_key, expected }) => {
- const result = buildUsageLimitApproachingMessage([{ name, percentage_usage: 0.9, usage_key }])
- expect(result.message).toContain(expected)
- })
-
- it('should format percentage with up to 2 decimal places', () => {
- const result = buildUsageLimitApproachingMessage([
- { name: 'Session replay', percentage_usage: 0.8567, usage_key: 'recordings' },
- ])
- expect(result.message).toContain('85.67%')
- })
-
- it.each([
- {
- hasBillingAccess: true,
- expectedSuffix: false,
- },
- {
- hasBillingAccess: false,
- expectedSuffix: true,
- },
- ])(
- 'should include admin contact message when hasBillingAccess=$hasBillingAccess',
- ({ hasBillingAccess, expectedSuffix }) => {
- const result = buildUsageLimitApproachingMessage(
- [{ name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' }],
- hasBillingAccess
- )
- if (expectedSuffix) {
- expect(result.message).toContain('Please ask an organization admin to increase the billing limit.')
- } else {
- expect(result.message).not.toContain('organization admin')
- }
- }
- )
-
- it('should say "owner" when minimumBillingAccessLevel is Owner and user has no billing access', () => {
- const result = buildUsageLimitApproachingMessage(
- [{ name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' }],
- false,
- OrganizationMembershipLevel.Owner
- )
- expect(result.message).toContain('ask an organization owner')
- })
-
- it('should default to no admin suffix when hasBillingAccess is not provided', () => {
- const result = buildUsageLimitApproachingMessage([
- { name: 'Session replay', percentage_usage: 0.9, usage_key: 'recordings' },
- ])
- expect(result.message).not.toContain('organization admin')
- })
-})
-
-describe('getMinimumBillingAccessLevel', () => {
- it('returns Admin when ownerOnlyBilling is false', () => {
- expect(getMinimumBillingAccessLevel(false)).toBe(OrganizationMembershipLevel.Admin)
- })
-
- it('returns Owner when ownerOnlyBilling is true', () => {
- expect(getMinimumBillingAccessLevel(true)).toBe(OrganizationMembershipLevel.Owner)
- })
-})
-
-describe('canAccessBilling', () => {
- it.each([
- { level: OrganizationMembershipLevel.Owner, ownerOnly: false, expected: true },
- { level: OrganizationMembershipLevel.Owner, ownerOnly: true, expected: true },
- { level: OrganizationMembershipLevel.Admin, ownerOnly: false, expected: true },
- { level: OrganizationMembershipLevel.Admin, ownerOnly: true, expected: false },
- { level: OrganizationMembershipLevel.Member, ownerOnly: false, expected: false },
- { level: OrganizationMembershipLevel.Member, ownerOnly: true, expected: false },
- { level: null, ownerOnly: false, expected: false },
- { level: null, ownerOnly: true, expected: false },
- ])('returns $expected for level=$level, ownerOnly=$ownerOnly', ({ level, ownerOnly, expected }) => {
- expect(canAccessBilling(level, ownerOnly)).toBe(expected)
- })
-})
-
-describe('getMinimumUsageSpendReadAccessLevel', () => {
- it.each([
- { memberAccess: false, ownerOnly: false, expected: OrganizationMembershipLevel.Admin },
- { memberAccess: true, ownerOnly: false, expected: OrganizationMembershipLevel.Member },
- { memberAccess: false, ownerOnly: true, expected: OrganizationMembershipLevel.Owner },
- // owner-only-billing wins over member-billing-usage-spend-read-access
- { memberAccess: true, ownerOnly: true, expected: OrganizationMembershipLevel.Owner },
- ])(
- 'returns $expected for memberAccess=$memberAccess, ownerOnly=$ownerOnly',
- ({ memberAccess, ownerOnly, expected }) => {
- expect(getMinimumUsageSpendReadAccessLevel(memberAccess, ownerOnly)).toBe(expected)
- }
- )
-})
-
-describe('canViewUsageAndSpend', () => {
- it.each([
- { level: OrganizationMembershipLevel.Member, memberAccess: true, ownerOnly: false, expected: true },
- { level: OrganizationMembershipLevel.Member, memberAccess: true, ownerOnly: true, expected: false },
- { level: OrganizationMembershipLevel.Member, memberAccess: false, ownerOnly: false, expected: false },
- { level: OrganizationMembershipLevel.Admin, memberAccess: false, ownerOnly: false, expected: true },
- { level: OrganizationMembershipLevel.Admin, memberAccess: true, ownerOnly: true, expected: false },
- { level: OrganizationMembershipLevel.Owner, memberAccess: false, ownerOnly: true, expected: true },
- { level: null, memberAccess: true, ownerOnly: false, expected: false },
- ])(
- 'returns $expected for level=$level, memberAccess=$memberAccess, ownerOnly=$ownerOnly',
- ({ level, memberAccess, ownerOnly, expected }) => {
- expect(canViewUsageAndSpend(level, memberAccess, ownerOnly)).toBe(expected)
- }
- )
-})
-
-describe('isMemberUsageSpendReadAccessEnabled', () => {
- it.each<{ case: string; featureFlags: FeatureFlagsSet; expected: boolean }>([
- {
- case: 'the grant is on',
- featureFlags: { [FEATURE_FLAGS.MEMBER_BILLING_USAGE_SPEND_READ_ACCESS]: true },
- expected: true,
- },
- {
- case: 'the grant is off',
- featureFlags: { [FEATURE_FLAGS.MEMBER_BILLING_USAGE_SPEND_READ_ACCESS]: false },
- expected: false,
- },
- { case: 'the flag is not present', featureFlags: {}, expected: false },
- ])('returns $expected when $case', ({ featureFlags, expected }) => {
- expect(isMemberUsageSpendReadAccessEnabled(featureFlags)).toBe(expected)
- })
-})
-
describe('selectionCoversEveryProject', () => {
const options = [{ key: '1' }, { key: '2' }, { key: '3' }]
diff --git a/frontend/src/scenes/billing/billing-utils.ts b/frontend/src/scenes/billing/billing-utils.ts
index 4a4fe0890dfb..7b5af62dca54 100644
--- a/frontend/src/scenes/billing/billing-utils.ts
+++ b/frontend/src/scenes/billing/billing-utils.ts
@@ -2,18 +2,15 @@ import { deepEqual as equal } from 'fast-equals'
import { LogicWrapper } from 'kea'
import { routerType } from 'kea-router/lib/routerType'
-import { FEATURE_FLAGS, OrganizationMembershipLevel } from 'lib/constants'
+import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
-import type { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
import { dateStringToDayJs } from 'lib/utils/dateFilters'
import { compactNumber } from 'lib/utils/numbers'
-import { membershipLevelToName } from 'lib/utils/permissioning'
-import { capitalizeFirstLetter, wordPluralize } from 'lib/utils/strings'
+import { wordPluralize } from 'lib/utils/strings'
import { Params } from 'scenes/sceneTypes'
import { BillingPeriod, BillingProductV2AddonType, BillingProductV2Type, BillingTierType, BillingType } from '~/types'
-import { billingProductDisplayName } from './billingProductDisplayName'
import { SPEND_TYPES, USAGE_TYPES } from './constants'
import type { BillingFilters, BillingUsageInteractionProps } from './types'
import { BillingGaugeItemKind, BillingGaugeItemType } from './types'
@@ -53,19 +50,6 @@ export const isBillingLimitShown = (product: BillingProductV2Type, billing: Bill
!product.inclusion_only &&
canHaveBillingLimit(product)
-export const isCompanionProduct = (product: BillingProductV2Type): boolean => !!product.companion_of
-
-// After the parent leaves a priced plan, billing keeps the companion on its plan with `subscribed: false`,
-// and it still bills.
-export const isCompanionHeld = (product: BillingProductV2Type): boolean =>
- !!product.subscribed || !!product.plans?.some((plan) => plan.current_plan)
-
-export const getHeldCompanions = (
- products: BillingProductV2Type[] | null | undefined,
- parentType: string
-): BillingProductV2Type[] =>
- products?.filter((product) => product.companion_of === parentType && isCompanionHeld(product)) ?? []
-
export const createGaugeItems = (
product: BillingProductV2Type | BillingProductV2AddonType,
options: {
@@ -122,14 +106,6 @@ export const summarizeUsage = (usage: number | null): string => {
return compactNumber(usage)
}
-export const isUsageAtOrOverLimit = (percentageUsage: number | null | undefined): boolean => {
- return (percentageUsage ?? 0) >= 1
-}
-
-export const isUsageApproachingLimit = (percentageUsage: number | null | undefined, threshold: number): boolean => {
- return (percentageUsage ?? 0) > threshold && !isUsageAtOrOverLimit(percentageUsage)
-}
-
/**
* Check if a product has display formatting configured.
*/
@@ -464,57 +440,6 @@ export const currencyFormatter = (value: number): string => {
}).format(value)
}
-/**
- * Returns the minimum membership level required to access billing.
- * When ownerOnlyBilling is true (via the owner-only-billing feature flag), only org owners can access billing.
- */
-export function getMinimumBillingAccessLevel(ownerOnlyBilling: boolean): OrganizationMembershipLevel {
- return ownerOnlyBilling ? OrganizationMembershipLevel.Owner : OrganizationMembershipLevel.Admin
-}
-
-/**
- * Determines if the user has sufficient permissions to access billing based on their org membership level.
- */
-export function canAccessBilling(membershipLevel: number | null | undefined, ownerOnlyBilling: boolean): boolean {
- if (!membershipLevel) {
- return false
- }
- return membershipLevel >= getMinimumBillingAccessLevel(ownerOnlyBilling)
-}
-
-/** Whether the member-level read grant for usage and spend is in effect. */
-export function isMemberUsageSpendReadAccessEnabled(featureFlags: FeatureFlagsSet): boolean {
- return !!featureFlags[FEATURE_FLAGS.MEMBER_BILLING_USAGE_SPEND_READ_ACCESS]
-}
-
-/**
- * Returns the minimum membership level required for read-only access to the billing usage/spend tabs.
- * The member-billing-usage-spend-read-access feature flag lowers it to Member, but owner-only-billing takes precedence.
- */
-export function getMinimumUsageSpendReadAccessLevel(
- memberUsageSpendReadAccess: boolean,
- ownerOnlyBilling: boolean
-): OrganizationMembershipLevel {
- if (ownerOnlyBilling) {
- return OrganizationMembershipLevel.Owner
- }
- return memberUsageSpendReadAccess ? OrganizationMembershipLevel.Member : OrganizationMembershipLevel.Admin
-}
-
-/**
- * Determines if the user can view the read-only billing usage/spend tabs based on their org membership level.
- */
-export function canViewUsageAndSpend(
- membershipLevel: number | null | undefined,
- memberUsageSpendReadAccess: boolean,
- ownerOnlyBilling: boolean
-): boolean {
- if (!membershipLevel) {
- return false
- }
- return membershipLevel >= getMinimumUsageSpendReadAccessLevel(memberUsageSpendReadAccess, ownerOnlyBilling)
-}
-
/**
* Synchronizes URL search parameters with billing filter state.
* Returns the appropriate router action format for kea-router.
@@ -685,124 +610,6 @@ export const formatTierPrice = (
return `$${formatWithDecimals(price)}`
}
-/**
- * Build a human-readable list of product names (e.g., "A, B and C")
- */
-export function formatProductNames(names: string[]): string {
- if (names.length === 0) {
- return ''
- }
- if (names.length === 1) {
- return names[0]
- }
- return names.slice(0, -1).join(', ') + ' and ' + names[names.length - 1]
-}
-
-/**
- * Get the consequence message for a product when it reaches its usage limit
- */
-export function getUsageLimitConsequence(productName: string): string {
- if (productName === 'Data warehouse' || productName === 'Sources') {
- return 'data will not be synced'
- }
- if (productName === 'Feature flags & Experiments') {
- return 'feature flags will not evaluate'
- }
- if (productName === 'PostHog AI') {
- return 'PostHog AI will be unavailable'
- }
- if (productName === 'Self-driving inbox') {
- return 'self-driving agents will be paused'
- }
- return 'data loss may occur'
-}
-
-/**
- * Build a consolidated message for products that have reached their usage limits
- */
-export function buildUsageLimitReachedMessage(
- products: Array<{ type?: string | null; name: string; subscribed: boolean | null }>,
- hasBillingAccess: boolean = true,
- minimumBillingAccessLevel: OrganizationMembershipLevel = OrganizationMembershipLevel.Admin,
- selfServeBillingNotice: string | null = null
-): {
- title: string
- message: string
-} {
- if (products.length === 0) {
- return { title: '', message: '' }
- }
-
- const productNames = products.map(billingProductDisplayName)
- const allSubscribed = products.every((p) => p.subscribed === true)
-
- // Build consequence message, deduplicating common consequences
- const consequences = [...new Set(productNames.map(getUsageLimitConsequence))]
-
- const productListText = formatProductNames(productNames)
- const consequenceText = consequences.join(' and ')
- const title = products.length === 1 ? 'Usage limit reached' : 'Usage limits reached'
-
- if (selfServeBillingNotice && !allSubscribed) {
- return {
- title,
- message: `You have reached the usage limit for ${productListText}. ${capitalizeFirstLetter(consequenceText)}. ${selfServeBillingNotice}`,
- }
- }
-
- let actionText: string
- if (hasBillingAccess) {
- actionText = allSubscribed ? 'increase your billing limit' : 'upgrade your plan'
- } else {
- const roleName = membershipLevelToName.get(minimumBillingAccessLevel)
- actionText = allSubscribed
- ? `ask an organization ${roleName} to increase the billing limit`
- : `ask an organization ${roleName} to upgrade the plan`
- }
-
- return {
- title,
- message: `You have reached the usage limit for ${productListText}. Please ${actionText} or ${consequenceText}.`,
- }
-}
-
-/**
- * Build a consolidated message for products approaching their usage limits
- */
-export function buildUsageLimitApproachingMessage(
- products: Array<{
- type?: string | null
- name: string
- percentage_usage: number
- usage_key?: string | null
- }>,
- hasBillingAccess: boolean = true,
- minimumBillingAccessLevel: OrganizationMembershipLevel = OrganizationMembershipLevel.Admin
-): { title: string; message: string } {
- if (products.length === 0) {
- return { title: '', message: '' }
- }
-
- const usageDetails = products.map((p) => {
- const percentage = parseFloat((p.percentage_usage * 100).toFixed(2))
- const productName = (p.name && billingProductDisplayName(p)) || p.usage_key?.toLowerCase() || 'usage'
- return `${percentage}% of your ${productName} allocation`
- })
-
- const roleName = membershipLevelToName.get(minimumBillingAccessLevel)
- const adminSuffix = hasBillingAccess ? '' : ` Please ask an organization ${roleName} to increase the billing limit.`
-
- const message =
- products.length === 1
- ? `You have currently used ${usageDetails[0]}.${adminSuffix}`
- : `You are approaching your usage limits: ${usageDetails.join(', ')}.${adminSuffix}`
-
- return {
- title: products.length === 1 ? 'You will soon hit your usage limit' : 'You will soon hit your usage limits',
- message,
- }
-}
-
/**
* Whether a project selection covers every project there is, in which case it is not a filter.
*
diff --git a/frontend/src/scenes/billing/billingProductLogic.test.ts b/frontend/src/scenes/billing/billingProductLogic.test.ts
index 89372835e14f..ef5a5a411433 100644
--- a/frontend/src/scenes/billing/billingProductLogic.test.ts
+++ b/frontend/src/scenes/billing/billingProductLogic.test.ts
@@ -9,7 +9,7 @@ import { dayjs } from 'lib/dayjs'
// replaces `.error` on the same `lemonToast` singleton the logic calls at runtime (see the same
// note in paymentEntryLogic.test.ts).
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { billingProductLogic } from 'scenes/billing/billingProductLogic'
import { paymentEntryLogic } from 'scenes/billing/paymentEntryLogic'
import { organizationLogic } from 'scenes/organizationLogic'
diff --git a/frontend/src/scenes/billing/billingProductLogic.ts b/frontend/src/scenes/billing/billingProductLogic.ts
index d1fb100cfe26..d3b1394aadb9 100644
--- a/frontend/src/scenes/billing/billingProductLogic.ts
+++ b/frontend/src/scenes/billing/billingProductLogic.ts
@@ -9,6 +9,10 @@ import { LemonDialog, lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
import type { FeatureFlagKey } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+import type { BillingAlertConfig, SwitchPlanPayload, UnsubscribeError } from 'lib/logic/billing/billingLogic'
+import { billingProductRowDisplayName } from 'lib/logic/billing/billingProductDisplayName'
+import { getHeldCompanions } from 'lib/logic/billing/companionProducts'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import {
@@ -26,15 +30,11 @@ import {
calculateFreeTier,
canHaveBillingLimit,
createGaugeItems,
- getHeldCompanions,
isAddonVisible,
isProductVariantPrimary,
} from './billing-utils'
import { getBillingLimitConfig } from './billingLimitConfig'
import type { BillingLimitConfig } from './billingLimitConfig'
-import { billingLogic } from './billingLogic'
-import type { BillingAlertConfig, SwitchPlanPayload, UnsubscribeError } from './billingLogic'
-import { billingProductRowDisplayName } from './billingProductDisplayName'
import { DATA_PIPELINES_CUTOFF_DATE } from './constants'
import { paymentEntryLogic } from './paymentEntryLogic'
import { BillingGaugeItemKind, BillingGaugeItemType } from './types'
diff --git a/frontend/src/scenes/billing/billingSpendLogic.test.ts b/frontend/src/scenes/billing/billingSpendLogic.test.ts
index 25af2cc813be..bd9132e479a1 100644
--- a/frontend/src/scenes/billing/billingSpendLogic.test.ts
+++ b/frontend/src/scenes/billing/billingSpendLogic.test.ts
@@ -3,9 +3,9 @@ import { expectLogic } from 'kea-test-utils'
import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { dateMapping } from 'lib/utils/dateFilters'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { urls } from 'scenes/urls'
import { billingJson } from '~/mocks/fixtures/_billing'
diff --git a/frontend/src/scenes/billing/billingSpendLogic.ts b/frontend/src/scenes/billing/billingSpendLogic.ts
index f6286d544b43..eac238817f22 100644
--- a/frontend/src/scenes/billing/billingSpendLogic.ts
+++ b/frontend/src/scenes/billing/billingSpendLogic.ts
@@ -9,6 +9,7 @@ import sortBy from 'lodash.sortby'
import { lemonToast } from '@posthog/lemon-ui'
import { dayjs } from 'lib/dayjs'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { dateMapping } from 'lib/utils/dateFilters'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
@@ -31,7 +32,6 @@ import {
syncBillingSearchParams,
updateBillingSearchParams,
} from './billing-utils'
-import { billingLogic } from './billingLogic'
import type { BillingPeriodMarker } from './BillingPeriodMarkers'
import { BillingReads, billingReadsLogic } from './billingReads'
import {
diff --git a/frontend/src/scenes/billing/billingUsageLogic.test.ts b/frontend/src/scenes/billing/billingUsageLogic.test.ts
index c7e4bda3b085..a3b68354f81c 100644
--- a/frontend/src/scenes/billing/billingUsageLogic.test.ts
+++ b/frontend/src/scenes/billing/billingUsageLogic.test.ts
@@ -4,8 +4,8 @@ import { expectLogic } from 'kea-test-utils'
import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { urls } from 'scenes/urls'
import { billingJson } from '~/mocks/fixtures/_billing'
diff --git a/frontend/src/scenes/billing/billingUsageLogic.ts b/frontend/src/scenes/billing/billingUsageLogic.ts
index b89b0bda36e2..ddd07bd8889f 100644
--- a/frontend/src/scenes/billing/billingUsageLogic.ts
+++ b/frontend/src/scenes/billing/billingUsageLogic.ts
@@ -9,6 +9,7 @@ import sortBy from 'lodash.sortby'
import { lemonToast } from '@posthog/lemon-ui'
import { dayjs } from 'lib/dayjs'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { dateMapping } from 'lib/utils/dateFilters'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
@@ -30,7 +31,6 @@ import {
syncBillingSearchParams,
updateBillingSearchParams,
} from './billing-utils'
-import { billingLogic } from './billingLogic'
import type { BillingPeriodMarker } from './BillingPeriodMarkers'
import { BillingReads, billingReadsLogic } from './billingReads'
import { DEFAULT_TOP_PROJECTS } from './constants'
diff --git a/frontend/src/scenes/billing/paymentEntryLogic.test.ts b/frontend/src/scenes/billing/paymentEntryLogic.test.ts
index 09fc79534b86..50308e7a203c 100644
--- a/frontend/src/scenes/billing/paymentEntryLogic.test.ts
+++ b/frontend/src/scenes/billing/paymentEntryLogic.test.ts
@@ -10,7 +10,7 @@ import posthog from 'posthog-js'
// calls at runtime. `jest.mock('@posthog/lemon-ui', ...)` did not propagate through the
// barrel's re-export chain — spying on the shared object avoids that issue.
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { paymentEntryLogic } from 'scenes/billing/paymentEntryLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/src/scenes/billing/paymentEntryLogic.ts b/frontend/src/scenes/billing/paymentEntryLogic.ts
index f5c0a2f42aa9..864df3534b25 100644
--- a/frontend/src/scenes/billing/paymentEntryLogic.ts
+++ b/frontend/src/scenes/billing/paymentEntryLogic.ts
@@ -7,6 +7,7 @@ import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
import { FEATURE_FLAGS } from 'lib/constants'
+import { billingLogic, parseBillingResponse } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { urls } from 'scenes/urls'
@@ -25,7 +26,6 @@ import {
import type { BillingActivationRequestApi } from 'products/billing/frontend/generated/api.schemas'
import { retrieve as retrieveOrganization } from 'products/platform_features/frontend/generated/api'
-import { billingLogic, parseBillingResponse } from './billingLogic'
import { billingProductLogic } from './billingProductLogic'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
diff --git a/frontend/src/scenes/coupons/CouponRedemption.tsx b/frontend/src/scenes/coupons/CouponRedemption.tsx
index 258a268baf62..2b9316272e44 100644
--- a/frontend/src/scenes/coupons/CouponRedemption.tsx
+++ b/frontend/src/scenes/coupons/CouponRedemption.tsx
@@ -9,7 +9,7 @@ import { NotFound } from 'lib/components/NotFound'
import { dayjs } from 'lib/dayjs'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { LemonField } from 'lib/lemon-ui/LemonField'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { billingProductLogic } from 'scenes/billing/billingProductLogic'
import { paymentEntryLogic } from 'scenes/billing/paymentEntryLogic'
import { urls } from 'scenes/urls'
diff --git a/frontend/src/scenes/coupons/couponLogic.ts b/frontend/src/scenes/coupons/couponLogic.ts
index 537461ec6faa..aa5a5c9fa9ce 100644
--- a/frontend/src/scenes/coupons/couponLogic.ts
+++ b/frontend/src/scenes/coupons/couponLogic.ts
@@ -7,7 +7,7 @@ import posthog from 'posthog-js'
import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/src/scenes/experiments/SharedMetrics/sharedMetricLogic.tsx b/frontend/src/scenes/experiments/SharedMetrics/sharedMetricLogic.tsx
index 5d20ee8ee87b..d499e21335ec 100644
--- a/frontend/src/scenes/experiments/SharedMetrics/sharedMetricLogic.tsx
+++ b/frontend/src/scenes/experiments/SharedMetrics/sharedMetricLogic.tsx
@@ -5,9 +5,9 @@ import { router, urlToAction } from 'kea-router'
import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { sceneConfigurations } from 'scenes/scenes'
import { Scene } from 'scenes/sceneTypes'
import { teamLogic } from 'scenes/teamLogic'
diff --git a/frontend/src/scenes/max/TicketPrompt.tsx b/frontend/src/scenes/max/TicketPrompt.tsx
index f95f43583c55..47c26e105a24 100644
--- a/frontend/src/scenes/max/TicketPrompt.tsx
+++ b/frontend/src/scenes/max/TicketPrompt.tsx
@@ -5,7 +5,7 @@ import { LemonButton, LemonInput, LemonModal, lemonToast } from '@posthog/lemon-
import { SupportForm } from 'lib/components/Support/SupportForm'
import { supportLogic } from 'lib/components/Support/supportLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { userLogic } from 'scenes/userLogic'
import { maxThreadLogic } from './maxThreadLogic'
diff --git a/frontend/src/scenes/max/maxBillingContextLogic.tsx b/frontend/src/scenes/max/maxBillingContextLogic.tsx
index e6c48df01b78..a53cf36a69ff 100644
--- a/frontend/src/scenes/max/maxBillingContextLogic.tsx
+++ b/frontend/src/scenes/max/maxBillingContextLogic.tsx
@@ -2,9 +2,10 @@ import { MakeLogicType, connect, kea, path, selectors } from 'kea'
import { objectsEqual } from 'kea-test-utils'
import { dayjs } from 'lib/dayjs'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
+import { isUsageAtOrOverLimit } from 'lib/logic/billing/usageLimits'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-import { isAddonVisible, isUsageAtOrOverLimit } from 'scenes/billing/billing-utils'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { isAddonVisible } from 'scenes/billing/billing-utils'
import { BillingSpendResponse, billingSpendLogic } from 'scenes/billing/billingSpendLogic'
import { BillingUsageResponse, billingUsageLogic } from 'scenes/billing/billingUsageLogic'
import { hogFunctionsListLogic } from 'scenes/hog-functions/list/hogFunctionsListLogic'
diff --git a/frontend/src/scenes/max/maxThreadLogic.tsx b/frontend/src/scenes/max/maxThreadLogic.tsx
index 3ca9870a2e1c..a881dfb72126 100644
--- a/frontend/src/scenes/max/maxThreadLogic.tsx
+++ b/frontend/src/scenes/max/maxThreadLogic.tsx
@@ -24,10 +24,10 @@ import { JSONContent } from 'lib/components/RichContentEditor/types'
import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { uuid } from 'lib/utils/dom'
import { objectsEqual } from 'lib/utils/objects'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { maxContextLogic } from 'scenes/max/maxContextLogic'
import { NotebookTarget } from 'scenes/notebooks/types'
import { organizationLogic } from 'scenes/organizationLogic'
diff --git a/frontend/src/scenes/onboarding/OnboardingFlowHost.tsx b/frontend/src/scenes/onboarding/OnboardingFlowHost.tsx
index c98c4ea9166b..fbbe734428be 100644
--- a/frontend/src/scenes/onboarding/OnboardingFlowHost.tsx
+++ b/frontend/src/scenes/onboarding/OnboardingFlowHost.tsx
@@ -4,7 +4,7 @@ import { useEffect } from 'react'
import { LemonBanner, Link, Spinner } from '@posthog/lemon-ui'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
diff --git a/frontend/src/scenes/onboarding/billing/FreeTierLimits.tsx b/frontend/src/scenes/onboarding/billing/FreeTierLimits.tsx
index afc76b83b511..3be995cb4eb7 100644
--- a/frontend/src/scenes/onboarding/billing/FreeTierLimits.tsx
+++ b/frontend/src/scenes/onboarding/billing/FreeTierLimits.tsx
@@ -1,6 +1,6 @@
import { useValues } from 'kea'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { availableOnboardingProducts, getProductIcon } from 'scenes/onboarding/shared/utils'
type FreeTierLimit = {
diff --git a/frontend/src/scenes/onboarding/billing/OnboardingUpgradeStep.tsx b/frontend/src/scenes/onboarding/billing/OnboardingUpgradeStep.tsx
index c04a08415481..19909c9ab28d 100644
--- a/frontend/src/scenes/onboarding/billing/OnboardingUpgradeStep.tsx
+++ b/frontend/src/scenes/onboarding/billing/OnboardingUpgradeStep.tsx
@@ -7,7 +7,7 @@ import { LemonButton, Spinner } from '@posthog/lemon-ui'
import { pngHoggie } from 'lib/brand/hoggies'
import { useHogfetti } from 'lib/components/Hogfetti/Hogfetti'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { PlatformAddonComparison } from 'scenes/billing/PlatformAddonComparison'
import { reportOnboardingStepCompleted, reportOnboardingStepSkipped } from 'scenes/onboarding/onboardingUsage'
diff --git a/frontend/src/scenes/onboarding/billing/PlanCards.tsx b/frontend/src/scenes/onboarding/billing/PlanCards.tsx
index e6c34a7b670d..15751b40cce0 100644
--- a/frontend/src/scenes/onboarding/billing/PlanCards.tsx
+++ b/frontend/src/scenes/onboarding/billing/PlanCards.tsx
@@ -10,8 +10,8 @@ import { LemonButton } from '@posthog/lemon-ui'
import { pngHoggie } from 'lib/brand/hoggies'
import { BillingUpgradeCTA } from 'lib/components/BillingUpgradeCTA'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { pluralize } from 'lib/utils/strings'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { billingProductLogic } from 'scenes/billing/billingProductLogic'
import { paymentEntryLogic } from 'scenes/billing/paymentEntryLogic'
import { reportOnboardingStepCompleted } from 'scenes/onboarding/onboardingUsage'
diff --git a/frontend/src/scenes/onboarding/onboardingLogic.tsx b/frontend/src/scenes/onboarding/onboardingLogic.tsx
index 726e49fcd9dc..4c7e4ad95184 100644
--- a/frontend/src/scenes/onboarding/onboardingLogic.tsx
+++ b/frontend/src/scenes/onboarding/onboardingLogic.tsx
@@ -7,12 +7,12 @@ import { lemonToast } from '@posthog/lemon-ui'
import { type SetupTaskId } from 'lib/components/ProductSetup'
import { globalSetupLogic } from 'lib/components/ProductSetup/globalSetupLogic'
import { OrganizationMembershipLevel } from 'lib/constants'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { isKeyOf } from 'lib/utils/guards'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { getRelativeNextPath } from 'lib/utils/url'
-import { billingLogic } from 'scenes/billing/billingLogic'
import {
reportOnboardingCompleted,
reportOnboardingStarted,
diff --git a/frontend/src/scenes/session-recordings/filters/ProductAnalyticsOverLimitBanner.tsx b/frontend/src/scenes/session-recordings/filters/ProductAnalyticsOverLimitBanner.tsx
index df5f6d29270d..69bc5fb54392 100644
--- a/frontend/src/scenes/session-recordings/filters/ProductAnalyticsOverLimitBanner.tsx
+++ b/frontend/src/scenes/session-recordings/filters/ProductAnalyticsOverLimitBanner.tsx
@@ -3,7 +3,7 @@ import { useValues } from 'kea'
import { LemonBanner, Link } from '@posthog/lemon-ui'
import { PostHogCaptureOnViewed } from '@posthog/react'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { urls } from 'scenes/urls'
import { ProductKey } from '~/queries/schema/schema-general'
diff --git a/frontend/src/scenes/settings/settingsLogic.ts b/frontend/src/scenes/settings/settingsLogic.ts
index 44d2d420a691..dd5f9f19bc44 100644
--- a/frontend/src/scenes/settings/settingsLogic.ts
+++ b/frontend/src/scenes/settings/settingsLogic.ts
@@ -4,10 +4,10 @@ import { actionToUrl, router, urlToAction } from 'kea-router'
import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { createFuse } from 'lib/utils/fuseSearch'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import type { Params } from 'scenes/sceneTypes'
import { organizationIntegrationsLogic } from 'scenes/settings/organization/organizationIntegrationsLogic'
diff --git a/frontend/src/scenes/startups/StartupProgram.test.tsx b/frontend/src/scenes/startups/StartupProgram.test.tsx
index fdb427c76396..dc031fd7f179 100644
--- a/frontend/src/scenes/startups/StartupProgram.test.tsx
+++ b/frontend/src/scenes/startups/StartupProgram.test.tsx
@@ -5,7 +5,7 @@ import { cleanup, render, screen, within } from '@testing-library/react'
import { BindLogic } from 'kea'
import { expectLogic } from 'kea-test-utils'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { billingJson } from '~/mocks/fixtures/_billing'
import { useMocks } from '~/mocks/jest'
diff --git a/frontend/src/scenes/startups/StartupProgram.tsx b/frontend/src/scenes/startups/StartupProgram.tsx
index a559bf6e91bf..979d452e19e8 100644
--- a/frontend/src/scenes/startups/StartupProgram.tsx
+++ b/frontend/src/scenes/startups/StartupProgram.tsx
@@ -33,8 +33,8 @@ import {
import { pngHoggie } from 'lib/brand/hoggies'
import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { billingProductLogic } from 'scenes/billing/billingProductLogic'
import { paymentEntryLogic } from 'scenes/billing/paymentEntryLogic'
import { SceneExport } from 'scenes/sceneTypes'
diff --git a/frontend/src/scenes/startups/startupProgramLogic.test.ts b/frontend/src/scenes/startups/startupProgramLogic.test.ts
index 041a371bfda9..ea4ddddcae81 100644
--- a/frontend/src/scenes/startups/startupProgramLogic.test.ts
+++ b/frontend/src/scenes/startups/startupProgramLogic.test.ts
@@ -5,7 +5,7 @@ import { expectLogic } from 'kea-test-utils'
import posthog from 'posthog-js'
import { OrganizationMembershipLevel } from 'lib/constants'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { userLogic } from 'scenes/userLogic'
import { billingJson } from '~/mocks/fixtures/_billing'
diff --git a/frontend/src/scenes/startups/startupProgramLogic.ts b/frontend/src/scenes/startups/startupProgramLogic.ts
index a855009035e2..a89d40076890 100644
--- a/frontend/src/scenes/startups/startupProgramLogic.ts
+++ b/frontend/src/scenes/startups/startupProgramLogic.ts
@@ -8,7 +8,7 @@ import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
import { Dayjs, dayjs } from 'lib/dayjs'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { userLogic } from 'scenes/userLogic'
diff --git a/frontend/toolbar-config.mjs b/frontend/toolbar-config.mjs
index 46f9704734ca..57fb5ae85949 100644
--- a/frontend/toolbar-config.mjs
+++ b/frontend/toolbar-config.mjs
@@ -51,9 +51,9 @@ const deniedPaths = [
'scenes/session-recordings/player/snapshot-processing/DecompressionWorkerManager.ts',
]
-// PayGateMini (shipped in the toolbar) imports scenes/billing, which we can't bundle because it
-// pulls in chart.js, monaco, and the rest of the app's billing scene graph.
-const deniedPatterns = [/scenes\/billing/]
+// PayGateMini (shipped in the toolbar) imports billingLogic, which we can't bundle because it
+// pulls in app-only logics and, through scenes/billing, the app's billing scene graph.
+const deniedPatterns = [/scenes\/billing/, /lib\/logic\/billing\//]
/**
* The toolbar shares lib/ code with the main app, and that code reaches app-only modules
@@ -66,7 +66,7 @@ const deniedPatterns = [/scenes\/billing/]
* the toolbar genuinely needs different answers (its own team context, no scene routing)
* than the app.
* - Denied modules get replaced with an inert proxy. The deny list is kept minimal: only the
- * paths a toolbar-shipped module actually reaches today (chiefly PayGateMini -> scenes/billing)
+ * paths a toolbar-shipped module actually reaches today (chiefly PayGateMini -> billingLogic)
* need cutting here. Regressions that reintroduce heavier dependencies are caught by the guard
* scripts rather than pre-emptively denied.
*
diff --git a/products/billing_alerts/frontend/billingAlertFormLogic.ts b/products/billing_alerts/frontend/billingAlertFormLogic.ts
index b33b451699df..45cb8586fca6 100644
--- a/products/billing_alerts/frontend/billingAlertFormLogic.ts
+++ b/products/billing_alerts/frontend/billingAlertFormLogic.ts
@@ -5,7 +5,7 @@ import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from
import { lemonToast } from '@posthog/lemon-ui'
import { ApiError } from 'lib/api'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import type { OrganizationType } from '~/types'
diff --git a/products/billing_alerts/frontend/billingAlertHistoryLogic.ts b/products/billing_alerts/frontend/billingAlertHistoryLogic.ts
index f3699a7d37f7..f4ce40910c06 100644
--- a/products/billing_alerts/frontend/billingAlertHistoryLogic.ts
+++ b/products/billing_alerts/frontend/billingAlertHistoryLogic.ts
@@ -1,7 +1,7 @@
import { MakeLogicType, afterMount, connect, kea, key, path, props, selectors } from 'kea'
import { loaders } from 'kea-loaders'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import type { OrganizationType } from '~/types'
diff --git a/products/billing_alerts/frontend/billingAlertNotificationLogic.ts b/products/billing_alerts/frontend/billingAlertNotificationLogic.ts
index 181c607f6592..aaf19dc82ef3 100644
--- a/products/billing_alerts/frontend/billingAlertNotificationLogic.ts
+++ b/products/billing_alerts/frontend/billingAlertNotificationLogic.ts
@@ -3,8 +3,8 @@ import { MakeLogicType, actions, connect, kea, key, listeners, path, props, redu
import { lemonToast } from '@posthog/lemon-ui'
import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { isHttpsUrl } from 'lib/utils/url'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { teamLogic } from 'scenes/teamLogic'
import type { IntegrationType, OrganizationType } from '~/types'
diff --git a/products/billing_alerts/frontend/billingAlertsLogic.test.ts b/products/billing_alerts/frontend/billingAlertsLogic.test.ts
index 4bd6f6fa7473..75479e2c1761 100644
--- a/products/billing_alerts/frontend/billingAlertsLogic.test.ts
+++ b/products/billing_alerts/frontend/billingAlertsLogic.test.ts
@@ -1,7 +1,7 @@
import { LemonDialog } from '@posthog/lemon-ui'
import { OrganizationMembershipLevel } from 'lib/constants'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { initKeaTests } from '~/test/init'
diff --git a/products/billing_alerts/frontend/billingAlertsLogic.ts b/products/billing_alerts/frontend/billingAlertsLogic.ts
index b803406d14d7..9319870f75eb 100644
--- a/products/billing_alerts/frontend/billingAlertsLogic.ts
+++ b/products/billing_alerts/frontend/billingAlertsLogic.ts
@@ -3,7 +3,7 @@ import { loaders } from 'kea-loaders'
import { LemonDialog, lemonToast } from '@posthog/lemon-ui'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import type { OrganizationType } from '~/types'
diff --git a/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.test.ts b/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.test.ts
index 8a824ac2e85b..d958b9aac6e0 100644
--- a/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.test.ts
+++ b/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.test.ts
@@ -4,8 +4,8 @@ import posthog from 'posthog-js'
import { CONVERSATIONS_MESSAGE_MAX_LENGTH, supportLogic } from 'lib/components/Support/supportLogic'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { urls } from 'scenes/urls'
diff --git a/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts b/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts
index 6d7e9bcf7620..66dd15f6f9c1 100644
--- a/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts
+++ b/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts
@@ -26,9 +26,9 @@ import {
warnSupportWidgetUnavailable,
} from 'lib/components/Support/supportLogic'
import { EMAIL_SUPPORT_BUTTON, lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
diff --git a/products/legal_documents/frontend/scenes/legalDocumentsLogic.test.ts b/products/legal_documents/frontend/scenes/legalDocumentsLogic.test.ts
index d2b164d444d3..ae01904c4efc 100644
--- a/products/legal_documents/frontend/scenes/legalDocumentsLogic.test.ts
+++ b/products/legal_documents/frontend/scenes/legalDocumentsLogic.test.ts
@@ -2,7 +2,7 @@ import { MOCK_DEFAULT_USER } from 'lib/api.mock'
import { expectLogic } from 'kea-test-utils'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { userLogic } from 'scenes/userLogic'
import { billingJson } from '~/mocks/fixtures/_billing'
diff --git a/products/legal_documents/frontend/scenes/legalDocumentsLogic.ts b/products/legal_documents/frontend/scenes/legalDocumentsLogic.ts
index 7a45d261f754..fc7efc3c4f24 100644
--- a/products/legal_documents/frontend/scenes/legalDocumentsLogic.ts
+++ b/products/legal_documents/frontend/scenes/legalDocumentsLogic.ts
@@ -6,7 +6,7 @@ import { router, urlToAction } from 'kea-router'
import { ApiError } from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
diff --git a/products/replay_vision/frontend/components/IngestionLimitBanner.tsx b/products/replay_vision/frontend/components/IngestionLimitBanner.tsx
index 52cf36cbcdb4..a32edbafd4fd 100644
--- a/products/replay_vision/frontend/components/IngestionLimitBanner.tsx
+++ b/products/replay_vision/frontend/components/IngestionLimitBanner.tsx
@@ -2,7 +2,7 @@ import { useMountedLogic, useValues } from 'kea'
import { LemonBanner, Link } from '@posthog/lemon-ui'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { urls } from 'scenes/urls'
import { ProductKey } from '~/queries/schema/schema-general'
diff --git a/products/replay_vision/frontend/logics/visionQuotaLogic.test.ts b/products/replay_vision/frontend/logics/visionQuotaLogic.test.ts
index 144c59f0bb19..6ab45815288a 100644
--- a/products/replay_vision/frontend/logics/visionQuotaLogic.test.ts
+++ b/products/replay_vision/frontend/logics/visionQuotaLogic.test.ts
@@ -1,6 +1,6 @@
import { expectLogic } from 'kea-test-utils'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
diff --git a/products/replay_vision/frontend/logics/visionQuotaLogic.ts b/products/replay_vision/frontend/logics/visionQuotaLogic.ts
index 7414dda85edd..e55f68af2bd9 100644
--- a/products/replay_vision/frontend/logics/visionQuotaLogic.ts
+++ b/products/replay_vision/frontend/logics/visionQuotaLogic.ts
@@ -1,7 +1,7 @@
import { MakeLogicType, actions, afterMount, connect, kea, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
-import { billingLogic } from 'scenes/billing/billingLogic'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { teamLogic } from 'scenes/teamLogic'
import type { BillingType } from '~/types'
diff --git a/products/signals/frontend/inbox/logics/inboxUsageLogic.ts b/products/signals/frontend/inbox/logics/inboxUsageLogic.ts
index fb6016da7896..2fcfc6dde8a7 100644
--- a/products/signals/frontend/inbox/logics/inboxUsageLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxUsageLogic.ts
@@ -7,10 +7,10 @@ import { subscriptions } from 'kea-subscriptions'
import { ApiError } from 'lib/api-error'
import { FEATURE_FLAGS } from 'lib/constants'
import { Dayjs } from 'lib/dayjs'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import type { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
import { getBillingLimitConfig } from 'scenes/billing/billingLimitConfig'
-import { billingLogic } from 'scenes/billing/billingLogic'
import {
INBOX_PRODUCT_TYPE,
creditsPerPr as deriveCreditsPerPr,
diff --git a/products/workflows/frontend/Workflows/Reputation/workflowsReputationLogic.test.ts b/products/workflows/frontend/Workflows/Reputation/workflowsReputationLogic.test.ts
index 2cf68f9247e4..ab2823cd479c 100644
--- a/products/workflows/frontend/Workflows/Reputation/workflowsReputationLogic.test.ts
+++ b/products/workflows/frontend/Workflows/Reputation/workflowsReputationLogic.test.ts
@@ -2,8 +2,8 @@ import { expectLogic } from 'kea-test-utils'
import { supportLogic } from 'lib/components/Support/supportLogic'
import { FEATURE_FLAGS } from 'lib/constants'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
diff --git a/products/workflows/frontend/Workflows/Reputation/workflowsReputationLogic.ts b/products/workflows/frontend/Workflows/Reputation/workflowsReputationLogic.ts
index 220ac4006c28..6bd5ace070f0 100644
--- a/products/workflows/frontend/Workflows/Reputation/workflowsReputationLogic.ts
+++ b/products/workflows/frontend/Workflows/Reputation/workflowsReputationLogic.ts
@@ -4,9 +4,9 @@ import posthog from 'posthog-js'
import { type SupportFormFields, supportLogic } from 'lib/components/Support/supportLogic'
import { FEATURE_FLAGS } from 'lib/constants'
+import { billingLogic } from 'lib/logic/billing/billingLogic'
import { type FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { humanFriendlyNumber, percentage } from 'lib/utils/numbers'
-import { billingLogic } from 'scenes/billing/billingLogic'
import { canCreateSupportTicket } from 'scenes/max/ticketUtils'
import { organizationLogic } from 'scenes/organizationLogic'
import { projectLogic } from 'scenes/projectLogic'