Repository navigation
feat(billing): Add deposit ledger protos to the contract service #480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
volokluev
wants to merge
6
commits into
main
Choose a base branch
from
volo/contract-deposit-ledger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ed6ed3
feat(billing): Add deposit ledger protos to the contract service
volokluev 8edd330
chore: Regenerate Rust bindings
getsantry[bot] 0f48db6
ref(billing): Let ledger withdrawals make the balance negative
volokluev 2f4de25
chore: Regenerate Rust bindings
getsantry[bot] fee3981
feat(billing): Write ledger deposits with their off-cycle invoice
volokluev 2070ff1
chore: Regenerate Rust bindings
getsantry[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
proto/sentry_protos/billing/v1/services/contract/ledger/v1/endpoint_get_ledger_balance.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package sentry_protos.billing.v1.services.contract.ledger.v1; | ||
|
|
||
| message GetLedgerBalanceRequest { | ||
| uint64 organization_id = 1; | ||
| string account_id = 2; | ||
| } | ||
|
|
||
| message GetLedgerBalanceResponse { | ||
| // Paid deposits minus withdrawals, plus adjustments. Zero for an account | ||
| // with no entries. | ||
| int64 balance_cents = 1; | ||
| // Deposits whose invoices are not paid yet. Not part of balance_cents. | ||
| int64 pending_deposit_cents = 2; | ||
| } |
22 changes: 22 additions & 0 deletions
22
...o/sentry_protos/billing/v1/services/contract/ledger/v1/endpoint_list_ledger_entries.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package sentry_protos.billing.v1.services.contract.ledger.v1; | ||
|
|
||
| import "sentry_protos/billing/v1/services/contract/ledger/v1/ledger_entry.proto"; | ||
|
|
||
| // Lists an account's entries, newest first. | ||
| message ListLedgerEntriesRequest { | ||
| uint64 organization_id = 1; | ||
| string account_id = 2; | ||
| // Return only entries older than this one. Pass next_cursor from the | ||
| // previous page. | ||
| optional uint64 before_entry_id = 3; | ||
| // Defaults to 100 when zero; capped at 1000. | ||
| uint32 limit = 4; | ||
| } | ||
|
|
||
| message ListLedgerEntriesResponse { | ||
| repeated LedgerEntry entries = 1; | ||
| // Unset on the last page. | ||
| optional uint64 next_cursor = 2; | ||
| } |
29 changes: 29 additions & 0 deletions
29
...try_protos/billing/v1/services/contract/ledger/v1/endpoint_record_ledger_adjustment.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package sentry_protos.billing.v1.services.contract.ledger.v1; | ||
|
|
||
| import "sentry_protos/billing/v1/services/contract/ledger/v1/ledger_entry.proto"; | ||
|
|
||
| // Records a manual correction. A refund is a negative adjustment: the refunded | ||
| // invoice stays paid, so its deposit still counts and the adjustment cancels | ||
| // it. | ||
| message RecordLedgerAdjustmentRequest { | ||
| uint64 organization_id = 1; | ||
| string account_id = 2; | ||
| // Must not be zero. | ||
| int64 amount_cents = 3; | ||
| // Unique per organization and account_id. A repeated key writes nothing | ||
| // and returns the existing entry with created=false. | ||
| string idempotency_key = 4; | ||
| // Required, so that the ledger shows why the balance changed. | ||
| string description = 5; | ||
| // The invoice the adjustment refers to, e.g. the refunded one. | ||
| optional uint64 invoice_id = 6; | ||
| } | ||
|
|
||
| message RecordLedgerAdjustmentResponse { | ||
| LedgerEntry entry = 1; | ||
| bool created = 2; | ||
| // The balance after the adjustment. | ||
| int64 balance_cents = 3; | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...try_protos/billing/v1/services/contract/ledger/v1/endpoint_record_ledger_withdrawal.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package sentry_protos.billing.v1.services.contract.ledger.v1; | ||
|
|
||
| import "sentry_protos/billing/v1/services/contract/ledger/v1/ledger_entry.proto"; | ||
|
|
||
| // Takes credit out of an account. The full amount is always withdrawn, even | ||
| // when that makes the balance negative. | ||
| message RecordLedgerWithdrawalRequest { | ||
| uint64 organization_id = 1; | ||
| string account_id = 2; | ||
| // Must be positive. | ||
| uint64 amount_cents = 3; | ||
| // Unique per organization and account_id. A repeated key writes nothing | ||
| // and returns the existing entry with created=false. | ||
| string idempotency_key = 4; | ||
| // The contract whose usage the withdrawal pays for. Defaults to the | ||
| // organization's current contract. | ||
| optional uint64 contract_id = 5; | ||
| optional string description = 6; | ||
| } | ||
|
|
||
| message RecordLedgerWithdrawalResponse { | ||
| LedgerEntry entry = 1; | ||
| bool created = 2; | ||
| // The balance after the withdrawal. | ||
| int64 balance_cents = 3; | ||
| } |
16 changes: 16 additions & 0 deletions
16
proto/sentry_protos/billing/v1/services/contract/ledger/v1/ledger_deposit.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package sentry_protos.billing.v1.services.contract.ledger.v1; | ||
|
|
||
| // Credit that an off-cycle invoice buys. The deposit is written in the same | ||
| // transaction as the invoice, so a crash can not leave a charge without its | ||
| // credit. It counts toward the balance once the invoice is paid. | ||
| message LedgerDeposit { | ||
| // 1 to 64 characters. | ||
| string account_id = 1; | ||
| // The credit bought. Must be positive and at most the invoice's total | ||
| // before tax. | ||
| uint64 amount_cents = 2; | ||
| // At most 256 characters. | ||
| optional string description = 3; | ||
| } |
37 changes: 37 additions & 0 deletions
37
proto/sentry_protos/billing/v1/services/contract/ledger/v1/ledger_entry.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package sentry_protos.billing.v1.services.contract.ledger.v1; | ||
|
|
||
| import "google/protobuf/timestamp.proto"; | ||
|
|
||
| enum LedgerEntryType { | ||
| LEDGER_ENTRY_TYPE_UNSPECIFIED = 0; | ||
| // Credit bought through an invoice. It adds to the balance only after the | ||
| // invoice is paid. | ||
| LEDGER_ENTRY_TYPE_DEPOSIT = 1; | ||
| // Credit used, e.g. the credit-only usage tallied at contract rollover. | ||
| LEDGER_ENTRY_TYPE_WITHDRAWAL = 2; | ||
| // A manual correction, such as a refund. It can be positive or negative. | ||
| LEDGER_ENTRY_TYPE_ADJUSTMENT = 3; | ||
| } | ||
|
|
||
| // One row of an account's transaction history. Entries are append-only. | ||
| message LedgerEntry { | ||
| uint64 id = 1; | ||
| uint64 organization_id = 2; | ||
| // Identifies one balance among the organization's accounts, e.g. "seer". | ||
| string account_id = 3; | ||
| // The organization's contract when the entry was written, if it had one. | ||
| optional uint64 contract_id = 4; | ||
| // Signed: deposits are positive, withdrawals are negative. | ||
| int64 amount_cents = 5; | ||
| LedgerEntryType entry_type = 6; | ||
| // The invoice that pays for a deposit, or that an adjustment refers to. | ||
| optional uint64 invoice_id = 7; | ||
| google.protobuf.Timestamp date_added = 8; | ||
| optional string idempotency_key = 9; | ||
| optional string description = 10; | ||
| // False only for a deposit whose invoice is not paid yet. Such an entry | ||
| // does not count toward the balance. | ||
| bool counts_toward_balance = 11; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to be clear, manual corrections means this endpoint would be called through _admin or something internal right