Class: Minfraud::FraudReportAssessment

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

Overview

Builds a minFraud Insights request for an order/payment, calls the Insights
API via InsightsClient, and maps the response onto the given FraudReport.

Extracted from Order::FraudDetector so that service stays focused on fraud
orchestration and decisioning, and so the request/response mapping lives
alongside the client it talks to. Request keys and response fields match the
MaxMind schema (the same data the minfraud gem sent and parsed).

See Also:

Constant Summary collapse

PAYMENT_METHOD_MAP =

Maps a Heatwave Payment category to a minFraud payment.method value.

{
  Payment::CREDIT_CARD => 'card',
  Payment::CREDIT_CARD_TERMINAL => 'card',
  Payment::PAYPAL => 'digital_wallet',
  Payment::PAYPAL_INVOICE => 'digital_wallet',
  Payment::ECHECK => 'bank_debit',
  Payment::CHECK => 'bank_debit',
  Payment::WIRE => 'bank_transfer',
  Payment::AMAZON_PAY => 'digital_wallet'
}.freeze
AVS_CODES =

AVS result code, keyed by [card is US?, address_line1_check,
address_zip_check]. The unavailable cases are handled separately.

{
  [true, 'pass', 'pass'] => 'Y',  # US: street + 5-digit zip match
  [true, 'pass', 'fail'] => 'A',  # US: street matches, zip does not
  [true, 'fail', 'pass'] => 'Z',  # US: zip matches, street does not
  [true, 'fail', 'fail'] => 'N',  # US: neither matches
  [false, 'pass', 'pass'] => 'M', # non-US: street + postal match
  [false, 'pass', 'fail'] => 'B', # non-US: street matches, postal not verified
  [false, 'fail', 'pass'] => 'P', # non-US: postal matches, street not verified
  [false, 'fail', 'fail'] => 'C'  # non-US: neither matches
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(order, payment, fraud_report, is_pickup:) ⇒ FraudReportAssessment

Returns a new instance of FraudReportAssessment.

Parameters:

  • order (Order)

    the order being assessed.

  • payment (Payment)

    the authorization being assessed.

  • fraud_report (FraudReport)

    populated in place by #assess!.

  • is_pickup (Boolean)

    warehouse-pickup orders omit shipping data.



44
45
46
47
48
49
# File 'app/services/minfraud/fraud_report_assessment.rb', line 44

def initialize(order, payment, fraud_report, is_pickup:)
  @order = order
  @payment = payment
  @fr = fraud_report
  @is_pickup = is_pickup
end

Instance Method Details

#assess!void

This method returns an undefined value.

Run the assessment, mutating the FraudReport in place. Network / parse
failures are non-fatal: they record fraud_report.minfraud_error and
report the exception, leaving the rest of the report intact.



56
57
58
59
60
61
# File 'app/services/minfraud/fraud_report_assessment.rb', line 56

def assess!
  store_insights(client.insights(request))
rescue StandardError => e
  @fr.minfraud_error = e.message
  ErrorReporting.error e
end