Skip to content

Commit c1399de

Browse files
feat(api): add charges list api http handler
1 parent 5d00754 commit c1399de

File tree

100 files changed

+2649
-692
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2649
-692
lines changed

.agents/skills/charges/SKILL.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Primary packages:
3232

3333
`openmeter/billing/charges` is the root facade for charge operations.
3434

35+
Charge-backed invoicing no longer relies on a charges-side `InvoicePendingLines(...)` wrapper. Billing owns invoice creation and dispatches gathering lines by `billing.LineEngineType`, while charge packages provide charge-specific line engines where needed.
36+
3537
Important layers:
3638

3739
- `charges.Service`
@@ -70,6 +72,34 @@ Important types:
7072
- `MeterValue`
7173
- `Totals`
7274

75+
## Billing Line Engines
76+
77+
Charge-backed gathering lines must carry the correct billing line engine when they are created.
78+
79+
Current engine values:
80+
81+
- `billing.LineEngineTypeChargeFlatFee`
82+
- `billing.LineEngineTypeChargeUsageBased`
83+
- `billing.LineEngineTypeChargeCreditPurchase`
84+
85+
Current implementations:
86+
87+
- flat fee line engine: `openmeter/billing/charges/flatfee/lineengine`
88+
- credit purchase line engine: `openmeter/billing/charges/creditpurchase/lineengine`
89+
90+
Important rules:
91+
92+
- do not rely on billing to infer a charge-backed engine from `ChargeID`
93+
- `billing/service.CreatePendingInvoiceLines(...)` rejects charge-backed gathering lines with empty `Engine`
94+
- production wiring must register charge line engines through `billing.Service.RegisterLineEngine(...)`
95+
- charge test setups must also register those engines explicitly; keep this in `openmeter/billing/charges/testutils`
96+
- if a charge create path stamps a new `LineEngineType`, app wiring and charge test wiring must register a matching implementation in the same change
97+
98+
Operational consequence:
99+
100+
- adding a new charge engine enum without a registered implementation causes invoice collection to fail when billing resolves the line engine
101+
- a schema migration defaulting old persisted rows to `invoicing` is not enough for charge-backed lines; existing persisted gathering lines may need a backfill if they should route to a charge engine after rollout
102+
73103
## Timestamp Normalization
74104

75105
Charge persistence assumes timestamp precision is bounded by streaming aggregation precision.
@@ -159,6 +189,11 @@ Placement guidance:
159189

160190
This means a newly created credit-only charge (usage-based or flat fee) that is eligible for immediate activation will be returned as `active` (or `final`) from `Create(...)` itself.
161191

192+
For invoice-settled charges:
193+
194+
- flat fee and credit purchase creation now stamp the gathering line engine in their type-specific `Create(...)` flows
195+
- usage-based charge creation also stamps `LineEngineTypeChargeUsageBased`; do not introduce this discriminator unless a corresponding billing engine exists or the path is intentionally blocked
196+
162197
## Root Charges Advance Flow
163198

164199
The root-facade advance flow is:

api/v3/handlers/charges/convert.gen.go

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)