Class: Workarea::Checkout::Fraud::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
app/models/workarea/checkout/fraud/analyzer.rb

Direct Known Subclasses

NoDecisionAnalyzer, TestAnalyzer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(checkout) ⇒ Analyzer

Returns a new instance of Analyzer.



11
12
13
# File 'app/models/workarea/checkout/fraud/analyzer.rb', line 11

def initialize(checkout)
  @checkout = checkout
end

Instance Attribute Details

#checkoutObject (readonly)

Returns the value of attribute checkout.



5
6
7
# File 'app/models/workarea/checkout/fraud/analyzer.rb', line 5

def checkout
  @checkout
end

Instance Method Details

#decide!Object



15
16
17
18
19
20
21
22
23
# File 'app/models/workarea/checkout/fraud/analyzer.rb', line 15

def decide!
  begin
    decision = make_decision.tap { |r| r.analyzer = self.class.name }
  rescue => e
    decision = error_decision(e.message)
  ensure
    order.set_fraud_decision!(decision)
  end
end

#error_decision(message) ⇒ Object



35
36
37
38
39
40
# File 'app/models/workarea/checkout/fraud/analyzer.rb', line 35

def error_decision(message)
  Workarea::Order::FraudDecision.new(
    decision: :no_decision,
    message: "An error occured during the fraud check: #{message}"
  )
end

#make_decision(checkout = nil) ⇒ Workarea::Order::FraudDecision

Gets a decision about the fraudlence of a given checkout

Parameters:

Returns:

Raises:

  • (NotImplementedError)


31
32
33
# File 'app/models/workarea/checkout/fraud/analyzer.rb', line 31

def make_decision(checkout = nil)
  raise(NotImplementedError, "#{self.class} must implement the #make_decision method")
end