mastercard_masterpass_merchant 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +24 -0
  3. data/README.md +74 -0
  4. data/lib/mastercard_masterpass_merchant.rb +182 -0
  5. data/lib/mastercard_masterpass_merchant/api/checkout_api.rb +41 -0
  6. data/lib/mastercard_masterpass_merchant/api/decryption_api.rb +40 -0
  7. data/lib/mastercard_masterpass_merchant/api/express_checkout_api.rb +42 -0
  8. data/lib/mastercard_masterpass_merchant/api/merchant_initialization_api.rb +40 -0
  9. data/lib/mastercard_masterpass_merchant/api/postback_api.rb +39 -0
  10. data/lib/mastercard_masterpass_merchant/api/precheckout_data_api.rb +42 -0
  11. data/lib/mastercard_masterpass_merchant/api/session_key_signing_api.rb +40 -0
  12. data/lib/mastercard_masterpass_merchant/api/shopping_cart_api.rb +40 -0
  13. data/lib/mastercard_masterpass_merchant/models/acceptance_option.rb +177 -0
  14. data/lib/mastercard_masterpass_merchant/models/address.rb +243 -0
  15. data/lib/mastercard_masterpass_merchant/models/address_extension_point.rb +176 -0
  16. data/lib/mastercard_masterpass_merchant/models/authentication_options.rb +265 -0
  17. data/lib/mastercard_masterpass_merchant/models/base_card.rb +221 -0
  18. data/lib/mastercard_masterpass_merchant/models/brands.rb +165 -0
  19. data/lib/mastercard_masterpass_merchant/models/card.rb +244 -0
  20. data/lib/mastercard_masterpass_merchant/models/card_extension.rb +189 -0
  21. data/lib/mastercard_masterpass_merchant/models/card_type.rb +174 -0
  22. data/lib/mastercard_masterpass_merchant/models/card_types.rb +166 -0
  23. data/lib/mastercard_masterpass_merchant/models/checkout.rb +259 -0
  24. data/lib/mastercard_masterpass_merchant/models/checkout_dsrp.rb +210 -0
  25. data/lib/mastercard_masterpass_merchant/models/checkout_extension.rb +259 -0
  26. data/lib/mastercard_masterpass_merchant/models/contact.rb +275 -0
  27. data/lib/mastercard_masterpass_merchant/models/date_of_birth.rb +199 -0
  28. data/lib/mastercard_masterpass_merchant/models/decryption_request.rb +199 -0
  29. data/lib/mastercard_masterpass_merchant/models/decryption_response.rb +165 -0
  30. data/lib/mastercard_masterpass_merchant/models/detail.rb +176 -0
  31. data/lib/mastercard_masterpass_merchant/models/details.rb +176 -0
  32. data/lib/mastercard_masterpass_merchant/models/dsrp.rb +199 -0
  33. data/lib/mastercard_masterpass_merchant/models/dsrp_extension.rb +189 -0
  34. data/lib/mastercard_masterpass_merchant/models/dsrp_options.rb +188 -0
  35. data/lib/mastercard_masterpass_merchant/models/error.rb +222 -0
  36. data/lib/mastercard_masterpass_merchant/models/errors.rb +174 -0
  37. data/lib/mastercard_masterpass_merchant/models/express_checkout_request.rb +276 -0
  38. data/lib/mastercard_masterpass_merchant/models/express_checkout_response.rb +201 -0
  39. data/lib/mastercard_masterpass_merchant/models/extension_point.rb +163 -0
  40. data/lib/mastercard_masterpass_merchant/models/installment.rb +221 -0
  41. data/lib/mastercard_masterpass_merchant/models/installment_option.rb +198 -0
  42. data/lib/mastercard_masterpass_merchant/models/installment_options.rb +166 -0
  43. data/lib/mastercard_masterpass_merchant/models/installments.rb +176 -0
  44. data/lib/mastercard_masterpass_merchant/models/issuers.rb +165 -0
  45. data/lib/mastercard_masterpass_merchant/models/merchant_initialization_extension.rb +201 -0
  46. data/lib/mastercard_masterpass_merchant/models/merchant_initialization_request.rb +199 -0
  47. data/lib/mastercard_masterpass_merchant/models/merchant_initialization_response.rb +177 -0
  48. data/lib/mastercard_masterpass_merchant/models/merchant_initialization_response_extension.rb +165 -0
  49. data/lib/mastercard_masterpass_merchant/models/merchant_transaction.rb +274 -0
  50. data/lib/mastercard_masterpass_merchant/models/merchant_transactions.rb +176 -0
  51. data/lib/mastercard_masterpass_merchant/models/option.rb +197 -0
  52. data/lib/mastercard_masterpass_merchant/models/pairing_data_type.rb +186 -0
  53. data/lib/mastercard_masterpass_merchant/models/pairing_data_types.rb +188 -0
  54. data/lib/mastercard_masterpass_merchant/models/payment_acceptance.rb +166 -0
  55. data/lib/mastercard_masterpass_merchant/models/payment_acceptance_types_extension.rb +166 -0
  56. data/lib/mastercard_masterpass_merchant/models/payment_options_extensions.rb +178 -0
  57. data/lib/mastercard_masterpass_merchant/models/precheckout_card.rb +288 -0
  58. data/lib/mastercard_masterpass_merchant/models/precheckout_cards.rb +188 -0
  59. data/lib/mastercard_masterpass_merchant/models/precheckout_data.rb +259 -0
  60. data/lib/mastercard_masterpass_merchant/models/precheckout_data_request.rb +178 -0
  61. data/lib/mastercard_masterpass_merchant/models/precheckout_data_response.rb +211 -0
  62. data/lib/mastercard_masterpass_merchant/models/precheckout_reward_program.rb +243 -0
  63. data/lib/mastercard_masterpass_merchant/models/precheckout_shipping_address.rb +298 -0
  64. data/lib/mastercard_masterpass_merchant/models/precheckout_shipping_addresses.rb +188 -0
  65. data/lib/mastercard_masterpass_merchant/models/private_data.rb +177 -0
  66. data/lib/mastercard_masterpass_merchant/models/private_datas.rb +166 -0
  67. data/lib/mastercard_masterpass_merchant/models/reward_program.rb +221 -0
  68. data/lib/mastercard_masterpass_merchant/models/reward_programs.rb +188 -0
  69. data/lib/mastercard_masterpass_merchant/models/risk_decisioning.rb +178 -0
  70. data/lib/mastercard_masterpass_merchant/models/session_key_signing_request.rb +199 -0
  71. data/lib/mastercard_masterpass_merchant/models/session_key_signing_response.rb +210 -0
  72. data/lib/mastercard_masterpass_merchant/models/shipping_address.rb +265 -0
  73. data/lib/mastercard_masterpass_merchant/models/shopping_cart.rb +210 -0
  74. data/lib/mastercard_masterpass_merchant/models/shopping_cart_item.rb +210 -0
  75. data/lib/mastercard_masterpass_merchant/models/shopping_cart_request.rb +189 -0
  76. data/lib/mastercard_masterpass_merchant/models/shopping_cart_request_extension_point.rb +165 -0
  77. data/lib/mastercard_masterpass_merchant/models/shopping_cart_response.rb +177 -0
  78. data/lib/mastercard_masterpass_merchant/models/tokenization.rb +188 -0
  79. data/lib/mastercard_masterpass_merchant/models/types.rb +174 -0
  80. data/lib/mastercard_masterpass_merchant/models/wallet.rb +177 -0
  81. data/lib/mastercard_masterpass_merchant/tracker/sdk_api_tracker.rb +57 -0
  82. data/lib/mastercard_masterpass_merchant/version.rb +3 -0
  83. metadata +240 -0
