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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//! Payments API
//!
//! This module provides functionality to initiate payments.
use crate::client::RainClient;
use crate::error::Result;
use crate::models::payments::*;
use uuid::Uuid;
impl RainClient {
/// Initiate a payment for a company
///
/// # Arguments
///
/// * `company_id` - The unique identifier of the company
/// * `request` - The payment initiation request
///
/// # Returns
///
/// Returns an [`InitiatePaymentResponse`] containing the payment address.
///
/// # Errors
///
/// This method can return the following errors:
/// - `400` - Invalid request
/// - `401` - Invalid authorization
/// - `404` - Company not found
/// - `423` - User address is locked
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use rain_sdk::models::payments::InitiatePaymentRequest;
/// use uuid::Uuid;
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let company_id = Uuid::new_v4();
/// let request = InitiatePaymentRequest {
/// amount: 10000, // $100.00 in cents
/// wallet_address: "0x1234...".to_string(),
/// chain_id: Some(1), // Ethereum mainnet
/// };
/// let response = client.initiate_company_payment(&company_id, &request).await?;
/// println!("Payment address: {}", response.address);
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn initiate_company_payment(
&self,
company_id: &Uuid,
request: &InitiatePaymentRequest,
) -> Result<InitiatePaymentResponse> {
let path = format!("/companies/{company_id}/payments");
self.post(&path, request).await
}
/// Initiate a payment for an authorized user tenant
///
/// # Arguments
///
/// * `request` - The payment initiation request
///
/// # Returns
///
/// Returns an [`InitiatePaymentResponse`] containing the payment address.
///
/// # Errors
///
/// This method can return the following errors:
/// - `400` - Invalid request
/// - `401` - Invalid authorization
/// - `423` - User address is locked
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use rain_sdk::models::payments::InitiatePaymentRequest;
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let request = InitiatePaymentRequest {
/// amount: 5000, // $50.00 in cents
/// wallet_address: "0x5678...".to_string(),
/// chain_id: Some(137), // Polygon
/// };
/// let response = client.initiate_payment(&request).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn initiate_payment(
&self,
request: &InitiatePaymentRequest,
) -> Result<InitiatePaymentResponse> {
let path = "/payments";
self.post(path, request).await
}
/// Initiate a payment for a user
///
/// # Arguments
///
/// * `user_id` - The unique identifier of the user
/// * `request` - The payment initiation request
///
/// # Returns
///
/// Returns an [`InitiatePaymentResponse`] containing the payment address.
///
/// # Errors
///
/// This method can return the following errors:
/// - `400` - Invalid request
/// - `401` - Invalid authorization
/// - `404` - User not found
/// - `423` - User address is locked
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use rain_sdk::models::payments::InitiatePaymentRequest;
/// use uuid::Uuid;
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let user_id = Uuid::new_v4();
/// let request = InitiatePaymentRequest {
/// amount: 2500, // $25.00 in cents
/// wallet_address: "0xabcd...".to_string(),
/// chain_id: Some(1),
/// };
/// let response = client.initiate_user_payment(&user_id, &request).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn initiate_user_payment(
&self,
user_id: &Uuid,
request: &InitiatePaymentRequest,
) -> Result<InitiatePaymentResponse> {
let path = format!("/users/{user_id}/payments");
self.post(&path, request).await
}
// ============================================================================
// Blocking Methods
// ============================================================================
/// Initiate a payment for a company (blocking)
#[cfg(feature = "sync")]
pub fn initiate_company_payment_blocking(
&self,
company_id: &Uuid,
request: &InitiatePaymentRequest,
) -> Result<InitiatePaymentResponse> {
let path = format!("/companies/{company_id}/payments");
self.post_blocking(&path, request)
}
/// Initiate a payment for an authorized user tenant (blocking)
#[cfg(feature = "sync")]
pub fn initiate_payment_blocking(
&self,
request: &InitiatePaymentRequest,
) -> Result<InitiatePaymentResponse> {
let path = "/payments";
self.post_blocking(path, request)
}
/// Initiate a payment for a user (blocking)
#[cfg(feature = "sync")]
pub fn initiate_user_payment_blocking(
&self,
user_id: &Uuid,
request: &InitiatePaymentRequest,
) -> Result<InitiatePaymentResponse> {
let path = format!("/users/{user_id}/payments");
self.post_blocking(&path, request)
}
}