kount-ris 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kount/khash.rb +1 -1
- data/lib/kount/ris/base.rb +9 -0
- data/lib/kount/ris/inquiry.rb +32 -8
- data/lib/kount/ris/response.rb +16 -14
- data/lib/kount/ris/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fc65ee2d09c6aa551d57d8b6d6f633a4ca4d37d
|
4
|
+
data.tar.gz: 15d1970184b6d164d7a83deeb5c3a74be5182d02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 275f28292316c3def712ce1162f92794576534cbcdce8404c1480c8cf448e10eb7f1d82e15d6b360fd22f5153937d833e352eb7b51b8a1e7c073675fba6b705d
|
7
|
+
data.tar.gz: b61786f3730813b9eaf8978659a713f2ae507549cd87417c2a98f8f443059a489896fc4b706357e706dca7c52b44ba8128cda3675249fb6ec061086388786a46
|
data/lib/kount/khash.rb
CHANGED
data/lib/kount/ris/base.rb
CHANGED
@@ -12,6 +12,15 @@ module Kount
|
|
12
12
|
NF MP NO OM PK PW PS PA PG PY PE PH PN PL PT PR QA RE RO RU RW BL SH KN LC MF PM VC
|
13
13
|
WS SM ST SA SN RS SC SL SG SK SI SB SO ZA GS SS ES LK SD SR SJ SZ SE CH SY TW TJ TZ
|
14
14
|
TH TL TG TK TO TT TN TR TM TC TV UG UA AE GB US UM UY UZ VU VE VN VI WF EH YE ZM ZW]
|
15
|
+
|
16
|
+
CURRENCY_CODES = %w[AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM BBD BDT BGN BHD BIF BMD
|
17
|
+
BND BOB BRL BSD BTN BWP BYN BZD CAD CDF CHF CLP CNY COP CRC CUC CUP CVE CZK DJF DKK
|
18
|
+
DOP DZD EGP ERN ETB EUR FJD FKP GBP GEL GGP GHS GIP GMD GNF GTQ GYD HKD HNL HRK HTG
|
19
|
+
HUF IDR ILS IMP INR IQD IRR ISK JEP JMD JOD JPY KES KGS KHR KMF KPW KRW KWD KYD KZT
|
20
|
+
LAK LBP LKR LRD LSL LYD MAD MDL MGA MKD MMK MNT MOP MRO MUR MVR MWK MXN MYR MZN NAD
|
21
|
+
NGN NIO NOK NPR NZD OMR PAB PEN PGK PHP PKR PLN PYG QAR RON RSD RUB RWF SAR SBD SCR
|
22
|
+
SDG SEK SGD SHP SLL SOS SPL SRD STD SVC SYP SZL THB TJS TMT TND TOP TRY TTD TVD TWD
|
23
|
+
TZS UAH UGX USD UYU UZS VEF VND VUV WST XAF XCD XDR XOF XPF YER ZAR ZMW ZWD]
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|
data/lib/kount/ris/inquiry.rb
CHANGED
@@ -43,12 +43,15 @@ module Kount
|
|
43
43
|
}.freeze
|
44
44
|
MODES = %w[q u p x e j w].freeze
|
45
45
|
RESPONSE_FORMATS = %w[sdk xml json yaml].freeze
|
46
|
-
GENDERS =
|
46
|
+
GENDERS = {
|
47
|
+
'm' => 'male',
|
48
|
+
'f' => 'female'
|
49
|
+
}.freeze
|
47
50
|
CARD_TYPES = %w[visa mastercard amex discover]
|
48
51
|
|
49
52
|
class << self
|
50
53
|
def currency_codes
|
51
|
-
Kount::RIS::Base::
|
54
|
+
Kount::RIS::Base::CURRENCY_CODES
|
52
55
|
end
|
53
56
|
|
54
57
|
def payment_types
|
@@ -128,7 +131,7 @@ module Kount
|
|
128
131
|
validates :response_format, inclusion: { in: response_formats }, presence: true # response_format
|
129
132
|
validates :last_four, format: { with: /\A[0-9]{4}\z/ }, length: { is: 4 }, allow_nil: true
|
130
133
|
validates :name, length: { maximum: 64 } # cardholder's name
|
131
|
-
validates :gender, inclusion: { in: genders }, allow_nil: true # gender
|
134
|
+
validates :gender, inclusion: { in: genders.values }, allow_nil: true # gender
|
132
135
|
validates :order_number, length: { maximum: 32 } # cardholder's name
|
133
136
|
validates :card_type, inclusion: { in: card_types }, allow_nil: true # Shipping Method
|
134
137
|
validate :products_are_valid
|
@@ -170,6 +173,18 @@ module Kount
|
|
170
173
|
shipping_methods[@shipping_method]
|
171
174
|
end
|
172
175
|
|
176
|
+
def gender=(value)
|
177
|
+
return @gender = nil if value.nil?
|
178
|
+
|
179
|
+
gender_value = genders.detect { |k,v| k if v.downcase == value.to_s.downcase }&.first || value.to_s.downcase
|
180
|
+
raise ArgumentError, "'#{value}' is not a valid gender" unless genders.include?(gender_value)
|
181
|
+
@gender = gender_value
|
182
|
+
end
|
183
|
+
|
184
|
+
def gender
|
185
|
+
genders[@gender]
|
186
|
+
end
|
187
|
+
|
173
188
|
def mode=(value)
|
174
189
|
return @mode = nil if value.nil?
|
175
190
|
|
@@ -229,8 +244,12 @@ module Kount
|
|
229
244
|
self
|
230
245
|
end
|
231
246
|
|
247
|
+
def payment_token_encoding
|
248
|
+
card_number =~ /x/i ? 'mask' : 'khash'
|
249
|
+
end
|
250
|
+
|
232
251
|
def payment_token
|
233
|
-
card_number =~ /x/i ? card_number : KHASH.new(card_number).to_s
|
252
|
+
card_number =~ /x/i ? card_number.to_s.upcase : KHASH.new(card_number).to_s
|
234
253
|
end
|
235
254
|
|
236
255
|
def avs_match_street
|
@@ -296,8 +315,9 @@ module Kount
|
|
296
315
|
PROD_PRICE: products.collect(&:price),
|
297
316
|
PROD_QUANT: products.collect(&:quantity),
|
298
317
|
PROD_TYPE: products.collect(&:category),
|
318
|
+
PENC: payment_token_encoding.to_s.upcase,
|
299
319
|
PTOK: payment_token,
|
300
|
-
PTYP: @payment_type,
|
320
|
+
PTYP: (@payment_type.to_s.upcase unless @payment_type.nil?),
|
301
321
|
SESS: session_id,
|
302
322
|
SITE: site_id,
|
303
323
|
TOTL: (total || products.sum { |product| product.price * product.quantity }),
|
@@ -310,13 +330,13 @@ module Kount
|
|
310
330
|
CVVR: (cvv_match.nil? ? 'X' : (cvv_match? ? 'M' : 'N')),
|
311
331
|
S2EM: recipient_email,
|
312
332
|
S2NM: recipient_name,
|
313
|
-
SHTP: @shipping_method,
|
333
|
+
SHTP: (@shipping_method.to_s.upcase unless @shipping_method.nil?),
|
314
334
|
UNIQ: customer_id,
|
315
335
|
UAGT: user_agent,
|
316
336
|
DOB: (birthdate.strftime('%Y-%m-%d') unless birthdate.nil?),
|
317
337
|
EPOC: (account_created_at.to_i unless account_created_at.nil?),
|
318
338
|
FRMT: (response_format.to_s.upcase unless response_format.nil?),
|
319
|
-
GENDER: gender,
|
339
|
+
GENDER: (@gender.to_s.upcase unless @gender.nil?),
|
320
340
|
LAST4: last_four,
|
321
341
|
NAME: name,
|
322
342
|
ORDR: order_number,
|
@@ -366,7 +386,11 @@ module Kount
|
|
366
386
|
|
367
387
|
response = http.request(request)
|
368
388
|
|
369
|
-
response_params =
|
389
|
+
response_params = begin
|
390
|
+
JSON.parse(response.body)
|
391
|
+
rescue JSON::ParserError => e
|
392
|
+
response.body.split("\n").collect { |params| Rack::Utils.parse_nested_query(params) }.reduce({}, :merge)
|
393
|
+
end
|
370
394
|
|
371
395
|
@response = Response.new(response_params)
|
372
396
|
end
|
data/lib/kount/ris/response.rb
CHANGED
@@ -144,7 +144,9 @@ module Kount
|
|
144
144
|
validate :pierced_location_is_valid # Location object
|
145
145
|
|
146
146
|
def initialize(attrs = {})
|
147
|
-
|
147
|
+
attrs_keys = attrs.compact.keys
|
148
|
+
|
149
|
+
self.score = attrs['SCOR'].to_i if attrs_keys.include?('SCOR')
|
148
150
|
self.reason_text = attrs['REASON_CODE']
|
149
151
|
self.merchant_id = attrs['MERC']
|
150
152
|
self.mode = attrs['MODE']
|
@@ -162,26 +164,26 @@ module Kount
|
|
162
164
|
|
163
165
|
device_attributes = {
|
164
166
|
browser: attrs['BROWSER'],
|
165
|
-
cookies_enabled: ((attrs['COOKIES'].downcase == 'y' ? true : false) if
|
166
|
-
first_seen_at: ((Date.strptime(attrs['DDFS'], '%Y-%m-%d') rescue nil) if
|
167
|
+
cookies_enabled: ((attrs['COOKIES'].downcase == 'y' ? true : false) if attrs_keys.include?('COOKIES')),
|
168
|
+
first_seen_at: ((Date.strptime(attrs['DDFS'], '%Y-%m-%d') rescue nil) if attrs_keys.include?('DDFS')),
|
167
169
|
layers: attrs['DEVICE_LAYERS'],
|
168
170
|
screen_resolution: attrs['DSR'],
|
169
171
|
fingerprint: attrs['FINGERPRINT'],
|
170
|
-
flash_enabled: ((attrs['FLASH'].downcase == 'y' ? true : false) if
|
172
|
+
flash_enabled: ((attrs['FLASH'].downcase == 'y' ? true : false) if attrs_keys.include?('FLASH')),
|
171
173
|
configured_country_code: attrs['HTTP_COUNTRY'],
|
172
|
-
javascript_enabled: ((attrs['JAVASCRIPT'].downcase == 'y' ? true : false) if
|
173
|
-
captured: ((attrs['KAPT'].downcase == 'y' ? true : false) if
|
174
|
+
javascript_enabled: ((attrs['JAVASCRIPT'].downcase == 'y' ? true : false) if attrs_keys.include?('JAVASCRIPT')),
|
175
|
+
captured: ((attrs['KAPT'].downcase == 'y' ? true : false) if attrs_keys.include?('KAPT')),
|
174
176
|
language_country_code: attrs['LANGUAGE'],
|
175
|
-
localtime: ((Date.strptime(attrs['LOCALTIME'], '%Y-%m-%d %H:%M:%S') rescue nil) if
|
176
|
-
using_forwarder: ((attrs['MOBILE_FORWARDER'].downcase == 'y' ? true : false) if
|
177
|
+
localtime: ((Date.strptime(attrs['LOCALTIME'], '%Y-%m-%d %H:%M:%S') rescue nil) if attrs_keys.include?('LOCALTIME')),
|
178
|
+
using_forwarder: ((attrs['MOBILE_FORWARDER'].downcase == 'y' ? true : false) if attrs_keys.include?('MOBILE_FORWARDER')),
|
177
179
|
mobile_type: attrs['MOBILE_TYPE'],
|
178
180
|
network_type: attrs['NETW'],
|
179
181
|
operating_system: attrs['OS'],
|
180
|
-
remote_access: ((attrs['PC_REMOTE'].downcase == 'y' ? true : false) if
|
182
|
+
remote_access: ((attrs['PC_REMOTE'].downcase == 'y' ? true : false) if attrs_keys.include?('PC_REMOTE')),
|
181
183
|
configured_region: attrs['REGN'],
|
182
184
|
timezone: attrs['TIMEZONE'],
|
183
185
|
user_agent: attrs['UAS'],
|
184
|
-
voice_enabled: ((attrs['VOICE_DEVICE'].downcase == 'y' ? true : false) if
|
186
|
+
voice_enabled: ((attrs['VOICE_DEVICE'].downcase == 'y' ? true : false) if attrs_keys.include?('VOICE_DEVICE')),
|
185
187
|
region: attrs['REGION'],
|
186
188
|
country_code: attrs['COUNTRY'],
|
187
189
|
}.compact
|
@@ -219,27 +221,27 @@ module Kount
|
|
219
221
|
}.compact
|
220
222
|
self.pierced_location = Location.new(pierced_location_attributes) if pierced_location_attributes.any?
|
221
223
|
|
222
|
-
self.counters = attrs['COUNTERS_TRIGGERED'].to_i.times.collect
|
224
|
+
self.counters = attrs['COUNTERS_TRIGGERED'].to_i.times.collect do |i|
|
223
225
|
Trigger::Counter.new(
|
224
226
|
name: attrs["COUNTER_NAME_#{i}"],
|
225
227
|
count: attrs["COUNTER_VALUE_#{i}"].to_i,
|
226
228
|
)
|
227
229
|
end
|
228
230
|
|
229
|
-
self.errors = attrs['ERROR_COUNT'].to_i.times.collect
|
231
|
+
self.errors = attrs['ERROR_COUNT'].to_i.times.collect do |i|
|
230
232
|
Trigger::Error.new(
|
231
233
|
message: attrs["ERROR_#{i}"],
|
232
234
|
)
|
233
235
|
end
|
234
236
|
|
235
|
-
self.rules = attrs['RULES_TRIGGERED'].to_i.times.collect
|
237
|
+
self.rules = attrs['RULES_TRIGGERED'].to_i.times.collect do |_,i|
|
236
238
|
Trigger::Rule.new(
|
237
239
|
description: attrs["RULE_DESCRIPTION_#{i}"],
|
238
240
|
id: attrs["RULE_ID_#{i}"].to_i,
|
239
241
|
)
|
240
242
|
end
|
241
243
|
|
242
|
-
self.warnings = attrs['WARNING_COUNT'].to_i.times.collect
|
244
|
+
self.warnings = attrs['WARNING_COUNT'].to_i.times.collect do |_,i|
|
243
245
|
Trigger::Warning.new(
|
244
246
|
message: attrs["WARNING_#{i}"],
|
245
247
|
)
|
data/lib/kount/ris/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kount-ris
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- blaq reports
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|