minfraud 1.6.0 → 2.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +1 -1
  3. data/.github/workflows/test.yml +1 -0
  4. data/.rubocop.yml +1 -20
  5. data/CHANGELOG.md +80 -4
  6. data/Gemfile +0 -9
  7. data/LICENSE.txt +1 -1
  8. data/README.md +4 -4
  9. data/lib/minfraud/assessments.rb +21 -16
  10. data/lib/minfraud/components/account.rb +1 -1
  11. data/lib/minfraud/components/billing.rb +1 -1
  12. data/lib/minfraud/components/credit_card.rb +40 -8
  13. data/lib/minfraud/components/custom_inputs.rb +1 -1
  14. data/lib/minfraud/components/device.rb +1 -1
  15. data/lib/minfraud/components/email.rb +1 -1
  16. data/lib/minfraud/components/event.rb +11 -11
  17. data/lib/minfraud/components/order.rb +1 -1
  18. data/lib/minfraud/components/payment.rb +153 -142
  19. data/lib/minfraud/components/report/transaction.rb +2 -2
  20. data/lib/minfraud/components/shipping.rb +2 -2
  21. data/lib/minfraud/components/shopping_cart.rb +1 -1
  22. data/lib/minfraud/components/shopping_cart_item.rb +3 -3
  23. data/lib/minfraud/http_service/response.rb +28 -21
  24. data/lib/minfraud/model/device.rb +1 -1
  25. data/lib/minfraud/model/disposition.rb +3 -3
  26. data/lib/minfraud/model/factors.rb +1 -1
  27. data/lib/minfraud/model/ip_address.rb +4 -47
  28. data/lib/minfraud/model/score.rb +1 -1
  29. data/lib/minfraud/model/subscores.rb +1 -23
  30. data/lib/minfraud/report.rb +19 -11
  31. data/lib/minfraud/validates.rb +2 -2
  32. data/lib/minfraud/version.rb +1 -1
  33. data/lib/minfraud.rb +18 -24
  34. data/minfraud.gemspec +13 -10
  35. metadata +47 -67
  36. data/lib/maxmind/geoip2/model/city.rb +0 -99
  37. data/lib/maxmind/geoip2/model/country.rb +0 -94
  38. data/lib/maxmind/geoip2/model/insights.rb +0 -38
  39. data/lib/maxmind/geoip2/record/abstract.rb +0 -46
  40. data/lib/maxmind/geoip2/record/city.rb +0 -62
  41. data/lib/maxmind/geoip2/record/continent.rb +0 -61
  42. data/lib/maxmind/geoip2/record/country.rb +0 -78
  43. data/lib/maxmind/geoip2/record/location.rb +0 -97
  44. data/lib/maxmind/geoip2/record/maxmind.rb +0 -41
  45. data/lib/maxmind/geoip2/record/place.rb +0 -52
  46. data/lib/maxmind/geoip2/record/postal.rb +0 -54
  47. data/lib/maxmind/geoip2/record/represented_country.rb +0 -47
  48. data/lib/maxmind/geoip2/record/subdivision.rb +0 -72
  49. data/lib/maxmind/geoip2/record/traits.rb +0 -233
  50. data/lib/minfraud/http_service/request.rb +0 -38
  51. data/lib/minfraud/http_service.rb +0 -45
@@ -4,7 +4,7 @@ module Minfraud
4
4
  module Components
5
5
  # Payment corresponds to the payment object of a minFraud request.
6
6
  #
7
- # @see https://dev.maxmind.com/minfraud/#Payment_(/payment)
7
+ # @see https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--payment
8
8
  class Payment < Base
9
9
  include ::Minfraud::Enum
10
10
  include Minfraud::Validates
@@ -15,147 +15,158 @@ module Minfraud
15
15
  # @!attribute processor
16
16
  #
17
17
  # @return [Symbol, nil]
