-
Notifications
You must be signed in to change notification settings - Fork 18
/
invoice_collection.go
66 lines (53 loc) · 1.77 KB
/
invoice_collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package lago
import (
"context"
"encoding/json"
)
type PaymentStatus string
type InvoiceCollectionRequest struct {
client *Client
}
type InvoiceCollectionListInput struct {
AmountCurrency string `json:"currency,omitempty"`
Months int `json:"months,omitempty,string"`
}
type InvoiceCollectionResult struct {
InvoiceCollection *InvoiceCollection `json:"invoice_collection,omitempty"`
InvoiceCollections []InvoiceCollection `json:"invoice_collections,omitempty"`
}
type InvoiceCollection struct {
Month string `json:"month,omitempty"`
PaymentStatus InvoicePaymentStatus `json:"payment_status,omitempty"`
InvoicesCount int `json:"invoices_count,omitempty"`
AmountCents int `json:"amount_cents,omitempty"`
AmountCurrency Currency `json:"currency,omitempty"`
}
func (c *Client) InvoiceCollection() *InvoiceCollectionRequest {
return &InvoiceCollectionRequest{
client: c,
}
}
func (adr *InvoiceCollectionRequest) GetList(ctx context.Context, InvoiceCollectionListInput *InvoiceCollectionListInput) (*InvoiceCollectionResult, *Error) {
jsonQueryparams, err := json.Marshal(InvoiceCollectionListInput)
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/invoice_collection",
QueryParams: queryParams,
Result: &InvoiceCollectionResult{},
}
result, clientErr := adr.client.Get(ctx, clientRequest)
if clientErr != nil {
return nil, clientErr
}
InvoiceCollectionResult, ok := result.(*InvoiceCollectionResult)
if !ok {
return nil, &ErrorTypeAssert
}
return InvoiceCollectionResult, nil
}