Class: Minfraud::InsightsClient

Inherits:
Object
  • Object
show all
Defined in:
app/services/minfraud/insights_client.rb

Overview

Direct Faraday client for the MaxMind minFraud Insights endpoint.

Replaces the minfraud gem, which was dropped so the bundle could move off
the gem's connection_pool < 3 and http < 6.0 version ceilings (it
transitively pinned maxmind-geoip2, which is unused elsewhere — geocoder's
:maxmind_geoip2 IP lookup is geocoder-native, not this gem). We only ever
called the Insights endpoint; the request and response shapes here match
exactly what the gem sent and parsed.

Defined Under Namespace

Classes: Error

Constant Summary collapse

HOST =
'https://minfraud.maxmind.com'
PATH =
'/minfraud/v2.0/insights'
BOOLEAN_KEYS =

Request fields the API expects as JSON booleans. The gem stringified every
other scalar; we mirror that so the wire format is unchanged.

%w[was_authorized is_gift has_gift_message].freeze

Instance Method Summary collapse

Constructor Details

#initialize(account_id:, license_key:) ⇒ InsightsClient

Returns a new instance of InsightsClient.

Parameters:

  • account_id (Integer, String)

    MaxMind account ID (basic-auth user).

  • license_key (String)

    MaxMind license key (basic-auth password).



29
30
31
32
# File 'app/services/minfraud/insights_client.rb', line 29

def initialize(account_id:, license_key:)
  @account_id  = 
  @license_key = license_key
end

Instance Method Details

#insights(request) ⇒ Hash

Perform a minFraud Insights request.

Parameters:

  • request (Hash)

    nested component hashes (:device, :event, :account,
    :email, :billing, :shipping, :payment, :credit_card, :order).

Returns:

  • (Hash)

    the parsed Insights response.

Raises:



40
41
42
43
44
45
46
47
# File 'app/services/minfraud/insights_client.rb', line 40

def insights(request)
  response = connection.post(PATH, serialize(request))
  return response.body if response.success?

  raise Error, error_message(response)
rescue Faraday::Error => e
  raise Error, e.message
end