-
Notifications
You must be signed in to change notification settings - Fork 462
/
recipienttransfer.go
155 lines (133 loc) · 6.84 KB
/
recipienttransfer.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
package stripe
import "encoding/json"
// RecipientTransferDestinationType consts represent valid recipient_transfer destinations.
type RecipientTransferDestinationType string
const (
RecipientTransferDestinationBankAccount RecipientTransferDestinationType = "bank_account"
RecipientTransferDestinationCard RecipientTransferDestinationType = "card"
)
// RecipientTransferFailureCode is the list of allowed values for the recipient_transfer's failure code.
type RecipientTransferFailureCode string
const (
RecipientTransferFailureCodeAccountClosed RecipientTransferFailureCode = "account_closed"
RecipientTransferFailureCodeAccountFrozen RecipientTransferFailureCode = "account_frozen"
RecipientTransferFailureCodeBankAccountRestricted RecipientTransferFailureCode = "bank_account_restricted"
RecipientTransferFailureCodeBankOwnershipChanged RecipientTransferFailureCode = "bank_ownership_changed"
RecipientTransferFailureCodeDebitNotAuthorized RecipientTransferFailureCode = "debit_not_authorized"
RecipientTransferFailureCodeCouldNotProcess RecipientTransferFailureCode = "could_not_process"
RecipientTransferFailureCodeInsufficientFunds RecipientTransferFailureCode = "insufficient_funds"
RecipientTransferFailureCodeInvalidAccountNumber RecipientTransferFailureCode = "invalid_account_number"
RecipientTransferFailureCodeInvalidCurrency RecipientTransferFailureCode = "invalid_currency"
RecipientTransferFailureCodeNoAccount RecipientTransferFailureCode = "no_account"
)
// RecipientTransferSourceType is the list of allowed values for the recipient_transfer's source_type field.
type RecipientTransferSourceType string
const (
RecipientTransferSourceTypeAlipayAccount RecipientTransferSourceType = "alipay_account"
RecipientTransferSourceTypeBankAccount RecipientTransferSourceType = "bank_account"
RecipientTransferSourceTypeBitcoinReceiver RecipientTransferSourceType = "bitcoin_receiver"
RecipientTransferSourceTypeCard RecipientTransferSourceType = "card"
)
// RecipientTransferStatus is the list of allowed values for the recipient_transfer's status.
type RecipientTransferStatus string
const (
RecipientTransferStatusFailed RecipientTransferStatus = "failed"
RecipientTransferStatusInTransit RecipientTransferStatus = "in_transit"
RecipientTransferStatusPaid RecipientTransferStatus = "paid"
RecipientTransferStatusPending RecipientTransferStatus = "pending"
)
// RecipientTransferType is the list of allowed values for the recipient_transfer's type.
type RecipientTransferType string
const (
RecipientTransferTypeBankAccount RecipientTransferType = "bank_account"
RecipientTransferTypeCard RecipientTransferType = "card"
)
// RecipientTransferMethodType represents the type of recipient_transfer
type RecipientTransferMethodType string
const (
RecipientTransferMethodInstant RecipientTransferMethodType = "instant"
RecipientTransferMethodStandard RecipientTransferMethodType = "standard"
)
// RecipientTransferDestination describes the destination of a RecipientTransfer.
// The Type should indicate which object is fleshed out
// For more details see https://stripe.com/docs/api/go#recipient_transfer_object
type RecipientTransferDestination struct {
BankAccount *BankAccount `json:"-"`
Card *Card `json:"-"`
ID string `json:"id"`
Type RecipientTransferDestinationType `json:"object"`
}
// RecipientTransfer is the resource representing a Stripe recipient_transfer.
// For more details see https://stripe.com/docs/api#recipient_transfers.
type RecipientTransfer struct {
Amount int64 `json:"amount"`
AmountReversed int64 `json:"amount_reversed"`
BalanceTransaction *BalanceTransaction `json:"balance_transaction"`
BankAccount *BankAccount `json:"bank_account"`
Card *Card `json:"card"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Date int64 `json:"date"`
Description string `json:"description"`
Destination string `json:"destination"`
FailureCode RecipientTransferFailureCode `json:"failure_code"`
FailureMessage string `json:"failure_message"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Method RecipientTransferMethodType `json:"method"`
Recipient *Recipient `json:"recipient"`
Reversals *ReversalList `json:"reversals"`
Reversed bool `json:"reversed"`
SourceTransaction *BalanceTransactionSource `json:"source_transaction"`
SourceType RecipientTransferSourceType `json:"source_type"`
StatementDescriptor string `json:"statement_descriptor"`
Status RecipientTransferStatus `json:"status"`
Type RecipientTransferType `json:"type"`
}
// UnmarshalJSON handles deserialization of a RecipientTransfer.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (t *RecipientTransfer) UnmarshalJSON(data []byte) error {
type transfer RecipientTransfer
var tb transfer
err := json.Unmarshal(data, &tb)
if err == nil {
*t = RecipientTransfer(tb)
} else {
// the id is surrounded by "\" characters, so strip them
t.ID = string(data[1 : len(data)-1])
}
return nil
}
// UnmarshalJSON handles deserialization of a RecipientTransferDestination.
// This custom unmarshaling is needed because the specific
// type of destination it refers to is specified in the JSON
func (d *RecipientTransferDestination) UnmarshalJSON(data []byte) error {
type dest RecipientTransferDestination
var dd dest
err := json.Unmarshal(data, &dd)
if err == nil {
*d = RecipientTransferDestination(dd)
switch d.Type {
case RecipientTransferDestinationBankAccount:
err = json.Unmarshal(data, &d.BankAccount)
case RecipientTransferDestinationCard:
err = json.Unmarshal(data, &d.Card)
}
if err != nil {
return err
}
} else {
// the id is surrounded by "\" characters, so strip them
d.ID = string(data[1 : len(data)-1])
}
return nil
}
// MarshalJSON handles serialization of a RecipientTransferDestination.
// This custom marshaling is needed because we can only send a string
// ID as a destination, even though it can be expanded to a full
// object when retrieving
func (d *RecipientTransferDestination) MarshalJSON() ([]byte, error) {
return json.Marshal(d.ID)
}