minfraud 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +46 -0
- data/.rubocop.yml +127 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +4 -2
- data/README.md +1 -1
- data/Rakefile +18 -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 +1 -1
- data/lib/minfraud.rb +29 -6
- data/lib/minfraud/assessments.rb +6 -2
- data/lib/minfraud/components/account.rb +2 -0
- data/lib/minfraud/components/addressable.rb +9 -7
- data/lib/minfraud/components/base.rb +6 -4
- data/lib/minfraud/components/billing.rb +2 -0
- data/lib/minfraud/components/credit_card.rb +4 -2
- data/lib/minfraud/components/custom_inputs.rb +2 -0
- data/lib/minfraud/components/device.rb +4 -2
- data/lib/minfraud/components/email.rb +2 -0
- data/lib/minfraud/components/event.rb +13 -11
- data/lib/minfraud/components/order.rb +3 -1
- data/lib/minfraud/components/payment.rb +14 -2
- data/lib/minfraud/components/report/transaction.rb +6 -6
- data/lib/minfraud/components/shipping.rb +2 -0
- data/lib/minfraud/components/shopping_cart.rb +4 -1
- data/lib/minfraud/components/shopping_cart_item.rb +2 -2
- data/lib/minfraud/enum.rb +6 -3
- data/lib/minfraud/error_handler.rb +15 -15
- data/lib/minfraud/errors.rb +2 -0
- data/lib/minfraud/http_service.rb +14 -4
- data/lib/minfraud/http_service/request.rb +3 -0
- data/lib/minfraud/http_service/response.rb +4 -2
- 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/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 +35 -16
- data/lib/minfraud/model/warning.rb +2 -2
- data/lib/minfraud/report.rb +5 -3
- data/lib/minfraud/resolver.rb +14 -12
- data/lib/minfraud/version.rb +3 -1
- data/minfraud.gemspec +4 -1
- metadata +18 -2
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
3
5
|
# @note This class is used as a parent class for all other components
|
4
6
|
# @note It defines a method which is used for basic JSON representation of PORO objects
|
5
7
|
class Base
|
6
8
|
# @return [Hash] a JSON representation of component attributes
|
7
|
-
def to_json
|
8
|
-
instance_variables.
|
9
|
+
def to_json(*_args)
|
10
|
+
instance_variables.reduce({}) { |mem, e| populate!(mem, e) }
|
9
11
|
end
|
10
12
|
|
11
13
|
private
|
@@ -15,7 +17,7 @@ module Minfraud
|
|
15
17
|
# @param [Symbol] v_sym an instance variable symbol
|
16
18
|
# @return [Hash] a hash containing a JSON representation of instance variable name and it's value
|
17
19
|
def populate!(hash, v_sym)
|
18
|
-
return hash unless value = instance_variable_get(v_sym)
|
20
|
+
return hash unless (value = instance_variable_get(v_sym))
|
19
21
|
|
20
22
|
key = v_sym.to_s.gsub(/@/, '')
|
21
23
|
hash.merge!(key => represent(key, value))
|
@@ -29,7 +31,7 @@ module Minfraud
|
|
29
31
|
end
|
30
32
|
|
31
33
|
# Keys that have to remain boolean
|
32
|
-
BOOLS = %w
|
34
|
+
BOOLS = %w[was_authorized is_gift has_gift_message].freeze
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
3
5
|
class CreditCard < Base
|
@@ -22,8 +24,8 @@ module Minfraud
|
|
22
24
|
# @return [String] The phone number, without the country code, for the issuing bank as provided by the end user
|
23
25
|
attr_accessor :bank_phone_number
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
# @attribute token
|
28
|
+
# @return [String] A token uniquely identifying the card. The token should consist of non-space printable ASCII characters.
|
27
29
|
attr_accessor :token
|
28
30
|
|
29
31
|
# @attribute avs_result
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
3
5
|
class Device < Base
|
@@ -15,12 +17,12 @@ module Minfraud
|
|
15
17
|
attr_accessor :accept_language
|
16
18
|
|
17
19
|
# @attribute :session_age
|
18
|
-
# @return [Decimal] The number of seconds between the creation of the user
|
20
|
+
# @return [Decimal] The number of seconds between the creation of the user's session and the time of the transaction.
|
19
21
|
# Note that session_age is not the duration of the current visit, but the time since the start of the first visit.
|
20
22
|
attr_accessor :session_age
|
21
23
|
|
22
24
|
# @attribute :session_id
|
23
|
-
# @return [String] An ID that uniquely identifies a visitor
|
25
|
+
# @return [String] An ID that uniquely identifies a visitor's session on the site.
|
24
26
|
attr_accessor :session_id
|
25
27
|
|
26
28
|
# Creates Minfraud::Components::Device instance
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
3
5
|
class Event < Base
|
@@ -18,17 +20,17 @@ module Minfraud
|
|
18
20
|
# @attribute type
|
19
21
|
# @return [String] The type of event being scored
|
20
22
|
enum_accessor :type,
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
[
|
24
|
+
:account_creation,
|
25
|
+
:account_login,
|
26
|
+
:email_change,
|
27
|
+
:password_reset,
|
28
|
+
:payout_change,
|
29
|
+
:purchase,
|
30
|
+
:recurring_purchase,
|
31
|
+
:referral,
|
32
|
+
:survey,
|
33
|
+
]
|
32
34
|
|
33
35
|
# Creates Minfraud::Components::Event instance
|
34
36
|
# @param [Hash] params hash of parameters
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
3
5
|
class Order < Base
|
@@ -37,7 +39,7 @@ module Minfraud
|
|
37
39
|
# Creates Minfraud::Components::Order instance
|
38
40
|
# @param [Hash] params hash of parameters
|
39
41
|
# @return [Minfraud::Components::Order] an Order instance
|
40
|
-
def initialize
|
42
|
+
def initialize(params = {})
|
41
43
|
@amount = params[:amount]
|
42
44
|
@has_gift_message = params[:has_gift_message]
|
43
45
|
@affiliate_id = params[:affiliate_id]
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
3
5
|
class Payment < Base
|
@@ -19,6 +21,7 @@ module Minfraud
|
|
19
21
|
:bpoint,
|
20
22
|
:braintree,
|
21
23
|
:cardpay,
|
24
|
+
:cashfree,
|
22
25
|
:ccavenue,
|
23
26
|
:ccnow,
|
24
27
|
:cetelem,
|
@@ -50,6 +53,7 @@ module Minfraud
|
|
50
53
|
:epx,
|
51
54
|
:eway,
|
52
55
|
:exact,
|
56
|
+
:first_atlantic_commerce,
|
53
57
|
:first_data,
|
54
58
|
:g2a_pay,
|
55
59
|
:global_payments,
|
@@ -62,6 +66,7 @@ module Minfraud
|
|
62
66
|
:intuit_quickbooks_payments,
|
63
67
|
:iugu,
|
64
68
|
:klarna,
|
69
|
+
:komoju,
|
65
70
|
:lemon_way,
|
66
71
|
:mastercard_payment_gateway,
|
67
72
|
:mercadopago,
|
@@ -89,6 +94,7 @@ module Minfraud
|
|
89
94
|
:payplus,
|
90
95
|
:paysafecard,
|
91
96
|
:paystation,
|
97
|
+
:paytm,
|
92
98
|
:paytrace,
|
93
99
|
:paytrail,
|
94
100
|
:payture,
|
@@ -103,6 +109,7 @@ module Minfraud
|
|
103
109
|
:qiwi,
|
104
110
|
:quickpay,
|
105
111
|
:raberil,
|
112
|
+
:razorpay,
|
106
113
|
:rede,
|
107
114
|
:redpagos,
|
108
115
|
:rewardspay,
|
@@ -116,6 +123,7 @@ module Minfraud
|
|
116
123
|
:sps_decidir,
|
117
124
|
:stripe,
|
118
125
|
:synapsefi,
|
126
|
+
:systempay,
|
119
127
|
:telerecargas,
|
120
128
|
:towah,
|
121
129
|
:transact_pro,
|
@@ -132,11 +140,15 @@ module Minfraud
|
|
132
140
|
]
|
133
141
|
|
134
142
|
# @attribute was_authorized
|
135
|
-
# @return [Boolean] The authorization outcome from the payment processor.
|
143
|
+
# @return [Boolean] The authorization outcome from the payment processor.
|
144
|
+
# If the transaction has not yet been approved or denied, do not include
|
145
|
+
# this field
|
136
146
|
attr_accessor :was_authorized
|
137
147
|
|
138
148
|
# @attribute decline_code
|
139
|
-
# @return [String] The decline code as provided by your payment
|
149
|
+
# @return [String] The decline code as provided by your payment
|
150
|
+
# processor. If the transaction was not declined, do not include this
|
151
|
+
# field
|
140
152
|
attr_accessor :decline_code
|
141
153
|
|
142
154
|
# Creates Minfraud::Components::Payment instance
|
@@ -55,13 +55,13 @@ module Minfraud
|
|
55
55
|
# @return [Minfraud::Components::Report::Transaction] a Report::Transaction
|
56
56
|
# instance
|
57
57
|
def initialize(params = {})
|
58
|
-
@ip_address
|
58
|
+
@ip_address = params[:ip_address]
|
59
59
|
@chargeback_code = params[:chargeback_code]
|
60
|
-
@maxmind_id
|
61
|
-
@minfraud_id
|
62
|
-
@notes
|
63
|
-
@transaction_id
|
64
|
-
self.tag
|
60
|
+
@maxmind_id = params[:maxmind_id]
|
61
|
+
@minfraud_id = params[:minfraud_id]
|
62
|
+
@notes = params[:notes]
|
63
|
+
@transaction_id = params[:transaction_id]
|
64
|
+
self.tag = params[:tag]
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Components
|
3
5
|
class ShoppingCart < Base
|
@@ -5,6 +7,7 @@ module Minfraud
|
|
5
7
|
# @return [Array] An array of Minfraud::Components::ShoppingCartItem instances
|
6
8
|
|
7
9
|
attr_accessor :items
|
10
|
+
|
8
11
|
# Creates Minfraud::Components::ShoppingCart instance
|
9
12
|
# @param [Hash] params hash of parameters
|
10
13
|
# @return [Minfraud::Components::ShoppingCart] ShoppingCart instance
|
@@ -13,7 +16,7 @@ module Minfraud
|
|
13
16
|
end
|
14
17
|
|
15
18
|
# @return [Array] a JSON representation of Minfraud::Components::ShoppingCart items
|
16
|
-
def to_json
|
19
|
+
def to_json(*_args)
|
17
20
|
@items.map(&:to_json)
|
18
21
|
end
|
19
22
|
|
data/lib/minfraud/enum.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minfraud
|
2
4
|
module Enum
|
3
5
|
def self.included(base)
|
@@ -21,10 +23,11 @@ module Minfraud
|
|
21
23
|
define_method("#{attribute}_values") { mapping[attribute] }
|
22
24
|
end
|
23
25
|
|
24
|
-
|
25
|
-
define_method(
|
26
|
+
class_eval do
|
27
|
+
define_method(attribute.to_s) { instance_variable_get("@#{attribute}") }
|
26
28
|
define_method "#{attribute}=" do |value|
|
27
|
-
raise NotEnumValueError,
|
29
|
+
raise NotEnumValueError, 'Value is not permitted' if value && !self.class.mapping[attribute].include?(value.intern)
|
30
|
+
|
28
31
|
instance_variable_set("@#{attribute}", value ? value.intern : nil)
|
29
32
|
end
|
30
33
|
end
|
@@ -9,54 +9,54 @@ module Minfraud
|
|
9
9
|
def examine(response)
|
10
10
|
return response if response.status > 199 && response.status < 300
|
11
11
|
|
12
|
-
raise
|
12
|
+
raise(*STATUS_CODES.fetch(response.code, [ServerError, 'Server error']))
|
13
13
|
end
|
14
14
|
|
15
15
|
# A hash that maps status codes returned by minFraud with errors & messages
|
16
16
|
STATUS_CODES = {
|
17
|
-
IP_ADDRESS_INVALID:
|
17
|
+
IP_ADDRESS_INVALID: [
|
18
18
|
ClientError, 'You have not supplied a valid IPv4 or IPv6 address'
|
19
19
|
],
|
20
|
-
IP_ADDRESS_REQUIRED:
|
20
|
+
IP_ADDRESS_REQUIRED: [
|
21
21
|
ClientError, 'You have not supplied an IP address which is a required field'
|
22
22
|
],
|
23
|
-
IP_ADDRESS_RESERVED:
|
23
|
+
IP_ADDRESS_RESERVED: [
|
24
24
|
ClientError, 'You have supplied an IP address which is reserved'
|
25
25
|
],
|
26
|
-
JSON_INVALID:
|
26
|
+
JSON_INVALID: [
|
27
27
|
ClientError, 'JSON body cannot be decoded'
|
28
28
|
],
|
29
|
-
MAXMIND_ID_INVALID:
|
29
|
+
MAXMIND_ID_INVALID: [
|
30
30
|
ClientError, 'You have not supplied a valid maxmind_id'
|
31
31
|
],
|
32
|
-
MINFRAUD_ID_INVALID:
|
32
|
+
MINFRAUD_ID_INVALID: [
|
33
33
|
ClientError, 'You have not supplied a valid minfraud_id'
|
34
34
|
],
|
35
|
-
PARAMETER_UNKNOWN:
|
35
|
+
PARAMETER_UNKNOWN: [
|
36
36
|
ClientError, 'You have supplied an unknown parameter'
|
37
37
|
],
|
38
|
-
TAG_REQUIRED:
|
38
|
+
TAG_REQUIRED: [
|
39
39
|
ClientError, 'You have not supplied a tag, which is a required field'
|
40
40
|
],
|
41
|
-
TAG_INVALID:
|
41
|
+
TAG_INVALID: [
|
42
42
|
ClientError, 'You have not supplied a valid tag'
|
43
43
|
],
|
44
|
-
ACCOUNT_ID_REQUIRED:
|
44
|
+
ACCOUNT_ID_REQUIRED: [
|
45
45
|
AuthorizationError, 'You have not supplied a account ID'
|
46
46
|
],
|
47
47
|
AUTHORIZATION_INVALID: [
|
48
48
|
AuthorizationError, 'Invalid license key and / or account ID'
|
49
49
|
],
|
50
|
-
LICENSE_KEY_REQUIRED:
|
50
|
+
LICENSE_KEY_REQUIRED: [
|
51
51
|
AuthorizationError, 'You have not supplied a license key'
|
52
52
|
],
|
53
|
-
USER_ID_REQUIRED:
|
53
|
+
USER_ID_REQUIRED: [
|
54
54
|
AuthorizationError, 'You have not supplied a account id'
|
55
55
|
],
|
56
|
-
INSUFFICIENT_FUNDS:
|
56
|
+
INSUFFICIENT_FUNDS: [
|
57
57
|
ClientError, 'The license key you have provided does not have a sufficient funds to use this service'
|
58
58
|
],
|
59
|
-
PERMISSION_REQUIRED:
|
59
|
+
PERMISSION_REQUIRED: [
|
60
60
|
ClientError, 'You do not have permission to use this service'
|
61
61
|
]
|
62
62
|
}.freeze
|
data/lib/minfraud/errors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'faraday_middleware'
|
3
5
|
|
@@ -6,18 +8,26 @@ module Minfraud
|
|
6
8
|
class << self
|
7
9
|
# @return [Hash] default HTTPService configuration
|
8
10
|
def configuration
|
11
|
+
server = DEFAULT_SERVER
|
12
|
+
if !Minfraud.host.nil?
|
13
|
+
server = 'https://' + Minfraud.host + '/minfraud/v2.0'
|
14
|
+
end
|
15
|
+
|
9
16
|
{
|
10
17
|
middleware: DEFAULT_MIDDLEWARE,
|
11
|
-
server:
|
18
|
+
server: server,
|
12
19
|
}
|
13
20
|
end
|
14
21
|
end
|
15
22
|
|
16
23
|
# Minfraud default middleware stack
|
17
|
-
DEFAULT_MIDDLEWARE =
|
24
|
+
DEFAULT_MIDDLEWARE = proc do |builder|
|
18
25
|
builder.request :json
|
19
26
|
|
20
|
-
|
27
|
+
account_id = Minfraud.account_id
|
28
|
+
account_id = Minfraud.user_id if account_id.nil?
|
29
|
+
|
30
|
+
builder.basic_auth account_id, Minfraud.license_key
|
21
31
|
|
22
32
|
builder.response :json, content_type: /\bjson$/
|
23
33
|
|
@@ -25,6 +35,6 @@ module Minfraud
|
|
25
35
|
end
|
26
36
|
|
27
37
|
# Minfraud default server
|
28
|
-
DEFAULT_SERVER = 'https://minfraud.maxmind.com/minfraud/v2.0'
|
38
|
+
DEFAULT_SERVER = 'https://minfraud.maxmind.com/minfraud/v2.0'
|
29
39
|
end
|
30
40
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
|
3
5
|
module Minfraud
|
@@ -27,6 +29,7 @@ module Minfraud
|
|
27
29
|
end
|
28
30
|
|
29
31
|
private
|
32
|
+
|
30
33
|
# Creates memoized Faraday::Connection instance
|
31
34
|
# @return [Faraday::Connection] Faraday::Connection instance
|
32
35
|
def adapter
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minfraud/model/error'
|
2
4
|
require 'minfraud/model/factors'
|
3
5
|
require 'minfraud/model/insights'
|
@@ -55,9 +57,9 @@ module Minfraud
|
|
55
57
|
end
|
56
58
|
|
57
59
|
ENDPOINT_TO_CLASS = {
|
58
|
-
factors:
|
60
|
+
factors: Minfraud::Model::Factors,
|
59
61
|
insights: Minfraud::Model::Insights,
|
60
|
-
score:
|
62
|
+
score: Minfraud::Model::Score
|
61
63
|
}.freeze
|
62
64
|
end
|
63
65
|
end
|