18
- enum_accessor :processor, [
19
- :adyen,
20
- :affirm,
21
- :afterpay,
22
- :altapay,
23
- :amazon_payments,
24
- :american_express_payment_gateway,
25
- :apple_pay,
26
- :aps_payments,
27
- :authorizenet,
28
- :balanced,
29
- :beanstream,
30
- :bluepay,
31
- :bluesnap,
32
- :bpoint,
33
- :braintree,
34
- :cardknox,
35
- :cardpay,
36
- :cashfree,
37
- :ccavenue,
38
- :ccnow,
39
- :cetelem,
40
- :chase_paymentech,
41
- :checkout_com,
42
- :cielo,
43
- :collector,
44
- :commdoo,
45
- :compropago,
46
- :concept_payments,
47
- :conekta,
48
- :creditguard,
49
- :credorax,
50
- :ct_payments,
51
- :cuentadigital,
52
- :curopayments,
53
- :cybersource,
54
- :dalenys,
55
- :dalpay,
56
- :datacap,
57
- :datacash,
58
- :dibs,
59
- :digital_river,
60
- :dlocal,
61
- :dotpay,
62
- :ebs,
63
- :ecomm365,
64
- :ecommpay,
65
- :elavon,
66
- :emerchantpay,
67
- :epay,
68
- :eprocessing_network,
69
- :epx,
70
- :eway,
71
- :exact,
72
- :first_atlantic_commerce,
73
- :first_data,
74
- :g2a_pay,
75
- :global_payments,
76
- :gocardless,
77
- :heartland,
78
- :hipay,
79
- :ingenico,
80
- :interac,
81
- :internetsecure,
82
- :intuit_quickbooks_payments,
83
- :iugu,
84
- :klarna,
85
- :komoju,
86
- :lemon_way,
87
- :mastercard_payment_gateway,
88
- :mercadopago,
89
- :mercanet,
90
- :merchant_esolutions,
91
- :mirjeh,
92
- :mollie,
93
- :moneris_solutions,
94
- :nmi,
95
- :oceanpayment,
96
- :oney,
97
- :onpay,
98
- :openpaymx,
99
- :optimal_payments,
100
- :orangepay,
101
- :other,
102
- :pacnet_services,
103
- :payeezy,
104
- :payfast,
105
- :paygate,
106
- :paylike,
107
- :payment_express,
108
- :paymentwall,
109
- :payone,
110
- :paypal,
111
- :payplus,
112
- :paysafecard,
113
- :paystation,
114
- :paytm,
115
- :paytrace,
116
- :paytrail,
117
- :payture,
118
- :payu,
119
- :payulatam,
120
- :payway,
121
- :payza,
122
- :pinpayments,
123
- :posconnect,
124
- :princeton_payment_solutions,
125
- :psigate,
126
- :qiwi,
127
- :quickpay,
128
- :raberil,
129
- :razorpay,
130
- :rede,
131
- :redpagos,
132
- :rewardspay,
133
- :safecharge,
134
- :sagepay,
135
- :securetrading,
136
- :simplify_commerce,
137
- :skrill,
138
- :smartcoin,
139
- :smartdebit,
140
- :solidtrust_pay,
141
- :sps_decidir,
142
- :stripe,
143
- :synapsefi,
144
- :systempay,
145
- :telerecargas,
146
- :towah,
147
- :transact_pro,
148
- :tsys,
149
- :usa_epay,
150
- :vantiv,
151
- :verepay,
152
- :vericheck,
153
- :vindicia,
154
- :virtual_card_services,
155
- :vme,
156
- :vpos,
157
- :wirecard,
158
- :worldpay
18
+ enum_accessor :processor, %i[
19
+ adyen
20
+ affirm
21
+ afterpay
22
+ altapay
23
+ amazon_payments
24
+ american_express_payment_gateway
25
+ apple_pay
26
+ aps_payments
27
+ authorizenet
28
+ balanced
29
+ beanstream
30
+ bluepay
31
+ bluesnap
32
+ boacompra
33
+ boku
34
+ bpoint
35
+ braintree
36
+ cardknox
37
+ cardpay
38
+ cashfree
39
+ ccavenue
40
+ ccnow
41
+ cetelem
42
+ chase_paymentech
43
+ checkout_com
44
+ cielo
45
+ collector
46
+ commdoo
47
+ compropago
48
+ concept_payments
49
+ conekta
50
+ coregateway
51
+ creditguard
52
+ credorax
53
+ ct_payments
54
+ cuentadigital
55
+ curopayments
56
+ cybersource
57
+ dalenys
58
+ dalpay
59
+ datacap
60
+ datacash
61
+ dibs
62
+ digital_river
63
+ dlocal
64
+ dotpay
65
+ ebs
66
+ ecomm365
67
+ ecommpay
68
+ elavon
69
+ emerchantpay
70
+ epay
71
+ eprocessing_network
72
+ epx
73
+ eway
74
+ exact
75
+ first_atlantic_commerce
76
+ first_data
77
+ fiserv
78
+ g2a_pay
79
+ global_payments
80
+ gocardless
81
+ heartland
82
+ hipay
83
+ ingenico
84
+ interac
85
+ internetsecure
86
+ intuit_quickbooks_payments
87
+ iugu
88
+ klarna
89
+ komoju
90
+ lemon_way
91
+ mastercard_payment_gateway
92
+ mercadopago
93
+ mercanet
94
+ merchant_esolutions
95
+ mirjeh
96
+ mollie
97
+ moneris_solutions
98
+ neopay
99
+ neosurf
100
+ nmi
101
+ oceanpayment
102
+ oney
103
+ onpay
104
+ openbucks
105
+ openpaymx
106
+ optimal_payments
107
+ orangepay
108
+ other
109
+ pacnet_services
110
+ payeezy
111
+ payfast
112
+ paygate
113
+ paylike
114
+ payment_express
115
+ paymentwall
116
+ payone
117
+ paypal
118
+ payplus
119
+ paysafecard
120
+ paysera
121
+ paystation
122
+ paytm
123
+ paytrace
124
+ paytrail
125
+ payture
126
+ payu
127
+ payulatam
128
+ payvision
129
+ payway
130
+ payza
131
+ pinpayments
132
+ posconnect
133
+ princeton_payment_solutions
134
+ psigate
135
+ qiwi
136
+ quickpay
137
+ raberil
138
+ razorpay
139
+ rede
140
+ redpagos
141
+ rewardspay
142
+ safecharge
143
+ sagepay
144
+ securetrading
145
+ simplify_commerce
146
+ skrill
147
+ smartcoin
148
+ smartdebit
149
+ solidtrust_pay
150
+ sps_decidir
151
+ stripe
152
+ synapsefi
153
+ systempay
154
+ telerecargas
155
+ towah
156
+ transact_pro
157
+ trustly
158
+ tsys
159
+ usa_epay
160
+ vantiv
161
+ verepay
162
+ vericheck
163
+ vindicia
164
+ virtual_card_services
165
+ vme
166
+ vpos
167
+ windcave
168
+ wirecard
169
+ worldpay
159
170
  ]
160
171
 
161
172
  # The authorization outcome from the payment processor. If the
@@ -5,7 +5,7 @@ module Minfraud
5
5
  module Report
6
6
  # Contains the fields used in the Report Transaction API.
7
7
  #
8
- # @see https://dev.maxmind.com/minfraud/report-transaction/
8
+ # @see https://dev.maxmind.com/minfraud/report-a-transaction?lang=en
9
9
  class Transaction < Base
10
10
  include ::Minfraud::Enum
11
11
 
@@ -24,7 +24,7 @@ module Minfraud
24
24
  # @!attribute tag
25
25
  #
26
26
  # @return [Symbol, nil]
27
- enum_accessor :tag, [:chargeback, :not_fraud, :spam_or_abuse, :suspected_fraud]
27
+ enum_accessor :tag, %i[chargeback not_fraud spam_or_abuse suspected_fraud]
28
28
 
29
29
  # A string which is provided by your payment processor indicating the
30
30
  # reason for the chargeback.
@@ -4,7 +4,7 @@ module Minfraud
4
4
  module Components
5
5
  # Shipping corresponds to the shipping object of a minFraud request.
6
6
  #
7
- # @see https://dev.maxmind.com/minfraud/#Shipping_(/shipping)
7
+ # @see https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--shipping
8
8
  class Shipping < Addressable
9
9
  include ::Minfraud::Enum
10
10
 
@@ -14,7 +14,7 @@ module Minfraud
14
14
  # @!attribute delivery_speed
15
15
  #
16
16
  # @return [Symbol, nil]
17
- enum_accessor :delivery_speed, [:same_day, :overnight, :expedited, :standard]
17
+ enum_accessor :delivery_speed, %i[same_day overnight expedited standard]
18
18
 
19
19
  # @param params [Hash] Hash of parameters. Each key/value should
20
20
  # correspond to one of the available attributes.
@@ -5,7 +5,7 @@ module Minfraud
5
5
  # ShoppingCart corresponds to the shopping_cart object of a minFraud
6
6
  # request.
7
7
  #
8
- # @see https://dev.maxmind.com/minfraud/#Shopping_Cart_(/shoppingcart)
8
+ # @see https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--shopping-cart
9
9
  class ShoppingCart < Base
10
10
  # An array of Minfraud::Components::ShoppingCartItem instances.
11
11
  #
@@ -5,20 +5,20 @@ module Minfraud
5
5
  # ShoppingCartItem corresponds to objects in the shopping_cart object
6
6
  # of a minFraud request.
7
7
  #
8
- # @see https://dev.maxmind.com/minfraud/#Shopping_Cart_Item
8
+ # @see https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--shopping-cart--item
9
9
  class ShoppingCartItem < Base
10
10
  include Minfraud::Validates
11
11
 
12
12
  # The category of the item. This can also be a hashed value; see link.
13
13
  #
14
- # @see https://dev.maxmind.com/minfraud/#cart-hashing
14
+ # @see https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--shopping-cart--item__category
15
15
  #
16
16
  # @return [String, nil]
17
17
  attr_accessor :category
18
18
 
19
19
  # The internal ID of the item. This can also be a hashed value; see link.
20
20
  #
21
- # @see https://dev.maxmind.com/minfraud/#cart-hashing
21
+ # @see https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--shopping-cart--item__item_id
22
22
  #
23
23
  # @return [String, nil]
24
24
  attr_accessor :item_id
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'minfraud/model/error'
4
5
  require 'minfraud/model/factors'
5
6
  require 'minfraud/model/insights'
@@ -9,32 +10,35 @@ module Minfraud
9
10
  module HTTPService
10
11
  # Response class for HTTP requests.
11
12
  class Response
12
- # HTTP response status.
13
+ # Response HTTP status code.
13
14
  #
14
- # @return [Integer, nil]
15
+ # @return [Fixnum, nil]
15
16
  attr_reader :status
16
17
 
17
- # HTTP response model.
18
+ # Response model.
18
19
  #
19
20
  # @return [Minfraud::Model::Score, Minfraud::Model::Insights,
20
21
  # Minfraud::Model::Factors, nil]
21
22
  attr_reader :body
22
23
 
23
- # HTTP response headers.
24
+ # @param endpoint [Symbol, nil] endpoint name, like :score.
24
25
  #
25
- # @return [Hash, nil]
26
- attr_reader :headers
26
+ # @param locales [Array<String>, nil] locales, like ["en"].
27
+ #
28
+ # @param response [HTTP::Response] the response object.
29
+ #
30
+ # @param body [String] the response body.
31
+ #
32
+ # @raise [JSON::ParserError] if there was invalid JSON in the response.
33
+ def initialize(endpoint, locales, response, body)
34
+ @status = response.code
27
35
 
28
- # @param params [Hash] Hash of parameters. +:status+, +:endpoint+,
29
- # +:body+, +:locales+, and +:headers+ are used.
30
- def initialize(params = {})
31
- @status = params[:status]
32
- @body = make_body(
33
- params[:endpoint],
34
- params[:body],
35
- params[:locales]
36
+ @body = make_body(
37
+ endpoint,
38
+ locales,
39
+ response,
40
+ body,
36
41
  )
37
- @headers = params[:headers]
38
42
  end
39
43
 
40
44
  # Return the minFraud-specific response code.
@@ -48,15 +52,18 @@ module Minfraud
48
52
 
49
53
  private
50
54
 
51
- def make_body(endpoint, body, locales)
52
- if @status != 200
53
- # Won't be a Hash when the body is not JSON.
54
- return nil unless body.is_a?(Hash)
55
+ def make_body(endpoint, locales, response, body)
56
+ if !response.mime_type || !response.mime_type.match(/json/i)
57
+ return nil
58
+ end
59
+
60
+ h = JSON.parse(body)
55
61
 
56
- return Minfraud::Model::Error.new(body)
62
+ if @status != 200
63
+ return Minfraud::Model::Error.new(h)
57
64
  end
58
65
 
59
- ENDPOINT_TO_CLASS[endpoint].new(body, locales)
66
+ ENDPOINT_TO_CLASS[endpoint].new(h, locales)
60
67
  end
61
68
 
62
69
  ENDPOINT_TO_CLASS = {
@@ -8,7 +8,7 @@ module Minfraud
8
8
  #
9
9
  # In order to receive device output from minFraud Insights or minFraud
10
10
  # Factors, you must be using the Device Tracking Add-on
11
- # (https://dev.maxmind.com/minfraud/device/).
11
+ # (https://dev.maxmind.com/minfraud/track-devices?lang=en).
12
12
  class Device < Abstract
13
13
  # This number represents our confidence that the device_id refers to a
14
14
  # unique device as opposed to a cluster of similar devices. A confidence
@@ -11,14 +11,14 @@ module Minfraud
11
11
  class Disposition < Abstract
12
12
  # The action to take on the transaction as defined by your custom rules.
13
13
  # The current set of values are "accept", "manual_review", "reject", and
14
- # "test". If you do not have custom rules set up, this will be nil.
14
+ # "test". If you do not have custom rules set up, this will be nil.
15
15
  #
16
16
  # @return [String, nil]
17
17
  attr_reader :action
18
18
 
19
19
  # The reason for the action. The current possible values are
20
- # "custom_rule", "block_list", and "default". If you do not have custom
21
- # rules set up, this will be nil.
20
+ # "custom_rule" and "default". If you do not have custom rules set up,
21
+ # this will be nil.
22
22
  #
23
23
  # @return [String, nil]
24
24
  attr_reader :reason
@@ -7,7 +7,7 @@ module Minfraud
7
7
  module Model
8
8
  # Model representing the Factors response.
9
9
  class Factors < Insights
10
- # An object containing subscores for many of the individual components
10
+ # An object containing scores for many of the individual risk factors
11
11
  # that are used to calculate the overall risk score.
12
12
  #
13
13
  # @return [Minfraud::Model::Subscores]
@@ -41,61 +41,18 @@ module Minfraud
41
41
  end
42
42
 
43
43
  @risk_reasons = []
44
- if record && record.key?('risk_reasons')
44
+ if record&.key?('risk_reasons')
45
45
  record['risk_reasons'].each do |r|
46
46
  @risk_reasons << Minfraud::Model::IPRiskReason.new(r)
47
47
  end
48
48
  end
49
49
 
50
- # Decorate objects with deprecated attributes and names for backwards
51
- # compatibility. Do this here rather than with the overhead of
52
- # subclasses/modules for them in the hope that one day we can delete
53
- # them.
54
-
55
- # These are named differently in maxmind-geoip2.
56
- @country.define_singleton_method(:is_in_european_union) { in_european_union? }
57
- @registered_country.define_singleton_method(:is_in_european_union) { in_european_union? }
58
- @represented_country.define_singleton_method(:is_in_european_union) { in_european_union? }
59
- @traits.define_singleton_method(:is_anonymous) { anonymous? }
60
- @traits.define_singleton_method(:is_anonymous_vpn) { anonymous_vpn? }
61
- @traits.define_singleton_method(:is_hosting_provider) { hosting_provider? }
62
- @traits.define_singleton_method(:is_public_proxy) { public_proxy? }
63
- @traits.define_singleton_method(:is_tor_exit_node) { tor_exit_node? }
64
-
65
- # Mashify turned each language code into an attribute, but
66
- # maxmind-geoip2 exposes the names as a hash.
67
- LANGUAGE_CODES.each do |c|
68
- if @city.names
69
- @city.names.define_singleton_method(c) { fetch(c.to_s, nil) }
70
- end
71
- if @continent.names
72
- @continent.names.define_singleton_method(c) { fetch(c.to_s, nil) }
73
- end
74
- if @country.names
75
- @country.names.define_singleton_method(c) { fetch(c.to_s, nil) }
76
- end
77
- if @registered_country.names
78
- @registered_country.names.define_singleton_method(c) { fetch(c.to_s, nil) }
79
- end
80
- if @represented_country.names
81
- @represented_country.names.define_singleton_method(c) { fetch(c.to_s, nil) }
82
- end
83
- @subdivisions.each do |s|
84
- if s.names
85
- s.names.define_singleton_method(c) { fetch(c.to_s, nil) }
86
- end
87
- end
88
- end
89
-
90
- # This attribute is deprecated.
91
- @country.define_singleton_method(:is_high_risk) { get('is_high_risk') }
92
-
93
- # These attributes are deprecated and aren't in maxmind-geoip2.
50
+ # These attributes are deprecated and aren't in maxmind-geoip2. The
51
+ # webservice still sends them as of writing, so we'd like to keep them
52
+ # for now as they could still be providing value.
94
53
  @traits.define_singleton_method(:is_anonymous_proxy) { get('is_anonymous_proxy') }
95
54
  @traits.define_singleton_method(:is_satellite_provider) { get('is_satellite_provider') }
96
55
  end
97
-
98
- LANGUAGE_CODES = [:de, :en, :es, :fr, :ja, :'pt-BR', :ru, :'zh-CN'].freeze
99
56
  end
100
57
  end
101
58
  end
@@ -65,7 +65,7 @@ module Minfraud
65
65
  @queries_remaining = get('queries_remaining')
66
66
  @risk_score = get('risk_score')
67
67
  @warnings = []
68
- if record && record.key?('warnings')
68
+ if record&.key?('warnings')
69
69
  record['warnings'].each do |w|
70
70
  @warnings << Minfraud::Model::Warning.new(w)
71
71
  end
@@ -4,7 +4,7 @@ require 'minfraud/model/abstract'
4
4
 
5
5
  module Minfraud
6
6
  module Model
7
- # Subscores for components that are used in calculating the riskScore.
7
+ # Score for risk factors that are used in calculating the riskScore.
8
8
  class Subscores < Abstract
9
9
  # The risk associated with the AVS result. If present, this is a value in
10
10
  # the range 0.01 to 99.
@@ -84,26 +84,6 @@ module Minfraud
84
84
  # @return [Float, nil]
85
85
  attr_reader :email_local_part
86
86
 
87
- # The risk associated with the issuer ID number on the email domain. If
88
- # present, this is a value in the range 0.01 to 99.
89
- #
90
- # Deprecated effective August 29, 2019. This subscore will default to 1
91
- # and will be removed in a future release. The user tenure on email is
92
- # reflected in the /subscores/email_address output.
93
- #
94
- # @return [Float, nil]
95
- attr_reader :email_tenure
96
-
97
- # The risk associated with the issuer ID number on the IP address. If
98
- # present, this is a value in the range 0.01 to 99.
99
- #
100
- # Deprecated effective August 29, 2019. This subscore will default to 1
101
- # and will be removed in a future release. The IP tenure is reflected in
102
- # the overall risk score.
103
- #
104
- # @return [Float, nil]
105
- attr_reader :ip_tenure
106
-
107
87
  # The risk associated with the particular issuer ID number (IIN) given
108
88
  # the billing location and the history of usage of the IIN on your
109
89
  # account and shop ID. If present, this is a value in the range 0.01 to
@@ -162,8 +142,6 @@ module Minfraud
162
142
  @email_address = get('email_address')
163
143
  @email_domain = get('email_domain')
164
144
  @email_local_part = get('email_local_part')
165
- @email_tenure = get('email_tenure')
166
- @ip_tenure = get('ip_tenure')
167
145
  @issuer_id_number = get('issuer_id_number')
168
146
  @order_amount = get('order_amount')
169
147
  @phone_number = get('phone_number')