mastercard_merchant_checkout 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/mastercard_merchant_checkout.rb +24 -0
  4. data/lib/mastercard_merchant_checkout/api/express_checkout_api.rb +40 -0
  5. data/lib/mastercard_merchant_checkout/api/pairing_id_api.rb +38 -0
  6. data/lib/mastercard_merchant_checkout/api/payment_data_api.rb +2 -2
  7. data/lib/mastercard_merchant_checkout/api/postback_api.rb +1 -1
  8. data/lib/mastercard_merchant_checkout/api/pre_checkout_data_api.rb +39 -0
  9. data/lib/mastercard_merchant_checkout/models/address.rb +9 -9
  10. data/lib/mastercard_merchant_checkout/models/authentication_options.rb +8 -8
  11. data/lib/mastercard_merchant_checkout/models/card.rb +22 -11
  12. data/lib/mastercard_merchant_checkout/models/contact_info.rb +211 -0
  13. data/lib/mastercard_merchant_checkout/models/cryptogram.rb +209 -0
  14. data/lib/mastercard_merchant_checkout/models/express_checkout_request.rb +244 -0
  15. data/lib/mastercard_merchant_checkout/models/pairing.rb +167 -0
  16. data/lib/mastercard_merchant_checkout/models/payment_data.rb +42 -8
  17. data/lib/mastercard_merchant_checkout/models/personal_info.rb +2 -2
  18. data/lib/mastercard_merchant_checkout/models/postback.rb +20 -9
  19. data/lib/mastercard_merchant_checkout/models/pre_checkout_card.rb +233 -0
  20. data/lib/mastercard_merchant_checkout/models/pre_checkout_data.rb +256 -0
  21. data/lib/mastercard_merchant_checkout/models/recipient_info.rb +178 -0
  22. data/lib/mastercard_merchant_checkout/models/shipping_address.rb +289 -0
  23. data/lib/mastercard_merchant_checkout/models/tokenization.rb +201 -0
  24. data/lib/mastercard_merchant_checkout/tracker/sdk_api_tracker.rb +1 -1
  25. data/lib/mastercard_merchant_checkout/version.rb +1 -1
  26. metadata +17 -5
