Skip to content

Commit

Permalink
feat(analytics): Add overdue balance endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Jul 15, 2024
1 parent 313f4f3 commit 72a1a16
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions gross_revenue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
63 changes: 63 additions & 0 deletions overdue_balance.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 72a1a16

Please sign in to comment.