Skip to main content

PaymentClient

Struct PaymentClient 

Source
pub struct PaymentClient<S = FirstMatch> { /* private fields */ }
Expand description

Buyer payment client.

Implementations§

Source§

impl<S: PaymentSelector> PaymentClient<S>

Source

pub async fn extension_headers( &self, payment_required: &PaymentRequired, request_url: &str, ) -> HeaderMap

Merges ClientExtension::on_payment_required headers for advertised keys.

request_url is the 402 response URL after redirects. Unadvertised keys are skipped (official HTTP client only invokes a transport hook when extension.key is in paymentRequired.extensions).

Source§

impl<S: PaymentSelector> PaymentClient<S>

Source

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.

Source§

impl PaymentClient<FirstMatch>

Source

pub fn new() -> Self

Empty client with FirstMatch selection and default $1 spend controls.

Source§

impl<S> PaymentClient<S>

Source

pub fn register(self, scheme: impl SchemeClient + 'static) -> Self

Registers a scheme client.

Source

pub fn with_selector<P: PaymentSelector>(self, selector: P) -> PaymentClient<P>

Replaces the payment selector.

Source

pub fn with_spend_controls(self, controls: SpendControls) -> Self

Enables spend controls with the given configuration.

Source

pub fn disable_spend_controls(self) -> Self

Disables all spend controls (any asset, no caps).

Source

pub fn with_policy(self, policy: impl PaymentPolicy + 'static) -> Self

Appends a payment policy (applied in registration order).

Source

pub fn with_hook(self, hook: impl ClientHooks + 'static) -> Self

Registers a client lifecycle hook.

Source

pub fn with_extension(self, extension: impl ClientExtension + 'static) -> Self

Registers a client extension (enrich and/or HTTP 402 header hook).

Source

pub fn scheme_count(&self) -> usize

Number of registered scheme clients.

Source

pub fn hook_count(&self) -> usize

Number of registered hooks.

Source

pub fn extension_count(&self) -> usize

Number of registered client extensions.

Source§

impl<S: PaymentSelector> PaymentClient<S>

Source

pub async fn create_payment( &self, payment_required: &PaymentRequired, ) -> Result<CreatedPayment, ClientError>

Creates a signed payment payload for a 402 challenge.

§Errors

Propagates selection, signing, and before-hook abort errors.

Source§

impl<S: PaymentSelector> PaymentClient<S>

Source

pub fn candidates( &self, payment_required: &PaymentRequired, ) -> Vec<PaymentCandidate>

Collects candidates from every registered scheme client.

Source

pub fn select_candidate<'a>( &self, candidates: &'a [PaymentCandidate], ) -> Result<&'a PaymentCandidate, ClientError>

Applies spend controls, policies, and the selector.

§Errors

Returns ClientError::NoMatchingPaymentOption when nothing remains, ClientError::UnrecognizedPaymentFlow when every candidate has an unknown extra.paymentFlow, or ClientError::SpendControls when spend controls reject every option.

Trait Implementations§

Source§

impl<S> Debug for PaymentClient<S>

Source§

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

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

impl Default for PaymentClient<FirstMatch>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.