Skip to content

feat(billing): depraracate tax code setting on billing profile - #4504

Merged
borbelyr-kong merged 5 commits into
mainfrom
feat/depracate-tax-code-set-at-billing-profile
Jun 17, 2026
Merged

borbelyr-kong merged 5 commits into
mainfrom
feat/depracate-tax-code-set-at-billing-profile

Conversation

@borbelyr-kong

@borbelyr-kong borbelyr-kong commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

@coderabbitai

Summary by CodeRabbit

Release Notes

  • New Features

    • Enforced deprecation for billing profiles’ default tax config: deprecated stripe.code / taxCodeId can no longer be added or changed. The organization default tax code is used instead; behavior remains supported. Existing deprecated values may be removed.
  • Documentation

    • Updated API specs and inline docs to reflect the deprecation and normalization rules.
  • Tests

    • Expanded create/update and edge-case coverage, including new adapter-based profile default-tax seeding to verify rejection and clearing behavior.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR enforces deprecation of tax code field assignments on billing profile default tax configurations. It adds validation logic that rejects create/update attempts to add or modify stripe.code or taxCodeId, while allowing removal and behavior-only configuration. API specs are updated with deprecation notes, the validator is wired into profile handlers, and existing tests are refactored to use a new adapter-based seeding pattern.

Changes

Tax Code Deprecation Enforcement

Layer / File(s) Summary
Schema and deprecation documentation
api/spec/packages/aip-client-javascript/src/models/types.ts, api/spec/packages/aip/src/billing/profile.tsp, api/spec/packages/legacy/src/billing/profile.tsp
API specs document that tax code fields on profile default tax configs are deprecated: they can no longer be added or changed, the organization default is used instead, and removal plus behavior-only config remain supported.
Tax code deprecation validator and tests
openmeter/billing/profile.go, openmeter/billing/profile_test.go
InvoicingConfig.Clone deep-copies configs safely. InvoicingConfig.WithDeprecatedTaxCodeEnforced rejects attempts to add or change stripe.code / taxCodeId by comparing incoming vs stored state. Removal is allowed and normalizes the config by clearing TaxCodeID. Comprehensive table-driven test covers creation, updates, transitions, and error cases.
Handler integration for profile create and update
openmeter/billing/service/profile.go, openmeter/productcatalog/tax.go
CreateProfile validates against zero-value stored state; UpdateProfile validates against existing profile state. Both gate changes on validation success. Code spacing improvements separate logical sections in ResolveTaxConfig.
Test seeding helper and test pattern refactor
test/billing/suite.go, test/billing/tax_test.go, test/billing/taxcode_dual_write_test.go
New SeedProfileDefaultTaxConfigViaAdapter helper uses the billing adapter to materialize tax configs, replacing direct profile provisioning edits. Tests add deprecation-gate rejection coverage for create and update flows. Dual-write tests shift focus from preserving tax code setup to validating the gate and verifying that removal clears the deprecated field pair.

Sequence Diagrams

sequenceDiagram
  participant CreateProfile
  participant UpdateProfile
  participant WithDeprecatedTaxCodeEnforced
  participant BillingAdapter
  
  CreateProfile->>WithDeprecatedTaxCodeEnforced: Validate incoming config vs zero-value
  alt Add or Change Attempted
    WithDeprecatedTaxCodeEnforced-->>CreateProfile: Return ValidationError
  else Removal or No-op
    WithDeprecatedTaxCodeEnforced-->>CreateProfile: Allow (possibly normalized)
    CreateProfile->>BillingAdapter: Persist profile
  end
  
  UpdateProfile->>WithDeprecatedTaxCodeEnforced: Validate incoming vs existing profile config
  alt Add or Change Attempted
    WithDeprecatedTaxCodeEnforced-->>UpdateProfile: Return ValidationError
  else Removal or No-op
    WithDeprecatedTaxCodeEnforced-->>UpdateProfile: Allow (possibly normalized)
    UpdateProfile->>BillingAdapter: Persist updated profile
  end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The PR introduces a new validation checkpoint with solid test coverage and integrates it cleanly into existing handler flows. The test refactoring spans multiple files and shifts intent from preservation to deprecation enforcement, requiring careful review of each test change to confirm intent alignment and assertion correctness.

Possibly Related PRs

  • openmeterio/openmeter#4224: Introduced ResolveTaxConfig and taxCodeId precedence handling, which this PR's deprecation logic builds upon and constrains.

Suggested Reviewers

  • turip
  • mark-vass-konghq
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 contains a typo ('depraracate' instead of 'deprecate') and accurately describes the main change: deprecating tax code setting on billing profiles.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/depracate-tax-code-set-at-billing-profile

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 and usage tips.

