forked from blacklightcms/recurly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounts.go
120 lines (105 loc) · 4.22 KB
/
accounts.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
package recurly
import (
"encoding/xml"
"time"
)
// Account represents an individual account on your site
type Account struct {
XMLName xml.Name `xml:"account"`
Code string `xml:"account_code,omitempty"`
State string `xml:"state,omitempty"`
Username string `xml:"username,omitempty"`
Email string `xml:"email,omitempty"`
FirstName string `xml:"first_name,omitempty"`
LastName string `xml:"last_name,omitempty"`
CompanyName string `xml:"company_name,omitempty"`
VATNumber string `xml:"vat_number,omitempty"`
TaxExempt NullBool `xml:"tax_exempt,omitempty"`
BillingInfo *Billing `xml:"billing_info,omitempty"`
Address Address `xml:"address,omitempty"`
AcceptLanguage string `xml:"accept_language,omitempty"`
HostedLoginToken string `xml:"hosted_login_token,omitempty"`
CreatedAt NullTime `xml:"created_at,omitempty"`
HasPausedSubscription bool `xml:"has_paused_subscription,omitempty"`
ShippingAddresses *[]ShippingAddress `xml:"shipping_addresses>shipping_address,omitempty"`
CustomFields *CustomFields `xml:"custom_fields,omitempty"`
}
// AccountBalance is used for getting the account balance.
type AccountBalance struct {
XMLName xml.Name `xml:"account_balance"`
AccountCode string `xml:"-"`
PastDue bool `xml:"past_due"`
Balance int `xml:"balance_in_cents>USD"`
}
// Address is used for embedded addresses within other structs.
type Address struct {
NameOnAccount string `xml:"name_on_account,omitempty"`
FirstName string `xml:"first_name,omitempty"`
LastName string `xml:"last_name,omitempty"`
Company string `xml:"company,omitempty"`
Address string `xml:"address1,omitempty"`
Address2 string `xml:"address2,omitempty"`
City string `xml:"city,omitempty"`
State string `xml:"state,omitempty"`
Zip string `xml:"zip,omitempty"`
Country string `xml:"country,omitempty"`
Phone string `xml:"phone,omitempty"`
}
// MarshalXML ensures addresses marshal to nil if empty without the need
// to use pointers.
func (a Address) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if a.Address == "" && a.Address2 == "" && a.City == "" && a.State == "" && a.Zip == "" && a.Country == "" && a.Phone == "" {
return nil
}
e.EncodeToken(xml.StartElement{Name: xml.Name{Local: "address"}})
if a.Address != "" {
s := xml.StartElement{Name: xml.Name{Local: "address1"}}
e.EncodeToken(s)
e.EncodeToken(xml.CharData([]byte(a.Address)))
e.EncodeToken(xml.EndElement{Name: s.Name})
}
if a.Address2 != "" {
s := xml.StartElement{Name: xml.Name{Local: "address2"}}
e.EncodeToken(s)
e.EncodeToken(xml.CharData([]byte(a.Address2)))
e.EncodeToken(xml.EndElement{Name: s.Name})
}
if a.City != "" {
s := xml.StartElement{Name: xml.Name{Local: "city"}}
e.EncodeToken(s)
e.EncodeToken(xml.CharData([]byte(a.City)))
e.EncodeToken(xml.EndElement{Name: s.Name})
}
if a.State != "" {
s := xml.StartElement{Name: xml.Name{Local: "state"}}
e.EncodeToken(s)
e.EncodeToken(xml.CharData([]byte(a.State)))
e.EncodeToken(xml.EndElement{Name: s.Name})
}
if a.Zip != "" {
s := xml.StartElement{Name: xml.Name{Local: "zip"}}
e.EncodeToken(s)
e.EncodeToken(xml.CharData([]byte(a.Zip)))
e.EncodeToken(xml.EndElement{Name: s.Name})
}
if a.Country != "" {
s := xml.StartElement{Name: xml.Name{Local: "country"}}
e.EncodeToken(s)
e.EncodeToken(xml.CharData([]byte(a.Country)))
e.EncodeToken(xml.EndElement{Name: s.Name})
}
if a.Phone != "" {
s := xml.StartElement{Name: xml.Name{Local: "phone"}}
e.EncodeToken(s)
e.EncodeToken(xml.CharData([]byte(a.Phone)))
e.EncodeToken(xml.EndElement{Name: s.Name})
}
e.EncodeToken(xml.EndElement{Name: xml.Name{Local: "address"}})
return nil
}
// Note holds account notes.
type Note struct {
XMLName xml.Name `xml:"note"`
Message string `xml:"message,omitempty"`
CreatedAt time.Time `xml:"created_at,omitempty"`
}