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
//! Transactions API
//!
//! This module provides functionality to manage transactions.
use crate::client::RainClient;
use crate::error::Result;
use crate::models::transactions::*;
use uuid::Uuid;
impl RainClient {
/// Get all transactions
///
/// # Arguments
///
/// * `params` - Query parameters to filter transactions
///
/// # Returns
///
/// Returns a [`Vec<Transaction>`] containing the list of transactions.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `500` - Internal server error
#[cfg(feature = "async")]
pub async fn list_transactions(
&self,
params: &ListTransactionsParams,
) -> Result<Vec<Transaction>> {
let path = "/transactions";
let query_string = serde_urlencoded::to_string(params)?;
let full_path = if query_string.is_empty() {
path.to_string()
} else {
format!("{path}?{query_string}")
};
self.get(&full_path).await
}
/// Get a transaction by its id
///
/// # Arguments
///
/// * `transaction_id` - The unique identifier of the transaction
///
/// # Returns
///
/// Returns a [`Transaction`] containing the transaction information.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `404` - Transaction not found
/// - `500` - Internal server error
#[cfg(feature = "async")]
pub async fn get_transaction(&self, transaction_id: &Uuid) -> Result<Transaction> {
let path = format!("/transactions/{transaction_id}");
self.get(&path).await
}
/// Update a transaction
///
/// # Arguments
///
/// * `transaction_id` - The unique identifier of the transaction
/// * `request` - The update request
///
/// # Returns
///
/// Returns success (204 No Content) with no response body.
///
/// # Errors
///
/// This method can return the following errors:
/// - `400` - Invalid request
/// - `401` - Invalid authorization
/// - `404` - Transaction not found
/// - `500` - Internal server error
#[cfg(feature = "async")]
pub async fn update_transaction(
&self,
transaction_id: &Uuid,
request: &UpdateTransactionRequest,
) -> Result<()> {
let path = format!("/transactions/{transaction_id}");
let _: serde_json::Value = self.patch(&path, request).await?;
Ok(())
}
/// Get a transaction's receipt
///
/// # Arguments
///
/// * `transaction_id` - The unique identifier of the transaction
///
/// # Returns
///
/// Returns the receipt as raw bytes (application/octet-stream).
#[cfg(feature = "async")]
pub async fn get_transaction_receipt(&self, transaction_id: &Uuid) -> Result<Vec<u8>> {
let path = format!("/transactions/{transaction_id}/receipt");
self.get_bytes(&path).await
}
/// Upload a transaction's receipt
///
/// # Arguments
///
/// * `transaction_id` - The unique identifier of the transaction
/// * `request` - The receipt upload request
///
/// # Returns
///
/// Returns success (204 No Content) with no response body.
#[cfg(feature = "async")]
pub async fn upload_transaction_receipt(
&self,
transaction_id: &Uuid,
request: &UploadReceiptRequest,
) -> Result<()> {
let path = format!("/transactions/{transaction_id}/receipt");
use reqwest::multipart::{Form, Part};
let form = Form::new().part(
"receipt",
Part::bytes(request.receipt.clone()).file_name(request.file_name.clone()),
);
self.put_multipart_no_content(&path, form).await
}
// ============================================================================
// Blocking Methods
// ============================================================================
/// Get all transactions (blocking)
#[cfg(feature = "sync")]
pub fn list_transactions_blocking(
&self,
params: &ListTransactionsParams,
) -> Result<Vec<Transaction>> {
let path = "/transactions";
let query_string = serde_urlencoded::to_string(params)?;
let full_path = if query_string.is_empty() {
path.to_string()
} else {
format!("{path}?{query_string}")
};
self.get_blocking(&full_path)
}
/// Get a transaction by its id (blocking)
#[cfg(feature = "sync")]
pub fn get_transaction_blocking(&self, transaction_id: &Uuid) -> Result<Transaction> {
let path = format!("/transactions/{transaction_id}");
self.get_blocking(&path)
}
/// Update a transaction (blocking)
#[cfg(feature = "sync")]
pub fn update_transaction_blocking(
&self,
transaction_id: &Uuid,
request: &UpdateTransactionRequest,
) -> Result<()> {
let path = format!("/transactions/{transaction_id}");
let _: serde_json::Value = self.patch_blocking(&path, request)?;
Ok(())
}
/// Get a transaction's receipt (blocking)
#[cfg(feature = "sync")]
pub fn get_transaction_receipt_blocking(&self, transaction_id: &Uuid) -> Result<Vec<u8>> {
let path = format!("/transactions/{transaction_id}/receipt");
self.get_bytes_blocking(&path)
}
/// Upload a transaction's receipt (blocking)
#[cfg(feature = "sync")]
pub fn upload_transaction_receipt_blocking(
&self,
transaction_id: &Uuid,
request: &UploadReceiptRequest,
) -> Result<()> {
let path = format!("/transactions/{transaction_id}/receipt");
use reqwest::blocking::multipart::{Form, Part};
let form = Form::new().part(
"receipt",
Part::bytes(request.receipt.clone()).file_name(request.file_name.clone()),
);
self.put_multipart_blocking_no_content(&path, form)
}
}