fireblocks_sdk/apis/
payments_payout_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 PaymentsPayoutApi: Send + Sync {
23    /// POST /payments/payout
24    ///
25    /// **Note:** The reference content in this section documents the Payments Engine endpoint. The Payments Engine endpoints include APIs available only for customers with Payments Engine enabled on their accounts. </br> </br>These endpoints are currently in beta and might be subject to changes.</br> </br>If you want to learn more about Fireblocks Payments Engine, please contact your Fireblocks Customer Success Manager or email CSM@fireblocks.com. </br> </br> <b u>Create a payout instruction set.</b> </u></br> A payout instruction set is a set of instructions for distributing payments from a single payment account to a list of payee accounts. </br> The instruction set defines: </br> <ul> <li>the payment account and its account type (vault, exchange, or fiat). </li> <li>the account type (vault account, exchange account, whitelisted address, network connection, fiat account, or merchant account), the amount, and the asset of payment for each payee account.</li> </ul> Learn more about Fireblocks Payments - Payouts in the following [guide](https://developers.fireblocks.com/docs/create-payouts). </br>Endpoint Permission: Admin, Non-Signing Admin.
26    async fn create_payout(
27        &self,
28        params: CreatePayoutParams,
29    ) -> Result<models::PayoutResponse, Error<CreatePayoutError>>;
30
31    /// POST /payments/payout/{payoutId}/actions/execute
32    ///
33    /// **Note:** The reference content in this section documents the Payments
34    /// Engine endpoint. The Payments Engine endpoints include APIs available
35    /// only for customers with Payments Engine enabled on their accounts. </br>
36    /// </br>These endpoints are currently in beta and might be subject to
37    /// changes.</br> </br>If you want to learn more about Fireblocks Payments
38    /// Engine, please contact your Fireblocks Customer Success Manager or email
39    /// CSM@fireblocks.com. </br> </br><b u>Execute a payout instruction
40    /// set.</b> </u> </br> </br>The instruction set will be verified and
41    /// executed.</br> <b><u>Source locking</br></b> </u> If you are executing a
42    /// payout instruction set from a payment account with an already active
43    /// payout the active payout will complete before the new payout instruction
44    /// set can be executed. </br> You cannot execute the same payout
45    /// instruction set more than once. </br>Endpoint Permission: Admin,
46    /// Non-Signing Admin.
47    async fn execute_payout_action(
48        &self,
49        params: ExecutePayoutActionParams,
50    ) -> Result<models::DispatchPayoutResponse, Error<ExecutePayoutActionError>>;
51
52    /// GET /payments/payout/{payoutId}
53    ///
54    /// **Note:** The reference content in this section documents the Payments
55    /// Engine endpoint. The Payments Engine endpoints include APIs available
56    /// only for customers with Payments Engine enabled on their accounts. </br>
57    /// </br>These endpoints are currently in beta and might be subject to
58    /// changes.</br> </br>If you want to learn more about Fireblocks Payments
59    /// Engine, please contact your Fireblocks Customer Success Manager or email
60    /// CSM@fireblocks.com. </br> </br>Endpoint Permission: Admin, Non-Signing
61    /// Admin.
62    async fn get_payout(
63        &self,
64        params: GetPayoutParams,
65    ) -> Result<models::PayoutResponse, Error<GetPayoutError>>;
66}
67
68pub struct PaymentsPayoutApiClient {
69    configuration: Arc<configuration::Configuration>,
70}
71
72impl PaymentsPayoutApiClient {
73    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
74        Self { configuration }
75    }
76}
77
78/// struct for passing parameters to the method [`create_payout`]
79#[derive(Clone, Debug)]
80#[cfg_attr(feature = "bon", derive(::bon::Builder))]
81pub struct CreatePayoutParams {
82    /// A unique identifier for the request. If the request is sent multiple
83    /// times with the same idempotency key, the server will return the same
84    /// response as the first request. The idempotency key is valid for 24
85    /// hours.
86    pub idempotency_key: Option<String>,
87    pub create_payout_request: Option<models::CreatePayoutRequest>,
88}
89
90/// struct for passing parameters to the method [`execute_payout_action`]
91#[derive(Clone, Debug)]
92#[cfg_attr(feature = "bon", derive(::bon::Builder))]
93pub struct ExecutePayoutActionParams {
94    /// the payout id received from the creation of the payout instruction set
95    pub payout_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}
102
103/// struct for passing parameters to the method [`get_payout`]
104#[derive(Clone, Debug)]
105#[cfg_attr(feature = "bon", derive(::bon::Builder))]
106pub struct GetPayoutParams {
107    /// the payout id received from the creation of the payout instruction set
108    pub payout_id: String,
109}
110
111#[async_trait]
112impl PaymentsPayoutApi for PaymentsPayoutApiClient {
113    /// **Note:** The reference content in this section documents the Payments Engine endpoint. The Payments Engine endpoints include APIs available only for customers with Payments Engine enabled on their accounts. </br> </br>These endpoints are currently in beta and might be subject to changes.</br> </br>If you want to learn more about Fireblocks Payments Engine, please contact your Fireblocks Customer Success Manager or email CSM@fireblocks.com. </br> </br> <b u>Create a payout instruction set.</b> </u></br> A payout instruction set is a set of instructions for distributing payments from a single payment account to a list of payee accounts. </br> The instruction set defines: </br> <ul> <li>the payment account and its account type (vault, exchange, or fiat). </li> <li>the account type (vault account, exchange account, whitelisted address, network connection, fiat account, or merchant account), the amount, and the asset of payment for each payee account.</li> </ul> Learn more about Fireblocks Payments - Payouts in the following [guide](https://developers.fireblocks.com/docs/create-payouts). </br>Endpoint Permission: Admin, Non-Signing Admin.
114    async fn create_payout(
115        &self,
116        params: CreatePayoutParams,
117    ) -> Result<models::PayoutResponse, Error<CreatePayoutError>> {
118        let CreatePayoutParams {
119            idempotency_key,
120            create_payout_request,
121        } = params;
122
123        let local_var_configuration = &self.configuration;
124
125        let local_var_client = &local_var_configuration.client;
126
127        let local_var_uri_str = format!("{}/payments/payout", local_var_configuration.base_path);
128        let mut local_var_req_builder =
129            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
130
131        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
132            local_var_req_builder = local_var_req_builder
133                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
134        }
135        if let Some(local_var_param_value) = idempotency_key {
136            local_var_req_builder =
137                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
138        }
139        local_var_req_builder = local_var_req_builder.json(&create_payout_request);
140
141        let local_var_req = local_var_req_builder.build()?;
142        let local_var_resp = local_var_client.execute(local_var_req).await?;
143
144        let local_var_status = local_var_resp.status();
145        let local_var_content_type = local_var_resp
146            .headers()
147            .get("content-type")
148            .and_then(|v| v.to_str().ok())
149            .unwrap_or("application/octet-stream");
150        let local_var_content_type = super::ContentType::from(local_var_content_type);
151        let local_var_content = local_var_resp.text().await?;
152
153        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
154            match local_var_content_type {
155                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
156                ContentType::Text => {
157                    return Err(Error::from(serde_json::Error::custom(
158                        "Received `text/plain` content type response that cannot be converted to \
159                         `models::PayoutResponse`",
160                    )));
161                }
162                ContentType::Unsupported(local_var_unknown_type) => {
163                    return Err(Error::from(serde_json::Error::custom(format!(
164                        "Received `{local_var_unknown_type}` content type response that cannot be \
165                         converted to `models::PayoutResponse`"
166                    ))));
167                }
168            }
169        } else {
170            let local_var_entity: Option<CreatePayoutError> =
171                serde_json::from_str(&local_var_content).ok();
172            let local_var_error = ResponseContent {
173                status: local_var_status,
174                content: local_var_content,
175                entity: local_var_entity,
176            };
177            Err(Error::ResponseError(local_var_error))
178        }
179    }
180
181    /// **Note:** The reference content in this section documents the Payments
182    /// Engine endpoint. The Payments Engine endpoints include APIs available
183    /// only for customers with Payments Engine enabled on their accounts. </br>
184    /// </br>These endpoints are currently in beta and might be subject to
185    /// changes.</br> </br>If you want to learn more about Fireblocks Payments
186    /// Engine, please contact your Fireblocks Customer Success Manager or email
187    /// CSM@fireblocks.com. </br> </br><b u>Execute a payout instruction
188    /// set.</b> </u> </br> </br>The instruction set will be verified and
189    /// executed.</br> <b><u>Source locking</br></b> </u> If you are executing a
190    /// payout instruction set from a payment account with an already active
191    /// payout the active payout will complete before the new payout instruction
192    /// set can be executed. </br> You cannot execute the same payout
193    /// instruction set more than once. </br>Endpoint Permission: Admin,
194    /// Non-Signing Admin.
195    async fn execute_payout_action(
196        &self,
197        params: ExecutePayoutActionParams,
198    ) -> Result<models::DispatchPayoutResponse, Error<ExecutePayoutActionError>> {
199        let ExecutePayoutActionParams {
200            payout_id,
201            idempotency_key,
202        } = params;
203
204        let local_var_configuration = &self.configuration;
205
206        let local_var_client = &local_var_configuration.client;
207
208        let local_var_uri_str = format!(
209            "{}/payments/payout/{payoutId}/actions/execute",
210            local_var_configuration.base_path,
211            payoutId = crate::apis::urlencode(payout_id)
212        );
213        let mut local_var_req_builder =
214            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
215
216        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
217            local_var_req_builder = local_var_req_builder
218                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
219        }
220        if let Some(local_var_param_value) = idempotency_key {
221            local_var_req_builder =
222                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
223        }
224
225        let local_var_req = local_var_req_builder.build()?;
226        let local_var_resp = local_var_client.execute(local_var_req).await?;
227
228        let local_var_status = local_var_resp.status();
229        let local_var_content_type = local_var_resp
230            .headers()
231            .get("content-type")
232            .and_then(|v| v.to_str().ok())
233            .unwrap_or("application/octet-stream");
234        let local_var_content_type = super::ContentType::from(local_var_content_type);
235        let local_var_content = local_var_resp.text().await?;
236
237        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238            match local_var_content_type {
239                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
240                ContentType::Text => {
241                    return Err(Error::from(serde_json::Error::custom(
242                        "Received `text/plain` content type response that cannot be converted to \
243                         `models::DispatchPayoutResponse`",
244                    )));
245                }
246                ContentType::Unsupported(local_var_unknown_type) => {
247                    return Err(Error::from(serde_json::Error::custom(format!(
248                        "Received `{local_var_unknown_type}` content type response that cannot be \
249                         converted to `models::DispatchPayoutResponse`"
250                    ))));
251                }
252            }
253        } else {
254            let local_var_entity: Option<ExecutePayoutActionError> =
255                serde_json::from_str(&local_var_content).ok();
256            let local_var_error = ResponseContent {
257                status: local_var_status,
258                content: local_var_content,
259                entity: local_var_entity,
260            };
261            Err(Error::ResponseError(local_var_error))
262        }
263    }
264
265    /// **Note:** The reference content in this section documents the Payments
266    /// Engine endpoint. The Payments Engine endpoints include APIs available
267    /// only for customers with Payments Engine enabled on their accounts. </br>
268    /// </br>These endpoints are currently in beta and might be subject to
269    /// changes.</br> </br>If you want to learn more about Fireblocks Payments
270    /// Engine, please contact your Fireblocks Customer Success Manager or email
271    /// CSM@fireblocks.com. </br> </br>Endpoint Permission: Admin, Non-Signing
272    /// Admin.
273    async fn get_payout(
274        &self,
275        params: GetPayoutParams,
276    ) -> Result<models::PayoutResponse, Error<GetPayoutError>> {
277        let GetPayoutParams { payout_id } = params;
278
279        let local_var_configuration = &self.configuration;
280
281        let local_var_client = &local_var_configuration.client;
282
283        let local_var_uri_str = format!(
284            "{}/payments/payout/{payoutId}",
285            local_var_configuration.base_path,
286            payoutId = crate::apis::urlencode(payout_id)
287        );
288        let mut local_var_req_builder =
289            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
290
291        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
292            local_var_req_builder = local_var_req_builder
293                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
294        }
295
296        let local_var_req = local_var_req_builder.build()?;
297        let local_var_resp = local_var_client.execute(local_var_req).await?;
298
299        let local_var_status = local_var_resp.status();
300        let local_var_content_type = local_var_resp
301            .headers()
302            .get("content-type")
303            .and_then(|v| v.to_str().ok())
304            .unwrap_or("application/octet-stream");
305        let local_var_content_type = super::ContentType::from(local_var_content_type);
306        let local_var_content = local_var_resp.text().await?;
307
308        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
309            match local_var_content_type {
310                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
311                ContentType::Text => {
312                    return Err(Error::from(serde_json::Error::custom(
313                        "Received `text/plain` content type response that cannot be converted to \
314                         `models::PayoutResponse`",
315                    )));
316                }
317                ContentType::Unsupported(local_var_unknown_type) => {
318                    return Err(Error::from(serde_json::Error::custom(format!(
319                        "Received `{local_var_unknown_type}` content type response that cannot be \
320                         converted to `models::PayoutResponse`"
321                    ))));
322                }
323            }
324        } else {
325            let local_var_entity: Option<GetPayoutError> =
326                serde_json::from_str(&local_var_content).ok();
327            let local_var_error = ResponseContent {
328                status: local_var_status,
329                content: local_var_content,
330                entity: local_var_entity,
331            };
332            Err(Error::ResponseError(local_var_error))
333        }
334    }
335}
336
337/// struct for typed errors of method [`create_payout`]
338#[derive(Debug, Clone, Serialize, Deserialize)]
339#[serde(untagged)]
340pub enum CreatePayoutError {
341    Status400(models::ErrorResponse),
342    Status401(models::ErrorResponse),
343    Status5XX(models::ErrorResponse),
344    UnknownValue(serde_json::Value),
345}
346
347/// struct for typed errors of method [`execute_payout_action`]
348#[derive(Debug, Clone, Serialize, Deserialize)]
349#[serde(untagged)]
350pub enum ExecutePayoutActionError {
351    Status400(models::ErrorResponse),
352    Status401(models::ErrorResponse),
353    Status5XX(models::ErrorResponse),
354    UnknownValue(serde_json::Value),
355}
356
357/// struct for typed errors of method [`get_payout`]
358#[derive(Debug, Clone, Serialize, Deserialize)]
359#[serde(untagged)]
360pub enum GetPayoutError {
361    Status401(models::ErrorResponse),
362    Status404(models::ErrorResponse),
363    Status5XX(models::ErrorResponse),
364    UnknownValue(serde_json::Value),
365}