@@ -0,0 +1,243 @@
1
+ require 'date'
2
+ require 'roxml'
3
+ require_relative '../../mastercard_masterpass_merchant/models/extension_point'
4
+
5
+
6
+ module MastercardMasterpassMerchant
7
+ # This class contains the methods for reward program such as reward id, reward name etc along with program expiry details.
8
+ class PrecheckoutRewardProgram
9
+ include ROXML
10
+
11
+ xml_name "PrecheckoutRewardProgram"
12
+
13
+ # @!attribute reward_number
14
+ # @return [String] the consumers reward number associated with the reward program.
15
+ xml_accessor :reward_number, :from =>"RewardNumber"
16
+
17
+ # @!attribute reward_id
18
+ # @return [String] the id associated with the reward program.
19
+ xml_accessor :reward_id, :from =>"RewardId"
20
+
21
+ # @!attribute reward_name
22
+ # @return [String] the name of reward program.
23
+ xml_accessor :reward_name, :from =>"RewardName"
24
+
25
+ # @!attribute expiry_month
26
+ # @return [Integer] the month when the reward program expires.
27
+ xml_accessor :expiry_month, :from =>"ExpiryMonth"
28
+
29
+ # @!attribute expiry_year
30
+ # @return [Integer] the year when the reward program expires.
31
+ xml_accessor :expiry_year, :from =>"ExpiryYear"
32
+
33
+ # @!attribute reward_program_id
34
+ # @return [String] the reward program id.
35
+ xml_accessor :reward_program_id, :from =>"RewardProgramId"
36
+
37
+ # @!attribute reward_logo_url
38
+ # @return [String] the reward logo url.
39
+ xml_accessor :reward_logo_url, :from =>"RewardLogoUrl"
40
+
41
+ # @!attribute extension_point
42
+ # @return [ExtensionPoint] the ExtensionPoint for future enhancement.
43
+ xml_accessor :extension_point, :from =>"ExtensionPoint",:as => ExtensionPoint
44
+
45
+
46
+ # Attribute mapping from ruby-style variable name to JSON key.
47
+ def self.attribute_map
48
+ {
49
+ :reward_number => :RewardNumber ,
50
+ :reward_id => :RewardId ,
51
+ :reward_name => :RewardName ,
52
+ :expiry_month => :ExpiryMonth ,
53
+ :expiry_year => :ExpiryYear ,
54
+ :reward_program_id => :RewardProgramId ,
55
+ :reward_logo_url => :RewardLogoUrl ,
56
+ :extension_point => :ExtensionPoint
57
+
58
+ }
59
+ end
60
+
61
+ def initialize(attributes = {})
62
+ return unless attributes.is_a?(Hash)
63
+
64
+ # convert string to symbol for hash key
65
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
66
+
67
+
68
+ if attributes.has_key?(:RewardNumber) || attributes.has_key?(:reward_number)
69
+ self.reward_number = attributes[:RewardNumber] || attributes[:reward_number]
70
+ end
71
+
72
+ if attributes.has_key?(:RewardId) || attributes.has_key?(:reward_id)
73
+ self.reward_id = attributes[:RewardId] || attributes[:reward_id]
74
+ end
75
+
76
+ if attributes.has_key?(:RewardName) || attributes.has_key?(:reward_name)
77
+ self.reward_name = attributes[:RewardName] || attributes[:reward_name]
78
+ end
79
+
80
+ if attributes.has_key?(:ExpiryMonth) || attributes.has_key?(:expiry_month)
81
+ self.expiry_month = attributes[:ExpiryMonth] || attributes[:expiry_month]
82
+ end
83
+
84
+ if attributes.has_key?(:ExpiryYear) || attributes.has_key?(:expiry_year)
85
+ self.expiry_year = attributes[:ExpiryYear] || attributes[:expiry_year]
86
+ end
87
+
88
+ if attributes.has_key?(:RewardProgramId) || attributes.has_key?(:reward_program_id)
89
+ self.reward_program_id = attributes[:RewardProgramId] || attributes[:reward_program_id]
90
+ end
91
+
92
+ if attributes.has_key?(:RewardLogoUrl) || attributes.has_key?(:reward_logo_url)
93
+ self.reward_logo_url = attributes[:RewardLogoUrl] || attributes[:reward_logo_url]
94
+ end
95
+
96
+ if attributes.has_key?(:ExtensionPoint) || attributes.has_key?(:extension_point)
97
+ self.extension_point = attributes[:ExtensionPoint] || attributes[:extension_point]
98
+ end
99
+
100
+ end
101
+
102
+
103
+
104
+
105
+ # Check equality by comparing each attribute.
106
+ def ==(o)
107
+ return true if self.equal?(o)
108
+ self.class == o.class &&
109
+ reward_number == o.reward_number &&
110
+ reward_id == o.reward_id &&
111
+ reward_name == o.reward_name &&
112
+ expiry_month == o.expiry_month &&
113
+ expiry_year == o.expiry_year &&
114
+ reward_program_id == o.reward_program_id &&
115
+ reward_logo_url == o.reward_logo_url &&
116
+ extension_point == o.extension_point
117
+ end
118
+
119
+ # @see the `==` method
120
+ def eql?(o)
121
+ self == o
122
+ end
123
+
124
+ # Calculate hash code according to all attributes.
125
+ def hash
126
+ [reward_number, reward_id, reward_name, expiry_month, expiry_year, reward_program_id, reward_logo_url, extension_point].hash
127
+ end
128
+
129
+ # build the object from hash
130
+ def build_from_hash(attributes)
131
+ return nil unless attributes.is_a?(Hash)
132
+ self.class.datatype_map.each_pair do |key, type|
133
+ if type =~ /^Array<(.*)>/i
134
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
135
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
136
+ else
137
+ #TODO show warning in debug mode
138
+ end
139
+ elsif !attributes[self.class.attribute_map[key]].nil?
140
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
141
+ else
142
+ # data not found in attributes(hash), not an issue as the data can be optional
143
+ end
144
+ end
145
+
146
+ self
147
+ end
148
+
149
+ def _deserialize(type, value)
150
+ case type.to_sym
151
+ when :DateTime
152
+ DateTime.parse(value)
153
+ when :Date
154
+ Date.parse(value)
155
+ when :String
156
+ value.to_s
157
+ when :Integer
158
+ value.to_i
159
+ when :Float
160
+ value.to_f
161
+ when :BOOLEAN
162
+ if value =~ /^(true|t|yes|y|1)$/i
163
+ true
164
+ else
165
+ false
166
+ end
167
+ when /\AArray<(?<inner_type>.+)>\z/
168
+ inner_type = Regexp.last_match[:inner_type]
169
+ value.map { |v| _deserialize(inner_type, v) }
170
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
171
+ k_type = Regexp.last_match[:k_type]
172
+ v_type = Regexp.last_match[:v_type]
173
+ {}.tap do |hash|
174
+ value.each do |k, v|
175
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
176
+ end
177
+ end
178
+ else # model
179
+ _model = MastercardMasterpassMerchant.const_get(type).new
180
+ _model.build_from_hash(value)
181
+ end
182
+ end
183
+
184
+ def to_s
185
+ to_hash.to_s
186
+ end
187
+
188
+ # to_body is an alias to to_body (backward compatibility))
189
+ def to_body
190
+ to_hash
191
+ end
192
+
193
+ # return the object in the form of hash
194
+ def to_hash
195
+ hash = {}
196
+ self.class.attribute_map.each_pair do |attr, param|
197
+ value = self.send(attr)
198
+ next if value.nil?
199
+ hash[param] = _to_hash(value)
200
+ end
201
+ hash
202
+ end
203
+
204
+ # Method to output non-array value in the form of hash
205
+ # For object, use to_hash. Otherwise, just return the value
206
+ def _to_hash(value)
207
+ if value.is_a?(Array)
208
+ value.compact.map{ |v| _to_hash(v) }
209
+ elsif value.is_a?(Hash)
210
+ {}.tap do |hash|
211
+ value.each { |k, v| hash[k] = _to_hash(v) }
212
+ end
213
+ elsif value.respond_to? :to_hash
214
+ value.to_hash
215
+ else
216
+ value
217
+ end
218
+ end
219
+
220
+
221
+ private
222
+ def after_parse
223
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
224
+ end
225
+
226
+ # Attribute datatype mapping.
227
+ def self.datatype_map
228
+ {
229
+ :reward_number => 'String',
230
+ :reward_id => 'String',
231
+ :reward_name => 'String',
232
+ :expiry_month => 'Integer',
233
+ :expiry_year => 'Integer',
234
+ :reward_program_id => 'String',
235
+ :reward_logo_url => 'String',
236
+ :extension_point => 'ExtensionPoint'
237
+
238
+ }
239
+ end
240
+ end
241
+
242
+
243
+ end
@@ -0,0 +1,298 @@
1
+ require 'date'
2
+ require 'roxml'
3
+ require_relative '../../mastercard_masterpass_merchant/models/address'
4
+ require_relative '../../mastercard_masterpass_merchant/models/address_extension_point'
5
+
6
+
7
+ module MastercardMasterpassMerchant
8
+ class PrecheckoutShippingAddress
9
+ include ROXML
10
+
11
+ xml_name "PrecheckoutShippingAddress"
12
+
13
+ # @!attribute line3
14
+ # @return [String] the address line 3 used to enter remaining address information if it does not fit in Line 1 and Line 2.
15
+ xml_accessor :line3, :from =>"Line3"
16
+
17
+ # @!attribute recipient_phone_number
18
+ # @return [String] the recipient phone number.
19
+ xml_accessor :recipient_phone_number, :from =>"RecipientPhoneNumber"
20
+
21
+ # @!attribute line2
22
+ # @return [String] the address line 2 used for Apt Number, Suite Number, and so on.
23
+ xml_accessor :line2, :from =>"Line2"
24
+
25
+ # @!attribute line1
26
+ # @return [String] the address line 1 used for Street number and Street Name.
27
+ xml_accessor :line1, :from =>"Line1"
28
+
29
+ # @!attribute country_subdivision
30
+ # @return [String] the cardholder's country subdivision. Defined by ISO 3166-1 alpha-2 digit code, for example, US-VA is Virginia, US-OH is Ohio
31
+ xml_accessor :country_subdivision, :from =>"CountrySubdivision"
32
+
33
+ # @!attribute recipient_name
34
+ # @return [String] the recipient name.
35
+ xml_accessor :recipient_name, :from =>"RecipientName"
36
+
37
+ # @!attribute country
38
+ # @return [String] the cardholder's country. Defined by ISO 3166-1 alpha-2 digit country codes, for example, US is United States, AU is Australia, CA is Canada, GB is United Kingdom, and so on.
39
+ xml_accessor :country, :from =>"Country"
40
+
41
+ # @!attribute shipping_alias
42
+ # @return [String] the shipping alias.
43
+ xml_accessor :shipping_alias, :from =>"ShippingAlias"
44
+
45
+ # @!attribute city
46
+ # @return [String] the cardholder's city.
47
+ xml_accessor :city, :from =>"City"
48
+
49
+ # @!attribute address_id
50
+ # @return [String] the address Id.
51
+ xml_accessor :address_id, :from =>"AddressId"
52
+
53
+ # @!attribute postal_code
54
+ # @return [String] the postal code or zip code appended to mailing address for the purpose of sorting mail.
55
+ xml_accessor :postal_code, :from =>"PostalCode"
56
+
57
+ # @!attribute selected_as_default
58
+ # @return [BOOLEAN] the default selection.
59
+ xml_accessor :selected_as_default, :from =>"SelectedAsDefault"
60
+
61
+ # @!attribute extension_point
62
+ # @return [AddressExtensionPoint] the AddressExtensionPoint for additional information.
63
+ xml_accessor :extension_point, :from =>"ExtensionPoint",:as => AddressExtensionPoint
64
+
65
+
66
+ # Attribute mapping from ruby-style variable name to JSON key.
67
+ def self.attribute_map
68
+ {
69
+ :line3 => :Line3 ,
70
+ :recipient_phone_number => :RecipientPhoneNumber ,
71
+ :line2 => :Line2 ,
72
+ :line1 => :Line1 ,
73
+ :country_subdivision => :CountrySubdivision ,
74
+ :recipient_name => :RecipientName ,
75
+ :country => :Country ,
76
+ :shipping_alias => :ShippingAlias ,
77
+ :city => :City ,
78
+ :address_id => :AddressId ,
79
+ :postal_code => :PostalCode ,
80
+ :selected_as_default => :SelectedAsDefault ,
81
+ :extension_point => :ExtensionPoint
82
+
83
+ }
84
+ end
85
+
86
+ def initialize(attributes = {})
87
+ return unless attributes.is_a?(Hash)
88
+
89
+ # convert string to symbol for hash key
90
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
91
+
92
+
93
+ if attributes.has_key?(:Line3) || attributes.has_key?(:line3)
94
+ self.line3 = attributes[:Line3] || attributes[:line3]
95
+ end
96
+
97
+ if attributes.has_key?(:RecipientPhoneNumber) || attributes.has_key?(:recipient_phone_number)
98
+ self.recipient_phone_number = attributes[:RecipientPhoneNumber] || attributes[:recipient_phone_number]
99
+ end
100
+
101
+ if attributes.has_key?(:Line2) || attributes.has_key?(:line2)
102
+ self.line2 = attributes[:Line2] || attributes[:line2]
103
+ end
104
+
105
+ if attributes.has_key?(:Line1) || attributes.has_key?(:line1)
106
+ self.line1 = attributes[:Line1] || attributes[:line1]
107
+ end
108
+
109
+ if attributes.has_key?(:CountrySubdivision) || attributes.has_key?(:country_subdivision)
110
+ self.country_subdivision = attributes[:CountrySubdivision] || attributes[:country_subdivision]
111
+ end
112
+
113
+ if attributes.has_key?(:RecipientName) || attributes.has_key?(:recipient_name)
114
+ self.recipient_name = attributes[:RecipientName] || attributes[:recipient_name]
115
+ end
116
+
117
+ if attributes.has_key?(:Country) || attributes.has_key?(:country)
118
+ self.country = attributes[:Country] || attributes[:country]
119
+ end
120
+
121
+ if attributes.has_key?(:ShippingAlias) || attributes.has_key?(:shipping_alias)
122
+ self.shipping_alias = attributes[:ShippingAlias] || attributes[:shipping_alias]
123
+ end
124
+
125
+ if attributes.has_key?(:City) || attributes.has_key?(:city)
126
+ self.city = attributes[:City] || attributes[:city]
127
+ end
128
+
129
+ if attributes.has_key?(:AddressId) || attributes.has_key?(:address_id)
130
+ self.address_id = attributes[:AddressId] || attributes[:address_id]
131
+ end
132
+
133
+ if attributes.has_key?(:PostalCode) || attributes.has_key?(:postal_code)
134
+ self.postal_code = attributes[:PostalCode] || attributes[:postal_code]
135
+ end
136
+
137
+ if attributes.has_key?(:SelectedAsDefault) || attributes.has_key?(:selected_as_default)
138
+ self.selected_as_default = attributes[:SelectedAsDefault] || attributes[:selected_as_default]
139
+ end
140
+
141
+ if attributes.has_key?(:ExtensionPoint) || attributes.has_key?(:extension_point)
142
+ self.extension_point = attributes[:ExtensionPoint] || attributes[:extension_point]
143
+ end
144
+
145
+ end
146
+
147
+
148
+
149
+
150
+ # Check equality by comparing each attribute.
151
+ def ==(o)
152
+ return true if self.equal?(o)
153
+ self.class == o.class &&
154
+ line3 == o.line3 &&
155
+ recipient_phone_number == o.recipient_phone_number &&
156
+ line2 == o.line2 &&
157
+ line1 == o.line1 &&
158
+ country_subdivision == o.country_subdivision &&
159
+ recipient_name == o.recipient_name &&
160
+ country == o.country &&
161
+ shipping_alias == o.shipping_alias &&
162
+ city == o.city &&
163
+ address_id == o.address_id &&
164
+ postal_code == o.postal_code &&
165
+ selected_as_default == o.selected_as_default &&
166
+ extension_point == o.extension_point
167
+ end
168
+
169
+ # @see the `==` method
170
+ def eql?(o)
171
+ self == o
172
+ end
173
+
174
+ # Calculate hash code according to all attributes.
175
+ def hash
176
+ [line3, recipient_phone_number, line2, line1, country_subdivision, recipient_name, country, shipping_alias, city, address_id, postal_code, selected_as_default, extension_point].hash
177
+ end
178
+
179
+ # build the object from hash
180
+ def build_from_hash(attributes)
181
+ return nil unless attributes.is_a?(Hash)
182
+ self.class.datatype_map.each_pair do |key, type|
183
+ if type =~ /^Array<(.*)>/i
184
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
185
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
186
+ else
187
+ #TODO show warning in debug mode
188
+ end
189
+ elsif !attributes[self.class.attribute_map[key]].nil?
190
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
191
+ else
192
+ # data not found in attributes(hash), not an issue as the data can be optional
193
+ end
194
+ end
195
+
196
+ self
197
+ end
198
+
199
+ def _deserialize(type, value)
200
+ case type.to_sym
201
+ when :DateTime
202
+ DateTime.parse(value)
203
+ when :Date
204
+ Date.parse(value)
205
+ when :String
206
+ value.to_s
207
+ when :Integer
208
+ value.to_i
209
+ when :Float
210
+ value.to_f
211
+ when :BOOLEAN
212
+ if value =~ /^(true|t|yes|y|1)$/i
213
+ true
214
+ else
215
+ false
216
+ end
217
+ when /\AArray<(?<inner_type>.+)>\z/
218
+ inner_type = Regexp.last_match[:inner_type]
219
+ value.map { |v| _deserialize(inner_type, v) }
220
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
221
+ k_type = Regexp.last_match[:k_type]
222
+ v_type = Regexp.last_match[:v_type]
223
+ {}.tap do |hash|
224
+ value.each do |k, v|
225
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
226
+ end
227
+ end
228
+ else # model
229
+ _model = MastercardMasterpassMerchant.const_get(type).new
230
+ _model.build_from_hash(value)
231
+ end
232
+ end
233
+
234
+ def to_s
235
+ to_hash.to_s
236
+ end
237
+
238
+ # to_body is an alias to to_body (backward compatibility))
239
+ def to_body
240
+ to_hash
241
+ end
242
+
243
+ # return the object in the form of hash
244
+ def to_hash
245
+ hash = {}
246
+ self.class.attribute_map.each_pair do |attr, param|
247
+ value = self.send(attr)
248
+ next if value.nil?
249
+ hash[param] = _to_hash(value)
250
+ end
251
+ hash
252
+ end
253
+
254
+ # Method to output non-array value in the form of hash
255
+ # For object, use to_hash. Otherwise, just return the value
256
+ def _to_hash(value)
257
+ if value.is_a?(Array)
258
+ value.compact.map{ |v| _to_hash(v) }
259
+ elsif value.is_a?(Hash)
260
+ {}.tap do |hash|
261
+ value.each { |k, v| hash[k] = _to_hash(v) }
262
+ end
263
+ elsif value.respond_to? :to_hash
264
+ value.to_hash
265
+ else
266
+ value
267
+ end
268
+ end
269
+
270
+
271
+ private
272
+ def after_parse
273
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
274
+ end
275
+
276
+ # Attribute datatype mapping.
277
+ def self.datatype_map
278
+ {
279
+ :line3 => 'String',
280
+ :recipient_phone_number => 'String',
281
+ :line2 => 'String',
282
+ :line1 => 'String',
283
+ :country_subdivision => 'String',
284
+ :recipient_name => 'String',
285
+ :country => 'String',
286
+ :shipping_alias => 'String',
287
+ :city => 'String',
288
+ :address_id => 'String',
289
+ :postal_code => 'String',
290
+ :selected_as_default => 'BOOLEAN',
291
+ :extension_point => 'AddressExtensionPoint'
292
+
293
+ }
294
+ end
295
+ end
296
+
297
+
298
+ end