#[allow(unused_imports)]
use super::types::*;
#[derive(Clone)]
pub struct DelegatedPayinsClient {
client: crate::client::Client,
}
impl DelegatedPayinsClient {
pub fn new(client: crate::client::Client) -> Self {
DelegatedPayinsClient { client }
}
pub async fn list_payins(
&self,
query: Option<ListPayinsQuery>,
) -> Result<ListPayinsResponse, crate::error::Error> {
let mut path = String::from("/payins");
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::<ListPayinsResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn create_payin_init(
&self,
body: CreatePayinRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/payins");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
pub async fn create_payin_complete(
&self,
body: CreatePayinRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<serde_json::Value, crate::error::Error> {
let path = String::from("/payins");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<serde_json::Value>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.await
}
pub async fn get_payin_recipient(
&self,
query: Option<GetPayinRecipientQuery>,
) -> Result<GetPayinRecipientResponse, crate::error::Error> {
let mut path = String::from("/payins/recipients");
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
q.push(format!(
"provider={}",
urlencoding::encode(&query.provider.to_string())
));
q.push(format!(
"walletId={}",
urlencoding::encode(&query.wallet_id.to_string())
));
q.push(format!(
"currency={}",
urlencoding::encode(&query.currency.to_string())
));
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<GetPayinRecipientResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn register_payin_recipient_init(
&self,
body: RegisterPayinRecipientRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/payins/recipients");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
pub async fn register_payin_recipient_complete(
&self,
body: RegisterPayinRecipientRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<RegisterPayinRecipientResponse, crate::error::Error> {
let path = String::from("/payins/recipients");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<RegisterPayinRecipientResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.await
}
pub async fn get_payin_status(
&self,
payin_id: String,
) -> Result<serde_json::Value, crate::error::Error> {
let path = format!("/payins/{}", urlencoding::encode(&payin_id));
self.client
.request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn list_payin_balances(
&self,
query: Option<ListPayinBalancesQuery>,
) -> Result<ListPayinBalancesResponse, crate::error::Error> {
let mut path = String::from("/payins/balances");
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
q.push(format!(
"provider={}",
urlencoding::encode(&query.provider.to_string())
));
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListPayinBalancesResponse>(reqwest::Method::GET, &path, None, false)
.await
}
}