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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/mastercard_merchant_checkout.rb +24 -0
- data/lib/mastercard_merchant_checkout/api/express_checkout_api.rb +40 -0
- data/lib/mastercard_merchant_checkout/api/pairing_id_api.rb +38 -0
- data/lib/mastercard_merchant_checkout/api/payment_data_api.rb +2 -2
- data/lib/mastercard_merchant_checkout/api/postback_api.rb +1 -1
- data/lib/mastercard_merchant_checkout/api/pre_checkout_data_api.rb +39 -0
- data/lib/mastercard_merchant_checkout/models/address.rb +9 -9
- data/lib/mastercard_merchant_checkout/models/authentication_options.rb +8 -8
- data/lib/mastercard_merchant_checkout/models/card.rb +22 -11
- data/lib/mastercard_merchant_checkout/models/contact_info.rb +211 -0
- data/lib/mastercard_merchant_checkout/models/cryptogram.rb +209 -0
- data/lib/mastercard_merchant_checkout/models/express_checkout_request.rb +244 -0
- data/lib/mastercard_merchant_checkout/models/pairing.rb +167 -0
- data/lib/mastercard_merchant_checkout/models/payment_data.rb +42 -8
- data/lib/mastercard_merchant_checkout/models/personal_info.rb +2 -2
- data/lib/mastercard_merchant_checkout/models/postback.rb +20 -9
- data/lib/mastercard_merchant_checkout/models/pre_checkout_card.rb +233 -0
- data/lib/mastercard_merchant_checkout/models/pre_checkout_data.rb +256 -0
- data/lib/mastercard_merchant_checkout/models/recipient_info.rb +178 -0
- data/lib/mastercard_merchant_checkout/models/shipping_address.rb +289 -0
- data/lib/mastercard_merchant_checkout/models/tokenization.rb +201 -0
- data/lib/mastercard_merchant_checkout/tracker/sdk_api_tracker.rb +1 -1
- data/lib/mastercard_merchant_checkout/version.rb +1 -1
- metadata +17 -5
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
|
4
|
+
|
5
|
+
module MastercardMerchantCheckout
|
6
|
+
# This class contains methods to set or get the pairing detail(s).
|
7
|
+
class Pairing
|
8
|
+
include ROXML
|
9
|
+
|
10
|
+
xml_name "Pairing"
|
11
|
+
|
12
|
+
# @!attribute pairing_id
|
13
|
+
# @return [String] the new pairing token identifier used to fetch pre-checkout data.
|
14
|
+
xml_accessor :pairing_id, :from =>"pairingId"
|
15
|
+
|
16
|
+
|
17
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
18
|
+
def self.attribute_map
|
19
|
+
{
|
20
|
+
:pairing_id => :pairingId
|
21
|
+
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(attributes = {})
|
26
|
+
return unless attributes.is_a?(Hash)
|
27
|
+
|
28
|
+
# convert string to symbol for hash key
|
29
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
30
|
+
|
31
|
+
|
32
|
+
if attributes.has_key?(:pairing_id)
|
33
|
+
self.pairing_id = attributes[:pairing_id]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
# Check equality by comparing each attribute.
|
42
|
+
def ==(o)
|
43
|
+
return true if self.equal?(o)
|
44
|
+
self.class == o.class &&
|
45
|
+
pairing_id == o.pairing_id
|
46
|
+
end
|
47
|
+
|
48
|
+
# @see the `==` method
|
49
|
+
def eql?(o)
|
50
|
+
self == o
|
51
|
+
end
|
52
|
+
|
53
|
+
# Calculate hash code according to all attributes.
|
54
|
+
def hash
|
55
|
+
[pairing_id].hash
|
56
|
+
end
|
57
|
+
|
58
|
+
# build the object from hash
|
59
|
+
def build_from_hash(attributes)
|
60
|
+
return nil unless attributes.is_a?(Hash)
|
61
|
+
self.class.datatype_map.each_pair do |key, type|
|
62
|
+
if type =~ /^Array<(.*)>/i
|
63
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
64
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
65
|
+
else
|
66
|
+
#TODO show warning in debug mode
|
67
|
+
end
|
68
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
69
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
70
|
+
else
|
71
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
def _deserialize(type, value)
|
79
|
+
case type.to_sym
|
80
|
+
when :DateTime
|
81
|
+
DateTime.parse(value)
|
82
|
+
when :Date
|
83
|
+
Date.parse(value)
|
84
|
+
when :String
|
85
|
+
value.to_s
|
86
|
+
when :Integer
|
87
|
+
value.to_i
|
88
|
+
when :Float
|
89
|
+
value.to_f
|
90
|
+
when :BOOLEAN
|
91
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
92
|
+
true
|
93
|
+
else
|
94
|
+
false
|
95
|
+
end
|
96
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
97
|
+
inner_type = Regexp.last_match[:inner_type]
|
98
|
+
value.map { |v| _deserialize(inner_type, v) }
|
99
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
100
|
+
k_type = Regexp.last_match[:k_type]
|
101
|
+
v_type = Regexp.last_match[:v_type]
|
102
|
+
{}.tap do |hash|
|
103
|
+
value.each do |k, v|
|
104
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
else # model
|
108
|
+
_model = MastercardMerchantCheckout.const_get(type).new
|
109
|
+
_model.build_from_hash(value)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def to_s
|
114
|
+
to_hash.to_s
|
115
|
+
end
|
116
|
+
|
117
|
+
# to_body is an alias to to_body (backward compatibility))
|
118
|
+
def to_body
|
119
|
+
to_hash
|
120
|
+
end
|
121
|
+
|
122
|
+
# return the object in the form of hash
|
123
|
+
def to_hash(include_root = false)
|
124
|
+
attributes_hash = {}
|
125
|
+
hash = {}
|
126
|
+
self.class.attribute_map.each_pair do |attr, param|
|
127
|
+
value = self.send(attr)
|
128
|
+
next if value.nil?
|
129
|
+
hash[param] = _to_hash(value)
|
130
|
+
end
|
131
|
+
attributes_hash = include_root ? { "Pairing" => hash } : hash
|
132
|
+
return attributes_hash
|
133
|
+
end
|
134
|
+
|
135
|
+
# Method to output non-array value in the form of hash
|
136
|
+
# For object, use to_hash. Otherwise, just return the value
|
137
|
+
def _to_hash(value)
|
138
|
+
if value.is_a?(Array)
|
139
|
+
value.compact.map{ |v| _to_hash(v) }
|
140
|
+
elsif value.is_a?(Hash)
|
141
|
+
{}.tap do |hash|
|
142
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
143
|
+
end
|
144
|
+
elsif value.respond_to? :to_hash
|
145
|
+
value.to_hash
|
146
|
+
else
|
147
|
+
value
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
private
|
153
|
+
def after_parse
|
154
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
155
|
+
end
|
156
|
+
|
157
|
+
# Attribute datatype mapping.
|
158
|
+
def self.datatype_map
|
159
|
+
{
|
160
|
+
:pairing_id => 'String'
|
161
|
+
|
162
|
+
}
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
end
|
@@ -4,17 +4,18 @@ require_relative '../../mastercard_merchant_checkout/models/address'
|
|
4
4
|
require_relative '../../mastercard_merchant_checkout/models/authentication_options'
|
5
5
|
require_relative '../../mastercard_merchant_checkout/models/card'
|
6
6
|
require_relative '../../mastercard_merchant_checkout/models/personal_info'
|
7
|
+
require_relative '../../mastercard_merchant_checkout/models/tokenization'
|
7
8
|
|
8
9
|
|
9
10
|
module MastercardMerchantCheckout
|
10
|
-
# This class contains various methods to get paymentData response parameters returned by
|
11
|
+
# This class contains various methods to get paymentData response parameters returned by PaymentDataApi.
|
11
12
|
class PaymentData
|
12
13
|
include ROXML
|
13
14
|
|
14
15
|
xml_name "PaymentData"
|
15
16
|
|
16
17
|
# @!attribute card
|
17
|
-
# @return [Card] the card details.
|
18
|
+
# @return [Card] the payment card details.
|
18
19
|
xml_accessor :card, :from =>"card",:as => Card
|
19
20
|
|
20
21
|
# @!attribute shipping_address
|
@@ -25,14 +26,26 @@ module MastercardMerchantCheckout
|
|
25
26
|
# @return [PersonalInfo] the recipient's personal information.
|
26
27
|
xml_accessor :personal_info, :from =>"personalInfo",:as => PersonalInfo
|
27
28
|
|
29
|
+
# @!attribute tokenization
|
30
|
+
# @return [Tokenization] the tokenized card information.
|
31
|
+
xml_accessor :tokenization, :from =>"tokenization",:as => Tokenization
|
32
|
+
|
28
33
|
# @!attribute wallet_id
|
29
|
-
# @return [String] the
|
34
|
+
# @return [String] the unique identifier for a wallet that helps identify the origin wallet for the transaction.
|
30
35
|
xml_accessor :wallet_id, :from =>"walletId"
|
31
36
|
|
37
|
+
# @!attribute wallet_name
|
38
|
+
# @return [String] the wallet name.
|
39
|
+
xml_accessor :wallet_name, :from =>"walletName"
|
40
|
+
|
32
41
|
# @!attribute authentication_options
|
33
42
|
# @return [AuthenticationOptions] the authentication information.
|
34
43
|
xml_accessor :authentication_options, :from =>"authenticationOptions",:as => AuthenticationOptions
|
35
44
|
|
45
|
+
# @!attribute pairing_id
|
46
|
+
# @return [String] the new pairingId.
|
47
|
+
xml_accessor :pairing_id, :from =>"pairingId"
|
48
|
+
|
36
49
|
|
37
50
|
# Attribute mapping from ruby-style variable name to JSON key.
|
38
51
|
def self.attribute_map
|
@@ -40,8 +53,11 @@ module MastercardMerchantCheckout
|
|
40
53
|
:card => :card ,
|
41
54
|
:shipping_address => :shippingAddress ,
|
42
55
|
:personal_info => :personalInfo ,
|
56
|
+
:tokenization => :tokenization ,
|
43
57
|
:wallet_id => :walletId ,
|
44
|
-
:
|
58
|
+
:wallet_name => :walletName ,
|
59
|
+
:authentication_options => :authenticationOptions ,
|
60
|
+
:pairing_id => :pairingId
|
45
61
|
|
46
62
|
}
|
47
63
|
end
|
@@ -65,14 +81,26 @@ module MastercardMerchantCheckout
|
|
65
81
|
self.personal_info = attributes[:personal_info]
|
66
82
|
end
|
67
83
|
|
84
|
+
if attributes.has_key?(:tokenization)
|
85
|
+
self.tokenization = attributes[:tokenization]
|
86
|
+
end
|
87
|
+
|
68
88
|
if attributes.has_key?(:wallet_id)
|
69
89
|
self.wallet_id = attributes[:wallet_id]
|
70
90
|
end
|
71
91
|
|
92
|
+
if attributes.has_key?(:wallet_name)
|
93
|
+
self.wallet_name = attributes[:wallet_name]
|
94
|
+
end
|
95
|
+
|
72
96
|
if attributes.has_key?(:authentication_options)
|
73
97
|
self.authentication_options = attributes[:authentication_options]
|
74
98
|
end
|
75
99
|
|
100
|
+
if attributes.has_key?(:pairing_id)
|
101
|
+
self.pairing_id = attributes[:pairing_id]
|
102
|
+
end
|
103
|
+
|
76
104
|
end
|
77
105
|
|
78
106
|
|
@@ -85,8 +113,11 @@ module MastercardMerchantCheckout
|
|
85
113
|
card == o.card &&
|
86
114
|
shipping_address == o.shipping_address &&
|
87
115
|
personal_info == o.personal_info &&
|
116
|
+
tokenization == o.tokenization &&
|
88
117
|
wallet_id == o.wallet_id &&
|
89
|
-
|
118
|
+
wallet_name == o.wallet_name &&
|
119
|
+
authentication_options == o.authentication_options &&
|
120
|
+
pairing_id == o.pairing_id
|
90
121
|
end
|
91
122
|
|
92
123
|
# @see the `==` method
|
@@ -96,7 +127,7 @@ module MastercardMerchantCheckout
|
|
96
127
|
|
97
128
|
# Calculate hash code according to all attributes.
|
98
129
|
def hash
|
99
|
-
[card, shipping_address, personal_info, wallet_id, authentication_options].hash
|
130
|
+
[card, shipping_address, personal_info, tokenization, wallet_id, wallet_name, authentication_options, pairing_id].hash
|
100
131
|
end
|
101
132
|
|
102
133
|
# build the object from hash
|
@@ -132,7 +163,7 @@ module MastercardMerchantCheckout
|
|
132
163
|
when :Float
|
133
164
|
value.to_f
|
134
165
|
when :BOOLEAN
|
135
|
-
if value =~
|
166
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
136
167
|
true
|
137
168
|
else
|
138
169
|
false
|
@@ -204,8 +235,11 @@ module MastercardMerchantCheckout
|
|
204
235
|
:card => 'Card',
|
205
236
|
:shipping_address => 'Address',
|
206
237
|
:personal_info => 'PersonalInfo',
|
238
|
+
:tokenization => 'Tokenization',
|
207
239
|
:wallet_id => 'String',
|
208
|
-
:
|
240
|
+
:wallet_name => 'String',
|
241
|
+
:authentication_options => 'AuthenticationOptions',
|
242
|
+
:pairing_id => 'String'
|
209
243
|
|
210
244
|
}
|
211
245
|
end
|
@@ -3,7 +3,7 @@ require 'roxml'
|
|
3
3
|
|
4
4
|
|
5
5
|
module MastercardMerchantCheckout
|
6
|
-
#
|
6
|
+
# The recipient's personal information.
|
7
7
|
class PersonalInfo
|
8
8
|
include ROXML
|
9
9
|
|
@@ -108,7 +108,7 @@ module MastercardMerchantCheckout
|
|
108
108
|
when :Float
|
109
109
|
value.to_f
|
110
110
|
when :BOOLEAN
|
111
|
-
if value =~
|
111
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
112
112
|
true
|
113
113
|
else
|
114
114
|
false
|
@@ -10,19 +10,19 @@ module MastercardMerchantCheckout
|
|
10
10
|
xml_name "Postback"
|
11
11
|
|
12
12
|
# @!attribute transaction_id
|
13
|
-
# @return [String] the transaction
|
13
|
+
# @return [String] the transaction identifiers. Identifies the transaction for which to return the consumer’s payment data. This is the oauth_verifier value sent by Masterpass in callback URL after the Masterpass user interface is closed.
|
14
14
|
xml_accessor :transaction_id, :from =>"transactionId"
|
15
15
|
|
16
16
|
# @!attribute currency
|
17
|
-
# @return [String] the
|
17
|
+
# @return [String] the ISO-4217 code for currency of the transaction.
|
18
18
|
xml_accessor :currency, :from =>"currency"
|
19
19
|
|
20
20
|
# @!attribute amount
|
21
|
-
# @return [Float] the transaction
|
21
|
+
# @return [Float] the transaction amount as an integer (10050 for $100.50).
|
22
22
|
xml_accessor :amount, :from =>"amount"
|
23
23
|
|
24
24
|
# @!attribute payment_successful
|
25
|
-
# @return [BOOLEAN] the payment status indicator. It is set to true if payment successful with
|
25
|
+
# @return [BOOLEAN] the payment status indicator. It is set to true if payment successful with payment processor else false.
|
26
26
|
xml_accessor :payment_successful, :from =>"paymentSuccessful"
|
27
27
|
|
28
28
|
# @!attribute payment_code
|
@@ -33,6 +33,10 @@ module MastercardMerchantCheckout
|
|
33
33
|
# @return [DateTime] the date of purchase.
|
34
34
|
xml_accessor :payment_date, :from =>"paymentDate"
|
35
35
|
|
36
|
+
# @!attribute pre_checkout_transaction_id
|
37
|
+
# @return [String] the preCheckoutTransactionId from the ExpressCheckout response.
|
38
|
+
xml_accessor :pre_checkout_transaction_id, :from =>"preCheckoutTransactionId"
|
39
|
+
|
36
40
|
|
37
41
|
# Attribute mapping from ruby-style variable name to JSON key.
|
38
42
|
def self.attribute_map
|
@@ -42,7 +46,8 @@ module MastercardMerchantCheckout
|
|
42
46
|
:amount => :amount ,
|
43
47
|
:payment_successful => :paymentSuccessful ,
|
44
48
|
:payment_code => :paymentCode ,
|
45
|
-
:payment_date => :paymentDate
|
49
|
+
:payment_date => :paymentDate ,
|
50
|
+
:pre_checkout_transaction_id => :preCheckoutTransactionId
|
46
51
|
|
47
52
|
}
|
48
53
|
end
|
@@ -78,6 +83,10 @@ module MastercardMerchantCheckout
|
|
78
83
|
self.payment_date = attributes[:payment_date]
|
79
84
|
end
|
80
85
|
|
86
|
+
if attributes.has_key?(:pre_checkout_transaction_id)
|
87
|
+
self.pre_checkout_transaction_id = attributes[:pre_checkout_transaction_id]
|
88
|
+
end
|
89
|
+
|
81
90
|
end
|
82
91
|
|
83
92
|
|
@@ -92,7 +101,8 @@ module MastercardMerchantCheckout
|
|
92
101
|
amount == o.amount &&
|
93
102
|
payment_successful == o.payment_successful &&
|
94
103
|
payment_code == o.payment_code &&
|
95
|
-
payment_date == o.payment_date
|
104
|
+
payment_date == o.payment_date &&
|
105
|
+
pre_checkout_transaction_id == o.pre_checkout_transaction_id
|
96
106
|
end
|
97
107
|
|
98
108
|
# @see the `==` method
|
@@ -102,7 +112,7 @@ module MastercardMerchantCheckout
|
|
102
112
|
|
103
113
|
# Calculate hash code according to all attributes.
|
104
114
|
def hash
|
105
|
-
[transaction_id, currency, amount, payment_successful, payment_code, payment_date].hash
|
115
|
+
[transaction_id, currency, amount, payment_successful, payment_code, payment_date, pre_checkout_transaction_id].hash
|
106
116
|
end
|
107
117
|
|
108
118
|
# build the object from hash
|
@@ -138,7 +148,7 @@ module MastercardMerchantCheckout
|
|
138
148
|
when :Float
|
139
149
|
value.to_f
|
140
150
|
when :BOOLEAN
|
141
|
-
if value =~
|
151
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
142
152
|
true
|
143
153
|
else
|
144
154
|
false
|
@@ -212,7 +222,8 @@ module MastercardMerchantCheckout
|
|
212
222
|
:amount => 'Float',
|
213
223
|
:payment_successful => 'BOOLEAN',
|
214
224
|
:payment_code => 'String',
|
215
|
-
:payment_date => 'DateTime'
|
225
|
+
:payment_date => 'DateTime',
|
226
|
+
:pre_checkout_transaction_id => 'String'
|
216
227
|
|
217
228
|
}
|
218
229
|
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
|
4
|
+
|
5
|
+
module MastercardMerchantCheckout
|
6
|
+
# This class contains precheckout cards details.
|
7
|
+
class PreCheckoutCard
|
8
|
+
include ROXML
|
9
|
+
|
10
|
+
xml_name "PreCheckoutCard"
|
11
|
+
|
12
|
+
# @!attribute brand_name
|
13
|
+
# @return [String] the card brand full name (Mastercard, American Express, Diners Club, Discover, JCB, Maestro, Visa).
|
14
|
+
xml_accessor :brand_name, :from =>"brandName"
|
15
|
+
|
16
|
+
# @!attribute card_holder_name
|
17
|
+
# @return [String] the cardholder's name for a card in the wallet.
|
18
|
+
xml_accessor :card_holder_name, :from =>"cardHolderName"
|
19
|
+
|
20
|
+
# @!attribute card_id
|
21
|
+
# @return [String] the unique indenifier for a card in the wallet.
|
22
|
+
xml_accessor :card_id, :from =>"cardId"
|
23
|
+
|
24
|
+
# @!attribute default
|
25
|
+
# @return [BOOLEAN] the Boolean value that identifies a card as the default card for the wallet (Specified by the user).
|
26
|
+
xml_accessor :default, :from =>"default"
|
27
|
+
|
28
|
+
# @!attribute expiry_year
|
29
|
+
# @return [Integer] the PAN expiration year, returned as a two-digit string (for the year 2020, Masterpass will return 20).
|
30
|
+
xml_accessor :expiry_year, :from =>"expiryYear"
|
31
|
+
|
32
|
+
# @!attribute expiry_month
|
33
|
+
# @return [Integer] the PAN expiration month, returned as a two-digit string.
|
34
|
+
xml_accessor :expiry_month, :from =>"expiryMonth"
|
35
|
+
|
36
|
+
# @!attribute last_four
|
37
|
+
# @return [String] the last four digits of the PAN.
|
38
|
+
xml_accessor :last_four, :from =>"lastFour"
|
39
|
+
|
40
|
+
|
41
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
42
|
+
def self.attribute_map
|
43
|
+
{
|
44
|
+
:brand_name => :brandName ,
|
45
|
+
:card_holder_name => :cardHolderName ,
|
46
|
+
:card_id => :cardId ,
|
47
|
+
:default => :default ,
|
48
|
+
:expiry_year => :expiryYear ,
|
49
|
+
:expiry_month => :expiryMonth ,
|
50
|
+
:last_four => :lastFour
|
51
|
+
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize(attributes = {})
|
56
|
+
return unless attributes.is_a?(Hash)
|
57
|
+
|
58
|
+
# convert string to symbol for hash key
|
59
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
60
|
+
|
61
|
+
|
62
|
+
if attributes.has_key?(:brand_name)
|
63
|
+
self.brand_name = attributes[:brand_name]
|
64
|
+
end
|
65
|
+
|
66
|
+
if attributes.has_key?(:card_holder_name)
|
67
|
+
self.card_holder_name = attributes[:card_holder_name]
|
68
|
+
end
|
69
|
+
|
70
|
+
if attributes.has_key?(:card_id)
|
71
|
+
self.card_id = attributes[:card_id]
|
72
|
+
end
|
73
|
+
|
74
|
+
if attributes.has_key?(:default)
|
75
|
+
self.default = attributes[:default]
|
76
|
+
end
|
77
|
+
|
78
|
+
if attributes.has_key?(:expiry_year)
|
79
|
+
self.expiry_year = attributes[:expiry_year]
|
80
|
+
end
|
81
|
+
|
82
|
+
if attributes.has_key?(:expiry_month)
|
83
|
+
self.expiry_month = attributes[:expiry_month]
|
84
|
+
end
|
85
|
+
|
86
|
+
if attributes.has_key?(:last_four)
|
87
|
+
self.last_four = attributes[:last_four]
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
# Check equality by comparing each attribute.
|
96
|
+
def ==(o)
|
97
|
+
return true if self.equal?(o)
|
98
|
+
self.class == o.class &&
|
99
|
+
brand_name == o.brand_name &&
|
100
|
+
card_holder_name == o.card_holder_name &&
|
101
|
+
card_id == o.card_id &&
|
102
|
+
default == o.default &&
|
103
|
+
expiry_year == o.expiry_year &&
|
104
|
+
expiry_month == o.expiry_month &&
|
105
|
+
last_four == o.last_four
|
106
|
+
end
|
107
|
+
|
108
|
+
# @see the `==` method
|
109
|
+
def eql?(o)
|
110
|
+
self == o
|
111
|
+
end
|
112
|
+
|
113
|
+
# Calculate hash code according to all attributes.
|
114
|
+
def hash
|
115
|
+
[brand_name, card_holder_name, card_id, default, expiry_year, expiry_month, last_four].hash
|
116
|
+
end
|
117
|
+
|
118
|
+
# build the object from hash
|
119
|
+
def build_from_hash(attributes)
|
120
|
+
return nil unless attributes.is_a?(Hash)
|
121
|
+
self.class.datatype_map.each_pair do |key, type|
|
122
|
+
if type =~ /^Array<(.*)>/i
|
123
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
124
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
125
|
+
else
|
126
|
+
#TODO show warning in debug mode
|
127
|
+
end
|
128
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
129
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
130
|
+
else
|
131
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
self
|
136
|
+
end
|
137
|
+
|
138
|
+
def _deserialize(type, value)
|
139
|
+
case type.to_sym
|
140
|
+
when :DateTime
|
141
|
+
DateTime.parse(value)
|
142
|
+
when :Date
|
143
|
+
Date.parse(value)
|
144
|
+
when :String
|
145
|
+
value.to_s
|
146
|
+
when :Integer
|
147
|
+
value.to_i
|
148
|
+
when :Float
|
149
|
+
value.to_f
|
150
|
+
when :BOOLEAN
|
151
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
152
|
+
true
|
153
|
+
else
|
154
|
+
false
|
155
|
+
end
|
156
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
157
|
+
inner_type = Regexp.last_match[:inner_type]
|
158
|
+
value.map { |v| _deserialize(inner_type, v) }
|
159
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
160
|
+
k_type = Regexp.last_match[:k_type]
|
161
|
+
v_type = Regexp.last_match[:v_type]
|
162
|
+
{}.tap do |hash|
|
163
|
+
value.each do |k, v|
|
164
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
else # model
|
168
|
+
_model = MastercardMerchantCheckout.const_get(type).new
|
169
|
+
_model.build_from_hash(value)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def to_s
|
174
|
+
to_hash.to_s
|
175
|
+
end
|
176
|
+
|
177
|
+
# to_body is an alias to to_body (backward compatibility))
|
178
|
+
def to_body
|
179
|
+
to_hash
|
180
|
+
end
|
181
|
+
|
182
|
+
# return the object in the form of hash
|
183
|
+
def to_hash(include_root = false)
|
184
|
+
attributes_hash = {}
|
185
|
+
hash = {}
|
186
|
+
self.class.attribute_map.each_pair do |attr, param|
|
187
|
+
value = self.send(attr)
|
188
|
+
next if value.nil?
|
189
|
+
hash[param] = _to_hash(value)
|
190
|
+
end
|
191
|
+
attributes_hash = include_root ? { "PreCheckoutCard" => hash } : hash
|
192
|
+
return attributes_hash
|
193
|
+
end
|
194
|
+
|
195
|
+
# Method to output non-array value in the form of hash
|
196
|
+
# For object, use to_hash. Otherwise, just return the value
|
197
|
+
def _to_hash(value)
|
198
|
+
if value.is_a?(Array)
|
199
|
+
value.compact.map{ |v| _to_hash(v) }
|
200
|
+
elsif value.is_a?(Hash)
|
201
|
+
{}.tap do |hash|
|
202
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
203
|
+
end
|
204
|
+
elsif value.respond_to? :to_hash
|
205
|
+
value.to_hash
|
206
|
+
else
|
207
|
+
value
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
private
|
213
|
+
def after_parse
|
214
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
215
|
+
end
|
216
|
+
|
217
|
+
# Attribute datatype mapping.
|
218
|
+
def self.datatype_map
|
219
|
+
{
|
220
|
+
:brand_name => 'String',
|
221
|
+
:card_holder_name => 'String',
|
222
|
+
:card_id => 'String',
|
223
|
+
:default => 'BOOLEAN',
|
224
|
+
:expiry_year => 'Integer',
|
225
|
+
:expiry_month => 'Integer',
|
226
|
+
:last_four => 'String'
|
227
|
+
|
228
|
+
}
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
end
|