Skip to main content

FacilitatorClient

Struct FacilitatorClient 

Source
pub struct FacilitatorClient { /* private fields */ }
Available on crate feature server only.
Expand description

A client for communicating with a remote x402 facilitator.

Implementations§

Source§

impl FacilitatorClient

Source

pub const DEFAULT_SUPPORTED_CACHE_TTL: Duration

Default /supported cache TTL used by Self::try_new.

Source

pub const DEFAULT_TIMEOUT: Duration

Default per-request timeout. Aligned with the Go/TS clients (30 s).

Source

pub const fn base_url(&self) -> &Url

Returns the base URL used by this client.

Source

pub const fn verify_url(&self) -> &Url

Returns the computed ./verify URL relative to Self::base_url.

Source

pub const fn settle_url(&self) -> &Url

Returns the computed ./settle URL relative to Self::base_url.

Source

pub const fn supported_url(&self) -> &Url

Returns the computed ./supported URL relative to Self::base_url.

Source

pub const fn timeout(&self) -> Option<&Duration>

Returns the configured timeout, if any.

Source

pub const fn supported_cache(&self) -> Option<&SupportedCache>

Returns the supported cache when one is configured.

Source

pub fn try_new( base_url: Url, ) -> Result<FacilitatorClient, FacilitatorClientError>

Constructs a new FacilitatorClient from a base URL.

Sets up ./verify, ./settle, and ./supported relative to the base. /supported is cached for Self::DEFAULT_SUPPORTED_CACHE_TTL. Call Self::without_supported_cache to disable.

§Errors

Returns FacilitatorClientError if URL construction fails.

Source

pub fn with_auth<F, Fut>(self, create: F) -> FacilitatorClient
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, FacilitatorClientError>> + Send + 'static,

Sets the callback that produces path-keyed facilitator auth headers.

The JSON object must be keyed by verify, settle, supported, and optionally bazaar. A flat headers object is rejected when headers are resolved.

Source

pub const fn with_timeout(self, timeout: Duration) -> FacilitatorClient

Sets a timeout for all future requests.

Source

pub fn with_supported_cache_ttl(self, ttl: Duration) -> FacilitatorClient

Enables TTL caching of the /supported response.

Source

pub fn without_supported_cache(self) -> FacilitatorClient

Disables caching for the /supported endpoint.

Source

pub async fn create_auth_headers( &self, path: &str, ) -> Result<HeaderMap, FacilitatorClientError>

Resolves authentication headers for one facilitator path.

§Errors

Returns FacilitatorClientError::FlatAuthHeaders when the callback result has no object-valued verify/settle/supported/bazaar key and some value is not a header object. Returns FacilitatorClientError::InvalidAuthHeader when a path object has a non-string or illegal header. Propagates callback Err values.

Source

pub async fn verify( &self, request: &VerifyRequest, ) -> Result<VerifyResponse, FacilitatorError>

Sends a POST /verify request to the facilitator.

2xx or non-2xx Invalid JSON is Ok. Non-2xx Valid JSON, timeout, connect/DNS/TLS/body failures, and malformed 2xx bodies are FacilitatorError::Transport (502).

§Errors

Returns FacilitatorError for transport, auth, or parse failures.

Source

pub async fn settle( &self, request: &SettleRequest, ) -> Result<SettleResponse, FacilitatorError>

Sends a POST /settle request to the facilitator.

2xx Success may have transaction: "". Non-2xx Failure is Ok. Non-2xx Success is Transport.

§Errors

Returns FacilitatorError for transport, auth, or parse failures.

Source

pub async fn supported(&self) -> Result<SupportedResponse, FacilitatorError>

Sends a GET /supported request to the facilitator. Results are cached when a TTL is configured (the default).

§Errors

Returns FacilitatorError if the HTTP request fails.

Source

pub async fn supported_inner( &self, ) -> Result<SupportedResponse, FacilitatorError>

GET /supported with 429-only retries, bypassing the TTL cache.

§Errors

Returns FacilitatorError if the HTTP request fails or the body is not a well-formed SupportedResponse.

Trait Implementations§

Source§

impl Clone for FacilitatorClient

Source§

fn clone(&self) -> FacilitatorClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FacilitatorClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Facilitator for FacilitatorClient

Source§

async fn verify( &self, request: VerifyRequest, ) -> Result<VerifyResponse, FacilitatorError>

Verifies a payment payload against its requirements.
Source§

async fn settle( &self, request: SettleRequest, ) -> Result<SettleResponse, FacilitatorError>

Settles a previously verified payment on-chain. Read more
Source§

async fn supported(&self) -> Result<SupportedResponse, FacilitatorError>

Returns the payment kinds supported by this facilitator.
Source§

impl TryFrom<&str> for FacilitatorClient

Source§

type Error = FacilitatorClientError

The type returned in the event of a conversion error.
Source§

fn try_from( value: &str, ) -> Result<FacilitatorClient, <FacilitatorClient as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl TryFrom<String> for FacilitatorClient

Source§

type Error = FacilitatorClientError

The type returned in the event of a conversion error.
Source§

fn try_from( value: String, ) -> Result<FacilitatorClient, <FacilitatorClient as TryFrom<String>>::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynFacilitator for T
where T: Facilitator + ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more