Skip to content

feat(api): add tax id and tax behavior to charges list api - #4263

Merged
mark-vass-konghq merged 4 commits into
mainfrom
feat/add-tax_id-and-tax-behavior-to-charges-list-api
May 5, 2026
Merged

mark-vass-konghq merged 4 commits into
mainfrom
feat/add-tax_id-and-tax-behavior-to-charges-list-api

Conversation

@mark-vass-konghq

@mark-vass-konghq mark-vass-konghq commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

@CodeRabbit

Summary by CodeRabbit

  • New Features

    • Optional per-charge TaxConfig added for flat-fee and usage-based charges; structured tax_code reference introduced and takes precedence over deprecated tax_code_id and legacy provider codes.
    • Shared TaxCodeReference model added and API mappings updated to surface tax_code consistently.
  • Tests

    • New unit and integration tests covering TaxConfig conversion, precedence rules, API mappings, and listing behavior.
  • Documentation

    • Deprecated fields updated with guidance to use tax_code instead.

@mark-vass-konghq mark-vass-konghq self-assigned this Apr 30, 2026
@mark-vass-konghq
mark-vass-konghq requested a review from a team as a code owner April 30, 2026 17:36
@mark-vass-konghq mark-vass-konghq added release-note/feature Release note: Exciting New Features area/billing labels Apr 30, 2026
@coderabbitai

coderabbitai Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Adds a typed tax-code reference and surfaces per-charge tax configuration: introduces TaxCodeReference/BillingTaxCodeReference, adds BillingTaxConfig.tax_code, exposes tax_config on ChargeBase, updates generated API types and converters/wrappers, and adds unit + persistence tests. (50 words)

Changes

Charge tax config + tax-code reference

Layer / File(s) Summary
Type/Schema (data shape)
api/spec/packages/aip/src/billing/tax.tsp, api/spec/packages/aip/src/customers/credits/grant.tsp, api/spec/packages/aip/src/customers/charges/charges.tsp
Adds TaxCodeReference { id: Shared.ULID }; adds tax_code?: TaxCodeReference to Billing.TaxConfig (takes precedence over deprecated tax_code_id/provider codes); retypes CreditGrantTaxConfig.tax_code; adds ChargeBase.tax_config?: Billing.TaxConfig (Lifecycle.Read).
Generated API types
api/v3/api.gen.go
Adds exported TaxCodeReference/BillingTaxCodeReference; BillingTaxConfig gains TaxCode *BillingTaxCodeReference while keeping deprecated TaxCodeId; adds TaxConfig *BillingTaxConfig to BillingFlatFeeCharge and BillingUsageBasedCharge; updates swagger blob.
Core conversion logic
api/v3/handlers/customers/charges/convert.go, api/v3/handlers/customers/credits/convert.go
Adds convertTaxCodeConfigToAPI to map domain productcatalog.TaxCodeConfig → api.BillingTaxConfig (nil for empty); flat-fee/usage charge converters populate TaxConfig; credit-grant converter uses BillingTaxCodeReference.
Wiring / higher-level mapping
api/v3/handlers/billingprofiles/convert.go
Introduces toAPIBillingTaxConfigFull / fromAPIBillingTaxConfigFull wrappers to synchronize deprecated TaxCode ↔ TaxCodeId; goverter mapping updated to ignore automated TaxCode mapping; workflow conversions switched to wrappers.
Tests
api/v3/handlers/customers/charges/convert_test.go, openmeter/billing/charges/service/taxcode_test.go
Adds TestConvertTaxCodeConfigToAPI (table-driven cases) and TestTaxConfigInListCharges asserting presence/nil of TaxConfig across created charges; adds pagination import used by the test.
sequenceDiagram
    participant Client as rgba(20,120,255,0.5) Client
    participant API as rgba(0,200,120,0.5) HTTP Handler
    participant Conv as rgba(255,180,0,0.5) Converter
    participant Service as rgba(200,60,200,0.5) Billing Service / DB

    Client->>API: request charge/list
    API->>Conv: build API model (convertTaxCodeConfigToAPI / wrappers)
    Conv->>Service: read/write intent with TaxCodeID/Behavior
    Service-->>Conv: stored intent (may include TaxCodeID/Behavior)
    Conv-->>API: API model with TaxConfig (TaxCode ref + Behavior)
    API-->>Client: response includes tax_config
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

