dfns-sdk-rust 0.2.0

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

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

/// Delegated client for payouts operations. Signed operations are split into
/// init/complete pairs so the challenge can be signed on the user side.
#[derive(Clone)]
pub struct DelegatedPayoutsClient {
    client: crate::client::Client,
}

impl DelegatedPayoutsClient {
    pub fn new(client: crate::client::Client) -> Self {
        DelegatedPayoutsClient { 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
    }

    /// Starts delegated signing for createPayout: returns the challenge to sign.
    /// Pass the signed assertion to create_payout_complete with the same arguments.
    pub async fn create_payout_init(
        &self,
        body: CreatePayoutRequest,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = String::from("/payouts");
        let body = serde_json::to_value(&body)?;
        self.client
            .create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
            .await
    }

    /// Finishes delegated signing for createPayout: submits the signed challenge
    /// and issues the request.
    pub async fn create_payout_complete(
        &self,
        body: CreatePayoutRequest,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = String::from("/payouts");
        let body = serde_json::to_value(&body)?;
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<serde_json::Value>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                &user_action,
            )
            .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
    }

    /// Starts delegated signing for createPayoutAction: returns the challenge to sign.
    /// Pass the signed assertion to create_payout_action_complete with the same arguments.
    pub async fn create_payout_action_init(
        &self,
        payout_id: String,
        body: CreatePayoutActionRequest,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = format!("/payouts/{}/action", urlencoding::encode(&payout_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
            .await
    }

    /// Finishes delegated signing for createPayoutAction: submits the signed challenge
    /// and issues the request.
    pub async fn create_payout_action_complete(
        &self,
        payout_id: String,
        body: CreatePayoutActionRequest,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<CreatePayoutActionResponse, crate::error::Error> {
        let path = format!("/payouts/{}/action", urlencoding::encode(&payout_id));
        let body = serde_json::to_value(&body)?;
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<CreatePayoutActionResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                &user_action,
            )
            .await
    }
}