Skip to content

feat: v3 invoice api actions#4671

Merged
borosr merged 4 commits into
mainfrom
feat/v3-invoice-api-actions
Jul 15, 2026
Merged

feat: v3 invoice api actions#4671
borosr merged 4 commits into
mainfrom
feat/v3-invoice-api-actions

Conversation

@borosr

@borosr borosr commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
  • feat: invoice actions v3 endpoints
  • fix: fix route value

Overview

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

  • New Features
    • Added invoice workflow actions: advance, approve, retry, and snapshot quantities.
    • Added invoice deletion support.
    • Exposed the actions and deletion across server endpoints and the JavaScript client/SDK (including new SDK methods).
  • Bug Fixes
    • Improved error classification and validation behavior for unsupported/non-standard invoice types.
  • Documentation
    • Expanded the JavaScript client README “Invoices” operations table with the new endpoints.
  • Tests
    • Added end-to-end coverage for v3 invoice actions and deletion, including expected success and failure cases.

Greptile Summary

This PR adds v3 invoice workflow actions and exposes them through the API clients. The main changes are:

  • New advance, approve, retry, and snapshot-quantities invoice endpoints.
  • Server route wiring and handler dispatch for the new invoice actions.
  • Generated OpenAPI, Go SDK, and JavaScript SDK updates.
  • Expanded e2e coverage for invoice actions and deletion.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
api/v3/handlers/billinginvoices/action.go Adds the shared v3 invoice action handler and maps each action to the billing service.
api/v3/server/routes.go Connects the new generated invoice action routes to the billing invoice handler.
api/v3/handlers/billinginvoices/convert.go Splits standard invoice conversion into a reusable helper for action responses.
api/spec/packages/aip/src/invoices/operations.tsp Defines the new invoice action operations in the TypeSpec API source.
api/v3/client/invoices.go Adds generated Go SDK methods for the new invoice actions.
e2e/billinginvoices_v3_test.go Adds end-to-end coverage for the new invoice action workflows.

Reviews (13): Last reviewed commit: "fix: response descriptions" | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - AGENTS.md (source)
  • Context used - api/spec/AGENTS.md (source)

@borosr
borosr requested a review from a team as a code owner July 9, 2026 07:47
@coderabbitai

coderabbitai Bot commented Jul 9, 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 adds invoice deletion and four workflow actions—advance, approve, retry, and snapshot quantities—across API contracts, Go server routing and handlers, billing validation, the JavaScript SDK, and end-to-end tests.

Changes

Invoice lifecycle operations

Layer / File(s) Summary
API contracts and client models
api/spec/packages/aip/src/invoices/operations.tsp, api/spec/packages/aip-client-javascript/src/models/...
Defines delete and workflow endpoints with matching request, response, plain, and wire schemas.
Generated server surface
api/v3/api.gen.go
Adds server interfaces, middleware, route registrations, stubs, and Swagger entries for the new endpoints.
Invoice handlers and service integration
api/v3/handlers/billinginvoices/..., api/v3/server/routes.go, openmeter/billing/service/invoice.go
Implements deletion, dispatches workflow actions to billing services, converts standard invoices, wires server routes, and classifies validation errors.
Invoice deletion validation
openmeter/billing/invoice_validator.go, openmeter/billing/httpdriver/...
Exports deletion-support validators and updates the HTTP driver and tests to use them.
JavaScript client operations
api/spec/packages/aip-client-javascript/src/funcs/invoices.ts, src/sdk/invoices.ts, README.md
Adds typed delete and action functions, SDK methods, response validation/conversion, and documentation.
End-to-end invoice coverage
e2e/billinginvoices_v3_test.go, e2e/v3helpers_test.go
Adds helpers and tests covering successful operations, repeated requests, status restrictions, and gathering-invoice rejection.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Server
  participant BillingInvoiceHandler
  participant InvoiceService

  Client->>Server: POST /billing/invoices/{invoiceId}/approve
  Server->>BillingInvoiceHandler: ProgressInvoice(approve)
  BillingInvoiceHandler->>InvoiceService: ApproveInvoice(invoiceId)
  InvoiceService-->>BillingInvoiceHandler: Updated invoice
  BillingInvoiceHandler->>BillingInvoiceHandler: ToAPIStandardInvoice(invoice)
  BillingInvoiceHandler-->>Client: 200 JSON invoice
Loading

Possibly related PRs

Suggested labels: area/billing

Suggested reviewers: tothandras, rolosp, turip, GAlexIHU, borbelyr-kong

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.59% 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main theme of adding v3 invoice API actions, though it omits the new delete endpoint.
✨ 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 feat/v3-invoice-api-actions

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.

