-
Notifications
You must be signed in to change notification settings - Fork 6
/
payment_sources.go
88 lines (81 loc) · 2.43 KB
/
payment_sources.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
package invoiced
import (
"encoding/json"
"errors"
)
type PaymentSourceRequest struct {
GatewayToken *string `json:"gateway_token,omitempty"`
InvoicedToken *string `json:"invoiced_token,omitempty"`
MakeDefault *bool `json:"make_default,omitempty"`
Method *string `json:"method,omitempty"`
Object *string `json:"object,omitempty"`
}
type PaymentSource struct {
*BankAccount
*Card
Object string `json:"object"`
}
type Card struct {
Brand string `json:"brand"`
Chargeable bool `json:"chargeable"`
CreatedAt int64 `json:"created_at"`
ExpMonth int64 `json:"exp_month"`
ExpYear int64 `json:"exp_year"`
FailureReason string `json:"failure_reason"`
Funding string `json:"funding"`
Gateway string `json:"gateway"`
GatewayCustomer string `json:"gateway_customer"`
GatewayId string `json:"gateway_id"`
Id int64 `json:"id"`
Last4 string `json:"last4"`
Object string `json:"object"`
ReceiptEmail string `json:"receipt_email"`
UpdatedAt int64 `json:"updated_at"`
}
type BankAccount struct {
BankName string `json:"bank_name"`
Chargeable bool `json:"chargeable"`
Country string `json:"country"`
CreatedAt int64 `json:"created_at"`
Currency string `json:"currency"`
FailureReason string `json:"failure_reason"`
Gateway string `json:"gateway"`
GatewayCustomer string `json:"gateway_customer"`
GatewayId string `json:"gateway_id"`
Id int64 `json:"id"`
Last4 string `json:"last4"`
Object string `json:"object"`
ReceiptEmail string `json:"receipt_email"`
RoutingNumber string `json:"routing_number"`
UpdatedAt int64 `json:"updated_at"`
Verified bool `json:"verified"`
}
type PaymentSources []*PaymentSource
func (d *PaymentSource) UnmarshalJSON(data []byte) error {
temp := struct {
Object string `json:"object"`
}{}
if err := json.Unmarshal(data, &temp); err != nil {
return err
}
if temp.Object == "card" {
var c Card
if err := json.Unmarshal(data, &c); err != nil {
return err
}
d.Card = &c
d.BankAccount = nil
d.Object = temp.Object
} else if temp.Object == "bank_account" {
var ba BankAccount
if err := json.Unmarshal(data, &ba); err != nil {
return err
}
d.BankAccount = &ba
d.Card = nil
d.Object = temp.Object
} else {
return errors.New("Invalid object value")
}
return nil
}