amazon_spapi/apis/
accounts_api.rs

1/*
2 * The Selling Partner API for Amazon Seller Wallet Open Banking API
3 *
4 * The Selling Partner API for Seller Wallet (Seller Wallet API) provides financial information that is relevant to a seller's Seller Wallet account. You can obtain financial events, balances, and transfer schedules for Seller Wallet accounts. You can also schedule and initiate transactions.
5 *
6 * The version of the OpenAPI document: 2024-03-01
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_account`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAccountError {
22    Status400(models::seller_wallet_2024_03_01::ErrorList),
23    Status403(models::seller_wallet_2024_03_01::ErrorList),
24    Status404(models::seller_wallet_2024_03_01::ErrorList),
25    Status408(models::seller_wallet_2024_03_01::ErrorList),
26    Status413(models::seller_wallet_2024_03_01::ErrorList),
27    Status415(models::seller_wallet_2024_03_01::ErrorList),
28    Status429(models::seller_wallet_2024_03_01::ErrorList),
29    Status500(models::seller_wallet_2024_03_01::ErrorList),
30    Status503(models::seller_wallet_2024_03_01::ErrorList),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`list_account_balances`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ListAccountBalancesError {
38    Status400(models::seller_wallet_2024_03_01::ErrorList),
39    Status403(models::seller_wallet_2024_03_01::ErrorList),
40    Status404(models::seller_wallet_2024_03_01::ErrorList),
41    Status408(models::seller_wallet_2024_03_01::ErrorList),
42    Status413(models::seller_wallet_2024_03_01::ErrorList),
43    Status415(models::seller_wallet_2024_03_01::ErrorList),
44    Status429(models::seller_wallet_2024_03_01::ErrorList),
45    Status500(models::seller_wallet_2024_03_01::ErrorList),
46    Status503(models::seller_wallet_2024_03_01::ErrorList),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`list_accounts`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum ListAccountsError {
54    Status400(models::seller_wallet_2024_03_01::ErrorList),
55    Status403(models::seller_wallet_2024_03_01::ErrorList),
56    Status404(models::seller_wallet_2024_03_01::ErrorList),
57    Status408(models::seller_wallet_2024_03_01::ErrorList),
58    Status413(models::seller_wallet_2024_03_01::ErrorList),
59    Status415(models::seller_wallet_2024_03_01::ErrorList),
60    Status429(models::seller_wallet_2024_03_01::ErrorList),
61    Status500(models::seller_wallet_2024_03_01::ErrorList),
62    Status503(models::seller_wallet_2024_03_01::ErrorList),
63    UnknownValue(serde_json::Value),
64}
65
66
67/// Retrieve a Seller Wallet bank account by Amazon account identifier.
68pub async fn get_account(configuration: &configuration::Configuration, account_id: &str) -> Result<models::seller_wallet_2024_03_01::BankAccount, Error<GetAccountError>> {
69    // add a prefix to parameters to efficiently prevent name collisions
70    let p_account_id = account_id;
71
72    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/accounts/{accountId}", configuration.base_path, accountId=crate::apis::urlencode(p_account_id));
73    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
74
75    if let Some(ref user_agent) = configuration.user_agent {
76        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77    }
78
79    let req = req_builder.build()?;
80    let resp = configuration.client.execute(req).await?;
81
82    let status = resp.status();
83    let content_type = resp
84        .headers()
85        .get("content-type")
86        .and_then(|v| v.to_str().ok())
87        .unwrap_or("application/octet-stream");
88    let content_type = super::ContentType::from(content_type);
89
90    if !status.is_client_error() && !status.is_server_error() {
91        let content = resp.text().await?;
92        match content_type {
93            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
94            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::seller_wallet_2024_03_01::BankAccount`"))),
95            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::seller_wallet_2024_03_01::BankAccount`")))),
96        }
97    } else {
98        let content = resp.text().await?;
99        let entity: Option<GetAccountError> = serde_json::from_str(&content).ok();
100        Err(Error::ResponseError(ResponseContent { status, content, entity }))
101    }
102}
103
104/// Retrieve the balance in a given Seller Wallet bank account.
105pub async fn list_account_balances(configuration: &configuration::Configuration, account_id: &str) -> Result<models::seller_wallet_2024_03_01::BalanceListing, Error<ListAccountBalancesError>> {
106    // add a prefix to parameters to efficiently prevent name collisions
107    let p_account_id = account_id;
108
109    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/accounts/{accountId}/balance", configuration.base_path, accountId=crate::apis::urlencode(p_account_id));
110    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
111
112    if let Some(ref user_agent) = configuration.user_agent {
113        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114    }
115
116    let req = req_builder.build()?;
117    let resp = configuration.client.execute(req).await?;
118
119    let status = resp.status();
120    let content_type = resp
121        .headers()
122        .get("content-type")
123        .and_then(|v| v.to_str().ok())
124        .unwrap_or("application/octet-stream");
125    let content_type = super::ContentType::from(content_type);
126
127    if !status.is_client_error() && !status.is_server_error() {
128        let content = resp.text().await?;
129        match content_type {
130            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
131            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::seller_wallet_2024_03_01::BalanceListing`"))),
132            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::seller_wallet_2024_03_01::BalanceListing`")))),
133        }
134    } else {
135        let content = resp.text().await?;
136        let entity: Option<ListAccountBalancesError> = serde_json::from_str(&content).ok();
137        Err(Error::ResponseError(ResponseContent { status, content, entity }))
138    }
139}
140
141/// Get Seller Wallet accounts for a seller.
142pub async fn list_accounts(configuration: &configuration::Configuration, marketplace_id: &str) -> Result<models::seller_wallet_2024_03_01::BankAccountListing, Error<ListAccountsError>> {
143    // add a prefix to parameters to efficiently prevent name collisions
144    let p_marketplace_id = marketplace_id;
145
146    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/accounts", configuration.base_path);
147    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
148
149    req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
150    if let Some(ref user_agent) = configuration.user_agent {
151        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
152    }
153
154    let req = req_builder.build()?;
155    let resp = configuration.client.execute(req).await?;
156
157    let status = resp.status();
158    let content_type = resp
159        .headers()
160        .get("content-type")
161        .and_then(|v| v.to_str().ok())
162        .unwrap_or("application/octet-stream");
163    let content_type = super::ContentType::from(content_type);
164
165    if !status.is_client_error() && !status.is_server_error() {
166        let content = resp.text().await?;
167        match content_type {
168            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
169            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::seller_wallet_2024_03_01::BankAccountListing`"))),
170            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::seller_wallet_2024_03_01::BankAccountListing`")))),
171        }
172    } else {
173        let content = resp.text().await?;
174        let entity: Option<ListAccountsError> = serde_json::from_str(&content).ok();
175        Err(Error::ResponseError(ResponseContent { status, content, entity }))
176    }
177}
178