You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(subscription): default added items to plan currency - #5275
Adding or replacing a priced subscription item without an explicit currency defaulted to invoice fiat, even for custom-currency plans. Hydrate Subscription.Currency from the referenced plan version and use Subscription.DefaultCurrency() for add-item edits, preserving the managed custom-currency ID.
Explicit item currencies remain unchanged. Subscriptions without a retained plan default fall back to InvoiceCurrency. No schema migration or event wire-format change is required.
Notes for reviewer
Regression coverage includes fiat and custom defaults, new items and replacements, pointer patches, explicit overrides, inline-plan fallback, unpriced items, currency validation, and event compatibility. The subscription README documents the defaulting contract.
Validation:
PostgreSQL-backed tests: POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/subscription ./openmeter/subscription/repo ./openmeter/subscription/service ./openmeter/subscription/patch ./openmeter/subscription/workflow/service
Focused lint and formatting: make lint-go-fast lint-go-style GO_LINT_PATH='./openmeter/subscription ./openmeter/subscription/repo ./openmeter/subscription/workflow/service'
Summary by CodeRabbit
Bug Fixes
Added subscription items without an explicitly selected currency now default to the referenced plan’s currency. For inline plans, they use the invoice currency instead.
Explicit currency selections and item-level overrides remain unchanged. Unpriced items remain without a currency.
Confidence Score: 5/5
The PR appears safe to merge.
Summary
Added and replaced priced subscription items now inherit the referenced plan’s currency when no currency is supplied.
Running subscription edits use the plan currency for new priced items.
No actionable issues were found. Tests were inspected but not run.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[EditRunning reads subscription] --> B[Load referenced plan currency]
B --> C{Item has explicit currency?}
C -->|Yes| F[Resolve and validate currency]
C -->|No, priced item| D{Plan default retained?}
D -->|Yes| E[Clone plan currency and managed ID]
D -->|No| G[Use invoice currency]
E --> F
G --> F
F --> H[Apply edit and save]
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
Subscription reads now retain the referenced plan’s currency. When an item edit adds a priced item without an explicit currency, the workflow uses that plan currency, or invoice currency when no plan default is available.
Changes
Plan-default currency for item edits
Layer / File(s)
Summary
Hydrate and expose the subscription currency openmeter/subscription/subscription.go, openmeter/subscription/repo/mapping.go, openmeter/subscription/currency.go, openmeter/subscription/events_test.go
Subscriptions now hold a non-serialized plan currency reference. Repository mapping populates it from the plan. DefaultCurrency returns that reference or falls back to invoice currency. The event test checks that the legacy invoice-currency field remains unchanged.
Apply the default to item edits openmeter/subscription/workflow/service/subscription.go, openmeter/subscription/workflow/service/edit_currency_test.go, openmeter/subscription/workflow/service/subscription_test.go, openmeter/subscription/README.md
EditRunning passes the subscription default to rate-card resolution. Tests cover fiat and custom plan currencies, inline plans, item overrides, new items, pointer-form patches, and unpriced items. The documented invariant describes the same defaulting behavior.
Added priced subscription items without an explicit currency now default to the plan version's currency, and invoice currency is the fallback. The supplied context shows regression tests for these cases and no actionable merge risk.
Pre-merge checks | 4
✅ Passed checks (4 passed)
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: defaulting added subscription items to the referenced plan currency.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings
Commit to this branch
Create a new PR
🧪 Generate unit tests (beta)
Commit to this branch
Create a new PR
🛠️ Fix failing CI checks 💡
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adding or replacing a priced subscription item without an explicit currency defaulted to invoice fiat, even for custom-currency plans. Hydrate
Subscription.Currencyfrom the referenced plan version and useSubscription.DefaultCurrency()for add-item edits, preserving the managed custom-currency ID.Explicit item currencies remain unchanged. Subscriptions without a retained plan default fall back to
InvoiceCurrency. No schema migration or event wire-format change is required.Notes for reviewer
Regression coverage includes fiat and custom defaults, new items and replacements, pointer patches, explicit overrides, inline-plan fallback, unpriced items, currency validation, and event compatibility. The subscription README documents the defaulting contract.
Validation:
POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/subscription ./openmeter/subscription/repo ./openmeter/subscription/service ./openmeter/subscription/patch ./openmeter/subscription/workflow/servicemake lint-go-fast lint-go-style GO_LINT_PATH='./openmeter/subscription ./openmeter/subscription/repo ./openmeter/subscription/workflow/service'Summary by CodeRabbit

Confidence Score: 5/5
The PR appears safe to merge.Summary
Added and replaced priced subscription items now inherit the referenced plan’s currency when no currency is supplied.
No actionable issues were found. Tests were inspected but not run.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[EditRunning reads subscription] --> B[Load referenced plan currency] B --> C{Item has explicit currency?} C -->|Yes| F[Resolve and validate currency] C -->|No, priced item| D{Plan default retained?} D -->|Yes| E[Clone plan currency and managed ID] D -->|No| G[Use invoice currency] E --> F G --> F F --> H[Apply edit and save]Reviews (1) · Last reviewed commit: "fix(subscription): default added items t..." · Reviewed by Greptile