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,176 @@
1
+ require 'date'
2
+ require 'roxml'
3
+
4
+
5
+ module MastercardMasterpassMerchant
6
+ # This class contains methods to get additional address details.
7
+ class AddressExtensionPoint
8
+ include ROXML
9
+
10
+ xml_name "AddressExtensionPoint"
11
+
12
+ # @!attribute line4
13
+ # @return [String] the address line 4 used to additional address information.
14
+ xml_accessor :line4, :from =>"Line4"
15
+
16
+ # @!attribute line5
17
+ # @return [String] the address line 5 used to remaining address information.
18
+ xml_accessor :line5, :from =>"Line5"
19
+
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :line4 => :Line4 ,
25
+ :line5 => :Line5
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?(:Line4) || attributes.has_key?(:line4)
38
+ self.line4 = attributes[:Line4] || attributes[:line4]
39
+ end
40
+
41
+ if attributes.has_key?(:Line5) || attributes.has_key?(:line5)
42
+ self.line5 = attributes[:Line5] || attributes[:line5]
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
+ line4 == o.line4 &&
55
+ line5 == o.line5
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
+ [line4, line5].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 =~ /^(true|t|yes|y|1)$/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 = MastercardMasterpassMerchant.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
134
+ hash = {}
135
+ self.class.attribute_map.each_pair do |attr, param|
136
+ value = self.send(attr)
137
+ next if value.nil?
138
+ hash[param] = _to_hash(value)
139
+ end
140
+ hash
141
+ end
142
+
143
+ # Method to output non-array value in the form of hash
144
+ # For object, use to_hash. Otherwise, just return the value
145
+ def _to_hash(value)
146
+ if value.is_a?(Array)
147
+ value.compact.map{ |v| _to_hash(v) }
148
+ elsif value.is_a?(Hash)
149
+ {}.tap do |hash|
150
+ value.each { |k, v| hash[k] = _to_hash(v) }
151
+ end
152
+ elsif value.respond_to? :to_hash
153
+ value.to_hash
154
+ else
155
+ value
156
+ end
157
+ end
158
+
159
+
160
+ private
161
+ def after_parse
162
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
163
+ end
164
+
165
+ # Attribute datatype mapping.
166
+ def self.datatype_map
167
+ {
168
+ :line4 => 'String',
169
+ :line5 => 'String'
170
+
171
+ }
172
+ end
173
+ end
174
+
175
+
176
+ end
@@ -0,0 +1,265 @@
1
+ require 'date'
2
+ require 'roxml'
3
+ require_relative '../../mastercard_masterpass_merchant/models/extension_point'
4
+
5
+
6
+ module MastercardMasterpassMerchant
7
+ # This class contains methods to set different authentication options required during DSRP.
8
+ class AuthenticationOptions
9
+ include ROXML
10
+
11
+ xml_name "AuthenticationOptions"
12
+
13
+ # @!attribute authenticate_method
14
+ # @return [String] the method used to authenticate the cardholder at checkout. Valid values are MERCHANT ONLY, 3DS and No Authentication.
15
+ xml_accessor :authenticate_method, :from =>"AuthenticateMethod"
16
+
17
+ # @!attribute card_enrollment_method
18
+ # @return [String] the method by which the card was added to the wallet. Valid values are: Manual Direct Provisioned 3DS Manual NFC Tap.
19
+ xml_accessor :card_enrollment_method, :from =>"CardEnrollmentMethod"
20
+
21
+ # @!attribute c_avv
22
+ # @return [String] the (CAVV) Cardholder Authentication Verification Value generated by card issuer upon successful authentication of the cardholder. This must be passed in the authorization message.
23
+ xml_accessor :c_avv, :from =>"CAvv"
24
+
25
+ # @!attribute eci_flag
26
+ # @return [String] the Electronic commerce indicator (ECI) flag. Possible values are as follows: MasterCard: 00:No Authentication 01:Attempts (Card Issuer Liability) 02:Authenticated by ACS (Card Issuer Liability) 03:Maestro (MARP) 05:Risk Based Authentication (Issuer, not in use) 06:Risk Based Authentication (Merchant, not in use) Visa: 05:Authenticated (Card Issuer Liability) 06:Attempts (Card Issuer Liability) 07:No 3DS Authentication (Merchant Liability)
27
+ xml_accessor :eci_flag, :from =>"EciFlag"
28
+
29
+ # @!attribute master_card_assigned_id
30
+ # @return [String] the value assigned by MasterCard and represents programs associated directly with Maestro cards. This field should be supplied in the authorization request by the merchant.
31
+ xml_accessor :master_card_assigned_id, :from =>"MasterCardAssignedID"
32
+
33
+ # @!attribute pa_res_status
34
+ # @return [String] the message formatted, digitally signed, and sent from the ACS (issuer) to the MPI providing the results of the issuer's MasterCard SecureCode/Verified by Visa cardholder authentication. Possible values are: Y-The card was successfully authenticated via 3-D Secure A-signifies that either (a) the transaction was successfully authenticated via a 3-D Secure attempts transaction or (b)the cardholder was prompted to activate 3-D Secure during shopping but declined (Visa). U-Authentication results were unavailable.
35
+ xml_accessor :pa_res_status, :from =>"PaResStatus"
36
+
37
+ # @!attribute sc_enrollment_status
38
+ # @return [String] the MasterCard SecureCode Enrollment Status. Indicates if the issuer of the card supports payer authentication for this card. Possible values are as follows: Y-The card is eligible for 3-D Secure authentication. N-The card is not eligible for 3-D Secure authentication. U-Lookup of the card's 3-D Secure eligibility status was either unavailable, or the card is inapplicable (for example, prepaid cards).
39
+ xml_accessor :sc_enrollment_status, :from =>"SCEnrollmentStatus"
40
+
41
+ # @!attribute signature_verification
42
+ # @return [String] the signature verification. Possible values are as follows: Y-Indicates that the signature of the PaRes has been validated successfully and the message contents can be trusted. N-Indicates that for a variety of reasons (tampering, certificate expiration, and so on) the PaRes could not be validated, and the result should not be trusted.
43
+ xml_accessor :signature_verification, :from =>"SignatureVerification"
44
+
45
+ # @!attribute xid
46
+ # @return [String] the transaction identifier resulting from authentication processing.
47
+ xml_accessor :xid, :from =>"Xid"
48
+
49
+ # @!attribute extension_point
50
+ # @return [ExtensionPoint] the ExtensionPoint for future enhancement.
51
+ xml_accessor :extension_point, :from =>"ExtensionPoint",:as => ExtensionPoint
52
+
53
+
54
+ # Attribute mapping from ruby-style variable name to JSON key.
55
+ def self.attribute_map
56
+ {
57
+ :authenticate_method => :AuthenticateMethod ,
58
+ :card_enrollment_method => :CardEnrollmentMethod ,
59
+ :c_avv => :CAvv ,
60
+ :eci_flag => :EciFlag ,
61
+ :master_card_assigned_id => :MasterCardAssignedID ,
62
+ :pa_res_status => :PaResStatus ,
63
+ :sc_enrollment_status => :SCEnrollmentStatus ,
64
+ :signature_verification => :SignatureVerification ,
65
+ :xid => :Xid ,
66
+ :extension_point => :ExtensionPoint
67
+
68
+ }
69
+ end
70
+
71
+ def initialize(attributes = {})
72
+ return unless attributes.is_a?(Hash)
73
+
74
+ # convert string to symbol for hash key
75
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
76
+
77
+
78
+ if attributes.has_key?(:AuthenticateMethod) || attributes.has_key?(:authenticate_method)
79
+ self.authenticate_method = attributes[:AuthenticateMethod] || attributes[:authenticate_method]
80
+ end
81
+
82
+ if attributes.has_key?(:CardEnrollmentMethod) || attributes.has_key?(:card_enrollment_method)
83
+ self.card_enrollment_method = attributes[:CardEnrollmentMethod] || attributes[:card_enrollment_method]
84
+ end
85
+
86
+ if attributes.has_key?(:CAvv) || attributes.has_key?(:c_avv)
87
+ self.c_avv = attributes[:CAvv] || attributes[:c_avv]
88
+ end
89
+
90
+ if attributes.has_key?(:EciFlag) || attributes.has_key?(:eci_flag)
91
+ self.eci_flag = attributes[:EciFlag] || attributes[:eci_flag]
92
+ end
93
+
94
+ if attributes.has_key?(:MasterCardAssignedID) || attributes.has_key?(:master_card_assigned_id)
95
+ self.master_card_assigned_id = attributes[:MasterCardAssignedID] || attributes[:master_card_assigned_id]
96
+ end
97
+
98
+ if attributes.has_key?(:PaResStatus) || attributes.has_key?(:pa_res_status)
99
+ self.pa_res_status = attributes[:PaResStatus] || attributes[:pa_res_status]
100
+ end
101
+
102
+ if attributes.has_key?(:SCEnrollmentStatus) || attributes.has_key?(:sc_enrollment_status)
103
+ self.sc_enrollment_status = attributes[:SCEnrollmentStatus] || attributes[:sc_enrollment_status]
104
+ end
105
+
106
+ if attributes.has_key?(:SignatureVerification) || attributes.has_key?(:signature_verification)
107
+ self.signature_verification = attributes[:SignatureVerification] || attributes[:signature_verification]
108
+ end
109
+
110
+ if attributes.has_key?(:Xid) || attributes.has_key?(:xid)
111
+ self.xid = attributes[:Xid] || attributes[:xid]
112
+ end
113
+
114
+ if attributes.has_key?(:ExtensionPoint) || attributes.has_key?(:extension_point)
115
+ self.extension_point = attributes[:ExtensionPoint] || attributes[:extension_point]
116
+ end
117
+
118
+ end
119
+
120
+
121
+
122
+
123
+ # Check equality by comparing each attribute.
124
+ def ==(o)
125
+ return true if self.equal?(o)
126
+ self.class == o.class &&
127
+ authenticate_method == o.authenticate_method &&
128
+ card_enrollment_method == o.card_enrollment_method &&
129
+ c_avv == o.c_avv &&
130
+ eci_flag == o.eci_flag &&
131
+ master_card_assigned_id == o.master_card_assigned_id &&
132
+ pa_res_status == o.pa_res_status &&
133
+ sc_enrollment_status == o.sc_enrollment_status &&
134
+ signature_verification == o.signature_verification &&
135
+ xid == o.xid &&
136
+ extension_point == o.extension_point
137
+ end
138
+
139
+ # @see the `==` method
140
+ def eql?(o)
141
+ self == o
142
+ end
143
+
144
+ # Calculate hash code according to all attributes.
145
+ def hash
146
+ [authenticate_method, card_enrollment_method, c_avv, eci_flag, master_card_assigned_id, pa_res_status, sc_enrollment_status, signature_verification, xid, extension_point].hash
147
+ end
148
+
149
+ # build the object from hash
150
+ def build_from_hash(attributes)
151
+ return nil unless attributes.is_a?(Hash)
152
+ self.class.datatype_map.each_pair do |key, type|
153
+ if type =~ /^Array<(.*)>/i
154
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
155
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
156
+ else
157
+ #TODO show warning in debug mode
158
+ end
159
+ elsif !attributes[self.class.attribute_map[key]].nil?
160
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
161
+ else
162
+ # data not found in attributes(hash), not an issue as the data can be optional
163
+ end
164
+ end
165
+
166
+ self
167
+ end
168
+
169
+ def _deserialize(type, value)
170
+ case type.to_sym
171
+ when :DateTime
172
+ DateTime.parse(value)
173
+ when :Date
174
+ Date.parse(value)
175
+ when :String
176
+ value.to_s
177
+ when :Integer
178
+ value.to_i
179
+ when :Float
180
+ value.to_f
181
+ when :BOOLEAN
182
+ if value =~ /^(true|t|yes|y|1)$/i
183
+ true
184
+ else
185
+ false
186
+ end
187
+ when /\AArray<(?<inner_type>.+)>\z/
188
+ inner_type = Regexp.last_match[:inner_type]
189
+ value.map { |v| _deserialize(inner_type, v) }
190
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
191
+ k_type = Regexp.last_match[:k_type]
192
+ v_type = Regexp.last_match[:v_type]
193
+ {}.tap do |hash|
194
+ value.each do |k, v|
195
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
196
+ end
197
+ end
198
+ else # model
199
+ _model = MastercardMasterpassMerchant.const_get(type).new
200
+ _model.build_from_hash(value)
201
+ end
202
+ end
203
+
204
+ def to_s
205
+ to_hash.to_s
206
+ end
207
+
208
+ # to_body is an alias to to_body (backward compatibility))
209
+ def to_body
210
+ to_hash
211
+ end
212
+
213
+ # return the object in the form of hash
214
+ def to_hash
215
+ hash = {}
216
+ self.class.attribute_map.each_pair do |attr, param|
217
+ value = self.send(attr)
218
+ next if value.nil?
219
+ hash[param] = _to_hash(value)
220
+ end
221
+ hash
222
+ end
223
+
224
+ # Method to output non-array value in the form of hash
225
+ # For object, use to_hash. Otherwise, just return the value
226
+ def _to_hash(value)
227
+ if value.is_a?(Array)
228
+ value.compact.map{ |v| _to_hash(v) }
229
+ elsif value.is_a?(Hash)
230
+ {}.tap do |hash|
231
+ value.each { |k, v| hash[k] = _to_hash(v) }
232
+ end
233
+ elsif value.respond_to? :to_hash
234
+ value.to_hash
235
+ else
236
+ value
237
+ end
238
+ end
239
+
240
+
241
+ private
242
+ def after_parse
243
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
244
+ end
245
+
246
+ # Attribute datatype mapping.
247
+ def self.datatype_map
248
+ {
249
+ :authenticate_method => 'String',
250
+ :card_enrollment_method => 'String',
251
+ :c_avv => 'String',
252
+ :eci_flag => 'String',
253
+ :master_card_assigned_id => 'String',
254
+ :pa_res_status => 'String',
255
+ :sc_enrollment_status => 'String',
256
+ :signature_verification => 'String',
257
+ :xid => 'String',
258
+ :extension_point => 'ExtensionPoint'
259
+
260
+ }
261
+ end
262
+ end
263
+
264
+
265
+ end
@@ -0,0 +1,221 @@
1
+ require 'date'
2
+ require 'roxml'
3
+ require_relative '../../mastercard_masterpass_merchant/models/address'
4
+
5
+
6
+ module MastercardMasterpassMerchant
7
+ # This class contains methods to get consumer card brand information.
8
+ class BaseCard
9
+ include ROXML
10
+
11
+ xml_name "BaseCard"
12
+
13
+ # @!attribute brand_id
14
+ # @return [String] the card brand id, for example, master for MasterCard.
15
+ xml_accessor :brand_id, :from =>"BrandId"
16
+
17
+ # @!attribute brand_name
18
+ # @return [String] the card brand name, for example, MasterCard.
19
+ xml_accessor :brand_name, :from =>"BrandName"
20
+
21
+ # @!attribute billing_address
22
+ # @return [Address] the billing address for the card holder.
23
+ xml_accessor :billing_address, :from =>"BillingAddress",:as => Address
24
+
25
+ # @!attribute card_holder_name
26
+ # @return [String] the cardholder name.
27
+ xml_accessor :card_holder_name, :from =>"CardHolderName"
28
+
29
+ # @!attribute expiry_month
30
+ # @return [Integer] the expiration month displayed on the payment card.
31
+ xml_accessor :expiry_month, :from =>"ExpiryMonth"
32
+
33
+ # @!attribute expiry_year
34
+ # @return [Integer] the expiration year displayed on the payment card.
35
+ xml_accessor :expiry_year, :from =>"ExpiryYear"
36
+
37
+
38
+ # Attribute mapping from ruby-style variable name to JSON key.
39
+ def self.attribute_map
40
+ {
41
+ :brand_id => :BrandId ,
42
+ :brand_name => :BrandName ,
43
+ :billing_address => :BillingAddress ,
44
+ :card_holder_name => :CardHolderName ,
45
+ :expiry_month => :ExpiryMonth ,
46
+ :expiry_year => :ExpiryYear
47
+
48
+ }
49
+ end
50
+
51
+ def initialize(attributes = {})
52
+ return unless attributes.is_a?(Hash)
53
+
54
+ # convert string to symbol for hash key
55
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
56
+
57
+
58
+ if attributes.has_key?(:BrandId) || attributes.has_key?(:brand_id)
59
+ self.brand_id = attributes[:BrandId] || attributes[:brand_id]
60
+ end
61
+
62
+ if attributes.has_key?(:BrandName) || attributes.has_key?(:brand_name)
63
+ self.brand_name = attributes[:BrandName] || attributes[:brand_name]
64
+ end
65
+
66
+ if attributes.has_key?(:BillingAddress) || attributes.has_key?(:billing_address)
67
+ self.billing_address = attributes[:BillingAddress] || attributes[:billing_address]
68
+ end
69
+
70
+ if attributes.has_key?(:CardHolderName) || attributes.has_key?(:card_holder_name)
71
+ self.card_holder_name = attributes[:CardHolderName] || attributes[:card_holder_name]
72
+ end
73
+
74
+ if attributes.has_key?(:ExpiryMonth) || attributes.has_key?(:expiry_month)
75
+ self.expiry_month = attributes[:ExpiryMonth] || attributes[:expiry_month]
76
+ end
77
+
78
+ if attributes.has_key?(:ExpiryYear) || attributes.has_key?(:expiry_year)
79
+ self.expiry_year = attributes[:ExpiryYear] || attributes[:expiry_year]
80
+ end
81
+
82
+ end
83
+
84
+
85
+
86
+
87
+ # Check equality by comparing each attribute.
88
+ def ==(o)
89
+ return true if self.equal?(o)
90
+ self.class == o.class &&
91
+ brand_id == o.brand_id &&
92
+ brand_name == o.brand_name &&
93
+ billing_address == o.billing_address &&
94
+ card_holder_name == o.card_holder_name &&
95
+ expiry_month == o.expiry_month &&
96
+ expiry_year == o.expiry_year
97
+ end
98
+
99
+ # @see the `==` method
100
+ def eql?(o)
101
+ self == o
102
+ end
103
+
104
+ # Calculate hash code according to all attributes.
105
+ def hash
106
+ [brand_id, brand_name, billing_address, card_holder_name, expiry_month, expiry_year].hash
107
+ end
108
+
109
+ # build the object from hash
110
+ def build_from_hash(attributes)
111
+ return nil unless attributes.is_a?(Hash)
112
+ self.class.datatype_map.each_pair do |key, type|
113
+ if type =~ /^Array<(.*)>/i
114
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
115
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
116
+ else
117
+ #TODO show warning in debug mode
118
+ end
119
+ elsif !attributes[self.class.attribute_map[key]].nil?
120
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
121
+ else
122
+ # data not found in attributes(hash), not an issue as the data can be optional
123
+ end
124
+ end
125
+
126
+ self
127
+ end
128
+
129
+ def _deserialize(type, value)
130
+ case type.to_sym
131
+ when :DateTime
132
+ DateTime.parse(value)
133
+ when :Date
134
+ Date.parse(value)
135
+ when :String
136
+ value.to_s
137
+ when :Integer
138
+ value.to_i
139
+ when :Float
140
+ value.to_f
141
+ when :BOOLEAN
142
+ if value =~ /^(true|t|yes|y|1)$/i
143
+ true
144
+ else
145
+ false
146
+ end
147
+ when /\AArray<(?<inner_type>.+)>\z/
148
+ inner_type = Regexp.last_match[:inner_type]
149
+ value.map { |v| _deserialize(inner_type, v) }
150
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
151
+ k_type = Regexp.last_match[:k_type]
152
+ v_type = Regexp.last_match[:v_type]
153
+ {}.tap do |hash|
154
+ value.each do |k, v|
155
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
156
+ end
157
+ end
158
+ else # model
159
+ _model = MastercardMasterpassMerchant.const_get(type).new
160
+ _model.build_from_hash(value)
161
+ end
162
+ end
163
+
164
+ def to_s
165
+ to_hash.to_s
166
+ end
167
+
168
+ # to_body is an alias to to_body (backward compatibility))
169
+ def to_body
170
+ to_hash
171
+ end
172
+
173
+ # return the object in the form of hash
174
+ def to_hash
175
+ hash = {}
176
+ self.class.attribute_map.each_pair do |attr, param|
177
+ value = self.send(attr)
178
+ next if value.nil?
179
+ hash[param] = _to_hash(value)
180
+ end
181
+ hash
182
+ end
183
+
184
+ # Method to output non-array value in the form of hash
185
+ # For object, use to_hash. Otherwise, just return the value
186
+ def _to_hash(value)
187
+ if value.is_a?(Array)
188
+ value.compact.map{ |v| _to_hash(v) }
189
+ elsif value.is_a?(Hash)
190
+ {}.tap do |hash|
191
+ value.each { |k, v| hash[k] = _to_hash(v) }
192
+ end
193
+ elsif value.respond_to? :to_hash
194
+ value.to_hash
195
+ else
196
+ value
197
+ end
198
+ end
199
+
200
+
201
+ private
202
+ def after_parse
203
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
204
+ end
205
+
206
+ # Attribute datatype mapping.
207
+ def self.datatype_map
208
+ {
209
+ :brand_id => 'String',
210
+ :brand_name => 'String',
211
+ :billing_address => 'Address',
212
+ :card_holder_name => 'String',
213
+ :expiry_month => 'Integer',
214
+ :expiry_year => 'Integer'
215
+
216
+ }
217
+ end
218
+ end
219
+
220
+
221
+ end