Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language; support finalized=true for creating invoices #3

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading