fireblocks-sdk 2026.3.28

Rust implementation of the Fireblocks SDK
Documentation
// Fireblocks API
//
// 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)
//
// The version of the OpenAPI document: 1.8.0
// Contact: developers@fireblocks.com
// Generated by: https://openapi-generator.tech

use {
    super::{Error, configuration},
    crate::{
        apis::{ContentType, ResponseContent},
        models,
    },
    async_trait::async_trait,
    reqwest,
    serde::{Deserialize, Serialize, de::Error as _},
    std::sync::Arc,
};

#[async_trait]
pub trait PaymentsPayoutApi: Send + Sync {
    /// POST /payments/payout
    ///
    /// **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.
    async fn create_payout(
        &self,
        params: CreatePayoutParams,
    ) -> Result<models::PayoutResponse, Error<CreatePayoutError>>;

    /// POST /payments/payout/{payoutId}/actions/execute
    ///
    /// **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>Execute a payout instruction
    /// set.</b> </u> </br> </br>The instruction set will be verified and
    /// executed.</br> <b><u>Source locking</br></b> </u> If you are executing a
    /// payout instruction set from a payment account with an already active
    /// payout the active payout will complete before the new payout instruction
    /// set can be executed. </br> You cannot execute the same payout
    /// instruction set more than once. </br>Endpoint Permission: Admin,
    /// Non-Signing Admin.
    async fn execute_payout_action(
        &self,
        params: ExecutePayoutActionParams,
    ) -> Result<models::DispatchPayoutResponse, Error<ExecutePayoutActionError>>;

    /// GET /payments/payout/{payoutId}
    ///
    /// **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>Endpoint Permission: Admin, Non-Signing
    /// Admin.
    async fn get_payout(
        &self,
        params: GetPayoutParams,
    ) -> Result<models::PayoutResponse, Error<GetPayoutError>>;
}

pub struct PaymentsPayoutApiClient {
    configuration: Arc<configuration::Configuration>,
}

impl PaymentsPayoutApiClient {
    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
        Self { configuration }
    }
}

/// struct for passing parameters to the method
/// [`PaymentsPayoutApi::create_payout`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct CreatePayoutParams {
    /// A unique identifier for the request. If the request is sent multiple
    /// times with the same idempotency key, the server will return the same
    /// response as the first request. The idempotency key is valid for 24
    /// hours.
    pub idempotency_key: Option<String>,
    pub create_payout_request: Option<models::CreatePayoutRequest>,
}

/// struct for passing parameters to the method
/// [`PaymentsPayoutApi::execute_payout_action`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct ExecutePayoutActionParams {
    /// the payout id received from the creation of the payout instruction set
    pub payout_id: String,
    /// A unique identifier for the request. If the request is sent multiple
    /// times with the same idempotency key, the server will return the same
    /// response as the first request. The idempotency key is valid for 24
    /// hours.
    pub idempotency_key: Option<String>,
}

/// struct for passing parameters to the method
/// [`PaymentsPayoutApi::get_payout`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct GetPayoutParams {
    /// the payout id received from the creation of the payout instruction set
    pub payout_id: String,
}

