minfraud 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -30
- data/.travis.yml +0 -1
- data/CHANGELOG.md +13 -0
- data/README.md +169 -54
- data/lib/maxmind/geoip2/record/traits.rb +9 -0
- data/lib/minfraud.rb +15 -0
- data/lib/minfraud/assessments.rb +107 -51
- data/lib/minfraud/components/account.rb +29 -9
- data/lib/minfraud/components/addressable.rb +71 -26
- data/lib/minfraud/components/base.rb +20 -10
- data/lib/minfraud/components/billing.rb +3 -0
- data/lib/minfraud/components/credit_card.rb +62 -20
- data/lib/minfraud/components/custom_inputs.rb +12 -3
- data/lib/minfraud/components/device.rb +43 -15
- data/lib/minfraud/components/email.rb +27 -7
- data/lib/minfraud/components/event.rb +46 -12
- data/lib/minfraud/components/order.rb +56 -21
- data/lib/minfraud/components/payment.rb +33 -13
- data/lib/minfraud/components/report/transaction.rb +44 -33
- data/lib/minfraud/components/shipping.rb +12 -5
- data/lib/minfraud/components/shopping_cart.rb +15 -11
- data/lib/minfraud/components/shopping_cart_item.rb +40 -11
- data/lib/minfraud/enum.rb +16 -5
- data/lib/minfraud/error_handler.rb +17 -4
- data/lib/minfraud/errors.rb +20 -2
- data/lib/minfraud/http_service.rb +10 -5
- data/lib/minfraud/http_service/request.rb +17 -19
- data/lib/minfraud/http_service/response.rb +15 -12
- data/lib/minfraud/model/subscores.rb +3 -0
- data/lib/minfraud/report.rb +28 -10
- data/lib/minfraud/resolver.rb +11 -5
- data/lib/minfraud/validates.rb +187 -0
- data/lib/minfraud/version.rb +2 -1
- data/minfraud.gemspec +4 -2
- metadata +45 -9
@@ -2,43 +2,68 @@
|
|
2
2
|
|
3
3
|
module Minfraud
|
4
4
|
module Components
|
5
|
+
# CreditCard corresponds to the credit_card object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Credit_Card_(/creditcard)
|
5
8
|
class CreditCard < Base
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
+
include Minfraud::Validates
|
10
|
+
|
11
|
+
# The issuer ID number for the credit card. This is the first 6 digits of
|
12
|
+
# the credit card number. It identifies the issuing bank.
|
13
|
+
#
|
14
|
+
# @return [String, nil]
|
9
15
|
attr_accessor :issuer_id_number
|
10
16
|
|
11
|
-
#
|
12
|
-
#
|
17
|
+
# The last four digits of the credit card number.
|
18
|
+
#
|
19
|
+
# @return [String, nil]
|
13
20
|
attr_accessor :last_4_digits
|
14
21
|
|
15
|
-
#
|
16
|
-
#
|
22
|
+
# The name of the issuing bank as provided by the end user.
|
23
|
+
#
|
24
|
+
# @return [String, nil]
|
17
25
|
attr_accessor :bank_name
|
18
26
|
|
19
|
-
#
|
20
|
-
#
|
27
|
+
# The phone country code for the issuing bank as provided by the end
|
28
|
+
# user. If you provide this information then you must provide at least
|
29
|
+
# one digit.
|
30
|
+
#
|
31
|
+
# @return [String, nil]
|
21
32
|
attr_accessor :bank_phone_country_code
|
22
33
|
|
23
|
-
#
|
24
|
-
#
|
34
|
+
# The phone number, without the country code, for the issuing bank as
|
35
|
+
# provided by the end user. Punctuation characters will be stripped.
|
36
|
+
# After stripping punctuation characters, the number must contain only
|
37
|
+
# digits.
|
38
|
+
#
|
39
|
+
# @return [String, nil]
|
25
40
|
attr_accessor :bank_phone_number
|
26
41
|
|
27
|
-
#
|
28
|
-
#
|
42
|
+
# A token uniquely identifying the card. The token should consist of
|
43
|
+
# non-space printable ASCII characters. If the token is all digits, it
|
44
|
+
# must be more than 19 characters long. The token must not be a primary
|
45
|
+
# account number (PAN) or a simple transformation of it. If you have a
|
46
|
+
# valid token that looks like a PAN but is not one, you may prefix that
|
47
|
+
# token with a fixed string, e.g., +token-+.
|
48
|
+
#
|
49
|
+
# @return [String, nil]
|
29
50
|
attr_accessor :token
|
30
51
|
|
31
|
-
#
|
32
|
-
#
|
52
|
+
# The address verification system (AVS) check result, as returned to you
|
53
|
+
# by the credit card processor. The minFraud service supports the
|
54
|
+
# standard AVS codes.
|
55
|
+
#
|
56
|
+
# @return [String, nil]
|
33
57
|
attr_accessor :avs_result
|
34
58
|
|
35
|
-
#
|
36
|
-
#
|
59
|
+
# The card verification value (CVV) code as provided by the payment
|
60
|
+
# processor.
|
61
|
+
#
|
62
|
+
# @return [String, nil]
|
37
63
|
attr_accessor :cvv_result
|
38
64
|
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# @return [Minfraud::Components::CreditCard] a CreditCard instance
|
65
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
66
|
+
# correspond to one of the available attributes.
|
42
67
|
def initialize(params = {})
|
43
68
|
@bank_phone_country_code = params[:bank_phone_country_code]
|
44
69
|
@issuer_id_number = params[:issuer_id_number]
|
@@ -48,6 +73,23 @@ module Minfraud
|
|
48
73
|
@avs_result = params[:avs_result]
|
49
74
|
@cvv_result = params[:cvv_result]
|
50
75
|
@token = params[:token]
|
76
|
+
|
77
|
+
validate
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def validate
|
83
|
+
return if !Minfraud.enable_validation
|
84
|
+
|
85
|
+
validate_telephone_country_code('bank_phone_country_code', @bank_phone_country_code)
|
86
|
+
validate_regex('issuer_id_number', /\A[0-9]{6}\z/, @issuer_id_number)
|
87
|
+
validate_regex('last_4_digits', /\A[0-9]{4}\z/, @last_4_digits)
|
88
|
+
validate_string('bank_name', 255, @bank_name)
|
89
|
+
validate_string('bank_phone_number', 255, @bank_phone_number)
|
90
|
+
validate_string('avs_result', 1, @avs_result)
|
91
|
+
validate_string('cvv_result', 1, @cvv_result)
|
92
|
+
validate_credit_card_token('token', @token)
|
51
93
|
end
|
52
94
|
end
|
53
95
|
end
|
@@ -2,13 +2,22 @@
|
|
2
2
|
|
3
3
|
module Minfraud
|
4
4
|
module Components
|
5
|
+
# CustomInputs corresponds to the custom_inputs object of a minFraud
|
6
|
+
# request.
|
7
|
+
#
|
8
|
+
# @see https://dev.maxmind.com/minfraud/#Custom_Inputs_(/custominputs)
|
5
9
|
class CustomInputs < Base
|
6
|
-
|
7
|
-
|
8
|
-
# @
|
10
|
+
include Minfraud::Validates
|
11
|
+
|
12
|
+
# @param params [Hash] Each key/value should correspond to your defined
|
13
|
+
# custom inputs.
|
9
14
|
def initialize(params = {})
|
10
15
|
params.each do |name, value|
|
11
16
|
instance_variable_set("@#{name}", value)
|
17
|
+
|
18
|
+
if Minfraud.enable_validation
|
19
|
+
validate_custom_input_value(name, value)
|
20
|
+
end
|
12
21
|
end
|
13
22
|
end
|
14
23
|
end
|
@@ -2,38 +2,66 @@
|
|
2
2
|
|
3
3
|
module Minfraud
|
4
4
|
module Components
|
5
|
+
# Device corresponds to the device object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Device_(/device)
|
5
8
|
class Device < Base
|
6
|
-
|
7
|
-
|
8
|
-
# The IP address
|
9
|
+
include Minfraud::Validates
|
10
|
+
|
11
|
+
# The IP address associated with the device used by the customer in the
|
12
|
+
# transaction. The IP address must be in IPv4 or IPv6 presentation
|
13
|
+
# format, i.e., dotted-quad notation or the IPv6 hexadecimal-colon
|
14
|
+
# notation. (Required)
|
15
|
+
#
|
16
|
+
# @return [String, nil]
|
9
17
|
attr_accessor :ip_address
|
10
18
|
|
11
|
-
#
|
12
|
-
#
|
19
|
+
# The HTTP "User-Agent" header of the browser used in the transaction.
|
20
|
+
#
|
21
|
+
# @return [String, nil]
|
13
22
|
attr_accessor :user_agent
|
14
23
|
|
15
|
-
#
|
16
|
-
#
|
24
|
+
# The HTTP "Accept-Language" header of the browser used in the
|
25
|
+
# transaction.
|
26
|
+
#
|
27
|
+
# @return [String, nil]
|
17
28
|
attr_accessor :accept_language
|
18
29
|
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
30
|
+
# The number of seconds between the creation of the user's session and
|
31
|
+
# the time of the transaction. Note that session_age is not the duration
|
32
|
+
# of the current visit, but the time since the start of the first visit.
|
33
|
+
# The value must be at least 0 and at most 10^13-1.
|
34
|
+
#
|
35
|
+
# @return [Float, nil]
|
22
36
|
attr_accessor :session_age
|
23
37
|
|
24
|
-
#
|
25
|
-
#
|
38
|
+
# An ID that uniquely identifies a visitor's session on the site.
|
39
|
+
#
|
40
|
+
# @return [String, nil]
|
26
41
|
attr_accessor :session_id
|
27
42
|
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# @return [Minfraud::Components::Device] a Device instance
|
43
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
44
|
+
# correspond to one of the available attributes.
|
31
45
|
def initialize(params = {})
|
32
46
|
@ip_address = params[:ip_address]
|
33
47
|
@user_agent = params[:user_agent]
|
34
48
|
@accept_language = params[:accept_language]
|
35
49
|
@session_age = params[:session_age]
|
36
50
|
@session_id = params[:session_id]
|
51
|
+
|
52
|
+
validate
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def validate
|
58
|
+
return if !Minfraud.enable_validation
|
59
|
+
|
60
|
+
validate_ip('ip_address', @ip_address)
|
61
|
+
validate_string('user_agent', 512, @user_agent)
|
62
|
+
validate_string('accept_language', 255, @accept_language)
|
63
|
+
validate_nonnegative_number('session_age', @session_age)
|
64
|
+
validate_string('session_id', 255, @session_id)
|
37
65
|
end
|
38
66
|
end
|
39
67
|
end
|
@@ -2,21 +2,41 @@
|
|
2
2
|
|
3
3
|
module Minfraud
|
4
4
|
module Components
|
5
|
+
# Email corresponds to the email object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Email_(/email)
|
5
8
|
class Email < Base
|
6
|
-
|
7
|
-
|
9
|
+
include Minfraud::Validates
|
10
|
+
|
11
|
+
# This field must be either be a valid email address or an MD5 of the
|
12
|
+
# lowercased email used in the transaction. Important: if using the MD5
|
13
|
+
# hash, please be sure to convert the email address to lowercase before
|
14
|
+
# calculating its MD5 hash.
|
15
|
+
#
|
16
|
+
# @return [String, nil]
|
8
17
|
attr_accessor :address
|
9
18
|
|
10
|
-
#
|
11
|
-
#
|
19
|
+
# The domain of the email address used in the transaction.
|
20
|
+
#
|
21
|
+
# @return [String, nil]
|
12
22
|
attr_accessor :domain
|
13
23
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# @return [Minfraud::Components::Email] an Email instance
|
24
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
25
|
+
# correspond to one of the available attributes.
|
17
26
|
def initialize(params = {})
|
18
27
|
@address = params[:address]
|
19
28
|
@domain = params[:domain]
|
29
|
+
|
30
|
+
validate
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def validate
|
36
|
+
return if !Minfraud.enable_validation
|
37
|
+
|
38
|
+
validate_email('email', @address)
|
39
|
+
validate_string('domain', 255, @domain)
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|
@@ -2,23 +2,46 @@
|
|
2
2
|
|
3
3
|
module Minfraud
|
4
4
|
module Components
|
5
|
+
# Event corresponds to the event object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Event_(/event)
|
5
8
|
class Event < Base
|
6
9
|
include ::Minfraud::Enum
|
7
|
-
|
8
|
-
|
10
|
+
include Minfraud::Validates
|
11
|
+
|
12
|
+
# Your internal ID for the transaction. MaxMind can use this to locate a
|
13
|
+
# specific transaction in logs, and it will also show up in email alerts
|
14
|
+
# and notifications from MaxMind to you. No specific format is required.
|
15
|
+
#
|
16
|
+
# @return [String, nil]
|
9
17
|
attr_accessor :transaction_id
|
10
18
|
|
11
|
-
#
|
12
|
-
#
|
19
|
+
# Your internal ID for the shop, affiliate, or merchant this order is
|
20
|
+
# coming from. Required for minFraud users who are resellers, payment
|
21
|
+
# providers, gateways and affiliate networks. No specific format is
|
22
|
+
# required.
|
23
|
+
#
|
24
|
+
# @return [String, nil]
|
13
25
|
attr_accessor :shop_id
|
14
26
|
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# If this field is not in the request, the
|
27
|
+
# The date and time the event occurred. The string must be in the RFC
|
28
|
+
# 3339 date-time format, e.g., "2012-04-12T23:20:50.52Z". The time must
|
29
|
+
# be within the past 10 years. If this field is not in the request, the
|
30
|
+
# current time will be used.
|
31
|
+
#
|
32
|
+
# @see https://tools.ietf.org/html/rfc3339
|
33
|
+
#
|
34
|
+
# @return [String, nil]
|
18
35
|
attr_accessor :time
|
19
36
|
|
20
|
-
#
|
21
|
-
#
|
37
|
+
# The type of event being scored. This must be one of
|
38
|
+
# +:account_creation+, +:account_login+, +:email_change+,
|
39
|
+
# +:password_reset+, +:payout_change+, +:purchase+,
|
40
|
+
# +:recurring_purchase+, +:referral+, or +:survey+.
|
41
|
+
#
|
42
|
+
# @!attribute type
|
43
|
+
#
|
44
|
+
# @return [Symbol, nil]
|
22
45
|
enum_accessor :type,
|
23
46
|
[
|
24
47
|
:account_creation,
|
@@ -32,14 +55,25 @@ module Minfraud
|
|
32
55
|
:survey,
|
33
56
|
]
|
34
57
|
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# @return [Minfraud::Components::Event] an Event instance
|
58
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
59
|
+
# correspond to one of the available attributes.
|
38
60
|
def initialize(params = {})
|
39
61
|
@transaction_id = params[:transaction_id]
|
40
62
|
@shop_id = params[:shop_id]
|
41
63
|
@time = params[:time]
|
42
64
|
self.type = params[:type]
|
65
|
+
|
66
|
+
validate
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def validate
|
72
|
+
return if !Minfraud.enable_validation
|
73
|
+
|
74
|
+
validate_string('transaction_id', 255, @transaction_id)
|
75
|
+
validate_string('shop_id', 255, @shop_id)
|
76
|
+
validate_rfc3339('time', @time)
|
43
77
|
end
|
44
78
|
end
|
45
79
|
end
|
@@ -2,52 +2,87 @@
|
|
2
2
|
|
3
3
|
module Minfraud
|
4
4
|
module Components
|
5
|
+
# Order corresponds to the order object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Order_(/order)
|
5
8
|
class Order < Base
|
6
|
-
|
7
|
-
|
9
|
+
include Minfraud::Validates
|
10
|
+
|
11
|
+
# The total order amount for the transaction before taxes and discounts.
|
12
|
+
# The value must be at least 0 and at most 1e14 - 1.
|
13
|
+
#
|
14
|
+
# @return [Float, nil]
|
8
15
|
attr_accessor :amount
|
9
16
|
|
10
|
-
#
|
11
|
-
#
|
17
|
+
# The ISO 4217 currency code for the currency used in the transaction.
|
18
|
+
#
|
19
|
+
# @see https://en.wikipedia.org/wiki/ISO_4217
|
20
|
+
#
|
21
|
+
# @return [String, nil]
|
12
22
|
attr_accessor :currency
|
13
23
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
24
|
+
# The discount code applied to the transaction. If multiple discount
|
25
|
+
# codes are used, please separate them with a comma.
|
26
|
+
#
|
27
|
+
# @return [String, nil]
|
17
28
|
attr_accessor :discount_code
|
18
29
|
|
19
|
-
#
|
20
|
-
#
|
30
|
+
# The ID of the affiliate where the order is coming from. No specific
|
31
|
+
# format is required.
|
32
|
+
#
|
33
|
+
# @return [String, nil]
|
21
34
|
attr_accessor :affiliate_id
|
22
35
|
|
23
|
-
#
|
24
|
-
#
|
36
|
+
# The ID of the sub-affiliate where the order is coming from. No specific
|
37
|
+
# format is required.
|
38
|
+
#
|
39
|
+
# @return [String, nil]
|
25
40
|
attr_accessor :subaffiliate_id
|
26
41
|
|
27
|
-
#
|
28
|
-
#
|
42
|
+
# The URI of the referring site for this order. Needs to be absolute and
|
43
|
+
# have a URI scheme such as +https://+.
|
44
|
+
#
|
45
|
+
# @return [String, nil]
|
29
46
|
attr_accessor :referrer_uri
|
30
47
|
|
31
|
-
#
|
32
|
-
#
|
48
|
+
# Whether order was marked as a gift by the purchaser.
|
49
|
+
#
|
50
|
+
# @return [Boolean, nil]
|
33
51
|
attr_accessor :is_gift
|
34
52
|
|
35
|
-
#
|
36
|
-
#
|
53
|
+
# Whether the purchaser included a gift message.
|
54
|
+
#
|
55
|
+
# @return [Boolean, nil]
|
37
56
|
attr_accessor :has_gift_message
|
38
57
|
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# @return [Minfraud::Components::Order] an Order instance
|
58
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
59
|
+
# correspond to one of the available attributes.
|
42
60
|
def initialize(params = {})
|
43
61
|
@amount = params[:amount]
|
44
62
|
@has_gift_message = params[:has_gift_message]
|
45
63
|
@affiliate_id = params[:affiliate_id]
|
46
64
|
@subaffiliate_id = params[:subaffiliate_id]
|
47
65
|
@currency = params[:currency]
|
48
|
-
@discount_code = params[:
|
66
|
+
@discount_code = params[:discount_code]
|
49
67
|
@referrer_uri = params[:referrer_uri]
|
50
68
|
@is_gift = params[:is_gift]
|
69
|
+
|
70
|
+
validate
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def validate
|
76
|
+
return if !Minfraud.enable_validation
|
77
|
+
|
78
|
+
validate_nonnegative_number('amount', @amount)
|
79
|
+
validate_boolean('has_gift_message', @has_gift_message)
|
80
|
+
validate_string('affiliate_id', 255, @affiliate_id)
|
81
|
+
validate_string('subaffiliate_id', 255, @subaffiliate_id)
|
82
|
+
validate_regex('currency', /\A[A-Z]{3}\z/, @currency)
|
83
|
+
validate_string('discount_code', 255, @discount_code)
|
84
|
+
validate_uri('referrer_uri', @referrer_uri)
|
85
|
+
validate_boolean('is_gift', @is_gift)
|
51
86
|
end
|
52
87
|
end
|
53
88
|
end
|