forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go_fixes_bug_5452_xml_omitempty.go
95 lines (90 loc) · 3.98 KB
/
go_fixes_bug_5452_xml_omitempty.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
// +build !go1.8
package braintree
import "encoding/xml"
// The functions in this file are required because of a bug in versions of go prior to go1.8.
// The bug was reported at https://github.com/golang/go/issues/5452 and fixed in
// https://github.com/golang/go/commit/daa121167b6ce630aba00195f1c3872cda39a50c.
//
// In versions prior to go1.8 the XML encoder did not include pointer fields that were non-nil
// if the field pointed to a value that was the default value for the pointed to type.
//
// To serialize the bool false value when it is set on `VerifyCard`, we must manually control
// if it is serialized or not.
func (cco *CreditCardOptions) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if cco.VerifyCard == nil {
type excludeVerifyCard struct {
VerifyCard *bool `xml:"-"`
VenmoSDKSession string `xml:"venmo-sdk-session,omitempty"`
MakeDefault bool `xml:"make-default,omitempty"`
FailOnDuplicatePaymentMethod bool `xml:"fail-on-duplicate-payment-method,omitempty"`
VerificationMerchantAccountId string `xml:"verification-merchant-account-id,omitempty"`
UpdateExistingToken string `xml:"update-existing-token,omitempty"`
}
return e.EncodeElement(
excludeVerifyCard{
VerifyCard: cco.VerifyCard,
VenmoSDKSession: cco.VenmoSDKSession,
MakeDefault: cco.MakeDefault,
FailOnDuplicatePaymentMethod: cco.FailOnDuplicatePaymentMethod,
VerificationMerchantAccountId: cco.VerificationMerchantAccountId,
UpdateExistingToken: cco.UpdateExistingToken,
},
start,
)
} else {
type includeVerifyCard struct {
VerifyCard *bool `xml:"verify-card"`
VenmoSDKSession string `xml:"venmo-sdk-session,omitempty"`
MakeDefault bool `xml:"make-default,omitempty"`
FailOnDuplicatePaymentMethod bool `xml:"fail-on-duplicate-payment-method,omitempty"`
VerificationMerchantAccountId string `xml:"verification-merchant-account-id,omitempty"`
UpdateExistingToken string `xml:"update-existing-token,omitempty"`
}
return e.EncodeElement(
includeVerifyCard{
VerifyCard: cco.VerifyCard,
VenmoSDKSession: cco.VenmoSDKSession,
MakeDefault: cco.MakeDefault,
FailOnDuplicatePaymentMethod: cco.FailOnDuplicatePaymentMethod,
VerificationMerchantAccountId: cco.VerificationMerchantAccountId,
UpdateExistingToken: cco.UpdateExistingToken,
},
start,
)
}
}
func (pmo *PaymentMethodRequestOptions) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if pmo.VerifyCard == nil {
type excludeVerifyCard struct {
MakeDefault bool `xml:"make-default,omitempty"`
FailOnDuplicatePaymentMethod bool `xml:"fail-on-duplicate-payment-method,omitempty"`
VerifyCard *bool `xml:"-"`
VerificationMerchantAccountId string `xml:"verification-merchant-account-id,omitempty"`
}
return e.EncodeElement(
excludeVerifyCard{
MakeDefault: pmo.MakeDefault,
FailOnDuplicatePaymentMethod: pmo.FailOnDuplicatePaymentMethod,
VerifyCard: pmo.VerifyCard,
VerificationMerchantAccountId: pmo.VerificationMerchantAccountId,
},
start,
)
} else {
type includeVerifyCard struct {
MakeDefault bool `xml:"make-default,omitempty"`
FailOnDuplicatePaymentMethod bool `xml:"fail-on-duplicate-payment-method,omitempty"`
VerifyCard *bool `xml:"verify-card"`
VerificationMerchantAccountId string `xml:"verification-merchant-account-id,omitempty"`
}
return e.EncodeElement(
includeVerifyCard{
MakeDefault: pmo.MakeDefault,
FailOnDuplicatePaymentMethod: pmo.FailOnDuplicatePaymentMethod,
VerifyCard: pmo.VerifyCard,
VerificationMerchantAccountId: pmo.VerificationMerchantAccountId,
},
start,
)
}
}