@@ -31,22 +31,56 @@ type Account struct {
3131 ActiveSince * time.Time `json:"active_since"`
3232}
3333
34+ // AccountUpdateOptions fields are those accepted by UpdateAccount
35+ type AccountUpdateOptions struct {
36+ Address1 string `json:"address_1,omitempty"`
37+ Address2 string `json:"address_2,omitempty"`
38+ City string `json:"city,omitempty"`
39+ Company string `json:"company,omitempty"`
40+ Country string `json:"country,omitempty"`
41+ Email string `json:"email,omitempty"`
42+ FirstName string `json:"first_name,omitempty"`
43+ LastName string `json:"last_name,omitempty"`
44+ Phone string `json:"phone,omitempty"`
45+ State string `json:"state,omitempty"`
46+ TaxID string `json:"tax_id,omitempty"`
47+ Zip string `json:"zip,omitempty"`
48+ }
49+
50+ // GetUpdateOptions converts an Account to AccountUpdateOptions for use in UpdateAccount
51+ func (i Account ) GetUpdateOptions () (o AccountUpdateOptions ) {
52+ o .Address1 = i .Address1
53+ o .Address2 = i .Address2
54+ o .City = i .City
55+ o .Company = i .Company
56+ o .Country = i .Country
57+ o .Email = i .Email
58+ o .FirstName = i .FirstName
59+ o .LastName = i .LastName
60+ o .Phone = i .Phone
61+ o .State = i .State
62+ o .TaxID = i .TaxID
63+ o .Zip = i .Zip
64+
65+ return
66+ }
67+
3468// UnmarshalJSON implements the json.Unmarshaler interface
35- func (account * Account ) UnmarshalJSON (b []byte ) error {
69+ func (i * Account ) UnmarshalJSON (b []byte ) error {
3670 type Mask Account
3771
3872 p := struct {
3973 * Mask
4074 ActiveSince * parseabletime.ParseableTime `json:"active_since"`
4175 }{
42- Mask : (* Mask )(account ),
76+ Mask : (* Mask )(i ),
4377 }
4478
4579 if err := json .Unmarshal (b , & p ); err != nil {
4680 return err
4781 }
4882
49- account .ActiveSince = (* time .Time )(p .ActiveSince )
83+ i .ActiveSince = (* time .Time )(p .ActiveSince )
5084
5185 return nil
5286}
@@ -59,11 +93,10 @@ type CreditCard struct {
5993
6094// GetAccount gets the contact and billing information related to the Account.
6195func (c * Client ) GetAccount (ctx context.Context ) (* Account , error ) {
62- e := "account"
63- response , err := doGETRequest [Account ](ctx , c , e )
64- if err != nil {
65- return nil , err
66- }
96+ return doGETRequest [Account ](ctx , c , "account" )
97+ }
6798
68- return response , nil
99+ // UpdateAccount updates the Account
100+ func (c * Client ) UpdateAccount (ctx context.Context , opts AccountUpdateOptions ) (* Account , error ) {
101+ return doPUTRequest [Account ](ctx , c , "account" , opts )
69102}
0 commit comments