feat(charges): add backend customer charge deletion - #4887
Conversation
📝 WalkthroughWalkthroughAdds customer charge deletion with validated payment-adjustment handling. The service applies delete patches, preserves immutable payment and invoice history, removes mutable gathering lines, and records invoice validation issues for unsupported discrepancies. ChangesCustomer charge deletion
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant CustomerChargeAPIService
participant service
participant CustomerChargePatch
Caller->>CustomerChargeAPIService: DeleteCustomerCharge(input)
CustomerChargeAPIService->>service: Validate input and namespace lockdown
service->>service: resolveDeletePolicy(paymentAdjustment)
service->>CustomerChargePatch: Create and apply delete patch
CustomerChargePatch-->>Caller: Return deletion result
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ 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 |
415fb14 to
9ec1a79
Compare
d8cd82c to
bf4c3d2
Compare
9ec1a79 to
80a7fef
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/billing/charges/service/api_test.go (1)
53-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOptional: drop the pass-through suite hooks.
SetupSuiteandTearDownTestonly call the embeddedBaseSuitemethods. Go promotes those methods automatically, so the overrides add no behavior. Removing them keeps the suite lean, and you can add them back when the suite needs extra setup.♻️ Proposed cleanup
-func (s *CustomerChargeAPIDeleteTestSuite) SetupSuite() { - s.BaseSuite.SetupSuite() -} - -func (s *CustomerChargeAPIDeleteTestSuite) 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 53 - 59, Remove the pass-through SetupSuite and TearDownTest overrides from CustomerChargeAPIDeleteTestSuite; rely on the embedded BaseSuite methods promoted by Go, preserving the existing suite lifecycle 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.
Nitpick comments:
In `@openmeter/billing/charges/service/api_test.go`:
- Around line 53-59: Remove the pass-through SetupSuite and TearDownTest
overrides from CustomerChargeAPIDeleteTestSuite; rely on the embedded BaseSuite
methods promoted by Go, preserving the existing suite lifecycle behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 542853e1-ed3a-4d62-88b6-167f556118b4
📒 Files selected for processing (6)
openmeter/billing/charges/README.mdopenmeter/billing/charges/api.goopenmeter/billing/charges/api_test.goopenmeter/billing/charges/service/api.goopenmeter/billing/charges/service/api_test.goopenmeter/server/server_test.go
Summary
noneto ignoring both credit and invoice refundsStack
Verification
Summary by CodeRabbit
New Features
Bug Fixes
Greptile Summary
The PR adds a backend customer-scoped facade for deleting flat-fee and usage-based charges while rejecting credit purchases and preserving immutable billing history.
noneto ignoring credit and invoice refunds while retaining normal invoice lifecycle reconciliation.Confidence Score: 5/5
The PR appears safe to merge because no blocking failure remains.
No blocking failure remains.
Important Files Changed
Sequence Diagram
Reviews (5): Last reviewed commit: "test(charges): remove redundant suite ho..." | Re-trigger Greptile
Context used: