fireblocks_sdk/apis/
fiat_accounts_api.rs

1// Fireblocks API
2//
3// Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain.  - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com)
4//
5// The version of the OpenAPI document: 1.8.0
6// Contact: developers@fireblocks.com
7// Generated by: https://openapi-generator.tech
8
9use {
10    super::{Error, configuration},
11    crate::{
12        apis::{ContentType, ResponseContent},
13        models,
14    },
15    async_trait::async_trait,
16    reqwest,
17    serde::{Deserialize, Serialize, de::Error as _},
18    std::sync::Arc,
19};
20
21#[async_trait]
22pub trait FiatAccountsApi: Send + Sync {
23    /// POST /fiat_accounts/{accountId}/deposit_from_linked_dda
24    ///
25    /// Deposits funds from the linked DDA. Learn more about Fireblocks FIAT Connectivity in the following [guide](https://developers.fireblocks.com/docs/connect-to-exchanges-and-fiat-providers). </br>Endpoint Permission: Admin, Non-Signing Admin.
26    async fn deposit_funds_from_linked_dda(
27        &self,
28        params: DepositFundsFromLinkedDdaParams,
29    ) -> Result<models::DepositFundsFromLinkedDdaResponse, Error<DepositFundsFromLinkedDdaError>>;
30
31    /// GET /fiat_accounts/{accountId}
32    ///
33    /// Returns a fiat account by ID. </br>Endpoint Permission: Admin,
34    /// Non-Signing Admin.
35    async fn get_fiat_account(
36        &self,
37        params: GetFiatAccountParams,
38    ) -> Result<models::FiatAccount, Error<GetFiatAccountError>>;
39
40    /// GET /fiat_accounts
41    ///
42    /// Returns all fiat accounts. </br>Endpoint Permission: Admin, Non-Signing
43    /// Admin.
44    async fn get_fiat_accounts(
45        &self,
46    ) -> Result<Vec<models::FiatAccount>, Error<GetFiatAccountsError>>;
47
48    /// POST /fiat_accounts/{accountId}/redeem_to_linked_dda
49    ///
50    /// Redeems funds to the linked DDA. Learn more about Fireblocks FIAT Connectivity in the following [guide](https://developers.fireblocks.com/docs/connect-to-exchanges-and-fiat-providers). </br>Endpoint Permission: Admin, Non-Signing Admin.
51    async fn redeem_funds_to_linked_dda(
52        &self,
53        params: RedeemFundsToLinkedDdaParams,
54    ) -> Result<models::RedeemFundsToLinkedDdaResponse, Error<RedeemFundsToLinkedDdaError>>;
55}
56
57pub struct FiatAccountsApiClient {
58    configuration: Arc<configuration::Configuration>,
59}
60
61impl FiatAccountsApiClient {
62    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
63        Self { configuration }
64    }
65}
66
67/// struct for passing parameters to the method
68/// [`deposit_funds_from_linked_dda`]
69#[derive(Clone, Debug)]
70#[cfg_attr(feature = "bon", derive(::bon::Builder))]
71pub struct DepositFundsFromLinkedDdaParams {
72    /// The ID of the fiat account to use
73    pub account_id: String,
74    /// A unique identifier for the request. If the request is sent multiple
75    /// times with the same idempotency key, the server will return the same
76    /// response as the first request. The idempotency key is valid for 24
77    /// hours.
78    pub idempotency_key: Option<String>,
79    pub funds: Option<models::Funds>,
80}
81
82/// struct for passing parameters to the method [`get_fiat_account`]
83#[derive(Clone, Debug)]
84#[cfg_attr(feature = "bon", derive(::bon::Builder))]
85pub struct GetFiatAccountParams {
86    /// The ID of the fiat account to return
87    pub account_id: String,
88}
89
90/// struct for passing parameters to the method [`redeem_funds_to_linked_dda`]
91#[derive(Clone, Debug)]
92#[cfg_attr(feature = "bon", derive(::bon::Builder))]
93pub struct RedeemFundsToLinkedDdaParams {
94    /// The ID of the fiat account to use
95    pub account_id: String,
96    /// A unique identifier for the request. If the request is sent multiple
97    /// times with the same idempotency key, the server will return the same
98    /// response as the first request. The idempotency key is valid for 24
99    /// hours.
100    pub idempotency_key: Option<String>,
101    pub funds: Option<models::Funds>,
102}
103
104#[async_trait]
105impl FiatAccountsApi for FiatAccountsApiClient {
106    /// Deposits funds from the linked DDA. Learn more about Fireblocks FIAT Connectivity in the following [guide](https://developers.fireblocks.com/docs/connect-to-exchanges-and-fiat-providers). </br>Endpoint Permission: Admin, Non-Signing Admin.
107    async fn deposit_funds_from_linked_dda(
108        &self,
109        params: DepositFundsFromLinkedDdaParams,
110    ) -> Result<models::DepositFundsFromLinkedDdaResponse, Error<DepositFundsFromLinkedDdaError>>
111    {
112        let DepositFundsFromLinkedDdaParams {
113            account_id,
114            idempotency_key,
115            funds,
116        } = params;
117
118        let local_var_configuration = &self.configuration;
119
120        let local_var_client = &local_var_configuration.client;
121
122        let local_var_uri_str = format!(
123            "{}/fiat_accounts/{accountId}/deposit_from_linked_dda",
124            local_var_configuration.base_path,
125            accountId = crate::apis::urlencode(account_id)
126        );
127        let mut local_var_req_builder =
128            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
129
130        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
131            local_var_req_builder = local_var_req_builder
132                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
133        }
134        if let Some(local_var_param_value) = idempotency_key {
135            local_var_req_builder =
136                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
137        }
138        local_var_req_builder = local_var_req_builder.json(&funds);
139
140        let local_var_req = local_var_req_builder.build()?;
141        let local_var_resp = local_var_client.execute(local_var_req).await?;
142
143        let local_var_status = local_var_resp.status();
144        let local_var_content_type = local_var_resp
145            .headers()
146            .get("content-type")
147            .and_then(|v| v.to_str().ok())
148            .unwrap_or("application/octet-stream");
149        let local_var_content_type = super::ContentType::from(local_var_content_type);
150        let local_var_content = local_var_resp.text().await?;
151
152        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153            match local_var_content_type {
154                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
155                ContentType::Text => {
156                    return Err(Error::from(serde_json::Error::custom(
157                        "Received `text/plain` content type response that cannot be converted to \
158                         `models::DepositFundsFromLinkedDdaResponse`",
159                    )));
160                }
161                ContentType::Unsupported(local_var_unknown_type) => {
162                    return Err(Error::from(serde_json::Error::custom(format!(
163                        "Received `{local_var_unknown_type}` content type response that cannot be \
164                         converted to `models::DepositFundsFromLinkedDdaResponse`"
165                    ))));
166                }
167            }
168        } else {
169            let local_var_entity: Option<DepositFundsFromLinkedDdaError> =
170                serde_json::from_str(&local_var_content).ok();
171            let local_var_error = ResponseContent {
172                status: local_var_status,
173                content: local_var_content,
174                entity: local_var_entity,
175            };
176            Err(Error::ResponseError(local_var_error))
177        }
178    }
179
180    /// Returns a fiat account by ID. </br>Endpoint Permission: Admin,
181    /// Non-Signing Admin.
182    async fn get_fiat_account(
183        &self,
184        params: GetFiatAccountParams,
185    ) -> Result<models::FiatAccount, Error<GetFiatAccountError>> {
186        let GetFiatAccountParams { account_id } = params;
187
188        let local_var_configuration = &self.configuration;
189
190        let local_var_client = &local_var_configuration.client;
191
192        let local_var_uri_str = format!(
193            "{}/fiat_accounts/{accountId}",
194            local_var_configuration.base_path,
195            accountId = crate::apis::urlencode(account_id)
196        );
197        let mut local_var_req_builder =
198            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
199
200        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
201            local_var_req_builder = local_var_req_builder
202                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
203        }
204
205        let local_var_req = local_var_req_builder.build()?;
206        let local_var_resp = local_var_client.execute(local_var_req).await?;
207
208        let local_var_status = local_var_resp.status();
209        let local_var_content_type = local_var_resp
210            .headers()
211            .get("content-type")
212            .and_then(|v| v.to_str().ok())
213            .unwrap_or("application/octet-stream");
214        let local_var_content_type = super::ContentType::from(local_var_content_type);
215        let local_var_content = local_var_resp.text().await?;
216
217        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
218            match local_var_content_type {
219                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
220                ContentType::Text => {
221                    return Err(Error::from(serde_json::Error::custom(
222                        "Received `text/plain` content type response that cannot be converted to \
223                         `models::FiatAccount`",
224                    )));
225                }
226                ContentType::Unsupported(local_var_unknown_type) => {
227                    return Err(Error::from(serde_json::Error::custom(format!(
228                        "Received `{local_var_unknown_type}` content type response that cannot be \
229                         converted to `models::FiatAccount`"
230                    ))));
231                }
232            }
233        } else {
234            let local_var_entity: Option<GetFiatAccountError> =
235                serde_json::from_str(&local_var_content).ok();
236            let local_var_error = ResponseContent {
237                status: local_var_status,
238                content: local_var_content,
239                entity: local_var_entity,
240            };
241            Err(Error::ResponseError(local_var_error))
242        }
243    }
244
245    /// Returns all fiat accounts. </br>Endpoint Permission: Admin, Non-Signing
246    /// Admin.
247    async fn get_fiat_accounts(
248        &self,
249    ) -> Result<Vec<models::FiatAccount>, Error<GetFiatAccountsError>> {
250        let local_var_configuration = &self.configuration;
251
252        let local_var_client = &local_var_configuration.client;
253
254        let local_var_uri_str = format!("{}/fiat_accounts", local_var_configuration.base_path);
255        let mut local_var_req_builder =
256            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
257
258        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
259            local_var_req_builder = local_var_req_builder
260                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
261        }
262
263        let local_var_req = local_var_req_builder.build()?;
264        let local_var_resp = local_var_client.execute(local_var_req).await?;
265
266        let local_var_status = local_var_resp.status();
267        let local_var_content_type = local_var_resp
268            .headers()
269            .get("content-type")
270            .and_then(|v| v.to_str().ok())
271            .unwrap_or("application/octet-stream");
272        let local_var_content_type = super::ContentType::from(local_var_content_type);
273        let local_var_content = local_var_resp.text().await?;
274
275        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
276            match local_var_content_type {
277                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
278                ContentType::Text => {
279                    return Err(Error::from(serde_json::Error::custom(
280                        "Received `text/plain` content type response that cannot be converted to \
281                         `Vec&lt;models::FiatAccount&gt;`",
282                    )));
283                }
284                ContentType::Unsupported(local_var_unknown_type) => {
285                    return Err(Error::from(serde_json::Error::custom(format!(
286                        "Received `{local_var_unknown_type}` content type response that cannot be \
287                         converted to `Vec&lt;models::FiatAccount&gt;`"
288                    ))));
289                }
290            }
291        } else {
292            let local_var_entity: Option<GetFiatAccountsError> =
293                serde_json::from_str(&local_var_content).ok();
294            let local_var_error = ResponseContent {
295                status: local_var_status,
296                content: local_var_content,
297                entity: local_var_entity,
298            };
299            Err(Error::ResponseError(local_var_error))
300        }
301    }
302
303    /// Redeems funds to the linked DDA. Learn more about Fireblocks FIAT Connectivity in the following [guide](https://developers.fireblocks.com/docs/connect-to-exchanges-and-fiat-providers). </br>Endpoint Permission: Admin, Non-Signing Admin.
304    async fn redeem_funds_to_linked_dda(
305        &self,
306        params: RedeemFundsToLinkedDdaParams,
307    ) -> Result<models::RedeemFundsToLinkedDdaResponse, Error<RedeemFundsToLinkedDdaError>> {
308        let RedeemFundsToLinkedDdaParams {
309            account_id,
310            idempotency_key,
311            funds,
312        } = params;
313
314        let local_var_configuration = &self.configuration;
315
316        let local_var_client = &local_var_configuration.client;
317
318        let local_var_uri_str = format!(
319            "{}/fiat_accounts/{accountId}/redeem_to_linked_dda",
320            local_var_configuration.base_path,
321            accountId = crate::apis::urlencode(account_id)
322        );
323        let mut local_var_req_builder =
324            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
325
326        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
327            local_var_req_builder = local_var_req_builder
328                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
329        }
330        if let Some(local_var_param_value) = idempotency_key {
331            local_var_req_builder =
332                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
333        }
334        local_var_req_builder = local_var_req_builder.json(&funds);
335
336        let local_var_req = local_var_req_builder.build()?;
337        let local_var_resp = local_var_client.execute(local_var_req).await?;
338
339        let local_var_status = local_var_resp.status();
340        let local_var_content_type = local_var_resp
341            .headers()
342            .get("content-type")
343            .and_then(|v| v.to_str().ok())
344            .unwrap_or("application/octet-stream");
345        let local_var_content_type = super::ContentType::from(local_var_content_type);
346        let local_var_content = local_var_resp.text().await?;
347
348        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
349            match local_var_content_type {
350                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
351                ContentType::Text => {
352                    return Err(Error::from(serde_json::Error::custom(
353                        "Received `text/plain` content type response that cannot be converted to \
354                         `models::RedeemFundsToLinkedDdaResponse`",
355                    )));
356                }
357                ContentType::Unsupported(local_var_unknown_type) => {
358                    return Err(Error::from(serde_json::Error::custom(format!(
359                        "Received `{local_var_unknown_type}` content type response that cannot be \
360                         converted to `models::RedeemFundsToLinkedDdaResponse`"
361                    ))));
362                }
363            }
364        } else {
365            let local_var_entity: Option<RedeemFundsToLinkedDdaError> =
366                serde_json::from_str(&local_var_content).ok();
367            let local_var_error = ResponseContent {
368                status: local_var_status,
369                content: local_var_content,
370                entity: local_var_entity,
371            };
372            Err(Error::ResponseError(local_var_error))
373        }
374    }
375}
376
377/// struct for typed errors of method [`deposit_funds_from_linked_dda`]
378#[derive(Debug, Clone, Serialize, Deserialize)]
379#[serde(untagged)]
380pub enum DepositFundsFromLinkedDdaError {
381    DefaultResponse(models::ErrorSchema),
382    UnknownValue(serde_json::Value),
383}
384
385/// struct for typed errors of method [`get_fiat_account`]
386#[derive(Debug, Clone, Serialize, Deserialize)]
387#[serde(untagged)]
388pub enum GetFiatAccountError {
389    DefaultResponse(models::ErrorSchema),
390    UnknownValue(serde_json::Value),
391}
392
393/// struct for typed errors of method [`get_fiat_accounts`]
394#[derive(Debug, Clone, Serialize, Deserialize)]
395#[serde(untagged)]
396pub enum GetFiatAccountsError {
397    DefaultResponse(models::ErrorSchema),
398    UnknownValue(serde_json::Value),
399}
400
401/// struct for typed errors of method [`redeem_funds_to_linked_dda`]
402#[derive(Debug, Clone, Serialize, Deserialize)]
403#[serde(untagged)]
404pub enum RedeemFundsToLinkedDdaError {
405    DefaultResponse(models::ErrorSchema),
406    UnknownValue(serde_json::Value),
407}