Repository navigation
fix(billing): retain non-zero overage lines settled via credits - #4882
Conversation
📝 WalkthroughWalkthroughFlat-fee and usage-based credit-then-invoice flows now classify zero overage from converted fiat amounts. Invoice-line omission no longer depends on whether a fiat transaction is required. Conversion errors propagate through settlement and line-mapping paths. Tests and documentation cover the updated behavior. ChangesCustom-currency overage handling
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openmeter/billing/charges/flatfee/service/linemapper_test.go`:
- Around line 35-52: Add conversion-failure test coverage for
isZeroFiatAmountOverageRun and line deletion handling: in
openmeter/billing/charges/flatfee/service/linemapper_test.go:35-52 and
openmeter/billing/charges/usagebased/service/creditheninvoice_test.go:83-100,
assert conversion failure returns false; in
openmeter/billing/charges/flatfee/service/linemapper_test.go:85-131 and
openmeter/billing/charges/usagebased/service/linemapper_test.go:377-415, assert
the conversion error is exposed while the affected line remains undeleted.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9a31cbab-1887-4175-8f20-98f6d5c3d6f5
📒 Files selected for processing (6)
openmeter/billing/charges/README.mdopenmeter/billing/charges/flatfee/service/creditheninvoice.goopenmeter/billing/charges/flatfee/service/linemapper_test.goopenmeter/billing/charges/usagebased/service/creditheninvoice.goopenmeter/billing/charges/usagebased/service/creditheninvoice_test.goopenmeter/billing/charges/usagebased/service/linemapper_test.go
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openmeter/billing/charges/usagebased/service/linemapper_test.go (1)
372-435: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAssert the converted fiat amount.
The new cases only assert line deletion or retention. A mapper that produces an incorrect nonzero fiat amount still passes. Assert that the flat price and credit-purchase detailed-line fiat amount equal the expected converted value, such as
6for amount3at rate2.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/billing/charges/usagebased/service/linemapper_test.go` around lines 372 - 435, Extend the new subtests around populateStandardLineFromRun to assert the converted fiat amount on the flat-price and credit-purchase detailed lines, not only DeletedAt. For the positive converted overage, verify both detailed-line amounts equal the expected conversion (for example, 6 from amount 3 at rate 2), while preserving the existing deletion and error assertions.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@openmeter/billing/charges/usagebased/service/linemapper_test.go`:
- Around line 372-435: Extend the new subtests around
populateStandardLineFromRun to assert the converted fiat amount on the
flat-price and credit-purchase detailed lines, not only DeletedAt. For the
positive converted overage, verify both detailed-line amounts equal the expected
conversion (for example, 6 from amount 3 at rate 2), while preserving the
existing deletion and error assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: b80ba427-c3e8-46f4-8b78-e3b0ea2ff994
📒 Files selected for processing (10)
openmeter/billing/charges/flatfee/service/creditheninvoice.goopenmeter/billing/charges/flatfee/service/lineengine.goopenmeter/billing/charges/flatfee/service/linemapper.goopenmeter/billing/charges/flatfee/service/linemapper_test.goopenmeter/billing/charges/usagebased/service/creditheninvoice.goopenmeter/billing/charges/usagebased/service/creditheninvoice_test.goopenmeter/billing/charges/usagebased/service/lineengine.goopenmeter/billing/charges/usagebased/service/linemapper.goopenmeter/billing/charges/usagebased/service/linemapper_test.goopenmeter/billing/charges/usagebased/service/payments.go
🚧 Files skipped from review as they are similar to previous changes (3)
- openmeter/billing/charges/flatfee/service/linemapper_test.go
- openmeter/billing/charges/usagebased/service/creditheninvoice_test.go
- openmeter/billing/charges/flatfee/service/creditheninvoice.go
Summary
Retain invoice lines for non-zero custom-currency overage even when no fiat transaction is required. This supports overage that is settled via credits: the billable line remains available for invoice settlement while payment handling can still be skipped.
Root cause
Line omission was based on
NoFiatTransactionRequired, which describes payment handling rather than whether converted fiat overage is zero. As a result, non-zero overage settled via credits could be deleted from the invoice.Changes
Tracking
OM-435
Validation
make lint-go-fast(before test-only additions).git diff --check.Summary by CodeRabbit
Bug Fixes
Documentation
Greptile Summary
The PR separates invoice-line omission from payment handling so non-zero custom-currency overage remains invoiceable when credits eliminate the required fiat transaction.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD R[Realization run totals] --> C[Convert custom-currency overage to fiat] C --> Z{Converted fiat overage is zero?} Z -->|Yes| O[Omit invoice line and bypass invoice settlement] Z -->|No| K[Retain billable invoice line] K --> P{Fiat transaction required?} P -->|Yes| T[Process fiat payment] P -->|No| S[Skip payment handling]Reviews (3): Last reviewed commit: "test(billing): assert converted overage ..." | Re-trigger Greptile
Context used: