Skip to main content

highlevel_api/apis/invoices/
client.rs

1use super::types::*;
2use crate::{error::Result, http::HttpClient};
3use std::sync::Arc;
4
5pub struct InvoicesApi {
6    http: Arc<HttpClient>,
7}
8
9impl InvoicesApi {
10    pub fn new(http: Arc<HttpClient>) -> Self {
11        Self { http }
12    }
13
14    pub async fn list(&self, params: &ListInvoicesParams) -> Result<GetInvoicesResponse> {
15        self.http.get_with_query("/invoices", params).await
16    }
17
18    pub async fn get(&self, invoice_id: &str) -> Result<GetInvoiceResponse> {
19        self.http.get(&format!("/invoices/{invoice_id}")).await
20    }
21
22    pub async fn create(&self, params: &CreateInvoiceParams) -> Result<GetInvoiceResponse> {
23        self.http.post("/invoices", params).await
24    }
25
26    pub async fn update(
27        &self,
28        invoice_id: &str,
29        params: &CreateInvoiceParams,
30    ) -> Result<GetInvoiceResponse> {
31        self.http
32            .put(&format!("/invoices/{invoice_id}"), params)
33            .await
34    }
35
36    pub async fn delete(&self, invoice_id: &str) -> Result<()> {
37        self.http
38            .delete_no_content(&format!("/invoices/{invoice_id}"))
39            .await
40    }
41
42    pub async fn send(
43        &self,
44        invoice_id: &str,
45        params: &SendInvoiceParams,
46    ) -> Result<GetInvoiceResponse> {
47        self.http
48            .post(&format!("/invoices/{invoice_id}/send"), params)
49            .await
50    }
51
52    pub async fn record_payment(
53        &self,
54        invoice_id: &str,
55        params: &RecordPaymentParams,
56    ) -> Result<GetInvoiceResponse> {
57        self.http
58            .post(&format!("/invoices/{invoice_id}/record-payment"), params)
59            .await
60    }
61
62    pub async fn generate_invoice_number(
63        &self,
64        location_id: &str,
65    ) -> Result<GenerateInvoiceNumberResponse> {
66        #[derive(serde::Serialize)]
67        struct Body<'a> {
68            #[serde(rename = "locationId")]
69            location_id: &'a str,
70        }
71        self.http
72            .post("/invoices/generate-invoice-number", &Body { location_id })
73            .await
74    }
75
76    // ── Schedules (deposit/balance split) ─────────────────────────────────────
77
78    pub async fn list_schedules(&self, invoice_id: &str) -> Result<ListSchedulesResponse> {
79        self.http
80            .get(&format!("/invoices/{invoice_id}/schedules"))
81            .await
82    }
83
84    pub async fn create_schedule(
85        &self,
86        invoice_id: &str,
87        params: &CreateScheduleParams,
88    ) -> Result<GetScheduleResponse> {
89        self.http
90            .post(&format!("/invoices/{invoice_id}/schedules"), params)
91            .await
92    }
93}