minfraud 1.1.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop.yml +12 -0
- data/.github/workflows/test.yml +33 -0
- data/.rubocop.yml +108 -0
- data/CHANGELOG.md +57 -0
- data/Gemfile +4 -2
- data/README.dev.md +1 -1
- data/README.md +170 -55
- data/Rakefile +9 -3
- data/bin/console +4 -3
- data/lib/maxmind/geoip2/model/city.rb +3 -3
- data/lib/maxmind/geoip2/model/country.rb +5 -5
- data/lib/maxmind/geoip2/record/traits.rb +13 -4
- data/lib/minfraud.rb +44 -6
- data/lib/minfraud/assessments.rb +113 -53
- data/lib/minfraud/components/account.rb +31 -9
- data/lib/minfraud/components/addressable.rb +73 -26
- data/lib/minfraud/components/base.rb +26 -14
- data/lib/minfraud/components/billing.rb +5 -0
- data/lib/minfraud/components/credit_card.rb +64 -20
- data/lib/minfraud/components/custom_inputs.rb +14 -3
- data/lib/minfraud/components/device.rb +45 -15
- data/lib/minfraud/components/email.rb +120 -9
- data/lib/minfraud/components/event.rb +60 -24
- data/lib/minfraud/components/order.rb +59 -22
- data/lib/minfraud/components/payment.rb +44 -9
- data/lib/minfraud/components/report/transaction.rb +50 -39
- data/lib/minfraud/components/shipping.rb +14 -5
- data/lib/minfraud/components/shopping_cart.rb +19 -12
- data/lib/minfraud/components/shopping_cart_item.rb +42 -13
- data/lib/minfraud/enum.rb +22 -8
- data/lib/minfraud/error_handler.rb +32 -25
- data/lib/minfraud/errors.rb +22 -2
- data/lib/minfraud/http_service.rb +23 -8
- data/lib/minfraud/http_service/request.rb +19 -18
- data/lib/minfraud/http_service/response.rb +19 -14
- data/lib/minfraud/model/address.rb +4 -4
- data/lib/minfraud/model/credit_card.rb +7 -7
- data/lib/minfraud/model/device.rb +2 -2
- data/lib/minfraud/model/email.rb +4 -4
- data/lib/minfraud/model/error.rb +1 -1
- data/lib/minfraud/model/insights.rb +5 -5
- data/lib/minfraud/model/ip_address.rb +20 -1
- data/lib/minfraud/model/ip_risk_reason.rb +48 -0
- data/lib/minfraud/model/issuer.rb +3 -3
- data/lib/minfraud/model/score.rb +6 -6
- data/lib/minfraud/model/shipping_address.rb +1 -1
- data/lib/minfraud/model/subscores.rb +38 -16
- data/lib/minfraud/model/warning.rb +2 -2
- data/lib/minfraud/report.rb +33 -13
- data/lib/minfraud/resolver.rb +25 -17
- data/lib/minfraud/validates.rb +187 -0
- data/lib/minfraud/version.rb +4 -1
- data/minfraud.gemspec +8 -2
- metadata +77 -10
- data/.travis.yml +0 -22
@@ -1,43 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
5
|
+
# Event corresponds to the event object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Event_(/event)
|
3
8
|
class Event < Base
|
4
9
|
include ::Minfraud::Enum
|
5
|
-
|
6
|
-
|
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]
|
7
17
|
attr_accessor :transaction_id
|
8
18
|
|
9
|
-
#
|
10
|
-
#
|
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]
|
11
25
|
attr_accessor :shop_id
|
12
26
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# 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]
|
16
35
|
attr_accessor :time
|
17
36
|
|
18
|
-
#
|
19
|
-
#
|
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]
|
20
45
|
enum_accessor :type,
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# @return [Minfraud::Components::Event] an Event instance
|
46
|
+
[
|
47
|
+
:account_creation,
|
48
|
+
:account_login,
|
49
|
+
:email_change,
|
50
|
+
:password_reset,
|
51
|
+
:payout_change,
|
52
|
+
:purchase,
|
53
|
+
:recurring_purchase,
|
54
|
+
:referral,
|
55
|
+
:survey,
|
56
|
+
]
|
57
|
+
|
58
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
59
|
+
# correspond to one of the available attributes.
|
36
60
|
def initialize(params = {})
|
37
61
|
@transaction_id = params[:transaction_id]
|
38
62
|
@shop_id = params[:shop_id]
|
39
63
|
@time = params[:time]
|
40
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)
|
41
77
|
end
|
42
78
|
end
|
43
79
|
end
|
@@ -1,51 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
5
|
+
# Order corresponds to the order object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Order_(/order)
|
3
8
|
class Order < Base
|
4
|
-
|
5
|
-
|
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]
|
6
15
|
attr_accessor :amount
|
7
16
|
|
8
|
-
#
|
9
|
-
#
|
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]
|
10
22
|
attr_accessor :currency
|
11
23
|
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
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]
|
15
28
|
attr_accessor :discount_code
|
16
29
|
|
17
|
-
#
|
18
|
-
#
|
30
|
+
# The ID of the affiliate where the order is coming from. No specific
|
31
|
+
# format is required.
|
32
|
+
#
|
33
|
+
# @return [String, nil]
|
19
34
|
attr_accessor :affiliate_id
|
20
35
|
|
21
|
-
#
|
22
|
-
#
|
36
|
+
# The ID of the sub-affiliate where the order is coming from. No specific
|
37
|
+
# format is required.
|
38
|
+
#
|
39
|
+
# @return [String, nil]
|
23
40
|
attr_accessor :subaffiliate_id
|
24
41
|
|
25
|
-
#
|
26
|
-
#
|
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]
|
27
46
|
attr_accessor :referrer_uri
|
28
47
|
|
29
|
-
#
|
30
|
-
#
|
48
|
+
# Whether order was marked as a gift by the purchaser.
|
49
|
+
#
|
50
|
+
# @return [Boolean, nil]
|
31
51
|
attr_accessor :is_gift
|
32
52
|
|
33
|
-
#
|
34
|
-
#
|
53
|
+
# Whether the purchaser included a gift message.
|
54
|
+
#
|
55
|
+
# @return [Boolean, nil]
|
35
56
|
attr_accessor :has_gift_message
|
36
57
|
|
37
|
-
#
|
38
|
-
#
|
39
|
-
|
40
|
-
def initialize (params = {})
|
58
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
59
|
+
# correspond to one of the available attributes.
|
60
|
+
def initialize(params = {})
|
41
61
|
@amount = params[:amount]
|
42
62
|
@has_gift_message = params[:has_gift_message]
|
43
63
|
@affiliate_id = params[:affiliate_id]
|
44
64
|
@subaffiliate_id = params[:subaffiliate_id]
|
45
65
|
@currency = params[:currency]
|
46
|
-
@discount_code = params[:
|
66
|
+
@discount_code = params[:discount_code]
|
47
67
|
@referrer_uri = params[:referrer_uri]
|
48
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)
|
49
86
|
end
|
50
87
|
end
|
51
88
|
end
|
@@ -1,9 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
5
|
+
# Payment corresponds to the payment object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Payment_(/payment)
|
3
8
|
class Payment < Base
|
4
9
|
include ::Minfraud::Enum
|
5
|
-
|
6
|
-
|
10
|
+
include Minfraud::Validates
|
11
|
+
|
12
|
+
# The payment processor used for the transaction. The value is one
|
13
|
+
# listed as a valid value, as a symbol.
|
14
|
+
#
|
15
|
+
# @!attribute processor
|
16
|
+
#
|
17
|
+
# @return [Symbol, nil]
|
7
18
|
enum_accessor :processor, [
|
8
19
|
:adyen,
|
9
20
|
:affirm,
|
@@ -11,6 +22,8 @@ module Minfraud
|
|
11
22
|
:altapay,
|
12
23
|
:amazon_payments,
|
13
24
|
:american_express_payment_gateway,
|
25
|
+
:apple_pay,
|
26
|
+
:aps_payments,
|
14
27
|
:authorizenet,
|
15
28
|
:balanced,
|
16
29
|
:beanstream,
|
@@ -19,6 +32,7 @@ module Minfraud
|
|
19
32
|
:bpoint,
|
20
33
|
:braintree,
|
21
34
|
:cardpay,
|
35
|
+
:cashfree,
|
22
36
|
:ccavenue,
|
23
37
|
:ccnow,
|
24
38
|
:cetelem,
|
@@ -50,6 +64,7 @@ module Minfraud
|
|
50
64
|
:epx,
|
51
65
|
:eway,
|
52
66
|
:exact,
|
67
|
+
:first_atlantic_commerce,
|
53
68
|
:first_data,
|
54
69
|
:g2a_pay,
|
55
70
|
:global_payments,
|
@@ -62,6 +77,7 @@ module Minfraud
|
|
62
77
|
:intuit_quickbooks_payments,
|
63
78
|
:iugu,
|
64
79
|
:klarna,
|
80
|
+
:komoju,
|
65
81
|
:lemon_way,
|
66
82
|
:mastercard_payment_gateway,
|
67
83
|
:mercadopago,
|
@@ -89,6 +105,7 @@ module Minfraud
|
|
89
105
|
:payplus,
|
90
106
|
:paysafecard,
|
91
107
|
:paystation,
|
108
|
+
:paytm,
|
92
109
|
:paytrace,
|
93
110
|
:paytrail,
|
94
111
|
:payture,
|
@@ -103,6 +120,7 @@ module Minfraud
|
|
103
120
|
:qiwi,
|
104
121
|
:quickpay,
|
105
122
|
:raberil,
|
123
|
+
:razorpay,
|
106
124
|
:rede,
|
107
125
|
:redpagos,
|
108
126
|
:rewardspay,
|
@@ -116,9 +134,11 @@ module Minfraud
|
|
116
134
|
:sps_decidir,
|
117
135
|
:stripe,
|
118
136
|
:synapsefi,
|
137
|
+
:systempay,
|
119
138
|
:telerecargas,
|
120
139
|
:towah,
|
121
140
|
:transact_pro,
|
141
|
+
:tsys,
|
122
142
|
:usa_epay,
|
123
143
|
:vantiv,
|
124
144
|
:verepay,
|
@@ -131,21 +151,36 @@ module Minfraud
|
|
131
151
|
:worldpay
|
132
152
|
]
|
133
153
|
|
134
|
-
#
|
135
|
-
#
|
154
|
+
# The authorization outcome from the payment processor. If the
|
155
|
+
# transaction has not yet been approved or denied, do not include this
|
156
|
+
# field.
|
157
|
+
#
|
158
|
+
# @return [Boolean, nil]
|
136
159
|
attr_accessor :was_authorized
|
137
160
|
|
138
|
-
#
|
139
|
-
#
|
161
|
+
# The decline code as provided by your payment processor. If the
|
162
|
+
# transaction was not declined, do not include this field.
|
163
|
+
#
|
164
|
+
# @return [String, nil]
|
140
165
|
attr_accessor :decline_code
|
141
166
|
|
142
|
-
#
|
143
|
-
#
|
144
|
-
# @return [Minfraud::Components::Payment] Payment instance
|
167
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
168
|
+
# correspond to one of the available attributes.
|
145
169
|
def initialize(params = {})
|
146
170
|
@was_authorized = params[:was_authorized]
|
147
171
|
@decline_code = params[:decline_code]
|
148
172
|
self.processor = params[:processor]
|
173
|
+
|
174
|
+
validate
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
def validate
|
180
|
+
return if !Minfraud.enable_validation
|
181
|
+
|
182
|
+
validate_boolean('was_authorized', @was_authorized)
|
183
|
+
validate_string('decline_code', 255, @decline_code)
|
149
184
|
end
|
150
185
|
end
|
151
186
|
end
|
@@ -3,65 +3,76 @@
|
|
3
3
|
module Minfraud
|
4
4
|
module Components
|
5
5
|
module Report
|
6
|
-
# Contains
|
6
|
+
# Contains the fields used in the Report Transaction API.
|
7
|
+
#
|
8
|
+
# @see https://dev.maxmind.com/minfraud/report-transaction/
|
7
9
|
class Transaction < Base
|
8
10
|
include ::Minfraud::Enum
|
9
11
|
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
12
|
+
# The IP address of the customer placing the order. This should be
|
13
|
+
# passed as a string like "152.216.7.110".
|
14
|
+
#
|
15
|
+
# @return [String, nil]
|
13
16
|
attr_accessor :ip_address
|
14
17
|
|
18
|
+
# A symbol indicating the likelihood that a transaction may be
|
19
|
+
# fraudulent.
|
20
|
+
#
|
21
|
+
# This may be one of +:chargeback+, +:not_fraud+, +:spam_or_abuse+, or
|
22
|
+
# +:suspected_fraud+.
|
23
|
+
#
|
15
24
|
# @!attribute tag
|
16
|
-
#
|
17
|
-
# @return [Symbol, nil]
|
18
|
-
# may be fraudulent.
|
25
|
+
#
|
26
|
+
# @return [Symbol, nil]
|
19
27
|
enum_accessor :tag, [:chargeback, :not_fraud, :spam_or_abuse, :suspected_fraud]
|
20
28
|
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
29
|
+
# A string which is provided by your payment processor indicating the
|
30
|
+
# reason for the chargeback.
|
31
|
+
#
|
32
|
+
# @return [String, nil]
|
24
33
|
attr_accessor :chargeback_code
|
25
34
|
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
35
|
+
# A unique eight character string identifying a minFraud Standard or
|
36
|
+
# Premium request. These IDs are returned in the maxmindID field of a
|
37
|
+
# response for a successful minFraud request. This field is not
|
38
|
+
# required, but you are encouraged to provide it, if possible.
|
39
|
+
#
|
40
|
+
# @return [String, nil]
|
31
41
|
attr_accessor :maxmind_id
|
32
42
|
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
43
|
+
# A UUID that identifies a minFraud Score, minFraud Insights, or
|
44
|
+
# minFraud Factors request. This ID is returned at /id in the response.
|
45
|
+
# This field is not required, but you are encouraged to provide it if
|
46
|
+
# the request was made to one of these services.
|
47
|
+
#
|
48
|
+
# @return [String, nil]
|
38
49
|
attr_accessor :minfraud_id
|
39
50
|
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
51
|
+
# Your notes on the fraud tag associated with the transaction. We
|
52
|
+
# manually review many reported transactions to improve our scoring for
|
53
|
+
# you so any additional details to help us understand context are
|
54
|
+
# helpful.
|
55
|
+
#
|
56
|
+
# @return [String, nil]
|
45
57
|
attr_accessor :notes
|
46
58
|
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
59
|
+
# The transaction ID you originally passed to minFraud. This field is
|
60
|
+
# not required, but you are encouraged to provide it or the
|
61
|
+
# transaction's maxmind_id or minfraud_id.
|
62
|
+
#
|
63
|
+
# @return [String, nil]
|
51
64
|
attr_accessor :transaction_id
|
52
65
|
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# @return [Minfraud::Components::Report::Transaction] a Report::Transaction
|
56
|
-
# instance
|
66
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
67
|
+
# correspond to one of the available attributes.
|
57
68
|
def initialize(params = {})
|
58
|
-
@ip_address
|
69
|
+
@ip_address = params[:ip_address]
|
59
70
|
@chargeback_code = params[:chargeback_code]
|
60
|
-
@maxmind_id
|
61
|
-
@minfraud_id
|
62
|
-
@notes
|
63
|
-
@transaction_id
|
64
|
-
self.tag
|
71
|
+
@maxmind_id = params[:maxmind_id]
|
72
|
+
@minfraud_id = params[:minfraud_id]
|
73
|
+
@notes = params[:notes]
|
74
|
+
@transaction_id = params[:transaction_id]
|
75
|
+
self.tag = params[:tag]
|
65
76
|
end
|
66
77
|
end
|
67
78
|
end
|