forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
331 lines (275 loc) · 10.9 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package stripe
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
)
// LegalEntityType describes the types for a legal entity.
// Current values are "individual", "company".
type LegalEntityType string
// IdentityVerificationStatus describes the different statuses for identity verification.
// Current values are "pending", "verified", "unverified".
type IdentityVerificationStatus string
// Interval describes the payout interval.
// Current values are "manual", "daily", "weekly", "monthly".
type Interval string
const (
Individual LegalEntityType = "individual"
Company LegalEntityType = "company"
IdentityVerificationPending IdentityVerificationStatus = "pending"
IdentityVerificationVerified IdentityVerificationStatus = "verified"
IdentityVerificationUnverified IdentityVerificationStatus = "unverified"
Manual Interval = "manual"
Day Interval = "daily"
Week Interval = "weekly"
Month Interval = "monthly"
)
// AccountParams are the parameters allowed during account creation/updates.
type AccountParams struct {
Params
Country, Email, DefaultCurrency, Statement, BusinessName, SupportPhone string
LegalEntity *LegalEntity
TransferSchedule *TransferScheduleParams
Managed bool
BankAccount *BankAccountParams
}
// AccountListParams are the parameters allowed during account listing.
type AccountListParams struct {
ListParams
}
// TransferScheduleParams are the parameters allowed for transfer schedules.
type TransferScheduleParams struct {
Delay, MonthAnchor uint64
WeekAnchor string
Interval Interval
MinimumDelay bool
}
// Account is the resource representing youe Stripe account.
// For more details see https://stripe.com/docs/api/#account.
type Account struct {
ID string `json:"id"`
ChargesEnabled bool `json:"charges_enabled"`
Country string `json:"country"`
// Currencies is the list of supported currencies.
Currencies []string `json:"currencies_supported"`
DefaultCurrency string `json:"default_currency"`
DetailsSubmitted bool `json:"details_submitted"`
TransfersEnabled bool `json:"transfers_enabled"`
Name string `json:"display_name"`
Email string `json:"email"`
Statement string `json:"statement_descriptor"`
Timezone string `json:"timezone"`
BusinessName string `json:"business_name"`
BusinessUrl string `json:"business_url"`
SupportPhone string `json:"support_phone"`
ProductDesc string `json:"product_description"`
Managed bool `json:"managed"`
DebitNegativeBal bool `json:"debit_negative_balances"`
Keys *struct {
Secret string `json:"secret"`
Publish string `json:"publishable"`
} `json:"keys"`
Verification *struct {
Fields []string `json:"fields_needed"`
Due *int64 `json:"due_by"`
Contacted bool `json:"contacted"`
} `json:"verification"`
LegalEntity *LegalEntity `json:"legal_entity"`
TransferSchedule *TransferSchedule `json:"transfer_schedule"`
BankAccounts *BankAccountList `json:"bank_accounts"`
}
// LegalEntity is the structure for properties related to an account's legal state.
type LegalEntity struct {
Type LegalEntityType `json:"type"`
BusinessName string `json:"business_name"`
Address Address `json:"address"`
First string `json:"first_name"`
Last string `json:"last_name"`
PersonalAddress Address `json:"personal_address"`
DOB DOB `json:"dob"`
AdditionalOwners []Owner `json:"additional_owners"`
Verification IdentityVerification `json:"verification"`
SSN string `json:"ssn_last_4"`
PersonalID string `json:"personal_id_number"`
BusinessTaxID string `json:"business_tax_id"`
BusinessVatID string `json:"business_vat_id"`
}
// Address is the structure for an account address.
type Address struct {
Line1 string `json:"line1"`
Line2 string `json:"line2"`
City string `json:"city"`
State string `json:"state"`
Zip string `json:"postal_code"`
Country string `json:"country"`
}
// DOB is a structure for an account owner's date of birth.
type DOB struct {
Day int `json:"day"`
Month int `json:"month"`
Year int `json:"year"`
}
// Owner is the structure for an account owner.
type Owner struct {
First string `json:"first_name"`
Last string `json:"last_name"`
DOB DOB `json:"dob"`
Address Address `json:"address"`
Verification IdentityVerification `json:"verification"`
}
// IdentityVerification is the structure for an account's verification.
type IdentityVerification struct {
Status IdentityVerificationStatus `json:"status"`
Document *IdentityDocument `json:"document"`
Details *string `json:"details"`
}
type IdentityDocument struct {
ID string `json:"id"`
Created int64 `json:"created"`
Size int64 `json:"size"`
}
// TransferSchedule is the structure for an account's transfer schedule.
type TransferSchedule struct {
Delay uint64 `json:"delay_days"`
Interval Interval `json:"interval"`
WeekAnchor string `json:"weekly_anchor"`
MonthAnchor uint64 `json:"monthly_anchor"`
}
// AppendDetails adds the legal entity to the query string.
func (l *LegalEntity) AppendDetails(values *url.Values) {
values.Add("legal_entity[type]", string(l.Type))
if len(l.BusinessName) > 0 {
values.Add("legal_entity[business_name]", l.BusinessName)
}
if len(l.First) > 0 {
values.Add("legal_entity[first_name]", l.First)
}
if len(l.Last) > 0 {
values.Add("legal_entity[last_name]", l.Last)
}
values.Add("legal_entity[dob][day]", strconv.Itoa(l.DOB.Day))
values.Add("legal_entity[dob][month]", strconv.Itoa(l.DOB.Month))
values.Add("legal_entity[dob][year]", strconv.Itoa(l.DOB.Year))
if len(l.SSN) > 0 {
values.Add("legal_entity[ssn_last_4]", l.SSN)
}
if len(l.PersonalID) > 0 {
values.Add("legal_entity[personal_id_number]", l.PersonalID)
}
if len(l.BusinessTaxID) > 0 {
values.Add("legal_entity[business_tax_id]", l.BusinessTaxID)
}
if len(l.BusinessVatID) > 0 {
values.Add("legal_entity[business_vat_id]", l.BusinessVatID)
}
if len(l.Address.Line1) > 0 {
values.Add("legal_entity[address][line1]", l.Address.Line1)
}
if len(l.Address.Line2) > 0 {
values.Add("legal_entity[address][line2]", l.Address.Line2)
}
if len(l.Address.City) > 0 {
values.Add("legal_entity[address][city]", l.Address.City)
}
if len(l.Address.State) > 0 {
values.Add("legal_entity[address][state]", l.Address.State)
}
if len(l.Address.Zip) > 0 {
values.Add("legal_entity[address][postal_code]", l.Address.Zip)
}
if len(l.Address.Country) > 0 {
values.Add("legal_entity[address][country]", l.Address.Country)
}
if len(l.PersonalAddress.Line1) > 0 {
values.Add("legal_entity[personal_address][line1]", l.PersonalAddress.Line1)
}
if len(l.PersonalAddress.Line2) > 0 {
values.Add("legal_entity[personal_address][line2]", l.PersonalAddress.Line2)
}
if len(l.PersonalAddress.City) > 0 {
values.Add("legal_entity[personal_address][city]", l.PersonalAddress.City)
}
if len(l.PersonalAddress.State) > 0 {
values.Add("legal_entity[personal_address][state]", l.PersonalAddress.State)
}
if len(l.PersonalAddress.Zip) > 0 {
values.Add("legal_entity[personal_address][postal_code]", l.PersonalAddress.Zip)
}
if len(l.PersonalAddress.Country) > 0 {
values.Add("legal_entity[personal_address][country]", l.PersonalAddress.Country)
}
for i, owner := range l.AdditionalOwners {
if len(owner.First) > 0 {
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][first_name]", i), owner.First)
}
if len(owner.Last) > 0 {
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][last_name]", i), owner.Last)
}
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][dob][day]", i), strconv.Itoa(owner.DOB.Day))
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][dob][month]", i), strconv.Itoa(owner.DOB.Month))
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][dob][year]", i), strconv.Itoa(owner.DOB.Year))
if len(owner.Address.Line1) > 0 {
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][address][line1]", i), owner.Address.Line1)
}
if len(owner.Address.Line2) > 0 {
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][address][line2]", i), owner.Address.Line2)
}
if len(owner.Address.City) > 0 {
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][address][city]", i), owner.Address.City)
}
if len(owner.Address.State) > 0 {
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][address][state]", i), owner.Address.State)
}
if len(owner.Address.Zip) > 0 {
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][address][postal_code]", i), owner.Address.Zip)
}
if len(owner.Address.Country) > 0 {
values.Add(fmt.Sprintf("legal_entity[additional_owners][%v][address][country]", i), owner.Address.Country)
}
}
}
// AppendDetails adds the transfer schedule to the query string.
func (t *TransferScheduleParams) AppendDetails(values *url.Values) {
if t.Delay > 0 {
values.Add("tranfer_schedule[delay_days]", strconv.FormatUint(t.Delay, 10))
} else if t.MinimumDelay {
values.Add("transfer_schedule[delay_days]", "minimum")
}
values.Add("transfer_schedule[interval]", string(t.Interval))
if t.Interval == Week && len(t.WeekAnchor) > 0 {
values.Add("transfer_schedule[weekly_anchor]", t.WeekAnchor)
} else if t.Interval == Month && t.MonthAnchor > 0 {
values.Add("transfer_schedule[monthly_anchor]", strconv.FormatUint(t.MonthAnchor, 10))
}
}
// UnmarshalJSON handles deserialization of an Account.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (a *Account) UnmarshalJSON(data []byte) error {
type account Account
var aa account
err := json.Unmarshal(data, &aa)
if err == nil {
*a = Account(aa)
} else {
// the id is surrounded by "\" characters, so strip them
a.ID = string(data[1 : len(data)-1])
}
return nil
}
// UnmarshalJSON handles deserialization of an IdentityDocument.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (d *IdentityDocument) UnmarshalJSON(data []byte) error {
type identityDocument IdentityDocument
var doc identityDocument
err := json.Unmarshal(data, &doc)
if err == nil {
*d = IdentityDocument(doc)
} else {
// the id is surrounded by "\" characters, so strip them
d.ID = string(data[1 : len(data)-1])
}
return nil
}