github.com/aiven/aiven-go-client@v1.36.0/billing_group.go (about) 1 package aiven 2 3 type ( 4 // BillingGroup represents an billing group 5 BillingGroup struct { 6 BillingGroupRequest 7 Id string `json:"billing_group_id"` 8 } 9 10 // BillingGroupRequest is the request from Aiven for the billing group endpoints. 11 BillingGroupRequest struct { 12 BillingGroupName string `json:"billing_group_name,omitempty"` 13 AccountId *string `json:"account_id,omitempty"` 14 CardId *string `json:"card_id,omitempty"` 15 VatId *string `json:"vat_id,omitempty"` 16 BillingCurrency *string `json:"billing_currency,omitempty"` 17 BillingExtraText *string `json:"billing_extra_text,omitempty"` 18 BillingEmails []*ContactEmail `json:"billing_emails,omitempty"` 19 Company *string `json:"company,omitempty"` 20 AddressLines []string `json:"address_lines,omitempty"` 21 CountryCode *string `json:"country_code,omitempty"` 22 City *string `json:"city,omitempty"` 23 State *string `json:"state,omitempty"` 24 ZipCode *string `json:"zip_code,omitempty"` 25 CopyFromBillingGroup *string `json:"copy_from_billing_group,omitempty"` 26 } 27 28 // BillingGroupHandler is the client that interacts with billing groups on Aiven 29 BillingGroupHandler struct { 30 client *Client 31 } 32 33 // BillingGroupResponse is the response from Aiven for the billing group endpoints. 34 BillingGroupResponse struct { 35 APIResponse 36 BillingGroup *BillingGroup `json:"billing_group"` 37 } 38 39 // BillingGroupListResponse is the response from Aiven from a list of billing groups. 40 BillingGroupListResponse struct { 41 APIResponse 42 BillingGroupList []BillingGroup `json:"billing_groups"` 43 } 44 45 // BillingGroupProjectsResponse is the response from Aiven for the billing group projects 46 BillingGroupProjectsResponse struct { 47 APIResponse 48 Projects []BillingGroupProject `json:"projects,omitempty"` 49 } 50 51 // BillingGroupProject is assigned billing group project response 52 BillingGroupProject struct { 53 AvailableCredits string `json:"available_credits"` 54 EstimatedBalance string `json:"estimated_balance"` 55 ProjectName string `json:"project_name"` 56 } 57 58 // BillingGroupInvoice is the structure of the billing group invoice. 59 BillingGroupInvoice struct { 60 // BillingGroupId is the billing group ID. 61 BillingGroupId string `json:"billing_group_id"` 62 // BillingGroupName is the billing group name. 63 BillingGroupName string `json:"billing_group_name"` 64 // BillingGroupState is the billing group state. 65 BillingGroupState string `json:"billing_group_state"` 66 // Currency is the currency of the invoice. 67 Currency string `json:"currency"` 68 // DownloadCookie is the authentication cookie for downloading the invoice. 69 DownloadCookie string `json:"download_cookie"` 70 // GeneratedAt is the time when the invoice was generated. 71 GeneratedAt *string `json:"generated_at,omitempty"` 72 // InvoiceNumber is the invoice number. 73 InvoiceNumber string `json:"invoice_number"` 74 // PeriodBegin is the start of the billing period. 75 PeriodBegin string `json:"period_begin"` 76 // PeriodEnd is the end of the billing period. 77 PeriodEnd string `json:"period_end"` 78 // State is the state of the invoice. 79 State string `json:"state"` 80 // TotalIncVAT is the total amount including VAT. 81 TotalIncVAT string `json:"total_inc_vat"` 82 // TotalVAT is the total amount excluding VAT. 83 TotalVATZero string `json:"total_vat_zero"` 84 } 85 86 // BillingGroupListInvoicesResponse is the response from Aiven for the billing group invoices. 87 BillingGroupListInvoicesResponse struct { 88 APIResponse 89 90 // Invoices is the list of invoices. 91 Invoices []BillingGroupInvoice `json:"invoices"` 92 } 93 94 // BillingGroupInvoiceResponse is the response from Aiven for the billing group invoice. 95 BillingGroupInvoiceResponse struct { 96 APIResponse 97 98 // Invoice is the invoice. 99 Invoice BillingGroupInvoice `json:"invoice"` 100 } 101 102 // BillingGroupInvoiceLine is the structure of the billing group invoice line. 103 BillingGroupInvoiceLine struct { 104 // CloudName is the name of the cloud. 105 CloudName *string `json:"cloud_name,omitempty"` 106 // CommitmentName is the name of the commitment. 107 CommitmentName *string `json:"commitment_name,omitempty"` 108 // Description is the human-readable description of the line. 109 Description string `json:"description"` 110 // LinePreDiscountLocal is the line amount before discount in local currency. 111 LinePreDiscountLocal *string `json:"line_pre_discount_local,omitempty"` 112 // LineTotalLocal is the line total in local currency. 113 LineTotalLocal *string `json:"line_total_local,omitempty"` 114 // LineTotalUSD is the line total in USD. 115 LineTotalUSD string `json:"line_total_usd"` 116 // LineType is the type of the line. 117 LineType string `json:"line_type"` 118 // LocalCurrency is the local currency. 119 LocalCurrency *string `json:"local_currency,omitempty"` 120 // ProjectName is the name of the project. 121 ProjectName *string `json:"project_name,omitempty"` 122 // ServiceName is the name of the service. 123 ServiceName *string `json:"service_name,omitempty"` 124 // ServicePlan is the name of the service plan. 125 ServicePlan *string `json:"service_plan,omitempty"` 126 // ServiceType is the type of the service. 127 ServiceType *string `json:"service_type,omitempty"` 128 // Tags is the list of tags. 129 Tags *string `json:"tags,omitempty"` 130 // TimestampBegin is the start of the line. 131 TimestampBegin *string `json:"timestamp_begin,omitempty"` 132 // TimestampEnd is the end of the line. 133 TimestampEnd *string `json:"timestamp_end,omitempty"` 134 } 135 136 // BillingGroupListInvoiceLinesResponse is the response from Aiven for the billing group invoice lines. 137 BillingGroupListInvoiceLinesResponse struct { 138 APIResponse 139 140 // Lines is the list of invoice lines. 141 Lines []BillingGroupInvoiceLine `json:"lines"` 142 } 143 ) 144 145 // ListAll retrieves a list of all billing groups 146 func (h *BillingGroupHandler) ListAll() ([]BillingGroup, error) { 147 bts, err := h.client.doGetRequest(buildPath("billing-group"), nil) 148 if err != nil { 149 return nil, err 150 } 151 152 var r BillingGroupListResponse 153 errR := checkAPIResponse(bts, &r) 154 155 return r.BillingGroupList, errR 156 } 157 158 // Create creates a new project. 159 func (h *BillingGroupHandler) Create(req BillingGroupRequest) (*BillingGroup, error) { 160 bts, err := h.client.doPostRequest(buildPath("billing-group"), req) 161 if err != nil { 162 return nil, err 163 } 164 165 var r BillingGroupResponse 166 errR := checkAPIResponse(bts, &r) 167 168 return r.BillingGroup, errR 169 } 170 171 // Get returns gets the specified billing group. 172 func (h *BillingGroupHandler) Get(id string) (*BillingGroup, error) { 173 bts, err := h.client.doGetRequest(buildPath("billing-group", id), nil) 174 if err != nil { 175 return nil, err 176 } 177 178 var r BillingGroupResponse 179 errR := checkAPIResponse(bts, &r) 180 181 return r.BillingGroup, errR 182 } 183 184 // Update modifies the specified billing group with the given parameters. 185 func (h *BillingGroupHandler) Update(id string, req BillingGroupRequest) (*BillingGroup, error) { 186 bts, err := h.client.doPutRequest(buildPath("billing-group", id), req) 187 if err != nil { 188 return nil, err 189 } 190 191 var r BillingGroupResponse 192 errR := checkAPIResponse(bts, &r) 193 194 return r.BillingGroup, errR 195 } 196 197 // Delete removes the given billing group. 198 func (h *BillingGroupHandler) Delete(id string) error { 199 bts, err := h.client.doDeleteRequest(buildPath("billing-group", id), nil) 200 if err != nil { 201 return err 202 } 203 204 return checkAPIResponse(bts, nil) 205 } 206 207 // AssignProjects assigns projects to the billing group 208 func (h *BillingGroupHandler) AssignProjects(id string, projects []string) error { 209 req := struct { 210 ProjectsNames []string `json:"projects_names"` 211 }{ 212 ProjectsNames: projects, 213 } 214 215 bts, err := h.client.doPostRequest(buildPath("billing-group", id, "projects-assign"), req) 216 if err != nil { 217 return err 218 } 219 220 return checkAPIResponse(bts, nil) 221 } 222 223 // GetProjects retrieves a list of assigned projects 224 func (h *BillingGroupHandler) GetProjects(id string) ([]string, error) { 225 r := new(BillingGroupProjectsResponse) 226 227 bts, err := h.client.doGetRequest(buildPath("billing-group", id, "projects"), nil) 228 if err != nil { 229 return nil, err 230 } 231 232 errR := checkAPIResponse(bts, r) 233 if errR != nil { 234 return nil, errR 235 } 236 237 var projects []string 238 for _, p := range r.Projects { 239 projects = append(projects, p.ProjectName) 240 } 241 242 return projects, nil 243 } 244 245 // ListInvoices lists invoices for the billing group. 246 func (h *BillingGroupHandler) ListInvoices(id string) (*BillingGroupListInvoicesResponse, error) { 247 bts, err := h.client.doGetRequest(buildPath("billing-group", id, "invoice"), nil) 248 if err != nil { 249 return nil, err 250 } 251 252 var r BillingGroupListInvoicesResponse 253 254 return &r, checkAPIResponse(bts, &r) 255 } 256 257 // GetInvoice gets the specified invoice for the billing group. 258 func (h *BillingGroupHandler) GetInvoice(id, invoiceNumber string) (*BillingGroupInvoiceResponse, error) { 259 bts, err := h.client.doGetRequest(buildPath("billing-group", id, "invoice", invoiceNumber), nil) 260 if err != nil { 261 return nil, err 262 } 263 264 var r BillingGroupInvoiceResponse 265 266 return &r, checkAPIResponse(bts, &r) 267 } 268 269 // ListLines lists invoice lines for the billing group's invoice. 270 func (h *BillingGroupHandler) ListLines(id, invoiceNumber string) (*BillingGroupListInvoiceLinesResponse, error) { 271 bts, err := h.client.doGetRequest(buildPath("billing-group", id, "invoice", invoiceNumber, "lines"), nil) 272 if err != nil { 273 return nil, err 274 } 275 276 var r BillingGroupListInvoiceLinesResponse 277 278 return &r, checkAPIResponse(bts, &r) 279 }