amazon_spapi/apis/
transfers_2024_06_01.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetPaymentMethodsError {
22 Status400(models::transfers_2024_06_01::ErrorList),
23 Status403(models::transfers_2024_06_01::ErrorList),
24 Status404(models::transfers_2024_06_01::ErrorList),
25 Status413(models::transfers_2024_06_01::ErrorList),
26 Status415(models::transfers_2024_06_01::ErrorList),
27 Status429(models::transfers_2024_06_01::ErrorList),
28 Status500(models::transfers_2024_06_01::ErrorList),
29 Status503(models::transfers_2024_06_01::ErrorList),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum InitiatePayoutError {
37 Status400(models::transfers_2024_06_01::ErrorList),
38 Status403(models::transfers_2024_06_01::ErrorList),
39 Status404(models::transfers_2024_06_01::ErrorList),
40 Status413(models::transfers_2024_06_01::ErrorList),
41 Status415(models::transfers_2024_06_01::ErrorList),
42 Status429(models::transfers_2024_06_01::ErrorList),
43 Status500(models::transfers_2024_06_01::ErrorList),
44 Status503(models::transfers_2024_06_01::ErrorList),
45 UnknownValue(serde_json::Value),
46}
47
48
49pub async fn get_payment_methods(configuration: &configuration::Configuration, marketplace_id: &str, payment_method_types: Option<Vec<String>>) -> Result<models::transfers_2024_06_01::GetPaymentMethodsResponse, Error<GetPaymentMethodsError>> {
51 let p_marketplace_id = marketplace_id;
53 let p_payment_method_types = payment_method_types;
54
55 let uri_str = format!("{}/finances/transfers/2024-06-01/paymentMethods", configuration.base_path);
56 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
57
58 req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
59 if let Some(ref param_value) = p_payment_method_types {
60 req_builder = match "csv" {
61 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("paymentMethodTypes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
62 _ => req_builder.query(&[("paymentMethodTypes", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
63 };
64 }
65 if let Some(ref user_agent) = configuration.user_agent {
66 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
67 }
68
69 let req = req_builder.build()?;
70 let resp = configuration.client.execute(req).await?;
71
72 let status = resp.status();
73 let content_type = resp
74 .headers()
75 .get("content-type")
76 .and_then(|v| v.to_str().ok())
77 .unwrap_or("application/octet-stream");
78 let content_type = super::ContentType::from(content_type);
79
80 if !status.is_client_error() && !status.is_server_error() {
81 let content = resp.text().await?;
82 match content_type {
83 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
84 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPaymentMethodsResponse`"))),
85 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetPaymentMethodsResponse`")))),
86 }
87 } else {
88 let content = resp.text().await?;
89 let entity: Option<GetPaymentMethodsError> = serde_json::from_str(&content).ok();
90 Err(Error::ResponseError(ResponseContent { status, content, entity }))
91 }
92}
93
94pub async fn initiate_payout(configuration: &configuration::Configuration, body: models::transfers_2024_06_01::InitiatePayoutRequest) -> Result<models::transfers_2024_06_01::InitiatePayoutResponse, Error<InitiatePayoutError>> {
96 let p_body = body;
98
99 let uri_str = format!("{}/finances/transfers/2024-06-01/payouts", configuration.base_path);
100 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
101
102 if let Some(ref user_agent) = configuration.user_agent {
103 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
104 }
105 req_builder = req_builder.json(&p_body);
106
107 let req = req_builder.build()?;
108 let resp = configuration.client.execute(req).await?;
109
110 let status = resp.status();
111 let content_type = resp
112 .headers()
113 .get("content-type")
114 .and_then(|v| v.to_str().ok())
115 .unwrap_or("application/octet-stream");
116 let content_type = super::ContentType::from(content_type);
117
118 if !status.is_client_error() && !status.is_server_error() {
119 let content = resp.text().await?;
120 match content_type {
121 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InitiatePayoutResponse`"))),
123 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InitiatePayoutResponse`")))),
124 }
125 } else {
126 let content = resp.text().await?;
127 let entity: Option<InitiatePayoutError> = serde_json::from_str(&content).ok();
128 Err(Error::ResponseError(ResponseContent { status, content, entity }))
129 }
130}
131