-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmod.rs
More file actions
104 lines (102 loc) · 3.98 KB
/
mod.rs
File metadata and controls
104 lines (102 loc) · 3.98 KB
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
102
103
104
//! # Open Payments HTTP Client
//!
//! This module provides HTTP client functionality for interacting with Open Payments servers.
//! It includes both authenticated and unauthenticated clients, along with utilities for
//! making requests, handling authentication, and managing resources.
//!
//! ## Client Types
//!
//! - [`AuthenticatedClient`] - Client for making authenticated requests with HTTP signatures
//! - [`UnauthenticatedClient`] - Client for making unauthenticated requests to public endpoints
//!
//! ## Configuration
//!
//! - [`ClientConfig`] - Configuration for authenticated clients including private key and key ID
//!
//! ## Resource APIs
//!
//! The client provides access to different Open Payments resources through dedicated APIs:
//!
//! - **Wallet Address**: [`mod@wallet_address`] - Get wallet address information
//! - **Incoming Payments**: [`mod@payments`] - Create and manage incoming payments
//! - **Outgoing Payments**: [`mod@payments`] - Create and manage outgoing payments
//! - **Quotes**: [`mod@quotes`] - Create and retrieve payment quotes
//! - **Grants**: [`mod@grant`] - Request and manage access tokens
//! - **Tokens**: [`mod@token`] - Manage access tokens
//!
//! ## Example Usage
//!
//! ```rust,no_run
//! use open_payments::client::{AuthenticatedClient, ClientConfig, AuthenticatedResources, UnauthenticatedResources};
//! use open_payments::types::{GrantRequest, AccessTokenRequest, AccessItem, IncomingPaymentAction, CreateIncomingPaymentRequest};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // In a real application, you would use actual file paths
//! let config = ClientConfig {
//! private_key_path: "path/to/private-key.pem".into(),
//! key_id: "my-key-id".to_string(),
//! jwks_path: Some("path/to/jwks.json".into()),
//! wallet_address_url: "https://rafiki.money/alice".into(),
//! };
//!
//! // This would fail in a real scenario if the files don't exist
//! // but demonstrates the API usage
//! let client = AuthenticatedClient::new(config)?;
//!
//! // Example of how to use the client (would require actual server)
//! let wallet_address = client.wallet_address().get("https://rafiki.money/alice").await?;
//!
//! // Example of how to request a grant
//! let grant_request = GrantRequest::new(
//! AccessTokenRequest {
//! access: vec![AccessItem::IncomingPayment {
//! actions: vec![IncomingPaymentAction::Create, IncomingPaymentAction::Read],
//! identifier: None,
//! }],
//! },
//! None,
//! );
//!
//! let access_token = client.grant().request(&wallet_address.auth_server, &grant_request).await?;
//!
//! // Example of creating a payment request
//! let resource_server = "https://ilp.rafiki.money";
//! let access_token = "your-access-token";
//! let payment_request = CreateIncomingPaymentRequest {
//! wallet_address: wallet_address.id,
//! incoming_amount: None,
//! expires_at: None,
//! metadata: None,
//! };
//!
//! // This would make actual HTTP requests in a real scenario
//! let payment = client
//! .incoming_payments()
//! .create(resource_server, &payment_request, Some(access_token))
//! .await?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Error Handling
//!
//! All client operations return a [`Result<T, OpClientError>`] where `OpClientError` provides
//! detailed error information for different failure scenarios.
pub mod api;
pub mod config;
pub mod core;
pub mod error;
pub mod grant;
pub mod payments;
pub mod quotes;
pub mod request;
pub mod token;
pub mod utils;
pub mod wallet_address;
pub use api::{AuthenticatedResources, UnauthenticatedResources};
pub use config::ClientConfig;
pub use core::{AuthenticatedClient, UnauthenticatedClient};
pub use core::{AuthenticatedOpenPaymentsClient, BaseClient, UnauthenticatedOpenPaymentsClient};
pub use error::{OpClientError, Result};