forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_pay_card.go
84 lines (74 loc) · 2.39 KB
/
android_pay_card.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
package braintree
import (
"encoding/xml"
"time"
)
type AndroidPayCard struct {
XMLName xml.Name `xml:"android-pay-card"`
Token string `xml:"token"`
CardType string `xml:"-"`
Last4 string `xml:"-"`
SourceCardType string `xml:"source-card-type"`
SourceCardLast4 string `xml:"source-card-last-4"`
SourceDescription string `xml:"source-description"`
VirtualCardType string `xml:"virtual-card-type"`
VirtualCardLast4 string `xml:"virtual-card-last-4"`
ExpirationMonth string `xml:"expiration-month"`
ExpirationYear string `xml:"expiration-year"`
BIN string `xml:"bin"`
GoogleTransactionID string `xml:"google-transaction-id"`
ImageURL string `xml:"image-url"`
Default bool `xml:"default"`
CustomerId string `xml:"customer-id"`
CreatedAt *time.Time `xml:"created-at"`
UpdatedAt *time.Time `xml:"updated-at"`
Subscriptions *Subscriptions `xml:"subscriptions"`
}
type AndroidPayCards struct {
AndroidPayCard []*AndroidPayCard `xml:"android-pay-card"`
}
func (a *AndroidPayCards) PaymentMethods() []PaymentMethod {
if a == nil {
return nil
}
var paymentMethods []PaymentMethod
for _, ac := range a.AndroidPayCard {
paymentMethods = append(paymentMethods, ac)
}
return paymentMethods
}
func (a *AndroidPayCard) GetCustomerId() string {
return a.CustomerId
}
func (a *AndroidPayCard) GetToken() string {
return a.Token
}
func (a *AndroidPayCard) IsDefault() bool {
return a.Default
}
func (a *AndroidPayCard) GetImageURL() string {
return a.ImageURL
}
// AllSubscriptions returns all subscriptions for this paypal account, or nil if none present.
func (a *AndroidPayCard) AllSubscriptions() []*Subscription {
if a.Subscriptions != nil {
subs := a.Subscriptions.Subscription
if len(subs) > 0 {
a := make([]*Subscription, 0, len(subs))
for _, s := range subs {
a = append(a, s)
}
return a
}
}
return nil
}
func (a *AndroidPayCard) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type typeWithNoFunctions AndroidPayCard
if err := d.DecodeElement((*typeWithNoFunctions)(a), &start); err != nil {
return err
}
a.CardType = a.VirtualCardType
a.Last4 = a.VirtualCardLast4
return nil
}