forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
balance.go
98 lines (85 loc) · 3.25 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
package stripe
import "encoding/json"
// TransactionStatus is the list of allowed values for the transaction's status.
// Allowed values are "available", "pending".
type TransactionStatus string
// TransactionType is the list of allowed values for the transaction's type.
// Allowed values are "charge", "refund", "adjustment", "application_fee",
// "application_fee_refund", "transfer", "transfer_cancel", "transfer_failure".
type TransactionType string
// 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
}
// TxParams 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 TxParams struct {
Params
}
// TxListParams 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 TxListParams struct {
ListParams
Created, Available int64
Currency, Src, Transfer string
Type TransactionType
}
// Balance is the resource representing your Stripe balance.
// For more details see https://stripe.com/docs/api/#balance.
type Balance struct {
// Live indicates the live mode.
Live bool `json:"livemode"`
Available []Amount `json:"available"`
Pending []Amount `json:"pending"`
}
// Transaction is the resource representing the balance transaction.
// For more details see https://stripe.com/docs/api/#balance.
type Transaction struct {
ID string `json:"id"`
Amount int64 `json:"amount"`
Currency Currency `json:"currency"`
Available int64 `json:"available_on"`
Created int64 `json:"created"`
Fee int64 `json:"fee"`
FeeDetails []TxFee `json:"fee_details"`
Net int64 `json:"net"`
Status TransactionStatus `json:"status"`
Type TransactionType `json:"type"`
Desc string `json:"description"`
Src string `json:"source"`
Recipient string `json:"recipient"`
}
// TransactionList is a list of transactions as returned from a list endpoint.
type TransactionList struct {
ListMeta
Values []*Transaction `json:"data"`
}
// Amount is a structure wrapping an amount value and its currency.
type Amount struct {
Value int64 `json:"amount"`
Currency Currency `json:"currency"`
}
// TxFee is a structure that breaks down the fees in a transaction.
type TxFee struct {
Amount int64 `json:"amount"`
Currency Currency `json:"currency"`
Type string `json:"type"`
Desc string `json:"description"`
Application string `json:"application"`
}
// 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 *Transaction) UnmarshalJSON(data []byte) error {
type transaction Transaction
var tt transaction
err := json.Unmarshal(data, &tt)
if err == nil {
*t = Transaction(tt)
} else {
// the id is surrounded by "\" characters, so strip them
t.ID = string(data[1 : len(data)-1])
}
return nil
}