@borosr
borosr requested review from rolosp, tothandras and turip July 9, 2026 07:48
@borosr borosr self-assigned this Jul 9, 2026
@borosr borosr added kind/feature New feature or request release-note/feature Release note: Exciting New Features labels Jul 9, 2026

@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: 2

🧹 Nitpick comments (1)
api/spec/packages/aip/src/invoices/operations.tsp (1)

154-238: 📐 Maintainability & Code Quality | 🔵 Trivial

Nice and consistent op definitions — one doc nit.

All four new actions (advance, approve, retry, snapshotQuantities) follow the existing pattern nicely (route/operationId/summary/extensions all lining up with what ends up in api.gen.go). One thing worth calling out to users: the actual handler (action.go) rejects non-standard invoices with a validation error, but none of these four doc comments mention that these actions only apply to standard invoices. Might be worth a quick line in each doc comment so API consumers aren't surprised.

As per path instructions, "The declared API should be accurate, in parity with the actual implementation, and easy to understand for the user."

🤖 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 `@api/spec/packages/aip/src/invoices/operations.tsp` around lines 154 - 238,
Add a brief note to each of the four invoice action doc comments on advance,
approve, retry, and snapshotQuantities to state that these actions only apply to
standard invoices. Update the comments in the invoice operations definition so
they match the behavior enforced by action.go and make the API contract clearer
for consumers.

Source: Path instructions

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

Inline comments:
In `@api/spec/packages/aip-client-javascript/README.md`:
- Line 206: Update the snapshotQuantities operation description in
operations.tsp so it consistently uses “usage-based” instead of “usage based” in
both places; this will flow through to the generated README entry for
client.invoices.snapshotQuantities and keep the docs wording consistent.

In `@api/v3/handlers/billinginvoices/action.go`:
- Around line 71-99: The ProgressInvoice action handler is doing an unnecessary
preflight invoice fetch and type check before dispatching to the service. Remove
the GetInvoiceById lookup and the standard-invoice guard from the action flow in
billinginvoices/action.go, and let the existing service methods (ApproveInvoice,
RetryInvoice, AdvanceInvoice, ForceCollectInvoice) own invoice loading and
validation so the handler only switches on action and returns the service
result.

---

Nitpick comments:
In `@api/spec/packages/aip/src/invoices/operations.tsp`:
- Around line 154-238: Add a brief note to each of the four invoice action doc
comments on advance, approve, retry, and snapshotQuantities to state that these
actions only apply to standard invoices. Update the comments in the invoice
operations definition so they match the behavior enforced by action.go and make
the API contract clearer for consumers.
🪄 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: 2c508cdb-c323-40f5-a42d-d964ff3c760c

📥 Commits

Reviewing files that changed from the base of the PR and between 4ccc0e8 and 9ea3106.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (11)
  • api/spec/packages/aip-client-javascript/README.md
  • api/spec/packages/aip-client-javascript/src/funcs/invoices.ts
  • api/spec/packages/aip-client-javascript/src/models/operations/invoices.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip-client-javascript/src/sdk/invoices.ts
  • api/spec/packages/aip/src/invoices/operations.tsp
  • api/v3/api.gen.go
  • api/v3/handlers/billinginvoices/action.go
  • api/v3/handlers/billinginvoices/convert.go
  • api/v3/handlers/billinginvoices/handler.go
  • api/v3/server/routes.go

Comment thread api/spec/packages/aip-client-javascript/README.md Outdated
Comment thread api/v3/handlers/billinginvoices/action.go Outdated
@borosr
borosr force-pushed the feat/v3-invoice-api-actions branch from 1e40dba to 08677be Compare July 10, 2026 14:10

@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 (2)
e2e/billinginvoices_v3_test.go (2)

1696-1699: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the typed status constant instead of hardcoded strings.

Line 1636 correctly uses string(billing.StandardInvoiceStatusDraftWaitingAutoApproval), but the manual-approval-needed check (line 1698) and the waiting-for-collection check (line 1959) fall back to raw string literals. Using the equivalent typed constants keeps these assertions resilient to any future renaming of the extended-status values.

♻️ Suggested fix (pending confirming the exact constant names)
-		require.Equal(t, "draft.manual_approval_needed", invoice.StatusDetails.ExtendedStatus)
+		require.Equal(t, string(billing.StandardInvoiceStatusDraftManualApprovalNeeded), invoice.StatusDetails.ExtendedStatus)
-		require.Equal(t, "draft.waiting_for_collection", invoice.StatusDetails.ExtendedStatus)
+		require.Equal(t, string(billing.StandardInvoiceStatusDraftWaitingForCollection), invoice.StatusDetails.ExtendedStatus)

