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,209 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
|
4
|
+
|
5
|
+
module MastercardMerchantCheckout
|
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 Base64 encoded unpredictable number. EMV quality random number generated by the merchant, service provider, or, Masterpass (if null).
|
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 = MastercardMerchantCheckout.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,244 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
|
4
|
+
|
5
|
+
module MastercardMerchantCheckout
|
6
|
+
# This class contains various methods to set express checkout request parameters required for ExpressCheckoutApi.
|
7
|
+
class ExpressCheckoutRequest
|
8
|
+
include ROXML
|
9
|
+
|
10
|
+
xml_name "ExpressCheckoutRequest"
|
11
|
+
|
12
|
+
# @!attribute checkout_id
|
13
|
+
# @return [String] the merchant Checkout identifier.
|
14
|
+
xml_accessor :checkout_id, :from =>"checkoutId"
|
15
|
+
|
16
|
+
# @!attribute pairing_id
|
17
|
+
# @return [String] the unique pairing token identifier used to fetch card and address data from a wallet that is paired with a merchant during Express Checkout.
|
18
|
+
xml_accessor :pairing_id, :from =>"pairingId"
|
19
|
+
|
20
|
+
# @!attribute pre_checkout_transaction_id
|
21
|
+
# @return [String] the precheckout identifier from PreCheckoutApi response.
|
22
|
+
xml_accessor :pre_checkout_transaction_id, :from =>"preCheckoutTransactionId"
|
23
|
+
|
24
|
+
# @!attribute amount
|
25
|
+
# @return [Float] the transaction amount.
|
26
|
+
xml_accessor :amount, :from =>"amount"
|
27
|
+
|
28
|
+
# @!attribute currency
|
29
|
+
# @return [String] the ISO-4217 code for currency of the transaction.
|
30
|
+
xml_accessor :currency, :from =>"currency"
|
31
|
+
|
32
|
+
# @!attribute card_id
|
33
|
+
# @return [String] the card identifier from PreCheckoutApi response.
|
34
|
+
xml_accessor :card_id, :from =>"cardId"
|
35
|
+
|
36
|
+
# @!attribute shipping_address_id
|
37
|
+
# @return [String] the shippingAddress identifier from PreCheckoutApi response.
|
38
|
+
xml_accessor :shipping_address_id, :from =>"shippingAddressId"
|
39
|
+
|
40
|
+
# @!attribute digital_goods
|
41
|
+
# @return [BOOLEAN] the flag to indicate digital goods are being purchased so a shipping address is not required for the transaction.
|
42
|
+
xml_accessor :digital_goods, :from =>"digitalGoods"
|
43
|
+
|
44
|
+
|
45
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
46
|
+
def self.attribute_map
|
47
|
+
{
|
48
|
+
:checkout_id => :checkoutId ,
|
49
|
+
:pairing_id => :pairingId ,
|
50
|
+
:pre_checkout_transaction_id => :preCheckoutTransactionId ,
|
51
|
+
:amount => :amount ,
|
52
|
+
:currency => :currency ,
|
53
|
+
:card_id => :cardId ,
|
54
|
+
:shipping_address_id => :shippingAddressId ,
|
55
|
+
:digital_goods => :digitalGoods
|
56
|
+
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize(attributes = {})
|
61
|
+
return unless attributes.is_a?(Hash)
|
62
|
+
|
63
|
+
# convert string to symbol for hash key
|
64
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
65
|
+
|
66
|
+
|
67
|
+
if attributes.has_key?(:checkout_id)
|
68
|
+
self.checkout_id = attributes[:checkout_id]
|
69
|
+
end
|
70
|
+
|
71
|
+
if attributes.has_key?(:pairing_id)
|
72
|
+
self.pairing_id = attributes[:pairing_id]
|
73
|
+
end
|
74
|
+
|
75
|
+
if attributes.has_key?(:pre_checkout_transaction_id)
|
76
|
+
self.pre_checkout_transaction_id = attributes[:pre_checkout_transaction_id]
|
77
|
+
end
|
78
|
+
|
79
|
+
if attributes.has_key?(:amount)
|
80
|
+
self.amount = attributes[:amount]
|
81
|
+
end
|
82
|
+
|
83
|
+
if attributes.has_key?(:currency)
|
84
|
+
self.currency = attributes[:currency]
|
85
|
+
end
|
86
|
+
|
87
|
+
if attributes.has_key?(:card_id)
|
88
|
+
self.card_id = attributes[:card_id]
|
89
|
+
end
|
90
|
+
|
91
|
+
if attributes.has_key?(:shipping_address_id)
|
92
|
+
self.shipping_address_id = attributes[:shipping_address_id]
|
93
|
+
end
|
94
|
+
|
95
|
+
if attributes.has_key?(:digital_goods)
|
96
|
+
self.digital_goods = attributes[:digital_goods]
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
# Check equality by comparing each attribute.
|
105
|
+
def ==(o)
|
106
|
+
return true if self.equal?(o)
|
107
|
+
self.class == o.class &&
|
108
|
+
checkout_id == o.checkout_id &&
|
109
|
+
pairing_id == o.pairing_id &&
|
110
|
+
pre_checkout_transaction_id == o.pre_checkout_transaction_id &&
|
111
|
+
amount == o.amount &&
|
112
|
+
currency == o.currency &&
|
113
|
+
card_id == o.card_id &&
|
114
|
+
shipping_address_id == o.shipping_address_id &&
|
115
|
+
digital_goods == o.digital_goods
|
116
|
+
end
|
117
|
+
|
118
|
+
# @see the `==` method
|
119
|
+
def eql?(o)
|
120
|
+
self == o
|
121
|
+
end
|
122
|
+
|
123
|
+
# Calculate hash code according to all attributes.
|
124
|
+
def hash
|
125
|
+
[checkout_id, pairing_id, pre_checkout_transaction_id, amount, currency, card_id, shipping_address_id, digital_goods].hash
|
126
|
+
end
|
127
|
+
|
128
|
+
# build the object from hash
|
129
|
+
def build_from_hash(attributes)
|
130
|
+
return nil unless attributes.is_a?(Hash)
|
131
|
+
self.class.datatype_map.each_pair do |key, type|
|
132
|
+
if type =~ /^Array<(.*)>/i
|
133
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
134
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
135
|
+
else
|
136
|
+
#TODO show warning in debug mode
|
137
|
+
end
|
138
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
139
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
140
|
+
else
|
141
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
self
|
146
|
+
end
|
147
|
+
|
148
|
+
def _deserialize(type, value)
|
149
|
+
case type.to_sym
|
150
|
+
when :DateTime
|
151
|
+
DateTime.parse(value)
|
152
|
+
when :Date
|
153
|
+
Date.parse(value)
|
154
|
+
when :String
|
155
|
+
value.to_s
|
156
|
+
when :Integer
|
157
|
+
value.to_i
|
158
|
+
when :Float
|
159
|
+
value.to_f
|
160
|
+
when :BOOLEAN
|
161
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
162
|
+
true
|
163
|
+
else
|
164
|
+
false
|
165
|
+
end
|
166
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
167
|
+
inner_type = Regexp.last_match[:inner_type]
|
168
|
+
value.map { |v| _deserialize(inner_type, v) }
|
169
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
170
|
+
k_type = Regexp.last_match[:k_type]
|
171
|
+
v_type = Regexp.last_match[:v_type]
|
172
|
+
{}.tap do |hash|
|
173
|
+
value.each do |k, v|
|
174
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
else # model
|
178
|
+
_model = MastercardMerchantCheckout.const_get(type).new
|
179
|
+
_model.build_from_hash(value)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def to_s
|
184
|
+
to_hash.to_s
|
185
|
+
end
|
186
|
+
|
187
|
+
# to_body is an alias to to_body (backward compatibility))
|
188
|
+
def to_body
|
189
|
+
to_hash
|
190
|
+
end
|
191
|
+
|
192
|
+
# return the object in the form of hash
|
193
|
+
def to_hash(include_root = false)
|
194
|
+
attributes_hash = {}
|
195
|
+
hash = {}
|
196
|
+
self.class.attribute_map.each_pair do |attr, param|
|
197
|
+
value = self.send(attr)
|
198
|
+
next if value.nil?
|
199
|
+
hash[param] = _to_hash(value)
|
200
|
+
end
|
201
|
+
attributes_hash = include_root ? { "ExpressCheckoutRequest" => hash } : hash
|
202
|
+
return attributes_hash
|
203
|
+
end
|
204
|
+
|
205
|
+
# Method to output non-array value in the form of hash
|
206
|
+
# For object, use to_hash. Otherwise, just return the value
|
207
|
+
def _to_hash(value)
|
208
|
+
if value.is_a?(Array)
|
209
|
+
value.compact.map{ |v| _to_hash(v) }
|
210
|
+
elsif value.is_a?(Hash)
|
211
|
+
{}.tap do |hash|
|
212
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
213
|
+
end
|
214
|
+
elsif value.respond_to? :to_hash
|
215
|
+
value.to_hash
|
216
|
+
else
|
217
|
+
value
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
private
|
223
|
+
def after_parse
|
224
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
225
|
+
end
|
226
|
+
|
227
|
+
# Attribute datatype mapping.
|
228
|
+
def self.datatype_map
|
229
|
+
{
|
230
|
+
:checkout_id => 'String',
|
231
|
+
:pairing_id => 'String',
|
232
|
+
:pre_checkout_transaction_id => 'String',
|
233
|
+
:amount => 'Float',
|
234
|
+
:currency => 'String',
|
235
|
+
:card_id => 'String',
|
236
|
+
:shipping_address_id => 'String',
|
237
|
+
:digital_goods => 'BOOLEAN'
|
238
|
+
|
239
|
+
}
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
end
|