area/api

Suggested reviewers

  • tothandras
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding tax configuration fields (tax id and tax behavior) to the charges list API, which aligns with the substantial updates across spec, generated code, and handlers.
Docstring Coverage ✅ Passed Docstring coverage is 84.62% which is sufficient. The required threshold is 80.00%.
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/add-tax_id-and-tax-behavior-to-charges-list-api

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@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)
api/spec/packages/aip/src/customers/charges/charges.tsp (1)

157-185: 💤 Low value

Could we give the nested tax-code reference a name?

The inline { id: Shared.ULID } shape will show up as an anonymous nested type in generated schemas/clients, which makes this payload a bit harder to document and reuse. A tiny named model would keep the contract clearer if tax-code references pop up elsewhere later.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/charges/charges.tsp` around lines 157 -
185, The inline anonymous shape for tax_code should be replaced with a named
model: add a new model (e.g., TaxCodeRef or Billing.TaxCodeRef) with a single
id: Shared.ULID field and appropriate `@summary/`@friendlyName, then update
ChargeTaxConfig.tax_code to reference that model instead of the inline `{ id:
Shared.ULID }`; ensure the new model is declared in the same file or a shared
models file so generated schemas/clients will use the named type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@api/spec/packages/aip/src/customers/charges/charges.tsp`:
- Around line 157-185: The inline anonymous shape for tax_code should be
replaced with a named model: add a new model (e.g., TaxCodeRef or
Billing.TaxCodeRef) with a single id: Shared.ULID field and appropriate
`@summary/`@friendlyName, then update ChargeTaxConfig.tax_code to reference that
model instead of the inline `{ id: Shared.ULID }`; ensure the new model is
declared in the same file or a shared models file so generated schemas/clients
will use the named type.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb426364-e022-41dd-ba09-07f6e537772d

📥 Commits

