pub(crate) mod chains;
pub(crate) mod discovery;
pub mod error;
pub mod fund;
pub mod types;
pub mod wallet;
mod x402;
pub use error::{PayError, PayErrorCode};
pub use types::{DiscoverResult, PayResult, PaymentInfo, Protocol, Service};
pub use wallet::{Account, WalletAccess};
pub async fn pay(
wallet: &dyn WalletAccess,
url: &str,
method: &str,
body: Option<&str>,
) -> Result<PayResult, PayError> {
let client = reqwest::Client::new();
let initial = x402::build_request(&client, url, method, body, None)?
.send()
.await?;
if initial.status().as_u16() != 402 {
let status = initial.status().as_u16();
let text = initial.text().await.unwrap_or_default();
return Ok(PayResult {
protocol: Protocol::X402,
status,
body: text,
payment: None,
});
}
let headers = initial.headers().clone();
let body_402 = initial.text().await.unwrap_or_default();
x402::handle_x402(wallet, url, method, body, &headers, &body_402).await
}
pub async fn discover(
query: Option<&str>,
limit: Option<u64>,
offset: Option<u64>,
) -> Result<DiscoverResult, PayError> {
discovery::discover_all(query, limit, offset).await
}