dfns_sdk_rust/payins/
mod.rs1pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9#[derive(Clone)]
11pub struct PayinsClient {
12 client: crate::client::Client,
13}
14
15impl PayinsClient {
16 pub fn new(client: crate::client::Client) -> Self {
17 PayinsClient { client }
18 }
19
20 pub async fn list_payins(
22 &self,
23 query: Option<ListPayinsQuery>,
24 ) -> Result<ListPayinsResponse, crate::error::Error> {
25 let mut path = String::from("/payins");
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::<ListPayinsResponse>(reqwest::Method::GET, &path, None, false)
60 .await
61 }
62
63 pub async fn create_payin(
65 &self,
66 body: CreatePayinRequest,
67 ) -> Result<serde_json::Value, crate::error::Error> {
68 let path = String::from("/payins");
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 pub async fn get_payin_recipient(
77 &self,
78 query: Option<GetPayinRecipientQuery>,
79 ) -> Result<GetPayinRecipientResponse, crate::error::Error> {
80 let mut path = String::from("/payins/recipients");
81 if let Some(query) = &query {
82 let mut q: Vec<String> = Vec::new();
83 q.push(format!(
84 "provider={}",
85 urlencoding::encode(&query.provider.to_string())
86 ));
87 q.push(format!(
88 "walletId={}",
89 urlencoding::encode(&query.wallet_id.to_string())
90 ));
91 q.push(format!(
92 "currency={}",
93 urlencoding::encode(&query.currency.to_string())
94 ));
95 if !q.is_empty() {
96 path.push('?');
97 path.push_str(&q.join("&"));
98 }
99 }
100 self.client
101 .request::<GetPayinRecipientResponse>(reqwest::Method::GET, &path, None, false)
102 .await
103 }
104
105 pub async fn register_payin_recipient(
109 &self,
110 body: RegisterPayinRecipientRequest,
111 ) -> Result<RegisterPayinRecipientResponse, crate::error::Error> {
112 let path = String::from("/payins/recipients");
113 let body = serde_json::to_value(&body)?;
114 self.client
115 .request::<RegisterPayinRecipientResponse>(
116 reqwest::Method::POST,
117 &path,
118 Some(&body),
119 true,
120 )
121 .await
122 }
123
124 pub async fn get_payin_status(
126 &self,
127 payin_id: String,
128 ) -> Result<serde_json::Value, crate::error::Error> {
129 let path = format!("/payins/{}", urlencoding::encode(&payin_id));
130 self.client
131 .request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
132 .await
133 }
134
135 pub async fn list_payin_balances(
138 &self,
139 query: Option<ListPayinBalancesQuery>,
140 ) -> Result<ListPayinBalancesResponse, crate::error::Error> {
141 let mut path = String::from("/payins/balances");
142 if let Some(query) = &query {
143 let mut q: Vec<String> = Vec::new();
144 q.push(format!(
145 "provider={}",
146 urlencoding::encode(&query.provider.to_string())
147 ));
148 if !q.is_empty() {
149 path.push('?');
150 path.push_str(&q.join("&"));
151 }
152 }
153 self.client
154 .request::<ListPayinBalancesResponse>(reqwest::Method::GET, &path, None, false)
155 .await
156 }
157}