forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankaccount.go
69 lines (59 loc) · 2.09 KB
/
bankaccount.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
package stripe
import (
"encoding/json"
"net/url"
)
// BankAccountStatus is the list of allowed values for the bank account's status.
// Allowed values are "new", "verified", "validated", "errored".
type BankAccountStatus string
// BankAccountParams is the set of parameters that can be used when creating or updating a bank account.
type BankAccountParams struct {
Params
AccountID, Token, Country, Routing, Account, Currency string
Default bool
}
// BankAccountListParams is the set of parameters that can be used when listing bank accounts.
type BankAccountListParams struct {
ListParams
AccountID string
}
// BankAccount represents a Stripe bank account.
type BankAccount struct {
ID string `json:"id"`
Name string `json:"bank_name"`
Country string `json:"country"`
Currency Currency `json:"currency"`
LastFour string `json:"last4"`
Fingerprint string `json:"fingerprint"`
Status BankAccountStatus `json:"status"`
Routing string `json:"routing_number"`
}
// BankAccountList is a list object for bank accounts.
type BankAccountList struct {
ListMeta
Values []*BankAccount `json:"data"`
}
// AppendDetails adds the bank account's details to the query string values.
func (b *BankAccountParams) AppendDetails(values *url.Values) {
values.Add("bank_account[country]", b.Country)
values.Add("bank_account[routing_number]", b.Routing)
values.Add("bank_account[account_number]", b.Account)
if len(b.Currency) > 0 {
values.Add("bank_account[currency]", b.Currency)
}
}
// UnmarshalJSON handles deserialization of a BankAccount.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (b *BankAccount) UnmarshalJSON(data []byte) error {
type bankAccount BankAccount
var bb bankAccount
err := json.Unmarshal(data, &bb)
if err == nil {
*b = BankAccount(bb)
} else {
// the id is surrounded by "\" characters, so strip them
b.ID = string(data[1 : len(data)-1])
}
return nil
}