@@ -0,0 +1,256 @@
1
+ require 'date'
2
+ require 'roxml'
3
+ require_relative '../../mastercard_merchant_checkout/models/contact_info'
4
+ require_relative '../../mastercard_merchant_checkout/models/pre_checkout_card'
5
+ require_relative '../../mastercard_merchant_checkout/models/shipping_address'
6
+
7
+
8
+ module MastercardMerchantCheckout
9
+ # This class contains different methods for different types of precheckout data like card, contact and shipping address details.
10
+ class PreCheckoutData
11
+ include ROXML
12
+
13
+ xml_name "PreCheckoutData"
14
+
15
+ # @!attribute cards
16
+ # @return [Array<PreCheckoutCard>] the cards in the paired wallet.
17
+ xml_accessor :cards, :from =>"cards", :as =>[PreCheckoutCard]
18
+
19
+ # @!attribute shipping_addresses
20
+ # @return [Array<ShippingAddress>] the shipping addresses details.
21
+ xml_accessor :shipping_addresses, :from =>"shippingAddresses", :as =>[ShippingAddress]
22
+
23
+ # @!attribute contact_info
24
+ # @return [ContactInfo] the contact info details.
25
+ xml_accessor :contact_info, :from =>"contactInfo",:as => ContactInfo
26
+
27
+ # @!attribute pre_checkout_transaction_id
28
+ # @return [String] the preCheckout transaction id.
29
+ xml_accessor :pre_checkout_transaction_id, :from =>"preCheckoutTransactionId"
30
+
31
+ # @!attribute consumer_wallet_id
32
+ # @return [String] the consumer's wallet id.
33
+ xml_accessor :consumer_wallet_id, :from =>"consumerWalletId"
34
+
35
+ # @!attribute wallet_name
36
+ # @return [String] the wallet name.
37
+ xml_accessor :wallet_name, :from =>"walletName"
38
+
39
+ # @!attribute pairing_id
40
+ # @return [String] the new pairing token id.
41
+ xml_accessor :pairing_id, :from =>"pairingId"
42
+
43
+
44
+ # Attribute mapping from ruby-style variable name to JSON key.
45
+ def self.attribute_map
46
+ {
47
+ :cards => :cards ,
48
+ :shipping_addresses => :shippingAddresses ,
49
+ :contact_info => :contactInfo ,
50
+ :pre_checkout_transaction_id => :preCheckoutTransactionId ,
51
+ :consumer_wallet_id => :consumerWalletId ,
52
+ :wallet_name => :walletName ,
53
+ :pairing_id => :pairingId
54
+
55
+ }
56
+ end
57
+
58
+ def initialize(attributes = {})
59
+ return unless attributes.is_a?(Hash)
60
+
61
+ # convert string to symbol for hash key
62
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
63
+
64
+
65
+ if attributes.has_key?(:cards)
66
+ self.cards = attributes[:cards]
67
+ end
68
+
69
+ if attributes.has_key?(:shipping_addresses)
70
+ self.shipping_addresses = attributes[:shipping_addresses]
71
+ end
72
+
73
+ if attributes.has_key?(:contact_info)
74
+ self.contact_info = attributes[:contact_info]
75
+ end
76
+
77
+ if attributes.has_key?(:pre_checkout_transaction_id)
78
+ self.pre_checkout_transaction_id = attributes[:pre_checkout_transaction_id]
79
+ end
80
+
81
+ if attributes.has_key?(:consumer_wallet_id)
82
+ self.consumer_wallet_id = attributes[:consumer_wallet_id]
83
+ end
84
+
85
+ if attributes.has_key?(:wallet_name)
86
+ self.wallet_name = attributes[:wallet_name]
87
+ end
88
+
89
+ if attributes.has_key?(:pairing_id)
90
+ self.pairing_id = attributes[:pairing_id]
91
+ end
92
+
93
+ end
94
+
95
+
96
+ # Overriding setter method cards
97
+ # @param value
98
+ def cards=(value)
99
+ if (value.is_a?(Array))
100
+ @cards = value
101
+ else
102
+ @cards = [] if !@cards
103
+ @cards.push value
104
+ end
105
+ end
106
+ # Overriding setter method shipping_addresses
107
+ # @param value
108
+ def shipping_addresses=(value)
109
+ if (value.is_a?(Array))
110
+ @shipping_addresses = value
111
+ else
112
+ @shipping_addresses = [] if !@shipping_addresses
113
+ @shipping_addresses.push value
114
+ end
115
+ end
116
+
117
+
118
+ # Check equality by comparing each attribute.
119
+ def ==(o)
120
+ return true if self.equal?(o)
121
+ self.class == o.class &&
122
+ cards == o.cards &&
123
+ shipping_addresses == o.shipping_addresses &&
124
+ contact_info == o.contact_info &&
125
+ pre_checkout_transaction_id == o.pre_checkout_transaction_id &&
126
+ consumer_wallet_id == o.consumer_wallet_id &&
127
+ wallet_name == o.wallet_name &&
128
+ pairing_id == o.pairing_id
129
+ end
130
+
131
+ # @see the `==` method
132
+ def eql?(o)
133
+ self == o
134
+ end
135
+
136
+ # Calculate hash code according to all attributes.
137
+ def hash
138
+ [cards, shipping_addresses, contact_info, pre_checkout_transaction_id, consumer_wallet_id, wallet_name, pairing_id].hash
139
+ end
140
+
141
+ # build the object from hash
142
+ def build_from_hash(attributes)
143
+ return nil unless attributes.is_a?(Hash)
144
+ self.class.datatype_map.each_pair do |key, type|
145
+ if type =~ /^Array<(.*)>/i
146
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
147
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
148
+ else
149
+ #TODO show warning in debug mode
150
+ end
151
+ elsif !attributes[self.class.attribute_map[key]].nil?
152
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
153
+ else
154
+ # data not found in attributes(hash), not an issue as the data can be optional
155
+ end
156
+ end
157
+
158
+ self
159
+ end
160
+
161
+ def _deserialize(type, value)
162
+ case type.to_sym
163
+ when :DateTime
164
+ DateTime.parse(value)
165
+ when :Date
166
+ Date.parse(value)
167
+ when :String
168
+ value.to_s
169
+ when :Integer
170
+ value.to_i
171
+ when :Float
172
+ value.to_f
173
+ when :BOOLEAN
174
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
175
+ true
176
+ else
177
+ false
178
+ end
179
+ when /\AArray<(?<inner_type>.+)>\z/
180
+ inner_type = Regexp.last_match[:inner_type]
181
+ value.map { |v| _deserialize(inner_type, v) }
182
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
183
+ k_type = Regexp.last_match[:k_type]
184
+ v_type = Regexp.last_match[:v_type]
185
+ {}.tap do |hash|
186
+ value.each do |k, v|
187
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
188
+ end
189
+ end
190
+ else # model
191
+ _model = MastercardMerchantCheckout.const_get(type).new
192
+ _model.build_from_hash(value)
193
+ end
194
+ end
195
+
196
+ def to_s
197
+ to_hash.to_s
198
+ end
199
+
200
+ # to_body is an alias to to_body (backward compatibility))
201
+ def to_body
202
+ to_hash
203
+ end
204
+
205
+ # return the object in the form of hash
206
+ def to_hash(include_root = false)
207
+ attributes_hash = {}
208
+ hash = {}
209
+ self.class.attribute_map.each_pair do |attr, param|
210
+ value = self.send(attr)
211
+ next if value.nil?
212
+ hash[param] = _to_hash(value)
213
+ end
214
+ attributes_hash = include_root ? { "PreCheckoutData" => hash } : hash
215
+ return attributes_hash
216
+ end
217
+
218
+ # Method to output non-array value in the form of hash
219
+ # For object, use to_hash. Otherwise, just return the value
220
+ def _to_hash(value)
221
+ if value.is_a?(Array)
222
+ value.compact.map{ |v| _to_hash(v) }
223
+ elsif value.is_a?(Hash)
224
+ {}.tap do |hash|
225
+ value.each { |k, v| hash[k] = _to_hash(v) }
226
+ end
227
+ elsif value.respond_to? :to_hash
228
+ value.to_hash
229
+ else
230
+ value
231
+ end
232
+ end
233
+
234
+
235
+ private
236
+ def after_parse
237
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
238
+ end
239
+
240
+ # Attribute datatype mapping.
241
+ def self.datatype_map
242
+ {
243
+ :cards => 'Array<PreCheckoutCard>',
244
+ :shipping_addresses => 'Array<ShippingAddress>',
245
+ :contact_info => 'ContactInfo',
246
+ :pre_checkout_transaction_id => 'String',
247
+ :consumer_wallet_id => 'String',
248
+ :wallet_name => 'String',
249
+ :pairing_id => 'String'
250
+
251
+ }
252
+ end
253
+ end
254
+
255
+
256
+ end
@@ -0,0 +1,178 @@
1
+ require 'date'
2
+ require 'roxml'
3
+
4
+
5
+ module MastercardMerchantCheckout
6
+ # This class contains recipient information.
7
+ class RecipientInfo
8
+ include ROXML
9
+
10
+ xml_name "RecipientInfo"
11
+
12
+ # @!attribute recipient_name
13
+ # @return [String] the recipient name.
14
+ xml_accessor :recipient_name, :from =>"recipientName"
15
+
16
+ # @!attribute recipient_phone
17
+ # @return [String] the recipient phone.
18
+ xml_accessor :recipient_phone, :from =>"recipientPhone"
19
+
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :recipient_name => :recipientName ,
25
+ :recipient_phone => :recipientPhone
26
+
27
+ }
28
+ end
29
+
30
+ def initialize(attributes = {})
31
+ return unless attributes.is_a?(Hash)
32
+
33
+ # convert string to symbol for hash key
34
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
35
+
36
+
37
+ if attributes.has_key?(:recipient_name)
38
+ self.recipient_name = attributes[:recipient_name]
39
+ end
40
+
41
+ if attributes.has_key?(:recipient_phone)
42
+ self.recipient_phone = attributes[:recipient_phone]
43
+ end
44
+
45
+ end
46
+
47
+
48
+
49
+
50
+ # Check equality by comparing each attribute.
51
+ def ==(o)
52
+ return true if self.equal?(o)
53
+ self.class == o.class &&
54
+ recipient_name == o.recipient_name &&
55
+ recipient_phone == o.recipient_phone
56
+ end
57
+
58
+ # @see the `==` method
59
+ def eql?(o)
60
+ self == o
61
+ end
62
+
63
+ # Calculate hash code according to all attributes.
64
+ def hash
65
+ [recipient_name, recipient_phone].hash
66
+ end
67
+
68
+ # build the object from hash
69
+ def build_from_hash(attributes)
70
+ return nil unless attributes.is_a?(Hash)
71
+ self.class.datatype_map.each_pair do |key, type|
72
+ if type =~ /^Array<(.*)>/i
73
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
74
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
75
+ else
76
+ #TODO show warning in debug mode
77
+ end
78
+ elsif !attributes[self.class.attribute_map[key]].nil?
79
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
80
+ else
81
+ # data not found in attributes(hash), not an issue as the data can be optional
82
+ end
83
+ end
84
+
85
+ self
86
+ end
87
+
88
+ def _deserialize(type, value)
89
+ case type.to_sym
90
+ when :DateTime
91
+ DateTime.parse(value)
92
+ when :Date
93
+ Date.parse(value)
94
+ when :String
95
+ value.to_s
96
+ when :Integer
97
+ value.to_i
98
+ when :Float
99
+ value.to_f
100
+ when :BOOLEAN
101
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
102
+ true
103
+ else
104
+ false
105
+ end
106
+ when /\AArray<(?<inner_type>.+)>\z/
107
+ inner_type = Regexp.last_match[:inner_type]
108
+ value.map { |v| _deserialize(inner_type, v) }
109
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
110
+ k_type = Regexp.last_match[:k_type]
111
+ v_type = Regexp.last_match[:v_type]
112
+ {}.tap do |hash|
113
+ value.each do |k, v|
114
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
115
+ end
116
+ end
117
+ else # model
118
+ _model = MastercardMerchantCheckout.const_get(type).new
119
+ _model.build_from_hash(value)
120
+ end
121
+ end
122
+
123
+ def to_s
124
+ to_hash.to_s
125
+ end
126
+
127
+ # to_body is an alias to to_body (backward compatibility))
128
+ def to_body
129
+ to_hash
130
+ end
131
+
132
+ # return the object in the form of hash
133
+ def to_hash(include_root = false)
134
+ attributes_hash = {}
135
+ hash = {}
136
+ self.class.attribute_map.each_pair do |attr, param|
137
+ value = self.send(attr)
138
+ next if value.nil?
139
+ hash[param] = _to_hash(value)
140
+ end
141
+ attributes_hash = include_root ? { "RecipientInfo" => hash } : hash
142
+ return attributes_hash
143
+ end
144
+
145
+ # Method to output non-array value in the form of hash
146
+ # For object, use to_hash. Otherwise, just return the value
147
+ def _to_hash(value)
148
+ if value.is_a?(Array)
149
+ value.compact.map{ |v| _to_hash(v) }
150
+ elsif value.is_a?(Hash)
151
+ {}.tap do |hash|
152
+ value.each { |k, v| hash[k] = _to_hash(v) }
153
+ end
154
+ elsif value.respond_to? :to_hash
155
+ value.to_hash
156
+ else
157
+ value
158
+ end
159
+ end
160
+
161
+
162
+ private
163
+ def after_parse
164
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
165
+ end
166
+
167
+ # Attribute datatype mapping.
168
+ def self.datatype_map
169
+ {
170
+ :recipient_name => 'String',
171
+ :recipient_phone => 'String'
172
+
173
+ }
174
+ end
175
+ end
176
+
177
+
178
+ end
@@ -0,0 +1,289 @@
1
+ require 'date'
2
+ require 'roxml'
3
+ require_relative '../../mastercard_merchant_checkout/models/recipient_info'
4
+
5
+
6
+ module MastercardMerchantCheckout
7
+ # This class contains shipping address information.
8
+ class ShippingAddress
9
+ include ROXML
10
+
11
+ xml_name "ShippingAddress"
12
+
13
+ # @!attribute recipient_info
14
+ # @return [RecipientInfo] the recipient information.
15
+ xml_accessor :recipient_info, :from =>"recipientInfo",:as => RecipientInfo
16
+
17
+ # @!attribute address_id
18
+ # @return [String] the address id.
19
+ xml_accessor :address_id, :from =>"addressId"
20
+
21
+ # @!attribute default
22
+ # @return [BOOLEAN] the default selection.
23
+ xml_accessor :default, :from =>"default"
24
+
25
+ # @!attribute city
26
+ # @return [String] the cardholder's city.
27
+ xml_accessor :city, :from =>"city"
28
+
29
+ # @!attribute country
30
+ # @return [String] the cardholder's country as defined by ISO 3166-1 alpha-2 digit country codes; for example, US is the United States, AU is Australia, CA is Canada, GB is the United Kingdom, and so on.
31
+ xml_accessor :country, :from =>"country"
32
+
33
+ # @!attribute subdivision
34
+ # @return [String] the cardholder's country's subdivision as defined by ISO 3166-1 alpha-2 digit code; for example, US-VA is Virginia, US-OH is Ohio, and so on.
35
+ xml_accessor :subdivision, :from =>"subdivision"
36
+
37
+ # @!attribute line1
38
+ # @return [String] the address in line 1 is used for the street number and the street name.
39
+ xml_accessor :line1, :from =>"line1"
40
+
41
+ # @!attribute line2
42
+ # @return [String] the address in line 2 is used for the apartment number, suite Number, and so on.
43
+ xml_accessor :line2, :from =>"line2"
44
+
45
+ # @!attribute line3
46
+ # @return [String] the address in line 3 is used to enter the remaining address information if it does not fit in lines 1 and 2.
47
+ xml_accessor :line3, :from =>"line3"
48
+
49
+ # @!attribute line4
50
+ # @return [String] the address in line 4 is used to enter the remaining address information if it does not fit in lines 1, 2 and 3.
51
+ xml_accessor :line4, :from =>"line4"
52
+
53
+ # @!attribute line5
54
+ # @return [String] the address in line 5 is used to enter the remaining address information if it does not fit in line 1,2,3 and 4.
55
+ xml_accessor :line5, :from =>"line5"
56
+
57
+ # @!attribute postal_code
58
+ # @return [String] the postal code or zip code appended to the mailing address for the purpose of sorting mail.
59
+ xml_accessor :postal_code, :from =>"postalCode"
60
+
61
+
62
+ # Attribute mapping from ruby-style variable name to JSON key.
63
+ def self.attribute_map
64
+ {
65
+ :recipient_info => :recipientInfo ,
66
+ :address_id => :addressId ,
67
+ :default => :default ,
68
+ :city => :city ,
69
+ :country => :country ,
70
+ :subdivision => :subdivision ,
71
+ :line1 => :line1 ,
72
+ :line2 => :line2 ,
73
+ :line3 => :line3 ,
74
+ :line4 => :line4 ,
75
+ :line5 => :line5 ,
76
+ :postal_code => :postalCode
77
+
78
+ }
79
+ end
80
+
81
+ def initialize(attributes = {})
82
+ return unless attributes.is_a?(Hash)
83
+
84
+ # convert string to symbol for hash key
85
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
86
+
87
+
88
+ if attributes.has_key?(:recipient_info)
89
+ self.recipient_info = attributes[:recipient_info]
90
+ end
91
+
92
+ if attributes.has_key?(:address_id)
93
+ self.address_id = attributes[:address_id]
94
+ end
95
+
96
+ if attributes.has_key?(:default)
97
+ self.default = attributes[:default]
98
+ end
99
+
100
+ if attributes.has_key?(:city)
101
+ self.city = attributes[:city]
102
+ end
103
+
104
+ if attributes.has_key?(:country)
105
+ self.country = attributes[:country]
106
+ end
107
+
108
+ if attributes.has_key?(:subdivision)
109
+ self.subdivision = attributes[:subdivision]
110
+ end
111
+
112
+ if attributes.has_key?(:line1)
113
+ self.line1 = attributes[:line1]
114
+ end
115
+
116
+ if attributes.has_key?(:line2)
117
+ self.line2 = attributes[:line2]
118
+ end
119
+
120
+ if attributes.has_key?(:line3)
121
+ self.line3 = attributes[:line3]
122
+ end
123
+
124
+ if attributes.has_key?(:line4)
125
+ self.line4 = attributes[:line4]
126
+ end
127
+
128
+ if attributes.has_key?(:line5)
129
+ self.line5 = attributes[:line5]
130
+ end
131
+
132
+ if attributes.has_key?(:postal_code)
133
+ self.postal_code = attributes[:postal_code]
134
+ end
135
+
136
+ end
137
+
138
+
139
+
140
+
141
+ # Check equality by comparing each attribute.
142
+ def ==(o)
143
+ return true if self.equal?(o)
144
+ self.class == o.class &&
145
+ recipient_info == o.recipient_info &&
146
+ address_id == o.address_id &&
147
+ default == o.default &&
148
+ city == o.city &&
149
+ country == o.country &&
150
+ subdivision == o.subdivision &&
151
+ line1 == o.line1 &&
152
+ line2 == o.line2 &&
153
+ line3 == o.line3 &&
154
+ line4 == o.line4 &&
155
+ line5 == o.line5 &&
156
+ postal_code == o.postal_code
157
+ end
158
+
159
+ # @see the `==` method
160
+ def eql?(o)
161
+ self == o
162
+ end
163
+
164
+ # Calculate hash code according to all attributes.
165
+ def hash
166
+ [recipient_info, address_id, default, city, country, subdivision, line1, line2, line3, line4, line5, postal_code].hash
167
+ end
168
+
169
+ # build the object from hash
170
+ def build_from_hash(attributes)
171
+ return nil unless attributes.is_a?(Hash)
172
+ self.class.datatype_map.each_pair do |key, type|
173
+ if type =~ /^Array<(.*)>/i
174
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
175
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
176
+ else
177
+ #TODO show warning in debug mode
178
+ end
179
+ elsif !attributes[self.class.attribute_map[key]].nil?
180
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
181
+ else
182
+ # data not found in attributes(hash), not an issue as the data can be optional
183
+ end
184
+ end
185
+
186
+ self
187
+ end
188
+
189
+ def _deserialize(type, value)
190
+ case type.to_sym
191
+ when :DateTime
192
+ DateTime.parse(value)
193
+ when :Date
194
+ Date.parse(value)
195
+ when :String
196
+ value.to_s
197
+ when :Integer
198
+ value.to_i
199
+ when :Float
200
+ value.to_f
201
+ when :BOOLEAN
202
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
203
+ true
204
+ else
205
+ false
206
+ end
207
+ when /\AArray<(?<inner_type>.+)>\z/
208
+ inner_type = Regexp.last_match[:inner_type]
209
+ value.map { |v| _deserialize(inner_type, v) }
210
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
211
+ k_type = Regexp.last_match[:k_type]
212
+ v_type = Regexp.last_match[:v_type]
213
+ {}.tap do |hash|
214
+ value.each do |k, v|
215
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
216
+ end
217
+ end
218
+ else # model
219
+ _model = MastercardMerchantCheckout.const_get(type).new
220
+ _model.build_from_hash(value)
221
+ end
222
+ end
223
+
224
+ def to_s
225
+ to_hash.to_s
226
+ end
227
+
228
+ # to_body is an alias to to_body (backward compatibility))
229
+ def to_body
230
+ to_hash
231
+ end
232
+
233
+ # return the object in the form of hash
234
+ def to_hash(include_root = false)
235
+ attributes_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
+ attributes_hash = include_root ? { "ShippingAddress" => hash } : hash
243
+ return attributes_hash
244
+ end
245
+
246
+ # Method to output non-array value in the form of hash
247
+ # For object, use to_hash. Otherwise, just return the value
248
+ def _to_hash(value)
249
+ if value.is_a?(Array)
250
+ value.compact.map{ |v| _to_hash(v) }
251
+ elsif value.is_a?(Hash)
252
+ {}.tap do |hash|
253
+ value.each { |k, v| hash[k] = _to_hash(v) }
254
+ end
255
+ elsif value.respond_to? :to_hash
256
+ value.to_hash
257
+ else
258
+ value
259
+ end
260
+ end
261
+
262
+
263
+ private
264
+ def after_parse
265
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
266
+ end
267
+
268
+ # Attribute datatype mapping.
269
+ def self.datatype_map
270
+ {
271
+ :recipient_info => 'RecipientInfo',
272
+ :address_id => 'String',
273
+ :default => 'BOOLEAN',
274
+ :city => 'String',
275
+ :country => 'String',
276
+ :subdivision => 'String',
277
+ :line1 => 'String',
278
+ :line2 => 'String',
279
+ :line3 => 'String',
280
+ :line4 => 'String',
281
+ :line5 => 'String',
282
+ :postal_code => 'String'
283
+
284
+ }
285
+ end
286
+ end
287
+
288
+
289
+ end