Skip to content

Commit

Permalink
Merge pull request #3 from hostwithquantum/add-language
Browse files Browse the repository at this point in the history
Add `language`; support finalized=true for creating invoices
  • Loading branch information
rwos committed Feb 8, 2024
2 parents 343b8df + a77f4a0 commit 7b3c10f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -155,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 {
Expand All @@ -165,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
}
Expand Down

0 comments on commit 7b3c10f

Please sign in to comment.