minfraud 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.travis.yml +20 -3
  4. data/CHANGELOG.md +31 -3
  5. data/CODE_OF_CONDUCT.md +4 -4
  6. data/Gemfile +9 -2
  7. data/LICENSE.txt +2 -1
  8. data/README.dev.md +4 -0
  9. data/README.md +106 -35
  10. data/lib/maxmind/geoip2/model/city.rb +99 -0
  11. data/lib/maxmind/geoip2/model/country.rb +94 -0
  12. data/lib/maxmind/geoip2/model/insights.rb +38 -0
  13. data/lib/maxmind/geoip2/record/abstract.rb +46 -0
  14. data/lib/maxmind/geoip2/record/city.rb +62 -0
  15. data/lib/maxmind/geoip2/record/continent.rb +61 -0
  16. data/lib/maxmind/geoip2/record/country.rb +78 -0
  17. data/lib/maxmind/geoip2/record/location.rb +97 -0
  18. data/lib/maxmind/geoip2/record/maxmind.rb +41 -0
  19. data/lib/maxmind/geoip2/record/place.rb +52 -0
  20. data/lib/maxmind/geoip2/record/postal.rb +54 -0
  21. data/lib/maxmind/geoip2/record/represented_country.rb +47 -0
  22. data/lib/maxmind/geoip2/record/subdivision.rb +72 -0
  23. data/lib/maxmind/geoip2/record/traits.rb +224 -0
  24. data/lib/minfraud.rb +5 -3
  25. data/lib/minfraud/assessments.rb +14 -5
  26. data/lib/minfraud/components/account.rb +1 -1
  27. data/lib/minfraud/components/addressable.rb +1 -1
  28. data/lib/minfraud/components/custom_inputs.rb +14 -0
  29. data/lib/minfraud/components/device.rb +11 -0
  30. data/lib/minfraud/components/event.rb +12 -1
  31. data/lib/minfraud/components/payment.rb +124 -12
  32. data/lib/minfraud/components/report/transaction.rb +69 -0
  33. data/lib/minfraud/error_handler.rb +36 -16
  34. data/lib/minfraud/http_service.rb +0 -1
  35. data/lib/minfraud/http_service/response.rb +36 -4
  36. data/lib/minfraud/model/abstract.rb +20 -0
  37. data/lib/minfraud/model/address.rb +52 -0
  38. data/lib/minfraud/model/billing_address.rb +11 -0
  39. data/lib/minfraud/model/credit_card.rb +75 -0
  40. data/lib/minfraud/model/device.rb +54 -0
  41. data/lib/minfraud/model/disposition.rb +35 -0
  42. data/lib/minfraud/model/email.rb +54 -0
  43. data/lib/minfraud/model/email_domain.rb +24 -0
  44. data/lib/minfraud/model/error.rb +28 -0
  45. data/lib/minfraud/model/factors.rb +24 -0
  46. data/lib/minfraud/model/geoip2_location.rb +25 -0
  47. data/lib/minfraud/model/insights.rb +68 -0
  48. data/lib/minfraud/model/ip_address.rb +82 -0
  49. data/lib/minfraud/model/issuer.rb +49 -0
  50. data/lib/minfraud/model/score.rb +76 -0
  51. data/lib/minfraud/model/score_ip_address.rb +23 -0
  52. data/lib/minfraud/model/shipping_address.rb +30 -0
  53. data/lib/minfraud/model/subscores.rb +156 -0
  54. data/lib/minfraud/model/warning.rb +63 -0
  55. data/lib/minfraud/report.rb +38 -0
  56. data/lib/minfraud/resolver.rb +2 -1
  57. data/lib/minfraud/version.rb +1 -1
  58. data/minfraud.gemspec +16 -16
  59. metadata +61 -39
@@ -5,15 +5,16 @@ require 'minfraud/components/account'
5
5
  require 'minfraud/components/addressable'
6
6
  require 'minfraud/components/billing'
7
7
  require 'minfraud/components/credit_card'
8
+ require 'minfraud/components/custom_inputs'
8
9
  require 'minfraud/components/device'
9
10
  require 'minfraud/components/email'
10
11
  require 'minfraud/components/event'
11
12
  require 'minfraud/components/order'
12
13
  require 'minfraud/components/payment'
13
- require 'minfraud/components/shopping_cart_item'
14
+ require 'minfraud/components/report/transaction'
14
15
  require 'minfraud/components/shipping'
