1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Lifecycle hooks for the x402 client payment creation pipeline.
//!
//! Hooks allow applications to intercept and customize the payment
//! creation lifecycle. This mirrors the Go SDK's `client_hooks.go` design,
//! using the same `HookDecision` / `FailureRecovery` enums as the
//! server-side hooks for a consistent API.
//!
//! ## Hook Lifecycle
//!
//! 1. **`before_payment_creation`** — Run before payment creation; can abort it.
//! 2. **Payment signing executes**
//! 3. **`after_payment_creation`** (on success) — Observes the result.
//! 4. **`on_payment_creation_failure`** (on error) — Can recover with substitute headers.
//!
//! ## Usage
//!
//! Implement [`ClientHooks`] with only the hooks you need — all methods
//! have default no-op implementations.
use HeaderMap;
use BoxFuture;
use ;
use proto;
/// Context passed to client payment creation lifecycle hooks.
/// 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`].