kount_complete 2.0.0 → 2.0.5

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.
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,128 +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 = '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
- # Merchant API for RIS acess
103
- def key
104
- @options[:key]
105
- end
106
-
107
- # Secret Kount salt for KHASH
108
- def ksalt
109
- @options[:ksalt]
110
- end
111
-
112
- # Is test or production setting
113
- def test?
114
- @options[:is_test]
115
- end
116
-
117
- private
118
-
119
- # Helper method to turn on/off the SSL cert verify based on is_test config
120
- def verify_ssl_option
121
- if test?
122
- OpenSSL::SSL::VERIFY_NONE
123
- else
124
- OpenSSL::SSL::VERIFY_PEER
125
- end
126
- end
127
- end
128
- 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 = '0710'
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
- 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
+ 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