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.
@@ -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
- # 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
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
@@ -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
@@ -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
+ 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.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
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