This repository has been archived by the owner on Dec 27, 2018. It is now read-only.
forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
balance.go
216 lines (191 loc) · 9.66 KB
/
balance.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
package stripe
import "encoding/json"
// BalanceTransactionStatus is the list of allowed values for the balance transaction's status.
type BalanceTransactionStatus string
// List of values that BalanceTransactionStatus can take.
const (
BalanceTransactionStatusAvailable BalanceTransactionStatus = "available"
BalanceTransactionStatusPending BalanceTransactionStatus = "pending"
)
// BalanceTransactionType is the list of allowed values for the balance transaction's type.
type BalanceTransactionType string
// List of values that BalanceTransactionType can take.
const (
BalanceTransactionTypeAdjustment BalanceTransactionType = "adjustment"
BalanceTransactionTypeApplicationFee BalanceTransactionType = "application_fee"
BalanceTransactionTypeApplicationFeeRefund BalanceTransactionType = "application_fee_refund"
BalanceTransactionTypeCharge BalanceTransactionType = "charge"
BalanceTransactionTypeIssuingAuthorizationHold BalanceTransactionType = "issuing_authorization_hold"
BalanceTransactionTypeIssuingAuthorizationRelease BalanceTransactionType = "issuing_authorization_release"
BalanceTransactionTypeIssuingAuthorizationTransaction BalanceTransactionType = "issuing_transaction"
BalanceTransactionTypePayment BalanceTransactionType = "payment"
BalanceTransactionTypePaymentFailureRefund BalanceTransactionType = "payment_failure_refund"
BalanceTransactionTypePaymentRefund BalanceTransactionType = "payment_refund"
BalanceTransactionTypePayout BalanceTransactionType = "payout"
BalanceTransactionTypePayoutCancel BalanceTransactionType = "payout_cancel"
BalanceTransactionTypePayoutFailure BalanceTransactionType = "payout_failure"
BalanceTransactionTypeRecipientTransfer BalanceTransactionType = "recipient_transfer"
BalanceTransactionTypeRecipientTransferCancel BalanceTransactionType = "recipient_transfer_cancel"
BalanceTransactionTypeRecipientTransferFailure BalanceTransactionType = "recipient_transfer_failure"
BalanceTransactionTypeRefund BalanceTransactionType = "refund"
BalanceTransactionTypeStripeFee BalanceTransactionType = "stripe_fee"
BalanceTransactionTypeTransfer BalanceTransactionType = "transfer"
BalanceTransactionTypeTransferRefund BalanceTransactionType = "transfer_refund"
)
// BalanceTransactionSourceType consts represent valid balance transaction sources.
type BalanceTransactionSourceType string
// List of values that BalanceTransactionSourceType can take.
const (
BalanceTransactionSourceTypeApplicationFee BalanceTransactionSourceType = "application_fee"
BalanceTransactionSourceTypeCharge BalanceTransactionSourceType = "charge"
BalanceTransactionSourceTypeDispute BalanceTransactionSourceType = "dispute"
BalanceTransactionSourceTypeIssuingAuthorization BalanceTransactionSourceType = "issuing.authorization"
BalanceTransactionSourceTypeIssuingTransaction BalanceTransactionSourceType = "issuing.transaction"
BalanceTransactionSourceTypePayout BalanceTransactionSourceType = "payout"
BalanceTransactionSourceTypeRecipientTransfer BalanceTransactionSourceType = "recipient_transfer"
BalanceTransactionSourceTypeRefund BalanceTransactionSourceType = "refund"
BalanceTransactionSourceTypeReversal BalanceTransactionSourceType = "reversal"
BalanceTransactionSourceTypeTransfer BalanceTransactionSourceType = "transfer"
)
// BalanceTransactionSource describes the source of a balance Transaction.
// The Type should indicate which object is fleshed out.
// For more details see https://stripe.com/docs/api#retrieve_balance_transaction
type BalanceTransactionSource struct {
ApplicationFee *ApplicationFee `json:"-"`
Charge *Charge `json:"-"`
Dispute *Dispute `json:"-"`
ID string `json:"id"`
IssuingAuthorization *IssuingAuthorization `json:"-"`
IssuingTransaction *IssuingAuthorization `json:"-"`
Payout *Payout `json:"-"`
RecipientTransfer *RecipientTransfer `json:"-"`
Refund *Refund `json:"-"`
Reversal *Reversal `json:"-"`
Transfer *Transfer `json:"-"`
Type BalanceTransactionSourceType `json:"object"`
}
// BalanceParams is the set of parameters that can be used when retrieving a balance.
// For more details see https://stripe.com/docs/api#balance.
type BalanceParams struct {
Params `form:"*"`
}
// BalanceTransactionParams is the set of parameters that can be used when retrieving a transaction.
// For more details see https://stripe.com/docs/api#retrieve_balance_transaction.
type BalanceTransactionParams struct {
Params `form:"*"`
}
// BalanceTransactionListParams is the set of parameters that can be used when listing balance transactions.
// For more details see https://stripe.com/docs/api/#balance_history.
type BalanceTransactionListParams struct {
ListParams `form:"*"`
AvailableOn *int64 `form:"available_on"`
AvailableOnRange *RangeQueryParams `form:"available_on"`
Created *int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
Currency *string `form:"currency"`
Payout *string `form:"payout"`
Source *string `form:"source"`
Type *string `form:"type"`
}
// Balance is the resource representing your Stripe balance.
// For more details see https://stripe.com/docs/api/#balance.
type Balance struct {
Available []*Amount `json:"available"`
Livemode bool `json:"livemode"`
Pending []*Amount `json:"pending"`
}
// BalanceTransaction is the resource representing the balance transaction.
// For more details see https://stripe.com/docs/api/#balance.
type BalanceTransaction struct {
Amount int64 `json:"amount"`
AvailableOn int64 `json:"available_on"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Description string `json:"description"`
ExchangeRate float64 `json:"exchange_rate"`
ID string `json:"id"`
Fee int64 `json:"fee"`
FeeDetails []*BalanceTransactionFee `json:"fee_details"`
Net int64 `json:"net"`
Recipient string `json:"recipient"`
Source *BalanceTransactionSource `json:"source"`
Status BalanceTransactionStatus `json:"status"`
Type BalanceTransactionType `json:"type"`
}
// BalanceTransactionList is a list of transactions as returned from a list endpoint.
type BalanceTransactionList struct {
ListMeta
Data []*BalanceTransaction `json:"data"`
}
// Amount is a structure wrapping an amount value and its currency.
type Amount struct {
Value int64 `json:"amount"`
Currency Currency `json:"currency"`
}
// BalanceTransactionFee is a structure that breaks down the fees in a transaction.
type BalanceTransactionFee struct {
Amount int64 `json:"amount"`
Application string `json:"application"`
Currency Currency `json:"currency"`
Description string `json:"description"`
Type string `json:"type"`
}
// UnmarshalJSON handles deserialization of a Transaction.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (t *BalanceTransaction) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
t.ID = id
return nil
}
type balanceTransaction BalanceTransaction
var v balanceTransaction
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*t = BalanceTransaction(v)
return nil
}
// UnmarshalJSON handles deserialization of a BalanceTransactionSource.
// This custom unmarshaling is needed because the specific
// type of transaction source it refers to is specified in the JSON
func (s *BalanceTransactionSource) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
s.ID = id
return nil
}
type balanceTransactionSource BalanceTransactionSource
var v balanceTransactionSource
if err := json.Unmarshal(data, &v); err != nil {
return err
}
var err error
*s = BalanceTransactionSource(v)
switch s.Type {
case BalanceTransactionSourceTypeApplicationFee:
err = json.Unmarshal(data, &s.ApplicationFee)
case BalanceTransactionSourceTypeCharge:
err = json.Unmarshal(data, &s.Charge)
case BalanceTransactionSourceTypeDispute:
err = json.Unmarshal(data, &s.Dispute)
case BalanceTransactionSourceTypeIssuingAuthorization:
err = json.Unmarshal(data, &s.IssuingAuthorization)
case BalanceTransactionSourceTypeIssuingTransaction:
err = json.Unmarshal(data, &s.IssuingTransaction)
case BalanceTransactionSourceTypePayout:
err = json.Unmarshal(data, &s.Payout)
case BalanceTransactionSourceTypeRecipientTransfer:
err = json.Unmarshal(data, &s.RecipientTransfer)
case BalanceTransactionSourceTypeRefund:
err = json.Unmarshal(data, &s.Refund)
case BalanceTransactionSourceTypeReversal:
err = json.Unmarshal(data, &s.Reversal)
case BalanceTransactionSourceTypeTransfer:
err = json.Unmarshal(data, &s.Transfer)
}
return err
}
// MarshalJSON handles serialization of a BalanceTransactionSource.
func (s *BalanceTransactionSource) MarshalJSON() ([]byte, error) {
return json.Marshal(s.ID)
}