forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
103 lines (89 loc) · 3.09 KB
/
account.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
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
// Account associated with the token in use.
type Account struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
Company string `json:"company"`
Address1 string `json:"address_1"`
Address2 string `json:"address_2"`
Balance float32 `json:"balance"`
BalanceUninvoiced float32 `json:"balance_uninvoiced"`
City string `json:"city"`
State string `json:"state"`
Zip string `json:"zip"`
Country string `json:"country"`
TaxID string `json:"tax_id"`
Phone string `json:"phone"`
CreditCard *CreditCard `json:"credit_card"`
EUUID string `json:"euuid"`
BillingSource string `json:"billing_source"`
Capabilities []string `json:"capabilities"`
ActiveSince *time.Time `json:"active_since"`
ActivePromotions []Promotion `json:"active_promotions"`
}
// AccountUpdateOptions fields are those accepted by UpdateAccount
type AccountUpdateOptions struct {
Address1 string `json:"address_1,omitempty"`
Address2 string `json:"address_2,omitempty"`
City string `json:"city,omitempty"`
Company string `json:"company,omitempty"`
Country string `json:"country,omitempty"`
Email string `json:"email,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Phone string `json:"phone,omitempty"`
State string `json:"state,omitempty"`
TaxID string `json:"tax_id,omitempty"`
Zip string `json:"zip,omitempty"`
}
// GetUpdateOptions converts an Account to AccountUpdateOptions for use in UpdateAccount
func (i Account) GetUpdateOptions() (o AccountUpdateOptions) {
o.Address1 = i.Address1
o.Address2 = i.Address2
o.City = i.City
o.Company = i.Company
o.Country = i.Country
o.Email = i.Email
o.FirstName = i.FirstName
o.LastName = i.LastName
o.Phone = i.Phone
o.State = i.State
o.TaxID = i.TaxID
o.Zip = i.Zip
return
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (i *Account) UnmarshalJSON(b []byte) error {
type Mask Account
p := struct {
*Mask
ActiveSince *parseabletime.ParseableTime `json:"active_since"`
}{
Mask: (*Mask)(i),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
i.ActiveSince = (*time.Time)(p.ActiveSince)
return nil
}
// CreditCard information associated with the Account.
type CreditCard struct {
LastFour string `json:"last_four"`
Expiry string `json:"expiry"`
}
// GetAccount gets the contact and billing information related to the Account.
func (c *Client) GetAccount(ctx context.Context) (*Account, error) {
return doGETRequest[Account](ctx, c, "account")
}
// UpdateAccount updates the Account
func (c *Client) UpdateAccount(ctx context.Context, opts AccountUpdateOptions) (*Account, error) {
return doPUTRequest[Account](ctx, c, "account", opts)
}