pub mod delegated;
pub mod types;
#[allow(unused_imports)]
use types::*;
#[derive(Clone)]
pub struct PayoutsClient {
client: crate::client::Client,
}
impl PayoutsClient {
pub fn new(client: crate::client::Client) -> Self {
PayoutsClient { client }
}
pub async fn list_payouts(
&self,
query: Option<ListPayoutsQuery>,
) -> Result<ListPayoutsResponse, crate::error::Error> {
let mut path = String::from("/payouts");
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.limit {
q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.pagination_token {
q.push(format!(
"paginationToken={}",
urlencoding::encode(&v.to_string())
));
}
if let Some(v) = &query.wallet_id {
q.push(format!("walletId={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.status {
for item in v {
q.push(format!("status={}", urlencoding::encode(&item.to_string())));
}
}
if let Some(v) = &query.provider {
for item in v {
q.push(format!(
"provider={}",
urlencoding::encode(&item.to_string())
));
}
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListPayoutsResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn create_payout(
&self,
body: CreatePayoutRequest,
) -> Result<serde_json::Value, crate::error::Error> {
let path = String::from("/payouts");
let body = serde_json::to_value(&body)?;
self.client
.request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), true)
.await
}
pub async fn request_payout_quote(
&self,
body: RequestPayoutQuoteRequest,
) -> Result<RequestPayoutQuoteResponse, crate::error::Error> {
let path = String::from("/payouts/quote");
let body = serde_json::to_value(&body)?;
self.client
.request::<RequestPayoutQuoteResponse>(reqwest::Method::POST, &path, Some(&body), false)
.await
}
pub async fn get_payout_status(
&self,
payout_id: String,
) -> Result<serde_json::Value, crate::error::Error> {
let path = format!("/payouts/{}", urlencoding::encode(&payout_id));
self.client
.request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn create_payout_action(
&self,
payout_id: String,
body: CreatePayoutActionRequest,
) -> Result<CreatePayoutActionResponse, crate::error::Error> {
let path = format!("/payouts/{}/action", urlencoding::encode(&payout_id));
let body = serde_json::to_value(&body)?;
self.client
.request::<CreatePayoutActionResponse>(reqwest::Method::POST, &path, Some(&body), true)
.await
}
}