15
16
  require 'minfraud/components/shopping_cart'
16
- require 'minfraud/components/device'
17
+ require 'minfraud/components/shopping_cart_item'
17
18
  require 'minfraud/resolver'
18
19
  require 'minfraud/version'
19
20
  require 'minfraud/errors'
@@ -22,11 +23,12 @@ require 'minfraud/http_service/request'
22
23
  require 'minfraud/http_service/response'
23
24
  require 'minfraud/error_handler'
24
25
  require 'minfraud/assessments'
26
+ require 'minfraud/report'
25
27
 
26
28
  module Minfraud
27
29
  class << self
28
30
  # @!attribute user_id
29
- # @return [String] MaxMind username that is used for authorization
31
+ # @return [String] MaxMind account ID that is used for authorization
30
32
  attr_accessor :user_id
31
33
 
32
34
  # @!attribute license_key
@@ -15,6 +15,10 @@ module Minfraud
15
15
  # @return [Minfraud::Components::CreditCard] CreditCard component
16
16
  attr_accessor :credit_card
17
17
 
18
+ # @attribute custom_inputs
19
+ # @return [Minfraud::Components::CustomInputs] CustomInputs component
20
+ attr_accessor :custom_inputs
21
+
18
22
  # @attribute device
19
23
  # @return [Minfraud::Components::Device] Device component
20
24
  attr_accessor :device
@@ -40,7 +44,7 @@ module Minfraud
40
44
  attr_accessor :shipping
41
45
 
42
46
  # @!attribute shopping_cart
43
- # @return [Minfraud::Components::ShoppingCarat] ShoppingCart component
47
+ # @return [Minfraud::Components::ShoppingCart] ShoppingCart component
44
48
  attr_accessor :shopping_cart
45
49
 
46
50
  # @param [Hash] params hash of parameters
@@ -48,6 +52,9 @@ module Minfraud
48
52
  # @note In case when params is a Hash of components it just assigns them to the corresponding instance variables
49
53
  # @return [Minfraud::Assessments] Assessments instance
50
54
  def initialize(params = {}, resolver = ::Minfraud::Resolver)
55
+ @locales = params.delete('locales')
56
+ @locales = ['en'] if @locales.nil?
57
+
51
58
  resolver.assign(self, params)
52
59
  end
53
60
 
@@ -60,12 +67,14 @@ module Minfraud
60
67
  define_method(endpoint) do
61
68
  raw = request.perform(verb: :post, endpoint: endpoint.to_s, body: request_body)
62
69
  response = ::Minfraud::HTTPService::Response.new(
63
- status: raw.status.to_i,
64
- body: raw.body,
65
- headers: raw.headers
70
+ endpoint: endpoint,
71
+ locales: @locales,
72
+ status: raw.status.to_i,
73
+ body: raw.body,
74
+ headers: raw.headers
66
75
  )
67
76
 
68
- ::Minfraud::ErrorHandler.inspect(response)
77
+ ::Minfraud::ErrorHandler.examine(response)
69
78
  end
70
79
  end
71
80
 
@@ -4,7 +4,7 @@ module Minfraud
4
4
  # @attribute user_id
5
5
  # @return [String] A unique user ID associated with the end-user in your system.
6
6
  # If your system allows the login name for the account to be changed, this should not be the login name for the account,
7
- # but rather should be an internal ID that does not change. This is not your MaxMind user ID
7
+ # but rather should be an internal ID that does not change. This is not your MaxMind user ID.
8
8
  attr_accessor :user_id
9
9
 
10
10
  # @attribute username_md5
@@ -22,7 +22,7 @@ module Minfraud
22
22
  attr_accessor :address_2
23
23
 
24
24
  # @attribute city
25
- # @return [String] The city of the users billing / shipping address
25
+ # @return [String] The city of the user's billing / shipping address
26
26
  attr_accessor :city
27
27
 
28
28
  # @attribute region
@@ -0,0 +1,14 @@
1
+ module Minfraud
2
+ module Components
3
+ class CustomInputs < Base
4
+ # Creates Minfraud::Components::CustomInputs instance
5
+ # @param [Hash] params hash with keys that match your created custom input keys
6
+ # @return [Minfraud::Components::CustomInputs] a CustomInputs instance
7
+ def initialize(params = {})
8
+ params.each do |name, value|
9
+ instance_variable_set("@#{name}", value)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -14,6 +14,15 @@ module Minfraud
14
14
  # @return [String] The HTTP "Accept-Language" header of the browser used in the transaction
