amazon_spapi/apis/
transfer_preview_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_transfer_preview`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetTransferPreviewError {
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
35/// Returns list of potential fees on a transaction based on the source and destination country currency code
36pub async fn get_transfer_preview(configuration: &configuration::Configuration, source_country_code: &str, source_currency_code: &str, destination_country_code: &str, destination_currency_code: &str, base_amount: f64) -> Result<models::seller_wallet_2024_03_01::TransferRatePreview, Error<GetTransferPreviewError>> {
37    // add a prefix to parameters to efficiently prevent name collisions
38    let p_source_country_code = source_country_code;
39    let p_source_currency_code = source_currency_code;
40    let p_destination_country_code = destination_country_code;
41    let p_destination_currency_code = destination_currency_code;
42    let p_base_amount = base_amount;
43
44    let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/transferPreview", configuration.base_path);
45    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
46
47    req_builder = req_builder.query(&[("sourceCountryCode", &p_source_country_code.to_string())]);
48    req_builder = req_builder.query(&[("sourceCurrencyCode", &p_source_currency_code.to_string())]);
49    req_builder = req_builder.query(&[("destinationCountryCode", &p_destination_country_code.to_string())]);
50    req_builder = req_builder.query(&[("destinationCurrencyCode", &p_destination_currency_code.to_string())]);
51    req_builder = req_builder.query(&[("baseAmount", &p_base_amount.to_string())]);
52    if let Some(ref user_agent) = configuration.user_agent {
53        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
54    }
55
56    let req = req_builder.build()?;
57    let resp = configuration.client.execute(req).await?;
58
59    let status = resp.status();
60    let content_type = resp
61        .headers()
62        .get("content-type")
63        .and_then(|v| v.to_str().ok())
64        .unwrap_or("application/octet-stream");
65    let content_type = super::ContentType::from(content_type);
66
67    if !status.is_client_error() && !status.is_server_error() {
68        let content = resp.text().await?;
69        match content_type {
70            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
71            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::TransferRatePreview`"))),
72            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::TransferRatePreview`")))),
73        }
74    } else {
75        let content = resp.text().await?;
76        let entity: Option<GetTransferPreviewError> = serde_json::from_str(&content).ok();
77        Err(Error::ResponseError(ResponseContent { status, content, entity }))
78    }
79}
80