|
| 1 | +// This file was automatically generated. DO NOT EDIT. |
| 2 | +// If you have any remark or suggestion do not hesitate to open an issue. |
| 3 | + |
| 4 | +// Package billing provides methods and message types of the billing v2alpha1 API. |
| 5 | +package billing |
| 6 | + |
| 7 | +import ( |
| 8 | + "bytes" |
| 9 | + "encoding/json" |
| 10 | + "fmt" |
| 11 | + "net" |
| 12 | + "net/http" |
| 13 | + "net/url" |
| 14 | + "strings" |
| 15 | + "time" |
| 16 | + |
| 17 | + "github.com/scaleway/scaleway-sdk-go/internal/errors" |
| 18 | + "github.com/scaleway/scaleway-sdk-go/internal/marshaler" |
| 19 | + "github.com/scaleway/scaleway-sdk-go/internal/parameter" |
| 20 | + "github.com/scaleway/scaleway-sdk-go/namegenerator" |
| 21 | + "github.com/scaleway/scaleway-sdk-go/scw" |
| 22 | +) |
| 23 | + |
| 24 | +// always import dependencies |
| 25 | +var ( |
| 26 | + _ fmt.Stringer |
| 27 | + _ json.Unmarshaler |
| 28 | + _ url.URL |
| 29 | + _ net.IP |
| 30 | + _ http.Header |
| 31 | + _ bytes.Reader |
| 32 | + _ time.Time |
| 33 | + _ = strings.Join |
| 34 | + |
| 35 | + _ scw.ScalewayRequest |
| 36 | + _ marshaler.Duration |
| 37 | + _ scw.File |
| 38 | + _ = parameter.AddToQuery |
| 39 | + _ = namegenerator.GetRandomName |
| 40 | +) |
| 41 | + |
| 42 | +// API: this API allows you to query your consumption. |
| 43 | +// Billing API. |
| 44 | +type API struct { |
| 45 | + client *scw.Client |
| 46 | +} |
| 47 | + |
| 48 | +// NewAPI returns a API object from a Scaleway client. |
| 49 | +func NewAPI(client *scw.Client) *API { |
| 50 | + return &API{ |
| 51 | + client: client, |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +type DownloadInvoiceRequestFileType string |
| 56 | + |
| 57 | +const ( |
| 58 | + DownloadInvoiceRequestFileTypePdf = DownloadInvoiceRequestFileType("pdf") |
| 59 | +) |
| 60 | + |
| 61 | +func (enum DownloadInvoiceRequestFileType) String() string { |
| 62 | + if enum == "" { |
| 63 | + // return default value if empty |
| 64 | + return "pdf" |
| 65 | + } |
| 66 | + return string(enum) |
| 67 | +} |
| 68 | + |
| 69 | +func (enum DownloadInvoiceRequestFileType) MarshalJSON() ([]byte, error) { |
| 70 | + return []byte(fmt.Sprintf(`"%s"`, enum)), nil |
| 71 | +} |
| 72 | + |
| 73 | +func (enum *DownloadInvoiceRequestFileType) UnmarshalJSON(data []byte) error { |
| 74 | + tmp := "" |
| 75 | + |
| 76 | + if err := json.Unmarshal(data, &tmp); err != nil { |
| 77 | + return err |
| 78 | + } |
| 79 | + |
| 80 | + *enum = DownloadInvoiceRequestFileType(DownloadInvoiceRequestFileType(tmp).String()) |
| 81 | + return nil |
| 82 | +} |
| 83 | + |
| 84 | +type InvoiceType string |
| 85 | + |
| 86 | +const ( |
| 87 | + InvoiceTypeUnknownType = InvoiceType("unknown_type") |
| 88 | + InvoiceTypePeriodic = InvoiceType("periodic") |
| 89 | + InvoiceTypePurchase = InvoiceType("purchase") |
| 90 | +) |
| 91 | + |
| 92 | +func (enum InvoiceType) String() string { |
| 93 | + if enum == "" { |
| 94 | + // return default value if empty |
| 95 | + return "unknown_type" |
| 96 | + } |
| 97 | + return string(enum) |
| 98 | +} |
| 99 | + |
| 100 | +func (enum InvoiceType) MarshalJSON() ([]byte, error) { |
| 101 | + return []byte(fmt.Sprintf(`"%s"`, enum)), nil |
| 102 | +} |
| 103 | + |
| 104 | +func (enum *InvoiceType) UnmarshalJSON(data []byte) error { |
| 105 | + tmp := "" |
| 106 | + |
| 107 | + if err := json.Unmarshal(data, &tmp); err != nil { |
| 108 | + return err |
| 109 | + } |
| 110 | + |
| 111 | + *enum = InvoiceType(InvoiceType(tmp).String()) |
| 112 | + return nil |
| 113 | +} |
| 114 | + |
| 115 | +type ListInvoicesRequestOrderBy string |
| 116 | + |
| 117 | +const ( |
| 118 | + ListInvoicesRequestOrderByInvoiceNumberDesc = ListInvoicesRequestOrderBy("invoice_number_desc") |
| 119 | + ListInvoicesRequestOrderByInvoiceNumberAsc = ListInvoicesRequestOrderBy("invoice_number_asc") |
| 120 | + ListInvoicesRequestOrderByStartDateDesc = ListInvoicesRequestOrderBy("start_date_desc") |
| 121 | + ListInvoicesRequestOrderByStartDateAsc = ListInvoicesRequestOrderBy("start_date_asc") |
| 122 | + ListInvoicesRequestOrderByIssuedDateDesc = ListInvoicesRequestOrderBy("issued_date_desc") |
| 123 | + ListInvoicesRequestOrderByIssuedDateAsc = ListInvoicesRequestOrderBy("issued_date_asc") |
| 124 | + ListInvoicesRequestOrderByDueDateDesc = ListInvoicesRequestOrderBy("due_date_desc") |
| 125 | + ListInvoicesRequestOrderByDueDateAsc = ListInvoicesRequestOrderBy("due_date_asc") |
| 126 | + ListInvoicesRequestOrderByTotalUntaxedDesc = ListInvoicesRequestOrderBy("total_untaxed_desc") |
| 127 | + ListInvoicesRequestOrderByTotalUntaxedAsc = ListInvoicesRequestOrderBy("total_untaxed_asc") |
| 128 | + ListInvoicesRequestOrderByTotalTaxedDesc = ListInvoicesRequestOrderBy("total_taxed_desc") |
| 129 | + ListInvoicesRequestOrderByTotalTaxedAsc = ListInvoicesRequestOrderBy("total_taxed_asc") |
| 130 | + ListInvoicesRequestOrderByInvoiceTypeDesc = ListInvoicesRequestOrderBy("invoice_type_desc") |
| 131 | + ListInvoicesRequestOrderByInvoiceTypeAsc = ListInvoicesRequestOrderBy("invoice_type_asc") |
| 132 | +) |
| 133 | + |
| 134 | +func (enum ListInvoicesRequestOrderBy) String() string { |
| 135 | + if enum == "" { |
| 136 | + // return default value if empty |
| 137 | + return "invoice_number_desc" |
| 138 | + } |
| 139 | + return string(enum) |
| 140 | +} |
| 141 | + |
| 142 | +func (enum ListInvoicesRequestOrderBy) MarshalJSON() ([]byte, error) { |
| 143 | + return []byte(fmt.Sprintf(`"%s"`, enum)), nil |
| 144 | +} |
| 145 | + |
| 146 | +func (enum *ListInvoicesRequestOrderBy) UnmarshalJSON(data []byte) error { |
| 147 | + tmp := "" |
| 148 | + |
| 149 | + if err := json.Unmarshal(data, &tmp); err != nil { |
| 150 | + return err |
| 151 | + } |
| 152 | + |
| 153 | + *enum = ListInvoicesRequestOrderBy(ListInvoicesRequestOrderBy(tmp).String()) |
| 154 | + return nil |
| 155 | +} |
| 156 | + |
| 157 | +// GetConsumptionResponse: get consumption response. |
| 158 | +type GetConsumptionResponse struct { |
| 159 | + // Consumptions: detailed consumption list. |
| 160 | + Consumptions []*GetConsumptionResponseConsumption `json:"consumptions"` |
| 161 | + // UpdatedAt: last consumption update date. |
| 162 | + UpdatedAt *time.Time `json:"updated_at"` |
| 163 | +} |
| 164 | + |
| 165 | +// GetConsumptionResponseConsumption: get consumption response. consumption. |
| 166 | +type GetConsumptionResponseConsumption struct { |
| 167 | + // Value: monetary value of the consumption. |
| 168 | + Value *scw.Money `json:"value"` |
| 169 | + // Description: description of the consumption. |
| 170 | + Description string `json:"description"` |
| 171 | + // ProjectID: project ID of the consumption. |
| 172 | + ProjectID string `json:"project_id"` |
| 173 | + // Category: category of the consumption. |
| 174 | + Category string `json:"category"` |
| 175 | + // OperationPath: unique identifier of the product. |
| 176 | + OperationPath string `json:"operation_path"` |
| 177 | +} |
| 178 | + |
| 179 | +// Invoice: invoice. |
| 180 | +type Invoice struct { |
| 181 | + // ID: invoice ID. |
| 182 | + ID string `json:"id"` |
| 183 | + // StartDate: start date of the billing period. |
| 184 | + StartDate *time.Time `json:"start_date"` |
| 185 | + // IssuedDate: date when the invoice was sent to the customer. |
| 186 | + IssuedDate *time.Time `json:"issued_date"` |
| 187 | + // DueDate: payment time limit, set according to the Organization's payment conditions. |
| 188 | + DueDate *time.Time `json:"due_date"` |
| 189 | + // TotalUntaxed: total amount, untaxed. |
| 190 | + TotalUntaxed *scw.Money `json:"total_untaxed"` |
| 191 | + // TotalTaxed: total amount, taxed. |
| 192 | + TotalTaxed *scw.Money `json:"total_taxed"` |
| 193 | + // InvoiceType: type of invoice. |
| 194 | + // Default value: unknown_type |
| 195 | + InvoiceType InvoiceType `json:"invoice_type"` |
| 196 | + // Number: invoice number. |
| 197 | + Number int32 `json:"number"` |
| 198 | +} |
| 199 | + |
| 200 | +// ListInvoicesResponse: list invoices response. |
| 201 | +type ListInvoicesResponse struct { |
| 202 | + // TotalCount: total number of invoices. |
| 203 | + TotalCount uint32 `json:"total_count"` |
| 204 | + // Invoices: paginated returned invoices. |
| 205 | + Invoices []*Invoice `json:"invoices"` |
| 206 | +} |
| 207 | + |
| 208 | +// Service API |
| 209 | + |
| 210 | +type GetConsumptionRequest struct { |
| 211 | + // OrganizationID: filter by organization ID. |
| 212 | + OrganizationID string `json:"-"` |
| 213 | +} |
| 214 | + |
| 215 | +func (s *API) GetConsumption(req *GetConsumptionRequest, opts ...scw.RequestOption) (*GetConsumptionResponse, error) { |
| 216 | + var err error |
| 217 | + |
| 218 | + if req.OrganizationID == "" { |
| 219 | + defaultOrganizationID, _ := s.client.GetDefaultOrganizationID() |
| 220 | + req.OrganizationID = defaultOrganizationID |
| 221 | + } |
| 222 | + |
| 223 | + query := url.Values{} |
| 224 | + parameter.AddToQuery(query, "organization_id", req.OrganizationID) |
| 225 | + |
| 226 | + scwReq := &scw.ScalewayRequest{ |
| 227 | + Method: "GET", |
| 228 | + Path: "/billing/v2alpha1/consumption", |
| 229 | + Query: query, |
| 230 | + Headers: http.Header{}, |
| 231 | + } |
| 232 | + |
| 233 | + var resp GetConsumptionResponse |
| 234 | + |
| 235 | + err = s.client.Do(scwReq, &resp, opts...) |
| 236 | + if err != nil { |
| 237 | + return nil, err |
| 238 | + } |
| 239 | + return &resp, nil |
| 240 | +} |
| 241 | + |
| 242 | +type ListInvoicesRequest struct { |
| 243 | + // OrganizationID: organization ID to filter for, only invoices from this Organization will be returned. |
| 244 | + OrganizationID *string `json:"-"` |
| 245 | + // StartedAfter: invoice's `start_date` is greater or equal to `started_after`. |
| 246 | + StartedAfter *time.Time `json:"-"` |
| 247 | + // StartedBefore: invoice's `start_date` precedes `started_before`. |
| 248 | + StartedBefore *time.Time `json:"-"` |
| 249 | + // InvoiceType: invoice type. It can either be `periodic` or `purchase`. |
| 250 | + // Default value: unknown_type |
| 251 | + InvoiceType InvoiceType `json:"-"` |
| 252 | + // Page: positive integer to choose the page to return. |
| 253 | + Page *int32 `json:"-"` |
| 254 | + // PageSize: positive integer lower or equal to 100 to select the number of items to return. |
| 255 | + // Default value: 20 |
| 256 | + PageSize *uint32 `json:"-"` |
| 257 | + // OrderBy: how invoices are ordered in the response. |
| 258 | + // Default value: invoice_number_desc |
| 259 | + OrderBy ListInvoicesRequestOrderBy `json:"-"` |
| 260 | +} |
| 261 | + |
| 262 | +func (s *API) ListInvoices(req *ListInvoicesRequest, opts ...scw.RequestOption) (*ListInvoicesResponse, error) { |
| 263 | + var err error |
| 264 | + |
| 265 | + defaultPageSize, exist := s.client.GetDefaultPageSize() |
| 266 | + if (req.PageSize == nil || *req.PageSize == 0) && exist { |
| 267 | + req.PageSize = &defaultPageSize |
| 268 | + } |
| 269 | + |
| 270 | + query := url.Values{} |
| 271 | + parameter.AddToQuery(query, "organization_id", req.OrganizationID) |
| 272 | + parameter.AddToQuery(query, "started_after", req.StartedAfter) |
| 273 | + parameter.AddToQuery(query, "started_before", req.StartedBefore) |
| 274 | + parameter.AddToQuery(query, "invoice_type", req.InvoiceType) |
| 275 | + parameter.AddToQuery(query, "page", req.Page) |
| 276 | + parameter.AddToQuery(query, "page_size", req.PageSize) |
| 277 | + parameter.AddToQuery(query, "order_by", req.OrderBy) |
| 278 | + |
| 279 | + scwReq := &scw.ScalewayRequest{ |
| 280 | + Method: "GET", |
| 281 | + Path: "/billing/v2alpha1/invoices", |
| 282 | + Query: query, |
| 283 | + Headers: http.Header{}, |
| 284 | + } |
| 285 | + |
| 286 | + var resp ListInvoicesResponse |
| 287 | + |
| 288 | + err = s.client.Do(scwReq, &resp, opts...) |
| 289 | + if err != nil { |
| 290 | + return nil, err |
| 291 | + } |
| 292 | + return &resp, nil |
| 293 | +} |
| 294 | + |
| 295 | +type DownloadInvoiceRequest struct { |
| 296 | + // InvoiceID: invoice ID. |
| 297 | + InvoiceID string `json:"-"` |
| 298 | + // FileType: wanted file type. |
| 299 | + // Default value: pdf |
| 300 | + FileType DownloadInvoiceRequestFileType `json:"-"` |
| 301 | +} |
| 302 | + |
| 303 | +func (s *API) DownloadInvoice(req *DownloadInvoiceRequest, opts ...scw.RequestOption) (*scw.File, error) { |
| 304 | + var err error |
| 305 | + |
| 306 | + query := url.Values{} |
| 307 | + parameter.AddToQuery(query, "file_type", req.FileType) |
| 308 | + |
| 309 | + if fmt.Sprint(req.InvoiceID) == "" { |
| 310 | + return nil, errors.New("field InvoiceID cannot be empty in request") |
| 311 | + } |
| 312 | + |
| 313 | + scwReq := &scw.ScalewayRequest{ |
| 314 | + Method: "GET", |
| 315 | + Path: "/billing/v2alpha1/invoices/" + fmt.Sprint(req.InvoiceID) + "/download", |
| 316 | + Query: query, |
| 317 | + Headers: http.Header{}, |
| 318 | + } |
| 319 | + |
| 320 | + var resp scw.File |
| 321 | + |
| 322 | + err = s.client.Do(scwReq, &resp, opts...) |
| 323 | + if err != nil { |
| 324 | + return nil, err |
| 325 | + } |
| 326 | + return &resp, nil |
| 327 | +} |
| 328 | + |
| 329 | +// UnsafeGetTotalCount should not be used |
| 330 | +// Internal usage only |
| 331 | +func (r *ListInvoicesResponse) UnsafeGetTotalCount() uint32 { |
| 332 | + return r.TotalCount |
| 333 | +} |
| 334 | + |
| 335 | +// UnsafeAppend should not be used |
| 336 | +// Internal usage only |
| 337 | +func (r *ListInvoicesResponse) UnsafeAppend(res interface{}) (uint32, error) { |
| 338 | + results, ok := res.(*ListInvoicesResponse) |
| 339 | + if !ok { |
| 340 | + return 0, errors.New("%T type cannot be appended to type %T", res, r) |
| 341 | + } |
| 342 | + |
| 343 | + r.Invoices = append(r.Invoices, results.Invoices...) |
| 344 | + r.TotalCount += uint32(len(results.Invoices)) |
| 345 | + return uint32(len(results.Invoices)), nil |
| 346 | +} |
0 commit comments