15
15
  attr_accessor :accept_language
16
16
 
17
+ # @attribute :session_age
18
+ # @return [Decimal] The number of seconds between the creation of the user’s session and the time of the transaction.
19
+ # Note that session_age is not the duration of the current visit, but the time since the start of the first visit.
20
+ attr_accessor :session_age
21
+
22
+ # @attribute :session_id
23
+ # @return [String] An ID that uniquely identifies a visitor’s session on the site.
24
+ attr_accessor :session_id
25
+
17
26
  # Creates Minfraud::Components::Device instance
18
27
  # @param [Hash] params hash of parameters
19
28
  # @return [Minfraud::Components::Device] a Device instance
@@ -21,6 +30,8 @@ module Minfraud
21
30
  @ip_address = params[:ip_address]
22
31
  @user_agent = params[:user_agent]
23
32
  @accept_language = params[:accept_language]
33
+ @session_age = params[:session_age]
34
+ @session_id = params[:session_id]
24
35
  end
25
36
  end
26
37
  end
@@ -17,7 +17,18 @@ module Minfraud
17
17
 
18
18
  # @attribute type
19
19
  # @return [String] The type of event being scored
20
- enum_accessor :type, [:account_creation, :account_login, :purchase, :recurring_purchase, :referral, :survey]
20
+ enum_accessor :type,
21
+ [
22
+ :account_creation,
23
+ :account_login,
24
+ :email_change,
25
+ :password_reset,
26
+ :payout_change,
27
+ :purchase,
28
+ :recurring_purchase,
29
+ :referral,
30
+ :survey,
31
+ ]
21
32
 
22
33
  # Creates Minfraud::Components::Event instance
23
34
  # @param [Hash] params hash of parameters
@@ -5,18 +5,130 @@ module Minfraud
5
5
  # @attribute processor
6
6
  # @return [String] The payment processor used for the transaction
7
7
  enum_accessor :processor, [
8
- :adyen, :altapay, :amazon_payments, :authorizenet, :balanced, :beanstream,
9
- :bluepay, :braintree, :ccnow, :chase_paymentech, :cielo, :collector, :compropago,
10
- :concept_payments, :conekta, :cuentadigital, :dalpay, :dibs, :digital_river, :ecomm365,
11
- :elavon, :epay, :eprocessing_network, :eway, :first_data, :global_payments, :ingenico,
12
- :internetsecure, :intuit_quickbooks_payments, :iugu, :mastercard_payment_gateway,
13
- :mercadopago, :merchant_esolutions, :mirjeh, :mollie, :moneris_solutions, :nmi,
14
- :openpaymx, :optimal_payments, :orangepay, :other, :pacnet_services, :payfast,
15
- :paygate, :payone, :paypal, :payplus, :paystation, :paytrace, :paytrail, :payture,
16
- :payu, :payulatam, :pinpayments, :princeton_payment_solutions, :psigate, :qiwi,
17
- :quickpay, :raberil, :rede, :redpagos, :rewardspay, :sagepay, :simplify_commerce,
18
- :skrill, :smartcoin, :sps_decidir, :stripe, :telerecargas, :towah, :usa_epay,
19
- :verepay, :vindicia, :virtual_card_services, :vme, :worldpay
8
+ :adyen,
9
+ :affirm,
10
+ :afterpay,
11
+ :altapay,
12
+ :amazon_payments,
13
+ :american_express_payment_gateway,
14
+ :authorizenet,
15
+ :balanced,
16
+ :beanstream,
17
+ :bluepay,
18
+ :bluesnap,
19
+ :bpoint,
20
+ :braintree,
21
+ :cardpay,
22
+ :ccavenue,
23
+ :ccnow,
24
+ :cetelem,
25
+ :chase_paymentech,
26
+ :checkout_com,
27
+ :cielo,
28
+ :collector,
29
+ :commdoo,
30
+ :compropago,
31
+ :concept_payments,
32
+ :conekta,
33
+ :ct_payments,
34
+ :cuentadigital,
35
+ :curopayments,
36
+ :cybersource,
37
+ :dalenys,
38
+ :dalpay,
39
+ :datacash,
40
+ :dibs,
41
+ :digital_river,
42
+ :dotpay,
43
+ :ebs,
44
+ :ecomm365,
45
+ :ecommpay,
46
+ :elavon,
47
+ :emerchantpay,
48
+ :epay,
49
+ :eprocessing_network,
50
+ :epx,
51
+ :eway,
52
+ :exact,
53
+ :first_data,
54
+ :g2a_pay,
55
+ :global_payments,
56
+ :gocardless,
57
+ :heartland,
58
+ :hipay,
59
+ :ingenico,
60
+ :interac,
61
+ :internetsecure,
62
+ :intuit_quickbooks_payments,
63
+ :iugu,
64
+ :klarna,
65
+ :lemon_way,
66
+ :mastercard_payment_gateway,
67
+ :mercadopago,
68
+ :mercanet,
69
+ :merchant_esolutions,
70
+ :mirjeh,
71
+ :mollie,
72
+ :moneris_solutions,
73
+ :nmi,
74
+ :oceanpayment,
75
+ :oney,
76
+ :openpaymx,
77
+ :optimal_payments,
78
+ :orangepay,
79
+ :other,
80
+ :pacnet_services,
81
+ :payeezy,
82
+ :payfast,
83
+ :paygate,
84
+ :paylike,
85
+ :payment_express,
86
+ :paymentwall,
87
+ :payone,
88
+ :paypal,
89
+ :payplus,
90
+ :paysafecard,
91
+ :paystation,
92
+ :paytrace,
93
+ :paytrail,
94
+ :payture,
95
+ :payu,
96
+ :payulatam,
97
+ :payway,
98
+ :payza,
99
+ :pinpayments,
100
+ :posconnect,
101
+ :princeton_payment_solutions,
102
+ :psigate,
103
+ :qiwi,
104
+ :quickpay,
105
+ :raberil,
106
+ :rede,
107
+ :redpagos,
108
+ :rewardspay,
109
+ :sagepay,
110
+ :securetrading,
111
+ :simplify_commerce,
112
+ :skrill,
113
+ :smartcoin,
114
+ :smartdebit,
115
+ :solidtrust_pay,
116
+ :sps_decidir,
117
+ :stripe,
118
+ :synapsefi,
119
+ :telerecargas,
120
+ :towah,
121
+ :transact_pro,
122
+ :usa_epay,
123
+ :vantiv,
124
+ :verepay,
125
+ :vericheck,
126
+ :vindicia,
127
+ :virtual_card_services,
128
+ :vme,
129
+ :vpos,
130
+ :wirecard,
131
+ :worldpay
20
132
  ]
