-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodel_create_subscription_payment_request_payment_method.go
248 lines (145 loc) · 7.19 KB
/
model_create_subscription_payment_request_payment_method.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
Cashfree Payment Gateway APIs
Cashfree's Payment Gateway APIs provide developers with a streamlined pathway to integrate advanced payment processing capabilities into their applications, platforms and websites.
API version: 2023-08-01
Contact: [email protected]
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package cashfree_pg
import (
"encoding/json"
"strings"
"fmt"
)
// CreateSubscriptionPaymentRequestPaymentMethod - Payment method. Can be one of [\"upi\", \"enach\", \"pnach\", \"card\"]
type CreateSubscriptionPaymentRequestPaymentMethod struct {
CreateSubscriptionPaymentRequestCard *CreateSubscriptionPaymentRequestCard
CreateSubscriptionPaymentRequestEnack *CreateSubscriptionPaymentRequestEnack
CreateSubscriptionPaymentRequestPnach *CreateSubscriptionPaymentRequestPnach
CreateSubscriptonPaymentRequestUpi *CreateSubscriptonPaymentRequestUpi
}
// CreateSubscriptionPaymentRequestCardAsCreateSubscriptionPaymentRequestPaymentMethod is a convenience function that returns CreateSubscriptionPaymentRequestCard wrapped in CreateSubscriptionPaymentRequestPaymentMethod
func CreateSubscriptionPaymentRequestCardAsCreateSubscriptionPaymentRequestPaymentMethod(v *CreateSubscriptionPaymentRequestCard) CreateSubscriptionPaymentRequestPaymentMethod {
return CreateSubscriptionPaymentRequestPaymentMethod{
CreateSubscriptionPaymentRequestCard: v,
}
}
// CreateSubscriptionPaymentRequestEnackAsCreateSubscriptionPaymentRequestPaymentMethod is a convenience function that returns CreateSubscriptionPaymentRequestEnack wrapped in CreateSubscriptionPaymentRequestPaymentMethod
func CreateSubscriptionPaymentRequestEnackAsCreateSubscriptionPaymentRequestPaymentMethod(v *CreateSubscriptionPaymentRequestEnack) CreateSubscriptionPaymentRequestPaymentMethod {
return CreateSubscriptionPaymentRequestPaymentMethod{
CreateSubscriptionPaymentRequestEnack: v,
}
}
// CreateSubscriptionPaymentRequestPnachAsCreateSubscriptionPaymentRequestPaymentMethod is a convenience function that returns CreateSubscriptionPaymentRequestPnach wrapped in CreateSubscriptionPaymentRequestPaymentMethod
func CreateSubscriptionPaymentRequestPnachAsCreateSubscriptionPaymentRequestPaymentMethod(v *CreateSubscriptionPaymentRequestPnach) CreateSubscriptionPaymentRequestPaymentMethod {
return CreateSubscriptionPaymentRequestPaymentMethod{
CreateSubscriptionPaymentRequestPnach: v,
}
}
// CreateSubscriptonPaymentRequestUpiAsCreateSubscriptionPaymentRequestPaymentMethod is a convenience function that returns CreateSubscriptonPaymentRequestUpi wrapped in CreateSubscriptionPaymentRequestPaymentMethod
func CreateSubscriptonPaymentRequestUpiAsCreateSubscriptionPaymentRequestPaymentMethod(v *CreateSubscriptonPaymentRequestUpi) CreateSubscriptionPaymentRequestPaymentMethod {
return CreateSubscriptionPaymentRequestPaymentMethod{
CreateSubscriptonPaymentRequestUpi: v,
}
}
// Unmarshal JSON data into one of the pointers in the struct
func (dst *CreateSubscriptionPaymentRequestPaymentMethod) UnmarshalJSON(data []byte) error {
var err error
match := 0
// try to unmarshal data into CreateSubscriptionPaymentRequestCard
err = json.Unmarshal(data, &dst.CreateSubscriptionPaymentRequestCard)
if err == nil {
jsonCreateSubscriptionPaymentRequestCard, _ := json.Marshal(dst.CreateSubscriptionPaymentRequestCard)
if strings.Contains(string(jsonCreateSubscriptionPaymentRequestCard), "{}") || strings.Contains(string(jsonCreateSubscriptionPaymentRequestCard), "null") { // empty struct
dst.CreateSubscriptionPaymentRequestCard = nil
} else {
match++
}
} else {
dst.CreateSubscriptionPaymentRequestCard = nil
}
// try to unmarshal data into CreateSubscriptionPaymentRequestEnack
err = json.Unmarshal(data, &dst.CreateSubscriptionPaymentRequestEnack)
if err == nil {
jsonCreateSubscriptionPaymentRequestEnack, _ := json.Marshal(dst.CreateSubscriptionPaymentRequestEnack)
if strings.Contains(string(jsonCreateSubscriptionPaymentRequestEnack), "{}") || strings.Contains(string(jsonCreateSubscriptionPaymentRequestEnack), "null") { // empty struct
dst.CreateSubscriptionPaymentRequestEnack = nil
} else {
match++
}
} else {
dst.CreateSubscriptionPaymentRequestEnack = nil
}
// try to unmarshal data into CreateSubscriptionPaymentRequestPnach
err = json.Unmarshal(data, &dst.CreateSubscriptionPaymentRequestPnach)
if err == nil {
jsonCreateSubscriptionPaymentRequestPnach, _ := json.Marshal(dst.CreateSubscriptionPaymentRequestPnach)
if strings.Contains(string(jsonCreateSubscriptionPaymentRequestPnach), "{}") || strings.Contains(string(jsonCreateSubscriptionPaymentRequestPnach), "null") { // empty struct
dst.CreateSubscriptionPaymentRequestPnach = nil
} else {
match++
}
} else {
dst.CreateSubscriptionPaymentRequestPnach = nil
}
// try to unmarshal data into CreateSubscriptonPaymentRequestUpi
err = json.Unmarshal(data, &dst.CreateSubscriptonPaymentRequestUpi)
if err == nil {
jsonCreateSubscriptonPaymentRequestUpi, _ := json.Marshal(dst.CreateSubscriptonPaymentRequestUpi)
if strings.Contains(string(jsonCreateSubscriptonPaymentRequestUpi), "{}") || strings.Contains(string(jsonCreateSubscriptonPaymentRequestUpi), "null") { // empty struct
dst.CreateSubscriptonPaymentRequestUpi = nil
} else {
match++
}
} else {
dst.CreateSubscriptonPaymentRequestUpi = nil
}
if match > 1 { // more than 1 match
// reset to nil
dst.CreateSubscriptionPaymentRequestCard = nil
dst.CreateSubscriptionPaymentRequestEnack = nil
dst.CreateSubscriptionPaymentRequestPnach = nil
dst.CreateSubscriptonPaymentRequestUpi = nil
return fmt.Errorf("data matches more than one schema in oneOf(CreateSubscriptionPaymentRequestPaymentMethod)")
} else if match == 1 {
return nil // exactly one match
} else { // no match
return fmt.Errorf("data failed to match schemas in oneOf(CreateSubscriptionPaymentRequestPaymentMethod)")
}
}
// Marshal data from the first non-nil pointers in the struct to JSON
func (src CreateSubscriptionPaymentRequestPaymentMethod) MarshalJSON() ([]byte, error) {
if src.CreateSubscriptionPaymentRequestCard != nil {
return json.Marshal(&src.CreateSubscriptionPaymentRequestCard)
}
if src.CreateSubscriptionPaymentRequestEnack != nil {
return json.Marshal(&src.CreateSubscriptionPaymentRequestEnack)
}
if src.CreateSubscriptionPaymentRequestPnach != nil {
return json.Marshal(&src.CreateSubscriptionPaymentRequestPnach)
}
if src.CreateSubscriptonPaymentRequestUpi != nil {
return json.Marshal(&src.CreateSubscriptonPaymentRequestUpi)
}
return nil, nil // no data in oneOf schemas
}
// Get the actual instance
func (obj *CreateSubscriptionPaymentRequestPaymentMethod) GetActualInstance() (interface{}) {
if obj == nil {
return nil
}
if obj.CreateSubscriptionPaymentRequestCard != nil {
return obj.CreateSubscriptionPaymentRequestCard
}
if obj.CreateSubscriptionPaymentRequestEnack != nil {
return obj.CreateSubscriptionPaymentRequestEnack
}
if obj.CreateSubscriptionPaymentRequestPnach != nil {
return obj.CreateSubscriptionPaymentRequestPnach
}
if obj.CreateSubscriptonPaymentRequestUpi != nil {
return obj.CreateSubscriptonPaymentRequestUpi
}
// all schemas are nil
return nil
}