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
Transaction
linking attribute (optional)
Transaction
attribute (optional)
Credit card result attribute (optional)
Credit card attribute (optional)
Required attribute
Required attribute
Transaction
attribute (optional)
Credit card result attribute (optional)
User attribute (optional)
Miscellaneous attribute (optional)
Required attribute
User attribute (optional)
Required attribute
Miscellaneous attribute (optional)
Transaction
linking attribute (optional)
Shipping address attribute (optional)
Shipping address attribute (optional)
Shipping address attribute (optional)
Shipping address attribute (optional)
Shipping address attribute (optional)
Required attribute
Transaction
attribute (optional)
Transaction
attribute (optional)
Transaction
linking attribute (optional)
Public Class Methods
# 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
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
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
@return [String, nil] domain of the email address
# File lib/minfraud/transaction.rb, line 98 def email_domain email.to_s.split('@').last end
@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
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
@return [String] license key set during configuration
# File lib/minfraud/transaction.rb, line 108 def license_key Minfraud.license_key end
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
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
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