minfraud 1.0.3 → 1.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/workflows/rubocop.yml +12 -0
- data/.github/workflows/test.yml +32 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +108 -0
- data/CHANGELOG.md +70 -2
- data/CODE_OF_CONDUCT.md +4 -4
- data/Gemfile +11 -2
- data/LICENSE.txt +2 -1
- data/README.dev.md +4 -0
- data/README.md +245 -59
- data/Rakefile +9 -3
- data/bin/console +4 -3
- data/lib/maxmind/geoip2/model/city.rb +99 -0
- data/lib/maxmind/geoip2/model/country.rb +94 -0
- data/lib/maxmind/geoip2/model/insights.rb +38 -0
- data/lib/maxmind/geoip2/record/abstract.rb +46 -0
- data/lib/maxmind/geoip2/record/city.rb +62 -0
- data/lib/maxmind/geoip2/record/continent.rb +61 -0
- data/lib/maxmind/geoip2/record/country.rb +78 -0
- data/lib/maxmind/geoip2/record/location.rb +97 -0
- data/lib/maxmind/geoip2/record/maxmind.rb +41 -0
- data/lib/maxmind/geoip2/record/place.rb +52 -0
- data/lib/maxmind/geoip2/record/postal.rb +54 -0
- data/lib/maxmind/geoip2/record/represented_country.rb +47 -0
- data/lib/maxmind/geoip2/record/subdivision.rb +72 -0
- data/lib/maxmind/geoip2/record/traits.rb +233 -0
- data/lib/minfraud.rb +48 -8
- data/lib/minfraud/assessments.rb +118 -49
- data/lib/minfraud/components/account.rb +31 -9
- data/lib/minfraud/components/addressable.rb +73 -26
- data/lib/minfraud/components/base.rb +35 -11
- data/lib/minfraud/components/billing.rb +5 -0
- data/lib/minfraud/components/credit_card.rb +64 -20
- data/lib/minfraud/components/custom_inputs.rb +25 -0
- data/lib/minfraud/components/device.rb +51 -10
- data/lib/minfraud/components/email.rb +29 -7
- data/lib/minfraud/components/event.rb +60 -13
- data/lib/minfraud/components/order.rb +60 -22
- data/lib/minfraud/components/payment.rb +166 -21
- data/lib/minfraud/components/report/transaction.rb +80 -0
- 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 +45 -18
- data/lib/minfraud/errors.rb +22 -2
- data/lib/minfraud/http_service.rb +22 -8
- data/lib/minfraud/http_service/request.rb +19 -18
- data/lib/minfraud/http_service/response.rb +49 -12
- 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 +54 -0
- data/lib/minfraud/model/disposition.rb +35 -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 +82 -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 +178 -0
- data/lib/minfraud/model/warning.rb +63 -0
- data/lib/minfraud/report.rb +58 -0
- data/lib/minfraud/resolver.rb +25 -16
- data/lib/minfraud/validates.rb +187 -0
- data/lib/minfraud/version.rb +4 -1
- data/minfraud.gemspec +23 -18
- metadata +113 -39
- data/.travis.yml +0 -5
data/lib/minfraud.rb
CHANGED
@@ -1,19 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
1
4
|
require 'minfraud'
|
2
5
|
require 'minfraud/enum'
|
6
|
+
require 'minfraud/validates'
|
3
7
|
require 'minfraud/components/base'
|
4
8
|
require 'minfraud/components/account'
|
5
9
|
require 'minfraud/components/addressable'
|
6
10
|
require 'minfraud/components/billing'
|
7
11
|
require 'minfraud/components/credit_card'
|
12
|
+
require 'minfraud/components/custom_inputs'
|
8
13
|
require 'minfraud/components/device'
|
9
14
|
require 'minfraud/components/email'
|
10
15
|
require 'minfraud/components/event'
|
11
16
|
require 'minfraud/components/order'
|
12
17
|
require 'minfraud/components/payment'
|
13
|
-
require 'minfraud/components/
|
18
|
+
require 'minfraud/components/report/transaction'
|
14
19
|
require 'minfraud/components/shipping'
|
15
20
|
require 'minfraud/components/shopping_cart'
|
16
|
-
require 'minfraud/components/
|
21
|
+
require 'minfraud/components/shopping_cart_item'
|
17
22
|
require 'minfraud/resolver'
|
18
23
|
require 'minfraud/version'
|
19
24
|
require 'minfraud/errors'
|
@@ -22,23 +27,58 @@ require 'minfraud/http_service/request'
|
|
22
27
|
require 'minfraud/http_service/response'
|
23
28
|
require 'minfraud/error_handler'
|
24
29
|
require 'minfraud/assessments'
|
30
|
+
require 'minfraud/report'
|
25
31
|
|
32
|
+
# This class holds global configuration parameters and provides a namespace
|
33
|
+
# for the gem's classes.
|
26
34
|
module Minfraud
|
27
35
|
class << self
|
28
|
-
#
|
29
|
-
#
|
36
|
+
# The MaxMind account ID that is used for authorization.
|
37
|
+
#
|
38
|
+
# @return [Integer, nil]
|
39
|
+
attr_accessor :account_id
|
40
|
+
|
41
|
+
# Enable client side validation. This is disabled by default.
|
42
|
+
#
|
43
|
+
# @return [Boolean, nil]
|
44
|
+
attr_accessor :enable_validation
|
45
|
+
|
46
|
+
# The host to use when connecting to the web service.
|
47
|
+
#
|
48
|
+
# @return [String, nil]
|
49
|
+
attr_accessor :host
|
50
|
+
|
51
|
+
# The MaxMind account ID that is used for authorization.
|
52
|
+
#
|
53
|
+
# @deprecated Use {::account_id} instead. This will be removed in the next
|
54
|
+
# major version.
|
55
|
+
#
|
56
|
+
# @return [Integer, nil]
|
30
57
|
attr_accessor :user_id
|
31
58
|
|
32
|
-
#
|
33
|
-
#
|
59
|
+
# The MaxMind license key that is used for authorization.
|
60
|
+
#
|
61
|
+
# @return [String, nil]
|
34
62
|
attr_accessor :license_key
|
35
63
|
|
36
|
-
#
|
64
|
+
# @!visibility private
|
65
|
+
attr_reader :connection
|
66
|
+
|
67
|
+
# Yield self to accept configuration settings.
|
68
|
+
#
|
69
|
+
# @yield [self]
|
37
70
|
def configure
|
38
71
|
yield self
|
72
|
+
|
73
|
+
config = Minfraud::HTTPService.configuration
|
74
|
+
@connection = Faraday.new(config[:server], {}, &config[:middleware])
|
39
75
|
end
|
40
76
|
|
41
|
-
#
|
77
|
+
# The current Minfraud configuration.
|
78
|
+
#
|
79
|
+
# @deprecated This will be removed in the next major version.
|
80
|
+
#
|
81
|
+
# @return [Hash]
|
42
82
|
def configuration
|
43
83
|
{
|
44
84
|
user_id: @user_id,
|
data/lib/minfraud/assessments.rb
CHANGED
@@ -1,90 +1,159 @@
|
|
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/
|
2
8
|
class Assessments
|
3
9
|
include ::Minfraud::HTTPService
|
4
10
|
include ::Minfraud::Resolver
|
5
11
|
|
6
|
-
#
|
7
|
-
#
|
12
|
+
# The Account component.
|
13
|
+
#
|
14
|
+
# @return [Minfraud::Components::Account, nil]
|
8
15
|
attr_accessor :account
|
9
16
|
|
10
|
-
#
|
11
|
-
#
|
17
|
+
# The Billing component.
|
18
|
+
#
|
19
|
+
# @return [Minfraud::Components::Billing, nil]
|
12
20
|
attr_accessor :billing
|
13
21
|
|
14
|
-
#
|
15
|
-
#
|
22
|
+
# The CreditCard component.
|
23
|
+
#
|
24
|
+
# @return [Minfraud::Components::CreditCard, nil]
|
16
25
|
attr_accessor :credit_card
|
17
26
|
|
18
|
-
#
|
19
|
-
#
|
27
|
+
# The CustomInputs component.
|
28
|
+
#
|
29
|
+
# @return [Minfraud::Components::CustomInputs, nil]
|
30
|
+
attr_accessor :custom_inputs
|
31
|
+
|
32
|
+
# The Device component.
|
33
|
+
#
|
34
|
+
# @return [Minfraud::Components::Device, nil]
|
20
35
|
attr_accessor :device
|
21
36
|
|
22
|
-
#
|
23
|
-
#
|
37
|
+
# The Email component.
|
38
|
+
#
|
39
|
+
# @return [Minfraud::Components::Email, nil]
|
24
40
|
attr_accessor :email
|
25
41
|
|
26
|
-
#
|
27
|
-
#
|
42
|
+
# The Event component.
|
43
|
+
#
|
44
|
+
# @return [Minfraud::Components::Event, nil]
|
28
45
|
attr_accessor :event
|
29
46
|
|
30
|
-
#
|
31
|
-
#
|
47
|
+
# The Order component.
|
48
|
+
#
|
49
|
+
# @return [Minfraud::Components::Order, nil]
|
32
50
|
attr_accessor :order
|
33
51
|
|
34
|
-
#
|
35
|
-
#
|
52
|
+
# The Payment component.
|
53
|
+
#
|
54
|
+
# @return [Minfraud::Components::Payment, nil]
|
36
55
|
attr_accessor :payment
|
37
56
|
|
38
|
-
#
|
39
|
-
#
|
57
|
+
# The Shipping component.
|
58
|
+
#
|
59
|
+
# @return [Minfraud::Components::Shipping, nil]
|
40
60
|
attr_accessor :shipping
|
41
61
|
|
42
|
-
#
|
43
|
-
#
|
62
|
+
# The ShoppingCart component.
|
63
|
+
#
|
64
|
+
# @return [Minfraud::Components::ShoppingCart, nil]
|
44
65
|
attr_accessor :shopping_cart
|
45
66
|
|
46
|
-
# @param
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
67
|
+
# @param params [Hash] Hash of parameters. Each key is a symbol
|
68
|
+
# corresponding to one of the available component attributes. Values may
|
69
|
+
# be component objects or hashes that will be provided to the component
|
70
|
+
# constructors.
|
71
|
+
#
|
72
|
+
# @param resolver [Minfraud::Resolver] Resolver that maps parameters to
|
73
|
+
# components.
|
50
74
|
def initialize(params = {}, resolver = ::Minfraud::Resolver)
|
75
|
+
@locales = params.delete('locales')
|
76
|
+
@locales = ['en'] if @locales.nil?
|
77
|
+
|
51
78
|
resolver.assign(self, params)
|
52
79
|
end
|
53
80
|
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
::Minfraud::ErrorHandler.inspect(response)
|
69
|
-
end
|
81
|
+
# Perform a minFraud Factors request.
|
82
|
+
#
|
83
|
+
# @return [Minfraud::HTTPService::Response]
|
84
|
+
#
|
85
|
+
# @raise [Minfraud::AuthorizationError] If there was an authentication
|
86
|
+
# problem.
|
87
|
+
#
|
88
|
+
# @raise [Minfraud::ClientError] If there was a critical problem with one
|
89
|
+
# of your inputs.
|
90
|
+
#
|
91
|
+
# @raise [Minfraud::ServerError] If the server reported an error of some
|
92
|
+
# kind.
|
93
|
+
def factors
|
94
|
+
perform_request(:factors)
|
70
95
|
end
|
71
96
|
|
72
|
-
|
73
|
-
|
74
|
-
|
97
|
+
# Perform a minFraud Insights request.
|
98
|
+
#
|
99
|
+
# @return [Minfraud::HTTPService::Response]
|
100
|
+
#
|
101
|
+
# @raise [Minfraud::AuthorizationError] If there was an authentication
|
102
|
+
# problem.
|
103
|
+
#
|
104
|
+
# @raise [Minfraud::ClientError] If there was a critical problem with one
|
105
|
+
# of your inputs.
|
106
|
+
#
|
107
|
+
# @raise [Minfraud::ServerError] If the server reported an error of some
|
108
|
+
# kind.
|
109
|
+
def insights
|
110
|
+
perform_request(:insights)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Perform a minFraud Score request.
|
114
|
+
#
|
115
|
+
# @return [Minfraud::HTTPService::Response]
|
116
|
+
#
|
117
|
+
# @raise [Minfraud::AuthorizationError] If there was an authentication
|
118
|
+
# problem.
|
119
|
+
#
|
120
|
+
# @raise [Minfraud::ClientError] If there was a critical problem with one
|
121
|
+
# of your inputs.
|
122
|
+
#
|
123
|
+
# @raise [Minfraud::ServerError] If the server reported an error of some
|
124
|
+
# kind.
|
125
|
+
def score
|
126
|
+
perform_request(:score)
|
127
|
+
end
|
75
128
|
|
76
129
|
private
|
77
|
-
|
78
|
-
|
130
|
+
|
131
|
+
def perform_request(endpoint)
|
132
|
+
raw = request.perform(
|
133
|
+
verb: :post,
|
134
|
+
endpoint: endpoint.to_s,
|
135
|
+
body: request_body,
|
136
|
+
)
|
137
|
+
|
138
|
+
response = ::Minfraud::HTTPService::Response.new(
|
139
|
+
endpoint: endpoint,
|
140
|
+
locales: @locales,
|
141
|
+
status: raw.status.to_i,
|
142
|
+
body: raw.body,
|
143
|
+
headers: raw.headers
|
144
|
+
)
|
145
|
+
|
146
|
+
::Minfraud::ErrorHandler.examine(response)
|
147
|
+
end
|
148
|
+
|
79
149
|
def request_body
|
80
|
-
MAPPING.keys.
|
81
|
-
next mem unless value = send(e)
|
150
|
+
MAPPING.keys.reduce({}) do |mem, e|
|
151
|
+
next mem unless (value = send(e))
|
152
|
+
|
82
153
|
mem.merge!(e.to_s => value.to_json)
|
83
154
|
end
|
84
155
|
end
|
85
156
|
|
86
|
-
# Creates memoized Minfraud::HTTPService::Request instance
|
87
|
-
# @return [Minfraud::HTTPService::Request] Request instance based on configuration params
|
88
157
|
def request
|
89
158
|
@request ||= Request.new(::Minfraud::HTTPService.configuration)
|
90
159
|
end
|
@@ -1,22 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
5
|
+
# Account corresponds to the account object of a minFraud request.
|
6
|
+
#
|
7
|
+
# @see https://dev.maxmind.com/minfraud/#Account_(/account)
|
3
8
|
class Account < Base
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
9
|
+
include Minfraud::Validates
|
10
|
+
|
11
|
+
# A unique user ID associated with the end-user in your system. If your
|
12
|
+
# system allows the login name for the account to be changed, this should
|
13
|
+
# not be the login name for the account, but rather should be an internal
|
14
|
+
# ID that does not change. This is not your MaxMind account ID. No
|
15
|
+
# specific format is required.
|
16
|
+
#
|
17
|
+
# @return [String, nil]
|
8
18
|
attr_accessor :user_id
|
9
19
|
|
10
|
-
#
|
11
|
-
#
|
20
|
+
# An MD5 hash as a hexadecimal string of the username or login name
|
21
|
+
# associated with the account.
|
22
|
+
#
|
23
|
+
# @return [String, nil]
|
12
24
|
attr_accessor :username_md5
|
13
25
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# @return [Minfraud::Components::Account] an Account instance
|
26
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
27
|
+
# correspond to one of the available attributes.
|
17
28
|
def initialize(params = {})
|
18
29
|
@user_id = params[:user_id]
|
19
30
|
@username_md5 = params[:username_md5]
|
31
|
+
|
32
|
+
validate
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def validate
|
38
|
+
return if !Minfraud.enable_validation
|
39
|
+
|
40
|
+
validate_string('user_id', 255, @user_id)
|
41
|
+
validate_md5('username_md5', @username_md5)
|
20
42
|
end
|
21
43
|
end
|
22
44
|
end
|
@@ -1,54 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
5
|
+
# This is a parent class for the Billing and Shipping components.
|
3
6
|
class Addressable < Base
|
4
|
-
|
5
|
-
|
7
|
+
include Minfraud::Validates
|
8
|
+
|
9
|
+
# The first name of the end user as provided in their billing / shipping
|
10
|
+
# information.
|
11
|
+
#
|
12
|
+
# @return [String, nil]
|
6
13
|
attr_accessor :first_name
|
7
14
|
|
8
|
-
#
|
9
|
-
#
|
15
|
+
# The last name of the end user as provided in their billing / shipping
|
16
|
+
# information.
|
17
|
+
#
|
18
|
+
# @return [String, nil]
|
10
19
|
attr_accessor :last_name
|
11
20
|
|
12
|
-
#
|
13
|
-
#
|
21
|
+
# The company of the end user as provided in their billing / shipping
|
22
|
+
# information.
|
23
|
+
#
|
24
|
+
# @return [String, nil]
|
14
25
|
attr_accessor :company
|
15
26
|
|
16
|
-
#
|
17
|
-
#
|
27
|
+
# The first line of the user's billing / shipping address.
|
28
|
+
#
|
29
|
+
# @return [String, nil]
|
18
30
|
attr_accessor :address
|
19
31
|
|
20
|
-
#
|
21
|
-
#
|
32
|
+
# The second line of the user's billing / shipping address.
|
33
|
+
#
|
34
|
+
# @return [String, nil]
|
22
35
|
attr_accessor :address_2
|
23
36
|
|
24
|
-
#
|
25
|
-
#
|
37
|
+
# The city of the user's billing / shipping address.
|
38
|
+
#
|
39
|
+
# @return [String, nil]
|
26
40
|
attr_accessor :city
|
27
41
|
|
28
|
-
#
|
29
|
-
#
|
42
|
+
# The ISO 3166-2 subdivision code for the user's billing / shipping
|
43
|
+
# address.
|
44
|
+
#
|
45
|
+
# @see https://en.wikipedia.org/wiki/ISO_3166-2
|
46
|
+
#
|
47
|
+
# @return [String, nil]
|
30
48
|
attr_accessor :region
|
31
49
|
|
32
|
-
#
|
33
|
-
#
|
50
|
+
# The two character ISO 3166-1 alpha-2 country code of the user's billing
|
51
|
+
# / shipping address.
|
52
|
+
#
|
53
|
+
# @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
54
|
+
#
|
55
|
+
# @return [String, nil]
|
34
56
|
attr_accessor :country
|
35
57
|
|
36
|
-
#
|
37
|
-
#
|
58
|
+
# The postal code of the user's billing / shipping address.
|
59
|
+
#
|
60
|
+
# @return [String, nil]
|
38
61
|
attr_accessor :postal
|
39
62
|
|
40
|
-
#
|
41
|
-
#
|
63
|
+
# The phone number without the country code for the user's billing /
|
64
|
+
# shipping address. Punctuation characters will be stripped. After
|
65
|
+
# stripping punctuation characters, the number must contain only digits.
|
66
|
+
#
|
67
|
+
# @return [String, nil]
|
42
68
|
attr_accessor :phone_number
|
43
69
|
|
44
|
-
#
|
45
|
-
#
|
70
|
+
# The country code for the phone number associated with the user's
|
71
|
+
# billing / shipping address. If you provide this information then you
|
72
|
+
# must provide at least one digit.
|
73
|
+
#
|
74
|
+
# @return [String, nil]
|
46
75
|
attr_accessor :phone_country_code
|
47
76
|
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# @param [Hash] params hash of parameters
|
51
|
-
# @return [Minfraud::Components::Addressable] an Addressable instance
|
77
|
+
# @param params [Hash] Hash of parameters. Each key/value should
|
78
|
+
# correspond to one of the available attributes.
|
52
79
|
def initialize(params = {})
|
53
80
|
@first_name = params[:first_name]
|
54
81
|
@last_name = params[:last_name]
|
@@ -61,6 +88,26 @@ module Minfraud
|
|
61
88
|
@postal = params[:postal]
|
62
89
|
@phone_number = params[:phone_number]
|
63
90
|
@phone_country_code = params[:phone_country_code]
|
91
|
+
|
92
|
+
validate
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def validate
|
98
|
+
return if !Minfraud.enable_validation
|
99
|
+
|
100
|
+
validate_string('first_name', 255, @first_name)
|
101
|
+
validate_string('last_name', 255, @last_name)
|
102
|
+
validate_string('company', 255, @company)
|
103
|
+
validate_string('address', 255, @address)
|
104
|
+
validate_string('address_2', 255, @address_2)
|
105
|
+
validate_string('city', 255, @city)
|
106
|
+
validate_subdivision_code('region', @region)
|
107
|
+
validate_country_code('country', @country)
|
108
|
+
validate_string('postal', 255, @postal)
|
109
|
+
validate_string('phone_number', 255, @phone_number)
|
110
|
+
validate_telephone_country_code('phone_country_code', @phone_country_code)
|
64
111
|
end
|
65
112
|
end
|
66
113
|
end
|