-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprojectbilling.go
More file actions
255 lines (227 loc) · 11.1 KB
/
projectbilling.go
File metadata and controls
255 lines (227 loc) · 11.1 KB
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
// Code generated by Aiven. DO NOT EDIT.
package projectbilling
import (
"context"
"encoding/json"
"fmt"
"net/url"
"time"
)
type Handler interface {
// InvoiceGet get a single invoice
// GET /v1/invoices/{invoice_number}
// https://api.aiven.io/doc/#tag/Billing/operation/InvoiceGet
InvoiceGet(ctx context.Context, invoiceNumber string) (*InvoiceGetOut, error)
// Deprecated: ProjectCreditsClaim claim a credit code
// POST /v1/project/{project}/credits
// https://api.aiven.io/doc/#tag/Project_Billing/operation/ProjectCreditsClaim
// Required roles or permissions: developer, operator
ProjectCreditsClaim(ctx context.Context, project string, in *ProjectCreditsClaimIn) (*ProjectCreditsClaimOut, error)
// Deprecated: ProjectCreditsList list credits available to the project
// GET /v1/project/{project}/credits
// https://api.aiven.io/doc/#tag/Project_Billing/operation/ProjectCreditsList
// Required roles or permissions: developer, operator, read_only
ProjectCreditsList(ctx context.Context, project string) ([]CreditOut, error)
// Deprecated: ProjectInvoiceList list project invoices
// GET /v1/project/{project}/invoice
// https://api.aiven.io/doc/#tag/Project_Billing/operation/ProjectInvoiceList
// Required roles or permissions: developer, operator, read_only
ProjectInvoiceList(ctx context.Context, project string) ([]InvoiceOut, error)
}
// doer http client
type doer interface {
Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error)
}
func NewHandler(doer doer) ProjectBillingHandler {
return ProjectBillingHandler{doer}
}
type ProjectBillingHandler struct {
doer doer
}
func (h *ProjectBillingHandler) InvoiceGet(ctx context.Context, invoiceNumber string) (*InvoiceGetOut, error) {
path := fmt.Sprintf("/v1/invoices/%s", url.PathEscape(invoiceNumber))
b, err := h.doer.Do(ctx, "InvoiceGet", "GET", path, nil)
if err != nil {
return nil, err
}
out := new(invoiceGetOut)
err = json.Unmarshal(b, out)
if err != nil {
return nil, err
}
return &out.Invoice, nil
}
func (h *ProjectBillingHandler) ProjectCreditsClaim(ctx context.Context, project string, in *ProjectCreditsClaimIn) (*ProjectCreditsClaimOut, error) {
path := fmt.Sprintf("/v1/project/%s/credits", url.PathEscape(project))
b, err := h.doer.Do(ctx, "ProjectCreditsClaim", "POST", path, in)
if err != nil {
return nil, err
}
out := new(projectCreditsClaimOut)
err = json.Unmarshal(b, out)
if err != nil {
return nil, err
}
return &out.Credit, nil
}
func (h *ProjectBillingHandler) ProjectCreditsList(ctx context.Context, project string) ([]CreditOut, error) {
path := fmt.Sprintf("/v1/project/%s/credits", url.PathEscape(project))
b, err := h.doer.Do(ctx, "ProjectCreditsList", "GET", path, nil)
if err != nil {
return nil, err
}
out := new(projectCreditsListOut)
err = json.Unmarshal(b, out)
if err != nil {
return nil, err
}
return out.Credits, nil
}
func (h *ProjectBillingHandler) ProjectInvoiceList(ctx context.Context, project string) ([]InvoiceOut, error) {
path := fmt.Sprintf("/v1/project/%s/invoice", url.PathEscape(project))
b, err := h.doer.Do(ctx, "ProjectInvoiceList", "GET", path, nil)
if err != nil {
return nil, err
}
out := new(projectInvoiceListOut)
err = json.Unmarshal(b, out)
if err != nil {
return nil, err
}
return out.Invoices, nil
}
type BillingGroupStateType string
const (
BillingGroupStateTypeActive BillingGroupStateType = "active"
BillingGroupStateTypeDeleted BillingGroupStateType = "deleted"
)
func BillingGroupStateTypeChoices() []string {
return []string{"active", "deleted"}
}
type CreditOut struct {
Code *string `json:"code,omitempty"` // Credit code
ExpireTime *time.Time `json:"expire_time,omitempty"` // Timestamp in ISO 8601 format, always in UTC
RemainingValue *string `json:"remaining_value,omitempty"` // Remaining credit value
StartTime *time.Time `json:"start_time,omitempty"` // Timestamp in ISO 8601 format, always in UTC
Type CreditType `json:"type,omitempty"` // Credit type
Value *string `json:"value,omitempty"` // Original credit value, or for expired credits, the consumed credit value
}
type CreditType string
const (
CreditTypeDiscount CreditType = "discount"
CreditTypeEmployee CreditType = "employee"
CreditTypeEvaluation CreditType = "evaluation"
CreditTypeInternal CreditType = "internal"
CreditTypeOther CreditType = "other"
CreditTypeOutage CreditType = "outage"
CreditTypePartner CreditType = "partner"
CreditTypePromotion CreditType = "promotion"
CreditTypePurchase CreditType = "purchase"
CreditTypeReferral CreditType = "referral"
CreditTypeSponsorship CreditType = "sponsorship"
CreditTypeTrial CreditType = "trial"
CreditTypeTrialOver CreditType = "trial_over"
)
func CreditTypeChoices() []string {
return []string{"discount", "employee", "evaluation", "internal", "other", "outage", "partner", "promotion", "purchase", "referral", "sponsorship", "trial", "trial_over"}
}
type CurrencyType string
const (
CurrencyTypeAud CurrencyType = "AUD"
CurrencyTypeCad CurrencyType = "CAD"
CurrencyTypeChf CurrencyType = "CHF"
CurrencyTypeDkk CurrencyType = "DKK"
CurrencyTypeEur CurrencyType = "EUR"
CurrencyTypeGbp CurrencyType = "GBP"
CurrencyTypeJpy CurrencyType = "JPY"
CurrencyTypeNok CurrencyType = "NOK"
CurrencyTypeNzd CurrencyType = "NZD"
CurrencyTypeSek CurrencyType = "SEK"
CurrencyTypeSgd CurrencyType = "SGD"
CurrencyTypeUsd CurrencyType = "USD"
)
func CurrencyTypeChoices() []string {
return []string{"AUD", "CAD", "CHF", "DKK", "EUR", "GBP", "JPY", "NOK", "NZD", "SEK", "SGD", "USD"}
}
// InvoiceGetOut InvoiceModel
type InvoiceGetOut struct {
BillingGroupId string `json:"billing_group_id"` // Billing Group ID
BillingGroupName string `json:"billing_group_name"` // Billing Group Name
BillingGroupState string `json:"billing_group_state"` // Billing group state
Currency string `json:"currency"`
DownloadCookie *string `json:"download_cookie,omitempty"` // Download Cookie
DueDate *string `json:"due_date,omitempty"` // Due Date
GeneratedAt time.Time `json:"generated_at"` // Generated At
InvoiceNumber string `json:"invoice_number"` // Invoice Number
IssueDate *string `json:"issue_date,omitempty"` // Issue Date
PeriodBegin string `json:"period_begin"` // Period Begin
PeriodEnd string `json:"period_end"` // Period End
State string `json:"state"`
TotalIncVat string `json:"total_inc_vat"` // Total Inc Vat
TotalVatZero string `json:"total_vat_zero"` // Total Vat Zero
}
type InvoiceOut struct {
BillingGroupId string `json:"billing_group_id"` // Billing group ID
BillingGroupName string `json:"billing_group_name"` // Billing group name
BillingGroupState BillingGroupStateType `json:"billing_group_state"` // Billing group state
Currency CurrencyType `json:"currency"` // Billing currency
DownloadCookie string `json:"download_cookie"` // Authentication cookie for downloads
DueDate *string `json:"due_date,omitempty"` // The time when the invoice is due
GeneratedAt *time.Time `json:"generated_at,omitempty"` // The time when the invoice was generated
InvoiceNumber string `json:"invoice_number"` // Unique invoice reference code
IssueDate *string `json:"issue_date,omitempty"` // The time when the invoice was issued
PeriodBegin string `json:"period_begin"` // Period begin
PeriodEnd string `json:"period_end"` // Period end
State InvoiceStateType `json:"state"` // State of this invoice
TotalIncVat string `json:"total_inc_vat"` // Total including taxes
TotalVatZero string `json:"total_vat_zero"` // Total excluding taxes
}
type InvoiceStateType string
const (
InvoiceStateTypeAccrual InvoiceStateType = "accrual"
InvoiceStateTypeConsolidated InvoiceStateType = "consolidated"
InvoiceStateTypeDue InvoiceStateType = "due"
InvoiceStateTypeDueOnlyProjectChargesCalculated InvoiceStateType = "due_only_project_charges_calculated"
InvoiceStateTypeEstimate InvoiceStateType = "estimate"
InvoiceStateTypeEstimateOnlyProjectChargesCalculated InvoiceStateType = "estimate_only_project_charges_calculated"
InvoiceStateTypeFailedCreditCardCharge InvoiceStateType = "failed_credit_card_charge"
InvoiceStateTypeFailedNoCreditCard InvoiceStateType = "failed_no_credit_card"
InvoiceStateTypeMailed InvoiceStateType = "mailed"
InvoiceStateTypeNoPaymentExpected InvoiceStateType = "no_payment_expected"
InvoiceStateTypePaid InvoiceStateType = "paid"
InvoiceStateTypePartnerMetering InvoiceStateType = "partner_metering"
InvoiceStateTypeUncollectible InvoiceStateType = "uncollectible"
InvoiceStateTypeWaived InvoiceStateType = "waived"
)
func InvoiceStateTypeChoices() []string {
return []string{"accrual", "consolidated", "due", "due_only_project_charges_calculated", "estimate", "estimate_only_project_charges_calculated", "failed_credit_card_charge", "failed_no_credit_card", "mailed", "no_payment_expected", "paid", "partner_metering", "uncollectible", "waived"}
}
// ProjectCreditsClaimIn ProjectCreditsClaimRequestBody
type ProjectCreditsClaimIn struct {
Code string `json:"code"` // Credit code
}
// ProjectCreditsClaimOut Assigned credit
type ProjectCreditsClaimOut struct {
Code *string `json:"code,omitempty"` // Credit code
ExpireTime *time.Time `json:"expire_time,omitempty"` // Timestamp in ISO 8601 format, always in UTC
RemainingValue *string `json:"remaining_value,omitempty"` // Remaining credit value
StartTime *time.Time `json:"start_time,omitempty"` // Timestamp in ISO 8601 format, always in UTC
Type CreditType `json:"type,omitempty"` // Credit type
Value *string `json:"value,omitempty"` // Original credit value, or for expired credits, the consumed credit value
}
// invoiceGetOut InvoiceGetResponse
type invoiceGetOut struct {
Invoice InvoiceGetOut `json:"invoice"` // InvoiceModel
}
// projectCreditsClaimOut ProjectCreditsClaimResponse
type projectCreditsClaimOut struct {
Credit ProjectCreditsClaimOut `json:"credit"` // Assigned credit
}
// projectCreditsListOut ProjectCreditsListResponse
type projectCreditsListOut struct {
Credits []CreditOut `json:"credits"` // List of credits assigned to a project
}
// projectInvoiceListOut ProjectInvoiceListResponse
type projectInvoiceListOut struct {
Invoices []InvoiceOut `json:"invoices"` // List of project invoices
}