fix(billing): exclude overdraft credits from credit overdraft balance#1502
fix(billing): exclude overdraft credits from credit overdraft balance#1502rohilsurana merged 2 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdded a balance query that excludes overdraft-source credits and wired it into invoice generation; extended credit transaction interfaces and mocks; implemented a Postgres repository method that sums debits and credits while excluding overdraft-source credits for a time range. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 09eb074a-1454-4a49-adb4-6b803cb518de
📒 Files selected for processing (1)
billing/invoice/service.go
Coverage Report for CI Build 24068983263Coverage decreased (-0.06%) to 41.147%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
1af73cd to
b64c958
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
internal/store/postgres/billing_transactions_repository.go (2)
534-536: Mark the transaction as read-only for this balance query.This method only reads; setting
ReadOnly: trueimproves intent and can reduce lock pressure.♻️ Proposed change
if err := r.dbc.WithTxn(ctx, sql.TxOptions{ Isolation: sql.LevelSerializable, + ReadOnly: true, }, func(tx *sqlx.Tx) error {
500-503: Consider an index strategy for the new filtered credit-sum path.This path is used for invoice generation; add/verify a supporting index for
(account_id, type, created_at, source)(or an equivalent partial index) to avoid full scans as transaction volume grows.Also applies to: 531-557
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a0d48227-bc12-483b-b696-3d57350eaf9a
📒 Files selected for processing (4)
billing/credit/mocks/transaction_repository.gobilling/credit/service.gobilling/invoice/service.gointernal/store/postgres/billing_transactions_repository.go
✅ Files skipped from review due to trivial changes (1)
- billing/credit/mocks/transaction_repository.go
🚧 Files skipped from review as they are similar to previous changes (1)
- billing/invoice/service.go
Before() is strict — when the previous invoice's start matches the customer's created_at exactly, startRange was never advanced past the previous invoice's end, preventing new invoices from being created for subsequent periods.
b64c958 to
6a4e978
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 57cb352f-5ea5-4cb4-b5a8-5128536835be
📒 Files selected for processing (4)
billing/credit/mocks/transaction_repository.gobilling/credit/service.gobilling/invoice/service.gointernal/store/postgres/billing_transactions_repository.go
🚧 Files skipped from review as they are similar to previous changes (2)
- billing/invoice/service.go
- billing/credit/mocks/transaction_repository.go
Follows up on #1498.
When a customer pays an overdraft invoice, reconciliation adds a
system.overdraftcredit transaction.GenerateForCreditsusesGetBalanceForRangeto check if a customer has negative balance — but the reconciliation credit inflates the balance, masking new usage that should be billed.Changes
GetBalanceForRangeWithoutOverdraftto the transaction repository, credit service, and invoice service — excludessystem.overdraftcredits from the balance sumGenerateForCreditsto callGetBalanceForRangeWithoutOverdraft