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

feat(analytics): Add overdue balance endpoint #194

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
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
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
}
Loading