Skip to content

fix(billing): map invoice subscription ids onto the documented fields - #5464

Merged
tothandras merged 2 commits into
openmeterio:mainfrom
pcbeingused333:fix/c1833-invoice-subscription-item-ids
Nov 13, 2026
Merged

tothandras merged 2 commits into
openmeterio:mainfrom
pcbeingused333:fix/c1833-invoice-subscription-item-ids

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5454

Overview

mapSubscriptionReferencesToAPI copied SubscriptionID into subscription.item.id and ItemID into subscription.subscription.id. The domain model and the OpenAPI spec keep those ids apart (subscription is the subscription, item is the subscription item), and the v3 converter (billingcommon/convert.go) already writes them that way. Standard invoice lines and gathering invoice lines both use this mapper, so both responses had the two ids swapped.

The fix writes ItemID to item.id and SubscriptionID to subscription.id. The phase id and billing period are unchanged.

Behaviour change

Both the invoice API response and invoice.* webhook payloads change: subscription.subscription.id and subscription.item.id now carry the right ids. Anyone who worked around the swap should remove the workaround. Webhook events created before this change keep the swapped ids in their stored payloads.

Notes for reviewer

TestMapSubscriptionReferencesToAPIKeepsIdsOnDocumentedFields checks the three ids, the billing period, and that a nil reference stays nil. It fails on the swapped subscription id before the change and passes after:

go test -mod=readonly -count=1 ./openmeter/billing/httpdriver/ -run TestMapSubscriptionReferencesToAPIKeepsIdsOnDocumentedFields

This change was prepared with the help of an AI coding assistant and submitted by the account owner.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Corrects the subscription and item IDs returned on invoice lines.

  • Invoice lines now show subscription and item IDs in their matching fields.

Reviews (2) · Last reviewed commit: "test(billing): move subscription referen..." · Reviewed by Greptile

Summary by CodeRabbit

  • Bug Fixes
    • Invoice line references now display the correct subscription and item IDs, while preserving phase details and billing-period boundaries. This improves the accuracy of subscription-related information shown in invoice data.

mapSubscriptionReferencesToAPI wrote the subscription id into item.id and
the item id into subscription.id. Invoice responses therefore swapped the
two identifiers described by InvoiceLineSubscriptionReference.

Fixes openmeterio#5454
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 7, 2026 16:53
@CLAassistant

CLAassistant commented Nov 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The invoice API now maps subscription IDs and item IDs to their corresponding reference fields. A test checks the mapping, billing-period endpoints, and nil input.

Changes: Invoice subscription references

Layer / File(s) Summary
Map and verify subscription reference IDs
openmeter/billing/httpdriver/invoiceline.go, openmeter/billing/httpdriver/invoiceline_test.go
The mapping assigns SubscriptionID to Subscription.Id and ItemID to Item.Id. The test checks these IDs, Phase.Id, billing-period endpoints, and nil input.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: kind/bug, area/billing

Suggested reviewers: turip

Merge Risk: Minimal · up to 3e4e8

The change places invoice subscription references on their documented fields. No merge-blocking issue was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the invoice line mapper now places subscription and item IDs in the documented API fields. The raw summary and PR objectives both confirm the swap fix in mapSubscripti…
Linked Issues check Passed [#5454] The whole-PR diff against the merge base changes one mapper in openmeter/billing/httpdriver/invoiceline.go. mapSubscriptionReferencesToAPI now sets Item.Id from optSub.ItemID and `Subs…
Out of Scope Changes check Passed [#5454] The whole-PR diff touches only two files: the mapper in invoiceline.go (+2/-2) and the new test in invoiceline_test.go (+23). The mapper change is the direct fix for the swapped `subscript…
Full details: Title check

Explanation

The title names the main change: the invoice line mapper now places subscription and item IDs in the documented API fields. The raw summary and PR objectives both confirm the swap fix in mapSubscriptionReferencesToAPI, so the title matches the changeset. It is specific and uses the conventional fix(billing) prefix.

Full details: Linked Issues check

Explanation

[#5454] The whole-PR diff against the merge base changes one mapper in openmeter/billing/httpdriver/invoiceline.go. mapSubscriptionReferencesToAPI now sets Item.Id from optSub.ItemID and Subscription.Id from optSub.SubscriptionID. Before the change these two sources were swapped, which matches the reported bug. The Phase.Id mapping is unchanged. The new test TestMapSubscriptionReferencesToAPIKeepsIdsOnDocumentedFields in invoiceline_test.go asserts Subscription.Id, Phase.Id, Item.Id, the billing period bounds, and that a nil input returns nil. The test file already imports time, require, and timeutil, so the new test has the imports it needs. The mapper is shared by standard and gathering invoice lines, so the fix covers both paths named in the issue. I did not run the test. The result rests on the diff and the file contents at the reviewed head. The previous PASS conclusion still holds for the same reason, and the diff since the previous head does not change it.

Full details: Out of Scope Changes check

Explanation

[#5454] The whole-PR diff touches only two files: the mapper in invoiceline.go (+2/-2) and the new test in invoiceline_test.go (+23). The mapper change is the direct fix for the swapped subscription.subscription.id and subscription.item.id fields. The test covers that fix and the unchanged phase and billing-period mapping. No unrelated code, refactoring, or documentation changes appear in the reviewed diff.

Finishing Touches

Generate unit tests (beta)

  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 369d602 and 3e4e836.

Files selected for processing: 1

  • openmeter/billing/httpdriver/invoiceline_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.

@tothandras tothandras added the release-note/bug-fix Release note: Bug Fixes label Nov 8, 2026

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

Thanks for the contribution, and for the clear write-up and regression test!

The fix looks right. The subscription and item IDs are stored correctly everywhere they're written; only this v1 mapper had them swapped. I checked that the new test fails against the old mapper and passes with the fix.

Before we can merge, please sign the Contributor License Agreement. The license/cla check is still pending.

Two small requests inline:

  • mention in the PR description that invoice.* webhook payloads change too, not only the API response
  • move the test to invoiceline_test.go

The failing OpenAPI codegen and release note label checks aren't caused by this change, so there's nothing to do there.

out := &api.InvoiceLineSubscriptionReference{
Item: api.IDResource{
Id: optSub.SubscriptionID,
Id: optSub.ItemID,

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.

This mapper also builds the payload for invoice.* webhooks (through MapEventInvoiceToAPI in the notification consumer), so the fix changes webhook payloads as well as API responses. Payloads are stored when the event is created, and resends replay the stored copy. Events from before this change will keep the swapped IDs under the same payload version.

Could you add a short note to the PR description saying that both the invoice API response and invoice.* webhook payloads change, and that anyone who worked around the swap should remove the workaround? We'll decide on our side whether it also needs the breaking-change label.

@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Added the note about API responses and invoice.* webhook payloads to the description, and moved the test to invoiceline_test.go.

This comment was drafted with Claude Code.

@tothandras
tothandras enabled auto-merge (squash) November 13, 2026 15:59
@tothandras
tothandras disabled auto-merge November 13, 2026 16:02
@tothandras
tothandras merged commit c693425 into openmeterio:main Nov 13, 2026
27 of 28 checks passed
@tothandras

Copy link
Copy Markdown
Contributor

Thank you, @pcbeingused333, for your contribution!

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.

Invoice API swaps subscription ID and item ID in subscription references

3 participants