From b125e95e4320b0e74d2cac337e012dcae7366a8d Mon Sep 17 00:00:00 2001 From: Edgar Date: Wed, 12 Aug 2020 15:01:31 +0200 Subject: [PATCH] add get_invoice and list_invoices --- src/common.rs | 2 +- src/invoice.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index 9a9bada..e44dd33 100644 --- a/src/common.rs +++ b/src/common.rs @@ -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, -} +} \ No newline at end of file diff --git a/src/invoice.rs b/src/invoice.rs index 956866e..6b53175 100644 --- a/src/invoice.rs +++ b/src/invoice.rs @@ -644,6 +644,19 @@ pub struct Invoice { pub links: Option>, } +/// 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, + /// HATEOAS links + links: Vec, +} + 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::().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> { + 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::().await?; + Ok(x) + } else { + Err(Box::new(res.json::().await?)) + } + } }