add get_invoice and list_invoices

This commit is contained in:
Edgar 2020-08-12 15:01:31 +02:00
parent a8b57dd256
commit b125e95e43
No known key found for this signature in database
GPG key ID: 8731E6C0166EAA85
2 changed files with 38 additions and 1 deletions

View file

@ -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>,
}
}

View file

@ -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?))
}
}
}