Skip to content

feat(charges): add backend customer charge deletion - #4887

Merged
turip merged 3 commits into
mainfrom
feat/charges-delete-backend-api
Aug 11, 2026
Merged

feat(charges): add backend customer charge deletion#4887
turip merged 3 commits into
mainfrom
feat/charges-delete-backend-api

Conversation

@turip

@turip turip commented Aug 8, 2026

Copy link
Copy Markdown
Member

Summary

  • add the backend customer charge deletion facade
  • require the facade-owned payment adjustment selection
  • map none to ignoring both credit and invoice refunds
  • support flat-fee and usage-based charges; reject credit purchases

Stack

Verification

  • focused existing charge and server suites pass
  • no new behavioral test cases are included in this split

Summary by CodeRabbit

New Features

  • Added support for deleting customer charges.
  • Added a “no payment adjustment” option for charge deletion.
  • Charge deletion preserves immutable invoice and payment history while removing eligible invoice lines.
  • Unsupported discrepancies are recorded as invoice validation issues.

Bug Fixes

  • Added validation for required deletion details and payment adjustment values.
  • Prevented deletion of charges belonging to another customer or credit purchases.

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.

  • Requires callers to explicitly select a payment adjustment policy.
  • Maps none to ignoring credit and invoice refunds while retaining normal invoice lifecycle reconciliation.
  • Adds service-level coverage for ownership checks, supported charge types, credit realizations, mutable invoice-line cleanup, and paid invoice preservation.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
openmeter/billing/charges/api.go Adds the customer charge deletion contract, validated input, and explicit payment-adjustment enum.
openmeter/billing/charges/service/api.go Implements customer-scoped deletion by mapping the facade policy into an internal delete patch and applying it through the existing charge workflow.
openmeter/billing/charges/service/api_test.go Exercises supported charge types, ownership enforcement, credit-purchase rejection, realization preservation, and mutable versus immutable invoice behavior.
openmeter/billing/charges/README.md Documents the semantics of deleting charges without compensating prior credit or payment effects.
openmeter/server/server_test.go Updates the test no-op charge service to satisfy the expanded facade interface.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant Facade as CustomerChargeAPIService
  participant Patches as ApplyPatches
  participant Charge as Charge state machine
  participant Invoice as Invoice updater
  Caller->>Facade: DeleteCustomerCharge(customer, charge, none)
  Facade->>Facade: Validate input and namespace
  Facade->>Patches: "PatchDelete(refunds = ignore)"
  Patches->>Charge: Validate ownership and apply deletion
  Charge->>Invoice: Reconcile associated invoice lines
  Invoice-->>Charge: Delete mutable lines or record immutable drift
  Charge-->>Caller: Deletion result
Loading

Reviews (5): Last reviewed commit: "test(charges): remove redundant suite ho..." | Re-trigger Greptile

Context used:

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Customer charge deletion

Layer / File(s) Summary
Deletion contract and validation
openmeter/billing/charges/api.go, openmeter/billing/charges/api_test.go
Adds DeleteCustomerCharge, DeleteCustomerChargeInput, and PaymentAdjustmentNone. Validation checks required identifiers and rejects unsupported payment adjustments.
Deletion service flow
openmeter/billing/charges/service/api.go, openmeter/billing/charges/service/api_test.go, openmeter/server/server_test.go
Validates namespace lockdown, resolves the deletion policy, applies delete patches, enforces ownership, rejects credit-purchase deletion, and updates the no-op service implementation.
Allocation and invoice effects
openmeter/billing/charges/service/api_test.go, openmeter/billing/charges/README.md
Tests preservation of credit allocations and paid invoice history, removal of gathering lines, and immutable-invoice validation issues. Documents payment-adjustment behavior.

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
Loading

Possibly related PRs

Suggested reviewers: chrisgacsal

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding backend customer charge deletion.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/charges-delete-backend-api

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@turip
turip force-pushed the feat/charges-delete-backend-api branch from 415fb14 to 9ec1a79 Compare August 9, 2026 11:13
@turip
turip force-pushed the agent/charge-statemachine-callers branch from d8cd82c to bf4c3d2 Compare August 10, 2026 12:08
Base automatically changed from agent/charge-statemachine-callers to main August 11, 2026 12:52
@turip
turip force-pushed the feat/charges-delete-backend-api branch from 9ec1a79 to 80a7fef Compare August 11, 2026 13:18
@turip
turip marked this pull request as ready for review August 11, 2026 13:21
@turip
turip requested a review from a team as a code owner August 11, 2026 13:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
openmeter/billing/charges/service/api_test.go (1)

53-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: drop the pass-through suite hooks.

SetupSuite and TearDownTest only call the embedded BaseSuite methods. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 170e66c and 80a7fef.

📒 Files selected for processing (6)
  • openmeter/billing/charges/README.md
  • openmeter/billing/charges/api.go
  • openmeter/billing/charges/api_test.go
  • openmeter/billing/charges/service/api.go
  • openmeter/billing/charges/service/api_test.go
  • openmeter/server/server_test.go

@turip turip added release-note/feature Release note: Exciting New Features area/billing labels Aug 11, 2026
@turip
turip merged commit 3873500 into main Aug 11, 2026
27 checks passed
@turip
turip deleted the feat/charges-delete-backend-api branch August 11, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants