Repository navigation
fix(billing): settle a free payer's run after they subscribe mid-run #9498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { and, eq, sql } from 'drizzle-orm' | |
| import { BILLING_LOCK_TIMEOUT_MS, DEFAULT_OVERAGE_THRESHOLD } from '@/lib/billing/constants' | ||
| import { getEffectiveBillingStatus, isOrganizationBillingBlocked } from '@/lib/billing/core/access' | ||
| import { calculateSubscriptionOverage, computeOrgOverageAmount } from '@/lib/billing/core/billing' | ||
| import { isDefaultBillingPeriod } from '@/lib/billing/core/billing-period' | ||
| import type { HighestPrioritySubscription } from '@/lib/billing/core/plan' | ||
| import { | ||
| getHighestPriorityPersonalSubscription, | ||
|
|
@@ -216,6 +217,11 @@ export async function checkAndBillPayerOverageThreshold( | |
| billingEntity: BillingEntity, | ||
| options: ThresholdBillingOptions = {} | ||
| ): Promise<ThresholdSettlementOutcome | undefined> { | ||
| // Spend admitted without a subscription stays in the open period, which no subscription the | ||
| // payer gains later ever spans, so it has no threshold to settle. | ||
| if (options.expectedBillingPeriod && isDefaultBillingPeriod(options.expectedBillingPeriod)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This guard conflates an open period with having no subscription. A paid or entitled subscription with missing billing dates is serialized with the default period, so this line acknowledges the callback without resolving or settling its overage instead of raising the existing retryable Prompt for AI agents |
||
| return noOp(options, 'no-subscription') | ||
| } | ||
| if (billingEntity.type === 'organization') { | ||
| return checkAndBillOrganizationOverageThreshold(billingEntity.id, options) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDefaultBillingPeriodis a new exported API without TSDoc. The repository requires TSDoc for exported APIs, so this must be addressed before merging. Add a short comment explaining that it recognizes the open fallback period by its dates, without requiring asourcefield.Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!