amazon-spapi 2.0.3

A Rust client library for Amazon Selling Partner API (SP-API)
Documentation
/*
 * The Selling Partner API for Transfers.
 *
 * 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.
 *
 * The version of the OpenAPI document: 2024-06-01
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};


/// struct for typed errors of method [`get_payment_methods`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPaymentMethodsError {
    Status400(models::transfers_2024_06_01::ErrorList),
    Status403(models::transfers_2024_06_01::ErrorList),
    Status404(models::transfers_2024_06_01::ErrorList),
    Status413(models::transfers_2024_06_01::ErrorList),
    Status415(models::transfers_2024_06_01::ErrorList),
    Status429(models::transfers_2024_06_01::ErrorList),
    Status500(models::transfers_2024_06_01::ErrorList),
    Status503(models::transfers_2024_06_01::ErrorList),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`initiate_payout`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InitiatePayoutError {
    Status400(models::transfers_2024_06_01::ErrorList),
    Status403(models::transfers_2024_06_01::ErrorList),
    Status404(models::transfers_2024_06_01::ErrorList),
    Status413(models::transfers_2024_06_01::ErrorList),
    Status415(models::transfers_2024_06_01::ErrorList),
    Status429(models::transfers_2024_06_01::ErrorList),
    Status500(models::transfers_2024_06_01::ErrorList),
    Status503(models::transfers_2024_06_01::ErrorList),
    UnknownValue(serde_json::Value),
}


/// 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).
pub 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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_marketplace_id = marketplace_id;
    let p_payment_method_types = payment_method_types;

    let uri_str = format!("{}/finances/transfers/2024-06-01/paymentMethods", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
    if let Some(ref param_value) = p_payment_method_types {
        req_builder = match "csv" {
            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("paymentMethodTypes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
            _ => req_builder.query(&[("paymentMethodTypes", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
        };
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPaymentMethodsResponse`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetPaymentMethodsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// 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).
pub async fn initiate_payout(configuration: &configuration::Configuration, body: models::transfers_2024_06_01::InitiatePayoutRequest) -> Result<models::transfers_2024_06_01::InitiatePayoutResponse, Error<InitiatePayoutError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body = body;

    let uri_str = format!("{}/finances/transfers/2024-06-01/payouts", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    req_builder = req_builder.json(&p_body);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InitiatePayoutResponse`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<InitiatePayoutError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}