class Kount::Client

This class is where the primary interaction with the merchant integration will take place.

Constants

DEFAULT_VERSION

RIS Version. Can be overridden my merchant if required.

ENDPOINT_PROD

Default endpoint for production. Used by the DEFAULT_OPTIONS

ENDPOINT_TEST

Default endpoint for test. Used by the TEST_DEFAULT_OPTIONS

PROD_DEFAULT_OPTIONS

Default params for production

RESPONSE_FORMAT

Tells the RIS server to respond in JSON instead of key/value pairs This cannot be overridden.

TEST_DEFAULT_OPTIONS

Default params for test if is_test is TRUE

Public Class Methods

new(params = {}) click to toggle source

Initialize a client object

Example usage

{:merchant_id => "123456", :key => "trhvihsrihsta7ftadk6edkre7y8..."}

@param params [Hash] Hash with merchant_id, ksalt and key, plus any other optional params

# File lib/kount/client.rb, line 50
def initialize(params = {})
  @options = {}
  if params[:is_test]
    @options.merge!(TEST_DEFAULT_OPTIONS)
  else
    @options.merge!(PROD_DEFAULT_OPTIONS)
  end
  @options.merge!(params)
end

Public Instance Methods

endpoint() click to toggle source

RIS Endpoint URL

# File lib/kount/client.rb, line 97
def endpoint
  @options[:endpoint]
end
get_response(request) click to toggle source

Makes the call to the Kount RIS server

@param request [Kount::Request] Kount inquiry or update object @return [Hash] RIS response formatted into a native hash

# File lib/kount/client.rb, line 64
def get_response(request)
  params = prepare_request_params(request)
  response = {}
  begin
    response = RestClient::Resource.new(
      endpoint,
      verify_ssl: verify_ssl_option, timeout: timeout
    ).post params, x_kount_api_key: key

    JSON.parse(response)
  rescue StandardError
    # RIS errors do not come back as JSON, so just pass them along raw.
    response
  end
end
key() click to toggle source

Merchant API for RIS acess

# File lib/kount/client.rb, line 107
def key
  @options[:key]
end
ksalt() click to toggle source

Secret Kount salt for KHASH

# File lib/kount/client.rb, line 112
def ksalt
  @options[:ksalt]
end
merchant_id() click to toggle source

Kount Merchant ID

# File lib/kount/client.rb, line 87
def merchant_id
  @options[:merchant_id]
end
prepare_request_params(request) click to toggle source

Give the request object what it needs to know to process the params to send to RIS.

# File lib/kount/client.rb, line 82
def prepare_request_params(request)
  request.prepare_params(version, merchant_id, RESPONSE_FORMAT, ksalt)
end
test?() click to toggle source

Is test or production setting

# File lib/kount/client.rb, line 117
def test?
  @options[:is_test]
end
timeout() click to toggle source

Timeout settings

# File lib/kount/client.rb, line 102
def timeout
  @options[:timeout]
end
version() click to toggle source

RIS Interface Version

# File lib/kount/client.rb, line 92
def version
  @options[:version]
end

Private Instance Methods

verify_ssl_option() click to toggle source

Helper method to turn on/off the SSL cert verify based on is_test config

# File lib/kount/client.rb, line 124
def verify_ssl_option
  if test?
    OpenSSL::SSL::VERIFY_NONE
  else
    OpenSSL::SSL::VERIFY_PEER
  end
end