@@ -48,6 +48,8 @@ import { buildUpgradeHref } from '@/lib/billing/upgrade-reasons'
4848import { getBaseUrl } from '@/lib/core/utils/urls'
4949import { AwsMarketplaceSubscriptionSection } from '@/app/workspace/[workspaceId]/settings/components/billing/components/aws-marketplace-subscription-section/aws-marketplace-subscription-section'
5050import { CreditUsageSection } from '@/app/workspace/[workspaceId]/settings/components/billing/components/credit-usage-section/credit-usage-section'
51+ import { EnterprisePaymentMethodRow } from '@/app/workspace/[workspaceId]/settings/components/billing/components/enterprise-payment-method-row/enterprise-payment-method-row'
52+ import { EnterpriseSeatsSection } from '@/app/workspace/[workspaceId]/settings/components/billing/components/enterprise-seats-section/enterprise-seats-section'
5153import { UsageLimitField } from '@/app/workspace/[workspaceId]/settings/components/billing/components/usage-limit-field/usage-limit-field'
5254import { getSubscriptionPermissions } from '@/app/workspace/[workspaceId]/settings/components/billing/subscription-permissions'
5355import { SettingsQueryErrorState } from '@/app/workspace/[workspaceId]/settings/components/settings-empty-state'
@@ -167,6 +169,9 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
167169 const openBillingPortal = useOpenBillingPortal ( )
168170
169171 const organizationBilling = organizationBillingData ?. data
172+ const enterpriseSelfServe = isOrganizationScope
173+ ? ( organizationBilling ?. enterpriseSelfServe ?? null )
174+ : null
170175 const upgradeWorkspaceId = isOrganizationScope
171176 ? organizationBilling ?. upgradeWorkspaceId
172177 : subscriptionData ?. data ?. upgradeWorkspaceId
@@ -296,6 +301,7 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
296301 isEnterprise : subscription . isEnterprise ,
297302 isPaid : subscription . isPaid ,
298303 isOrgScoped : subscription . isOrgScoped ,
304+ isEnterpriseSelfServe : enterpriseSelfServe !== null ,
299305 plan : subscription . plan || 'free' ,
300306 status : subscription . status || 'inactive' ,
301307 } ,
@@ -498,16 +504,19 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
498504
499505 const canManageBilling = permissions . canManageBilling
500506 const canExplorePlans = permissions . showUpgradePlans
501- const showUsageLimit = subscription . isPaid && ! subscription . isEnterprise
502- const showOnDemand = hasUsablePaidAccess && ! subscription . isEnterprise && ! isTrialing
507+ const hasEditableLimit = ! subscription . isEnterprise || enterpriseSelfServe !== null
508+ const showUsageLimit = subscription . isPaid && hasEditableLimit
509+ const showOnDemand = hasUsablePaidAccess && hasEditableLimit && ! isTrialing
503510
504511 const usageLimitCurrent =
505512 subscription . isOrgScoped && organizationBilling
506513 ? organizationBilling . totalUsageLimit
507514 : usage . limit
508515
509- const usageLimitMinimum =
510- subscription . isOrgScoped && organizationBilling
516+ // A self-serve Enterprise limit cannot fall below what the contract already covers.
517+ const usageLimitMinimum = enterpriseSelfServe
518+ ? covered
519+ : subscription . isOrgScoped && organizationBilling
511520 ? organizationBilling . minimumBillingAmount
512521 : getPlanTierDollars ( subscription . plan )
513522 const explorePlansLabel = isOrganizationScope
@@ -587,7 +596,7 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
587596 < Switch
588597 id = 'on-demand-usage'
589598 checked = { isOnDemandActive }
590- disabled = { isTogglingOnDemand || ! canManageBilling }
599+ disabled = { isTogglingOnDemand || ! permissions . canEditUsageLimit }
591600 onCheckedChange = { handleToggleOnDemand }
592601 />
593602 ) }
@@ -639,15 +648,22 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
639648 </ div >
640649 ) }
641650
642- < div className = 'flex items-center justify-between' >
643- < span className = 'text-[var(--text-body)] text-small' > Payment method</ span >
644- < Chip
645- disabled = { ! canManageBilling || openBillingPortal . isPending }
646- onClick = { handleOpenBillingPortal }
647- >
648- Manage in Stripe
649- </ Chip >
650- </ div >
651+ { enterpriseSelfServe && billingOrganizationId ? (
652+ < EnterprisePaymentMethodRow
653+ organizationId = { billingOrganizationId }
654+ canManage = { permissions . canManageEnterprisePayment }
655+ />
656+ ) : (
657+ < div className = 'flex items-center justify-between' >
658+ < span className = 'text-[var(--text-body)] text-small' > Payment method</ span >
659+ < Chip
660+ disabled = { ! canManageBilling || openBillingPortal . isPending }
661+ onClick = { handleOpenBillingPortal }
662+ >
663+ Manage in Stripe
664+ </ Chip >
665+ </ div >
666+ ) }
651667
652668 { ! subscription . isEnterprise && (
653669 < div className = 'flex items-center justify-between' >
@@ -677,6 +693,13 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
677693 </ SettingsSection >
678694 ) }
679695
696+ { enterpriseSelfServe && (
697+ < EnterpriseSeatsSection
698+ terms = { enterpriseSelfServe }
699+ billingInterval = { billingInterval ?? 'year' }
700+ />
701+ ) }
702+
680703 < AwsMarketplaceSubscriptionSection organizationId = { billingOrganizationId } />
681704 { isOrganizationScope && (
682705 < AwsMarketplaceSubscriptionSection
0 commit comments