mastercard_psp_payment 1.0.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.
- checksums.yaml +7 -0
- data/LICENSE.txt +24 -0
- data/README.md +53 -0
- data/lib/mastercard_psp_payment/api/psp_payment_data_api.rb +36 -0
- data/lib/mastercard_psp_payment/models/address.rb +255 -0
- data/lib/mastercard_psp_payment/models/authentication_options.rb +255 -0
- data/lib/mastercard_psp_payment/models/card.rb +245 -0
- data/lib/mastercard_psp_payment/models/cryptogram.rb +209 -0
- data/lib/mastercard_psp_payment/models/payment_data.rb +203 -0
- data/lib/mastercard_psp_payment/models/tokenization.rb +212 -0
- data/lib/mastercard_psp_payment/tracker/sdk_api_tracker.rb +57 -0
- data/lib/mastercard_psp_payment/version.rb +3 -0
- data/lib/mastercard_psp_payment.rb +30 -0
- metadata +172 -0
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
require_relative '../../mastercard_psp_payment/models/address'
|
4
|
+
|
5
|
+
|
6
|
+
module MastercardPspPayment
|
7
|
+
# This class contains Card details for the available cards.
|
8
|
+
class Card
|
9
|
+
include ROXML
|
10
|
+
|
11
|
+
xml_name "Card"
|
12
|
+
|
13
|
+
# @!attribute brand_id
|
14
|
+
# @return [String] the card's brand id; for example, master for Mastercard.
|
15
|
+
xml_accessor :brand_id, :from =>"brandId"
|
16
|
+
|
17
|
+
# @!attribute brand_name
|
18
|
+
# @return [String] the card's brand name; for example, Mastercard.
|
19
|
+
xml_accessor :brand_name, :from =>"brandName"
|
20
|
+
|
21
|
+
# @!attribute account_number
|
22
|
+
# @return [String] the PAN.
|
23
|
+
xml_accessor :account_number, :from =>"accountNumber"
|
24
|
+
|
25
|
+
# @!attribute card_holder_name
|
26
|
+
# @return [String] the cardholder's 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
|
+
# @!attribute billing_address
|
38
|
+
# @return [Address] the billing details.
|
39
|
+
xml_accessor :billing_address, :from =>"billingAddress",:as => Address
|
40
|
+
|
41
|
+
# @!attribute last_four
|
42
|
+
# @return [String] the last four digit of actual card number.
|
43
|
+
xml_accessor :last_four, :from =>"lastFour"
|
44
|
+
|
45
|
+
|
46
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
47
|
+
def self.attribute_map
|
48
|
+
{
|
49
|
+
:brand_id => :brandId ,
|
50
|
+
:brand_name => :brandName ,
|
51
|
+
:account_number => :accountNumber ,
|
52
|
+
:card_holder_name => :cardHolderName ,
|
53
|
+
:expiry_month => :expiryMonth ,
|
54
|
+
:expiry_year => :expiryYear ,
|
55
|
+
:billing_address => :billingAddress ,
|
56
|
+
:last_four => :lastFour
|
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?(:brand_id)
|
69
|
+
self.brand_id = attributes[:brand_id]
|
70
|
+
end
|
71
|
+
|
72
|
+
if attributes.has_key?(:brand_name)
|
73
|
+
self.brand_name = attributes[:brand_name]
|
74
|
+
end
|
75
|
+
|
76
|
+
if attributes.has_key?(:account_number)
|
77
|
+
self.account_number = attributes[:account_number]
|
78
|
+
end
|
79
|
+
|
80
|
+
if attributes.has_key?(:card_holder_name)
|
81
|
+
self.card_holder_name = attributes[:card_holder_name]
|
82
|
+
end
|
83
|
+
|
84
|
+
if attributes.has_key?(:expiry_month)
|
85
|
+
self.expiry_month = attributes[:expiry_month]
|
86
|
+
end
|
87
|
+
|
88
|
+
if attributes.has_key?(:expiry_year)
|
89
|
+
self.expiry_year = attributes[:expiry_year]
|
90
|
+
end
|
91
|
+
|
92
|
+
if attributes.has_key?(:billing_address)
|
93
|
+
self.billing_address = attributes[:billing_address]
|
94
|
+
end
|
95
|
+
|
96
|
+
if attributes.has_key?(:last_four)
|
97
|
+
self.last_four = attributes[:last_four]
|
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
|
+
brand_id == o.brand_id &&
|
110
|
+
brand_name == o.brand_name &&
|
111
|
+
account_number == o.account_number &&
|
112
|
+
card_holder_name == o.card_holder_name &&
|
113
|
+
expiry_month == o.expiry_month &&
|
114
|
+
expiry_year == o.expiry_year &&
|
115
|
+
billing_address == o.billing_address &&
|
116
|
+
last_four == o.last_four
|
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
|
+
[brand_id, brand_name, account_number, card_holder_name, expiry_month, expiry_year, billing_address, last_four].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.to_s =~ /\A(true|t|yes|y|1)\z/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 = MastercardPspPayment.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(include_root = false)
|
195
|
+
attributes_hash = {}
|
196
|
+
hash = {}
|
197
|
+
self.class.attribute_map.each_pair do |attr, param|
|
198
|
+
value = self.send(attr)
|
199
|
+
next if value.nil?
|
200
|
+
hash[param] = _to_hash(value)
|
201
|
+
end
|
202
|
+
attributes_hash = include_root ? { "Card" => hash } : hash
|
203
|
+
return attributes_hash
|
204
|
+
end
|
205
|
+
|
206
|
+
# Method to output non-array value in the form of hash
|
207
|
+
# For object, use to_hash. Otherwise, just return the value
|
208
|
+
def _to_hash(value)
|
209
|
+
if value.is_a?(Array)
|
210
|
+
value.compact.map{ |v| _to_hash(v) }
|
211
|
+
elsif value.is_a?(Hash)
|
212
|
+
{}.tap do |hash|
|
213
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
214
|
+
end
|
215
|
+
elsif value.respond_to? :to_hash
|
216
|
+
value.to_hash
|
217
|
+
else
|
218
|
+
value
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
private
|
224
|
+
def after_parse
|
225
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
226
|
+
end
|
227
|
+
|
228
|
+
# Attribute datatype mapping.
|
229
|
+
def self.datatype_map
|
230
|
+
{
|
231
|
+
:brand_id => 'String',
|
232
|
+
:brand_name => 'String',
|
233
|
+
:account_number => 'String',
|
234
|
+
:card_holder_name => 'String',
|
235
|
+
:expiry_month => 'Integer',
|
236
|
+
:expiry_year => 'Integer',
|
237
|
+
:billing_address => 'Address',
|
238
|
+
:last_four => 'String'
|
239
|
+
|
240
|
+
}
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
|
4
|
+
|
5
|
+
module MastercardPspPayment
|
6
|
+
# This class contains the cryptogram generated by the consumer's Masterpass wallet.
|
7
|
+
class Cryptogram
|
8
|
+
include ROXML
|
9
|
+
|
10
|
+
xml_name "Cryptogram"
|
11
|
+
|
12
|
+
# @!attribute crypto_value
|
13
|
+
# @return [String] the cryptogram generated by the consumer's Masterpass wallet.
|
14
|
+
xml_accessor :crypto_value, :from =>"cryptoValue"
|
15
|
+
|
16
|
+
# @!attribute crypto_type
|
17
|
+
# @return [String] the type of cryptogram generated by the consumers Masterpass wallet. Masterpass passes the most secure selection (ICC) if the merchant or service provider has indicated they can accept both types (UCAF, ICC).
|
18
|
+
xml_accessor :crypto_type, :from =>"cryptoType"
|
19
|
+
|
20
|
+
# @!attribute unpredictable_number
|
21
|
+
# @return [String] the unpredictable number. EMV quality random number generated by the merchant, service provider, or, if null, by Masterpass and Base64 encoded.
|
22
|
+
xml_accessor :unpredictable_number, :from =>"unpredictableNumber"
|
23
|
+
|
24
|
+
# @!attribute eci
|
25
|
+
# @return [String] the electronic commerce indicator (ECI) value (DE 48 SE 42 position 3). Present only when crypto type is UCAF. For Mastercard brand cards, value is: 02 Authenticated by ACS (Card Issuer Liability)
|
26
|
+
xml_accessor :eci, :from =>"eci"
|
27
|
+
|
28
|
+
|
29
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
30
|
+
def self.attribute_map
|
31
|
+
{
|
32
|
+
:crypto_value => :cryptoValue ,
|
33
|
+
:crypto_type => :cryptoType ,
|
34
|
+
:unpredictable_number => :unpredictableNumber ,
|
35
|
+
:eci => :eci
|
36
|
+
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(attributes = {})
|
41
|
+
return unless attributes.is_a?(Hash)
|
42
|
+
|
43
|
+
# convert string to symbol for hash key
|
44
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
45
|
+
|
46
|
+
|
47
|
+
if attributes.has_key?(:crypto_value)
|
48
|
+
self.crypto_value = attributes[:crypto_value]
|
49
|
+
end
|
50
|
+
|
51
|
+
if attributes.has_key?(:crypto_type)
|
52
|
+
self.crypto_type = attributes[:crypto_type]
|
53
|
+
end
|
54
|
+
|
55
|
+
if attributes.has_key?(:unpredictable_number)
|
56
|
+
self.unpredictable_number = attributes[:unpredictable_number]
|
57
|
+
end
|
58
|
+
|
59
|
+
if attributes.has_key?(:eci)
|
60
|
+
self.eci = attributes[:eci]
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
# Custom attribute writer method checking allowed values (enum).
|
69
|
+
def crypto_type=(crypto_type)
|
70
|
+
allowed_values = ["ICC", "UCAF", "TAVV"]
|
71
|
+
if crypto_type && !allowed_values.include?(crypto_type)
|
72
|
+
fail "invalid value for 'crypto_type', must be one of #{allowed_values}"
|
73
|
+
end
|
74
|
+
@crypto_type = crypto_type
|
75
|
+
end
|
76
|
+
|
77
|
+
# Check equality by comparing each attribute.
|
78
|
+
def ==(o)
|
79
|
+
return true if self.equal?(o)
|
80
|
+
self.class == o.class &&
|
81
|
+
crypto_value == o.crypto_value &&
|
82
|
+
crypto_type == o.crypto_type &&
|
83
|
+
unpredictable_number == o.unpredictable_number &&
|
84
|
+
eci == o.eci
|
85
|
+
end
|
86
|
+
|
87
|
+
# @see the `==` method
|
88
|
+
def eql?(o)
|
89
|
+
self == o
|
90
|
+
end
|
91
|
+
|
92
|
+
# Calculate hash code according to all attributes.
|
93
|
+
def hash
|
94
|
+
[crypto_value, crypto_type, unpredictable_number, eci].hash
|
95
|
+
end
|
96
|
+
|
97
|
+
# build the object from hash
|
98
|
+
def build_from_hash(attributes)
|
99
|
+
return nil unless attributes.is_a?(Hash)
|
100
|
+
self.class.datatype_map.each_pair do |key, type|
|
101
|
+
if type =~ /^Array<(.*)>/i
|
102
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
103
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
104
|
+
else
|
105
|
+
#TODO show warning in debug mode
|
106
|
+
end
|
107
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
108
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
109
|
+
else
|
110
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def _deserialize(type, value)
|
118
|
+
case type.to_sym
|
119
|
+
when :DateTime
|
120
|
+
DateTime.parse(value)
|
121
|
+
when :Date
|
122
|
+
Date.parse(value)
|
123
|
+
when :String
|
124
|
+
value.to_s
|
125
|
+
when :Integer
|
126
|
+
value.to_i
|
127
|
+
when :Float
|
128
|
+
value.to_f
|
129
|
+
when :BOOLEAN
|
130
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
131
|
+
true
|
132
|
+
else
|
133
|
+
false
|
134
|
+
end
|
135
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
136
|
+
inner_type = Regexp.last_match[:inner_type]
|
137
|
+
value.map { |v| _deserialize(inner_type, v) }
|
138
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
139
|
+
k_type = Regexp.last_match[:k_type]
|
140
|
+
v_type = Regexp.last_match[:v_type]
|
141
|
+
{}.tap do |hash|
|
142
|
+
value.each do |k, v|
|
143
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
else # model
|
147
|
+
_model = MastercardPspPayment.const_get(type).new
|
148
|
+
_model.build_from_hash(value)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def to_s
|
153
|
+
to_hash.to_s
|
154
|
+
end
|
155
|
+
|
156
|
+
# to_body is an alias to to_body (backward compatibility))
|
157
|
+
def to_body
|
158
|
+
to_hash
|
159
|
+
end
|
160
|
+
|
161
|
+
# return the object in the form of hash
|
162
|
+
def to_hash(include_root = false)
|
163
|
+
attributes_hash = {}
|
164
|
+
hash = {}
|
165
|
+
self.class.attribute_map.each_pair do |attr, param|
|
166
|
+
value = self.send(attr)
|
167
|
+
next if value.nil?
|
168
|
+
hash[param] = _to_hash(value)
|
169
|
+
end
|
170
|
+
attributes_hash = include_root ? { "Cryptogram" => hash } : hash
|
171
|
+
return attributes_hash
|
172
|
+
end
|
173
|
+
|
174
|
+
# Method to output non-array value in the form of hash
|
175
|
+
# For object, use to_hash. Otherwise, just return the value
|
176
|
+
def _to_hash(value)
|
177
|
+
if value.is_a?(Array)
|
178
|
+
value.compact.map{ |v| _to_hash(v) }
|
179
|
+
elsif value.is_a?(Hash)
|
180
|
+
{}.tap do |hash|
|
181
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
182
|
+
end
|
183
|
+
elsif value.respond_to? :to_hash
|
184
|
+
value.to_hash
|
185
|
+
else
|
186
|
+
value
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
private
|
192
|
+
def after_parse
|
193
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
194
|
+
end
|
195
|
+
|
196
|
+
# Attribute datatype mapping.
|
197
|
+
def self.datatype_map
|
198
|
+
{
|
199
|
+
:crypto_value => 'String',
|
200
|
+
:crypto_type => 'String',
|
201
|
+
:unpredictable_number => 'String',
|
202
|
+
:eci => 'String'
|
203
|
+
|
204
|
+
}
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
require_relative '../../mastercard_psp_payment/models/authentication_options'
|
4
|
+
require_relative '../../mastercard_psp_payment/models/card'
|
5
|
+
require_relative '../../mastercard_psp_payment/models/tokenization'
|
6
|
+
|
7
|
+
|
8
|
+
module MastercardPspPayment
|
9
|
+
# This class contains various methods for to set different merchant initialization request parameters required for Merchant Initialization Service.
|
10
|
+
class PaymentData
|
11
|
+
include ROXML
|
12
|
+
|
13
|
+
xml_name "PaymentData"
|
14
|
+
|
15
|
+
# @!attribute card
|
16
|
+
# @return [Card] the card details.
|
17
|
+
xml_accessor :card, :from =>"card",:as => Card
|
18
|
+
|
19
|
+
# @!attribute tokenization
|
20
|
+
# @return [Tokenization] the tokenized card information.
|
21
|
+
xml_accessor :tokenization, :from =>"tokenization",:as => Tokenization
|
22
|
+
|
23
|
+
# @!attribute wallet_id
|
24
|
+
# @return [String] the value which helps to identify origin wallet.
|
25
|
+
xml_accessor :wallet_id, :from =>"walletId"
|
26
|
+
|
27
|
+
# @!attribute authentication_options
|
28
|
+
# @return [AuthenticationOptions] the tokenized card information.
|
29
|
+
xml_accessor :authentication_options, :from =>"authenticationOptions",:as => AuthenticationOptions
|
30
|
+
|
31
|
+
|
32
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
33
|
+
def self.attribute_map
|
34
|
+
{
|
35
|
+
:card => :card ,
|
36
|
+
:tokenization => :tokenization ,
|
37
|
+
:wallet_id => :walletId ,
|
38
|
+
:authentication_options => :authenticationOptions
|
39
|
+
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize(attributes = {})
|
44
|
+
return unless attributes.is_a?(Hash)
|
45
|
+
|
46
|
+
# convert string to symbol for hash key
|
47
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
48
|
+
|
49
|
+
|
50
|
+
if attributes.has_key?(:card)
|
51
|
+
self.card = attributes[:card]
|
52
|
+
end
|
53
|
+
|
54
|
+
if attributes.has_key?(:tokenization)
|
55
|
+
self.tokenization = attributes[:tokenization]
|
56
|
+
end
|
57
|
+
|
58
|
+
if attributes.has_key?(:wallet_id)
|
59
|
+
self.wallet_id = attributes[:wallet_id]
|
60
|
+
end
|
61
|
+
|
62
|
+
if attributes.has_key?(:authentication_options)
|
63
|
+
self.authentication_options = attributes[:authentication_options]
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
# Check equality by comparing each attribute.
|
72
|
+
def ==(o)
|
73
|
+
return true if self.equal?(o)
|
74
|
+
self.class == o.class &&
|
75
|
+
card == o.card &&
|
76
|
+
tokenization == o.tokenization &&
|
77
|
+
wallet_id == o.wallet_id &&
|
78
|
+
authentication_options == o.authentication_options
|
79
|
+
end
|
80
|
+
|
81
|
+
# @see the `==` method
|
82
|
+
def eql?(o)
|
83
|
+
self == o
|
84
|
+
end
|
85
|
+
|
86
|
+
# Calculate hash code according to all attributes.
|
87
|
+
def hash
|
88
|
+
[card, tokenization, wallet_id, authentication_options].hash
|
89
|
+
end
|
90
|
+
|
91
|
+
# build the object from hash
|
92
|
+
def build_from_hash(attributes)
|
93
|
+
return nil unless attributes.is_a?(Hash)
|
94
|
+
self.class.datatype_map.each_pair do |key, type|
|
95
|
+
if type =~ /^Array<(.*)>/i
|
96
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
97
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
98
|
+
else
|
99
|
+
#TODO show warning in debug mode
|
100
|
+
end
|
101
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
102
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
103
|
+
else
|
104
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
self
|
109
|
+
end
|
110
|
+
|
111
|
+
def _deserialize(type, value)
|
112
|
+
case type.to_sym
|
113
|
+
when :DateTime
|
114
|
+
DateTime.parse(value)
|
115
|
+
when :Date
|
116
|
+
Date.parse(value)
|
117
|
+
when :String
|
118
|
+
value.to_s
|
119
|
+
when :Integer
|
120
|
+
value.to_i
|
121
|
+
when :Float
|
122
|
+
value.to_f
|
123
|
+
when :BOOLEAN
|
124
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
125
|
+
true
|
126
|
+
else
|
127
|
+
false
|
128
|
+
end
|
129
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
130
|
+
inner_type = Regexp.last_match[:inner_type]
|
131
|
+
value.map { |v| _deserialize(inner_type, v) }
|
132
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
133
|
+
k_type = Regexp.last_match[:k_type]
|
134
|
+
v_type = Regexp.last_match[:v_type]
|
135
|
+
{}.tap do |hash|
|
136
|
+
value.each do |k, v|
|
137
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
else # model
|
141
|
+
_model = MastercardPspPayment.const_get(type).new
|
142
|
+
_model.build_from_hash(value)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def to_s
|
147
|
+
to_hash.to_s
|
148
|
+
end
|
149
|
+
|
150
|
+
# to_body is an alias to to_body (backward compatibility))
|
151
|
+
def to_body
|
152
|
+
to_hash
|
153
|
+
end
|
154
|
+
|
155
|
+
# return the object in the form of hash
|
156
|
+
def to_hash(include_root = false)
|
157
|
+
attributes_hash = {}
|
158
|
+
hash = {}
|
159
|
+
self.class.attribute_map.each_pair do |attr, param|
|
160
|
+
value = self.send(attr)
|
161
|
+
next if value.nil?
|
162
|
+
hash[param] = _to_hash(value)
|
163
|
+
end
|
164
|
+
attributes_hash = include_root ? { "PaymentData" => hash } : hash
|
165
|
+
return attributes_hash
|
166
|
+
end
|
167
|
+
|
168
|
+
# Method to output non-array value in the form of hash
|
169
|
+
# For object, use to_hash. Otherwise, just return the value
|
170
|
+
def _to_hash(value)
|
171
|
+
if value.is_a?(Array)
|
172
|
+
value.compact.map{ |v| _to_hash(v) }
|
173
|
+
elsif value.is_a?(Hash)
|
174
|
+
{}.tap do |hash|
|
175
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
176
|
+
end
|
177
|
+
elsif value.respond_to? :to_hash
|
178
|
+
value.to_hash
|
179
|
+
else
|
180
|
+
value
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
private
|
186
|
+
def after_parse
|
187
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
188
|
+
end
|
189
|
+
|
190
|
+
# Attribute datatype mapping.
|
191
|
+
def self.datatype_map
|
192
|
+
{
|
193
|
+
:card => 'Card',
|
194
|
+
:tokenization => 'Tokenization',
|
195
|
+
:wallet_id => 'String',
|
196
|
+
:authentication_options => 'AuthenticationOptions'
|
197
|
+
|
198
|
+
}
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
end
|