#[async_trait]
impl PaymentsPayoutApi for PaymentsPayoutApiClient {
    /// **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.
    async fn create_payout(
        &self,
        params: CreatePayoutParams,
    ) -> Result<models::PayoutResponse, Error<CreatePayoutError>> {
        let CreatePayoutParams {
            idempotency_key,
            create_payout_request,
        } = params;

        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}/payments/payout", local_var_configuration.base_path);
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
            local_var_req_builder = local_var_req_builder
                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
        }
        if let Some(local_var_param_value) = idempotency_key {
            local_var_req_builder =
                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
        }
        local_var_req_builder = local_var_req_builder.json(&create_payout_request);

        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content_type = local_var_resp
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("application/octet-stream");
        let local_var_content_type = super::ContentType::from(local_var_content_type);
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            match local_var_content_type {
                ContentType::Json => {
                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
                }
                ContentType::Text => {
                    return Err(Error::from(serde_json::Error::custom(
                        "Received `text/plain` content type response that cannot be converted to \
                         `models::PayoutResponse`",
                    )));
                }
                ContentType::Unsupported(local_var_unknown_type) => {
                    return Err(Error::from(serde_json::Error::custom(format!(
                        "Received `{local_var_unknown_type}` content type response that cannot be \
                         converted to `models::PayoutResponse`"
                    ))));
                }
            }
        } else {
            let local_var_entity: Option<CreatePayoutError> =
                serde_json::from_str(&local_var_content).ok();
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
                entity: local_var_entity,
            };
            Err(Error::ResponseError(local_var_error))
        }
    }

    /// **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>Execute a payout instruction
    /// set.</b> </u> </br> </br>The instruction set will be verified and
    /// executed.</br> <b><u>Source locking</br></b> </u> If you are executing a
    /// payout instruction set from a payment account with an already active
    /// payout the active payout will complete before the new payout instruction
    /// set can be executed. </br> You cannot execute the same payout
    /// instruction set more than once. </br>Endpoint Permission: Admin,
    /// Non-Signing Admin.
    async fn execute_payout_action(
        &self,
        params: ExecutePayoutActionParams,
    ) -> Result<models::DispatchPayoutResponse, Error<ExecutePayoutActionError>> {
        let ExecutePayoutActionParams {
            payout_id,
            idempotency_key,
        } = params;

        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/payments/payout/{payoutId}/actions/execute",
            local_var_configuration.base_path,
            payoutId = crate::apis::urlencode(payout_id)
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
            local_var_req_builder = local_var_req_builder
                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
        }
        if let Some(local_var_param_value) = idempotency_key {
            local_var_req_builder =
                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
        }

        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content_type = local_var_resp
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("application/octet-stream");
        let local_var_content_type = super::ContentType::from(local_var_content_type);
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            match local_var_content_type {
                ContentType::Json => {
                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
                }
                ContentType::Text => {
                    return Err(Error::from(serde_json::Error::custom(
                        "Received `text/plain` content type response that cannot be converted to \
                         `models::DispatchPayoutResponse`",
                    )));
                }
                ContentType::Unsupported(local_var_unknown_type) => {
                    return Err(Error::from(serde_json::Error::custom(format!(
                        "Received `{local_var_unknown_type}` content type response that cannot be \
                         converted to `models::DispatchPayoutResponse`"
                    ))));
                }
            }
        } else {
            let local_var_entity: Option<ExecutePayoutActionError> =
                serde_json::from_str(&local_var_content).ok();
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
                entity: local_var_entity,
            };
            Err(Error::ResponseError(local_var_error))
        }
    }

    /// **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>Endpoint Permission: Admin, Non-Signing
    /// Admin.
    async fn get_payout(
        &self,
        params: GetPayoutParams,
    ) -> Result<models::PayoutResponse, Error<GetPayoutError>> {
        let GetPayoutParams { payout_id } = params;

        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/payments/payout/{payoutId}",
            local_var_configuration.base_path,
            payoutId = crate::apis::urlencode(payout_id)
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
            local_var_req_builder = local_var_req_builder
                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
        }

        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content_type = local_var_resp
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("application/octet-stream");
        let local_var_content_type = super::ContentType::from(local_var_content_type);
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            match local_var_content_type {
                ContentType::Json => {
                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
                }
                ContentType::Text => {
                    return Err(Error::from(serde_json::Error::custom(
                        "Received `text/plain` content type response that cannot be converted to \
                         `models::PayoutResponse`",
                    )));
                }
                ContentType::Unsupported(local_var_unknown_type) => {
                    return Err(Error::from(serde_json::Error::custom(format!(
                        "Received `{local_var_unknown_type}` content type response that cannot be \
                         converted to `models::PayoutResponse`"
                    ))));
                }
            }
        } else {
            let local_var_entity: Option<GetPayoutError> =
                serde_json::from_str(&local_var_content).ok();
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
                entity: local_var_entity,
            };
            Err(Error::ResponseError(local_var_error))
        }
    }
}

/// struct for typed errors of method [`PaymentsPayoutApi::create_payout`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreatePayoutError {
    Status400(models::ErrorResponse),
    Status401(models::ErrorResponse),
    Status5XX(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method
/// [`PaymentsPayoutApi::execute_payout_action`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ExecutePayoutActionError {
    Status400(models::ErrorResponse),
    Status401(models::ErrorResponse),
    Status5XX(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`PaymentsPayoutApi::get_payout`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPayoutError {
    Status401(models::ErrorResponse),
    Status404(models::ErrorResponse),
    Status5XX(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}