-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbilling.go
346 lines (272 loc) · 9.56 KB
/
billing.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package clcv1
import (
"github.com/grrtrr/clcv1/microsoft"
)
/*
* Account Billing Summary
*/
type AccountSummary struct {
// The current estimate of total hourly charges, assuming the current hourly run rate.
// FIXME: in the v1 API doc this is called 'MonthlyEstimates' instead of 'MonthlyEstimate'
MonthlyEstimate float64
// The total of actual hourly charges incurred thus far.
MonthToDate float64
// The total charges incurred during the current hour.
CurrentHour float64
// The total charges incurred during the previous hour.
PreviousHour float64
// The total one time charges incurred this month
// (this would be for non-recurring charges such as domain name registration, SSL Certificates, etc.).
OneTimeCharges float64
// The total charges incurred this month to date, including one-time charges.
MonthToDateTotal float64
}
// Get monthly and hourly charges and estimates for a given account or collection of accounts.
// @acctAlias: Short code of the account to query.
func (c *Client) GetAccountSummary(acctAlias string) (summary AccountSummary, err error) {
req := struct { AccountAlias string } { acctAlias }
err = c.getResponse("/Billing/GetAccountSummary/JSON", &req, &struct {
BaseResponse
*AccountSummary
} { AccountSummary: &summary })
return
}
type BillingHistory struct {
// Mirrors @acctAlias or the default account
AccountAlias string
// FIXME: the following field is mentioned in the v1 API, but does not appear:
// The total unpaid balance associated with the account.
// OutstandingBalance float64
// Array of ledger entries
BillingHistory []struct{
// Identifier for the account's invoice.
InvoiceID string
// Date of the invoice.
Date microsoft.Timestamp
// Descriptive text of the invoice; typically the name of the invoice.
Description string
// Charges associated with the invoice period.
Debit float64
// Credits applied to the account during this invoice period.
Credit float64
// FIXME: the following field is mentioned in the v1 API, but does not appear:
// Total balance due for this invoice.
// OutstandingBalance float64
// FIXME: Undocumented value that appears in the output
DisplayPrecedence int
}
}
// Get the entire billing history for a given account or collection of accounts.
// @acctAlias: Short code of the account to query.
func (c *Client) GetBillingHistory(acctAlias string) (history BillingHistory, err error) {
req := struct { AccountAlias string } { acctAlias }
err = c.getResponse("/Billing/GetBillingHistory/JSON", &req, &struct {
BaseResponse
*BillingHistory
} { BillingHistory: &history })
return
}
type CostEstimate struct {
// Estimated cost of this group given current rate of usage.
MonthlyEstimate float64
// Current charges so far this month.
MonthToDate float64
// Charges for the current hour of usage.
CurrentHour float64
// Charges for the previous hour of usage.
PreviousHour float64
}
/*
* Servers
*/
// Get the estimated monthly cost for a given server.
// @serverId: Name of the server.
// @acctAlias: Short code of the account to query.
func (c *Client) GetServerEstimate(serverId, acctAlias string) (estimate CostEstimate, err error) {
req := struct { AccountAlias, ServerName string } { acctAlias, serverId }
err = c.getResponse("/Billing/GetServerEstimate/JSON", &req, &struct {
BaseResponse
*CostEstimate
} { CostEstimate: &estimate })
return
}
type ServerHourlyCharges struct {
// Name given to the server.
ServerName string
// Short code for a particular account.
AccountAlias string
// Start of the query period.
StartDate microsoft.Timestamp
// End of the query period.
EndDate microsoft.Timestamp
// Aggregation of charges for the server.
Summary CostEstimate
// Per hour for the server.
HourlyCharges []struct {
// FIXME: the following appear in the output,
// but are not documented.
Hour string
ProcessorCost string
MemoryCost string
StorageCost string
OSCost string
}
}
// Get the server-based hourly cost for a given time period.
// @serverId: Name of the server.
// @start: Start date of the date range (optional).
// @end: End date of the date range (optional).
// @acctAlias: Short code of the account to query.
func (c *Client) GetServerHourlyCharges(serverId, start, end, acctAlias string) (hourly ServerHourlyCharges, err error) {
req := struct { AccountAlias, ServerName, StartDate, EndDate string } { acctAlias, serverId, start, end }
err = c.getResponse("/Billing/GetServerHourlyCharges/JSON", &req, &struct {
BaseResponse
*ServerHourlyCharges
} { ServerHourlyCharges: &hourly })
return
}
/*
* Hardware Groups
*/
// Get estimated costs for a group of servers.
// @grpUuid: Unique identifier of the hardware group to estimate.
// @acctAlias: Short code of the account to query.
func (c *Client) GetGroupEstimate(grpUuid, acctAlias string) (estimate CostEstimate, err error) {
req := struct { AccountAlias, HardwareGroupUUID string } { acctAlias, grpUuid }
err = c.getResponse("/Billing/GetGroupEstimate/JSON", &req, &struct {
BaseResponse
*CostEstimate
} { CostEstimate: &estimate })
return
}
type GroupSummaries struct {
// Account that this group summary applied to.
AccountAlias string
// Start date of the query range.
StartDate string
// End date of the query range.
EndDate string
// Overview of costs for the group.
Summary CostEstimate
// Details of individual costs of each group.
GroupTotals []struct {
// User-given name to this group.
GroupName string
// Unique identifier for this specific group.
GroupID int
// Data center alias corresponding to this group.
LocationAlias string
// Charges and estimated costs for this group based on current usage
CostEstimate
// Collection of servers that make up the group, and the individual cost of each.
ServerTotals []struct{
// Name of this server that is incurring charges.
ServerName string
// Charges and estimated costs for the server based on current usage.
CostEstimate
}
}
}
// Get the charges for groups and servers within a given account and date range.
// @startDate: Start date of the date range (optional).
// @endDate: End date of the date range (optional).
// @acctAlias: Short code of the account to query.
func (c *Client) GetGroupSummaries(startDate, endDate, acctAlias string) (summaries GroupSummaries, err error) {
req := struct { AccountAlias, StartDate, EndDate string } { acctAlias, startDate, endDate }
err = c.getResponse("/Billing/GetGroupSummaries/JSON", &req, &struct {
BaseResponse
*GroupSummaries
} { GroupSummaries: &summaries })
return
}
/*
* Invoices
*/
type Invoice struct {
// Unique identifier of the invoice.
ID string
// Date of the invoice.
InvoiceDate microsoft.Timestamp
// Billing terms of this invoice.
Terms string
// Name of the company associated with the account.
CompanyName string
// Short code of the account.
AccountAlias string
// FIXME: this one is not documented, but appears in the output
PricingAccountAlias string
// FIXME: this one is not documented, but appears in the output
ParentAccountAlias string
// Street address associated with the account.
Address1 string
// Secondary street address associated with the account.
Address2 string
// City associated with the account.
City string
// State or province associated with the account.
StateProvince string
// Postcal code associated with the account.
PostalCode string
// Email address associated with the account.
BillingContactEmail string
// Secondary email address associated with the account.
InvoiceCCEmail string
// Total amount of this invoice.
TotalAmount float64
// Purchase Order identifier.
PONumber string
// Individual line item on the invoice.
LineItems []struct {
// Typically the name of the billed resource or container.
Description string
// Data center alias associated with this resource.
ServiceLocation string
// Cost of one unit of the resource.
UnitCost float64
// Unit cost multiplied by the quantity.
ItemTotal float64
// Count of the item that is being charged.
Quantity int
// Individual line item description and cost.
// For instance, may refer to the servers within a group.
ItemDetails []struct {
// Typically the name of the lowest level billed resource, such as a server name.
Description string
// Cost of this resource.
Cost float64
}
}
}
type InvoiceDetails struct {
// Invoice details and line items.
Invoice Invoice
// Indicator of support level for the account
// (developer, legacy, professional, enterprise)
SupportLevel string
/*
FIXME: the following fields appear in the documentation at
https://www.ctl.io/api-docs/v1/#billing-getinvoicedetails,
but not in the output (Oct 2015):
// Previous balance on the account.
OpeningBalance float64
// New charges for the invoice period.
NewCharges float64
// Amount of payments received.
Payments float64
// Total billed amount for this invoice.
EndingBalance float64
// Total amount owed by this account.
CurrentOutstandingBalance float64
*/
}
// Get the details for a given invoice within an account.
// @invoiceID: Unique identifier for a given invoice.
// @acctAlias: Short code of the account to query (optional).
func (c *Client) GetInvoiceDetails(invoiceID, acctAlias string) (details InvoiceDetails, err error) {
req := struct { AccountAlias, InvoiceID string } { acctAlias, invoiceID }
err = c.getResponse("/Billing/GetInvoiceDetails/JSON", &req, &struct {
BaseResponse
*InvoiceDetails
} { InvoiceDetails: &details })
return
}