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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5523cb6babed5c559ba622141b2db65a2396cbb016c6215ec641ba765fc01d10
4
- data.tar.gz: 54dbf8b2cc34be45a428da2017f09b7cb2d7445c94ff7f37dda0a26c28a3fbfe
3
+ metadata.gz: e5fce80d6ea146e9d31c969019ccefb4a79789645ecbb1db17e1221e90d46e7e
4
+ data.tar.gz: c1c4082e3a4b4305a530ed84f7a126c2f08872930ecc0df50e3fa20a9ece19cd
5
5
  SHA512:
6
- metadata.gz: 80142ac976fb6df365a3192a96dbf62c8ea7935f4ca9fea89333d0e2f2e64f5e4af402dc03814f58f268e354ed7adcb5c61134fb2d526c0a06b48581cad3fc54
7
- data.tar.gz: a9b6caf26aaee87f5ebc479391cda46d3489cf591315772c481d722b343399edfc5ad40fca8eac0d740d826c0021bcf33d3aade2419247d26d1787328763599b
6
+ metadata.gz: c3996a9546ab76d48a2cd1721612a6d1833c37715f9f4da957dbe584be5a5c8523c552989c766af1f1c72f83b8b20eede3721543f0db86e381a2e8c333d4526b
7
+ data.tar.gz: 960d79206d07a0ec8b00cb48948dc6699c23693fcf64910a5469d728f6c2028a530f50d3f0079aa59acbd603544c29a88df659686bc8a4f3998bf4804af42a16
@@ -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
- # These are new and rubocop warns if you don't configure them.
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
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9
5
4
  - 2.0
6
5
  - 2.1
7
6
  - 2.2
@@ -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
- ```ruby
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
- # You can either provide a hash of parameters to the initializer
69
+ # Prepare the request.
53
70
  assessment = Minfraud::Assessments.new(
54
71
  device: {
55
- ip_address: '1.2.3.4.5'
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
- # or create a component and assign them to the assessments object directly
59
- device = Minfraud::Components::Device.new(ip_address: '1.2.3.4.5')
60
- assessment = Minfraud::Assessments.new(device: device)
61
- # or
62
- assessment = Minfraud::Assessments.new
63
- assessment.device = device
64
-
65
- # There are multiple components that reflect the minFraud request top level
66
- # keys.
67
-
68
- # Some components will raise an error if provided with the wrong values for
69
- # attributes, e.g
70
- event = Minfraud::Components::Event.new(type: 'foobar') # => Minfraud::NotEnumValueError
71
-
72
- # You can check the list of permitted values for the attribute by calling a
73
- # class method
74
- Minfraud::Components::Event.type_values # => ["account_creation", "account_login", ....]
75
-
76
- # You can now call 3 different minFraud endpoints: score, insights and factors
77
- assessment.score
78
- assessment.insights
79
- assessment.factors
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 continually used to improve the accuracy of their fraud
101
- detection algorithms.
196
+ channel is used to improve the accuracy of their fraud detection
197
+ algorithms.
102
198
 
103
- To use the Report Transactions API, create a new
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 params may also
106
- be set, as documented below.
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 with be thrown.
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: '1.2.3.4',
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 unpermitted key is provided to the
135
- `Minfraud::Assessments` initializer
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
  #
@@ -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.