amazon_spapi/apis/
transactions_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 [`create_transaction`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateTransactionError {
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    Status422(models::seller_wallet_2024_03_01::ErrorList),
29    Status429(models::seller_wallet_2024_03_01::ErrorList),
30    Status500(models::seller_wallet_2024_03_01::ErrorList),
31    Status503(models::seller_wallet_2024_03_01::ErrorList),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`get_transaction`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetTransactionError {
39    Status400(models::seller_wallet_2024_03_01::ErrorList),
40    Status403(models::seller_wallet_2024_03_01::ErrorList),
41    Status404(models::seller_wallet_2024_03_01::ErrorList),
42    Status408(models::seller_wallet_2024_03_01::ErrorList),
43    Status413(models::seller_wallet_2024_03_01::ErrorList),
44    Status415(models::seller_wallet_2024_03_01::ErrorList),
45    Status429(models::seller_wallet_2024_03_01::ErrorList),
46    Status500(models::seller_wallet_2024_03_01::ErrorList),
47    Status503(models::seller_wallet_2024_03_01::ErrorList),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`list_account_transactions`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum ListAccountTransactionsError {
55    Status400(models::seller_wallet_2024_03_01::ErrorList),
56    Status403(models::seller_wallet_2024_03_01::ErrorList),
57    Status404(models::seller_wallet_2024_03_01::ErrorList),
58    Status408(models::seller_wallet_2024_03_01::ErrorList),
59    Status413(models::seller_wallet_2024_03_01::ErrorList),
60    Status415(models::seller_wallet_2024_03_01::ErrorList),
61    Status429(models::seller_wallet_2024_03_01::ErrorList),
62    Status500(models::seller_wallet_2024_03_01::ErrorList),
63    Status503(models::seller_wallet_2024_03_01::ErrorList),
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Create a transaction request from a Seller Wallet account to another customer-provided account.
69pub async fn create_transaction(configuration: &configuration::Configuration, dest_account_digital_signature: &str, amount_digital_signature: &str, body: models::seller_wallet_2024_03_01::TransactionInitiationRequest) -> Result<models::seller_wallet_2024_03_01::Transaction, Error<CreateTransactionError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    let p_dest_account_digital_signature = dest_account_digital_signature;
72    let p_amount_digital_signature = amount_digital_signature;
73    let p_body = body;
74
75    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transactions", configuration.base_path);
76    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
77
78    if let Some(ref user_agent) = configuration.user_agent {
79        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
80    }
81    req_builder = req_builder.header("destAccountDigitalSignature", p_dest_account_digital_signature.to_string());
82    req_builder = req_builder.header("amountDigitalSignature", p_amount_digital_signature.to_string());
83    req_builder = req_builder.json(&p_body);
84
85    let req = req_builder.build()?;
86    let resp = configuration.client.execute(req).await?;
87
88    let status = resp.status();
89    let content_type = resp
90        .headers()
91        .get("content-type")
92        .and_then(|v| v.to_str().ok())
93        .unwrap_or("application/octet-stream");
94    let content_type = super::ContentType::from(content_type);
95
96    if !status.is_client_error() && !status.is_server_error() {
97        let content = resp.text().await?;
98        match content_type {
99            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
100            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::Transaction`"))),
101            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::Transaction`")))),
102        }
103    } else {
104        let content = resp.text().await?;
105        let entity: Option<CreateTransactionError> = serde_json::from_str(&content).ok();
106        Err(Error::ResponseError(ResponseContent { status, content, entity }))
107    }
108}
109
110/// Returns a transaction
111pub async fn get_transaction(configuration: &configuration::Configuration, transaction_id: &str) -> Result<models::seller_wallet_2024_03_01::Transaction, Error<GetTransactionError>> {
112    // add a prefix to parameters to efficiently prevent name collisions
113    let p_transaction_id = transaction_id;
114
115    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transactions/{transactionId}", configuration.base_path, transactionId=crate::apis::urlencode(p_transaction_id));
116    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
117
118    if let Some(ref user_agent) = configuration.user_agent {
119        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
120    }
121
122    let req = req_builder.build()?;
123    let resp = configuration.client.execute(req).await?;
124
125    let status = resp.status();
126    let content_type = resp
127        .headers()
128        .get("content-type")
129        .and_then(|v| v.to_str().ok())
130        .unwrap_or("application/octet-stream");
131    let content_type = super::ContentType::from(content_type);
132
133    if !status.is_client_error() && !status.is_server_error() {
134        let content = resp.text().await?;
135        match content_type {
136            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
137            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::Transaction`"))),
138            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::Transaction`")))),
139        }
140    } else {
141        let content = resp.text().await?;
142        let entity: Option<GetTransactionError> = serde_json::from_str(&content).ok();
143        Err(Error::ResponseError(ResponseContent { status, content, entity }))
144    }
145}
146
147/// Retrieve a list of transactions for a given Seller Wallet bank account.
148pub async fn list_account_transactions(configuration: &configuration::Configuration, account_id: &str, next_page_token: Option<&str>) -> Result<models::seller_wallet_2024_03_01::TransactionListing, Error<ListAccountTransactionsError>> {
149    // add a prefix to parameters to efficiently prevent name collisions
150    let p_account_id = account_id;
151    let p_next_page_token = next_page_token;
152
153    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transactions", configuration.base_path);
154    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
155
156    req_builder = req_builder.query(&[("accountId", &p_account_id.to_string())]);
157    if let Some(ref param_value) = p_next_page_token {
158        req_builder = req_builder.query(&[("nextPageToken", &param_value.to_string())]);
159    }
160    if let Some(ref user_agent) = configuration.user_agent {
161        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
162    }
163
164    let req = req_builder.build()?;
165    let resp = configuration.client.execute(req).await?;
166
167    let status = resp.status();
168    let content_type = resp
169        .headers()
170        .get("content-type")
171        .and_then(|v| v.to_str().ok())
172        .unwrap_or("application/octet-stream");
173    let content_type = super::ContentType::from(content_type);
174
175    if !status.is_client_error() && !status.is_server_error() {
176        let content = resp.text().await?;
177        match content_type {
178            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
179            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::TransactionListing`"))),
180            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::TransactionListing`")))),
181        }
182    } else {
183        let content = resp.text().await?;
184        let entity: Option<ListAccountTransactionsError> = serde_json::from_str(&content).ok();
185        Err(Error::ResponseError(ResponseContent { status, content, entity }))
186    }
187}
188