Skip to main content

Crate rustlavel_billing

Crate rustlavel_billing 

Source
Expand description

rustlavel-billing: subscriptions where the customer pays, rather than is charged.

In a market where cards are rare and virtual accounts, QRIS and e-wallets are how people pay, a subscription cannot pull money. It can only ask: each cycle it raises an invoice, presents a way to pay it, and waits. This crate is that loop.

§The cycle

  1. Billing::subscribe creates the subscription, its first invoice, and a charge at the payment gateway — the VA number or QR the customer pays.
  2. The gateway’s webhook says paid. The application’s receiver calls Billing::on_paid, which marks the invoice paid, extends the subscription by one cycle, and credits the plan’s allowance through the ledger — idempotently, under the invoice’s id, so a retried webhook credits once.
  3. Billing::tick runs on a schedule. When a period ends it raises the next invoice and charge; while an invoice is unpaid past the period’s end the subscription is in grace; when grace runs out it is suspended. tick returns the Reminders that fell due, and the application sends them — this crate does not know what the mail should say.

§What this does not do

Overage. A customer who wants more credits than the plan gives buys a top-up, which is one charge and one Ledger::top_up and needs no machinery here. Proration on plan change is a policy decision this crate does not make for you: Billing::change_plan takes effect at the next cycle.

Re-exports§

pub use billing::Billing;
pub use billing::Paid;
pub use billing::Reminder;
pub use billing::ReminderKind;
pub use billing::Tick;
pub use plan::Cycle;
pub use plan::Plan;
pub use schema::CreateBillingTables;
pub use schema::create_tables;
pub use schema::drop_tables;
pub use subscription::Invoice;
pub use subscription::InvoiceStatus;
pub use subscription::Subscriber;
pub use subscription::Subscription;
pub use subscription::SubscriptionStatus;

Modules§

billing
The loop: raise, wait, extend.
plan
What is being sold.
schema
The three tables.
subscription
A customer on a plan, and the invoices that keep them there.

Structs§

Instructions
What the customer needs in order to pay. Which fields are set depends on the channel.
Money

Enums§

Channel
Error
Every failure the framework itself can produce.

Type Aliases§

Result
The framework-wide result type.