Repository navigation
feat(api): expose booked and spendable credit balances - #5316
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Balance fields and timestamp semantics api/spec/packages/aip/src/customers/credits/*, api/spec/packages/aip-client-javascript/src/models/*, api/v3/client/models_customers.go, api/v3/api.gen.go, openmeter/ledger/customerbalance/README.md |
The balance contract defines booked and spendable values, documents settled as a deprecated alias, and clarifies transaction-history and historical timestamp semantics. |
FBO-backed balance calculation openmeter/ledger/customerbalance/*.go, app/common/customerbalance.go, cmd/server/wire_gen.go |
The service queries FBO spendable buckets, returns booked and spendable balances, and uses spendable sources for current live-balance calculations. Application wiring constructs and supplies the FBO service. |
API balance mapping api/v3/handlers/customers/credits/convert.go, api/v3/handlers/customers/credits/convert_test.go |
The API conversion populates booked and spendable values and maps settled to booked. Tests cover custom-currency and fiat balances, including a negative booked value. |
Balance tests and FBO test setup openmeter/ledger/customerbalance/*_test.go, openmeter/ledger/fbo/testutils/service.go, openmeter/billing/charges/service/customcurrency_ledger_integration_test.go, test/credits/* |
Tests use booked balances and cover spendable, live, pending, historical, and transaction-history results. Test setup now provides an FBO service. |
Priority:
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant BalanceFacade
participant CustomerBalanceService
participant AccountResolver
participant FBO
participant BalanceQuerier
BalanceFacade->>CustomerBalanceService: Request customer balance
CustomerBalanceService->>AccountResolver: Resolve customer accounts
CustomerBalanceService->>FBO: Query spendable buckets
FBO-->>CustomerBalanceService: Return buckets and routes
CustomerBalanceService->>BalanceQuerier: Read FBO and receivable balances
BalanceQuerier-->>CustomerBalanceService: Return balances
CustomerBalanceService-->>BalanceFacade: Return balance values
Suggested labels: area/billing
Suggested reviewers: turip, borosr
Merge Risk: 
Minimal · up to 08f0d
-
The change adds
bookedandspendablecredit balance fields to the API and keepssettledas a deprecated alias. The supplied generated-code changes show no concrete merge-blocking risk.
Pre-merge checks: 
4
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 @coderabbitai help to get the list of available commands.
d0a5c27 to
cb62a45
Compare
|
|
||
| // Read spendable credit once, then use the same amounts for the live projection. | ||
| // Advance debt is still a journal balance and can make the total negative. | ||
| func (s *service) getBalanceSources(ctx context.Context, input GetBalanceServiceInput) (balance, []liveBalanceSource, error) { |
There was a problem hiding this comment.
nit: this function can receive it's own return type instead of returning a half initialized balance struct.
5ccc8d2 to
a0deb40
Compare
a0deb40 to
08f0def
Compare
Overview
Expose booked and spendable credit balances separately.
bookedcontains the ledger balance at the requested timestamp, including credit-only advance debt. The existingsettledfield remains an identical deprecated alias.spendablepreserves credit allocated to later recorded usage and prevents future grants from being spent early.livenow applies unbooked usage impacts to spendable sources, preserving feature restrictions and settlement policy. Advance debt can make balances negative.Notes for reviewer
live; all balance reads use currently recorded postings.settledis marked deprecated in OpenAPI.bookedandsettled, including negative balances.Summary by CodeRabbit
New Features
Documentation


Confidence Score: 5/5
The PR appears safe to merge.Summary
Separates booked credit from credit still available to spend.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD FBO[FBO source histories] --> Minimum[Spendable source balances] Minimum --> Spendable[spendable] Debt[Booked advance debt] --> Spendable Journal[Booked FBO balance] --> Booked[booked] Debt --> Booked Booked --> Settled[settled alias] Spendable --> Live[live] Usage[Unbooked usage impacts] --> LiveReviews (5) · Last reviewed commit: "fix(test): wire FBO into billing balance..." · Reviewed by Greptile