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 payins operations.
#[derive(Clone)]
pub struct PayinsClient {
    client: crate::client::Client,
}

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

    /// List payins with optional filtering and pagination.
    pub async fn list_payins(
        &self,
        query: Option<ListPayinsQuery>,
    ) -> Result<ListPayinsResponse, crate::error::Error> {
        let mut path = String::from("/payins");
        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::<ListPayinsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Deliver stablecoin from the organisation's provider balance to a wallet on-chain.
    pub async fn create_payin(
        &self,
        body: CreatePayinRequest,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = String::from("/payins");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Check whether a wallet's address is registered (and approved) as an payin recipient with the provider.
    pub async fn get_payin_recipient(
        &self,
        query: Option<GetPayinRecipientQuery>,
    ) -> Result<GetPayinRecipientResponse, crate::error::Error> {
        let mut path = String::from("/payins/recipients");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            q.push(format!(
                "provider={}",
                urlencoding::encode(&query.provider.to_string())
            ));
            q.push(format!(
                "walletId={}",
                urlencoding::encode(&query.wallet_id.to_string())
            ));
            q.push(format!(
                "currency={}",
                urlencoding::encode(&query.currency.to_string())
            ));
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<GetPayinRecipientResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Register a wallet's address as an payin recipient with the provider. The registration then needs
    ///     to be approved on the provider's side (for Circle Mint: by an administrator in the Mint Console)
    ///     before payins to that wallet can be created.
    pub async fn register_payin_recipient(
        &self,
        body: RegisterPayinRecipientRequest,
    ) -> Result<RegisterPayinRecipientResponse, crate::error::Error> {
        let path = String::from("/payins/recipients");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<RegisterPayinRecipientResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }

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

    /// The organisation's available balance at the payin provider, one entry per currency —
    ///     the funds payins can deliver on-chain.
    pub async fn list_payin_balances(
        &self,
        query: Option<ListPayinBalancesQuery>,
    ) -> Result<ListPayinBalancesResponse, crate::error::Error> {
        let mut path = String::from("/payins/balances");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            q.push(format!(
                "provider={}",
                urlencoding::encode(&query.provider.to_string())
            ));
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListPayinBalancesResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }
}