Class: Kount::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kount/client.rb

Overview

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

Constant Summary collapse

RESPONSE_FORMAT =

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

'JSON'
DEFAULT_VERSION =

RIS Version. Can be overridden my merchant if required.

'0700'
ENDPOINT_PROD =

Default endpoint for production. Used by the DEFAULT_OPTIONS

'https://risk.kount.net'
ENDPOINT_TEST =

Default endpoint for test. Used by the TEST_DEFAULT_OPTIONS

'https://risk.test.kount.net'
PROD_DEFAULT_OPTIONS =

Default params for production

{
  endpoint: ENDPOINT_PROD,
  version: DEFAULT_VERSION,
  is_test: false,
  timeout: 10
}
TEST_DEFAULT_OPTIONS =

Default params for test if is_test is TRUE

{
  endpoint: ENDPOINT_TEST,
  version: DEFAULT_VERSION,
  timeout: 10
}

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Client

Initialize a client object

Example usage

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

other optional params

Parameters:

  • params (Hash) (defaults to: {})

    Hash with merchant_id, ksalt and key, plus any



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kount/client.rb', line 52

def initialize(params = {})
  @logger = Logger.new("Logs.log")
  @options = {}
  if params[:is_test]
    @options.merge!(TEST_DEFAULT_OPTIONS)
  else
    @options.merge!(PROD_DEFAULT_OPTIONS)
  end
  @options.merge!(params)
  @logger.info("Options Params : #{@options}")
end

Instance Method Details

#endpointObject

RIS Endpoint URL



112
113
114
# File 'lib/kount/client.rb', line 112

def endpoint
  @options[:endpoint]
end

#get_response(request) ⇒ Hash

Makes the call to the Kount RIS server

Parameters:

Returns:

  • (Hash)

    RIS response formatted into a native hash



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kount/client.rb', line 68

def get_response(request)
  params = prepare_request_params(request)
  response = {}
  begin
    response = RestClient::Resource.new(
      endpoint,
      verify_ssl: verify_ssl_option, timeout: timeout, log: @logger
    ).post params, x_kount_api_key: key

    @logger.info("Response Object : #{JSON.parse(response)}")
    JSON.parse(response)
  rescue StandardError
    # RIS errors do not come back as JSON, so just pass them along raw.
    # @logger.error("Error : Network Timeout Getting #{response} Response.
    #   Your Timeout option valus is #{timeout}, 
    #   Use Default timeout which is 10 sec.")
    if response.empty?
      @logger.debug("Network Timeout Getting #{response} Response.
        Current Timeout option valus is #{timeout}, 
        Use Default timeout which is 10 sec.")
    else
      @logger.error("#{response}")
    end
    response
  end
end

#keyObject

Merchant API for RIS acess



122
123
124
# File 'lib/kount/client.rb', line 122

def key
  @options[:key]
end

#ksaltObject

Secret Kount salt for KHASH



127
128
129
# File 'lib/kount/client.rb', line 127

def ksalt
  @options[:ksalt]
end

#merchant_idObject

Kount Merchant ID



102
103
104
# File 'lib/kount/client.rb', line 102

def merchant_id
  @options[:merchant_id]
end

#prepare_request_params(request) ⇒ Object

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



97
98
99
# File 'lib/kount/client.rb', line 97

def prepare_request_params(request)
  request.prepare_params(version, merchant_id, RESPONSE_FORMAT, ksalt)
end

#test?Boolean

Is test or production setting

Returns:

  • (Boolean)


132
133
134
# File 'lib/kount/client.rb', line 132

def test?
  @options[:is_test]
end

#timeoutObject

Timeout settings



117
118
119
# File 'lib/kount/client.rb', line 117

def timeout
  @options[:timeout]
end

#versionObject

RIS Interface Version



107
108
109
# File 'lib/kount/client.rb', line 107

def version
  @options[:version]
end