MCPcopy Index your code
hub / github.com/simstudioai/sim / getSimplifiedBillingSummary

Function getSimplifiedBillingSummary

apps/sim/lib/billing/core/billing.ts:394–690  ·  view source on GitHub ↗
(
  userId: string,
  organizationId?: string,
  executor: DbClient = db
)

Source from the content-addressed store, hash-verified

392 * Get comprehensive billing and subscription summary
393 */
394export async function getSimplifiedBillingSummary(
395 userId: string,
396 organizationId?: string,
397 executor: DbClient = db
398): Promise<{
399 type: 'individual' | 'organization'
400 plan: string
401 currentUsage: number
402 usageLimit: number
403 percentUsed: number
404 isWarning: boolean
405 isExceeded: boolean
406 daysRemaining: number
407 creditBalance: number
408 billingInterval: 'month' | 'year'
409 // Subscription details
410 isPaid: boolean
411 isPro: boolean
412 isTeam: boolean
413 isEnterprise: boolean
414 /** True when the subscription's `referenceId` is an organization id. */
415 isOrgScoped: boolean
416 /** Present when `isOrgScoped` is true. */
417 organizationId: string | null
418 status: string | null
419 seats: number | null
420 metadata: any
421 stripeSubscriptionId: string | null
422 periodEnd: Date | string | null
423 cancelAtPeriodEnd?: boolean
424 // Usage details
425 usage: {
426 current: number
427 limit: number
428 percentUsed: number
429 isWarning: boolean
430 isExceeded: boolean
431 billingPeriodStart: Date | null
432 billingPeriodEnd: Date | null
433 lastPeriodCost: number
434 lastPeriodCopilotCost: number
435 daysRemaining: number
436 copilotCost: number
437 }
438}> {
439 try {
440 // Get subscription and usage data upfront
441 const [subscription, usageData] = await Promise.all([
442 organizationId
443 ? getOrganizationSubscription(organizationId, { executor })
444 : getHighestPrioritySubscription(userId, { executor }),
445 getUserUsageData(userId, executor),
446 ])
447
448 const plan = subscription?.plan || 'free'
449 const hasPaidEntitlement = hasPaidSubscriptionStatus(subscription?.status)
450 const planIsPaid = hasPaidEntitlement && isPaid(plan)
451 const planIsPro = hasPaidEntitlement && isPro(plan)

Callers 1

route.tsFile · 0.90

Calls 15

getUserUsageDataFunction · 0.90
isPaidFunction · 0.90
isProFunction · 0.90
isTeamFunction · 0.90
isEnterpriseFunction · 0.90
isOrgScopedSubscriptionFunction · 0.90
getPlanTierDollarsFunction · 0.90
getOrgUsageLimitFunction · 0.90

Tested by

no test coverage detected