Sha256: f034f6eeac72168cb148bacde613b8dbef6e46f00710912d0097f8d5429714f9

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Workarea
  module Kount
    class Gateway
      delegate :merchant_id, :key, :ksalt, to: Workarea::Kount
      attr_reader :options

      RESPONSE_FORMAT = 'JSON'

      VERSION = '0630'
      ENDPOINT_PROD = 'https://risk.kount.net'
      ENDPOINT_TEST = 'https://risk.test.kount.net'

      def initialize(options = {})
        @options = options
      end

      def call(body)
        body = body.merge(VERS: VERSION, MERC: Kount.merchant_id, FRMT: RESPONSE_FORMAT)

        response = RestClient::Resource
          .new(endpoint, verify_ssl: verify_ssl_option, timeout: 1)
          .post(body, x_kount_api_key: Kount.key)

        begin
          Response.new(JSON.parse(response))
        rescue
          Response.from_error(response.body)
        end
      end

      private

        def test?
          options.fetch(:is_test, false)
        end

        def endpoint
          test? ? ENDPOINT_TEST : ENDPOINT_PROD
        end

        def verify_ssl_option
          if test?
            OpenSSL::SSL::VERIFY_NONE
          else
            OpenSSL::SSL::VERIFY_PEER
          end
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-kount-3.3.1 lib/workarea/kount/gateway.rb
workarea-kount-3.3.0 lib/workarea/kount/gateway.rb