Skip to content

fix: invoice pending lines via charges#4059

Merged
turip merged 1 commit into
mainfrom
fix/invoice-pending-lines
Apr 2, 2026
Merged

fix: invoice pending lines via charges#4059
turip merged 1 commit into
mainfrom
fix/invoice-pending-lines

Conversation

@turip
Copy link
Copy Markdown
Member

@turip turip commented Apr 2, 2026

Overview

When credits enabled we need to use charges to invoke InvoicePendingLines until the refactored billing worker's in place.

This patch makes sure that we are using the right backend.

Notes for reviewer

Summary by CodeRabbit

  • Refactor

    • Split invoice pending-lines handling into its own service and updated billing wiring across the server and billing components to improve separation of concerns.
  • Tests

    • Updated test setups and configurations to reflect the new billing service wiring.

@turip turip requested a review from a team as a code owner April 2, 2026 06:50
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

Adds an InvoicePendingLinesService interface and threads it through billing registry, HTTP handlers, workers, router, server, and tests; refactors consumers to call the new dedicated service instead of the broader billing service.

Changes

Cohort / File(s) Summary
Service Interfaces
openmeter/billing/service.go, openmeter/billing/charges/service.go
Added InvoicePendingLinesService; InvoiceService now embeds it. GatheringInvoiceService gains RecalculateGatheringInvoices.
Registry & Server Bootstrap
app/common/billing.go, cmd/server/main.go
Added BillingRegistry.InvoicePendingLinesService() and wired its result into server/router bootstrap.
HTTP Handler
openmeter/billing/httpdriver/handler.go, openmeter/billing/httpdriver/invoice.go
Handler now accepts invoicePendingLinesService and InvoicePendingLinesAction calls the dedicated service instead of the general billing service.
Invoice Collector Worker
openmeter/billing/worker/collect/collect.go
Replaced single billing.Service dependency with GatheringInvoiceService and InvoicePendingLinesService; rewired list/collect fallback calls accordingly.
Subscription Sync Worker
openmeter/billing/worker/subscriptionsync/service/service.go, .../sync.go, .../base_test.go
Config and service now require InvoicePendingLinesService; code paths switched to use the new dependency. Tests updated to provide the new field.
Router & Tests
openmeter/server/router/router.go, openmeter/server/server_test.go, test/.../framework_test.go, test/billing/subscription_test.go
Router config extended with BillingInvoicePendingLines; server and test fixtures wired to supply the new dependency.

Sequence Diagram(s)

(Skipped — changes are wiring/refactor without introducing a new multi-component runtime flow that benefits from sequence visualization.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

release-note/misc, area/billing

Suggested reviewers

  • tothandras
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: invoice pending lines via charges' clearly summarizes the main change: enabling InvoicePendingLines to be invoked via the charges backend when credits are enabled, which is the core objective of this PR.

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

✨ 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 fix/invoice-pending-lines

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.

Base automatically changed from chore/wire-charges to main April 2, 2026 10:02
@turip turip force-pushed the fix/invoice-pending-lines branch from 767cd9e to c8546e4 Compare April 2, 2026 10:03
@turip turip added area/api release-note/misc Miscellaneous changes labels Apr 2, 2026
@turip turip enabled auto-merge (squash) April 2, 2026 10:05
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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/service.go (1)

98-100: RecalculateGatheringInvoices is declared in both InvoiceService and GatheringInvoiceService.

This method appears in both interfaces (lines 98-100 and line 126). Since Service embeds both, this works fine, but it's a bit redundant. If this is intentional (e.g., allowing consumers to depend on either interface), that's cool! If not, you might want to keep it in just one place.

Also applies to: 126-126

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

In `@openmeter/billing/service.go` around lines 98 - 100, The
RecalculateGatheringInvoices method is duplicated in both InvoiceService and
GatheringInvoiceService; decide which interface should own it (e.g., keep it
only in GatheringInvoiceService or only in InvoiceService) and remove the
redundant declaration from the other interface so Service still inherits it by
embedding the correct interface; update any docs/comments to reflect the single
source of truth and ensure callers reference the chosen interface name
(RecalculateGatheringInvoices, InvoiceService, GatheringInvoiceService, Service)
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/service.go`:
- Around line 98-100: The RecalculateGatheringInvoices method is duplicated in
both InvoiceService and GatheringInvoiceService; decide which interface should
own it (e.g., keep it only in GatheringInvoiceService or only in InvoiceService)
and remove the redundant declaration from the other interface so Service still
inherits it by embedding the correct interface; update any docs/comments to
reflect the single source of truth and ensure callers reference the chosen
interface name (RecalculateGatheringInvoices, InvoiceService,
GatheringInvoiceService, Service) accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9a0b1f4a-f51b-414a-8591-7468c1b3ca00

📥 Commits

Reviewing files that changed from the base of the PR and between 767cd9e and c8546e4.

📒 Files selected for processing (14)
  • app/common/billing.go
  • cmd/server/main.go
  • openmeter/billing/charges/service.go
  • openmeter/billing/httpdriver/handler.go
  • openmeter/billing/httpdriver/invoice.go
  • openmeter/billing/service.go
  • openmeter/billing/worker/collect/collect.go
  • openmeter/billing/worker/subscriptionsync/service/base_test.go
  • openmeter/billing/worker/subscriptionsync/service/service.go
  • openmeter/billing/worker/subscriptionsync/service/sync.go
  • openmeter/server/router/router.go
  • openmeter/server/server_test.go
  • test/billing/subscription_test.go
  • test/subscription/framework_test.go
✅ Files skipped from review due to trivial changes (2)
  • openmeter/billing/worker/subscriptionsync/service/base_test.go
  • openmeter/billing/charges/service.go
🚧 Files skipped from review as they are similar to previous changes (8)
  • test/billing/subscription_test.go
  • test/subscription/framework_test.go
  • openmeter/server/server_test.go
  • openmeter/billing/httpdriver/handler.go
  • openmeter/server/router/router.go
  • app/common/billing.go
  • openmeter/billing/worker/subscriptionsync/service/service.go
  • openmeter/billing/worker/collect/collect.go

@turip turip merged commit 32b5260 into main Apr 2, 2026
37 of 41 checks passed
@turip turip deleted the fix/invoice-pending-lines branch April 2, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants