minfraud 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5fce80d6ea146e9d31c969019ccefb4a79789645ecbb1db17e1221e90d46e7e
|
4
|
+
data.tar.gz: c1c4082e3a4b4305a530ed84f7a126c2f08872930ecc0df50e3fa20a9ece19cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3996a9546ab76d48a2cd1721612a6d1833c37715f9f4da957dbe584be5a5c8523c552989c766af1f1c72f83b8b20eede3721543f0db86e381a2e8c333d4526b
|
7
|
+
data.tar.gz: 960d79206d07a0ec8b00cb48948dc6699c23693fcf64910a5469d728f6c2028a530f50d3f0079aa59acbd603544c29a88df659686bc8a4f3998bf4804af42a16
|
data/.rubocop.yml
CHANGED
@@ -90,38 +90,19 @@ Style/Documentation:
|
|
90
90
|
Style/FormatStringToken:
|
91
91
|
Enabled: false # Seems unnecessary.
|
92
92
|
|
93
|
+
# Asks to use x.negative? instead of x < 0. But this isn't available until 2.3.
|
94
|
+
Style/NumericPredicate:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
# Seems unnecessary. Asks us to call super in a bunch of places when there's no
|
98
|
+
# need.
|
99
|
+
Lint/MissingSuper:
|
100
|
+
Enabled: false
|
101
|
+
|
93
102
|
# Naming.
|
94
103
|
|
95
104
|
Naming/VariableNumber:
|
96
105
|
Enabled: false # Doesn't always make sense.
|
97
106
|
|
98
|
-
|
99
|
-
|
100
|
-
Layout/EmptyLinesAroundAttributeAccessor:
|
101
|
-
Enabled: true
|
102
|
-
Layout/SpaceAroundMethodCallOperator:
|
103
|
-
Enabled: true
|
104
|
-
Lint/DeprecatedOpenSSLConstant:
|
105
|
-
Enabled: true
|
106
|
-
Lint/MixedRegexpCaptureTypes:
|
107
|
-
Enabled: true
|
108
|
-
Lint/RaiseException:
|
109
|
-
Enabled: true
|
110
|
-
Lint/StructNewOverride:
|
111
|
-
Enabled: true
|
112
|
-
Style/ExponentialNotation:
|
113
|
-
Enabled: true
|
114
|
-
Style/HashEachMethods:
|
115
|
-
Enabled: true
|
116
|
-
Style/HashTransformKeys:
|
117
|
-
Enabled: true
|
118
|
-
Style/HashTransformValues:
|
119
|
-
Enabled: true
|
120
|
-
Style/RedundantFetchBlock:
|
121
|
-
Enabled: true
|
122
|
-
Style/RedundantRegexpCharacterClass:
|
123
|
-
Enabled: true
|
124
|
-
Style/RedundantRegexpEscape:
|
125
|
-
Enabled: true
|
126
|
-
Style/SlicingWithRange:
|
127
|
-
Enabled: true
|
107
|
+
AllCops:
|
108
|
+
NewCops: enable
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Minfraud Changelog
|
2
2
|
|
3
|
+
## v1.3.0 (2020-09-25)
|
4
|
+
|
5
|
+
* Adds support for persistent HTTP connections. Connections persist
|
6
|
+
automatically.
|
7
|
+
* IMPORTANT: Ruby 1.9 is no longer supported. If you're using Ruby 1.9,
|
8
|
+
please use version 1.2.0 or older.
|
9
|
+
* Adds support for client side validation of inputs. An `InvalidInputError`
|
10
|
+
exception will be raised if an input is invalid. This can be enabled by
|
11
|
+
setting `enable_validation` to `true` when configuring `Minfraud`. It is
|
12
|
+
disabled by default.
|
13
|
+
* Adds the `residential_proxy?` method to `MaxMind::GeoIP2::Record::Traits`
|
14
|
+
for use with minFraud Insights and Factors.
|
15
|
+
|
3
16
|
## v1.2.0 (2020-07-15)
|
4
17
|
|
5
18
|
* Adds new processor types to `Minfraud::Components::Payment`: `:cashfree`,
|
data/README.md
CHANGED
@@ -10,10 +10,6 @@ API](https://dev.maxmind.com/minfraud/report-transaction/).
|
|
10
10
|
The legacy minFraud Standard and Premium services are not supported by this
|
11
11
|
API.
|
12
12
|
|
13
|
-
## Requirements
|
14
|
-
|
15
|
-
This gem works with Ruby 1.9 and above.
|
16
|
-
|
17
13
|
## Installation
|
18
14
|
|
19
15
|
Add this line to your application's Gemfile:
|
@@ -24,71 +20,171 @@ gem 'minfraud'
|
|
24
20
|
|
25
21
|
And then execute:
|
26
22
|
|
27
|
-
```
|
23
|
+
```
|
28
24
|
$ bundle
|
29
25
|
```
|
30
26
|
|
31
27
|
Or install it yourself as:
|
28
|
+
|
32
29
|
```
|
33
30
|
$ gem install minfraud
|
34
31
|
```
|
35
32
|
|
33
|
+
## API Documentation
|
34
|
+
|
35
|
+
See the [API documentation](https://www.rubydoc.info/gems/minfraud) for
|
36
|
+
more details.
|
37
|
+
|
36
38
|
## Usage
|
37
39
|
|
38
40
|
### Configuration
|
39
41
|
|
40
42
|
An account ID and license key are required to work with the web services.
|
43
|
+
Configure these before making a request:
|
41
44
|
|
42
45
|
```ruby
|
43
46
|
Minfraud.configure do |c|
|
44
47
|
c.account_id = 12345
|
45
48
|
c.license_key = 'your_license_key'
|
49
|
+
c.enable_validation = true
|
46
50
|
end
|
47
51
|
````
|
48
52
|
|
49
53
|
### Making a minFraud Score, Insights, or Factors Request
|
50
54
|
|
55
|
+
To use the minFraud API, create a `Minfraud::Assessments` object. The
|
56
|
+
constructor takes a hash of symbols corresponding to each component of the
|
57
|
+
minFraud request. You can also set components by their attribute after
|
58
|
+
creating the object.
|
59
|
+
|
60
|
+
After populating the object, call the method for the minFraud endpoint you
|
61
|
+
want to use: `#score`, `#insights`, or `#factors`. The returned value is a
|
62
|
+
`MinFraud::Response` object. You can access the response model through its
|
63
|
+
`#body` attribute.
|
64
|
+
|
65
|
+
An exception will be thrown for critical errors. You should check for
|
66
|
+
`warnings` related to your inputs after a request.
|
67
|
+
|
51
68
|
```ruby
|
52
|
-
#
|
69
|
+
# Prepare the request.
|
53
70
|
assessment = Minfraud::Assessments.new(
|
54
71
|
device: {
|
55
|
-
ip_address:
|
56
|
-
|
72
|
+
ip_address: '152.216.7.110',
|
73
|
+
accept_language: 'en-US,en;q=0.8',
|
74
|
+
session_age: 3600.5,
|
75
|
+
session_id: 'foo',
|
76
|
+
user_agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
|
77
|
+
},
|
78
|
+
event: {
|
79
|
+
transaction_id: 'txn3134133',
|
80
|
+
shop_id: 's2123',
|
81
|
+
time: '2012-04-12T23:20:50+00:00',
|
82
|
+
type: :purchase,
|
83
|
+
},
|
84
|
+
account: {
|
85
|
+
user_id: '3132',
|
86
|
+
username_md5: '4f9726678c438914fa04bdb8c1a24088',
|
87
|
+
},
|
88
|
+
email: {
|
89
|
+
address: 'test@maxmind.com',
|
90
|
+
domain: 'maxmind.com',
|
91
|
+
},
|
92
|
+
billing: {
|
93
|
+
first_name: 'First',
|
94
|
+
last_name: 'Last',
|
95
|
+
company: 'Company',
|
96
|
+
address: '101 Address Rd.',
|
97
|
+
address_2: 'Unit 5',
|
98
|
+
city: 'New Haven',
|
99
|
+
region: 'CT',
|
100
|
+
country: 'US',
|
101
|
+
postal: '06510',
|
102
|
+
phone_number: '123-456-7890',
|
103
|
+
phone_country_code: '1',
|
104
|
+
},
|
105
|
+
shipping: {
|
106
|
+
first_name: 'ShipFirst',
|
107
|
+
last_name: 'ShipLast',
|
108
|
+
company: 'ShipCo',
|
109
|
+
address: '322 Ship Addr. Ln.',
|
110
|
+
address_2: 'St. 43',
|
111
|
+
city: 'Nowhere',
|
112
|
+
region: 'OK',
|
113
|
+
country: 'US',
|
114
|
+
postal: '73003',
|
115
|
+
phone_number: '123-456-0000',
|
116
|
+
phone_country_code: '1',
|
117
|
+
delivery_speed: :same_day,
|
118
|
+
},
|
119
|
+
payment: {
|
120
|
+
processor: :stripe,
|
121
|
+
was_authorized: false,
|
122
|
+
decline_code: 'invalid number',
|
123
|
+
},
|
124
|
+
credit_card: {
|
125
|
+
issuer_id_number: '411111',
|
126
|
+
last_4_digits: '7643',
|
127
|
+
bank_name: 'Bank of No Hope',
|
128
|
+
bank_phone_country_code: '1',
|
129
|
+
bank_phone_number: '123-456-1234',
|
130
|
+
token: 'abcd',
|
131
|
+
avs_result: 'Y',
|
132
|
+
cvv_result: 'N',
|
133
|
+
},
|
134
|
+
order: {
|
135
|
+
amount: 323.21,
|
136
|
+
currency: 'USD',
|
137
|
+
discount_code: 'FIRST',
|
138
|
+
is_gift: true,
|
139
|
+
has_gift_message: false,
|
140
|
+
affiliate_id: 'af12',
|
141
|
+
subaffiliate_id: 'saf42',
|
142
|
+
referrer_uri: 'http://www.amazon.com/',
|
143
|
+
},
|
144
|
+
shopping_cart: [
|
145
|
+
{
|
146
|
+
category: 'pets',
|
147
|
+
item_id: 'leash-0231',
|
148
|
+
quantity: 2,
|
149
|
+
price: 20.43,
|
150
|
+
},
|
151
|
+
{
|
152
|
+
category: 'beauty',
|
153
|
+
item_id: 'msc-1232',
|
154
|
+
quantity: 1,
|
155
|
+
price: 100.00,
|
156
|
+
},
|
157
|
+
],
|
158
|
+
custom_inputs: {
|
159
|
+
section: 'news',
|
160
|
+
previous_purchases: 19,
|
161
|
+
discount: 3.2,
|
162
|
+
previous_user: true,
|
163
|
+
},
|
57
164
|
)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
result = assessment.score # => Minfraud::Response instance
|
82
|
-
|
83
|
-
result.status # => Response status code
|
84
|
-
result.code # => minFraud-specific response code
|
85
|
-
result.body # => Response body
|
86
|
-
result.headers # => Response headers
|
87
|
-
|
88
|
-
# You can change data between requests
|
89
|
-
first_request = assessment.insights
|
90
|
-
assessment.device.ip_address = '22.22.22.33'
|
91
|
-
second_request = assessment.insights
|
165
|
+
|
166
|
+
# To get the Factors response model, use #factors.
|
167
|
+
factors_model = assessment.factors.body
|
168
|
+
|
169
|
+
factors_model.warnings.each { |w| puts w.warning }
|
170
|
+
|
171
|
+
p factors_model.subscores.email_address
|
172
|
+
p factors_model.risk_score
|
173
|
+
|
174
|
+
# To get the Insights response model, use #insights.
|
175
|
+
insights_model = assessment.insights.body
|
176
|
+
|
177
|
+
insights_model.warnings.each { |w| puts w.warning }
|
178
|
+
|
179
|
+
p insights_model.credit_card.issuer.name
|
180
|
+
p insights_model.risk_score
|
181
|
+
|
182
|
+
# To get the Score response model, use #score.
|
183
|
+
score_model = assessment.score.body
|
184
|
+
|
185
|
+
score_model.warnings.each { |w| puts w.warning }
|
186
|
+
|
187
|
+
p score_model.risk_score
|
92
188
|
```
|
93
189
|
|
94
190
|
See the [API documentation](https://www.rubydoc.info/gems/minfraud) for
|
@@ -97,23 +193,21 @@ more details.
|
|
97
193
|
### Reporting a Transaction to MaxMind
|
98
194
|
|
99
195
|
MaxMind encourages the use of this API, as data received through this
|
100
|
-
channel is
|
101
|
-
|
196
|
+
channel is used to improve the accuracy of their fraud detection
|
197
|
+
algorithms.
|
102
198
|
|
103
|
-
To use the Report
|
199
|
+
To use the Report Transaction API, create a
|
104
200
|
`Minfraud::Components::Report::Transaction` object. An IP address and a
|
105
|
-
valid tag are required arguments for this API. Additional
|
106
|
-
|
201
|
+
valid tag are required arguments for this API. Additional parameters may be
|
202
|
+
set, as shown below.
|
107
203
|
|
108
204
|
If the report is successful, nothing is returned. If the report fails, an
|
109
|
-
exception
|
110
|
-
|
111
|
-
See the API documentation for more details.
|
205
|
+
exception will be thrown.
|
112
206
|
|
113
207
|
```ruby
|
114
208
|
# The report_transaction method only makes use of a transaction component:
|
115
209
|
txn = Minfraud::Components::Report::Transaction.new(
|
116
|
-
ip_address: '
|
210
|
+
ip_address: '152.216.7.110',
|
117
211
|
tag: :suspected_fraud,
|
118
212
|
maxmind_id: '12345678',
|
119
213
|
minfraud_id: '58fa38d8-4b87-458b-a22b-f00eda1aa20d',
|
@@ -127,13 +221,20 @@ reporter.report_transaction
|
|
127
221
|
See the [API documentation](https://www.rubydoc.info/gems/minfraud) for
|
128
222
|
more details.
|
129
223
|
|
224
|
+
### Persistent HTTP Connections
|
225
|
+
|
226
|
+
This gem supports persistent HTTP connections, allowing you to avoid the
|
227
|
+
overhead of creating a new HTTP connection for each minFraud request if you
|
228
|
+
plan to perform more than one. You do not need to do anything to enable
|
229
|
+
this functionality.
|
230
|
+
|
130
231
|
### Exceptions
|
131
232
|
|
132
233
|
The gem supplies several distinct exception-types:
|
133
234
|
|
134
|
-
* `RequestFormatError` - Raised if
|
135
|
-
`Minfraud::Assessments`
|
136
|
-
* `ClientError` - Raised if the IP address is absent, reserved or the JSON
|
235
|
+
* `RequestFormatError` - Raised if an unknown key is provided to the
|
236
|
+
`Minfraud::Assessments` constructor
|
237
|
+
* `ClientError` - Raised if the IP address is absent, reserved, or the JSON
|
137
238
|
body cannot be decoded
|
138
239
|
* `AuthorizationError` - Raised if there are problems with the account ID
|
139
240
|
and/or license key
|
@@ -142,6 +243,16 @@ The gem supplies several distinct exception-types:
|
|
142
243
|
* `NotEnumValueError` - Raised if an attribute value doesn't belong to the
|
143
244
|
predefined set of values
|
144
245
|
|
246
|
+
### Thread Safety
|
247
|
+
|
248
|
+
This gem is safe for use from multiple threads.
|
249
|
+
|
250
|
+
`Minfraud::Assessments` and `Minfraud::Report` objects must not be shared
|
251
|
+
across threads.
|
252
|
+
|
253
|
+
Please note that you must run `Minfraud.configure` before calling any
|
254
|
+
functionality using multiple threads.
|
255
|
+
|
145
256
|
## Support
|
146
257
|
|
147
258
|
Please report all issues with this code using the
|
@@ -151,6 +262,10 @@ If you are having an issue with the minFraud service that is not specific
|
|
151
262
|
to the client API, please see
|
152
263
|
[our support page](https://www.maxmind.com/en/support).
|
153
264
|
|
265
|
+
## Requirements
|
266
|
+
|
267
|
+
This gem works with Ruby 2.0 and above.
|
268
|
+
|
154
269
|
## Contributing
|
155
270
|
|
156
271
|
Bug reports and pull requests are welcome on
|
@@ -139,6 +139,15 @@ module MaxMind
|
|
139
139
|
get('is_public_proxy')
|
140
140
|
end
|
141
141
|
|
142
|
+
# This is true if the IP address is on a suspected anonymizing network
|
143
|
+
# and belongs to a residential ISP. This property is only available
|
144
|
+
# from GeoIP2 Precision Insights.
|
145
|
+
#
|
146
|
+
# @return [Boolean]
|
147
|
+
def residential_proxy?
|
148
|
+
get('is_residential_proxy')
|
149
|
+
end
|
150
|
+
|
142
151
|
# This is true if the IP address is a Tor exit node. This property is only
|
143
152
|
# available from GeoIP2 Precision Insights.
|
144
153
|
#
|
data/lib/minfraud.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'faraday'
|
3
4
|
require 'minfraud'
|
4
5
|
require 'minfraud/enum'
|
6
|
+
require 'minfraud/validates'
|
5
7
|
require 'minfraud/components/base'
|
6
8
|
require 'minfraud/components/account'
|
7
9
|
require 'minfraud/components/addressable'
|
@@ -27,6 +29,8 @@ require 'minfraud/error_handler'
|
|
27
29
|
require 'minfraud/assessments'
|
28
30
|
require 'minfraud/report'
|
29
31
|
|
32
|
+
# This class holds global configuration parameters and provides a namespace
|
33
|
+
# for the gem's classes.
|
30
34
|
module Minfraud
|
31
35
|
class << self
|
32
36
|
# The MaxMind account ID that is used for authorization.
|
@@ -34,6 +38,11 @@ module Minfraud
|
|
34
38
|
# @return [Integer, nil]
|
35
39
|
attr_accessor :account_id
|
36
40
|
|
41
|
+
# Enable client side validation. This is disabled by default.
|
42
|
+
#
|
43
|
+
# @return [Boolean, nil]
|
44
|
+
attr_accessor :enable_validation
|
45
|
+
|
37
46
|
# The host to use when connecting to the web service.
|
38
47
|
#
|
39
48
|
# @return [String, nil]
|
@@ -52,11 +61,17 @@ module Minfraud
|
|
52
61
|
# @return [String, nil]
|
53
62
|
attr_accessor :license_key
|
54
63
|
|
64
|
+
# @!visibility private
|
65
|
+
attr_reader :connection
|
66
|
+
|
55
67
|
# Yield self to accept configuration settings.
|
56
68
|
#
|
57
69
|
# @yield [self]
|
58
70
|
def configure
|
59
71
|
yield self
|
72
|
+
|
73
|
+
config = Minfraud::HTTPService.configuration
|
74
|
+
@connection = Faraday.new(config[:server], {}, &config[:middleware])
|
60
75
|
end
|
61
76
|
|
62
77
|
# The current Minfraud configuration.
|