pub struct PaymentClient<S = FirstMatch> { /* private fields */ }Expand description
Buyer payment client.
Implementations§
Source§impl<S: PaymentSelector> PaymentClient<S>
impl<S: PaymentSelector> PaymentClient<S>
Sourcepub async fn extension_headers(
&self,
payment_required: &PaymentRequired,
request_url: &str,
) -> HeaderMap
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>
impl<S: PaymentSelector> PaymentClient<S>
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.
Source§impl PaymentClient<FirstMatch>
impl PaymentClient<FirstMatch>
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty client with FirstMatch selection and default $1 spend controls.
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 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_spend_controls(self, controls: SpendControls) -> Self
pub fn with_spend_controls(self, controls: SpendControls) -> Self
Enables spend controls with the given configuration.
Sourcepub fn disable_spend_controls(self) -> Self
pub fn disable_spend_controls(self) -> Self
Disables all spend controls (any asset, no caps).
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 with_extension(self, extension: impl ClientExtension + 'static) -> Self
pub fn with_extension(self, extension: impl ClientExtension + 'static) -> Self
Registers a client extension (enrich and/or HTTP 402 header 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.
Sourcepub fn extension_count(&self) -> usize
pub fn extension_count(&self) -> usize
Number of registered client extensions.
Source§impl<S: PaymentSelector> PaymentClient<S>
impl<S: PaymentSelector> PaymentClient<S>
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.
§Errors
Propagates selection, signing, and before-hook abort errors.
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 fn select_candidate<'a>(
&self,
candidates: &'a [PaymentCandidate],
) -> Result<&'a PaymentCandidate, ClientError>
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.