From 72a1a167f7951c8662791f8522c775bfeea03ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Semp=C3=A9?= Date: Mon, 15 Jul 2024 11:03:21 +0200 Subject: [PATCH] feat(analytics): Add overdue balance endpoint --- gross_revenue.go | 1 + overdue_balance.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 overdue_balance.go diff --git a/gross_revenue.go b/gross_revenue.go index fee9910..11153f5 100644 --- a/gross_revenue.go +++ b/gross_revenue.go @@ -24,6 +24,7 @@ type GrossRevenue struct { Month string `json:"month,omitempty"` AmountCents int `json:"amount_cents,omitempty"` AmountCurrency Currency `json:"currency,omitempty"` + InvoicesCount int `json:"invoices_count,omitempty"` } func (c *Client) GrossRevenue() *GrossRevenueRequest { diff --git a/overdue_balance.go b/overdue_balance.go new file mode 100644 index 0000000..0d3fa52 --- /dev/null +++ b/overdue_balance.go @@ -0,0 +1,63 @@ +package lago + +import ( + "context" + "encoding/json" +) + +type OverdueBalanceRequest struct { + client *Client +} + +type OverdueBalanceListInput struct { + AmountCurrency string `json:"currency,omitempty"` + ExternalCustomerId string `json:"external_customer_id,omitempty"` + Months int `json:"months,omitempty,string"` +} + +type OverdueBalanceResult struct { + OverdueBalance *OverdueBalance `json:"overdue_balance,omitempty"` + OverdueBalances []OverdueBalance `json:"overdue_balances,omitempty"` +} + +type OverdueBalance struct { + Month string `json:"month,omitempty"` + AmountCents int `json:"amount_cents,omitempty"` + AmountCurrency Currency `json:"currency,omitempty"` +} + +func (c *Client) OverdueBalance() *OverdueBalanceRequest { + return &OverdueBalanceRequest{ + client: c, + } +} + +func (adr *OverdueBalanceRequest) GetList(ctx context.Context, OverdueBalanceListInput *OverdueBalanceListInput) (*OverdueBalanceResult, *Error) { + jsonQueryparams, err := json.Marshal(OverdueBalanceListInput) + if err != nil { + return nil, &Error{Err: err} + } + + queryParams := make(map[string]string) + if err = json.Unmarshal(jsonQueryparams, &queryParams); err != nil { + return nil, &Error{Err: err} + } + + clientRequest := &ClientRequest{ + Path: "analytics/overdue_balance", + QueryParams: queryParams, + Result: &OverdueBalanceResult{}, + } + + result, clientErr := adr.client.Get(ctx, clientRequest) + if clientErr != nil { + return nil, clientErr + } + + OverdueBalanceResult, ok := result.(*OverdueBalanceResult) + if !ok { + return nil, &ErrorTypeAssert + } + + return OverdueBalanceResult, nil +}