@borbelyr-kong borbelyr-kong added the release-note/deprecation Release note: Deprecations label Jun 10, 2026
@borbelyr-kong
borbelyr-kong force-pushed the feat/depracate-tax-code-set-at-billing-profile branch from aebd198 to ee12371 Compare June 12, 2026 11:30
@borbelyr-kong

Copy link
Copy Markdown
Contributor Author

@greptileai review this draft

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

🧹 Nitpick comments (1)
test/billing/taxcode_dual_write_test.go (1)

95-155: ⚡ Quick win

Cover the taxCodeId service path too.

These new rejection tests only exercise DefaultTaxConfig.Stripe.Code, but the deprecation rule here blocks both stripe.code and taxCodeId. Right now a service-level regression in the TaxCodeID branch would still leave this suite green. Adding one create case and one update case with DefaultTaxConfig.TaxCodeID would close that gap nicely.

As per coding guidelines, **/*_test.go: "Make sure the tests are comprehensive and cover the changes."

🤖 Prompt for 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.

In `@test/billing/taxcode_dual_write_test.go` around lines 95 - 155, Add parallel
assertions that exercise the taxCodeId path by creating new cases (or extending
the existing tests TestProfileCreateWithTaxCodeRejected and
TestProfileUpdateAddTaxCodeRejected) which set
input.WorkflowConfig.Invoicing.DefaultTaxConfig.TaxCodeID (instead of/in
addition to Stripe.Code) when calling BillingService.CreateProfile and
BillingService.UpdateProfile; ensure you assert the returned error is a
billing.ValidationError and that no default profile or TaxCode entity is
persisted (same GetDefaultProfile and DBClient.TaxCode.Query() checks) after the
rejected create/update.

Source: Coding guidelines

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

Nitpick comments:
In `@test/billing/taxcode_dual_write_test.go`:
- Around line 95-155: Add parallel assertions that exercise the taxCodeId path
by creating new cases (or extending the existing tests
TestProfileCreateWithTaxCodeRejected and TestProfileUpdateAddTaxCodeRejected)
which set input.WorkflowConfig.Invoicing.DefaultTaxConfig.TaxCodeID (instead
of/in addition to Stripe.Code) when calling BillingService.CreateProfile and
BillingService.UpdateProfile; ensure you assert the returned error is a
billing.ValidationError and that no default profile or TaxCode entity is
persisted (same GetDefaultProfile and DBClient.TaxCode.Query() checks) after the
rejected create/update.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3ebc3605-db37-47aa-8d42-1d0363eb2aab

📥 Commits

Reviewing files that changed from the base of the PR and between b569f81 and ee12371.

📒 Files selected for processing (7)
  • openmeter/billing/profile.go
  • openmeter/billing/profile_test.go
  • openmeter/billing/service/profile.go
  • openmeter/productcatalog/tax.go
  • test/billing/suite.go
  • test/billing/tax_test.go
  • test/billing/taxcode_dual_write_test.go
✅ Files skipped from review due to trivial changes (1)
  • openmeter/productcatalog/tax.go

@greptile-apps

greptile-apps Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Enforces deprecation of stripe.code / taxCodeId on billing profile default tax config — any attempt to add or change these fields via the service API now returns a billing.ValidationError; only removal and behavior changes remain allowed. Legacy rows seeded before deprecation continue to round-trip correctly via the existing resolveDefaultTaxCode path in updates.

  • InvoicingConfig.WithDeprecatedTaxCodeEnforced is the new gate function, inserted before the adapter call in both CreateProfile and UpdateProfile; it also normalizes the stripe-drop-clears-pair case so that clearing stripe.code while echoing taxCodeId removes both fields.
  • resolveDefaultTaxCode is removed from CreateProfile (tax codes on creates are now rejected outright) but retained in UpdateProfile after the gate, so legacy clients that echo only stripe.code still have taxCodeId re-stamped.
  • Tests are updated throughout to seed legacy tax-code rows via a new SeedProfileDefaultTaxConfigViaAdapter helper that bypasses the gate, and three new rejection tests (A3b, A3c) verify the gate at the integration level.

Confidence Score: 5/5

Safe to merge; the gate logic is straightforward and backed by 20+ unit tests plus updated integration tests.

The core gate function is well-structured, covered by a comprehensive table-driven test, and the two-pass ordering (gate → resolver) is preserved in UpdateProfile with a clear comment. The only finding is a stale method name in a doc comment. No logic regressions were identified.

No files require special attention; the suite.go doc comment stale reference is cosmetic only.

Important Files Changed

Filename Overview
openmeter/billing/profile.go Adds InvoicingConfig.Clone() and WithDeprecatedTaxCodeEnforced() — the core gate that blocks new/changed tax-code fields while allowing echoes and removals. Logic is correct; covers the stripe-drop-clears-pair and legacy-echo paths.
openmeter/billing/service/profile.go Wires the deprecation gate into CreateProfile (replaces resolveDefaultTaxCode) and UpdateProfile (runs gate before the existing resolver). Order of calls is correct and well-commented.
openmeter/billing/profile_test.go New unit test file with 20+ table-driven cases covering create rejection, update rejection, echo round-trip, removal variants, and the stripe-drop-clears-pair normalization. Coverage is thorough including previously flagged TaxCodeID-only stored rows.
test/billing/suite.go Adds SeedProfileDefaultTaxConfigViaAdapter helper to bypass the deprecation gate and seed legacy rows for integration tests; stale method name in its doc comment (EnforceTaxCodeDeprecation vs WithDeprecatedTaxCodeEnforced).
test/billing/taxcode_dual_write_test.go Removes tests that assumed tax codes could be set on create/update; adds rejection tests (A3b, A3c) and adapts remaining tests to use the adapter-seeding helper. Behavioral inversion for C4 (bare TaxCodeID now clears the pair) is deliberate and correct.
test/billing/tax_test.go Updates TestDefaultTaxConfigProfileSnapshotting to seed tax config via the adapter helper instead of the deprecated create-time flag.
openmeter/productcatalog/tax.go Minor blank-line additions for readability; no logic changes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[API request: Create/Update billing profile] --> B{Has DefaultTaxConfig?}
    B -- No --> Z[Pass through to adapter]
    B -- Yes --> C{WithDeprecatedTaxCodeEnforced}

    C --> D{taxCodeChanged OR stripeCodeChanged?}
    D -- Yes --> E[Return ValidationError 400]
    D -- No --> F{stripeCodeRemoved?}

    F -- Yes --> G[Clear TaxCodeID from incoming config]
    G --> H[Return normalized InvoicingConfig]
    F -- No --> H

    H --> I{Create or Update?}
    I -- Create --> Z
    I -- Update --> J[resolveDefaultTaxCode: re-stamp TaxCodeID from echoed Stripe.Code]
    J --> Z
    Z --> K[adapter.CreateProfile / UpdateProfile]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[API request: Create/Update billing profile] --> B{Has DefaultTaxConfig?}
    B -- No --> Z[Pass through to adapter]
    B -- Yes --> C{WithDeprecatedTaxCodeEnforced}

    C --> D{taxCodeChanged OR stripeCodeChanged?}
    D -- Yes --> E[Return ValidationError 400]
    D -- No --> F{stripeCodeRemoved?}

    F -- Yes --> G[Clear TaxCodeID from incoming config]
    G --> H[Return normalized InvoicingConfig]
    F -- No --> H

    H --> I{Create or Update?}
    I -- Create --> Z
    I -- Update --> J[resolveDefaultTaxCode: re-stamp TaxCodeID from echoed Stripe.Code]
    J --> Z
    Z --> K[adapter.CreateProfile / UpdateProfile]
Loading

Reviews (6): Last reviewed commit: "feat(billing): rename WithDeprecatedTaxC..." | Re-trigger Greptile

Comment thread openmeter/billing/service/profile.go Resolved
Comment thread openmeter/billing/profile.go Resolved
@borbelyr-kong
borbelyr-kong force-pushed the feat/depracate-tax-code-set-at-billing-profile branch 2 times, most recently from 26ef38e to 8083bef Compare June 12, 2026 13:01
@borbelyr-kong
borbelyr-kong marked this pull request as ready for review June 12, 2026 13:01
@borbelyr-kong
borbelyr-kong requested a review from a team as a code owner June 12, 2026 13:01
@borbelyr-kong
borbelyr-kong force-pushed the feat/depracate-tax-code-set-at-billing-profile branch from 4879485 to 0a39d58 Compare June 17, 2026 09:25
- Delete profiletaxdeprecation.go (CheckProfileTaxConfigDeprecation) and
  remove the duplicate handler-layer calls from httpdriver/profile.go and
  both api/v3/handlers/billingprofiles handlers. The gate now lives
  exclusively in InvoicingConfig.EnforceTaxCodeDeprecation called from
  the service.
- Rename profiletaxdeprecation_test.go → profile_test.go to match the
  method's new home on InvoicingConfig.
- Add missing TaxCode entity assertion in TestProfileUpdateAddTaxCodeRejected
  (parity with the analogous create test).
- Add 'create: both stripe.code and taxCodeId set is rejected' test case.
- Clarify the zero-value stored argument on the CreateProfile call site.
@borbelyr-kong
borbelyr-kong force-pushed the feat/depracate-tax-code-set-at-billing-profile branch from 0a39d58 to daa27cd Compare June 17, 2026 11:16
@borbelyr-kong
borbelyr-kong enabled auto-merge (squash) June 17, 2026 11:17
@borbelyr-kong
borbelyr-kong merged commit 2c10c47 into main Jun 17, 2026
27 of 28 checks passed
@borbelyr-kong
borbelyr-kong deleted the feat/depracate-tax-code-set-at-billing-profile branch June 17, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants