kount_complete 1.0.7 → 2.0.3
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/lib/kount.rb +28 -28
- data/lib/kount/Response.rb +344 -0
- data/lib/kount/cart.rb +36 -36
- data/lib/kount/client.rb +133 -125
- data/lib/kount/payment_types.rb +52 -52
- data/lib/kount/request.rb +41 -41
- data/lib/kount/request/inquiry.rb +90 -90
- data/lib/kount/request/update.rb +28 -28
- data/lib/kount/security_mash.rb +82 -82
- data/lib/kount/utils/khash.rb +56 -47
- metadata +5 -5
data/lib/kount/client.rb
CHANGED
@@ -1,125 +1,133 @@
|
|
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
|
-
|
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 = '
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@options.merge!(
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
#
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
response
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
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
|
+
require 'kount/utils/khash'
|
9
|
+
|
10
|
+
|
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 = '0700'
|
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
|
+
timeout: 10
|
35
|
+
}
|
36
|
+
|
37
|
+
# Default params for test if is_test is TRUE
|
38
|
+
TEST_DEFAULT_OPTIONS = {
|
39
|
+
endpoint: ENDPOINT_TEST,
|
40
|
+
version: DEFAULT_VERSION,
|
41
|
+
timeout: 10
|
42
|
+
}
|
43
|
+
|
44
|
+
# Initialize a client object
|
45
|
+
#
|
46
|
+
# Example usage
|
47
|
+
# {:merchant_id => "123456", :key => "trhvihsrihsta7ftadk6edkre7y8..."}
|
48
|
+
#
|
49
|
+
# @param params [Hash] Hash with merchant_id, ksalt and key, plus any
|
50
|
+
# other optional params
|
51
|
+
def initialize(params = {})
|
52
|
+
@options = {}
|
53
|
+
if params[:is_test]
|
54
|
+
@options.merge!(TEST_DEFAULT_OPTIONS)
|
55
|
+
else
|
56
|
+
@options.merge!(PROD_DEFAULT_OPTIONS)
|
57
|
+
end
|
58
|
+
@options.merge!(params)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Makes the call to the Kount RIS server
|
62
|
+
#
|
63
|
+
# @param request [Kount::Request] Kount inquiry or update object
|
64
|
+
# @return [Hash] RIS response formatted into a native hash
|
65
|
+
def get_response(request)
|
66
|
+
params = prepare_request_params(request)
|
67
|
+
response = {}
|
68
|
+
begin
|
69
|
+
response = RestClient::Resource.new(
|
70
|
+
endpoint,
|
71
|
+
verify_ssl: verify_ssl_option, timeout: timeout
|
72
|
+
).post params, x_kount_api_key: key
|
73
|
+
|
74
|
+
JSON.parse(response)
|
75
|
+
rescue StandardError
|
76
|
+
# RIS errors do not come back as JSON, so just pass them along raw.
|
77
|
+
response
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Give the request object what it needs to know to process the params
|
82
|
+
# to send to RIS.
|
83
|
+
def prepare_request_params(request)
|
84
|
+
request.prepare_params(version, merchant_id, RESPONSE_FORMAT, ksalt)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Kount Merchant ID
|
88
|
+
def merchant_id
|
89
|
+
@options[:merchant_id]
|
90
|
+
end
|
91
|
+
|
92
|
+
# RIS Interface Version
|
93
|
+
def version
|
94
|
+
@options[:version]
|
95
|
+
end
|
96
|
+
|
97
|
+
# RIS Endpoint URL
|
98
|
+
def endpoint
|
99
|
+
@options[:endpoint]
|
100
|
+
end
|
101
|
+
|
102
|
+
# Timeout settings
|
103
|
+
def timeout
|
104
|
+
@options[:timeout]
|
105
|
+
end
|
106
|
+
|
107
|
+
# Merchant API for RIS acess
|
108
|
+
def key
|
109
|
+
@options[:key]
|
110
|
+
end
|
111
|
+
|
112
|
+
# Secret Kount salt for KHASH
|
113
|
+
def ksalt
|
114
|
+
@options[:ksalt]
|
115
|
+
end
|
116
|
+
|
117
|
+
# Is test or production setting
|
118
|
+
def test?
|
119
|
+
@options[:is_test]
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
# Helper method to turn on/off the SSL cert verify based on is_test config
|
125
|
+
def verify_ssl_option
|
126
|
+
if test?
|
127
|
+
OpenSSL::SSL::VERIFY_NONE
|
128
|
+
else
|
129
|
+
OpenSSL::SSL::VERIFY_PEER
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
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
|
-
|
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
|
+
raise "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,90 +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
|
-
ptok = Kount::Khash.
|
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.
|
48
|
-
params.merge!(PTOK: ptok, PENC: 'KHASH')
|
49
|
-
when 'CHEK', 'OTHER'
|
50
|
-
ptok = Kount::Khash.
|
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
|
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.hash_payment_token(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.hash_gift_card(ptok, ksalt, merchant_id)
|
48
|
+
params.merge!(PTOK: ptok, PENC: 'KHASH')
|
49
|
+
when 'CHEK', 'OTHER'
|
50
|
+
ptok = Kount::Khash.hash_check_payment(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
|