21
133
 
22
134
  # @attribute was_authorized
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minfraud
4
+ module Components
5
+ module Report
6
+ # Contains all of the fields which are used in the report transaction API
7
+ class Transaction < Base
8
+ include ::Minfraud::Enum
9
+
10
+ # @!attribute ip_address
11
+ # @return [String, nil] The IP address of the customer placing the order. This
12
+ # should be passed as a string like "44.55.66.77" or "2001:db8::2:1".
13
+ attr_accessor :ip_address
14
+
15
+ # @!attribute tag
16
+ # This may be one of +:chargeback+, +:not_fraud+, +:spam_or_abuse+ or +:suspected_fraud+
17
+ # @return [Symbol, nil] A symbol indicating the likelihood that a transaction
18
+ # may be fraudulent.
19
+ enum_accessor :tag, [:chargeback, :not_fraud, :spam_or_abuse, :suspected_fraud]
20
+
21
+ # @attribute chargeback_code
22
+ # @return [String, nil] A string which is provided by your payment processor
23
+ # indicating the reason for the chargeback.
24
+ attr_accessor :chargeback_code
25
+
26
+ # @attribute maxmind_id
27
+ # @return [String, nil] A unique eight character string identifying a minFraud
28
+ # Standard or Premium request. These IDs are returned in the maxmindID
29
+ # field of a response for a successful minFraud request. This field is
30
+ # not required, but you are encouraged to provide it, if possible.
31
+ attr_accessor :maxmind_id
32
+
33
+ # @attribute minfraud_id
34
+ # @return [String, nil] A UUID that identifies a minFraud Score, minFraud
35
+ # Insights, or minFraud Factors request. This ID is returned at /id in
36
+ # the response. This field is not required, but you are encouraged to
37
+ # provide it if the request was made to one of these services.
38
+ attr_accessor :minfraud_id
39
+
40
+ # @attribute notes
41
+ # @return [String, nil] Your notes on the fraud tag associated with the
42
+ # transaction. We manually review many reported transactions to improve
43
+ # our scoring for you so any additional details to help us understand
44
+ # context are helpful.
45
+ attr_accessor :notes
46
+
47
+ # @attribute transaction_id
48
+ # @return [String, nil] The transaction ID you originally passed to minFraud.
49
+ # This field is not required, but you are encouraged to provide it or
50
+ # the transaction's maxmind_id or minfraud_id
51
+ attr_accessor :transaction_id
52
+
53
+ # Creates Minfraud::Components::Report::Transaction instance
54
+ # @param [Hash] params hash of parameters
55
+ # @return [Minfraud::Components::Report::Transaction] a Report::Transaction
56
+ # instance
57
+ def initialize(params = {})
58
+ @ip_address = params[:ip_address]
59
+ @chargeback_code = params[:chargeback_code]
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
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,45 +1,65 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module ErrorHandler
3
5
  class << self
