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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! # 402fly Client
//!
//! HTTP client library for the 402fly payment protocol with automatic payment handling.
//!
//! This library provides two client implementations:
//! - **X402Client**: Explicit control over payment flow
//! - **X402AutoClient**: Automatic payment handling
//!
//! ## Features
//!
//! - Automatic detection of 402 Payment Required responses
//! - Seamless payment creation and transaction broadcasting
//! - Configurable payment limits and retry behavior
//! - Support for GET and POST requests
//!
//! ## Example: Explicit Client
//!
//! ```rust,no_run
//! use fly402_client::X402Client;
//! use solana_sdk::signature::Keypair;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let keypair = Keypair::new(); // Load your keypair
//! let client = X402Client::new(keypair, None);
//!
//! // Make request
//! let response = client.get("https://api.example.com/premium-data").await?;
//!
//! // Check if payment is required
//! if client.is_payment_required(&response) {
//! // Parse payment request
//! let payment_request = client.parse_payment_request(response).await?;
//!
//! // Create payment
//! let authorization = client.create_payment(&payment_request).await?;
//!
//! // Retry with payment
//! let response = client.get_with_auth(
//! "https://api.example.com/premium-data",
//! &authorization
//! ).await?;
//!
//! println!("Got data: {:?}", response.text().await?);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Example: Auto Client
//!
//! ```rust,no_run
//! use fly402_client::{X402AutoClient, AutoClientOptions};
//! use solana_sdk::signature::Keypair;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let keypair = Keypair::new(); // Load your keypair
//!
//! // Configure options
//! let options = AutoClientOptions {
//! max_payment_amount: "5.0".to_string(),
//! auto_retry: true,
//! max_retries: 3,
//! };
//!
//! let client = X402AutoClient::new(keypair, None, Some(options));
//!
//! // Make request - payment is handled automatically!
//! let response = client.get("https://api.example.com/premium-data").await?;
//! println!("Got data: {:?}", response.text().await?);
//!
//! Ok(())
//! }
//! ```
// Re-export commonly used types
pub use ;
pub use X402Client;
// Re-export core types for convenience
pub use ;
/// Library version
pub const VERSION: &str = env!;