add get_invoice and list_invoices
This commit is contained in:
parent
a8b57dd256
commit
b125e95e43
|
@ -105,4 +105,4 @@ pub struct LinkDescription {
|
|||
/// The HTTP method required to make the related call.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub method: Option<LinkMethod>,
|
||||
}
|
||||
}
|
|
@ -644,6 +644,19 @@ pub struct Invoice {
|
|||
pub links: Option<Vec<LinkDescription>>,
|
||||
}
|
||||
|
||||
/// A invoice list
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InvoiceList {
|
||||
/// Total items
|
||||
pub total_items: i32,
|
||||
/// Total pages
|
||||
pub total_pages: i32,
|
||||
/// The invoices
|
||||
items: Vec<Invoice>,
|
||||
/// HATEOAS links
|
||||
links: Vec<LinkDescription>,
|
||||
}
|
||||
|
||||
impl super::Client {
|
||||
/// Generates the next invoice number that is available to the merchant.
|
||||
///
|
||||
|
@ -714,4 +727,28 @@ impl super::Client {
|
|||
Err(Box::new(res.json::<errors::ApiResponseError>().await?))
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an invoice by ID.
|
||||
/// Page size has the following limits: [1, 100].
|
||||
pub async fn list_invoices(
|
||||
&self,
|
||||
header_params: crate::HeaderParams,
|
||||
page: i32,
|
||||
page_size: i32,
|
||||
) -> Result<InvoiceList, Box<dyn std::error::Error>> {
|
||||
let build = self.setup_headers(
|
||||
self.client
|
||||
.get(format!("{}/v2/invoicing/invoices?page={}&page_size={}&total_required=true", self.endpoint(), page, page_size).as_str()),
|
||||
header_params,
|
||||
);
|
||||
|
||||
let res = build.send().await?;
|
||||
|
||||
if res.status().is_success() {
|
||||
let x = res.json::<InvoiceList>().await?;
|
||||
Ok(x)
|
||||
} else {
|
||||
Err(Box::new(res.json::<errors::ApiResponseError>().await?))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue