Repository navigation
feat(charges): add backend customer charge override set - #4888
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR adds customer charge override creation and replacement for flat-fee and usage-based charges. It validates mutable snapshots, preserves base intent, applies lifecycle-specific rerating, and rejects unsupported realization states. ChangesCustomer charge overrides
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Customer
participant CustomerChargeAPIService
participant ChargeStateMachine
participant ChargeState
Customer->>CustomerChargeAPIService: SetCustomerChargeOverride
CustomerChargeAPIService->>ChargeStateMachine: Apply set_override patch
ChargeStateMachine->>ChargeState: Rerate and reconcile charge
ChargeState-->>CustomerChargeAPIService: Updated charge
CustomerChargeAPIService-->>Customer: Updated charge
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 |
faa6040 to
0e3b6c8
Compare
415fb14 to
9ec1a79
Compare
0e3b6c8 to
fb06895
Compare
9ec1a79 to
80a7fef
Compare
fb06895 to
49cbc32
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openmeter/billing/charges/service/api_test.go (1)
689-695: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDrop the pass-through
SetupSuiteandTearDownTest.Both methods only call the embedded
BaseSuiteversion. Go promotes embedded methods, so removing them keeps the same behavior with less code.♻️ Proposed cleanup
-func (s *CustomerChargeAPISetOverrideTestSuite) SetupSuite() { - s.BaseSuite.SetupSuite() -} - -func (s *CustomerChargeAPISetOverrideTestSuite) TearDownTest() { - s.BaseSuite.TearDownTest() -} -As per coding guidelines: "Do not extract trivial or single-use helpers unless the name captures non-obvious domain intent; inline pass-through wrappers."
🤖 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/service/api_test.go` around lines 689 - 695, Remove the pass-through SetupSuite and TearDownTest methods from CustomerChargeAPISetOverrideTestSuite, allowing the embedded BaseSuite methods to be promoted and preserving the existing behavior.Source: Coding guidelines
🤖 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/service/api.go`:
- Around line 143-145: Update the ownership check in the charge retrieval flow
so the customerID.ID != input.CustomerID branch returns
models.NewGenericNotFoundError(errors.New("charge not found")) instead of a
formatted ownership error, producing a typed 404 without revealing charge
ownership.
---
Nitpick comments:
In `@openmeter/billing/charges/service/api_test.go`:
- Around line 689-695: Remove the pass-through SetupSuite and TearDownTest
methods from CustomerChargeAPISetOverrideTestSuite, allowing the embedded
BaseSuite methods to be promoted and preserving the existing behavior.
🪄 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: 3de04aa4-e9c5-4d1f-8d84-0523cc31bd03
📒 Files selected for processing (21)
openmeter/billing/charges/README.mdopenmeter/billing/charges/api.goopenmeter/billing/charges/api_test.goopenmeter/billing/charges/flatfee/charge.goopenmeter/billing/charges/flatfee/patch.goopenmeter/billing/charges/flatfee/service/creditheninvoice.goopenmeter/billing/charges/flatfee/service/creditsonly.goopenmeter/billing/charges/flatfee/service/statemachine.goopenmeter/billing/charges/meta/patch.goopenmeter/billing/charges/meta/patchsetoverride.goopenmeter/billing/charges/meta/patchsetoverride_test.goopenmeter/billing/charges/meta/triggers.goopenmeter/billing/charges/service/api.goopenmeter/billing/charges/service/api_test.goopenmeter/billing/charges/usagebased/charge.goopenmeter/billing/charges/usagebased/patch.goopenmeter/billing/charges/usagebased/service/creditheninvoice.goopenmeter/billing/charges/usagebased/service/creditsonly.goopenmeter/billing/charges/usagebased/service/statemachine.goopenmeter/billing/worker/subscriptionsync/service/creditsonly_test.goopenmeter/server/server_test.go
Summary
Stack
Verification
Summary by CodeRabbit
New Features
Bug Fixes
Greptile Summary
The PR introduces a customer-facing facade for replacing complete mutable override snapshots on flat-fee and usage-based charges while preserving base intent.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Caller participant Facade as Customer Charge Facade participant ChargeSM as Charge State Machine participant Store as Charge Persistence participant Billing as Invoice/Credit Reconciliation Caller->>Facade: SetCustomerChargeOverride Facade->>Facade: Validate ownership, payload, and charge type Facade->>ChargeSM: Apply typed SetOverride patch ChargeSM->>Store: Create or replace override layer alt Flat fee ChargeSM->>Billing: Rerate and reconcile credits/invoice state else Credit-only usage ChargeSM->>Billing: Correct and void mutable runs ChargeSM->>Store: Reschedule charge from override else Invoice-backed usage after realization ChargeSM-->>Facade: Reject with precondition failure end Facade-->>Caller: Return refreshed chargeReviews (7): Last reviewed commit: "style(charges): format override patch al..." | Re-trigger Greptile
Context used: