use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, RequestOptions};
use reqwest::Method;
pub struct ChargeBacksClient {
pub http_client: HttpClient,
}
impl ChargeBacksClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
pub async fn add_response(
&self,
id: i64,
request: &ResponseChargeBack,
options: Option<RequestOptions>,
) -> Result<AddResponseResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("ChargeBacks/response/{}", id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
pub async fn get_chargeback(
&self,
id: i64,
options: Option<RequestOptions>,
) -> Result<ChargebackQueryRecords, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("ChargeBacks/read/{}", id),
None,
None,
options,
)
.await
}
pub async fn get_chargeback_attachment(
&self,
id: i64,
file_name: &str,
options: Option<RequestOptions>,
) -> Result<String, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("ChargeBacks/getChargebackAttachments/{}/{}", id, file_name),
None,
None,
options,
)
.await
}
}