Skip to content

feat(customcurrencies): add configuration flag#4776

Merged
turip merged 1 commit into
mainfrom
feat/custom-currencies-config
Jul 27, 2026
Merged

feat(customcurrencies): add configuration flag#4776
turip merged 1 commit into
mainfrom
feat/custom-currencies-config

Conversation

@turip

@turip turip commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

  • gate custom-currency creation and cost-basis creation with the existing credits.enabled feature flag at the v3 currencies API boundary
  • keep currency reads available when credits are disabled
  • remove the separate credits.customCurrenciesEnabled configuration
  • remove custom-currency feature flags and test-only enablement switches from charge services, where custom currencies are now supported unconditionally

When credits are disabled, the custom-currency mutation endpoints return 400 Bad Request.

Validation

  • go test -tags=dynamic ./api/v3/handlers/currencies ./app/config ./app/common ./openmeter/billing/charges/creditpurchase/service ./openmeter/billing/charges/flatfee/service ./openmeter/billing/charges/usagebased/service
  • POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/billing/charges/service
  • focused go vet for the changed packages
  • focused golangci-lint for the changed packages

Summary by CodeRabbit

  • New Features

    • Custom currency charge creation is now controlled by the deployment’s credits setting.
    • Currency and cost-basis creation endpoints return a clear validation error when credits are disabled.
    • Custom currency charges can proceed when credits are enabled.
  • Bug Fixes

    • Prevented disabled custom-currency endpoints from processing requests before rejecting them.
  • Tests

    • Updated coverage to verify credits-based custom-currency behavior.

Greptile Summary

Updates custom-currency handling:

  • Gates custom-currency and cost-basis creation endpoints using the existing credits configuration.
  • Removes test-only custom-currency switches and service-level rejection checks from flat-fee, usage-based, and credit-purchase charge creation.
  • Updates handler and charge-service tests for the revised behavior.

Confidence Score: 5/5

The PR appears safe to merge within the follow-up review scope.

No blocking failure eligible for this follow-up review remains.

Important Files Changed

Filename Overview
api/v3/handlers/currencies/create.go Adds a configuration-dependent validation guard before custom-currency creation.
api/v3/handlers/currencies/create_cost_basis.go Adds the corresponding validation guard before custom cost-basis creation.
api/v3/server/server.go Passes the credits configuration state into the v3 currency handler.
openmeter/server/router/router.go Passes the credits configuration state into the legacy router's currency handler.
openmeter/billing/charges/flatfee/service/create.go Removes the service-local custom-currency rejection from flat-fee charge creation.
openmeter/billing/charges/usagebased/service/create.go Removes the service-local custom-currency rejection from usage-based charge creation.
openmeter/billing/charges/creditpurchase/service/create.go Removes the service-local custom-currency rejection from credit-purchase creation.

Reviews (3): Last reviewed commit: "feat(customcurrencies): gate API with cr..." | Re-trigger Greptile

Context used:

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Custom-currency mutation endpoints now enforce the credits flag at the HTTP layer. Charge services remove internal custom-currency gates and test toggles, while tests configure support through service constructors and semantic setup.

Changes

Custom currency gating

Layer / File(s) Summary
Currency handler enforcement
api/v3/handlers/currencies/*, api/v3/server/server.go, openmeter/server/router/router.go
The handler accepts creditsEnabled, rejects disabled currency and cost-basis mutations with validation errors, and receives the flag from server configuration.
Charge service gating removal
openmeter/billing/charges/{creditpurchase,flatfee,usagebased}/service/*
Charge creation no longer applies the internal custom-currency rejection, and the atomic enablement fields and test helpers are removed.
Semantic test configuration
openmeter/billing/charges/service/*, .agents/skills/charges/SKILL.md
Tests configure custom-currency support through service constructors or updated suite setup instead of runtime interface assertions and toggle helpers.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested labels: kind/feature

Suggested reviewers: chrisgacsal, mark-vass-konghq

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 matches the main change: adding a custom-currencies configuration flag.
✨ 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/custom-currencies-config

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 added area/billing release-note/feature Release note: Exciting New Features labels Jul 23, 2026
@turip
turip marked this pull request as ready for review July 23, 2026 10:57
@turip
turip requested a review from a team as a code owner July 23, 2026 10:57
@turip
turip enabled auto-merge (squash) July 23, 2026 10:58
@turip
turip force-pushed the feat/custom-currencies-config branch from ab0d023 to e66efd0 Compare July 27, 2026 13:14
@turip
turip force-pushed the feat/custom-currencies-config branch from e66efd0 to 1d58ed1 Compare July 27, 2026 14:24

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

Actionable comments posted: 2

🤖 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 `@api/v3/handlers/currencies/handler.go`:
- Around line 25-38: Update the currencies handler constructor New to accept an
injected *slog.Logger and store or propagate it through the handler as required.
Update all production server/router call sites that invoke New to pass the
existing configured logger, without using slog.Default() or introducing a
fallback.

In `@openmeter/server/router/router.go`:
- Around line 526-531: Update the currencyHandler construction to pass the
dedicated custom-currency enablement setting from config instead of
config.Credits.Enabled. Preserve the existing resolveNamespace, CurrencyService,
and error-handler wiring while ensuring custom-currency mutations require the
credits.customCurrenciesEnabled opt-in.
🪄 Autofix (Beta)

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: d0702057-6c05-4f5a-bd7a-20ef124f1bfb

📥 Commits

Reviewing files that changed from the base of the PR and between e66efd0 and 1d58ed1.

📒 Files selected for processing (20)
  • .agents/skills/charges/SKILL.md
  • api/v3/handlers/currencies/create.go
  • api/v3/handlers/currencies/create_cost_basis.go
  • api/v3/handlers/currencies/handler.go
  • api/v3/handlers/currencies/handler_test.go
  • api/v3/handlers/currencies/list_test.go
  • api/v3/server/server.go
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/billing/charges/creditpurchase/service/service.go
  • openmeter/billing/charges/flatfee/service/create.go
  • openmeter/billing/charges/flatfee/service/service.go
  • openmeter/billing/charges/service/base_test.go
  • openmeter/billing/charges/service/creditpurchase_test.go
  • openmeter/billing/charges/service/flatfee_costbasis_test.go
  • openmeter/billing/charges/service/invoicable_test.go
  • openmeter/billing/charges/service/usagebased_costbasis_test.go
  • openmeter/billing/charges/service/usagebased_test.go
  • openmeter/billing/charges/usagebased/service/create.go
  • openmeter/billing/charges/usagebased/service/service.go
  • openmeter/server/router/router.go
💤 Files with no reviewable changes (8)
  • openmeter/billing/charges/flatfee/service/create.go
  • .agents/skills/charges/SKILL.md
  • openmeter/billing/charges/service/base_test.go
  • openmeter/billing/charges/service/usagebased_test.go
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/billing/charges/usagebased/service/create.go
  • openmeter/billing/charges/service/invoicable_test.go
  • openmeter/billing/charges/flatfee/service/service.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • api/v3/handlers/currencies/handler_test.go
  • api/v3/handlers/currencies/create_cost_basis.go
  • api/v3/server/server.go
  • api/v3/handlers/currencies/list_test.go
  • api/v3/handlers/currencies/create.go

Comment thread api/v3/handlers/currencies/handler.go
Comment thread openmeter/server/router/router.go
@turip
turip merged commit 0c9c299 into main Jul 27, 2026
26 of 27 checks passed
@turip
turip deleted the feat/custom-currencies-config branch July 27, 2026 14:35
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