Skip to content

feat(billing): Add deposit ledger protos to the contract service - #480

Draft
volokluev wants to merge 1 commit into
mainfrom
volo/contract-deposit-ledger
Draft

volokluev wants to merge 1 commit into
mainfrom
volo/contract-deposit-ledger

Conversation

@volokluev

@volokluev volokluev commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Adds a ledger package under services/contract for an organization's prepaid credit (for example, Seer credit bought through an off-cycle invoice). It sits in its own folder to keep it apart from the contract and invoice messages.

ContractService in getsentry implements these endpoints. It is implemented in getsentry/getsentry#22745.

Messages

  • LedgerEntry and LedgerEntryType: deposit, withdrawal, adjustment. Amounts are signed. counts_toward_balance is false only for a deposit whose invoice is unpaid.
  • RecordLedgerDeposit: links credit to an off-cycle invoice. Allows one deposit per invoice, so a retry returns the existing entry.
  • RecordLedgerWithdrawal: never makes the balance negative. If the balance is too small, allow_partial picks between withdrawing what is there and withdrawing nothing. shortfall_cents tells the caller what it still has to bill. Retries are safe through idempotency_key.
  • RecordLedgerAdjustment: a manual correction, positive or negative. A refund is a negative adjustment. The refunded invoice stays paid, so its deposit still counts and the adjustment cancels it out.
  • GetLedgerBalance: the balance, plus deposits still waiting on payment.
  • ListLedgerEntries: newest first, with a cursor.

Not covered here

Disputes. The plan is for a dispute to suspend the whole account through account status. The ledger does not model it.

Add a ledger package under services/contract for an organization's
prepaid credit accounts. It defines LedgerEntry and endpoints to record
deposits, withdrawals, and adjustments, read the balance, and list
entries.

A deposit is tied to an off-cycle invoice and counts toward the balance
only once that invoice is paid. A withdrawal never makes the balance
negative; callers choose between a partial withdrawal and none.
@github-actions

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedOct 23, 2026, 11:23 PM

This branch has not been deployed

No deployments
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.

1 participant