feat(charges): support custom currency credits-only charges#4769
Conversation
📝 WalkthroughWalkthroughDetailed-line currency is deprecated in models, mappings, validation, and rating. Parent invoice lines now supply currency to output and persistence paths. Promotional and credit-only charges accept custom currencies, with expanded end-to-end tests. ChangesDetailed-line currency deprecation
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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
`@tools/migrate/migrations/20260721140844_deprecate_detailed_line_currency.down.sql`:
- Around line 1-6: Make the down migration rollback-safe by handling existing
NULL currency values before restoring NOT NULL on the detailed-line tables.
Backfill each table’s NULL currency from its corresponding parent line or
charge, or add a clear preflight that aborts with recovery guidance, then
regenerate the migration using Atlas.
🪄 Autofix (Beta)
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
Run ID: 9f619195-ebd4-4769-99c9-98afbda2888d
⛔ Files ignored due to path filters (20)
openmeter/ent/db/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerundetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerundetailedline/chargeflatfeerundetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerundetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerundetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerundetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrundetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrundetailedline/chargeusagebasedrundetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrundetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrundetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrundetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (32)
openmeter/billing/adapter/stdinvoicelinemapper.goopenmeter/billing/adapter/stdinvoicelines.goopenmeter/billing/charges/creditpurchase/service/create.goopenmeter/billing/charges/flatfee/adapter/detailedline_test.goopenmeter/billing/charges/flatfee/service/create.goopenmeter/billing/charges/service/base_test.goopenmeter/billing/charges/service/creditpurchase_test.goopenmeter/billing/charges/service/handlers_test.goopenmeter/billing/charges/service/invoicable_test.goopenmeter/billing/charges/usagebased/adapter/detailedline_test.goopenmeter/billing/charges/usagebased/detailedline.goopenmeter/billing/charges/usagebased/service/create.goopenmeter/billing/charges/usagebased/service/linemapper_test.goopenmeter/billing/charges/usagebased/service/rating/delta/engine.goopenmeter/billing/charges/usagebased/service/rating/delta/engine_test.goopenmeter/billing/charges/usagebased/service/rating/periodpreserving/engine.goopenmeter/billing/charges/usagebased/service/rating/service_test.goopenmeter/billing/charges/usagebased/service/rating/subtract/subtract.goopenmeter/billing/charges/usagebased/service/rating/subtract/subtract_test.goopenmeter/billing/httpdriver/invoiceline.goopenmeter/billing/invoicedetailedline_test.goopenmeter/billing/models/stddetailedline/create.goopenmeter/billing/models/stddetailedline/derived.gen.goopenmeter/billing/models/stddetailedline/mapping.goopenmeter/billing/models/stddetailedline/mixin.goopenmeter/billing/models/stddetailedline/model.goopenmeter/billing/service/invoicecalc/details.goopenmeter/billing/stdinvoiceline.goopenmeter/billing/stdinvoiceline_test.gotest/billing/adapter_test.gotools/migrate/migrations/20260721140844_deprecate_detailed_line_currency.down.sqltools/migrate/migrations/20260721140844_deprecate_detailed_line_currency.up.sql
💤 Files with no reviewable changes (20)
- openmeter/billing/models/stddetailedline/derived.gen.go
- openmeter/billing/stdinvoiceline.go
- openmeter/billing/models/stddetailedline/mapping.go
- openmeter/billing/charges/usagebased/service/rating/delta/engine.go
- openmeter/billing/invoicedetailedline_test.go
- openmeter/billing/models/stddetailedline/create.go
- openmeter/billing/charges/usagebased/adapter/detailedline_test.go
- openmeter/billing/charges/usagebased/service/linemapper_test.go
- openmeter/billing/charges/usagebased/service/rating/subtract/subtract.go
- openmeter/billing/stdinvoiceline_test.go
- openmeter/billing/charges/usagebased/service/rating/delta/engine_test.go
- openmeter/billing/charges/flatfee/adapter/detailedline_test.go
- openmeter/billing/adapter/stdinvoicelinemapper.go
- test/billing/adapter_test.go
- openmeter/billing/models/stddetailedline/model.go
- openmeter/billing/charges/usagebased/service/rating/periodpreserving/engine.go
- openmeter/billing/charges/usagebased/service/rating/service_test.go
- openmeter/billing/service/invoicecalc/details.go
- openmeter/billing/charges/usagebased/service/rating/subtract/subtract_test.go
- openmeter/billing/charges/usagebased/detailedline.go
Summary
credits_onlycharges to use custom currenciesWhy
Custom currencies are supported by charges after #4755, but create-time validation still rejected the promotional and credits-only flows. These flows should be accepted by the charge lifecycle while the ledger integration remains responsible for rejecting unsupported custom-currency operations.
Detailed-line currency duplicated the parent charge or invoice currency and its three-character database type prevented valid custom currencies from being persisted. Detailed lines now derive currency context from their parent instead.
Testing
go test -tags=dynamic -count=1 ./openmeter/billing/charges/servicego test -count=1 ./tools/migratego test -tags=dynamic -run '^$' ./...Stack
Depends on #4755.
Summary by CodeRabbit
Greptile Summary
This PR adds custom-currency support to selected credit charge flows. The main changes are:
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (3): Last reviewed commit: "style: satisfy linter" | Re-trigger Greptile
Context used: