Skip to main content

Module server

Module server 

Source
Available on crate feature server only.
Expand description

Axum middleware for enforcing x402 payments on protected routes (V2-only).

This middleware validates incoming payment headers using a configured x402 facilitator, verifies the payment, executes the request, and settles valid payments after successful execution. If the handler returns an error (4xx/5xx), settlement is skipped.

Returns a 402 Payment Required response if the request lacks a valid payment.

See X402Middleware for full configuration options. For low-level interaction with the facilitator, see facilitator::FacilitatorClient.

§Settlement Modes

Re-exports§

pub use facilitator::FacilitatorClient;
pub use facilitator::FacilitatorClientError;
pub use hooks::DynPaygateHooks;
pub use hooks::PaygateHooks;
pub use hooks::ProtectedRequestOutcome;
pub use middleware::SettlementMode;
pub use middleware::X402Layer;
pub use middleware::X402Middleware;
pub use paygate::Paygate;
pub use paygate::PaygateBuilder;
pub use paygate::PaygateError;
pub use paygate::ResourceTemplate;
pub use paygate::VerifiedPayment;
pub use paygate::X402_EXPOSED_HEADERS;
pub use paygate::ensure_expose_headers;
pub use paygate::reason_to_status;
pub use paygate::settlement_to_header;
pub use pricing::DynamicPriceTags;
pub use pricing::PriceTagSource;
pub use pricing::StaticPriceTags;
pub use tracker::BackgroundSettlementTracker;
pub use upto::SETTLEMENT_OVERRIDES_HEADER;
pub use upto::UptoActualAmount;
pub use upto::marshal_settlement_overrides;
pub use upto::resolve_response_settlement_amount;
pub use upto::set_settlement_overrides;
pub use upto::set_settlement_overrides_on_response;
pub use upto::settlement_overrides_header_name;
pub use upto::take_settlement_overrides_header;

Modules§

facilitator
A r402_core::facilitator::Facilitator implementation that interacts with a remote x402 Facilitator over HTTP.
hooks
Paygate-level lifecycle hooks.
middleware
Axum middleware for enforcing x402 payments on protected routes.
paygate
Core payment gate logic for enforcing x402 payments (V2-only).
pricing
Price tag sources for the x402 payment gate.
tracker
In-flight counter for background settlement tasks.
upto
HTTP-level support for the x402 upto scheme (partial settlement).

Structs§

SettlementOverrides
Official partial-settlement overrides (amount atomic / percent / dollar). Official wire shape for partial settlement (upto billing by actual usage).