kount_complete 1.0.9 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
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,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 = '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
- }
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
data/lib/kount/request.rb CHANGED
@@ -1,41 +1,39 @@
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
+ @params = initial_params
16
+ end
17
+
18
+ # Add params to the current request object
19
+ # @param hash [Hash] Hash of values to be added
20
+ def add_params(hash)
21
+ @params.merge!(hash)
22
+ end
23
+
24
+ # This method creates the final state of the params collection such that
25
+ # it can be sent to RIS. Items that are specific to either the Inquiry
26
+ # or Update calls are delegated to the prepare_params method in each
27
+ # respective class.
28
+ #
29
+ # @param version [String] RIS version
30
+ # @param merchant_id [String] Merchant ID
31
+ # @param response_format [String] Response format (JSON)
32
+ # @param _ksalt [String] Kount supplied secret salt for KHASH
33
+ def prepare_params(version, merchant_id, response_format, _ksalt = '')
34
+ # The KSALT is not used here, however, it is used in the corresponding
35
+ # subclass prepare_params methods.
36
+ params.merge!(VERS: version, MERC: merchant_id, FRMT: response_format)
37
+ end
38
+ end
39
+ end