-
Notifications
You must be signed in to change notification settings - Fork 460
/
sourcetransaction.go
56 lines (49 loc) · 1.57 KB
/
sourcetransaction.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
package stripe
import "encoding/json"
// SourceTransactionListParams is the set of parameters that can be used when listing SourceTransactions.
type SourceTransactionListParams struct {
ListParams `form:"*"`
Source *string `form:"-"` // Sent in with the URL
}
// SourceTransactionList is a list object for SourceTransactions.
type SourceTransactionList struct {
APIResource
ListMeta
Data []*SourceTransaction `json:"data"`
}
// SourceTransaction is the resource representing a Stripe source transaction.
type SourceTransaction struct {
Amount int64 `json:"amount"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
CustomerData string `json:"customer_data"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Source string `json:"source"`
Type string `json:"type"`
TypeData map[string]interface{}
}
// UnmarshalJSON handles deserialization of a SourceTransaction. This custom
// unmarshaling is needed to extract the type specific data (accessible under
// `TypeData`) but stored in JSON under a hash named after the `type` of the
// source transaction.
func (t *SourceTransaction) UnmarshalJSON(data []byte) error {
type sourceTransaction SourceTransaction
var v sourceTransaction
err := json.Unmarshal(data, &v)
if err != nil {
return err
}
*t = SourceTransaction(v)
var raw map[string]interface{}
err = json.Unmarshal(data, &raw)
if err != nil {
return err
}
if d, ok := raw[t.Type]; ok {
if m, ok := d.(map[string]interface{}); ok {
t.TypeData = m
}
}
return nil
}