Skip to main content

ClientHooks

Trait ClientHooks 

Source
pub trait ClientHooks: Send + Sync {
    // Provided methods
    fn before_payment_creation<'a>(
        &'a self,
        _ctx: &'a PaymentCreationContext,
    ) -> BoxFuture<'a, HookDecision> { ... }
    fn after_payment_creation<'a>(
        &'a self,
        _ctx: &'a PaymentCreationContext,
        _headers: &'a HeaderMap,
    ) -> BoxFuture<'a, ()> { ... }
    fn on_payment_creation_failure<'a>(
        &'a self,
        _ctx: &'a PaymentCreationContext,
        _error: &'a str,
    ) -> BoxFuture<'a, FailureRecovery<HeaderMap>> { ... }
}
Available on crate feature client only.
Expand description

Lifecycle hooks for client-side payment creation.

All methods have default no-op implementations. Override only the hooks you need. This trait is dyn-compatible for use in heterogeneous hook lists.

The hook lifecycle mirrors r402::hooks::FacilitatorHooks:

  1. before_payment_creation — Can abort with HookDecision::Abort.
  2. Payment signing executes
  3. after_payment_creation (on success) — Observes the signed headers.
  4. on_payment_creation_failure (on error) — Can recover with FailureRecovery::Recovered.

Provided Methods§

Source

fn before_payment_creation<'a>( &'a self, _ctx: &'a PaymentCreationContext, ) -> BoxFuture<'a, HookDecision>

Called before payment creation.

If any hook returns HookDecision::Abort, payment creation is skipped and the original 402 response is returned to the caller.

Source

fn after_payment_creation<'a>( &'a self, _ctx: &'a PaymentCreationContext, _headers: &'a HeaderMap, ) -> BoxFuture<'a, ()>

Called after successful payment creation.

Receives the signed payment headers. Cannot affect the outcome.

Source

fn on_payment_creation_failure<'a>( &'a self, _ctx: &'a PaymentCreationContext, _error: &'a str, ) -> BoxFuture<'a, FailureRecovery<HeaderMap>>

Called when payment creation fails.

If a hook returns FailureRecovery::Recovered, the provided headers replace the error.

Implementors§