Skip to content

fix(billing): reject custom-currency manual charges - #4840

Merged
GAlexIHU merged 1 commit into
mainfrom
codex/reject-custom-manual-charges
Aug 3, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
codex/reject-custom-manual-charges

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • reject resolved custom currencies at the manual customer-charge service boundary
  • return the existing ErrCustomCurrencyNotSupported marker as a validation error before charge persistence
  • add Postgres-backed service coverage asserting rejection and no persisted charge

Why

The v3 manual customer-charge API resolved custom currencies and passed them into root charge creation. Root creation intentionally commits before auto-advance, while billing lineage still rejects custom currencies during advancement. An immediate charge could therefore remain persisted after a failed request, and a future-dated charge could be accepted and fail later in the worker.

The guard stays in CreateCustomerCharge so internal root charge APIs remain available for supported ledger/chargeadapter mechanics and future billing integration.

Validation

  • nix develop --impure .#ci -c env POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/billing/charges/service -run '^TestCustomerChargeAPI$' -count=1
  • nix develop --impure .#ci -c env POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/billing/charges/service ./api/v3/handlers/customers/charges

Summary by CodeRabbit

  • Bug Fixes
    • Customer charges now reject unsupported custom currencies with a clear validation error.
    • Invalid charges are not saved or processed.

Greptile Summary

The PR prevents manual customer charges denominated in custom currencies from reaching charge persistence while preserving custom-currency support in the internal root service.

  • Rejects resolved custom currencies at the CreateCustomerCharge boundary with the existing validation marker.
  • Adds Postgres-backed coverage for error classification and absence of persisted charges.
  • Retains coverage for successful custom-currency creation through the root charge service.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
openmeter/billing/charges/service/api.go Adds an early, correctly classified custom-currency rejection before root charge creation and persistence.
openmeter/billing/charges/service/invoicable_test.go Verifies rejection, validation-error identity, no persisted manual charge, and continued root-service support.

Reviews (2): Last reviewed commit: "fix(billing): reject custom-currency man..." | Re-trigger Greptile

Context used:

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d56fa6f7-c6c0-4000-ab0d-0bff2d549aee

📥 Commits

Reviewing files that changed from the base of the PR and between 913c436 and 655db03.

📒 Files selected for processing (2)
  • openmeter/billing/charges/service/api.go
  • openmeter/billing/charges/service/invoicable_test.go

📝 Walkthrough

Walkthrough

The customer charge API now rejects custom currencies before charge creation. Tests verify the validation errors and confirm that no charge is persisted.

Changes

Custom currency validation

Layer / File(s) Summary
Customer charge API rejection
openmeter/billing/charges/service/api.go
CreateCustomerCharge rejects custom currencies with a validation error wrapping meta.ErrCustomCurrencyNotSupported before creating the charge.
Rejection and persistence coverage
openmeter/billing/charges/service/invoicable_test.go
Tests verify the error types and confirm that rejected custom-currency charges are not persisted. Existing subtest numbers were updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: area/billing

Suggested reviewers: tothandras, turip

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: rejecting custom-currency manual charges in billing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 codex/reject-custom-manual-charges

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.

@GAlexIHU
GAlexIHU force-pushed the codex/reject-custom-manual-charges branch from 2b4d528 to aceb2bd Compare August 3, 2026 10:55
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Aug 3, 2026
@GAlexIHU
GAlexIHU force-pushed the codex/reject-custom-manual-charges branch from aceb2bd to 655db03 Compare August 3, 2026 11:01
@GAlexIHU
GAlexIHU marked this pull request as ready for review August 3, 2026 11:02
@GAlexIHU
GAlexIHU requested a review from a team as a code owner August 3, 2026 11:02
@GAlexIHU
GAlexIHU enabled auto-merge (squash) August 3, 2026 11:03

@chrisgacsal chrisgacsal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice catch! :shipit:

@GAlexIHU
GAlexIHU merged commit 6270d5e into main Aug 3, 2026
28 checks passed
@GAlexIHU
GAlexIHU deleted the codex/reject-custom-manual-charges branch August 3, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants