1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait PaymentsPayoutApi: Send + Sync {
23 async fn create_payout(
27 &self,
28 params: CreatePayoutParams,
29 ) -> Result<models::PayoutResponse, Error<CreatePayoutError>>;
30
31 async fn execute_payout_action(
48 &self,
49 params: ExecutePayoutActionParams,
50 ) -> Result<models::DispatchPayoutResponse, Error<ExecutePayoutActionError>>;
51
52 async fn get_payout(
63 &self,
64 params: GetPayoutParams,
65 ) -> Result<models::PayoutResponse, Error<GetPayoutError>>;
66}
67
68pub struct PaymentsPayoutApiClient {
69 configuration: Arc<configuration::Configuration>,
70}
71
72impl PaymentsPayoutApiClient {
73 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
74 Self { configuration }
75 }
76}
77
78#[derive(Clone, Debug)]
80#[cfg_attr(feature = "bon", derive(::bon::Builder))]
81pub struct CreatePayoutParams {
82 pub idempotency_key: Option<String>,
87 pub create_payout_request: Option<models::CreatePayoutRequest>,
88}
89
90#[derive(Clone, Debug)]
92#[cfg_attr(feature = "bon", derive(::bon::Builder))]
93pub struct ExecutePayoutActionParams {
94 pub payout_id: String,
96 pub idempotency_key: Option<String>,
101}
102
103#[derive(Clone, Debug)]
105#[cfg_attr(feature = "bon", derive(::bon::Builder))]
106pub struct GetPayoutParams {
107 pub payout_id: String,
109}
110
111#[async_trait]
112impl PaymentsPayoutApi for PaymentsPayoutApiClient {
113 async fn create_payout(
115 &self,
116 params: CreatePayoutParams,
117 ) -> Result<models::PayoutResponse, Error<CreatePayoutError>> {
118 let CreatePayoutParams {
119 idempotency_key,
120 create_payout_request,
121 } = params;
122
123 let local_var_configuration = &self.configuration;
124
125 let local_var_client = &local_var_configuration.client;
126
127 let local_var_uri_str = format!("{}/payments/payout", local_var_configuration.base_path);
128 let mut local_var_req_builder =
129 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
130
131 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
132 local_var_req_builder = local_var_req_builder
133 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
134 }
135 if let Some(local_var_param_value) = idempotency_key {
136 local_var_req_builder =
137 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
138 }
139 local_var_req_builder = local_var_req_builder.json(&create_payout_request);
140
141 let local_var_req = local_var_req_builder.build()?;
142 let local_var_resp = local_var_client.execute(local_var_req).await?;
143
144 let local_var_status = local_var_resp.status();
145 let local_var_content_type = local_var_resp
146 .headers()
147 .get("content-type")
148 .and_then(|v| v.to_str().ok())
149 .unwrap_or("application/octet-stream");
150 let local_var_content_type = super::ContentType::from(local_var_content_type);
151 let local_var_content = local_var_resp.text().await?;
152
153 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
154 match local_var_content_type {
155 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
156 ContentType::Text => {
157 return Err(Error::from(serde_json::Error::custom(
158 "Received `text/plain` content type response that cannot be converted to \
159 `models::PayoutResponse`",
160 )));
161 }
162 ContentType::Unsupported(local_var_unknown_type) => {
163 return Err(Error::from(serde_json::Error::custom(format!(
164 "Received `{local_var_unknown_type}` content type response that cannot be \
165 converted to `models::PayoutResponse`"
166 ))));
167 }
168 }
169 } else {
170 let local_var_entity: Option<CreatePayoutError> =
171 serde_json::from_str(&local_var_content).ok();
172 let local_var_error = ResponseContent {
173 status: local_var_status,
174 content: local_var_content,
175 entity: local_var_entity,
176 };
177 Err(Error::ResponseError(local_var_error))
178 }
179 }
180
181 async fn execute_payout_action(
196 &self,
197 params: ExecutePayoutActionParams,
198 ) -> Result<models::DispatchPayoutResponse, Error<ExecutePayoutActionError>> {
199 let ExecutePayoutActionParams {
200 payout_id,
201 idempotency_key,
202 } = params;
203
204 let local_var_configuration = &self.configuration;
205
206 let local_var_client = &local_var_configuration.client;
207
208 let local_var_uri_str = format!(
209 "{}/payments/payout/{payoutId}/actions/execute",
210 local_var_configuration.base_path,
211 payoutId = crate::apis::urlencode(payout_id)
212 );
213 let mut local_var_req_builder =
214 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
215
216 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
217 local_var_req_builder = local_var_req_builder
218 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
219 }
220 if let Some(local_var_param_value) = idempotency_key {
221 local_var_req_builder =
222 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
223 }
224
225 let local_var_req = local_var_req_builder.build()?;
226 let local_var_resp = local_var_client.execute(local_var_req).await?;
227
228 let local_var_status = local_var_resp.status();
229 let local_var_content_type = local_var_resp
230 .headers()
231 .get("content-type")
232 .and_then(|v| v.to_str().ok())
233 .unwrap_or("application/octet-stream");
234 let local_var_content_type = super::ContentType::from(local_var_content_type);
235 let local_var_content = local_var_resp.text().await?;
236
237 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238 match local_var_content_type {
239 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
240 ContentType::Text => {
241 return Err(Error::from(serde_json::Error::custom(
242 "Received `text/plain` content type response that cannot be converted to \
243 `models::DispatchPayoutResponse`",
244 )));
245 }
246 ContentType::Unsupported(local_var_unknown_type) => {
247 return Err(Error::from(serde_json::Error::custom(format!(
248 "Received `{local_var_unknown_type}` content type response that cannot be \
249 converted to `models::DispatchPayoutResponse`"
250 ))));
251 }
252 }
253 } else {
254 let local_var_entity: Option<ExecutePayoutActionError> =
255 serde_json::from_str(&local_var_content).ok();
256 let local_var_error = ResponseContent {
257 status: local_var_status,
258 content: local_var_content,
259 entity: local_var_entity,
260 };
261 Err(Error::ResponseError(local_var_error))
262 }
263 }
264
265 async fn get_payout(
274 &self,
275 params: GetPayoutParams,
276 ) -> Result<models::PayoutResponse, Error<GetPayoutError>> {
277 let GetPayoutParams { payout_id } = params;
278
279 let local_var_configuration = &self.configuration;
280
281 let local_var_client = &local_var_configuration.client;
282
283 let local_var_uri_str = format!(
284 "{}/payments/payout/{payoutId}",
285 local_var_configuration.base_path,
286 payoutId = crate::apis::urlencode(payout_id)
287 );
288 let mut local_var_req_builder =
289 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
290
291 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
292 local_var_req_builder = local_var_req_builder
293 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
294 }
295
296 let local_var_req = local_var_req_builder.build()?;
297 let local_var_resp = local_var_client.execute(local_var_req).await?;
298
299 let local_var_status = local_var_resp.status();
300 let local_var_content_type = local_var_resp
301 .headers()
302 .get("content-type")
303 .and_then(|v| v.to_str().ok())
304 .unwrap_or("application/octet-stream");
305 let local_var_content_type = super::ContentType::from(local_var_content_type);
306 let local_var_content = local_var_resp.text().await?;
307
308 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
309 match local_var_content_type {
310 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
311 ContentType::Text => {
312 return Err(Error::from(serde_json::Error::custom(
313 "Received `text/plain` content type response that cannot be converted to \
314 `models::PayoutResponse`",
315 )));
316 }
317 ContentType::Unsupported(local_var_unknown_type) => {
318 return Err(Error::from(serde_json::Error::custom(format!(
319 "Received `{local_var_unknown_type}` content type response that cannot be \
320 converted to `models::PayoutResponse`"
321 ))));
322 }
323 }
324 } else {
325 let local_var_entity: Option<GetPayoutError> =
326 serde_json::from_str(&local_var_content).ok();
327 let local_var_error = ResponseContent {
328 status: local_var_status,
329 content: local_var_content,
330 entity: local_var_entity,
331 };
332 Err(Error::ResponseError(local_var_error))
333 }
334 }
335}
336
337#[derive(Debug, Clone, Serialize, Deserialize)]
339#[serde(untagged)]
340pub enum CreatePayoutError {
341 Status400(models::ErrorResponse),
342 Status401(models::ErrorResponse),
343 Status5XX(models::ErrorResponse),
344 UnknownValue(serde_json::Value),
345}
346
347#[derive(Debug, Clone, Serialize, Deserialize)]
349#[serde(untagged)]
350pub enum ExecutePayoutActionError {
351 Status400(models::ErrorResponse),
352 Status401(models::ErrorResponse),
353 Status5XX(models::ErrorResponse),
354 UnknownValue(serde_json::Value),
355}
356
357#[derive(Debug, Clone, Serialize, Deserialize)]
359#[serde(untagged)]
360pub enum GetPayoutError {
361 Status401(models::ErrorResponse),
362 Status404(models::ErrorResponse),
363 Status5XX(models::ErrorResponse),
364 UnknownValue(serde_json::Value),
365}