Skip to content

feat(billing): Add invoice, list charges, and rollover endpoints#211

Merged
noahsmartin merged 2 commits intomainfrom
billing/invoice-and-charge-endpoints
Apr 23, 2026
Merged

feat(billing): Add invoice, list charges, and rollover endpoints#211
noahsmartin merged 2 commits intomainfrom
billing/invoice-and-charge-endpoints

Conversation

@noahsmartin
Copy link
Copy Markdown
Contributor

@noahsmartin noahsmartin commented Apr 22, 2026

Add new endpoints and supporting messages for the charge and contract services:

  • charge: ListChargesForInvoice
    This is used by the invoicer when we get uncharged invoices. We first list all charges to confirm that it is really not charged yet (in case the charge was written but we failed to update the invoice model)

  • contract: GetInvoice, GetUnchargedInvoices, RolloverContract
    get invoice is used by the invoicer in an async task that will be provided just the invoice_id
    get uncharged invoices is the main mechanism for charging (and also retrying) similar to how we get contracts that aren't invoiced
    rollover contract is the API for creating a new billing period and creating the invoice model (done as one operation to avoid race conditions/satisfy FK requirements)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

The latest Buf updates on your PR. Results from workflow ci / buf-checks (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedApr 22, 2026, 8:51 PM

@noahsmartin noahsmartin force-pushed the billing/invoice-and-charge-endpoints branch 2 times, most recently from d78268e to e9db102 Compare April 22, 2026 20:18
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ac36a32. Configure here.

Add new endpoints and supporting messages for the charge and contract
services:

- charge: ListChargesForInvoice
- contract: GetInvoice, GetUnchargedInvoices, RolloverContract
- contract: Invoice and InvoiceLineItem shared messages

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@noahsmartin noahsmartin force-pushed the billing/invoice-and-charge-endpoints branch from ac36a32 to 3001778 Compare April 22, 2026 20:50
Copy link
Copy Markdown
Member

@volokluev volokluev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall a good start


// True if additional matching invoices existed beyond max_items and were
// not included in this response.
bool truncated = 2;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just return what the next offset should be

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to it, but the other pagination API already uses this "truncated" boolean. Seems like matching it is better than starting a new standard

Copy link
Copy Markdown
Member

@brendanhsentry brendanhsentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are all the invoice protos in the contract directory?

message Invoice {
uint64 invoice_id = 1;
repeated InvoiceLineItem line_items = 2;
// Not just a sum of line items since there may be credit applied
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently, we create invoice line items for credits which I think makes it easier to understand everything that went into the final amount billed.

Copy link
Copy Markdown
Contributor Author

@noahsmartin noahsmartin Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be like an overpayment that gets applied, not a typical "credit". Maybe those will also end up in the line items too though

@volokluev
Copy link
Copy Markdown
Member

why are all the invoice protos in the contract directory?

we're keeping the data in the contract service because the contract is highly tied to the billing period either way. The invoice service just mediates the tallying and charging but doesn't store anything

@noahsmartin noahsmartin merged commit 363e6f1 into main Apr 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants