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
SettlementMode::Sequential(default): verify → execute → settle.SettlementMode::Concurrent: verify → (settle ∥ execute) → await settle.
Re-exports§
pub use layer::SettlementMode;pub use layer::X402LayerBuilder;pub use layer::X402Middleware;pub use paygate::Paygate;pub use paygate::PaygateBuilder;pub use paygate::PaygateError;pub use paygate::ResourceTemplate;pub use paygate::VerificationError;pub use paygate::VerifiedPayment;pub use paygate::settlement_to_header;pub use pricing::DynamicPriceTags;pub use pricing::PriceTagSource;pub use pricing::StaticPriceTags;
Modules§
- facilitator
- A
r402::facilitator::Facilitatorimplementation that interacts with a remote x402 Facilitator over HTTP. - layer
- 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.