forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipient.go
113 lines (97 loc) · 3.3 KB
/
recipient.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
package stripe
import (
"encoding/json"
"net/url"
)
// RecipientType is the list of allowed values for the recipient's type.
// Allowed values are "individual", "corporation".
type RecipientType string
const (
Individual RecipientType = "individual"
Corp RecipientType = "corporation"
)
// RecipientParams is the set of parameters that can be used when creating or updating recipients.
// For more details see https://stripe.com/docs/api#create_recipient and https://stripe.com/docs/api#update_recipient.
type RecipientParams struct {
Params
Name string
Type RecipientType
TaxId, Token, Email, Desc string
Bank *BankAccountParams
Card *CardParams
DefaultCard string
}
// RecipientListParams is the set of parameters that can be used when listing recipients.
// For more details see https://stripe.com/docs/api#list_recipients.
type RecipientListParams struct {
ListParams
Verified bool
}
// BankAccountParams is the set of parameters that can be used when creating or updating a bank account.
type BankAccountParams struct {
Country, Routing, Account string
}
// Recipient is the resource representing a Stripe recipient.
// For more details see https://stripe.com/docs/api#recipients.
type Recipient struct {
Id string `json:"id"`
Live bool `json:"livemode"`
Created int64 `json:"created"`
Type RecipientType `json:"type"`
Bank *BankAccount `json:"active_account"`
Desc string `json:"description"`
Email string `json:"email"`
Meta map[string]string `json:"metadata"`
Name string `json:"name"`
Cards *CardList `json:"cards"`
DefaultCard *Card `json:"default_card"`
}
// 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"`
Disabled bool `json:"disabled"`
Fingerprint string `json:"fingerprint"`
Valid bool `json:"validated"`
}
// RecipientIter is a iterator for list responses.
type RecipientIter struct {
Iter *Iter
}
// Next returns the next value in the list.
func (i *RecipientIter) Next() (*Recipient, error) {
r, err := i.Iter.Next()
if err != nil {
return nil, err
}
return r.(*Recipient), err
}
// Stop returns true if there are no more iterations to be performed.
func (i *RecipientIter) Stop() bool {
return i.Iter.Stop()
}
// Meta returns the list metadata.
func (i *RecipientIter) Meta() *ListMeta {
return i.Iter.Meta()
}
// 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)
}
func (r *Recipient) UnmarshalJSON(data []byte) error {
type recipient Recipient
var rr recipient
err := json.Unmarshal(data, &rr)
if err == nil {
*r = Recipient(rr)
} else {
// the id is surrounded by escaped \, so ignore those
r.Id = string(data[1 : len(data)-1])
}
return nil
}