From 29d9b97ad4b8e233bfd8f392ca0ec5fa346e73b6 Mon Sep 17 00:00:00 2001 From: Richard Wossal Date: Thu, 8 Feb 2024 15:54:21 +0100 Subject: [PATCH 1/2] Chore: add invoice property `language` --- invoices.go | 1 + 1 file changed, 1 insertion(+) diff --git a/invoices.go b/invoices.go index 0fce814..11f2590 100644 --- a/invoices.go +++ b/invoices.go @@ -40,6 +40,7 @@ type InvoiceBody struct { Title string `json:"title"` Introduction string `json:"introduction"` Remark string `json:"remark"` + Language string `json:"language"` } type InvoiceBodyAddress struct { From a77f4a04bf043aaca16239f501c14dc27765739e Mon Sep 17 00:00:00 2001 From: Richard Wossal Date: Thu, 8 Feb 2024 16:03:32 +0100 Subject: [PATCH 2/2] Chore: support finalized=true for creating invoices --- invoices.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/invoices.go b/invoices.go index 11f2590..1b5a103 100644 --- a/invoices.go +++ b/invoices.go @@ -156,6 +156,16 @@ func (c *Config) Invoice(id string) (InvoiceBody, error) { // AddInvoice is to create a invoice func (c *Config) AddInvoice(body InvoiceBody) (InvoiceReturn, error) { + // NOTE: we're using VoucherStatus ("open" or "draft") to determine if this + // should be a draft invoice + // + // The way the API works is this: (https://developers.lexoffice.io/docs/#invoices-endpoint-create-an-invoice) + // > Invoices transmitted via the API are created in draft mode per default. To + // > create a finalized invoice with status open the optional query parameter + // > finalize has to be set. The status of an invoice cannot be changed via the api. + isOpen := body.VoucherStatus == "open" + body.VoucherStatus = "" // unset for the request + // Convert body convert, err := json.Marshal(body) if err != nil { @@ -166,7 +176,11 @@ func (c *Config) AddInvoice(body InvoiceBody) (InvoiceReturn, error) { //c := NewConfig(, token, &http.Client{}) // Send request - response, err := c.Send("/v1/invoices", bytes.NewBuffer(convert), "POST", "application/json") + url := "/v1/invoices" + if isOpen { + url += "?finalize=true" + } + response, err := c.Send(url, bytes.NewBuffer(convert), "POST", "application/json") if err != nil { return InvoiceReturn{}, err }