diff --git a/gross_revenue.go b/gross_revenue.go new file mode 100644 index 0000000..a13fb66 --- /dev/null +++ b/gross_revenue.go @@ -0,0 +1,63 @@ +package lago + +import ( + "context" + "encoding/json" +) + +type GrossRevenueRequest struct { + client *Client +} + +type GrossRevenueListInput struct { + AmountCurrency string `json:"currency,omitempty,string"` + ExternalCustomerId string `json:"external_customer_id,omitempty,string"` + Months int `json:"months,omitempty,string"` +} + +type GrossRevenueResult struct { + GrossRevenue *GrossRevenue `json:"gross_revenue,omitempty"` + GrossRevenues []GrossRevenue `json:"gross_revenues,omitempty"` +} + +type GrossRevenue struct { + Month string `json:"month,omitempty"` + AmountCents int `json:"amount_cents,omitempty"` + AmountCurrency Currency `json:"currency,omitempty"` +} + +func (c *Client) GrossRevenue() *GrossRevenueRequest { + return &GrossRevenueRequest{ + client: c, + } +} + +func (adr *GrossRevenueRequest) GetList(ctx context.Context, GrossRevenueListInput *GrossRevenueListInput) (*GrossRevenueResult, *Error) { + jsonQueryparams, err := json.Marshal(GrossRevenueListInput) + 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/gross_revenue", + QueryParams: queryParams, + Result: &GrossRevenueResult{}, + } + + result, clientErr := adr.client.Get(ctx, clientRequest) + if clientErr != nil { + return nil, clientErr + } + + GrossRevenueResult, ok := result.(*GrossRevenueResult) + if !ok { + return nil, &ErrorTypeAssert + } + + return GrossRevenueResult, nil +} diff --git a/invoiced_usage.go b/invoiced_usage.go new file mode 100644 index 0000000..ee689bd --- /dev/null +++ b/invoiced_usage.go @@ -0,0 +1,63 @@ +package lago + +import ( + "context" + "encoding/json" +) + +type InvoicedUsageRequest struct { + client *Client +} + +type InvoicedUsageListInput struct { + AmountCurrency string `json:"currency,omitempty,string"` + Months int `json:"months,omitempty,string"` +} + +type InvoicedUsageResult struct { + InvoicedUsage *InvoicedUsage `json:"invoiced_usage,omitempty"` + InvoicedUsages []InvoicedUsage `json:"invoiced_usages,omitempty"` +} + +type InvoicedUsage struct { + Month string `json:"month,omitempty"` + Code string `json:"code,omitempty"` + AmountCents int `json:"amount_cents,omitempty"` + AmountCurrency Currency `json:"currency,omitempty"` +} + +func (c *Client) InvoicedUsage() *InvoicedUsageRequest { + return &InvoicedUsageRequest{ + client: c, + } +} + +func (adr *InvoicedUsageRequest) GetList(ctx context.Context, InvoicedUsageListInput *InvoicedUsageListInput) (*InvoicedUsageResult, *Error) { + jsonQueryparams, err := json.Marshal(InvoicedUsageListInput) + 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/invoiced_usage", + QueryParams: queryParams, + Result: &InvoicedUsageResult{}, + } + + result, clientErr := adr.client.Get(ctx, clientRequest) + if clientErr != nil { + return nil, clientErr + } + + InvoicedUsageResult, ok := result.(*InvoicedUsageResult) + if !ok { + return nil, &ErrorTypeAssert + } + + return InvoicedUsageResult, nil +} diff --git a/mrr.go b/mrr.go new file mode 100644 index 0000000..40d4f17 --- /dev/null +++ b/mrr.go @@ -0,0 +1,62 @@ +package lago + +import ( + "context" + "encoding/json" +) + +type MrrRequest struct { + client *Client +} + +type MrrListInput struct { + AmountCurrency string `json:"currency,omitempty,string"` + Months int `json:"months,omitempty,string"` +} + +type MrrResult struct { + Mrr *Mrr `json:"mrr,omitempty"` + Mrrs []Mrr `json:"mrrs,omitempty"` +} + +type Mrr struct { + Month string `json:"month,omitempty"` + AmountCents int `json:"amount_cents,omitempty"` + AmountCurrency Currency `json:"currency,omitempty"` +} + +func (c *Client) Mrr() *MrrRequest { + return &MrrRequest{ + client: c, + } +} + +func (adr *MrrRequest) GetList(ctx context.Context, MrrListInput *MrrListInput) (*MrrResult, *Error) { + jsonQueryparams, err := json.Marshal(MrrListInput) + 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/mrr", + QueryParams: queryParams, + Result: &MrrResult{}, + } + + result, clientErr := adr.client.Get(ctx, clientRequest) + if clientErr != nil { + return nil, clientErr + } + + MrrResult, ok := result.(*MrrResult) + if !ok { + return nil, &ErrorTypeAssert + } + + return MrrResult, nil +} diff --git a/outstanding_invoice.go b/outstanding_invoice.go new file mode 100644 index 0000000..7ac160a --- /dev/null +++ b/outstanding_invoice.go @@ -0,0 +1,66 @@ +package lago + +import ( + "context" + "encoding/json" +) + +type PaymentStatus string + +type OutstandingInvoiceRequest struct { + client *Client +} + +type OutstandingInvoiceListInput struct { + AmountCurrency string `json:"currency,omitempty,string"` + Months int `json:"months,omitempty,string"` +} + +type OutstandingInvoiceResult struct { + OutstandingInvoice *OutstandingInvoice `json:"outstanding_invoice,omitempty"` + OutstandingInvoices []OutstandingInvoice `json:"outstanding_invoices,omitempty"` +} + +type OutstandingInvoice 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) OutstandingInvoice() *OutstandingInvoiceRequest { + return &OutstandingInvoiceRequest{ + client: c, + } +} + +func (adr *OutstandingInvoiceRequest) GetList(ctx context.Context, OutstandingInvoiceListInput *OutstandingInvoiceListInput) (*OutstandingInvoiceResult, *Error) { + jsonQueryparams, err := json.Marshal(OutstandingInvoiceListInput) + 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/outstanding_invoices", + QueryParams: queryParams, + Result: &OutstandingInvoiceResult{}, + } + + result, clientErr := adr.client.Get(ctx, clientRequest) + if clientErr != nil { + return nil, clientErr + } + + OutstandingInvoiceResult, ok := result.(*OutstandingInvoiceResult) + if !ok { + return nil, &ErrorTypeAssert + } + + return OutstandingInvoiceResult, nil +}