4
- # Returns a response if status code is 200, rises an error otherwise
6
+ # Returns a response if status code is 2xx, raises an error otherwise
5
7
  # @param [Minfraud::HTTPService::Response] response
6
8
  # @return [Minfraud::HTTPService::Response] if status code is 200
7
- def inspect(response)
8
- return response if response.status == 200
9
+ def examine(response)
10
+ return response if response.status > 199 && response.status < 300
9
11
 
10
12
  raise *STATUS_CODES.fetch(response.code, [ServerError, 'Server error'])
11
13
  end
12
14
 
13
15
  # A hash that maps status codes returned by minFraud with errors & messages
14
16
  STATUS_CODES = {
15
- IP_ADDRESS_INVALID: [
16
- ClientError, 'You have no supplied a valid IPv4 or IPv6 address'
17
+ IP_ADDRESS_INVALID: [
18
+ ClientError, 'You have not supplied a valid IPv4 or IPv6 address'
17
19
  ],
18
- IP_ADDRESS_REQUIRED: [
19
- ClientError, 'You have not supplied an IP address which is required filed'
20
+ IP_ADDRESS_REQUIRED: [
21
+ ClientError, 'You have not supplied an IP address which is a required field'
20
22
  ],
21
- IP_ADDRESS_RESERVED: [
23
+ IP_ADDRESS_RESERVED: [
22
24
  ClientError, 'You have supplied an IP address which is reserved'
23
25
  ],
24
- JSON_INVALID: [
26
+ JSON_INVALID: [
25
27
  ClientError, 'JSON body cannot be decoded'
26
28
  ],
29
+ MAXMIND_ID_INVALID: [
30
+ ClientError, 'You have not supplied a valid maxmind_id'
31
+ ],
32
+ MINFRAUD_ID_INVALID: [
33
+ ClientError, 'You have not supplied a valid minfraud_id'
34
+ ],
35
+ PARAMETER_UNKNOWN: [
36
+ ClientError, 'You have supplied an unknown parameter'
37
+ ],
38
+ TAG_REQUIRED: [
39
+ ClientError, 'You have not supplied a tag, which is a required field'
40
+ ],
41
+ TAG_INVALID: [
42
+ ClientError, 'You have not supplied a valid tag'
43
+ ],
44
+ ACCOUNT_ID_REQUIRED: [
45
+ AuthorizationError, 'You have not supplied a account ID'
46
+ ],
27
47
  AUTHORIZATION_INVALID: [
28
- AuthorizationError, 'Invalid license key and / or user id'
48
+ AuthorizationError, 'Invalid license key and / or account ID'
29
49
  ],
30
- LICENSE_KEY_REQUIRED: [
50
+ LICENSE_KEY_REQUIRED: [
31
51
  AuthorizationError, 'You have not supplied a license key'
32
52
  ],
33
- USER_ID_REQUIRED: [
34
- AuthorizationError, 'You have not supplied a user id'
53
+ USER_ID_REQUIRED: [
54
+ AuthorizationError, 'You have not supplied a account id'
35
55
  ],
36
- INSUFFICIENT_FUNDS: [
56
+ INSUFFICIENT_FUNDS: [
37
57
  ClientError, 'The license key you have provided does not have a sufficient funds to use this service'
38
58
  ],
39
- PERMISSION_REQUIRED: [
59
+ PERMISSION_REQUIRED: [
40
60
  ClientError, 'You do not have permission to use this service'
41
61
  ]
42
- }
62
+ }.freeze
43
63
  end
44
64
  end
45
65
  end