forked from BoltApp/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paypal_account.go
69 lines (59 loc) · 1.88 KB
/
paypal_account.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
package braintree
import (
"encoding/xml"
"time"
)
type PayPalAccount struct {
XMLName xml.Name `xml:"paypal-account"`
CustomerId string `xml:"customer-id,omitempty"`
Token string `xml:"token,omitempty"`
Email string `xml:"email,omitempty"`
ImageURL string `xml:"image-url,omitempty"`
CreatedAt *time.Time `xml:"created-at,omitempty"`
UpdatedAt *time.Time `xml:"updated-at,omitempty"`
Subscriptions *Subscriptions `xml:"subscriptions,omitempty"`
Default bool `xml:"default,omitempty"`
Options *PayPalAccountOptions `xml:"options,omitempty"`
}
type PayPalAccounts struct {
PayPalAccount []*PayPalAccount `xml:"paypal-account"`
}
func (pp *PayPalAccounts) PaymentMethods() []PaymentMethod {
if pp == nil {
return nil
}
var paymentMethods []PaymentMethod
for _, pp := range pp.PayPalAccount {
paymentMethods = append(paymentMethods, pp)
}
return paymentMethods
}
type PayPalAccountOptions struct {
MakeDefault bool `xml:"make-default,omitempty"`
}
func (paypalAccount *PayPalAccount) GetCustomerId() string {
return paypalAccount.CustomerId
}
func (paypalAccount *PayPalAccount) GetToken() string {
return paypalAccount.Token
}
func (paypalAccount *PayPalAccount) IsDefault() bool {
return paypalAccount.Default
}
func (paypalAccount *PayPalAccount) GetImageURL() string {
return paypalAccount.ImageURL
}
// AllSubscriptions returns all subscriptions for this paypal account, or nil if none present.
func (paypalAccount *PayPalAccount) AllSubscriptions() []*Subscription {
if paypalAccount.Subscriptions != nil {
subs := paypalAccount.Subscriptions.Subscription
if len(subs) > 0 {
a := make([]*Subscription, 0, len(subs))
for _, s := range subs {
a = append(a, s)
}
return a
}
}
return nil
}