-
Notifications
You must be signed in to change notification settings - Fork 11
/
account.go
219 lines (166 loc) · 8.66 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
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
// This file is automatically created by Recurly's OpenAPI generation process
// and thus any edits you make by hand will be lost. If you wish to make a
// change to this file, please create a Github issue explaining the changes you
// need and we will usher them to the appropriate places.
package recurly
import (
"context"
"net/http"
"time"
)
type Account struct {
recurlyResponse *ResponseMetadata
Id string `json:"id,omitempty"`
// Object type
Object string `json:"object,omitempty"`
// Accounts can be either active or inactive.
State string `json:"state,omitempty"`
// The unique token for automatically logging the account in to the hosted management pages. You may automatically log the user into their hosted management pages by directing the user to: `https://{subdomain}.recurly.com/account/{hosted_login_token}`.
HostedLoginToken string `json:"hosted_login_token,omitempty"`
// The shipping addresses on the account.
ShippingAddresses []ShippingAddress `json:"shipping_addresses,omitempty"`
// Indicates if the account has a subscription that is either active, canceled, future, or paused.
HasLiveSubscription bool `json:"has_live_subscription,omitempty"`
// Indicates if the account has an active subscription.
HasActiveSubscription bool `json:"has_active_subscription,omitempty"`
// Indicates if the account has a future subscription.
HasFutureSubscription bool `json:"has_future_subscription,omitempty"`
// Indicates if the account has a canceled subscription.
HasCanceledSubscription bool `json:"has_canceled_subscription,omitempty"`
// Indicates if the account has a paused subscription.
HasPausedSubscription bool `json:"has_paused_subscription,omitempty"`
// Indicates if the account has a past due invoice.
HasPastDueInvoice bool `json:"has_past_due_invoice,omitempty"`
// When the account was created.
CreatedAt time.Time `json:"created_at,omitempty"`
// When the account was last changed.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// If present, when the account was last marked inactive.
DeletedAt time.Time `json:"deleted_at,omitempty"`
// The unique identifier of the account. This cannot be changed once the account is created.
Code string `json:"code,omitempty"`
// A secondary value for the account.
Username string `json:"username,omitempty"`
// The email address used for communicating with this customer. The customer will also use this email address to log into your hosted account management pages. This value does not need to be unique.
Email string `json:"email,omitempty"`
// Unique ID to identify the business entity assigned to the account. Available when the `Multiple Business Entities` feature is enabled.
OverrideBusinessEntityId string `json:"override_business_entity_id,omitempty"`
// Used to determine the language and locale of emails sent on behalf of the merchant to the customer.
PreferredLocale string `json:"preferred_locale,omitempty"`
// The [IANA time zone name](https://docs.recurly.com/docs/email-time-zones-and-time-stamps#supported-api-iana-time-zone-names) used to determine the time zone of emails sent on behalf of the merchant to the customer.
PreferredTimeZone string `json:"preferred_time_zone,omitempty"`
// Additional email address that should receive account correspondence. These should be separated only by commas. These CC emails will receive all emails that the `email` field also receives.
CcEmails string `json:"cc_emails,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Company string `json:"company,omitempty"`
// The VAT number of the account (to avoid having the VAT applied). This is only used for manually collected invoices.
VatNumber string `json:"vat_number,omitempty"`
// The tax status of the account. `true` exempts tax on the account, `false` applies tax on the account.
TaxExempt bool `json:"tax_exempt,omitempty"`
// The tax exemption certificate number for the account. If the merchant has an integration for the Vertex tax provider, this optional value will be sent in any tax calculation requests for the account.
ExemptionCertificate string `json:"exemption_certificate,omitempty"`
// The external accounts belonging to this account
ExternalAccounts []ExternalAccount `json:"external_accounts,omitempty"`
// The UUID of the parent account associated with this account.
ParentAccountId string `json:"parent_account_id,omitempty"`
// An enumerable describing the billing behavior of the account, specifically whether the account is self-paying or will rely on the parent account to pay.
BillTo string `json:"bill_to,omitempty"`
// Unique ID to identify a dunning campaign. Used to specify if a non-default dunning campaign should be assigned to this account. For sites without multiple dunning campaigns enabled, the default dunning campaign will always be used.
DunningCampaignId string `json:"dunning_campaign_id,omitempty"`
// Unique ID to identify an invoice template. Available when the site is on a Pro or Elite plan. Used to specify if a non-default invoice template will be used to generate invoices for the account. For sites without multiple invoice templates enabled, the default template will always be used.
InvoiceTemplateId string `json:"invoice_template_id,omitempty"`
Address Address `json:"address,omitempty"`
BillingInfo BillingInfo `json:"billing_info,omitempty"`
// The custom fields will only be altered when they are included in a request. Sending an empty array will not remove any existing values. To remove a field send the name with a null or empty value.
CustomFields []CustomField `json:"custom_fields,omitempty"`
// The Avalara AvaTax value that can be passed to identify the customer type for tax purposes. The range of values can be A - R (more info at Avalara). Value is case-sensitive.
EntityUseCode string `json:"entity_use_code,omitempty"`
}
// GetResponse returns the ResponseMetadata that generated this resource
func (resource *Account) GetResponse() *ResponseMetadata {
return resource.recurlyResponse
}
// setResponse sets the ResponseMetadata that generated this resource
func (resource *Account) setResponse(res *ResponseMetadata) {
resource.recurlyResponse = res
}
// internal struct for deserializing accounts
type accountList struct {
ListMetadata
Data []Account `json:"data"`
recurlyResponse *ResponseMetadata
}
// GetResponse returns the ResponseMetadata that generated this resource
func (resource *accountList) GetResponse() *ResponseMetadata {
return resource.recurlyResponse
}
// setResponse sets the ResponseMetadata that generated this resource
func (resource *accountList) setResponse(res *ResponseMetadata) {
resource.recurlyResponse = res
}
// AccountList allows you to paginate Account objects
type AccountList struct {
client HTTPCaller
requestOptions *RequestOptions
nextPagePath string
hasMore bool
data []Account
}
func NewAccountList(client HTTPCaller, nextPagePath string, requestOptions *RequestOptions) *AccountList {
return &AccountList{
client: client,
requestOptions: requestOptions,
nextPagePath: nextPagePath,
hasMore: true,
}
}
type AccountLister interface {
Fetch() error
FetchWithContext(ctx context.Context) error
Count() (*int64, error)
CountWithContext(ctx context.Context) (*int64, error)
Data() []Account
HasMore() bool
Next() string
}
func (list *AccountList) HasMore() bool {
return list.hasMore
}
func (list *AccountList) Next() string {
return list.nextPagePath
}
func (list *AccountList) Data() []Account {
return list.data
}
// Fetch fetches the next page of data into the `Data` property
func (list *AccountList) FetchWithContext(ctx context.Context) error {
resources := &accountList{}
err := list.client.Call(ctx, http.MethodGet, list.nextPagePath, nil, nil, list.requestOptions, resources)
if err != nil {
return err
}
// copy over properties from the response
list.nextPagePath = resources.Next
list.hasMore = resources.HasMore
list.data = resources.Data
return nil
}
// Fetch fetches the next page of data into the `Data` property
func (list *AccountList) Fetch() error {
return list.FetchWithContext(context.Background())
}
// Count returns the count of items on the server that match this pager
func (list *AccountList) CountWithContext(ctx context.Context) (*int64, error) {
resources := &accountList{}
err := list.client.Call(ctx, http.MethodHead, list.nextPagePath, nil, nil, list.requestOptions, resources)
if err != nil {
return nil, err
}
resp := resources.GetResponse()
return resp.TotalRecords, nil
}
// Count returns the count of items on the server that match this pager
func (list *AccountList) Count() (*int64, error) {
return list.CountWithContext(context.Background())
}