minfraud 1.0.4 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/release.yml +28 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.github/workflows/test.yml +36 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +90 -0
- data/CHANGELOG.md +197 -4
- data/CODE_OF_CONDUCT.md +4 -4
- data/Gemfile +2 -2
- data/LICENSE.txt +2 -1
- data/README.dev.md +4 -0
- data/README.md +255 -58
- data/Rakefile +9 -3
- data/bin/console +4 -3
- data/dev-bin/release.sh +59 -0
- data/lib/minfraud/assessments.rb +127 -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 +117 -29
- data/lib/minfraud/components/custom_inputs.rb +25 -0
- data/lib/minfraud/components/device.rb +51 -10
- data/lib/minfraud/components/email.rb +120 -9
- data/lib/minfraud/components/event.rb +60 -13
- data/lib/minfraud/components/order.rb +59 -22
- data/lib/minfraud/components/payment.rb +192 -22
- data/lib/minfraud/components/report/transaction.rb +80 -0
- data/lib/minfraud/components/shipping.rb +15 -6
- 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 +45 -18
- data/lib/minfraud/errors.rb +22 -2
- data/lib/minfraud/http_service/response.rb +61 -17
- data/lib/minfraud/model/abstract.rb +20 -0
- data/lib/minfraud/model/address.rb +52 -0
- data/lib/minfraud/model/billing_address.rb +11 -0
- data/lib/minfraud/model/credit_card.rb +75 -0
- data/lib/minfraud/model/device.rb +51 -0
- data/lib/minfraud/model/disposition.rb +42 -0
- data/lib/minfraud/model/email.rb +54 -0
- data/lib/minfraud/model/email_domain.rb +24 -0
- data/lib/minfraud/model/error.rb +28 -0
- data/lib/minfraud/model/factors.rb +24 -0
- data/lib/minfraud/model/geoip2_location.rb +25 -0
- data/lib/minfraud/model/insights.rb +68 -0
- data/lib/minfraud/model/ip_address.rb +58 -0
- data/lib/minfraud/model/ip_risk_reason.rb +48 -0
- data/lib/minfraud/model/issuer.rb +49 -0
- data/lib/minfraud/model/score.rb +76 -0
- data/lib/minfraud/model/score_ip_address.rb +23 -0
- data/lib/minfraud/model/shipping_address.rb +30 -0
- data/lib/minfraud/model/subscores.rb +156 -0
- data/lib/minfraud/model/warning.rb +63 -0
- data/lib/minfraud/report.rb +66 -0
- data/lib/minfraud/resolver.rb +25 -16
- data/lib/minfraud/validates.rb +187 -0
- data/lib/minfraud/version.rb +4 -1
- data/lib/minfraud.rb +55 -16
- data/minfraud.gemspec +27 -18
- metadata +107 -36
- data/.travis.yml +0 -5
- data/lib/minfraud/http_service/request.rb +0 -37
- data/lib/minfraud/http_service.rb +0 -31
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# Ruby API for MaxMind minFraud Services
|
2
2
|
|
3
|
-
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/github/kushniryb/minfraud-api-v2/badge.svg?branch=master)](https://coveralls.io/github/kushniryb/minfraud-api-v2?branch=master)
|
5
|
-
[![Build Status](https://travis-ci.org/kushniryb/minfraud-api-v2.svg?branch=master)](https://travis-ci.org/kushniryb/minfraud-api-v2)
|
3
|
+
## Description
|
6
4
|
|
7
|
-
|
5
|
+
This package provides an API for the [MaxMind minFraud web
|
6
|
+
services](https://dev.maxmind.com/minfraud?lang=en). This includes minFraud Score,
|
7
|
+
Insights, and Factors. It also includes our [minFraud Report Transaction
|
8
|
+
API](https://dev.maxmind.com/minfraud/report-a-transaction?lang=en).
|
8
9
|
|
9
|
-
|
10
|
+
The legacy minFraud Standard and Premium services are not supported by this
|
11
|
+
API.
|
10
12
|
|
11
13
|
## Installation
|
12
14
|
|
@@ -18,90 +20,285 @@ gem 'minfraud'
|
|
18
20
|
|
19
21
|
And then execute:
|
20
22
|
|
21
|
-
```
|
23
|
+
```
|
22
24
|
$ bundle
|
23
25
|
```
|
24
26
|
|
25
27
|
Or install it yourself as:
|
28
|
+
|
26
29
|
```
|
27
30
|
$ gem install minfraud
|
28
31
|
```
|
29
32
|
|
30
|
-
##
|
33
|
+
## API Documentation
|
34
|
+
|
35
|
+
See the [API documentation](https://www.rubydoc.info/gems/minfraud) for
|
36
|
+
more details.
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
### Configuration
|
41
|
+
|
42
|
+
An account ID and license key are required to work with the web services.
|
43
|
+
Configure these before making a request:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Minfraud.configure do |c|
|
47
|
+
c.account_id = 12345
|
48
|
+
c.license_key = 'your_license_key'
|
49
|
+
c.enable_validation = true
|
50
|
+
end
|
51
|
+
````
|
31
52
|
|
32
|
-
|
53
|
+
To use the Sandbox web service instead of the production web service, you can provide the host:
|
33
54
|
|
34
55
|
```ruby
|
35
56
|
Minfraud.configure do |c|
|
57
|
+
c.account_id = 12345
|
36
58
|
c.license_key = 'your_license_key'
|
37
|
-
c.
|
59
|
+
c.host = 'sandbox.maxmind.com'
|
38
60
|
end
|
39
61
|
```
|
40
62
|
|
41
|
-
|
63
|
+
### Making a minFraud Score, Insights, or Factors Request
|
64
|
+
|
65
|
+
To use the minFraud API, create a `Minfraud::Assessments` object. The
|
66
|
+
constructor takes a hash of symbols corresponding to each component of the
|
67
|
+
minFraud request. You can also set components by their attribute after
|
68
|
+
creating the object.
|
69
|
+
|
70
|
+
After populating the object, call the method for the minFraud endpoint you
|
71
|
+
want to use: `#score`, `#insights`, or `#factors`. The returned value is a
|
72
|
+
`MinFraud::Response` object. You can access the response model through its
|
73
|
+
`#body` attribute.
|
74
|
+
|
75
|
+
An exception will be thrown for critical errors. You should check for
|
76
|
+
`warnings` related to your inputs after a request.
|
77
|
+
|
42
78
|
```ruby
|
43
|
-
#
|
79
|
+
# Prepare the request.
|
44
80
|
assessment = Minfraud::Assessments.new(
|
45
81
|
device: {
|
46
|
-
ip_address:
|
47
|
-
|
82
|
+
ip_address: '152.216.7.110',
|
83
|
+
accept_language: 'en-US,en;q=0.8',
|
84
|
+
session_age: 3600.5,
|
85
|
+
session_id: 'foo',
|
86
|
+
user_agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
|
87
|
+
},
|
88
|
+
event: {
|
89
|
+
transaction_id: 'txn3134133',
|
90
|
+
shop_id: 's2123',
|
91
|
+
time: '2012-04-12T23:20:50+00:00',
|
92
|
+
type: :purchase,
|
93
|
+
},
|
94
|
+
account: {
|
95
|
+
user_id: '3132',
|
96
|
+
username_md5: '4f9726678c438914fa04bdb8c1a24088',
|
97
|
+
},
|
98
|
+
email: {
|
99
|
+
address: 'test@maxmind.com',
|
100
|
+
domain: 'maxmind.com',
|
101
|
+
},
|
102
|
+
billing: {
|
103
|
+
first_name: 'First',
|
104
|
+
last_name: 'Last',
|
105
|
+
company: 'Company',
|
106
|
+
address: '101 Address Rd.',
|
107
|
+
address_2: 'Unit 5',
|
108
|
+
city: 'New Haven',
|
109
|
+
region: 'CT',
|
110
|
+
country: 'US',
|
111
|
+
postal: '06510',
|
112
|
+
phone_number: '123-456-7890',
|
113
|
+
phone_country_code: '1',
|
114
|
+
},
|
115
|
+
shipping: {
|
116
|
+
first_name: 'ShipFirst',
|
117
|
+
last_name: 'ShipLast',
|
118
|
+
company: 'ShipCo',
|
119
|
+
address: '322 Ship Addr. Ln.',
|
120
|
+
address_2: 'St. 43',
|
121
|
+
city: 'Nowhere',
|
122
|
+
region: 'OK',
|
123
|
+
country: 'US',
|
124
|
+
postal: '73003',
|
125
|
+
phone_number: '123-456-0000',
|
126
|
+
phone_country_code: '1',
|
127
|
+
delivery_speed: :same_day,
|
128
|
+
},
|
129
|
+
payment: {
|
130
|
+
processor: :stripe,
|
131
|
+
was_authorized: false,
|
132
|
+
decline_code: 'invalid number',
|
133
|
+
},
|
134
|
+
credit_card: {
|
135
|
+
issuer_id_number: '411111',
|
136
|
+
last_digits: '7643',
|
137
|
+
bank_name: 'Bank of No Hope',
|
138
|
+
bank_phone_country_code: '1',
|
139
|
+
bank_phone_number: '123-456-1234',
|
140
|
+
token: 'abcd',
|
141
|
+
avs_result: 'Y',
|
142
|
+
cvv_result: 'N',
|
143
|
+
was_3d_secure_successful: true,
|
144
|
+
},
|
145
|
+
order: {
|
146
|
+
amount: 323.21,
|
147
|
+
currency: 'USD',
|
148
|
+
discount_code: 'FIRST',
|
149
|
+
is_gift: true,
|
150
|
+
has_gift_message: false,
|
151
|
+
affiliate_id: 'af12',
|
152
|
+
subaffiliate_id: 'saf42',
|
153
|
+
referrer_uri: 'http://www.amazon.com/',
|
154
|
+
},
|
155
|
+
shopping_cart: [
|
156
|
+
{
|
157
|
+
category: 'pets',
|
158
|
+
item_id: 'leash-0231',
|
159
|
+
quantity: 2,
|
160
|
+
price: 20.43,
|
161
|
+
},
|
162
|
+
{
|
163
|
+
category: 'beauty',
|
164
|
+
item_id: 'msc-1232',
|
165
|
+
quantity: 1,
|
166
|
+
price: 100.00,
|
167
|
+
},
|
168
|
+
],
|
169
|
+
custom_inputs: {
|
170
|
+
section: 'news',
|
171
|
+
previous_purchases: 19,
|
172
|
+
discount: 3.2,
|
173
|
+
previous_user: true,
|
174
|
+
},
|
48
175
|
)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
# You can also change data inbetween requests
|
74
|
-
first_request = assessment.insights
|
75
|
-
assessment.device.ip_address = '22.22.22.33'
|
76
|
-
second_request = assessment.insights
|
176
|
+
|
177
|
+
# To get the Factors response model, use #factors.
|
178
|
+
factors_model = assessment.factors.body
|
179
|
+
|
180
|
+
factors_model.warnings.each { |w| puts w.warning }
|
181
|
+
|
182
|
+
p factors_model.subscores.email_address
|
183
|
+
p factors_model.risk_score
|
184
|
+
|
185
|
+
# To get the Insights response model, use #insights.
|
186
|
+
insights_model = assessment.insights.body
|
187
|
+
|
188
|
+
insights_model.warnings.each { |w| puts w.warning }
|
189
|
+
|
190
|
+
p insights_model.credit_card.issuer.name
|
191
|
+
p insights_model.risk_score
|
192
|
+
|
193
|
+
# To get the Score response model, use #score.
|
194
|
+
score_model = assessment.score.body
|
195
|
+
|
196
|
+
score_model.warnings.each { |w| puts w.warning }
|
197
|
+
|
198
|
+
p score_model.risk_score
|
77
199
|
```
|
78
200
|
|
79
|
-
|
201
|
+
See the [API documentation](https://www.rubydoc.info/gems/minfraud) for
|
202
|
+
more details.
|
80
203
|
|
81
|
-
|
82
|
-
```ruby
|
83
|
-
# Raised if unpermitted key is provided to Minfraud::Assessments initializer
|
84
|
-
class RequestFormatError < BaseError; end
|
204
|
+
### Reporting a Transaction to MaxMind
|
85
205
|
|
86
|
-
|
87
|
-
|
206
|
+
MaxMind encourages the use of this API, as data received through this
|
207
|
+
channel is used to improve the accuracy of their fraud detection
|
208
|
+
algorithms.
|
88
209
|
|
89
|
-
|
90
|
-
|
210
|
+
To use the Report Transaction API, create a
|
211
|
+
`Minfraud::Components::Report::Transaction` object. An IP address and a
|
212
|
+
valid tag are required arguments for this API. Additional parameters may be
|
213
|
+
set, as shown below.
|
91
214
|
|
92
|
-
|
93
|
-
|
215
|
+
If the report is successful, nothing is returned. If the report fails, an
|
216
|
+
exception will be thrown.
|
94
217
|
|
95
|
-
|
96
|
-
|
218
|
+
```ruby
|
219
|
+
# The report_transaction method only makes use of a transaction component:
|
220
|
+
txn = Minfraud::Components::Report::Transaction.new(
|
221
|
+
ip_address: '152.216.7.110',
|
222
|
+
tag: :suspected_fraud,
|
223
|
+
maxmind_id: '12345678',
|
224
|
+
minfraud_id: '58fa38d8-4b87-458b-a22b-f00eda1aa20d',
|
225
|
+
notes: 'notes go here',
|
226
|
+
transaction_id: '1FA254yZ'
|
227
|
+
)
|
228
|
+
reporter = Minfraud::Report.new(transaction: txn)
|
229
|
+
reporter.report_transaction
|
97
230
|
```
|
98
231
|
|
232
|
+
See the [API documentation](https://www.rubydoc.info/gems/minfraud) for
|
233
|
+
more details.
|
234
|
+
|
235
|
+
### Persistent HTTP Connections
|
236
|
+
|
237
|
+
This gem supports persistent HTTP connections, allowing you to avoid the
|
238
|
+
overhead of creating a new HTTP connection for each minFraud request if you
|
239
|
+
plan to perform more than one. You do not need to do anything to enable
|
240
|
+
this functionality.
|
241
|
+
|
242
|
+
### Exceptions
|
243
|
+
|
244
|
+
The gem supplies several distinct exception-types:
|
245
|
+
|
246
|
+
* `RequestFormatError` - Raised if an unknown key is provided to the
|
247
|
+
`Minfraud::Assessments` constructor
|
248
|
+
* `ClientError` - Raised if the IP address is absent, reserved, or the JSON
|
249
|
+
body cannot be decoded
|
250
|
+
* `AuthorizationError` - Raised if there are problems with the account ID
|
251
|
+
and/or license key
|
252
|
+
* `ServerError` - Raised if minFraud returns an error or if there is an
|
253
|
+
HTTP error
|
254
|
+
* `NotEnumValueError` - Raised if an attribute value doesn't belong to the
|
255
|
+
predefined set of values
|
256
|
+
|
257
|
+
### Thread Safety
|
258
|
+
|
259
|
+
This gem is safe for use from multiple threads.
|
260
|
+
|
261
|
+
`Minfraud::Assessments` and `Minfraud::Report` objects must not be shared
|
262
|
+
across threads.
|
263
|
+
|
264
|
+
Please note that you must run `Minfraud.configure` before calling any
|
265
|
+
functionality using multiple threads.
|
266
|
+
|
267
|
+
## Support
|
268
|
+
|
269
|
+
Please report all issues with this code using the
|
270
|
+
[GitHub issue tracker](https://github.com/maxmind/minfraud-api-ruby/issues).
|
271
|
+
|
272
|
+
If you are having an issue with the minFraud service that is not specific
|
273
|
+
to the client API, please see
|
274
|
+
[our support page](https://www.maxmind.com/en/support).
|
275
|
+
|
276
|
+
## Requirements
|
277
|
+
|
278
|
+
This gem works with Ruby 2.7 and above.
|
279
|
+
|
99
280
|
## Contributing
|
100
281
|
|
101
|
-
Bug reports and pull requests are welcome on
|
282
|
+
Bug reports and pull requests are welcome on
|
283
|
+
[GitHub](https://github.com/maxmind/minfraud-api-ruby). This project is
|
284
|
+
intended to be a safe, welcoming space for collaboration, and contributors
|
285
|
+
are expected to adhere to the [Contributor
|
286
|
+
Covenant](https://contributor-covenant.org) code of conduct.
|
287
|
+
|
288
|
+
## Versioning
|
289
|
+
|
290
|
+
This API uses [Semantic Versioning](https://semver.org/).
|
291
|
+
|
292
|
+
## Copyright and License
|
293
|
+
|
294
|
+
Copyright (c) 2016-2020 kushnir.yb.
|
102
295
|
|
296
|
+
Copyright (c) 2020-2024 MaxMind, Inc.
|
103
297
|
|
104
|
-
|
298
|
+
The gem is available as open source under the terms of the [MIT
|
299
|
+
License](https://opensource.org/licenses/MIT).
|
105
300
|
|
106
|
-
|
301
|
+
## Thank You
|
107
302
|
|
303
|
+
This gem is the work of the creator and original maintainer kushnir.yb
|
304
|
+
(@kushniryb).
|
data/Rakefile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
3
6
|
|
4
7
|
RSpec::Core::RakeTask.new(:spec)
|
5
8
|
|
6
|
-
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
|
11
|
+
task default: :spec
|
12
|
+
task default: :rubocop
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'minfraud'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "minfraud"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
data/dev-bin/release.sh
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -eu -o pipefail
|
4
|
+
|
5
|
+
changelog=$(cat CHANGELOG.md)
|
6
|
+
|
7
|
+
regex='
|
8
|
+
## v([0-9]+\.[0-9]+\.[0-9]+) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
|
9
|
+
|
10
|
+
((.|
|
11
|
+
)*)
|
12
|
+
'
|
13
|
+
|
14
|
+
if [[ ! $changelog =~ $regex ]]; then
|
15
|
+
echo "Could not find date line in change log!"
|
16
|
+
exit 1
|
17
|
+
fi
|
18
|
+
|
19
|
+
version="${BASH_REMATCH[1]}"
|
20
|
+
date="${BASH_REMATCH[2]}"
|
21
|
+
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -E '/^## v[0-9]+\.[0-9]+\.[0-9]+/,$!p')"
|
22
|
+
|
23
|
+
echo "$notes"
|
24
|
+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
|
25
|
+
echo "$date is not today!"
|
26
|
+
exit 1
|
27
|
+
fi
|
28
|
+
|
29
|
+
tag="v$version"
|
30
|
+
|
31
|
+
if [ -n "$(git status --porcelain)" ]; then
|
32
|
+
echo ". is not clean." >&2
|
33
|
+
exit 1
|
34
|
+
fi
|
35
|
+
|
36
|
+
perl -pi -e "s/(?<=VERSION = \').+?(?=\')/$version/g" lib/minfraud/version.rb
|
37
|
+
|
38
|
+
echo $"Test results:"
|
39
|
+
|
40
|
+
rake
|
41
|
+
|
42
|
+
echo $'\nDiff:'
|
43
|
+
git diff
|
44
|
+
|
45
|
+
echo $'\nRelease notes:'
|
46
|
+
echo "$notes"
|
47
|
+
|
48
|
+
read -e -p "Commit changes and push to origin? " should_push
|
49
|
+
|
50
|
+
if [ "$should_push" != "y" ]; then
|
51
|
+
echo "Aborting"
|
52
|
+
exit 1
|
53
|
+
fi
|
54
|
+
|
55
|
+
git commit -m "Update for $tag" -a
|
56
|
+
|
57
|
+
git push
|
58
|
+
|
59
|
+
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag"
|
data/lib/minfraud/assessments.rb
CHANGED
@@ -1,92 +1,166 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
4
|
+
# Assessments is used to perform minFraud Score, Insights, and Factors
|
5
|
+
# requests.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud?lang=en
|
2
8
|
class Assessments
|
3
|
-
include ::Minfraud::HTTPService
|
4
9
|
include ::Minfraud::Resolver
|
5
10
|
|
6
|
-
#
|
7
|
-
#
|
11
|
+
# The Account component.
|
12
|
+
#
|
13
|
+
# @return [Minfraud::Components::Account, nil]
|
8
14
|
attr_accessor :account
|
9
15
|
|
10
|
-
#
|
11
|
-
#
|
16
|
+
# The Billing component.
|
17
|
+
#
|
18
|
+
# @return [Minfraud::Components::Billing, nil]
|
12
19
|
attr_accessor :billing
|
13
20
|
|
14
|
-
#
|
15
|
-
#
|
21
|
+
# The CreditCard component.
|
22
|
+
#
|
23
|
+
# @return [Minfraud::Components::CreditCard, nil]
|
16
24
|
attr_accessor :credit_card
|
17
25
|
|
18
|
-
#
|
19
|
-
#
|
26
|
+
# The CustomInputs component.
|
27
|
+
#
|
28
|
+
# @return [Minfraud::Components::CustomInputs, nil]
|
29
|
+
attr_accessor :custom_inputs
|
30
|
+
|
31
|
+
# The Device component.
|
32
|
+
#
|
33
|
+
# @return [Minfraud::Components::Device, nil]
|
20
34
|
attr_accessor :device
|
21
35
|
|
22
|
-
#
|
23
|
-
#
|
36
|
+
# The Email component.
|
37
|
+
#
|
38
|
+
# @return [Minfraud::Components::Email, nil]
|
24
39
|
attr_accessor :email
|
25
40
|
|
26
|
-
#
|
27
|
-
#
|
41
|
+
# The Event component.
|
42
|
+
#
|
43
|
+
# @return [Minfraud::Components::Event, nil]
|
28
44
|
attr_accessor :event
|
29
45
|
|
30
|
-
#
|
31
|
-
#
|
46
|
+
# The Order component.
|
47
|
+
#
|
48
|
+
# @return [Minfraud::Components::Order, nil]
|
32
49
|
attr_accessor :order
|
33
50
|
|
34
|
-
#
|
35
|
-
#
|
51
|
+
# The Payment component.
|
52
|
+
#
|
53
|
+
# @return [Minfraud::Components::Payment, nil]
|
36
54
|
attr_accessor :payment
|
37
55
|
|
38
|
-
#
|
39
|
-
#
|
56
|
+
# The Shipping component.
|
57
|
+
#
|
58
|
+
# @return [Minfraud::Components::Shipping, nil]
|
40
59
|
attr_accessor :shipping
|
41
60
|
|
42
|
-
#
|
43
|
-
#
|
61
|
+
# The ShoppingCart component.
|
62
|
+
#
|
63
|
+
# @return [Minfraud::Components::ShoppingCart, nil]
|
44
64
|
attr_accessor :shopping_cart
|
45
65
|
|
46
|
-
# @param
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
66
|
+
# @param params [Hash] Hash of parameters. Each key is a symbol
|
67
|
+
# corresponding to one of the available component attributes. Values may
|
68
|
+
# be component objects or hashes that will be provided to the component
|
69
|
+
# constructors.
|
70
|
+
#
|
71
|
+
# @param resolver [Minfraud::Resolver] Resolver that maps parameters to
|
72
|
+
# components.
|
50
73
|
def initialize(params = {}, resolver = ::Minfraud::Resolver)
|
74
|
+
@locales = params.delete('locales')
|
75
|
+
@locales = ['en'] if @locales.nil?
|
76
|
+
|
51
77
|
resolver.assign(self, params)
|
52
78
|
end
|
53
79
|
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
80
|
+
# Perform a minFraud Factors request.
|
81
|
+
#
|
82
|
+
# @return [Minfraud::HTTPService::Response]
|
83
|
+
#
|
84
|
+
# @raise [JSON::ParserError] if there was invalid JSON in the response.
|
85
|
+
#
|
86
|
+
# @raise [Minfraud::AuthorizationError] If there was an authentication
|
87
|
+
# problem.
|
88
|
+
#
|
89
|
+
# @raise [Minfraud::ClientError] If there was a critical problem with one
|
90
|
+
# of your inputs.
|
91
|
+
#
|
92
|
+
# @raise [Minfraud::ServerError] If the server reported an error of some
|
93
|
+
# kind.
|
94
|
+
def factors
|
95
|
+
perform_request(:factors)
|
96
|
+
end
|
67
97
|
|
68
|
-
|
69
|
-
|
98
|
+
# Perform a minFraud Insights request.
|
99
|
+
#
|
100
|
+
# @return [Minfraud::HTTPService::Response]
|
101
|
+
#
|
102
|
+
# @raise [JSON::ParserError] if there was invalid JSON in the response.
|
103
|
+
#
|
104
|
+
# @raise [Minfraud::AuthorizationError] If there was an authentication
|
105
|
+
# problem.
|
106
|
+
#
|
107
|
+
# @raise [Minfraud::ClientError] If there was a critical problem with one
|
108
|
+
# of your inputs.
|
109
|
+
#
|
110
|
+
# @raise [Minfraud::ServerError] If the server reported an error of some
|
111
|
+
# kind.
|
112
|
+
def insights
|
113
|
+
perform_request(:insights)
|
70
114
|
end
|
71
115
|
|
72
|
-
|
73
|
-
|
74
|
-
|
116
|
+
# Perform a minFraud Score request.
|
117
|
+
#
|
118
|
+
# @return [Minfraud::HTTPService::Response]
|
119
|
+
#
|
120
|
+
# @raise [JSON::ParserError] if there was invalid JSON in the response.
|
121
|
+
#
|
122
|
+
# @raise [Minfraud::AuthorizationError] If there was an authentication
|
123
|
+
# problem.
|
124
|
+
#
|
125
|
+
# @raise [Minfraud::ClientError] If there was a critical problem with one
|
126
|
+
# of your inputs.
|
127
|
+
#
|
128
|
+
# @raise [Minfraud::ServerError] If the server reported an error of some
|
129
|
+
# kind.
|
130
|
+
def score
|
131
|
+
perform_request(:score)
|
132
|
+
end
|
75
133
|
|
76
134
|
private
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
135
|
+
|
136
|
+
def perform_request(endpoint)
|
137
|
+
response = nil
|
138
|
+
body = nil
|
139
|
+
Minfraud.connection_pool.with do |client|
|
140
|
+
response = client.post(
|
141
|
+
"/minfraud/v2.0/#{endpoint}",
|
142
|
+
json: request_body,
|
143
|
+
)
|
144
|
+
|
145
|
+
body = response.to_s
|
83
146
|
end
|
147
|
+
|
148
|
+
response = ::Minfraud::HTTPService::Response.new(
|
149
|
+
endpoint,
|
150
|
+
@locales,
|
151
|
+
response,
|
152
|
+
body,
|
153
|
+
)
|
154
|
+
|
155
|
+
::Minfraud::ErrorHandler.examine(response)
|
84
156
|
end
|
85
157
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
158
|
+
def request_body
|
159
|
+
MAPPING.keys.reduce({}) do |mem, e|
|
160
|
+
next mem unless (value = send(e))
|
161
|
+
|
162
|
+
mem.merge!(e.to_s => value.to_json)
|
163
|
+
end
|
90
164
|
end
|
91
165
|
end
|
92
166
|
end
|