Also applies to: 1957-1960

🤖 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 `@e2e/billinginvoices_v3_test.go` around lines 1696 - 1699, Replace the
hardcoded extended-status strings in the manual-approval assertion near invoice
creation and the waiting-for-collection assertion with the corresponding typed
constants from the billing package, converting them with string(...) as needed.
Use the existing StandardInvoiceStatusDraftWaitingAutoApproval pattern to
identify the appropriate constants and update both checks.

1058-1081: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

These two blocks could reuse the new pinBillingProfileFromDefault helper.

TestV3DeleteBillingInvoice and TestV3AdvanceBillingInvoice both manually inline the create-profile-then-pin-to-customer sequence, while the later tests in this same file (Approve/Retry/Snapshot) use the pinBillingProfileFromDefault helper added at line 1487. Worth retrofitting these two for consistency and less duplication, since the helper exists precisely to avoid this.

Also applies to: 1292-1310

🤖 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 `@e2e/billinginvoices_v3_test.go` around lines 1058 - 1081, The
TestV3DeleteBillingInvoice and TestV3AdvanceBillingInvoice setup blocks
duplicate the create-and-pin billing profile flow. Replace each inline profile
creation and UpdateCustomerBilling call with the existing
pinBillingProfileFromDefault helper, passing the appropriate customer and
configuration callback to disable AutoAdvance and set SendInvoice collection
behavior.
🤖 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 `@e2e/billinginvoices_v3_test.go`:
- Around line 1696-1699: Replace the hardcoded extended-status strings in the
manual-approval assertion near invoice creation and the waiting-for-collection
assertion with the corresponding typed constants from the billing package,
converting them with string(...) as needed. Use the existing
StandardInvoiceStatusDraftWaitingAutoApproval pattern to identify the
appropriate constants and update both checks.
- Around line 1058-1081: The TestV3DeleteBillingInvoice and
TestV3AdvanceBillingInvoice setup blocks duplicate the create-and-pin billing
profile flow. Replace each inline profile creation and UpdateCustomerBilling
call with the existing pinBillingProfileFromDefault helper, passing the
appropriate customer and configuration callback to disable AutoAdvance and set
SendInvoice collection behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 820e9446-ac65-4bea-a050-94d9ae9cc52c

📥 Commits

Reviewing files that changed from the base of the PR and between 1e40dba and 08677be.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (18)
  • api/spec/packages/aip-client-javascript/README.md
  • api/spec/packages/aip-client-javascript/src/funcs/invoices.ts
  • api/spec/packages/aip-client-javascript/src/models/operations/invoices.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip-client-javascript/src/sdk/invoices.ts
  • api/spec/packages/aip/src/invoices/operations.tsp
  • api/v3/api.gen.go
  • api/v3/handlers/billinginvoices/action.go
  • api/v3/handlers/billinginvoices/convert.go
  • api/v3/handlers/billinginvoices/delete.go
  • api/v3/handlers/billinginvoices/handler.go
  • api/v3/server/routes.go
  • e2e/billinginvoices_v3_test.go
  • e2e/v3helpers_test.go
  • openmeter/billing/httpdriver/invoice.go
  • openmeter/billing/httpdriver/invoice_test.go
  • openmeter/billing/invoice_validator.go
  • openmeter/billing/service/invoice.go
✅ Files skipped from review due to trivial changes (2)
  • api/spec/packages/aip-client-javascript/src/models/operations/invoices.ts
  • api/v3/api.gen.go
🚧 Files skipped from review as they are similar to previous changes (9)
  • api/v3/handlers/billinginvoices/handler.go
  • openmeter/billing/service/invoice.go
  • api/v3/handlers/billinginvoices/convert.go
  • api/v3/server/routes.go
  • api/spec/packages/aip-client-javascript/src/sdk/invoices.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/v3/handlers/billinginvoices/action.go
  • e2e/v3helpers_test.go
  • api/spec/packages/aip/src/invoices/operations.tsp

@borosr
borosr force-pushed the feat/v3-invoice-api-actions branch 4 times, most recently from c9a845d to 822cf2a Compare July 14, 2026 14:08
Comment thread api/spec/packages/aip/src/invoices/operations.tsp Outdated
@borosr
borosr force-pushed the feat/v3-invoice-api-actions branch from 8ff7ddb to 0f98e64 Compare July 15, 2026 11:08
turip
turip previously approved these changes Jul 15, 2026
@borosr
borosr merged commit 0d94d28 into main Jul 15, 2026
30 checks passed
@borosr
borosr deleted the feat/v3-invoice-api-actions branch July 15, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature New feature or request release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants