Subscription and billing for Rust applications
| Tier | domain |
| Role | unclassified (baselined) |
| Path | crates/domain/billing |
| Edition | 2021 |
| Targets | domain_billing |
| Public items | 77 across 0 modules |
| Tests | 51 |
What it is for
Subscription and billing library crates for Rust applications.
This crate provides types for managing subscriptions, plans, invoices, and billing cycles.
Capabilities
BillingError
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub enum BillingError |
BillingInterval
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub enum BillingInterval |
BillingInterval :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
BillingInterval :: const fn days(& self) -> u32 |
Invoice:Invoice
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub struct Invoice |
Invoice:apply
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn apply_payment(& mut self, amount : Decimal) -> Result <Decimal> |
Invoice:finalize
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn finalize(& mut self) -> Result <()> |
Invoice:has
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn has_payments(& self) -> bool |
Invoice:is
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn is_past_due(& self) -> bool |
Invoice:mark
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn mark_paid(& mut self) -> Result <()> |
Invoice :: fn mark_uncollectible(& mut self) -> Result <()> |
Invoice:new
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn new(number : impl Into <String>, customer_id : PartyId) -> Self |
Invoice :: fn new_payable(number : impl Into <String>, vendor_id : PartyId) -> Self |
Invoice:payment
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn payment_progress(& self) -> Decimal |
Invoice:recalculate
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn recalculate(& mut self) |
Invoice:void
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn void(& mut self) -> Result <()> |
Invoice:with
Subscription and billing library crates for Rust applications.
| Item |
|---|
Invoice :: fn with_direction(mut self, direction : InvoiceDirection) -> Self |
Invoice :: fn with_line_item(mut self, item : InvoiceLineItem) -> Self |
Invoice :: fn with_tax(mut self, tax : Decimal) -> Self |
Invoice :: fn with_due_date(mut self, due : DateTime <Utc>) -> Self |
Invoice :: fn with_journal_entry(mut self, journal_entry_id : Uuid) -> Self |
InvoiceDirection
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub enum InvoiceDirection |
InvoiceDirection :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
InvoiceLineItem
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub struct InvoiceLineItem |
InvoiceLineItem :: fn new(description : impl Into <String>, quantity : u32, unit_price : Decimal) -> Self |
InvoiceLineItem :: fn with_tax_rate(mut self, tax_rate : Decimal) -> Self |
InvoiceLineItem :: fn with_currency(mut self, currency : impl Into <String>) -> Self |
InvoiceStatus
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub enum InvoiceStatus |
InvoiceStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
InvoiceStatus :: fn can_accept_payment(& self) -> bool |
InvoiceStatus :: fn is_terminal(& self) -> bool |
Payment:Payment
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub struct Payment |
Payment:apply
Subscription and billing library crates for Rust applications.
| Item |
|---|
Payment :: fn apply_to_invoice(& mut self, invoice_id : Uuid, amount : Decimal,) -> Result <PaymentApplication> |
Payment:has
Subscription and billing library crates for Rust applications.
| Item |
|---|
Payment :: fn has_unapplied(& self) -> bool |
Payment:is
Subscription and billing library crates for Rust applications.
| Item |
|---|
Payment :: fn is_fully_applied(& self) -> bool |
Payment:new
Subscription and billing library crates for Rust applications.
| Item |
|---|
Payment :: fn new(payer_id : PartyId, amount : Decimal) -> Self |
Payment:refund
Subscription and billing library crates for Rust applications.
| Item |
|---|
Payment :: fn refund(& mut self) -> Result <()> |
Payment:unapply
Subscription and billing library crates for Rust applications.
| Item |
|---|
Payment :: fn unapply_from_invoice(& mut self, invoice_id : Uuid) -> Result <Decimal> |
Payment:void
Subscription and billing library crates for Rust applications.
| Item |
|---|
Payment :: fn void(& mut self) -> Result <()> |
Payment:with
Subscription and billing library crates for Rust applications.
| Item |
|---|
Payment :: fn with_method(mut self, method : PaymentMethod) -> Self |
Payment :: fn with_reference(mut self, reference : impl Into <String>) -> Self |
Payment :: fn with_currency(mut self, currency : impl Into <String>) -> Self |
Payment :: fn with_received_at(mut self, received_at : DateTime <Utc>) -> Self |
Payment :: fn with_notes(mut self, notes : impl Into <String>) -> Self |
Payment :: fn with_journal_entry(mut self, journal_entry_id : Uuid) -> Self |
PaymentApplication
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub struct PaymentApplication |
PaymentApplication :: fn new(payment_id : Uuid, invoice_id : Uuid, amount : Decimal) -> Self |
PaymentMethod
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub enum PaymentMethod |
PaymentMethod :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
PaymentStatus
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub enum PaymentStatus |
PaymentStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
PaymentStatus :: fn can_apply(& self) -> bool |
PaymentStatus :: fn is_terminal(& self) -> bool |
Plan
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub struct Plan |
Plan :: fn new(slug : impl Into <String>, name : impl Into <String>, price : Decimal, interval : BillingInterval,) -> Self |
Plan :: fn with_description(mut self, desc : impl Into <String>) -> Self |
Plan :: fn with_trial(mut self, days : u32) -> Self |
Plan :: fn with_feature(mut self, feature : impl Into <String>) -> Self |
Plan :: fn with_currency(mut self, currency : impl Into <String>) -> Self |
Plan :: fn monthly_price(& self) -> Decimal |
Result
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub type Result<T>: std::result::Result <T, BillingError> |
Subscription
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub struct Subscription |
Subscription :: fn new(customer_id : PartyId, plan_id : Uuid, period_end : DateTime <Utc>) -> Self |
Subscription :: fn with_trial(mut self, trial_end : DateTime <Utc>) -> Self |
Subscription :: fn cancel(& mut self) -> Result <()> |
Subscription :: fn cancel_now(& mut self) -> Result <()> |
Subscription :: fn pause(& mut self) -> Result <()> |
Subscription :: fn resume(& mut self) -> Result <()> |
Subscription :: fn mark_past_due(& mut self) |
Subscription :: fn is_trialing(& self) -> bool |
Subscription :: fn days_remaining(& self) -> i64 |
SubscriptionStatus
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub enum SubscriptionStatus |
SubscriptionStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
SubscriptionStatus :: fn is_active(& self) -> bool |
SubscriptionStatus :: fn is_terminal(& self) -> bool |
UsageRecord
Subscription and billing library crates for Rust applications.
| Item |
|---|
pub struct UsageRecord |
UsageRecord :: fn new(subscription_id : Uuid, metric : impl Into <String>, quantity : u64) -> Self |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum BillingError | Errors that can occur with billing operations. |
pub type Result<T>: std::result::Result <T, BillingError> | Result type for billing operations. |
pub enum BillingInterval | Billing interval. |
BillingInterval :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
BillingInterval :: const fn days(& self) -> u32 | Returns the number of days in this interval. |
pub struct Plan | A billing plan. |
Plan :: fn new(slug : impl Into <String>, name : impl Into <String>, price : Decimal, interval : BillingInterval,) -> Self | Creates a new plan. |
Plan :: fn with_description(mut self, desc : impl Into <String>) -> Self | Sets the description. |
Plan :: fn with_trial(mut self, days : u32) -> Self | Sets the trial period. |
Plan :: fn with_feature(mut self, feature : impl Into <String>) -> Self | Adds a feature. |
Plan :: fn with_currency(mut self, currency : impl Into <String>) -> Self | Sets the currency. |
Plan :: fn monthly_price(& self) -> Decimal | Returns the monthly equivalent price. |
pub enum SubscriptionStatus | Subscription status. |
SubscriptionStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
SubscriptionStatus :: fn is_active(& self) -> bool | Returns true if the subscription is usable. |
SubscriptionStatus :: fn is_terminal(& self) -> bool | Returns true if the subscription is in a terminal state. |
pub struct Subscription | A subscription. |
Subscription :: fn new(customer_id : PartyId, plan_id : Uuid, period_end : DateTime <Utc>) -> Self | Creates a new subscription |
Subscription :: fn with_trial(mut self, trial_end : DateTime <Utc>) -> Self | Creates a subscription with a trial. |
Subscription :: fn cancel(& mut self) -> Result <()> | Cancels the subscription at period end. |
Subscription :: fn cancel_now(& mut self) -> Result <()> | Cancels the subscription immediately. |
Subscription :: fn pause(& mut self) -> Result <()> | Pauses the subscription. |
Subscription :: fn resume(& mut self) -> Result <()> | Resumes a paused subscription. |
Subscription :: fn mark_past_due(& mut self) | Marks the subscription as past due. |
Subscription :: fn is_trialing(& self) -> bool | Returns true if currently in trial. |
Subscription :: fn days_remaining(& self) -> i64 | Returns days remaining in current period. |
pub enum InvoiceStatus | Invoice status. |
InvoiceStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
InvoiceStatus :: fn can_accept_payment(& self) -> bool | Returns true if the invoice can accept payments. |
InvoiceStatus :: fn is_terminal(& self) -> bool | Returns true if the invoice is in a terminal state. |
pub enum InvoiceDirection | Invoice direction for AR/AP classification. |
InvoiceDirection :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub struct InvoiceLineItem | An invoice line item. |
InvoiceLineItem :: fn new(description : impl Into <String>, quantity : u32, unit_price : Decimal) -> Self | Creates a new line item. |
InvoiceLineItem :: fn with_tax_rate(mut self, tax_rate : Decimal) -> Self | Sets the tax rate and recalculates amounts. |
InvoiceLineItem :: fn with_currency(mut self, currency : impl Into <String>) -> Self | Sets the currency. |
pub struct Invoice | An invoice. |
Invoice :: fn new(number : impl Into <String>, customer_id : PartyId) -> Self | Creates a new invoice (AR by default) |
Invoice :: fn new_payable(number : impl Into <String>, vendor_id : PartyId) -> Self | Creates a new AP invoice (bill/payable). |
Invoice :: fn with_direction(mut self, direction : InvoiceDirection) -> Self | Sets the invoice direction. |
Invoice :: fn with_line_item(mut self, item : InvoiceLineItem) -> Self | Adds a line item and recalculates totals. |
Invoice :: fn with_tax(mut self, tax : Decimal) -> Self | Sets the tax amount (overrides line item taxes). |
Invoice :: fn with_due_date(mut self, due : DateTime <Utc>) -> Self | Sets the due date. |
Invoice :: fn with_journal_entry(mut self, journal_entry_id : Uuid) -> Self | Sets the posted journal entry ID for ledger integration. |
Invoice :: fn recalculate(& mut self) | Recalculates totals from line items. |
Invoice :: fn finalize(& mut self) -> Result <()> | Finalizes the invoice (Draft -> Open). |
Invoice :: fn apply_payment(& mut self, amount : Decimal) -> Result <Decimal> | Applies a payment amount to this invoice |
Invoice :: fn mark_paid(& mut self) -> Result <()> | Marks the invoice as fully paid (bypasses payment tracking). |
Invoice :: fn void(& mut self) -> Result <()> | Voids the invoice. |
Invoice :: fn mark_uncollectible(& mut self) -> Result <()> | Marks the invoice as uncollectible. |
Invoice :: fn is_past_due(& self) -> bool | Returns true if the invoice is past due. |
Invoice :: fn has_payments(& self) -> bool | Returns true if the invoice has any payments applied. |
Invoice :: fn payment_progress(& self) -> Decimal | Returns the payment progress as a percentage (0.0 to 1.0). |
pub struct UsageRecord | Usage record for metered billing. |
UsageRecord :: fn new(subscription_id : Uuid, metric : impl Into <String>, quantity : u64) -> Self | Creates a new usage record. |
pub enum PaymentMethod | Payment method type. |
PaymentMethod :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub enum PaymentStatus | Payment status. |
PaymentStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
PaymentStatus :: fn can_apply(& self) -> bool | Returns true if the payment can be applied to invoices. |
PaymentStatus :: fn is_terminal(& self) -> bool | Returns true if the payment is in a terminal state. |
pub struct Payment | A payment received from a customer. |
Payment :: fn new(payer_id : PartyId, amount : Decimal) -> Self | Creates a new payment. |
Payment :: fn with_method(mut self, method : PaymentMethod) -> Self | Sets the payment method. |
Payment :: fn with_reference(mut self, reference : impl Into <String>) -> Self | Sets the external reference. |
Payment :: fn with_currency(mut self, currency : impl Into <String>) -> Self | Sets the currency. |
Payment :: fn with_received_at(mut self, received_at : DateTime <Utc>) -> Self | Sets the received date. |
Payment :: fn with_notes(mut self, notes : impl Into <String>) -> Self | Sets notes. |
Payment :: fn with_journal_entry(mut self, journal_entry_id : Uuid) -> Self | Sets the posted journal entry ID. |
Payment :: fn apply_to_invoice(& mut self, invoice_id : Uuid, amount : Decimal,) -> Result <PaymentApplication> | Applies a portion of this payment to an invoice |
Payment :: fn unapply_from_invoice(& mut self, invoice_id : Uuid) -> Result <Decimal> | Removes an application from this payment. |
Payment :: fn has_unapplied(& self) -> bool | Returns true if this payment has unapplied funds. |
Payment :: fn is_fully_applied(& self) -> bool | Returns true if this payment is fully applied. |
Payment :: fn void(& mut self) -> Result <()> | Voids this payment. |
Payment :: fn refund(& mut self) -> Result <()> | Marks the payment as refunded. |
pub struct PaymentApplication | A record of payment applied to an invoice. |
PaymentApplication :: fn new(payment_id : Uuid, invoice_id : Uuid, amount : Decimal) -> Self | Creates a new payment application. |
No pub use re-exports: every item above is declared in this crate.
Boundary
Reaches into foundation, identity.
Shares tier domain with 41 other crates: domain-agreements, domain-ai-report, domain-catalog, domain-classify, domain-comments, domain-competitive-intel, domain-contact, domain-conversation-engine, … (41 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | domain |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/domain/billing |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_domain["domain"] --> n_foundation["foundation"] n_domain["domain"] --> n_identity["identity"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `foundation-basemodels` | foundation | no | always |
| `foundation-money` | foundation | no | always |
| `identity-parties` | identity | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
rust_decimal | ^1 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
thiserror | ^2 | — | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio | ^1 | full | no | always |
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_billing["application-billing"] -->|uses| SELF SELF["domain-billing"] SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"] SELF -->|runtime| n_foundation_money["foundation-money"] SELF -->|runtime| n_identity_parties["identity-parties"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | domain_billing | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
BillingError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
1 workspace crate depends on this one: application-billing.
Verification
| Kind | Count |
|---|---|
| Unit tests | 51 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 15 | 0 | 1 |
What the tests establish, by name:
test_billing_interval_days—src/lib.rstest_billing_interval_display—src/lib.rstest_error_display—src/lib.rstest_invoice_apply_payment_full—src/lib.rstest_invoice_apply_payment_overpay_capped—src/lib.rstest_invoice_apply_payment_partial—src/lib.rstest_invoice_apply_payment_to_partially_paid—src/lib.rstest_invoice_cannot_apply_to_draft—src/lib.rstest_invoice_direction—src/lib.rstest_invoice_finalize—src/lib.rstest_invoice_line_item—src/lib.rstest_invoice_line_item_with_tax_rate—src/lib.rstest_invoice_mark_paid—src/lib.rstest_invoice_new—src/lib.rstest_invoice_new_has_direction—src/lib.rstest_invoice_new_payable—src/lib.rstest_invoice_payment_progress—src/lib.rstest_invoice_status_display—src/lib.rstest_invoice_status_is_terminal—src/lib.rstest_invoice_status_partially_paid—src/lib.rstest_invoice_void—src/lib.rstest_invoice_with_journal_entry—src/lib.rstest_invoice_with_line_items—src/lib.rstest_invoice_with_tax—src/lib.rstest_invoice_with_taxed_line_items—src/lib.rstest_payment_apply_to_invoice—src/lib.rstest_payment_apply_to_multiple_invoices—src/lib.rstest_payment_cannot_apply_more_than_available—src/lib.rstest_payment_cannot_apply_to_same_invoice_twice—src/lib.rstest_payment_cannot_void_with_applications—src/lib.rs- _… 21 more_
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 71 | 77 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 71
"No rustdoc detected" : 6
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 1680 |
| Code lines | 1262 |
| Public API items | 77 |
| Public modules | 0 |
| Tests | 51 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 9 |
| Workspace reverse dependencies | 1 |
pie showData
title Public API by kind
"enum" : 7
"method" : 62
"struct" : 7
"type alias" : 1
pie showData
title Rust source composition
"Code" : 1262
"Blank or comment" : 418
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.