class Minfraud::Transaction

This is the container for the data you’re sending to MaxMind. A transaction holds data like name, address, IP, order amount, etc.

Attributes

accept_language[RW]

Transaction linking attribute (optional)

amount[RW]

Transaction attribute (optional)

avs_result[RW]

Credit card result attribute (optional)

bin[RW]

Credit card attribute (optional)

city[RW]

Required attribute

country[RW]

Required attribute

currency[RW]

Transaction attribute (optional)

cvv_result[RW]

Credit card result attribute (optional)

email[RW]

User attribute (optional)

forwarded_ip[RW]

Miscellaneous attribute (optional)

ip[RW]

Required attribute

phone[RW]

User attribute (optional)

postal[RW]

Required attribute

requested_type[RW]

Miscellaneous attribute (optional)

session_id[RW]

Transaction linking attribute (optional)

ship_addr[RW]

Shipping address attribute (optional)

ship_city[RW]

Shipping address attribute (optional)

ship_country[RW]

Shipping address attribute (optional)

ship_postal[RW]

Shipping address attribute (optional)

ship_state[RW]

Shipping address attribute (optional)

state[RW]

Required attribute

txn_id[RW]

Transaction attribute (optional)

txn_type[RW]

Transaction attribute (optional)

user_agent[RW]

Transaction linking attribute (optional)

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/minfraud/transaction.rb, line 33
def initialize
  yield self
  unless has_required_attributes?
    raise TransactionError, 'You did not set all the required transaction attributes.'
  end
  validate_attributes
end

Public Instance Methods

attributes() click to toggle source

Hash of attributes that have been set @return [Hash] present attributes

# File lib/minfraud/transaction.rb, line 51
def attributes
  attrs = [:ip, :city, :state, :postal, :country, :license_key, :ship_addr, :ship_city, :ship_state, :ship_postal, :ship_country, :email_domain, :email_md5, :phone, :bin, :session_id, :user_agent, :accept_language, :txn_id, :amount, :currency, :txn_type, :avs_result, :cvv_result, :requested_type, :forwarded_ip]
  attrs.map! do |a|
    [a, send(a)]
  end
  Hash[attrs]
end
risk_score() click to toggle source

Retrieves the risk score from MaxMind. A higher score indicates a higher risk of fraud. For example, a score of 20 indicates a 20% chance that a transaction is fraudulent. @return [Float] 0.01 - 100.0

# File lib/minfraud/transaction.rb, line 45
def risk_score
  results.risk_score
end

Private Instance Methods

email_domain() click to toggle source

@return [String, nil] domain of the email address

# File lib/minfraud/transaction.rb, line 98
def email_domain
  email.to_s.split('@').last
end
email_md5() click to toggle source

@return [String, nil] MD5 hash of the whole email address

# File lib/minfraud/transaction.rb, line 103
def email_md5
  Digest::MD5.hexdigest(email.to_s)
end
has_required_attributes?() click to toggle source

Ensures the required attributes are present @return [Boolean]

# File lib/minfraud/transaction.rb, line 69
def has_required_attributes?
  ip and city and state and postal and country
end
license_key() click to toggle source

@return [String] license key set during configuration

# File lib/minfraud/transaction.rb, line 108
def license_key
  Minfraud.license_key
end
results() click to toggle source

Sends transaction to MaxMind in order to get risk data on it. Caches response object in @response. @return [Response]

# File lib/minfraud/transaction.rb, line 93
def results
  @response ||= Request.get(self)
end
validate_attributes() click to toggle source

Validates the types of the attributes @return [nil, TransactionError]

# File lib/minfraud/transaction.rb, line 75
def validate_attributes
  [:ip, :city, :state, :postal, :country].each { |s| validate_string(s) }
end
validate_string(attr_name) click to toggle source

Given the symbol of an attribute that should be a string, it checks the attribute’s type and throws an error if it’s not a string. @param attr_name [Symbol] name of the attribute to validate @return [nil, TransactionError]

# File lib/minfraud/transaction.rb, line 83
def validate_string(attr_name)
  attribute = self.send(attr_name)
  unless attribute.instance_of?(String)
    raise TransactionError, "Transaction.#{attr_name} must me a string"
  end
end