This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankaccount.go
100 lines (85 loc) · 3.13 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
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
package stripe
import (
"encoding/json"
"fmt"
"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
// The identifier of the parent account under which bank accounts are
// nested.
AccountID string
// A token referencing an external account like one returned from
// Stripe.js.
Token string
// Information on an external account to reference. Only used if `Token`
// is not provided.
Account, AccountHolderName, AccountHolderType, Country, Currency, Routing string
Default bool
Customer string
}
// 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"`
AccountHolderName string `json:"account_holder_name"`
AccountHolderType string `json:"account_holder_type"`
Country string `json:"country"`
Currency Currency `json:"currency"`
Default bool `json:"default_for_currency"`
LastFour string `json:"last4"`
Fingerprint string `json:"fingerprint"`
Status BankAccountStatus `json:"status"`
Routing string `json:"routing_number"`
Deleted bool `json:"deleted"`
Customer *Customer `json:"customer"`
Meta map[string]string `json:"metadata"`
}
// BankAccountList is a list object for bank accounts.
type BankAccountList struct {
ListMeta
Values []*BankAccount `json:"data"`
}
// Display implements Displayer.Display.
func (b *BankAccount) Display() string {
return fmt.Sprintf("Bank account ending in %s", b.LastFour)
}
// 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 b.AccountHolderName != "" {
values.Add("bank_account[account_holder_name]", b.AccountHolderName)
}
if b.AccountHolderType != "" {
values.Add("bank_account[account_holder_type]", b.AccountHolderType)
}
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
}