Skip to main content

Crate autumn_billing

Crate autumn_billing 

Source
Expand description

§autumn-billing

Subscription billing for autumn-web applications: hosted checkout, the customer portal, a webhook-fed local mirror of billing state, a plan gate, and durable dunning. Stripe ships first behind a provider-neutral BillingProvider trait.

§Quick start

ⓘ
use autumn_billing::prelude::*;

let billing = BillingConfig::from_autumn_toml("autumn.toml")?;
let plans = PlanCatalog::new().plan(
    Plan::new("pro", "Pro", "price_123", Money::from_minor(1999, Currency::USD), BillingInterval::Month)
        .entitlement("export"),
);
autumn_web::app()
    .plugin(BillingPlugin::new().config(billing).plans(&plans))
    .run()
    .await;

Declare the webhook receiver in autumn.toml so SignedWebhook verifies it and CSRF exempts it. max_body_bytes is required: the webhook default is 1 MiB, a large provider event can exceed it, and boot fails below 4 MiB:

[[security.webhooks.endpoints]]
name = "billing"
path = "/billing/webhook"
provider = "stripe"
secret_env = "STRIPE_WEBHOOK_SECRET"
max_body_bytes = 4194304

Gate a route:

ⓘ
struct Pro;
impl PlanRequirement for Pro {
    fn rule() -> PlanRule { PlanRule::plan("pro") }
}

#[get("/reports")]
async fn reports(_pro: Entitled<Pro>) -> &'static str { "ok" }

Re-exports§

pub use config::BillingConfig;
pub use config::DunningPolicy;
pub use config::ExhaustionAction;
pub use config::SecretString;
pub use config::StripeConfig;
pub use error::BillingError;
pub use event::BillingEvent;
pub use event::BillingEventKind;
pub use event::CheckoutSnapshot;
pub use event::InvoiceSnapshot;
pub use event::SubscriptionSnapshot;
pub use gate::Billing;
pub use gate::Entitled;
pub use gate::PlanRequirement;
pub use gate::PlanRule;
pub use gate::SubscriptionView;
pub use hooks::BillingHooks;
pub use hooks::NoHooks;
pub use model::Customer;
pub use model::DunningAttempt;
pub use model::DunningState;
pub use model::Invoice;
pub use model::InvoiceStatus;
pub use model::ProviderId;
pub use model::Subscription;
pub use model::SubscriptionStatus;
pub use money::Currency;
pub use money::Money;
pub use money::MoneyError;
pub use plan::BillingInterval;
pub use plan::Plan;
pub use plan::PlanCatalog;
pub use plan::PlanId;
pub use provider::BillingProvider;
pub use provider::CheckoutRequest;
pub use provider::CustomerRequest;
pub use provider::HostedSession;
pub use provider::PaymentAttemptOutcome;
pub use provider::PortalRequest;
pub use reconcile::ReconcileOutcome;
pub use store::DbBillingStore;
pub use store::BillingStore;
pub use store::MemoryBillingStore;

Modules§

config
[billing] configuration.
dunning
Durable retries for failed payments.
error
Error type for the billing plugin.
event
Provider-neutral billing events.
gate
The plan gate: read local mirror state, default deny.
hooks
Application callbacks for billing state changes.
model
Provider-neutral mirror records.
money
Exact money: integer minor units plus an explicit currency.
notify
Notifications (#1148) and hook fan-out for billing events.
plan
Plans: the products a customer can subscribe to.
prelude
Common imports for configuring and mounting the plugin.
provider
The provider seam. Stripe ships first; the trait never names Stripe types.
reconcile
Apply a BillingEvent to the mirror, once.
routes
Plugin routes, mounted under config.route_prefix.
store
The mirror store: customers, subscriptions, invoices, the event ledger and the dunning schedule.

Structs§

BillingPlugin
The billing plugin. Mount with app.plugin(BillingPlugin::new()...).
BillingService
Runtime handle installed on AppState by the plugin.
StripeProvider
The Stripe provider.

Constants§

EVENT_CLAIM_STALE_AFTER
How long a ledger claim in processing blocks redelivery before it is treated as abandoned.
MIGRATIONS
Embedded migrations for the mirror tables. Registered by BillingPlugin.