use reqwest::Method;
use crate::{Client, Invoice, InvoiceListOptions, InvoiceUpdateRequest, RequestOptions, Result};
use super::path_segment;
#[derive(Debug, Clone)]
pub struct Invoices {
client: Client,
}
impl Invoices {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn list(&self, options: &InvoiceListOptions) -> Result<Vec<Invoice>> {
let request = self
.client
.request(Method::GET, "/v1/invoices")?
.query(options);
self.client.send_collection(request, "invoices").await
}
pub async fn get(&self, id: &str) -> Result<Invoice> {
let request = self
.client
.request(Method::GET, &format!("/v1/invoices/{}", path_segment(id)))?;
self.client.send(request, RequestOptions::default()).await
}
pub async fn update(
&self,
id: &str,
input: &InvoiceUpdateRequest,
options: RequestOptions,
) -> Result<Invoice> {
let request = self
.client
.request(Method::PATCH, &format!("/v1/invoices/{}", path_segment(id)))?
.json(input);
self.client.send(request, options).await
}
pub async fn cancel(&self, id: &str, options: RequestOptions) -> Result<Invoice> {
self.client
.post_empty(
&format!("/v1/invoices/{}/cancel", path_segment(id)),
options,
)
.await
}
pub async fn retry(&self, id: &str, options: RequestOptions) -> Result<Invoice> {
self.client
.post_empty(&format!("/v1/invoices/{}/retry", path_segment(id)), options)
.await
}
}