Skip to content

fix(subscription): allow free plan currency mismatch - #4954

Merged
GAlexIHU merged 1 commit into
mainfrom
codex/fix-free-plan-currency-validation
Aug 18, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
codex/fix-free-plan-currency-validation

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • let fiat plans define the subscription invoice currency without rejecting customer mismatches in the resolver
  • retain customer/invoice currency mismatch validation for subscriptions with billable contents
  • allow free plans to differ from the customer currency while keeping unpriced items currency-less
  • keep custom-currency plans invoiced in the customer's fiat currency

Root cause

The plan-start currency resolver enforced customer and fiat-plan currency equality before a subscription spec existed. That duplicated price-dependent validation at a layer that could not distinguish priced from unpriced contents.

The resolver now only selects the invoice currency: the plan currency for fiat plans, or the customer fiat for custom-currency plans. The subscription service remains the owning validation boundary and rejects customer/invoice currency mismatches when spec.HasBillables() is true.

Impact

Free subscriptions can start and be updated without spurious currency errors. Priced fiat-plan subscriptions retain the existing customer currency mismatch protection.

Validation

  • go test -tags=dynamic ./openmeter/subscription/workflow/service -run 'Test(ResolveSubscriptionInvoiceCurrency|CreateFromPlan)$' -count=1
  • go test -tags=dynamic ./openmeter/subscription/... ./openmeter/productcatalog/subscription/... -count=1
  • git diff --check

Greptile Summary

The PR moves fiat customer/plan mismatch handling from the early invoice-currency resolver to the subscription spec’s billability-aware validation.

  • Allows unpriced plans to use a plan currency different from the customer currency.
  • Keeps mismatching priced plans rejected before persistence.
  • Adds resolver and workflow regression coverage and documents the price-dependent invariant.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
openmeter/subscription/workflow/service/subscription.go Defers fiat mismatch rejection to the existing billability-aware core validation while preserving custom-currency requirements.
openmeter/subscription/workflow/service/currency_test.go Updates resolver expectations to verify that a fiat plan determines invoice currency independently of customer mismatch.
openmeter/subscription/workflow/service/subscription_test.go Covers successful free-plan mismatch creation and update, plus rejection of mismatching priced plans.
openmeter/subscription/README.md Documents that customer and invoice currencies must match only when the subscription contains priced items.

Sequence Diagram

sequenceDiagram
  participant W as Subscription workflow
  participant R as Currency resolver
  participant S as Subscription spec
  participant V as Core service validation
  participant DB as Persistence
  W->>R: Resolve invoice currency
  R-->>W: Fiat plan currency
  W->>S: Build spec from plan
  W->>V: Create subscription
  alt Spec has priced items
    V->>V: Compare customer and invoice currencies
    alt Currencies mismatch
      V-->>W: Validation error
    else Currencies match
      V->>DB: Persist subscription
    end
  else Spec has no priced items
    V->>DB: Persist subscription
  end
Loading

Reviews (3): Last reviewed commit: "fix(subscription): allow free plan curre..." | Re-trigger Greptile

Context used:

Summary by CodeRabbit

  • New Features

    • Subscriptions using priced items now require the customer and invoice currencies to match.
    • Free or unpriced plans can be created and revalidated across different fiat currencies.
    • Fiat-priced plans consistently use the plan’s currency.
    • Custom plans continue to require a customer currency.
  • Bug Fixes

    • Improved validation and clearer errors for unsupported currency combinations.

@coderabbitai

coderabbitai Bot commented Aug 18, 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: 0c4c7224-e849-4481-91e7-595bade5e24e

📥 Commits

Reviewing files that changed from the base of the PR and between c1b27a6 and 1cec0c2.

📒 Files selected for processing (4)
  • openmeter/subscription/README.md
  • openmeter/subscription/workflow/service/currency_test.go
  • openmeter/subscription/workflow/service/subscription.go
  • openmeter/subscription/workflow/service/subscription_test.go

Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Subscription invoice currency resolution now prioritizes fiat plan currencies. Custom plans validate customer currencies. Priced subscriptions reject customer and plan currency mismatches, while unpriced subscriptions can use different currencies.

Changes

Subscription currency handling

Layer / File(s) Summary
Invoice currency resolution
openmeter/subscription/workflow/service/subscription.go, openmeter/subscription/workflow/service/currency_test.go
Fiat plans use the plan currency regardless of the customer currency. Custom plans require a customer currency, which must be fiat.
Subscription currency validation
openmeter/subscription/workflow/service/subscription_test.go, openmeter/subscription/README.md
Unpriced plans can use a different customer currency and pass revalidation. Priced plans reject currency mismatches with a validation error. The README documents this invariant.

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

Merge Risk: ⚪ Minimal · up to 1cec0

This localized change allows free plans to use a different currency from the customer while preserving validation for priced subscriptions; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: rolosp

🚥 Pre-merge checks | ✅ 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: allowing currency mismatches for free subscription plans.
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/fix-free-plan-currency-validation

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 added the release-note/bug-fix Release note: Bug Fixes label Aug 18, 2026
@GAlexIHU
GAlexIHU force-pushed the codex/fix-free-plan-currency-validation branch from 7513165 to 2e9ee7b Compare August 18, 2026 12:27
@GAlexIHU
GAlexIHU force-pushed the codex/fix-free-plan-currency-validation branch from 2e9ee7b to 1cec0c2 Compare August 18, 2026 12:31
@GAlexIHU
GAlexIHU marked this pull request as ready for review August 18, 2026 12:36
@GAlexIHU
GAlexIHU requested a review from a team as a code owner August 18, 2026 12:36
@GAlexIHU
GAlexIHU enabled auto-merge (squash) August 18, 2026 12:36
@GAlexIHU
GAlexIHU merged commit 12e68f1 into main Aug 18, 2026
27 checks passed
@GAlexIHU
GAlexIHU deleted the codex/fix-free-plan-currency-validation branch August 18, 2026 12:39
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