open_payments/client/mod.rs
1//! # Open Payments HTTP Client
2//!
3//! This module provides HTTP client functionality for interacting with Open Payments servers.
4//! It includes both authenticated and unauthenticated clients, along with utilities for
5//! making requests, handling authentication, and managing resources.
6//!
7//! ## Client Types
8//!
9//! - [`AuthenticatedClient`] - Client for making authenticated requests with HTTP signatures
10//! - [`UnauthenticatedClient`] - Client for making unauthenticated requests to public endpoints
11//!
12//! ## Configuration
13//!
14//! - [`ClientConfig`] - Configuration for authenticated clients including private key and key ID
15//!
16//! ## Resource APIs
17//!
18//! The client provides access to different Open Payments resources through dedicated APIs:
19//!
20//! - **Wallet Address**: [`mod@wallet_address`] - Get wallet address information
21//! - **Incoming Payments**: [`mod@payments`] - Create and manage incoming payments
22//! - **Outgoing Payments**: [`mod@payments`] - Create and manage outgoing payments
23//! - **Quotes**: [`mod@quotes`] - Create and retrieve payment quotes
24//! - **Grants**: [`mod@grant`] - Request and manage access tokens
25//! - **Tokens**: [`mod@token`] - Manage access tokens
26//!
27//! ## Example Usage
28//!
29//! ```rust,no_run
30//! use open_payments::client::{AuthenticatedClient, ClientConfig, AuthenticatedResources, UnauthenticatedResources};
31//! use open_payments::types::{GrantRequest, AccessTokenRequest, AccessItem, IncomingPaymentAction, CreateIncomingPaymentRequest};
32//!
33//! #[tokio::main]
34//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
35//! // In a real application, you would use actual file paths
36//! let config = ClientConfig {
37//! private_key_path: "path/to/private-key.pem".into(),
38//! key_id: "my-key-id".to_string(),
39//! jwks_path: Some("path/to/jwks.json".into()),
40//! };
41//!
42//! // This would fail in a real scenario if the files don't exist
43//! // but demonstrates the API usage
44//! let client = AuthenticatedClient::new(config)?;
45//!
46//! // Example of how to use the client (would require actual server)
47//! let wallet_address = client.wallet_address().get("https://rafiki.money/alice").await?;
48//!
49//! // Example of how to request a grant
50//! let grant_request = GrantRequest {
51//! access_token: AccessTokenRequest {
52//! access: vec![AccessItem::IncomingPayment {
53//! actions: vec![IncomingPaymentAction::Create, IncomingPaymentAction::Read],
54//! identifier: None,
55//! }],
56//! },
57//! client: "https://rafiki.money/alice".to_string(),
58//! interact: None,
59//! };
60//!
61//! let access_token = client.grant().request(&wallet_address.auth_server, &grant_request).await?;
62//!
63//! // Example of creating a payment request
64//! let resource_server = "https://ilp.rafiki.money";
65//! let access_token = "your-access-token";
66//! let payment_request = CreateIncomingPaymentRequest {
67//! wallet_address: wallet_address.id,
68//! incoming_amount: None,
69//! expires_at: None,
70//! metadata: None,
71//! };
72//!
73//! // This would make actual HTTP requests in a real scenario
74//! let payment = client
75//! .incoming_payments()
76//! .create(resource_server, &payment_request, Some(access_token))
77//! .await?;
78//!
79//! Ok(())
80//! }
81//! ```
82//!
83//! ## Error Handling
84//!
85//! All client operations return a [`Result<T, OpClientError>`] where `OpClientError` provides
86//! detailed error information for different failure scenarios.
87
88pub mod api;
89pub mod config;
90pub mod core;
91pub mod error;
92pub mod grant;
93pub mod payments;
94pub mod quotes;
95pub mod request;
96pub mod token;
97pub mod utils;
98pub mod wallet_address;
99
100pub use api::{AuthenticatedResources, UnauthenticatedResources};
101pub use config::ClientConfig;
102pub use core::{AuthenticatedClient, UnauthenticatedClient};
103pub use core::{AuthenticatedOpenPaymentsClient, BaseClient, UnauthenticatedOpenPaymentsClient};
104pub use error::{OpClientError, Result};