Skip to content

feat(customcurrencies): add configuration flag#4776

Open
turip wants to merge 1 commit into
mainfrom
feat/custom-currencies-config
Open

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

Conversation

@turip

@turip turip commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

Adds an explicit credits.customCurrenciesEnabled opt-in for the experimental custom-currency flow.

When enabled, the setting initializes custom-currency support for flat-fee, usage-based, and credit-purchase charges and allows custom currencies and their cost bases to be created through the API. It remains disabled by default, while quickstart and e2e opt in so the flow can be exercised in development and automated coverage.

The example configuration includes a prominent warning that the feature is experimental and can cause database inconsistencies until the full implementation is complete.

Validation

  • make lint-go-fast
  • focused Go tests and vet for config, wiring, charge services, and currency handlers
  • make test-nocache (6,288 tests; only the out-of-scope Svix connectivity test failed because the local Svix service was not running)

Greptile Summary

Adds an opt-in configuration flag for experimental custom-currency support.

  • Defaults custom-currency mutations and charge creation to disabled.
  • Propagates the flag through both API surfaces and all three charge-service implementations.
  • Enables the feature in quickstart and end-to-end configurations and documents its experimental status.

Confidence Score: 5/5

The PR appears safe to merge with the custom-currency opt-in consistently applied across API mutations and production charge services.

The disabled default is preserved, both API constructions receive the configured value, and server, billing-worker, and jobs wiring propagate it to flat-fee, usage-based, and credit-purchase services without an uncovered production path.

Important Files Changed

Filename Overview
app/config/credits.go Adds the disabled-by-default custom-currency configuration field and Viper default.
app/common/charges.go Propagates the configured flag into all three production charge-service constructors.
api/v3/handlers/currencies/handler.go Stores the feature setting on currency handlers for mutation gating.
api/v3/handlers/currencies/create.go Rejects custom-currency creation when the experimental feature is disabled.
api/v3/handlers/currencies/create_cost_basis.go Rejects cost-basis creation when the experimental feature is disabled.
openmeter/billing/charges/flatfee/service/service.go Initializes flat-fee custom-currency support from configuration.
openmeter/billing/charges/usagebased/service/service.go Initializes usage-based custom-currency support from configuration.
openmeter/billing/charges/creditpurchase/service/service.go Initializes credit-purchase custom-currency support from configuration.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Config[credits.customCurrenciesEnabled] --> V1[v1 currency handler]
    Config --> V3[v3 currency handler]
    Config --> Registry[charges registry]
    Registry --> FlatFee[flat-fee service]
    Registry --> Usage[usage-based service]
    Registry --> Purchase[credit-purchase service]
    V1 --> Mutations[custom currency and cost-basis mutations]
    V3 --> Mutations
    FlatFee --> Charges[custom-currency charge creation]
    Usage --> Charges
    Purchase --> Charges
Loading

Reviews (1): Last reviewed commit: "feat(customcurrencies): add configuratio..." | Re-trigger Greptile

Context used:

Summary by CodeRabbit

  • New Features

    • Added a configuration option to enable or disable custom-currency support.
    • Custom-currency creation and cost-basis operations now return a validation error when the feature is disabled.
    • Enabled custom-currency support in quickstart and end-to-end configurations.
  • Bug Fixes

    • Ensured custom-currency settings are consistently applied across billing services and API handlers.
  • Documentation

    • Added configuration guidance and warnings noting that custom currencies are experimental.

@coderabbitai

coderabbitai Bot commented Jul 23, 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: 39c14327-4b92-46ac-b6b9-c76760dae480

📥 Commits

Reviewing files that changed from the base of the PR and between fab8c28 and ab0d023.

📒 Files selected for processing (19)
  • .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
  • app/common/charges.go
  • app/config/config_test.go
  • app/config/credits.go
  • config.example.yaml
  • e2e/config.yaml
  • openmeter/billing/charges/creditpurchase/service/service.go
  • openmeter/billing/charges/flatfee/service/service.go
  • openmeter/billing/charges/service/creditpurchase_test.go
  • openmeter/billing/charges/service/invoicable_test.go
  • openmeter/billing/charges/usagebased/service/service.go
  • openmeter/server/router/router.go
  • quickstart/config.yaml

📝 Walkthrough

Walkthrough

Changes

Custom-currency enablement is now configured through credits.customCurrenciesEnabled, propagated into charge services and currency handlers, and enforced on currency mutation endpoints. Disabled mutations return validation errors before parsing. Tests and configuration examples reflect enabled and disabled environments.

Custom currency configuration

Layer / File(s) Summary
Configuration contract
app/config/credits.go, app/config/config_test.go, config.example.yaml, e2e/config.yaml, quickstart/config.yaml
Adds the customCurrenciesEnabled credits setting, defaults it to false, and configures it for example, e2e, and quickstart environments.
Charge service initialization
app/common/charges.go, openmeter/billing/charges/*/service.go, openmeter/billing/charges/service/*_test.go, .agents/skills/charges/SKILL.md
Passes the credits flag into flat-fee, usage-based, and credit-purchase services, which initialize their internal custom-currency state; test helpers set the flag through service configuration.
Currency handler enforcement
api/v3/handlers/currencies/*.go, api/v3/server/server.go, openmeter/server/router/router.go
Passes the credits flag into currency handlers and rejects currency and cost-basis creation with validation errors when disabled.
Mutation and constructor tests
api/v3/handlers/currencies/handler_test.go, api/v3/handlers/currencies/list_test.go
Verifies disabled mutation endpoints return HTTP 400 and updates existing handler construction calls for the new flag.

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

Sequence Diagram(s)

sequenceDiagram
  participant Config
  participant NewServer
  participant CurrencyHandler
  participant Client
  Config->>NewServer: credits.customCurrenciesEnabled
  NewServer->>CurrencyHandler: initialize with feature flag
  Client->>CurrencyHandler: create currency or cost basis
  CurrencyHandler-->>Client: 400 validation error when disabled
Loading

Possibly related PRs

Suggested reviewers: mark-vass-konghq, chrisgacsal, tothandras

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately captures the main change: adding a custom-currencies configuration flag.
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 feat/custom-currencies-config

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
config.example.yaml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

e2e/config.yaml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

quickstart/config.yaml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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

1 participant