mastercard_masterpass_merchant 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +24 -0
- data/README.md +74 -0
- data/lib/mastercard_masterpass_merchant.rb +182 -0
- data/lib/mastercard_masterpass_merchant/api/checkout_api.rb +41 -0
- data/lib/mastercard_masterpass_merchant/api/decryption_api.rb +40 -0
- data/lib/mastercard_masterpass_merchant/api/express_checkout_api.rb +42 -0
- data/lib/mastercard_masterpass_merchant/api/merchant_initialization_api.rb +40 -0
- data/lib/mastercard_masterpass_merchant/api/postback_api.rb +39 -0
- data/lib/mastercard_masterpass_merchant/api/precheckout_data_api.rb +42 -0
- data/lib/mastercard_masterpass_merchant/api/session_key_signing_api.rb +40 -0
- data/lib/mastercard_masterpass_merchant/api/shopping_cart_api.rb +40 -0
- data/lib/mastercard_masterpass_merchant/models/acceptance_option.rb +177 -0
- data/lib/mastercard_masterpass_merchant/models/address.rb +243 -0
- data/lib/mastercard_masterpass_merchant/models/address_extension_point.rb +176 -0
- data/lib/mastercard_masterpass_merchant/models/authentication_options.rb +265 -0
- data/lib/mastercard_masterpass_merchant/models/base_card.rb +221 -0
- data/lib/mastercard_masterpass_merchant/models/brands.rb +165 -0
- data/lib/mastercard_masterpass_merchant/models/card.rb +244 -0
- data/lib/mastercard_masterpass_merchant/models/card_extension.rb +189 -0
- data/lib/mastercard_masterpass_merchant/models/card_type.rb +174 -0
- data/lib/mastercard_masterpass_merchant/models/card_types.rb +166 -0
- data/lib/mastercard_masterpass_merchant/models/checkout.rb +259 -0
- data/lib/mastercard_masterpass_merchant/models/checkout_dsrp.rb +210 -0
- data/lib/mastercard_masterpass_merchant/models/checkout_extension.rb +259 -0
- data/lib/mastercard_masterpass_merchant/models/contact.rb +275 -0
- data/lib/mastercard_masterpass_merchant/models/date_of_birth.rb +199 -0
- data/lib/mastercard_masterpass_merchant/models/decryption_request.rb +199 -0
- data/lib/mastercard_masterpass_merchant/models/decryption_response.rb +165 -0
- data/lib/mastercard_masterpass_merchant/models/detail.rb +176 -0
- data/lib/mastercard_masterpass_merchant/models/details.rb +176 -0
- data/lib/mastercard_masterpass_merchant/models/dsrp.rb +199 -0
- data/lib/mastercard_masterpass_merchant/models/dsrp_extension.rb +189 -0
- data/lib/mastercard_masterpass_merchant/models/dsrp_options.rb +188 -0
- data/lib/mastercard_masterpass_merchant/models/error.rb +222 -0
- data/lib/mastercard_masterpass_merchant/models/errors.rb +174 -0
- data/lib/mastercard_masterpass_merchant/models/express_checkout_request.rb +276 -0
- data/lib/mastercard_masterpass_merchant/models/express_checkout_response.rb +201 -0
- data/lib/mastercard_masterpass_merchant/models/extension_point.rb +163 -0
- data/lib/mastercard_masterpass_merchant/models/installment.rb +221 -0
- data/lib/mastercard_masterpass_merchant/models/installment_option.rb +198 -0
- data/lib/mastercard_masterpass_merchant/models/installment_options.rb +166 -0
- data/lib/mastercard_masterpass_merchant/models/installments.rb +176 -0
- data/lib/mastercard_masterpass_merchant/models/issuers.rb +165 -0
- data/lib/mastercard_masterpass_merchant/models/merchant_initialization_extension.rb +201 -0
- data/lib/mastercard_masterpass_merchant/models/merchant_initialization_request.rb +199 -0
- data/lib/mastercard_masterpass_merchant/models/merchant_initialization_response.rb +177 -0
- data/lib/mastercard_masterpass_merchant/models/merchant_initialization_response_extension.rb +165 -0
- data/lib/mastercard_masterpass_merchant/models/merchant_transaction.rb +274 -0
- data/lib/mastercard_masterpass_merchant/models/merchant_transactions.rb +176 -0
- data/lib/mastercard_masterpass_merchant/models/option.rb +197 -0
- data/lib/mastercard_masterpass_merchant/models/pairing_data_type.rb +186 -0
- data/lib/mastercard_masterpass_merchant/models/pairing_data_types.rb +188 -0
- data/lib/mastercard_masterpass_merchant/models/payment_acceptance.rb +166 -0
- data/lib/mastercard_masterpass_merchant/models/payment_acceptance_types_extension.rb +166 -0
- data/lib/mastercard_masterpass_merchant/models/payment_options_extensions.rb +178 -0
- data/lib/mastercard_masterpass_merchant/models/precheckout_card.rb +288 -0
- data/lib/mastercard_masterpass_merchant/models/precheckout_cards.rb +188 -0
- data/lib/mastercard_masterpass_merchant/models/precheckout_data.rb +259 -0
- data/lib/mastercard_masterpass_merchant/models/precheckout_data_request.rb +178 -0
- data/lib/mastercard_masterpass_merchant/models/precheckout_data_response.rb +211 -0
- data/lib/mastercard_masterpass_merchant/models/precheckout_reward_program.rb +243 -0
- data/lib/mastercard_masterpass_merchant/models/precheckout_shipping_address.rb +298 -0
- data/lib/mastercard_masterpass_merchant/models/precheckout_shipping_addresses.rb +188 -0
- data/lib/mastercard_masterpass_merchant/models/private_data.rb +177 -0
- data/lib/mastercard_masterpass_merchant/models/private_datas.rb +166 -0
- data/lib/mastercard_masterpass_merchant/models/reward_program.rb +221 -0
- data/lib/mastercard_masterpass_merchant/models/reward_programs.rb +188 -0
- data/lib/mastercard_masterpass_merchant/models/risk_decisioning.rb +178 -0
- data/lib/mastercard_masterpass_merchant/models/session_key_signing_request.rb +199 -0
- data/lib/mastercard_masterpass_merchant/models/session_key_signing_response.rb +210 -0
- data/lib/mastercard_masterpass_merchant/models/shipping_address.rb +265 -0
- data/lib/mastercard_masterpass_merchant/models/shopping_cart.rb +210 -0
- data/lib/mastercard_masterpass_merchant/models/shopping_cart_item.rb +210 -0
- data/lib/mastercard_masterpass_merchant/models/shopping_cart_request.rb +189 -0
- data/lib/mastercard_masterpass_merchant/models/shopping_cart_request_extension_point.rb +165 -0
- data/lib/mastercard_masterpass_merchant/models/shopping_cart_response.rb +177 -0
- data/lib/mastercard_masterpass_merchant/models/tokenization.rb +188 -0
- data/lib/mastercard_masterpass_merchant/models/types.rb +174 -0
- data/lib/mastercard_masterpass_merchant/models/wallet.rb +177 -0
- data/lib/mastercard_masterpass_merchant/tracker/sdk_api_tracker.rb +57 -0
- data/lib/mastercard_masterpass_merchant/version.rb +3 -0
- metadata +240 -0
@@ -0,0 +1,288 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
require_relative '../../mastercard_masterpass_merchant/models/address'
|
4
|
+
require_relative '../../mastercard_masterpass_merchant/models/base_card'
|
5
|
+
require_relative '../../mastercard_masterpass_merchant/models/card_extension'
|
6
|
+
|
7
|
+
|
8
|
+
module MastercardMasterpassMerchant
|
9
|
+
class PrecheckoutCard
|
10
|
+
include ROXML
|
11
|
+
|
12
|
+
xml_name "PrecheckoutCard"
|
13
|
+
|
14
|
+
# @!attribute last_four
|
15
|
+
# @return [String] the last four digits of card.
|
16
|
+
xml_accessor :last_four, :from =>"LastFour"
|
17
|
+
|
18
|
+
# @!attribute card_id
|
19
|
+
# @return [String] the card id.
|
20
|
+
xml_accessor :card_id, :from =>"CardId"
|
21
|
+
|
22
|
+
# @!attribute brand_id
|
23
|
+
# @return [String] the card brand id, for example, master for MasterCard.
|
24
|
+
xml_accessor :brand_id, :from =>"BrandId"
|
25
|
+
|
26
|
+
# @!attribute card_alias
|
27
|
+
# @return [String] the card alias.
|
28
|
+
xml_accessor :card_alias, :from =>"CardAlias"
|
29
|
+
|
30
|
+
# @!attribute expiry_month
|
31
|
+
# @return [Integer] the expiration month displayed on the payment card.
|
32
|
+
xml_accessor :expiry_month, :from =>"ExpiryMonth"
|
33
|
+
|
34
|
+
# @!attribute selected_as_default
|
35
|
+
# @return [BOOLEAN] the default selection.
|
36
|
+
xml_accessor :selected_as_default, :from =>"SelectedAsDefault"
|
37
|
+
|
38
|
+
# @!attribute bnb_unverified
|
39
|
+
# @return [BOOLEAN] the flag for BNB unverified.
|
40
|
+
xml_accessor :bnb_unverified, :from =>"BNBUnverified"
|
41
|
+
|
42
|
+
# @!attribute card_holder_name
|
43
|
+
# @return [String] the cardholder name.
|
44
|
+
xml_accessor :card_holder_name, :from =>"CardHolderName"
|
45
|
+
|
46
|
+
# @!attribute extension_point
|
47
|
+
# @return [CardExtension] the ExtensionPoint for future enhancement.
|
48
|
+
xml_accessor :extension_point, :from =>"ExtensionPoint",:as => CardExtension
|
49
|
+
|
50
|
+
# @!attribute billing_address
|
51
|
+
# @return [Address] the billing address for the card holder.
|
52
|
+
xml_accessor :billing_address, :from =>"BillingAddress",:as => Address
|
53
|
+
|
54
|
+
# @!attribute brand_name
|
55
|
+
# @return [String] the card brand name, for example, MasterCard.
|
56
|
+
xml_accessor :brand_name, :from =>"BrandName"
|
57
|
+
|
58
|
+
# @!attribute expiry_year
|
59
|
+
# @return [Integer] the expiration year displayed on the payment card.
|
60
|
+
xml_accessor :expiry_year, :from =>"ExpiryYear"
|
61
|
+
|
62
|
+
|
63
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
64
|
+
def self.attribute_map
|
65
|
+
{
|
66
|
+
:last_four => :LastFour ,
|
67
|
+
:card_id => :CardId ,
|
68
|
+
:brand_id => :BrandId ,
|
69
|
+
:card_alias => :CardAlias ,
|
70
|
+
:expiry_month => :ExpiryMonth ,
|
71
|
+
:selected_as_default => :SelectedAsDefault ,
|
72
|
+
:bnb_unverified => :BNBUnverified ,
|
73
|
+
:card_holder_name => :CardHolderName ,
|
74
|
+
:extension_point => :ExtensionPoint ,
|
75
|
+
:billing_address => :BillingAddress ,
|
76
|
+
:brand_name => :BrandName ,
|
77
|
+
:expiry_year => :ExpiryYear
|
78
|
+
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize(attributes = {})
|
83
|
+
return unless attributes.is_a?(Hash)
|
84
|
+
|
85
|
+
# convert string to symbol for hash key
|
86
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
87
|
+
|
88
|
+
|
89
|
+
if attributes.has_key?(:LastFour) || attributes.has_key?(:last_four)
|
90
|
+
self.last_four = attributes[:LastFour] || attributes[:last_four]
|
91
|
+
end
|
92
|
+
|
93
|
+
if attributes.has_key?(:CardId) || attributes.has_key?(:card_id)
|
94
|
+
self.card_id = attributes[:CardId] || attributes[:card_id]
|
95
|
+
end
|
96
|
+
|
97
|
+
if attributes.has_key?(:BrandId) || attributes.has_key?(:brand_id)
|
98
|
+
self.brand_id = attributes[:BrandId] || attributes[:brand_id]
|
99
|
+
end
|
100
|
+
|
101
|
+
if attributes.has_key?(:CardAlias) || attributes.has_key?(:card_alias)
|
102
|
+
self.card_alias = attributes[:CardAlias] || attributes[:card_alias]
|
103
|
+
end
|
104
|
+
|
105
|
+
if attributes.has_key?(:ExpiryMonth) || attributes.has_key?(:expiry_month)
|
106
|
+
self.expiry_month = attributes[:ExpiryMonth] || attributes[:expiry_month]
|
107
|
+
end
|
108
|
+
|
109
|
+
if attributes.has_key?(:SelectedAsDefault) || attributes.has_key?(:selected_as_default)
|
110
|
+
self.selected_as_default = attributes[:SelectedAsDefault] || attributes[:selected_as_default]
|
111
|
+
end
|
112
|
+
|
113
|
+
if attributes.has_key?(:BNBUnverified) || attributes.has_key?(:bnb_unverified)
|
114
|
+
self.bnb_unverified = attributes[:BNBUnverified] || attributes[:bnb_unverified]
|
115
|
+
end
|
116
|
+
|
117
|
+
if attributes.has_key?(:CardHolderName) || attributes.has_key?(:card_holder_name)
|
118
|
+
self.card_holder_name = attributes[:CardHolderName] || attributes[:card_holder_name]
|
119
|
+
end
|
120
|
+
|
121
|
+
if attributes.has_key?(:ExtensionPoint) || attributes.has_key?(:extension_point)
|
122
|
+
self.extension_point = attributes[:ExtensionPoint] || attributes[:extension_point]
|
123
|
+
end
|
124
|
+
|
125
|
+
if attributes.has_key?(:BillingAddress) || attributes.has_key?(:billing_address)
|
126
|
+
self.billing_address = attributes[:BillingAddress] || attributes[:billing_address]
|
127
|
+
end
|
128
|
+
|
129
|
+
if attributes.has_key?(:BrandName) || attributes.has_key?(:brand_name)
|
130
|
+
self.brand_name = attributes[:BrandName] || attributes[:brand_name]
|
131
|
+
end
|
132
|
+
|
133
|
+
if attributes.has_key?(:ExpiryYear) || attributes.has_key?(:expiry_year)
|
134
|
+
self.expiry_year = attributes[:ExpiryYear] || attributes[:expiry_year]
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
# Check equality by comparing each attribute.
|
143
|
+
def ==(o)
|
144
|
+
return true if self.equal?(o)
|
145
|
+
self.class == o.class &&
|
146
|
+
last_four == o.last_four &&
|
147
|
+
card_id == o.card_id &&
|
148
|
+
brand_id == o.brand_id &&
|
149
|
+
card_alias == o.card_alias &&
|
150
|
+
expiry_month == o.expiry_month &&
|
151
|
+
selected_as_default == o.selected_as_default &&
|
152
|
+
bnb_unverified == o.bnb_unverified &&
|
153
|
+
card_holder_name == o.card_holder_name &&
|
154
|
+
extension_point == o.extension_point &&
|
155
|
+
billing_address == o.billing_address &&
|
156
|
+
brand_name == o.brand_name &&
|
157
|
+
expiry_year == o.expiry_year
|
158
|
+
end
|
159
|
+
|
160
|
+
# @see the `==` method
|
161
|
+
def eql?(o)
|
162
|
+
self == o
|
163
|
+
end
|
164
|
+
|
165
|
+
# Calculate hash code according to all attributes.
|
166
|
+
def hash
|
167
|
+
[last_four, card_id, brand_id, card_alias, expiry_month, selected_as_default, bnb_unverified, card_holder_name, extension_point, billing_address, brand_name, expiry_year].hash
|
168
|
+
end
|
169
|
+
|
170
|
+
# build the object from hash
|
171
|
+
def build_from_hash(attributes)
|
172
|
+
return nil unless attributes.is_a?(Hash)
|
173
|
+
self.class.datatype_map.each_pair do |key, type|
|
174
|
+
if type =~ /^Array<(.*)>/i
|
175
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
176
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
177
|
+
else
|
178
|
+
#TODO show warning in debug mode
|
179
|
+
end
|
180
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
181
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
182
|
+
else
|
183
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
self
|
188
|
+
end
|
189
|
+
|
190
|
+
def _deserialize(type, value)
|
191
|
+
case type.to_sym
|
192
|
+
when :DateTime
|
193
|
+
DateTime.parse(value)
|
194
|
+
when :Date
|
195
|
+
Date.parse(value)
|
196
|
+
when :String
|
197
|
+
value.to_s
|
198
|
+
when :Integer
|
199
|
+
value.to_i
|
200
|
+
when :Float
|
201
|
+
value.to_f
|
202
|
+
when :BOOLEAN
|
203
|
+
if value =~ /^(true|t|yes|y|1)$/i
|
204
|
+
true
|
205
|
+
else
|
206
|
+
false
|
207
|
+
end
|
208
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
209
|
+
inner_type = Regexp.last_match[:inner_type]
|
210
|
+
value.map { |v| _deserialize(inner_type, v) }
|
211
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
212
|
+
k_type = Regexp.last_match[:k_type]
|
213
|
+
v_type = Regexp.last_match[:v_type]
|
214
|
+
{}.tap do |hash|
|
215
|
+
value.each do |k, v|
|
216
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
else # model
|
220
|
+
_model = MastercardMasterpassMerchant.const_get(type).new
|
221
|
+
_model.build_from_hash(value)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def to_s
|
226
|
+
to_hash.to_s
|
227
|
+
end
|
228
|
+
|
229
|
+
# to_body is an alias to to_body (backward compatibility))
|
230
|
+
def to_body
|
231
|
+
to_hash
|
232
|
+
end
|
233
|
+
|
234
|
+
# return the object in the form of hash
|
235
|
+
def to_hash
|
236
|
+
hash = {}
|
237
|
+
self.class.attribute_map.each_pair do |attr, param|
|
238
|
+
value = self.send(attr)
|
239
|
+
next if value.nil?
|
240
|
+
hash[param] = _to_hash(value)
|
241
|
+
end
|
242
|
+
hash
|
243
|
+
end
|
244
|
+
|
245
|
+
# Method to output non-array value in the form of hash
|
246
|
+
# For object, use to_hash. Otherwise, just return the value
|
247
|
+
def _to_hash(value)
|
248
|
+
if value.is_a?(Array)
|
249
|
+
value.compact.map{ |v| _to_hash(v) }
|
250
|
+
elsif value.is_a?(Hash)
|
251
|
+
{}.tap do |hash|
|
252
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
253
|
+
end
|
254
|
+
elsif value.respond_to? :to_hash
|
255
|
+
value.to_hash
|
256
|
+
else
|
257
|
+
value
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
private
|
263
|
+
def after_parse
|
264
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
265
|
+
end
|
266
|
+
|
267
|
+
# Attribute datatype mapping.
|
268
|
+
def self.datatype_map
|
269
|
+
{
|
270
|
+
:last_four => 'String',
|
271
|
+
:card_id => 'String',
|
272
|
+
:brand_id => 'String',
|
273
|
+
:card_alias => 'String',
|
274
|
+
:expiry_month => 'Integer',
|
275
|
+
:selected_as_default => 'BOOLEAN',
|
276
|
+
:bnb_unverified => 'BOOLEAN',
|
277
|
+
:card_holder_name => 'String',
|
278
|
+
:extension_point => 'CardExtension',
|
279
|
+
:billing_address => 'Address',
|
280
|
+
:brand_name => 'String',
|
281
|
+
:expiry_year => 'Integer'
|
282
|
+
|
283
|
+
}
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
require_relative '../../mastercard_masterpass_merchant/models/extension_point'
|
4
|
+
require_relative '../../mastercard_masterpass_merchant/models/precheckout_card'
|
5
|
+
|
6
|
+
|
7
|
+
module MastercardMasterpassMerchant
|
8
|
+
# This class contains different methods related to precheckout card.
|
9
|
+
class PrecheckoutCards
|
10
|
+
include ROXML
|
11
|
+
|
12
|
+
xml_name "PrecheckoutCards"
|
13
|
+
|
14
|
+
# @!attribute card
|
15
|
+
# @return [Array<PrecheckoutCard>] the card information.
|
16
|
+
xml_accessor :card, :from =>"Card", :as =>[PrecheckoutCard]
|
17
|
+
|
18
|
+
# @!attribute extension_point
|
19
|
+
# @return [ExtensionPoint] the ExtensionPoint for future enhancement.
|
20
|
+
xml_accessor :extension_point, :from =>"ExtensionPoint",:as => ExtensionPoint
|
21
|
+
|
22
|
+
|
23
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
24
|
+
def self.attribute_map
|
25
|
+
{
|
26
|
+
:card => :Card ,
|
27
|
+
:extension_point => :ExtensionPoint
|
28
|
+
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(attributes = {})
|
33
|
+
return unless attributes.is_a?(Hash)
|
34
|
+
|
35
|
+
# convert string to symbol for hash key
|
36
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
37
|
+
|
38
|
+
|
39
|
+
if attributes.has_key?(:Card) || attributes.has_key?(:card)
|
40
|
+
self.card = attributes[:Card] || attributes[:card]
|
41
|
+
end
|
42
|
+
|
43
|
+
if attributes.has_key?(:ExtensionPoint) || attributes.has_key?(:extension_point)
|
44
|
+
self.extension_point = attributes[:ExtensionPoint] || attributes[:extension_point]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Overriding setter method card
|
51
|
+
# @param value
|
52
|
+
def card=(value)
|
53
|
+
if (value.is_a?(Array))
|
54
|
+
@card = value
|
55
|
+
else
|
56
|
+
@card = [] if !@card
|
57
|
+
@card.push value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Check equality by comparing each attribute.
|
63
|
+
def ==(o)
|
64
|
+
return true if self.equal?(o)
|
65
|
+
self.class == o.class &&
|
66
|
+
card == o.card &&
|
67
|
+
extension_point == o.extension_point
|
68
|
+
end
|
69
|
+
|
70
|
+
# @see the `==` method
|
71
|
+
def eql?(o)
|
72
|
+
self == o
|
73
|
+
end
|
74
|
+
|
75
|
+
# Calculate hash code according to all attributes.
|
76
|
+
def hash
|
77
|
+
[card, extension_point].hash
|
78
|
+
end
|
79
|
+
|
80
|
+
# build the object from hash
|
81
|
+
def build_from_hash(attributes)
|
82
|
+
return nil unless attributes.is_a?(Hash)
|
83
|
+
self.class.datatype_map.each_pair do |key, type|
|
84
|
+
if type =~ /^Array<(.*)>/i
|
85
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
86
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
87
|
+
else
|
88
|
+
#TODO show warning in debug mode
|
89
|
+
end
|
90
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
91
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
92
|
+
else
|
93
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
def _deserialize(type, value)
|
101
|
+
case type.to_sym
|
102
|
+
when :DateTime
|
103
|
+
DateTime.parse(value)
|
104
|
+
when :Date
|
105
|
+
Date.parse(value)
|
106
|
+
when :String
|
107
|
+
value.to_s
|
108
|
+
when :Integer
|
109
|
+
value.to_i
|
110
|
+
when :Float
|
111
|
+
value.to_f
|
112
|
+
when :BOOLEAN
|
113
|
+
if value =~ /^(true|t|yes|y|1)$/i
|
114
|
+
true
|
115
|
+
else
|
116
|
+
false
|
117
|
+
end
|
118
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
119
|
+
inner_type = Regexp.last_match[:inner_type]
|
120
|
+
value.map { |v| _deserialize(inner_type, v) }
|
121
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
122
|
+
k_type = Regexp.last_match[:k_type]
|
123
|
+
v_type = Regexp.last_match[:v_type]
|
124
|
+
{}.tap do |hash|
|
125
|
+
value.each do |k, v|
|
126
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
else # model
|
130
|
+
_model = MastercardMasterpassMerchant.const_get(type).new
|
131
|
+
_model.build_from_hash(value)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def to_s
|
136
|
+
to_hash.to_s
|
137
|
+
end
|
138
|
+
|
139
|
+
# to_body is an alias to to_body (backward compatibility))
|
140
|
+
def to_body
|
141
|
+
to_hash
|
142
|
+
end
|
143
|
+
|
144
|
+
# return the object in the form of hash
|
145
|
+
def to_hash
|
146
|
+
hash = {}
|
147
|
+
self.class.attribute_map.each_pair do |attr, param|
|
148
|
+
value = self.send(attr)
|
149
|
+
next if value.nil?
|
150
|
+
hash[param] = _to_hash(value)
|
151
|
+
end
|
152
|
+
hash
|
153
|
+
end
|
154
|
+
|
155
|
+
# Method to output non-array value in the form of hash
|
156
|
+
# For object, use to_hash. Otherwise, just return the value
|
157
|
+
def _to_hash(value)
|
158
|
+
if value.is_a?(Array)
|
159
|
+
value.compact.map{ |v| _to_hash(v) }
|
160
|
+
elsif value.is_a?(Hash)
|
161
|
+
{}.tap do |hash|
|
162
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
163
|
+
end
|
164
|
+
elsif value.respond_to? :to_hash
|
165
|
+
value.to_hash
|
166
|
+
else
|
167
|
+
value
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
private
|
173
|
+
def after_parse
|
174
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
175
|
+
end
|
176
|
+
|
177
|
+
# Attribute datatype mapping.
|
178
|
+
def self.datatype_map
|
179
|
+
{
|
180
|
+
:card => 'Array<PrecheckoutCard>',
|
181
|
+
:extension_point => 'ExtensionPoint'
|
182
|
+
|
183
|
+
}
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
end
|