dfns-sdk-rust 0.2.0

Dfns API SDK for Rust
Documentation
// Code generated by rust-sdk-generator. DO NOT EDIT.

pub mod delegated;
pub mod types;

#[allow(unused_imports)]
use types::*;

/// Client for payouts operations.
#[derive(Clone)]
pub struct PayoutsClient {
    client: crate::client::Client,
}

impl PayoutsClient {
    pub fn new(client: crate::client::Client) -> Self {
        PayoutsClient { client }
    }

    /// List payouts with optional filtering and pagination.
    pub async fn list_payouts(
        &self,
        query: Option<ListPayoutsQuery>,
    ) -> Result<ListPayoutsResponse, crate::error::Error> {
        let mut path = String::from("/payouts");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if let Some(v) = &query.wallet_id {
                q.push(format!("walletId={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.status {
                for item in v {
                    q.push(format!("status={}", urlencoding::encode(&item.to_string())));
                }
            }
            if let Some(v) = &query.provider {
                for item in v {
                    q.push(format!(
                        "provider={}",
                        urlencoding::encode(&item.to_string())
                    ));
                }
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListPayoutsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Create a new payout to convert crypto assets to fiat currency.
    pub async fn create_payout(
        &self,
        body: CreatePayoutRequest,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = String::from("/payouts");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Request a quote from a given provider for a payout. Returns estimated fiat amount and fees.
    pub async fn request_payout_quote(
        &self,
        body: RequestPayoutQuoteRequest,
    ) -> Result<RequestPayoutQuoteResponse, crate::error::Error> {
        let path = String::from("/payouts/quote");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<RequestPayoutQuoteResponse>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Retrieve the current status of a payout by its ID.
    pub async fn get_payout_status(
        &self,
        payout_id: String,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = format!("/payouts/{}", urlencoding::encode(&payout_id));
        self.client
            .request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Perform an action on a payout, such as confirming or canceling.
    pub async fn create_payout_action(
        &self,
        payout_id: String,
        body: CreatePayoutActionRequest,
    ) -> Result<CreatePayoutActionResponse, crate::error::Error> {
        let path = format!("/payouts/{}/action", urlencoding::encode(&payout_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreatePayoutActionResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }
}