pub struct PaymentClient<S = FirstMatch> { /* private fields */ }Expand description
V2 payment client — scheme registry + selector + policies + hooks.
Mirrors Go/TS x402Client without V1 registration paths.
Implementations§
Source§impl PaymentClient<FirstMatch>
impl PaymentClient<FirstMatch>
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty client with FirstMatch selection.
Source§impl<S> PaymentClient<S>
impl<S> PaymentClient<S>
Sourcepub fn register(self, scheme: impl SchemeClient + 'static) -> Self
pub fn register(self, scheme: impl SchemeClient + 'static) -> Self
Registers a V2 scheme client.
Sourcepub fn with_selector<P: PaymentSelector>(self, selector: P) -> PaymentClient<P>
pub fn with_selector<P: PaymentSelector>(self, selector: P) -> PaymentClient<P>
Replaces the payment selector.
Sourcepub fn with_policy(self, policy: impl PaymentPolicy + 'static) -> Self
pub fn with_policy(self, policy: impl PaymentPolicy + 'static) -> Self
Appends a payment policy (applied in registration order).
Sourcepub fn with_hook(self, hook: impl ClientHooks + 'static) -> Self
pub fn with_hook(self, hook: impl ClientHooks + 'static) -> Self
Registers a client lifecycle hook.
Sourcepub fn scheme_count(&self) -> usize
pub fn scheme_count(&self) -> usize
Number of registered scheme clients.
Sourcepub fn hook_count(&self) -> usize
pub fn hook_count(&self) -> usize
Number of registered hooks.
Source§impl<S: PaymentSelector> PaymentClient<S>
impl<S: PaymentSelector> PaymentClient<S>
Sourcepub fn candidates(
&self,
payment_required: &PaymentRequired,
) -> Vec<PaymentCandidate>
pub fn candidates( &self, payment_required: &PaymentRequired, ) -> Vec<PaymentCandidate>
Collects candidates from every registered scheme client.
Sourcepub async fn create_payment(
&self,
payment_required: &PaymentRequired,
) -> Result<CreatedPayment, ClientError>
pub async fn create_payment( &self, payment_required: &PaymentRequired, ) -> Result<CreatedPayment, ClientError>
Creates a signed payment payload for a 402 challenge.
Runs before/after/failure hooks around selection + signing.
§Errors
Propagates selection, signing, and before-hook abort errors.
Sourcepub async fn handle_payment_response(
&self,
ctx: &PaymentResponseContext,
) -> PaymentResponseResult
pub async fn handle_payment_response( &self, ctx: &PaymentResponseContext, ) -> PaymentResponseResult
Dispatches ClientHooks::on_payment_response for every hook.
First recovered: true wins; remaining hooks still run (instrumentation).
Trait Implementations§
Source§impl<S> Debug for PaymentClient<S>
impl<S> Debug for PaymentClient<S>
Source§impl Default for PaymentClient<FirstMatch>
impl Default for PaymentClient<FirstMatch>
Auto Trait Implementations§
impl<S = FirstMatch> !RefUnwindSafe for PaymentClient<S>
impl<S = FirstMatch> !UnwindSafe for PaymentClient<S>
impl<S> Freeze for PaymentClient<S>where
S: Freeze,
impl<S> Send for PaymentClient<S>where
S: Send,
impl<S> Sync for PaymentClient<S>where
S: Sync,
impl<S> Unpin for PaymentClient<S>where
S: Unpin,
impl<S> UnsafeUnpin for PaymentClient<S>where
S: UnsafeUnpin,
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