Reviewing files that changed from the base of the PR and between 0da1145 and 72d2bd6.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (5)
  • api/spec/packages/aip/src/customers/charges/charges.tsp
  • api/v3/api.gen.go
  • api/v3/handlers/customers/charges/convert.go
  • api/v3/handlers/customers/charges/convert_test.go
  • openmeter/billing/charges/service/taxcode_test.go

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/spec/packages/aip/src/billing/tax.tsp`:
- Around line 49-64: The docs are ambiguous about precedence between the
deprecated tax_code_id and the new tax_code; update the comments for tax_code
(and/or tax_code_id) to explicitly state which field wins when both are provided
(e.g., "When both tax_code and tax_code_id are provided, tax_code takes
precedence and tax_code_id is ignored"), and mirror the same precedence rule
already documented for stripe.code so generated docs match runtime conversion
behavior; locate the fields tax_code_id, tax_code, and the TaxCodeReference
comment in this file and add the single-sentence precedence clarification.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 26ecfd23-f497-4f03-92ff-1f2176595ee5

📥 Commits

Reviewing files that changed from the base of the PR and between 72d2bd6 and 03c8ef9.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (9)
  • api/spec/packages/aip/src/billing/tax.tsp
  • api/spec/packages/aip/src/customers/charges/charges.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/api.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/customers/charges/convert.go
  • api/v3/handlers/customers/charges/convert_test.go
  • api/v3/handlers/customers/credits/convert.go
  • openmeter/billing/charges/service/taxcode_test.go
✅ Files skipped from review due to trivial changes (4)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • openmeter/billing/charges/service/taxcode_test.go
  • api/v3/handlers/customers/credits/convert.go
  • api/v3/api.gen.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/v3/handlers/customers/charges/convert_test.go
  • api/v3/handlers/customers/charges/convert.go

@mark-vass-konghq
mark-vass-konghq force-pushed the feat/add-tax_id-and-tax-behavior-to-charges-list-api branch from 03c8ef9 to d2c748f Compare May 4, 2026 10:21

@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)
openmeter/billing/charges/service/taxcode_test.go (1)

785-792: 💤 Low value

Tiny nit: taxConfigFlat and taxConfigUsage are structurally identical

Both configs share the same InclusiveTaxBehavior and point to the same tcID. Using distinct behaviors (e.g., ExclusiveTaxBehavior for the usage-based charge) would make the per-type assertions independently meaningful rather than both asserting the same expected value.

✨ Suggested tweak
 taxConfigFlat := &productcatalog.TaxCodeConfig{
     Behavior:  lo.ToPtr(productcatalog.InclusiveTaxBehavior),
     TaxCodeID: &tcID,
 }
 taxConfigUsage := &productcatalog.TaxCodeConfig{
-    Behavior:  lo.ToPtr(productcatalog.InclusiveTaxBehavior),
+    Behavior:  lo.ToPtr(productcatalog.ExclusiveTaxBehavior),
     TaxCodeID: &tcID,
 }

…and update the usage-based assertion at line 881:

-s.Equal(productcatalog.InclusiveTaxBehavior, *ub.Intent.TaxConfig.Behavior)
+s.Equal(productcatalog.ExclusiveTaxBehavior, *ub.Intent.TaxConfig.Behavior)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 785 - 792,
taxConfigFlat and taxConfigUsage are identical; change taxConfigUsage to use a
different behavior (e.g., set Behavior to
lo.ToPtr(productcatalog.ExclusiveTaxBehavior) while keeping TaxCodeID as &tcID)
so the two configs differ, and update the corresponding usage-based assertion
that checks tax behavior (the assertion referencing taxConfigUsage) to expect
ExclusiveTaxBehavior instead of InclusiveTaxBehavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 785-792: taxConfigFlat and taxConfigUsage are identical; change
taxConfigUsage to use a different behavior (e.g., set Behavior to
lo.ToPtr(productcatalog.ExclusiveTaxBehavior) while keeping TaxCodeID as &tcID)
so the two configs differ, and update the corresponding usage-based assertion
that checks tax behavior (the assertion referencing taxConfigUsage) to expect
ExclusiveTaxBehavior instead of InclusiveTaxBehavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3fbc5012-7e79-4ab1-8c30-0a87b2699f5d

📥 Commits

Reviewing files that changed from the base of the PR and between 03c8ef9 and d2c748f.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (9)
  • api/spec/packages/aip/src/billing/tax.tsp
  • api/spec/packages/aip/src/customers/charges/charges.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/api.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/customers/charges/convert.go
  • api/v3/handlers/customers/charges/convert_test.go
  • api/v3/handlers/customers/credits/convert.go
  • openmeter/billing/charges/service/taxcode_test.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/spec/packages/aip/src/customers/charges/charges.tsp
  • api/v3/handlers/customers/charges/convert_test.go
  • api/v3/handlers/customers/charges/convert.go
  • api/spec/packages/aip/src/billing/tax.tsp

@mark-vass-konghq
mark-vass-konghq force-pushed the feat/add-tax_id-and-tax-behavior-to-charges-list-api branch from d2c748f to bb5f6fc Compare May 4, 2026 12:57

@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)
openmeter/billing/charges/service/taxcode_test.go (1)

784-792: 💤 Low value

Minor: taxConfigFlat and taxConfigUsage share the same &tcID pointer

Both configs point to the same underlying variable:

tcID := tc.ID
taxConfigFlat := &productcatalog.TaxCodeConfig{TaxCodeID: &tcID, ...}
taxConfigUsage := &productcatalog.TaxCodeConfig{TaxCodeID: &tcID, ...}

Since tcID is never mutated after construction this is harmless, but if either config is ever extended with different values you'd have a surprise. Since both configs are identical here anyway, you can simplify with a helper or just one variable:

✨ Optional cleanup
-	tcID := tc.ID
-	taxConfigFlat := &productcatalog.TaxCodeConfig{
-		Behavior:  lo.ToPtr(productcatalog.InclusiveTaxBehavior),
-		TaxCodeID: &tcID,
-	}
-	taxConfigUsage := &productcatalog.TaxCodeConfig{
-		Behavior:  lo.ToPtr(productcatalog.InclusiveTaxBehavior),
-		TaxCodeID: &tcID,
-	}
+	newTaxConfig := func() *productcatalog.TaxCodeConfig {
+		id := tc.ID
+		return &productcatalog.TaxCodeConfig{
+			Behavior:  lo.ToPtr(productcatalog.InclusiveTaxBehavior),
+			TaxCodeID: &id,
+		}
+	}
+	taxConfigFlat := newTaxConfig()
+	taxConfigUsage := newTaxConfig()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 784 - 792,
taxConfigFlat and taxConfigUsage both reference the same &tcID pointer which can
cause surprises if one is later mutated; change the construction so each
TaxCodeConfig gets its own pointer (or reuse a single config/ helper) by either
creating separate local copies like tcIDFlat := tc.ID and tcIDUsage := tc.ID and
using &tcIDFlat / &tcIDUsage for productcatalog.TaxCodeConfig, or collapse to a
single shared config variable if they must remain identical; update references
to taxConfigFlat and taxConfigUsage accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 784-792: taxConfigFlat and taxConfigUsage both reference the same
&tcID pointer which can cause surprises if one is later mutated; change the
construction so each TaxCodeConfig gets its own pointer (or reuse a single
config/ helper) by either creating separate local copies like tcIDFlat := tc.ID
and tcIDUsage := tc.ID and using &tcIDFlat / &tcIDUsage for
productcatalog.TaxCodeConfig, or collapse to a single shared config variable if
they must remain identical; update references to taxConfigFlat and
taxConfigUsage accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 31f41027-40fe-4b59-9de9-b50bfcb94152

📥 Commits

Reviewing files that changed from the base of the PR and between d2c748f and bb5f6fc.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (9)
  • api/spec/packages/aip/src/billing/tax.tsp
  • api/spec/packages/aip/src/customers/charges/charges.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/api.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/customers/charges/convert.go
  • api/v3/handlers/customers/charges/convert_test.go
  • api/v3/handlers/customers/credits/convert.go
  • openmeter/billing/charges/service/taxcode_test.go
✅ Files skipped from review due to trivial changes (3)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/handlers/customers/credits/convert.go
  • api/v3/handlers/billingprofiles/convert.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/spec/packages/aip/src/billing/tax.tsp

@borbelyr-kong
borbelyr-kong self-requested a review May 5, 2026 09:14
borbelyr-kong
borbelyr-kong previously approved these changes May 5, 2026
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/add-tax_id-and-tax-behavior-to-charges-list-api branch from 211d41c to b7f8ad8 Compare May 5, 2026 13:21
@mark-vass-konghq
mark-vass-konghq enabled auto-merge (squash) May 5, 2026 14:31
@mark-vass-konghq
mark-vass-konghq merged commit 5f7ad28 into main May 5, 2026
26 of 27 checks passed
@mark-vass-konghq
mark-vass-konghq deleted the feat/add-tax_id-and-tax-behavior-to-charges-list-api branch May 5, 2026 14:36

This branch was previously deployed

1 inactive deployment
dev — 3385aa39 Deployed May 5, 2026 by tothandras via Migration Checks #14089
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.

3 participants