pub struct PaymentGateLayer { /* private fields */ }Expand description
Tower Layer that adds x402 payment gating to an inner service.
§Example
use std::sync::Arc;
use std::collections::HashMap;
use r402::server::X402ResourceServer;
use r402_http::server::PaymentGateLayer;
use r402_http::types::{RouteConfig, PaymentOption};
let server = Arc::new(X402ResourceServer::new());
let mut routes = HashMap::new();
routes.insert("GET /weather".into(), RouteConfig::single(PaymentOption {
scheme: "exact".into(),
pay_to: "0xRecipient".into(),
price: serde_json::json!("0.01"),
network: "eip155:8453".into(),
max_timeout_seconds: None,
extra: None,
}));
let layer = PaymentGateLayer::new(server, routes);
// Apply to Axum router: app.layer(layer)Corresponds to Python SDK’s x402HTTPResourceServer.
Implementations§
Source§impl PaymentGateLayer
impl PaymentGateLayer
Sourcepub fn new(server: Arc<X402ResourceServer>, routes: RoutesConfig) -> Self
pub fn new(server: Arc<X402ResourceServer>, routes: RoutesConfig) -> Self
Creates a new payment gate layer with the given server and routes.
Sourcepub fn with_paywall(
server: Arc<X402ResourceServer>,
routes: RoutesConfig,
paywall_config: PaywallConfig,
) -> Self
pub fn with_paywall( server: Arc<X402ResourceServer>, routes: RoutesConfig, paywall_config: PaywallConfig, ) -> Self
Creates a layer with optional paywall configuration.
Source§impl PaymentGateLayer
impl PaymentGateLayer
Sourcepub fn validate_routes(&self) -> Vec<RouteValidationError>
pub fn validate_routes(&self) -> Vec<RouteValidationError>
Validates all route configurations against the server’s registered schemes and facilitator support.
Should be called after X402ResourceServer::initialize to catch
misconfigurations early (at startup) rather than at request time.
Returns an empty Vec if all routes are valid.
Corresponds to Python SDK’s _validate_route_configuration in
x402_http_server_base.py.
Trait Implementations§
Source§impl Clone for PaymentGateLayer
impl Clone for PaymentGateLayer
Source§fn clone(&self) -> PaymentGateLayer
fn clone(&self) -> PaymentGateLayer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PaymentGateLayer
impl Debug for PaymentGateLayer
Auto Trait Implementations§
impl Freeze for PaymentGateLayer
impl !RefUnwindSafe for PaymentGateLayer
impl Send for PaymentGateLayer
impl Sync for PaymentGateLayer
impl Unpin for PaymentGateLayer
impl !UnwindSafe for PaymentGateLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more