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:
before_payment_creation— Can abort withHookDecision::Abort.- Payment signing executes
after_payment_creation(on success) — Observes the signed headers.on_payment_creation_failure(on error) — Can recover withFailureRecovery::Recovered.
Provided Methods§
Sourcefn before_payment_creation<'a>(
&'a self,
_ctx: &'a PaymentCreationContext,
) -> BoxFuture<'a, HookDecision>
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.
Sourcefn after_payment_creation<'a>(
&'a self,
_ctx: &'a PaymentCreationContext,
_headers: &'a HeaderMap,
) -> BoxFuture<'a, ()>
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.
Sourcefn on_payment_creation_failure<'a>(
&'a self,
_ctx: &'a PaymentCreationContext,
_error: &'a str,
) -> BoxFuture<'a, FailureRecovery<HeaderMap>>
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.