Skip to content

fix(subscription): default added items to plan currency - #5275

Merged
GAlexIHU merged 1 commit into
mainfrom
codex/fix-add-item-plan-currency
Oct 13, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
codex/fix-add-item-plan-currency

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Overview

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.

RetriggerConfidence 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]
Loading

Reviews (1) · Last reviewed commit: "fix(subscription): default added items t..." · Reviewed by Greptile

@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Oct 12, 2026
@GAlexIHU
GAlexIHU requested a review from a team as a code owner October 12, 2026 09:07
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Oct 12, 2026
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: openmeterio/openmeter/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dec62f32-df12-457b-994b-c344a59ede69

📥 Commits

Reviewing files that changed from the base of the PR and between e00163c and 156b498.


📒 Files selected for processing (8)
  • openmeter/subscription/README.md
  • openmeter/subscription/currency.go
  • openmeter/subscription/events_test.go
  • openmeter/subscription/repo/mapping.go
  • openmeter/subscription/subscription.go
  • openmeter/subscription/workflow/service/edit_currency_test.go
  • openmeter/subscription/workflow/service/subscription.go
  • openmeter/subscription/workflow/service/subscription_test.go

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.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: tothandras


Merge Risk: ⚪ Minimal · up to 156b4

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 | Passed 4
✅ 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 clearly and concisely describes the main change: defaulting added subscription items to the referenced plan currency.
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 💡 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.

❤️ Share

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

@GAlexIHU
GAlexIHU enabled auto-merge (squash) October 12, 2026 09:08
@GAlexIHU
GAlexIHU disabled auto-merge October 13, 2026 12:32
@GAlexIHU
GAlexIHU merged commit 5e2e51c into main Oct 13, 2026
@GAlexIHU
GAlexIHU deleted the codex/fix-add-item-plan-currency branch October 13, 2026 12:33
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