Skip to main content

dfns_sdk_rust/payouts/
mod.rs

1// Code generated by rust-sdk-generator. DO NOT EDIT.
2
3pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9/// Client for payouts operations.
10#[derive(Clone)]
11pub struct PayoutsClient {
12    client: crate::client::Client,
13}
14
15impl PayoutsClient {
16    pub fn new(client: crate::client::Client) -> Self {
17        PayoutsClient { client }
18    }
19
20    /// List payouts with optional filtering and pagination.
21    pub async fn list_payouts(
22        &self,
23        query: Option<ListPayoutsQuery>,
24    ) -> Result<ListPayoutsResponse, crate::error::Error> {
25        let mut path = String::from("/payouts");
26        if let Some(query) = &query {
27            let mut q: Vec<String> = Vec::new();
28            if let Some(v) = &query.limit {
29                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
30            }
31            if let Some(v) = &query.pagination_token {
32                q.push(format!(
33                    "paginationToken={}",
34                    urlencoding::encode(&v.to_string())
35                ));
36            }
37            if let Some(v) = &query.wallet_id {
38                q.push(format!("walletId={}", urlencoding::encode(&v.to_string())));
39            }
40            if let Some(v) = &query.status {
41                for item in v {
42                    q.push(format!("status={}", urlencoding::encode(&item.to_string())));
43                }
44            }
45            if let Some(v) = &query.provider {
46                for item in v {
47                    q.push(format!(
48                        "provider={}",
49                        urlencoding::encode(&item.to_string())
50                    ));
51                }
52            }
53            if !q.is_empty() {
54                path.push('?');
55                path.push_str(&q.join("&"));
56            }
57        }
58        self.client
59            .request::<ListPayoutsResponse>(reqwest::Method::GET, &path, None, false)
60            .await
61    }
62
63    /// Create a new payout to convert crypto assets to fiat currency.
64    pub async fn create_payout(
65        &self,
66        body: CreatePayoutRequest,
67    ) -> Result<serde_json::Value, crate::error::Error> {
68        let path = String::from("/payouts");
69        let body = serde_json::to_value(&body)?;
70        self.client
71            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), true)
72            .await
73    }
74
75    /// Request a quote from a given provider for a payout. Returns estimated fiat amount and fees.
76    pub async fn request_payout_quote(
77        &self,
78        body: RequestPayoutQuoteRequest,
79    ) -> Result<RequestPayoutQuoteResponse, crate::error::Error> {
80        let path = String::from("/payouts/quote");
81        let body = serde_json::to_value(&body)?;
82        self.client
83            .request::<RequestPayoutQuoteResponse>(reqwest::Method::POST, &path, Some(&body), false)
84            .await
85    }
86
87    /// Retrieve the current status of a payout by its ID.
88    pub async fn get_payout_status(
89        &self,
90        payout_id: String,
91    ) -> Result<serde_json::Value, crate::error::Error> {
92        let path = format!("/payouts/{}", urlencoding::encode(&payout_id));
93        self.client
94            .request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
95            .await
96    }
97
98    /// Perform an action on a payout, such as confirming or canceling.
99    pub async fn create_payout_action(
100        &self,
101        payout_id: String,
102        body: CreatePayoutActionRequest,
103    ) -> Result<CreatePayoutActionResponse, crate::error::Error> {
104        let path = format!("/payouts/{}/action", urlencoding::encode(&payout_id));
105        let body = serde_json::to_value(&body)?;
106        self.client
107            .request::<CreatePayoutActionResponse>(reqwest::Method::POST, &path, Some(&body), true)
108            .await
109    }
110}