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 67 68 69 70 71 72 73 74
|
package dnsimple
import (
"context"
"fmt"
"github.com/shopspring/decimal"
)
type ListChargesOptions struct {
// Only include results after the given date.
StartDate string `url:"start_date,omitempty"`
// Only include results before the given date.
EndDate string `url:"end_date,omitempty"`
// Sort results. Default sorting is by invoiced ascending.
Sort string `url:"sort,omitempty"`
}
type ListChargesResponse struct {
Response
Data []Charge `json:"data"`
}
type Charge struct {
InvoicedAt string `json:"invoiced_at,omitempty"`
TotalAmount decimal.Decimal `json:"total_amount,omitempty"`
BalanceAmount decimal.Decimal `json:"balance_amount,omitempty"`
Reference string `json:"reference,omitempty"`
State string `json:"state,omitempty"`
Items []ChargeItem `json:"items,omitempty"`
}
type ChargeItem struct {
Description string `json:"description,omitempty"`
Amount decimal.Decimal `json:"amount,omitempty"`
ProductId int64 `json:"product_id,omitempty"`
ProductType string `json:"product_type,omitempty"`
ProductReference string `json:"product_reference,omitempty"`
}
type BillingService struct {
client *Client
}
// Lists the billing charges for the account.
//
// See https://developer.dnsimple.com/v2/billing/#listCharges
func (s *BillingService) ListCharges(
ctx context.Context,
account string,
options ListChargesOptions,
) (*ListChargesResponse, error) {
res := &ListChargesResponse{}
path := fmt.Sprintf("/v2/%v/billing/charges", account)
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
httpRes, err := s.client.get(
ctx,
path,
res,
)
if err != nil {
return nil, err
}
res.HTTPResponse = httpRes
return res, nil
}
|