amazon_spapi/apis/
transfers_2024_06_01.rs

1/*
2 * The Selling Partner API for Transfers.
3 *
4 * The Selling Partner API for Transfers enables selling partners to retrieve payment methods and initiate payouts for their seller accounts. This API supports the following marketplaces: DE, FR, IT, ES, SE, NL, PL, and BE.
5 *
6 * The version of the OpenAPI document: 2024-06-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_payment_methods`]
19#[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/// struct for typed errors of method [`initiate_payout`]
34#[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
49/// Returns the list of payment methods for the seller, which can be filtered by method type.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | .5 | 30 |  The `x-amzn-RateLimit-Limit` response header contains the usage plan rate limits for the operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
50pub 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    // add a prefix to parameters to efficiently prevent name collisions
52    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(&param_value.into_iter().map(|p| ("paymentMethodTypes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
62            _ => req_builder.query(&[("paymentMethodTypes", &param_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
94/// Initiates an on-demand payout to the seller's default deposit method in Seller Central for the given `marketplaceId` and `accountType`, if eligible. You can only initiate one on-demand payout for each marketplace and account type within a 24-hour period.   **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.017 | 2 |  The `x-amzn-RateLimit-Limit` response header contains the usage plan rate limits for the operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
95pub async fn initiate_payout(configuration: &configuration::Configuration, body: models::transfers_2024_06_01::InitiatePayoutRequest) -> Result<models::transfers_2024_06_01::InitiatePayoutResponse, Error<InitiatePayoutError>> {
96    // add a prefix to parameters to efficiently prevent name collisions
97    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