kount_complete 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kount.rb +28 -28
- data/lib/kount/cart.rb +36 -36
- data/lib/kount/client.rb +125 -124
- data/lib/kount/payment_types.rb +52 -52
- data/lib/kount/request.rb +41 -41
- data/lib/kount/request/inquiry.rb +90 -85
- data/lib/kount/request/update.rb +28 -28
- data/lib/kount/security_mash.rb +82 -82
- data/lib/kount/utils/khash.rb +47 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4fb5f2ac5146df1e91864887f3a299676a6e3359998657ece5bdaa16a9a0981
|
4
|
+
data.tar.gz: 830538c8d4a58d49b035b5e4ecbf01e5a2566acedccd010cc88b45b2fef1df4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72f8a404eb61e3565b67ef39a2267fe1674c769674493150f7ee9543424ceb7c353664451a458e6e6d658638600a7257f9874238d38c18e5bbd26cfdd14c6d2c
|
7
|
+
data.tar.gz: c679e2d85a2bd53cc9420e5e09d3c5f39636018b0ac45f7a94e9100d73cd16551a3ba0087a2b176004386b1376f0a2ac6ddd80cfc58881a9c6b7603148eb9656
|
data/lib/kount.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require 'kount/client'
|
2
|
-
require 'kount/payment_types'
|
3
|
-
|
4
|
-
##
|
5
|
-
# This module is the main entry point to the service wrapper.
|
6
|
-
# Its primary function is to collect the runtime options
|
7
|
-
# and return a Client object, on which all of the runtime
|
8
|
-
# integration takes place.
|
9
|
-
module Kount
|
10
|
-
# Creates the client object
|
11
|
-
#
|
12
|
-
# Expected options include:
|
13
|
-
# options = {
|
14
|
-
# :merchant_id => "MERCHANT_ID" # required (6 digit number)
|
15
|
-
# :ksalt => "KSALT" # required (provided by Kount)
|
16
|
-
# :key => "RIS_KEY" # required (created in the AWC web app)
|
17
|
-
# :endpoint => "RIS_ENDPOINT" # optional (default https://risk.kount.net)
|
18
|
-
# :version => "RIS_VERSION" # optional (defaults "0630")
|
19
|
-
# :is_test => "IS_TEST" # optional (defaults to false)
|
20
|
-
# }
|
21
|
-
# @param options Hash
|
22
|
-
def new(options = {})
|
23
|
-
fail ArgumentError, 'Config options required' if options.empty?
|
24
|
-
Client.new(options)
|
25
|
-
end
|
26
|
-
|
27
|
-
module_function :new
|
28
|
-
end
|
1
|
+
require 'kount/client'
|
2
|
+
require 'kount/payment_types'
|
3
|
+
|
4
|
+
##
|
5
|
+
# This module is the main entry point to the service wrapper.
|
6
|
+
# Its primary function is to collect the runtime options
|
7
|
+
# and return a Client object, on which all of the runtime
|
8
|
+
# integration takes place.
|
9
|
+
module Kount
|
10
|
+
# Creates the client object
|
11
|
+
#
|
12
|
+
# Expected options include:
|
13
|
+
# options = {
|
14
|
+
# :merchant_id => "MERCHANT_ID" # required (6 digit number)
|
15
|
+
# :ksalt => "KSALT" # required (provided by Kount)
|
16
|
+
# :key => "RIS_KEY" # required (created in the AWC web app)
|
17
|
+
# :endpoint => "RIS_ENDPOINT" # optional (default https://risk.kount.net)
|
18
|
+
# :version => "RIS_VERSION" # optional (defaults "0630")
|
19
|
+
# :is_test => "IS_TEST" # optional (defaults to false)
|
20
|
+
# }
|
21
|
+
# @param options Hash
|
22
|
+
def new(options = {})
|
23
|
+
fail ArgumentError, 'Config options required' if options.empty?
|
24
|
+
Client.new(options)
|
25
|
+
end
|
26
|
+
|
27
|
+
module_function :new
|
28
|
+
end
|
data/lib/kount/cart.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
module Kount
|
2
|
-
##
|
3
|
-
# This class handles cart data until the get_request is ready
|
4
|
-
# to push the data into the form fields
|
5
|
-
class Cart
|
6
|
-
attr_accessor :items
|
7
|
-
|
8
|
-
# Initialize cart object
|
9
|
-
def initialize
|
10
|
-
@items = []
|
11
|
-
end
|
12
|
-
|
13
|
-
# Add cart items
|
14
|
-
#
|
15
|
-
# @param item [String] Cart item name
|
16
|
-
# @param type [String] Cart type name
|
17
|
-
# @param desc [String] Cart item long description
|
18
|
-
# @param quant [String] Cart item quantity
|
19
|
-
# @param price [String] Cart item price in cents
|
20
|
-
def add_item(item, type, desc, quant, price)
|
21
|
-
@items << { TYPE: type,
|
22
|
-
DESC: desc,
|
23
|
-
ITEM: item,
|
24
|
-
QUANT: quant,
|
25
|
-
PRICE: price }
|
26
|
-
end
|
27
|
-
|
28
|
-
# Initialize an Inquiry object
|
29
|
-
#
|
30
|
-
# @param param [String] Param type: :TYPE, :DESC, :ITEM, :PRICE, or :QUANT
|
31
|
-
# @return [Array] Ordered array of the cart contents for each param type
|
32
|
-
def get_item(param)
|
33
|
-
@items.collect { |item| item[param] }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
module Kount
|
2
|
+
##
|
3
|
+
# This class handles cart data until the get_request is ready
|
4
|
+
# to push the data into the form fields
|
5
|
+
class Cart
|
6
|
+
attr_accessor :items
|
7
|
+
|
8
|
+
# Initialize cart object
|
9
|
+
def initialize
|
10
|
+
@items = []
|
11
|
+
end
|
12
|
+
|
13
|
+
# Add cart items
|
14
|
+
#
|
15
|
+
# @param item [String] Cart item name
|
16
|
+
# @param type [String] Cart type name
|
17
|
+
# @param desc [String] Cart item long description
|
18
|
+
# @param quant [String] Cart item quantity
|
19
|
+
# @param price [String] Cart item price in cents
|
20
|
+
def add_item(item, type, desc, quant, price)
|
21
|
+
@items << { TYPE: type,
|
22
|
+
DESC: desc,
|
23
|
+
ITEM: item,
|
24
|
+
QUANT: quant,
|
25
|
+
PRICE: price }
|
26
|
+
end
|
27
|
+
|
28
|
+
# Initialize an Inquiry object
|
29
|
+
#
|
30
|
+
# @param param [String] Param type: :TYPE, :DESC, :ITEM, :PRICE, or :QUANT
|
31
|
+
# @return [Array] Ordered array of the cart contents for each param type
|
32
|
+
def get_item(param)
|
33
|
+
@items.collect { |item| item[param] }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/kount/client.rb
CHANGED
@@ -1,124 +1,125 @@
|
|
1
|
-
require 'kount/security_mash'
|
2
|
-
require 'kount/cart'
|
3
|
-
require 'kount/request'
|
4
|
-
require 'kount/request/update'
|
5
|
-
require 'kount/request/inquiry'
|
6
|
-
require 'rest-client'
|
7
|
-
require 'uri'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# @
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
# to
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
1
|
+
require 'kount/security_mash'
|
2
|
+
require 'kount/cart'
|
3
|
+
require 'kount/request'
|
4
|
+
require 'kount/request/update'
|
5
|
+
require 'kount/request/inquiry'
|
6
|
+
require 'rest-client'
|
7
|
+
require 'uri'
|
8
|
+
require 'kount/utils/khash'
|
9
|
+
|
10
|
+
# rubocop:disable Style/ClassVars
|
11
|
+
module Kount
|
12
|
+
##
|
13
|
+
# This class is where the primary interaction with
|
14
|
+
# the merchant integration will take place.
|
15
|
+
class Client
|
16
|
+
# Tells the RIS server to respond in JSON instead of key/value pairs
|
17
|
+
# This cannot be overridden.
|
18
|
+
RESPONSE_FORMAT = 'JSON'
|
19
|
+
|
20
|
+
# RIS Version. Can be overridden my merchant if required.
|
21
|
+
DEFAULT_VERSION = '0630'
|
22
|
+
|
23
|
+
# Default endpoint for production. Used by the DEFAULT_OPTIONS
|
24
|
+
ENDPOINT_PROD = 'https://risk.kount.net'
|
25
|
+
|
26
|
+
# Default endpoint for test. Used by the TEST_DEFAULT_OPTIONS
|
27
|
+
ENDPOINT_TEST = 'https://risk.test.kount.net'
|
28
|
+
|
29
|
+
# Default params for production
|
30
|
+
PROD_DEFAULT_OPTIONS = {
|
31
|
+
endpoint: ENDPOINT_PROD,
|
32
|
+
version: DEFAULT_VERSION,
|
33
|
+
is_test: false
|
34
|
+
}
|
35
|
+
|
36
|
+
# Default params for test if is_test is TRUE
|
37
|
+
TEST_DEFAULT_OPTIONS = {
|
38
|
+
endpoint: ENDPOINT_TEST,
|
39
|
+
version: DEFAULT_VERSION
|
40
|
+
}
|
41
|
+
|
42
|
+
# Initialize a client object
|
43
|
+
#
|
44
|
+
# Example usage
|
45
|
+
# {:merchant_id => "123456", :key => "trhvihsrihsta7ftadk6edkre7y8..."}
|
46
|
+
#
|
47
|
+
# @param params [Hash] Hash with merchant_id, ksalt and key, plus any
|
48
|
+
# other optional params
|
49
|
+
def initialize(params = {})
|
50
|
+
@options = {}
|
51
|
+
if params[:is_test]
|
52
|
+
@options.merge!(TEST_DEFAULT_OPTIONS)
|
53
|
+
else
|
54
|
+
@options.merge!(PROD_DEFAULT_OPTIONS)
|
55
|
+
end
|
56
|
+
@options.merge!(params)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Makes the call to the Kount RIS server
|
60
|
+
#
|
61
|
+
# @param request [Kount::Request] Kount inquiry or update object
|
62
|
+
# @return [Hash] RIS response formatted into a native hash
|
63
|
+
def get_response(request)
|
64
|
+
params = prepare_request_params(request)
|
65
|
+
response = {}
|
66
|
+
begin
|
67
|
+
response = RestClient::Resource.new(
|
68
|
+
endpoint,
|
69
|
+
verify_ssl: verify_ssl_option, timeout: 1).post params, x_kount_api_key: key
|
70
|
+
|
71
|
+
JSON.parse(response)
|
72
|
+
rescue
|
73
|
+
# RIS errors do not come back as JSON, so just pass them along raw.
|
74
|
+
response
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Give the request object what it needs to know to process the params
|
79
|
+
# to send to RIS.
|
80
|
+
def prepare_request_params(request)
|
81
|
+
request.prepare_params(version, merchant_id, RESPONSE_FORMAT, ksalt)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Kount Merchant ID
|
85
|
+
def merchant_id
|
86
|
+
@options[:merchant_id]
|
87
|
+
end
|
88
|
+
|
89
|
+
# RIS Interface Version
|
90
|
+
def version
|
91
|
+
@options[:version]
|
92
|
+
end
|
93
|
+
|
94
|
+
# RIS Endpoint URL
|
95
|
+
def endpoint
|
96
|
+
@options[:endpoint]
|
97
|
+
end
|
98
|
+
|
99
|
+
# Merchant API for RIS acess
|
100
|
+
def key
|
101
|
+
@options[:key]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Secret Kount salt for KHASH
|
105
|
+
def ksalt
|
106
|
+
@options[:ksalt]
|
107
|
+
end
|
108
|
+
|
109
|
+
# Is test or production setting
|
110
|
+
def test?
|
111
|
+
@options[:is_test]
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
# Helper method to turn on/off the SSL cert verify based on is_test config
|
117
|
+
def verify_ssl_option
|
118
|
+
if test?
|
119
|
+
OpenSSL::SSL::VERIFY_NONE
|
120
|
+
else
|
121
|
+
OpenSSL::SSL::VERIFY_PEER
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/lib/kount/payment_types.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
module Kount
|
2
|
-
##
|
3
|
-
# Convenience class to provide a list of PTYP values
|
4
|
-
class PaymentTypes
|
5
|
-
# Credit card (VISA, MasterCard, Amercian Express, etc)
|
6
|
-
CREDIT_CARD = 'CARD'
|
7
|
-
#Generic Token
|
8
|
-
TOKEN = 'TOKEN'
|
9
|
-
# PayPal
|
10
|
-
PAYPAL = 'PYPL'
|
11
|
-
# Check
|
12
|
-
CHECK = 'CHEK'
|
13
|
-
# Merchant issued gift card (not the ones with VISA/MC on them)
|
14
|
-
GIFT_CARD = 'GIFT'
|
15
|
-
# Carte Bleue
|
16
|
-
CARTE_BLEUE = 'CARTE_BLEUE'
|
17
|
-
# Sofort
|
18
|
-
SOFORT = 'SOFORT'
|
19
|
-
# Elv
|
20
|
-
ELV = 'ELV'
|
21
|
-
# Poli
|
22
|
-
POLI = 'POLI'
|
23
|
-
# Neteller
|
24
|
-
NETELLER = 'NETELLER'
|
25
|
-
# Giropay
|
26
|
-
GIROPAY = 'GIROPAY'
|
27
|
-
# BPay
|
28
|
-
BPAY = 'BPAY'
|
29
|
-
# Interac
|
30
|
-
INTERAC = 'INTERAC'
|
31
|
-
# Apple Pay
|
32
|
-
APPLE_PAY = 'APAY'
|
33
|
-
# Skrill
|
34
|
-
SKRILL = 'SKRILL'
|
35
|
-
# Moneybooker (basically another name for Skrill)
|
36
|
-
MONEYBOOKERS = 'SKRILL'
|
37
|
-
# Mercado Pago
|
38
|
-
MERCADO_PAGO = 'MERCADE_PAGO'
|
39
|
-
# Bill Me Later
|
40
|
-
BILL_ME_LATER = 'BLML'
|
41
|
-
# Google Checkout
|
42
|
-
GOOGLE_CHECKOUT = 'GOOG'
|
43
|
-
# Green Dot Money Pack
|
44
|
-
GREEN_DOT_MONEY_PACK = 'GDMP'
|
45
|
-
# Single Euro Payments Area
|
46
|
-
SINGLE_EURO_PAYMENTS_AREA = 'SEPA'
|
47
|
-
# None
|
48
|
-
NONE = 'NONE'
|
49
|
-
# Other
|
50
|
-
OTHER = 'OTHER'
|
51
|
-
end
|
52
|
-
end
|
1
|
+
module Kount
|
2
|
+
##
|
3
|
+
# Convenience class to provide a list of PTYP values
|
4
|
+
class PaymentTypes
|
5
|
+
# Credit card (VISA, MasterCard, Amercian Express, etc)
|
6
|
+
CREDIT_CARD = 'CARD'
|
7
|
+
#Generic Token
|
8
|
+
TOKEN = 'TOKEN'
|
9
|
+
# PayPal
|
10
|
+
PAYPAL = 'PYPL'
|
11
|
+
# Check
|
12
|
+
CHECK = 'CHEK'
|
13
|
+
# Merchant issued gift card (not the ones with VISA/MC on them)
|
14
|
+
GIFT_CARD = 'GIFT'
|
15
|
+
# Carte Bleue
|
16
|
+
CARTE_BLEUE = 'CARTE_BLEUE'
|
17
|
+
# Sofort
|
18
|
+
SOFORT = 'SOFORT'
|
19
|
+
# Elv
|
20
|
+
ELV = 'ELV'
|
21
|
+
# Poli
|
22
|
+
POLI = 'POLI'
|
23
|
+
# Neteller
|
24
|
+
NETELLER = 'NETELLER'
|
25
|
+
# Giropay
|
26
|
+
GIROPAY = 'GIROPAY'
|
27
|
+
# BPay
|
28
|
+
BPAY = 'BPAY'
|
29
|
+
# Interac
|
30
|
+
INTERAC = 'INTERAC'
|
31
|
+
# Apple Pay
|
32
|
+
APPLE_PAY = 'APAY'
|
33
|
+
# Skrill
|
34
|
+
SKRILL = 'SKRILL'
|
35
|
+
# Moneybooker (basically another name for Skrill)
|
36
|
+
MONEYBOOKERS = 'SKRILL'
|
37
|
+
# Mercado Pago
|
38
|
+
MERCADO_PAGO = 'MERCADE_PAGO'
|
39
|
+
# Bill Me Later
|
40
|
+
BILL_ME_LATER = 'BLML'
|
41
|
+
# Google Checkout
|
42
|
+
GOOGLE_CHECKOUT = 'GOOG'
|
43
|
+
# Green Dot Money Pack
|
44
|
+
GREEN_DOT_MONEY_PACK = 'GDMP'
|
45
|
+
# Single Euro Payments Area
|
46
|
+
SINGLE_EURO_PAYMENTS_AREA = 'SEPA'
|
47
|
+
# None
|
48
|
+
NONE = 'NONE'
|
49
|
+
# Other
|
50
|
+
OTHER = 'OTHER'
|
51
|
+
end
|
52
|
+
end
|
data/lib/kount/request.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
require 'kount/security_mash'
|
2
|
-
module Kount
|
3
|
-
##
|
4
|
-
# This class acts as an abstract class for each type of request.
|
5
|
-
class Request
|
6
|
-
attr_accessor :params
|
7
|
-
|
8
|
-
# Initialize a Request object
|
9
|
-
#
|
10
|
-
# Example usage
|
11
|
-
# Not used directly. Use Inquiry or Update instead.
|
12
|
-
#
|
13
|
-
# @param initial_params [Hash] Initial params for request
|
14
|
-
def initialize(initial_params = {})
|
15
|
-
fail "Cannot directly instantiate a #{self.class}." if
|
16
|
-
self.class == Request
|
17
|
-
@params = initial_params
|
18
|
-
end
|
19
|
-
|
20
|
-
# Add params to the current request object
|
21
|
-
# @param hash [Hash] Hash of values to be added
|
22
|
-
def add_params(hash)
|
23
|
-
@params.merge!(hash)
|
24
|
-
end
|
25
|
-
|
26
|
-
# This method creates the final state of the params collection such that
|
27
|
-
# it can be sent to RIS. Items that are specific to either the Inquiry
|
28
|
-
# or Update calls are delegated to the prepare_params method in each
|
29
|
-
# respective class.
|
30
|
-
#
|
31
|
-
# @param version [String] RIS version
|
32
|
-
# @param merchant_id [String] Merchant ID
|
33
|
-
# @param response_format [String] Response format (JSON)
|
34
|
-
# @param _ksalt [String] Kount supplied secret salt for KHASH
|
35
|
-
def prepare_params(version, merchant_id, response_format, _ksalt = '')
|
36
|
-
# The KSALT is not used here, however, it is used in the corresponding
|
37
|
-
# subclass prepare_params methods.
|
38
|
-
params.merge!(VERS: version, MERC: merchant_id, FRMT: response_format)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
require 'kount/security_mash'
|
2
|
+
module Kount
|
3
|
+
##
|
4
|
+
# This class acts as an abstract class for each type of request.
|
5
|
+
class Request
|
6
|
+
attr_accessor :params
|
7
|
+
|
8
|
+
# Initialize a Request object
|
9
|
+
#
|
10
|
+
# Example usage
|
11
|
+
# Not used directly. Use Inquiry or Update instead.
|
12
|
+
#
|
13
|
+
# @param initial_params [Hash] Initial params for request
|
14
|
+
def initialize(initial_params = {})
|
15
|
+
fail "Cannot directly instantiate a #{self.class}." if
|
16
|
+
self.class == Request
|
17
|
+
@params = initial_params
|
18
|
+
end
|
19
|
+
|
20
|
+
# Add params to the current request object
|
21
|
+
# @param hash [Hash] Hash of values to be added
|
22
|
+
def add_params(hash)
|
23
|
+
@params.merge!(hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
# This method creates the final state of the params collection such that
|
27
|
+
# it can be sent to RIS. Items that are specific to either the Inquiry
|
28
|
+
# or Update calls are delegated to the prepare_params method in each
|
29
|
+
# respective class.
|
30
|
+
#
|
31
|
+
# @param version [String] RIS version
|
32
|
+
# @param merchant_id [String] Merchant ID
|
33
|
+
# @param response_format [String] Response format (JSON)
|
34
|
+
# @param _ksalt [String] Kount supplied secret salt for KHASH
|
35
|
+
def prepare_params(version, merchant_id, response_format, _ksalt = '')
|
36
|
+
# The KSALT is not used here, however, it is used in the corresponding
|
37
|
+
# subclass prepare_params methods.
|
38
|
+
params.merge!(VERS: version, MERC: merchant_id, FRMT: response_format)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,85 +1,90 @@
|
|
1
|
-
module Kount
|
2
|
-
##
|
3
|
-
# This class extends the Request class.
|
4
|
-
class Inquiry < Request
|
5
|
-
attr_accessor :cart
|
6
|
-
|
7
|
-
# Initialize an Inquiry object
|
8
|
-
#
|
9
|
-
# Example usage
|
10
|
-
# {:MACK => "Y", :AUTH => "A"}
|
11
|
-
#
|
12
|
-
# @param initial_params [Hash] Initial params for request
|
13
|
-
def initialize(initial_params = {})
|
14
|
-
super(initial_params)
|
15
|
-
@cart = Cart.new
|
16
|
-
# We want Request to default to MODE Q unless a different mode has
|
17
|
-
# been passed.
|
18
|
-
add_params(MODE: 'Q') unless initial_params.key?(:MODE)
|
19
|
-
end
|
20
|
-
|
21
|
-
# @param version [String] RIS version
|
22
|
-
# @param merchant_id [String] Merchant ID
|
23
|
-
# @param response_format [String] Response format (JSON)
|
24
|
-
# @param ksalt [String] Kount supplied secret salt for KHASH
|
25
|
-
def prepare_params(version, merchant_id, response_format, ksalt)
|
26
|
-
super(version, merchant_id, response_format, ksalt)
|
27
|
-
begin
|
28
|
-
params.merge! collect_cart_items
|
29
|
-
# The Kount::Request has no knowledge of the KSALT or merchant_id, both
|
30
|
-
# of which are needed for KHASH. Request form params have everything we
|
31
|
-
# need at this point to do the KHASH if needed.
|
32
|
-
fixup_payment_params(ksalt, merchant_id)
|
33
|
-
end
|
34
|
-
params
|
35
|
-
end
|
36
|
-
|
37
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
38
|
-
def fixup_payment_params(ksalt, merchant_id)
|
39
|
-
ptok = params[:PTOK]
|
40
|
-
case params[:PTYP]
|
41
|
-
when 'CARD', 'TOKEN'
|
42
|
-
ptok = Kount::SecurityMash.hash_credit_card(ptok, ksalt)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
params.merge!(PTOK:
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
1
|
+
module Kount
|
2
|
+
##
|
3
|
+
# This class extends the Request class.
|
4
|
+
class Inquiry < Request
|
5
|
+
attr_accessor :cart
|
6
|
+
|
7
|
+
# Initialize an Inquiry object
|
8
|
+
#
|
9
|
+
# Example usage
|
10
|
+
# {:MACK => "Y", :AUTH => "A"}
|
11
|
+
#
|
12
|
+
# @param initial_params [Hash] Initial params for request
|
13
|
+
def initialize(initial_params = {})
|
14
|
+
super(initial_params)
|
15
|
+
@cart = Cart.new
|
16
|
+
# We want Request to default to MODE Q unless a different mode has
|
17
|
+
# been passed.
|
18
|
+
add_params(MODE: 'Q') unless initial_params.key?(:MODE)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param version [String] RIS version
|
22
|
+
# @param merchant_id [String] Merchant ID
|
23
|
+
# @param response_format [String] Response format (JSON)
|
24
|
+
# @param ksalt [String] Kount supplied secret salt for KHASH
|
25
|
+
def prepare_params(version, merchant_id, response_format, ksalt)
|
26
|
+
super(version, merchant_id, response_format, ksalt)
|
27
|
+
begin
|
28
|
+
params.merge! collect_cart_items
|
29
|
+
# The Kount::Request has no knowledge of the KSALT or merchant_id, both
|
30
|
+
# of which are needed for KHASH. Request form params have everything we
|
31
|
+
# need at this point to do the KHASH if needed.
|
32
|
+
fixup_payment_params(ksalt, merchant_id)
|
33
|
+
end
|
34
|
+
params
|
35
|
+
end
|
36
|
+
|
37
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
38
|
+
def fixup_payment_params(ksalt, merchant_id)
|
39
|
+
ptok = params[:PTOK]
|
40
|
+
case params[:PTYP]
|
41
|
+
when 'CARD', 'TOKEN'
|
42
|
+
#ptok = Kount::SecurityMash.hash_credit_card(ptok, ksalt)
|
43
|
+
ptok = Kount::Khash.HashPaymentToken(ptok, ksalt)
|
44
|
+
params.merge!(PTOK: ptok, PENC: 'KHASH')
|
45
|
+
when 'GIFT', 'OTHER'
|
46
|
+
#ptok = Kount::SecurityMash.hash_gift_card(ptok, ksalt, merchant_id)
|
47
|
+
ptok = Kount::Khash.HashGiftCard(ptok, ksalt, merchant_id)
|
48
|
+
params.merge!(PTOK: ptok, PENC: 'KHASH')
|
49
|
+
when 'CHEK', 'OTHER'
|
50
|
+
ptok = Kount::Khash.HashCheckPayment(ptok, ksalt)
|
51
|
+
params.merge!(PTOK: ptok, PENC: 'KHASH')
|
52
|
+
when 'NONE'
|
53
|
+
params.merge!(PTOK: nil, PENC: nil)
|
54
|
+
else
|
55
|
+
params[:PENC] ||= 'NONE'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Pulls the cart data into the request params hash
|
60
|
+
def collect_cart_items
|
61
|
+
{
|
62
|
+
PROD_TYPE: cart.get_item(:TYPE),
|
63
|
+
PROD_DESC: cart.get_item(:DESC),
|
64
|
+
PROD_ITEM: cart.get_item(:ITEM),
|
65
|
+
PROD_PRICE: cart.get_item(:PRICE),
|
66
|
+
PROD_QUANT: cart.get_item(:QUANT)
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
# Puts the cart object into the request for processing
|
71
|
+
# @param cart [Kount::Cart] Cart object
|
72
|
+
def add_cart(cart)
|
73
|
+
@cart = cart
|
74
|
+
end
|
75
|
+
|
76
|
+
# Add UDF to request
|
77
|
+
# @param name [String] UDF label name
|
78
|
+
# @param value [String] UDF value
|
79
|
+
def add_udf(name, value)
|
80
|
+
@params.merge!("UDF[#{name}]" => value)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Convenience method to create the payment params
|
84
|
+
# @param type [String] Payment type
|
85
|
+
# @param token [String] Payment token
|
86
|
+
def add_payment(type, token = '')
|
87
|
+
add_params(PTYP: type, PTOK: token)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/kount/request/update.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
module Kount
|
2
|
-
##
|
3
|
-
# This class extends the Request class and is used in the
|
4
|
-
# process of sending updates to an existing transaction
|
5
|
-
# generated by a previous Inquiry request.
|
6
|
-
class Update < Request
|
7
|
-
# Initialize an Update object
|
8
|
-
#
|
9
|
-
# Example usage
|
10
|
-
# {:MACK => "Y", :AUTH => "A"}
|
11
|
-
#
|
12
|
-
# @param initial_params [Hash] Initial params for request
|
13
|
-
def initialize(initial_params = {})
|
14
|
-
super(initial_params)
|
15
|
-
# Default to mode U unless mode X is explicitly set
|
16
|
-
add_params(MODE: 'U') unless initial_params[:MODE] == 'X'
|
17
|
-
end
|
18
|
-
|
19
|
-
# @param version [String] RIS version
|
20
|
-
# @param merchant_id [String] Merchant ID
|
21
|
-
# @param response_format [String] Response format (JSON)
|
22
|
-
# @param ksalt [String] Kount supplied secret salt for KHASH
|
23
|
-
def prepare_params(version, merchant_id, response_format, ksalt)
|
24
|
-
super(version, merchant_id, response_format, ksalt)
|
25
|
-
params
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module Kount
|
2
|
+
##
|
3
|
+
# This class extends the Request class and is used in the
|
4
|
+
# process of sending updates to an existing transaction
|
5
|
+
# generated by a previous Inquiry request.
|
6
|
+
class Update < Request
|
7
|
+
# Initialize an Update object
|
8
|
+
#
|
9
|
+
# Example usage
|
10
|
+
# {:MACK => "Y", :AUTH => "A"}
|
11
|
+
#
|
12
|
+
# @param initial_params [Hash] Initial params for request
|
13
|
+
def initialize(initial_params = {})
|
14
|
+
super(initial_params)
|
15
|
+
# Default to mode U unless mode X is explicitly set
|
16
|
+
add_params(MODE: 'U') unless initial_params[:MODE] == 'X'
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param version [String] RIS version
|
20
|
+
# @param merchant_id [String] Merchant ID
|
21
|
+
# @param response_format [String] Response format (JSON)
|
22
|
+
# @param ksalt [String] Kount supplied secret salt for KHASH
|
23
|
+
def prepare_params(version, merchant_id, response_format, ksalt)
|
24
|
+
super(version, merchant_id, response_format, ksalt)
|
25
|
+
params
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/kount/security_mash.rb
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
require 'digest/sha1'
|
2
|
-
module Kount
|
3
|
-
##
|
4
|
-
# This class implements the Kount KHASH for cards and gift cards.
|
5
|
-
# rubocop:disable Style/Documentation
|
6
|
-
class SecurityMash
|
7
|
-
# @param plain_text [String] String to be hashed
|
8
|
-
# @param ptyp [String] Payment type code: CARD, GIFT, or OTHER
|
9
|
-
# @return [String] KHASH version of string
|
10
|
-
def self.hash_token(plain_text, ptyp, ksalt, merchant_id = '')
|
11
|
-
if ptyp == 'CARD'
|
12
|
-
hash_credit_card(plain_text, ksalt)
|
13
|
-
else
|
14
|
-
hash_gift_card(plain_text, ksalt, merchant_id)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Hash a credit card number.
|
19
|
-
# Preserves first six characters of the input so that hashed cards can be
|
20
|
-
# categorized by Bank Identification Number (BIN).
|
21
|
-
#
|
22
|
-
# Example usage:
|
23
|
-
# hashed = Kount::SecurityMash.hash_credit_card("4111111111111111")
|
24
|
-
# Expect: 411111WMS5YA6FUZA1KC
|
25
|
-
# hashed = Kount::SecurityMash.hash_credit_card("5199185454061655")
|
26
|
-
# Expect: 5199182NOQRXNKTTFL11
|
27
|
-
# hashed = Kount::SecurityMash.hash_credit_card("4259344583883")
|
28
|
-
# Expect: 425934FEXQI1QS6TH2O5
|
29
|
-
#
|
30
|
-
# @param plain_text [String] String to be hashed
|
31
|
-
# @return [String] KHASH version of string
|
32
|
-
def self.hash_credit_card(plain_text, ksalt)
|
33
|
-
return plain_text if khashed?(plain_text)
|
34
|
-
first_six = plain_text[0..5]
|
35
|
-
mashed = mash(plain_text, 14, ksalt)
|
36
|
-
"#{first_six}#{mashed}"
|
37
|
-
end
|
38
|
-
|
39
|
-
# Hash a gift card number.
|
40
|
-
# Use the six characters of the merchant id so that hashed cards can be
|
41
|
-
# unique across the entire domain.
|
42
|
-
#
|
43
|
-
# Example usage:
|
44
|
-
# hashed = Kount::SecurityMash.hash_gift_card("123456", "3245876")
|
45
|
-
# Expect: 1234569HXH32Y5NNJCGB
|
46
|
-
|
47
|
-
# @param plain_text [String] String to be hashed
|
48
|
-
# @return [String] KHASH version of string
|
49
|
-
def self.hash_gift_card(plain_text, ksalt, merchant_id)
|
50
|
-
mashed = mash(plain_text, 14, ksalt)
|
51
|
-
"#{merchant_id}#{mashed}"
|
52
|
-
end
|
53
|
-
|
54
|
-
# Compute a base64 hash of the provided data.
|
55
|
-
#
|
56
|
-
# @param data [String] Data to hash
|
57
|
-
# @param len [int] Length of hash to retain
|
58
|
-
# @return [String] Hashed data
|
59
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
60
|
-
def self.mash(data, len, m)
|
61
|
-
a = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
62
|
-
r = Digest::SHA1.hexdigest("#{data}.#{m}")
|
63
|
-
c = ''
|
64
|
-
len = 17 if len > 17
|
65
|
-
limit = 2 * len
|
66
|
-
i = 0
|
67
|
-
while i < limit
|
68
|
-
c << a[r[i..i + 6].to_i(16) % 36]
|
69
|
-
i += 2
|
70
|
-
end
|
71
|
-
c
|
72
|
-
end
|
73
|
-
|
74
|
-
# end mash
|
75
|
-
|
76
|
-
# @param val [String] Token that may or may not be khashed
|
77
|
-
# @return [Boolean] True if token is already khashed
|
78
|
-
def self.khashed?(val)
|
79
|
-
true if val =~ /(\d{6}[A-Z0-9]{14})/
|
80
|
-
end
|
81
|
-
end # end KountSecurityMash
|
82
|
-
end
|
1
|
+
require 'digest/sha1'
|
2
|
+
module Kount
|
3
|
+
##
|
4
|
+
# This class implements the Kount KHASH for cards and gift cards.
|
5
|
+
# rubocop:disable Style/Documentation
|
6
|
+
class SecurityMash
|
7
|
+
# @param plain_text [String] String to be hashed
|
8
|
+
# @param ptyp [String] Payment type code: CARD, GIFT, or OTHER
|
9
|
+
# @return [String] KHASH version of string
|
10
|
+
def self.hash_token(plain_text, ptyp, ksalt, merchant_id = '')
|
11
|
+
if ptyp == 'CARD'
|
12
|
+
hash_credit_card(plain_text, ksalt)
|
13
|
+
else
|
14
|
+
hash_gift_card(plain_text, ksalt, merchant_id)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Hash a credit card number.
|
19
|
+
# Preserves first six characters of the input so that hashed cards can be
|
20
|
+
# categorized by Bank Identification Number (BIN).
|
21
|
+
#
|
22
|
+
# Example usage:
|
23
|
+
# hashed = Kount::SecurityMash.hash_credit_card("4111111111111111")
|
24
|
+
# Expect: 411111WMS5YA6FUZA1KC
|
25
|
+
# hashed = Kount::SecurityMash.hash_credit_card("5199185454061655")
|
26
|
+
# Expect: 5199182NOQRXNKTTFL11
|
27
|
+
# hashed = Kount::SecurityMash.hash_credit_card("4259344583883")
|
28
|
+
# Expect: 425934FEXQI1QS6TH2O5
|
29
|
+
#
|
30
|
+
# @param plain_text [String] String to be hashed
|
31
|
+
# @return [String] KHASH version of string
|
32
|
+
def self.hash_credit_card(plain_text, ksalt)
|
33
|
+
return plain_text if khashed?(plain_text)
|
34
|
+
first_six = plain_text[0..5]
|
35
|
+
mashed = mash(plain_text, 14, ksalt)
|
36
|
+
"#{first_six}#{mashed}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Hash a gift card number.
|
40
|
+
# Use the six characters of the merchant id so that hashed cards can be
|
41
|
+
# unique across the entire domain.
|
42
|
+
#
|
43
|
+
# Example usage:
|
44
|
+
# hashed = Kount::SecurityMash.hash_gift_card("123456", "3245876")
|
45
|
+
# Expect: 1234569HXH32Y5NNJCGB
|
46
|
+
|
47
|
+
# @param plain_text [String] String to be hashed
|
48
|
+
# @return [String] KHASH version of string
|
49
|
+
def self.hash_gift_card(plain_text, ksalt, merchant_id)
|
50
|
+
mashed = mash(plain_text, 14, ksalt)
|
51
|
+
"#{merchant_id}#{mashed}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Compute a base64 hash of the provided data.
|
55
|
+
#
|
56
|
+
# @param data [String] Data to hash
|
57
|
+
# @param len [int] Length of hash to retain
|
58
|
+
# @return [String] Hashed data
|
59
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
60
|
+
def self.mash(data, len, m)
|
61
|
+
a = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
62
|
+
r = Digest::SHA1.hexdigest("#{data}.#{m}")
|
63
|
+
c = ''
|
64
|
+
len = 17 if len > 17
|
65
|
+
limit = 2 * len
|
66
|
+
i = 0
|
67
|
+
while i < limit
|
68
|
+
c << a[r[i..i + 6].to_i(16) % 36]
|
69
|
+
i += 2
|
70
|
+
end
|
71
|
+
c
|
72
|
+
end
|
73
|
+
|
74
|
+
# end mash
|
75
|
+
|
76
|
+
# @param val [String] Token that may or may not be khashed
|
77
|
+
# @return [Boolean] True if token is already khashed
|
78
|
+
def self.khashed?(val)
|
79
|
+
true if val =~ /(\d{6}[A-Z0-9]{14})/
|
80
|
+
end
|
81
|
+
end # end KountSecurityMash
|
82
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Kount
|
2
|
+
class Khash
|
3
|
+
# @param plain_text [String] String to be hashed
|
4
|
+
# @param ptyp [String] Payment type code: CARD, GIFT, or OTHER
|
5
|
+
# @return [String] KHASH version of string
|
6
|
+
def self.hash_token(plain_text, ptyp, ksalt, merchant_id = '')
|
7
|
+
if ptyp == 'CARD'
|
8
|
+
HashPaymentToken(plain_text, ksalt)
|
9
|
+
elsif ptyp == 'CHEK'
|
10
|
+
HashCheckPayment(plain_text, ksalt)
|
11
|
+
else
|
12
|
+
HashGiftCard(plain_text, ksalt, merchant_id)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.getKhash(data, len, m)
|
17
|
+
a = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
18
|
+
r = Digest::SHA1.hexdigest("#{data}.#{m}")
|
19
|
+
c = ''
|
20
|
+
len = 17 if len > 17
|
21
|
+
limit = 2 * len
|
22
|
+
i = 0
|
23
|
+
while i < limit
|
24
|
+
c << a[r[i..i + 6].to_i(16) % 36]
|
25
|
+
i += 2
|
26
|
+
end
|
27
|
+
c
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.HashPaymentToken(plain_text, ksalt)
|
31
|
+
first_six = plain_text[0..5]
|
32
|
+
mashed = getKhash(plain_text, 14, ksalt)
|
33
|
+
"#{first_six}#{mashed}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.HashCheckPayment(plain_text, ksalt)
|
37
|
+
first_six = plain_text[0..5]
|
38
|
+
mashed = getKhash(plain_text, 14, ksalt)
|
39
|
+
"#{first_six}#{mashed}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.HashGiftCard(plain_text, ksalt, merchant_id)
|
43
|
+
mashed = getKhash(plain_text, 14, ksalt)
|
44
|
+
"#{merchant_id}#{mashed}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kount_complete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kount
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
description: A wrapper to facilitate making Kount RIS calls
|
48
|
-
email:
|
48
|
+
email: ruby@kount.com
|
49
49
|
executables: []
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/kount/request/inquiry.rb
|
59
59
|
- lib/kount/request/update.rb
|
60
60
|
- lib/kount/security_mash.rb
|
61
|
+
- lib/kount/utils/khash.rb
|
61
62
|
homepage: http://rubygems.org/gems/kount_complete
|
62
63
|
licenses:
|
63
64
|
- MIT
|
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
79
|
version: 1.3.5
|
79
80
|
requirements: []
|
80
81
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.7.
|
82
|
+
rubygems_version: 2.7.6.2
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: Kount Complete Services Wrapper
|