amazon_spapi/apis/
transfer_schedule_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_transfer_schedule`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateTransferScheduleError {
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    Status409(models::seller_wallet_2024_03_01::ErrorList),
27    Status413(models::seller_wallet_2024_03_01::ErrorList),
28    Status415(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 [`delete_schedule_transaction`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum DeleteScheduleTransactionError {
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 [`get_transfer_schedule`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum GetTransferScheduleError {
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/// struct for typed errors of method [`list_transfer_schedules`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ListTransferSchedulesError {
71    Status400(models::seller_wallet_2024_03_01::ErrorList),
72    Status403(models::seller_wallet_2024_03_01::ErrorList),
73    Status404(models::seller_wallet_2024_03_01::ErrorList),
74    Status408(models::seller_wallet_2024_03_01::ErrorList),
75    Status413(models::seller_wallet_2024_03_01::ErrorList),
76    Status415(models::seller_wallet_2024_03_01::ErrorList),
77    Status429(models::seller_wallet_2024_03_01::ErrorList),
78    Status500(models::seller_wallet_2024_03_01::ErrorList),
79    Status503(models::seller_wallet_2024_03_01::ErrorList),
80    UnknownValue(serde_json::Value),
81}
82
83/// struct for typed errors of method [`update_transfer_schedule`]
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum UpdateTransferScheduleError {
87    Status400(models::seller_wallet_2024_03_01::ErrorList),
88    Status403(models::seller_wallet_2024_03_01::ErrorList),
89    Status404(models::seller_wallet_2024_03_01::ErrorList),
90    Status408(models::seller_wallet_2024_03_01::ErrorList),
91    Status413(models::seller_wallet_2024_03_01::ErrorList),
92    Status415(models::seller_wallet_2024_03_01::ErrorList),
93    Status429(models::seller_wallet_2024_03_01::ErrorList),
94    Status500(models::seller_wallet_2024_03_01::ErrorList),
95    Status503(models::seller_wallet_2024_03_01::ErrorList),
96    UnknownValue(serde_json::Value),
97}
98
99
100/// Create a transfer schedule request from a Seller Wallet account to another customer-provided account.
101pub async fn create_transfer_schedule(configuration: &configuration::Configuration, dest_account_digital_signature: &str, amount_digital_signature: &str, body: models::seller_wallet_2024_03_01::TransferScheduleRequest) -> Result<models::seller_wallet_2024_03_01::TransferSchedule, Error<CreateTransferScheduleError>> {
102    // add a prefix to parameters to efficiently prevent name collisions
103    let p_dest_account_digital_signature = dest_account_digital_signature;
104    let p_amount_digital_signature = amount_digital_signature;
105    let p_body = body;
106
107    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transferSchedules", configuration.base_path);
108    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
109
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    req_builder = req_builder.header("destAccountDigitalSignature", p_dest_account_digital_signature.to_string());
114    req_builder = req_builder.header("amountDigitalSignature", p_amount_digital_signature.to_string());
115    req_builder = req_builder.json(&p_body);
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132            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::TransferSchedule`"))),
133            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::TransferSchedule`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<CreateTransferScheduleError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent { status, content, entity }))
139    }
140}
141
142/// Delete a transaction request that is scheduled from a Seller Wallet account to another customer-provided account.
143pub async fn delete_schedule_transaction(configuration: &configuration::Configuration, transfer_schedule_id: &str) -> Result<models::seller_wallet_2024_03_01::DeleteTransferSchedule, Error<DeleteScheduleTransactionError>> {
144    // add a prefix to parameters to efficiently prevent name collisions
145    let p_transfer_schedule_id = transfer_schedule_id;
146
147    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transferSchedules/{transferScheduleId}", configuration.base_path, transferScheduleId=crate::apis::urlencode(p_transfer_schedule_id));
148    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
149
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::DeleteTransferSchedule`"))),
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::DeleteTransferSchedule`")))),
171        }
172    } else {
173        let content = resp.text().await?;
174        let entity: Option<DeleteScheduleTransactionError> = serde_json::from_str(&content).ok();
175        Err(Error::ResponseError(ResponseContent { status, content, entity }))
176    }
177}
178
179/// Find a particular Seller Wallet account transfer schedule.
180pub async fn get_transfer_schedule(configuration: &configuration::Configuration, transfer_schedule_id: &str) -> Result<models::seller_wallet_2024_03_01::TransferSchedule, Error<GetTransferScheduleError>> {
181    // add a prefix to parameters to efficiently prevent name collisions
182    let p_transfer_schedule_id = transfer_schedule_id;
183
184    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transferSchedules/{transferScheduleId}", configuration.base_path, transferScheduleId=crate::apis::urlencode(p_transfer_schedule_id));
185    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
186
187    if let Some(ref user_agent) = configuration.user_agent {
188        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189    }
190
191    let req = req_builder.build()?;
192    let resp = configuration.client.execute(req).await?;
193
194    let status = resp.status();
195    let content_type = resp
196        .headers()
197        .get("content-type")
198        .and_then(|v| v.to_str().ok())
199        .unwrap_or("application/octet-stream");
200    let content_type = super::ContentType::from(content_type);
201
202    if !status.is_client_error() && !status.is_server_error() {
203        let content = resp.text().await?;
204        match content_type {
205            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
206            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::TransferSchedule`"))),
207            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::TransferSchedule`")))),
208        }
209    } else {
210        let content = resp.text().await?;
211        let entity: Option<GetTransferScheduleError> = serde_json::from_str(&content).ok();
212        Err(Error::ResponseError(ResponseContent { status, content, entity }))
213    }
214}
215
216/// Retrieve transfer schedules of a Seller Wallet bank account.
217pub async fn list_transfer_schedules(configuration: &configuration::Configuration, account_id: &str, next_page_token: Option<&str>) -> Result<models::seller_wallet_2024_03_01::TransferScheduleListing, Error<ListTransferSchedulesError>> {
218    // add a prefix to parameters to efficiently prevent name collisions
219    let p_account_id = account_id;
220    let p_next_page_token = next_page_token;
221
222    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transferSchedules", configuration.base_path);
223    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
224
225    req_builder = req_builder.query(&[("accountId", &p_account_id.to_string())]);
226    if let Some(ref param_value) = p_next_page_token {
227        req_builder = req_builder.query(&[("nextPageToken", &param_value.to_string())]);
228    }
229    if let Some(ref user_agent) = configuration.user_agent {
230        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
231    }
232
233    let req = req_builder.build()?;
234    let resp = configuration.client.execute(req).await?;
235
236    let status = resp.status();
237    let content_type = resp
238        .headers()
239        .get("content-type")
240        .and_then(|v| v.to_str().ok())
241        .unwrap_or("application/octet-stream");
242    let content_type = super::ContentType::from(content_type);
243
244    if !status.is_client_error() && !status.is_server_error() {
245        let content = resp.text().await?;
246        match content_type {
247            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
248            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::TransferScheduleListing`"))),
249            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::TransferScheduleListing`")))),
250        }
251    } else {
252        let content = resp.text().await?;
253        let entity: Option<ListTransferSchedulesError> = serde_json::from_str(&content).ok();
254        Err(Error::ResponseError(ResponseContent { status, content, entity }))
255    }
256}
257
258/// Returns a transfer belonging to the updated scheduled transfer request
259pub async fn update_transfer_schedule(configuration: &configuration::Configuration, dest_account_digital_signature: &str, amount_digital_signature: &str, body: models::seller_wallet_2024_03_01::TransferSchedule) -> Result<models::seller_wallet_2024_03_01::TransferSchedule, Error<UpdateTransferScheduleError>> {
260    // add a prefix to parameters to efficiently prevent name collisions
261    let p_dest_account_digital_signature = dest_account_digital_signature;
262    let p_amount_digital_signature = amount_digital_signature;
263    let p_body = body;
264
265    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transferSchedules", configuration.base_path);
266    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
267
268    if let Some(ref user_agent) = configuration.user_agent {
269        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
270    }
271    req_builder = req_builder.header("destAccountDigitalSignature", p_dest_account_digital_signature.to_string());
272    req_builder = req_builder.header("amountDigitalSignature", p_amount_digital_signature.to_string());
273    req_builder = req_builder.json(&p_body);
274
275    let req = req_builder.build()?;
276    let resp = configuration.client.execute(req).await?;
277
278    let status = resp.status();
279    let content_type = resp
280        .headers()
281        .get("content-type")
282        .and_then(|v| v.to_str().ok())
283        .unwrap_or("application/octet-stream");
284    let content_type = super::ContentType::from(content_type);
285
286    if !status.is_client_error() && !status.is_server_error() {
287        let content = resp.text().await?;
288        match content_type {
289            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
290            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::TransferSchedule`"))),
291            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::TransferSchedule`")))),
292        }
293    } else {
294        let content = resp.text().await?;
295        let entity: Option<UpdateTransferScheduleError> = serde_json::from_str(&content).ok();
296        Err(Error::ResponseError(ResponseContent { status, content, entity }))
297    }
298}
299