minfraud 1.0.0 → 1.1.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 (66) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.travis.yml +20 -3
  4. data/CHANGELOG.md +42 -0
  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 +109 -39
  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 +6 -4
  25. data/lib/minfraud/assessments.rb +32 -13
  26. data/lib/minfraud/components/account.rb +2 -2
  27. data/lib/minfraud/components/addressable.rb +2 -2
  28. data/lib/minfraud/components/base.rb +26 -4
  29. data/lib/minfraud/components/credit_card.rb +6 -1
  30. data/lib/minfraud/components/custom_inputs.rb +14 -0
  31. data/lib/minfraud/components/device.rb +11 -0
  32. data/lib/minfraud/components/event.rb +14 -9
  33. data/lib/minfraud/components/order.rb +1 -0
  34. data/lib/minfraud/components/payment.rb +125 -13
  35. data/lib/minfraud/components/report/transaction.rb +69 -0
  36. data/lib/minfraud/components/shipping.rb +1 -5
  37. data/lib/minfraud/components/shopping_cart.rb +2 -1
  38. data/lib/minfraud/enum.rb +8 -4
  39. data/lib/minfraud/error_handler.rb +37 -17
  40. data/lib/minfraud/http_service.rb +1 -2
  41. data/lib/minfraud/http_service/request.rb +1 -1
  42. data/lib/minfraud/http_service/response.rb +38 -10
  43. data/lib/minfraud/model/abstract.rb +20 -0
  44. data/lib/minfraud/model/address.rb +52 -0
  45. data/lib/minfraud/model/billing_address.rb +11 -0
  46. data/lib/minfraud/model/credit_card.rb +75 -0
  47. data/lib/minfraud/model/device.rb +54 -0
  48. data/lib/minfraud/model/disposition.rb +35 -0
  49. data/lib/minfraud/model/email.rb +54 -0
  50. data/lib/minfraud/model/email_domain.rb +24 -0
  51. data/lib/minfraud/model/error.rb +28 -0
  52. data/lib/minfraud/model/factors.rb +24 -0
  53. data/lib/minfraud/model/geoip2_location.rb +25 -0
  54. data/lib/minfraud/model/insights.rb +68 -0
  55. data/lib/minfraud/model/ip_address.rb +82 -0
  56. data/lib/minfraud/model/issuer.rb +49 -0
  57. data/lib/minfraud/model/score.rb +76 -0
  58. data/lib/minfraud/model/score_ip_address.rb +23 -0
  59. data/lib/minfraud/model/shipping_address.rb +30 -0
  60. data/lib/minfraud/model/subscores.rb +156 -0
  61. data/lib/minfraud/model/warning.rb +63 -0
  62. data/lib/minfraud/report.rb +38 -0
  63. data/lib/minfraud/resolver.rb +4 -3
  64. data/lib/minfraud/version.rb +1 -1
  65. data/minfraud.gemspec +18 -15
  66. metadata +68 -19
@@ -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
@@ -38,7 +40,7 @@ module Minfraud
38
40
  yield self
39
41
  end
40
42
 
41
- # @return [Hash] with the current configuration
43
+ # @return [Hash] current Minfraud configuration
42
44
  def configuration
43
45
  {
44
46
  user_id: @user_id,
@@ -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,37 +44,52 @@ 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
47
51
  # @param [Minfraud::Resolver] resolver resolver that maps params to components
52
+ # @note In case when params is a Hash of components it just assigns them to the corresponding instance variables
48
53
  # @return [Minfraud::Assessments] Assessments instance
49
54
  def initialize(params = {}, resolver = ::Minfraud::Resolver)
50
- resolver.assign(context: self, params: params)
55
+ @locales = params.delete('locales')
56
+ @locales = ['en'] if @locales.nil?
57
+
58
+ resolver.assign(self, params)
51
59
  end
52
60
 
53
- # These methods correspond to the minFraud API endpoints and require the same set of params
54
- # Raises an error in case of invalid response
55
- # @return [Minfraud::HTTPService::Response] Wrapped minFraud response
56
- %w(score insights factors).each do |endpoint|
57
- define_method endpoint do
58
- raw = request.perform(verb: :post, endpoint: endpoint, body: request_body)
61
+ # @!macro [attach] define
62
+ # @method $1
63
+ # Makes a request to minFraud $1 endpoint.
64
+ # Raises an error in case of invalid response
65
+ # @return [Minfraud::HTTPService::Response] Wrapped minFraud response
66
+ def self.define(endpoint)
67
+ define_method(endpoint) do
68
+ raw = request.perform(verb: :post, endpoint: endpoint.to_s, body: request_body)
59
69
  response = ::Minfraud::HTTPService::Response.new(
60
- status: raw.status.to_i,
61
- body: raw.body,
62
- headers: raw.headers
70
+ endpoint: endpoint,
71
+ locales: @locales,
72
+ status: raw.status.to_i,
73
+ body: raw.body,
74
+ headers: raw.headers
63
75
  )
64
76
 
65
- ::Minfraud::ErrorHandler.inspect(response)
77
+ ::Minfraud::ErrorHandler.examine(response)
66
78
  end
67
79
  end
68
80
 
81
+ define :score
82
+ define :insights
83
+ define :factors
84
+
69
85
  private
70
86
  # Creates a unified request body from components converted to JSON
71
87
  # @return [Hash] Request body
72
88
  def request_body
73
- MAPPING.keys.inject({}) { |mem, e| mem.merge!(e.to_s => send(e)&.to_json) }
89
+ MAPPING.keys.inject({}) do |mem, e|
90
+ next mem unless value = send(e)
91
+ mem.merge!(e.to_s => value.to_json)
92
+ end
74
93
  end
75
94
 
76
95
  # Creates memoized Minfraud::HTTPService::Request instance
@@ -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
@@ -13,7 +13,7 @@ module Minfraud
13
13
 
14
14
  # Creates Minfraud::Components::Account instance
15
15
  # @param [Hash] params hash of parameters
16
- # @return [Minfraud::Components::Account] a Account instance
16
+ # @return [Minfraud::Components::Account] an Account instance
17
17
  def initialize(params = {})
18
18
  @user_id = params[:user_id]
19
19
  @username_md5 = params[: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
@@ -46,7 +46,7 @@ module Minfraud
46
46
  attr_accessor :phone_country_code
47
47
 
48
48
  # Creates Minfraud::Components::Addressable instance
49
- # This class is used as a parent class for Billing and Shipping components
49
+ # @note This class is used as a parent class for Billing and Shipping components
50
50
  # @param [Hash] params hash of parameters
51
51
  # @return [Minfraud::Components::Addressable] an Addressable instance
52
52
  def initialize(params = {})
@@ -1,13 +1,35 @@
1
1
  module Minfraud
2
2
  module Components
3
- # Note: This class is used as a parent class for all other components
4
- # It defines a method which is used for basic JSON representation of PORO objects
3
+ # @note This class is used as a parent class for all other components
4
+ # @note It defines a method which is used for basic JSON representation of PORO objects
5
5
  class Base
6
6
  # @return [Hash] a JSON representation of component attributes
7
7
  def to_json
8
- instance_variables.inject({}) { |mem, e| mem.merge!(e.to_s.gsub(/@/, '') => instance_variable_get(e).to_s) }
9
- .delete_if { |_, v| v.empty? }
8
+ instance_variables.inject({}) { |mem, e| populate!(mem, e) }
10
9
  end
10
+
11
+ private
12
+
13
+ # @note This method may modify passed hash. Non-existing instance variables are ignored
14
+ # @param [Hash] hash an accumulator
15
+ # @param [Symbol] v_sym an instance variable symbol
16
+ # @return [Hash] a hash containing a JSON representation of instance variable name and it's value
17
+ def populate!(hash, v_sym)
18
+ return hash unless value = instance_variable_get(v_sym)
19
+
20
+ key = v_sym.to_s.gsub(/@/, '')
21
+ hash.merge!(key => represent(key, value))
22
+ end
23
+
24
+ # param [Symbol] key instance variable symbol
25
+ # param [Object] value instance variable value
26
+ # @return [Object] value representation according to the request format
27
+ def represent(key, value)
28
+ BOOLS.include?(key) ? value : value.to_s
29
+ end
30
+
31
+ # Keys that have to remain boolean
32
+ BOOLS = %w(was_authorized is_gift has_gift_message)
11
33
  end
12
34
  end
13
35
  end
@@ -18,10 +18,14 @@ module Minfraud
18
18
  # @return [String] The phone country code for the issuing bank as provided by the end user
19
19
  attr_accessor :bank_phone_country_code
20
20
 
21
- # @attribute phone_phone_number
21
+ # @attribute bank_phone_number
22
22
  # @return [String] The phone number, without the country code, for the issuing bank as provided by the end user
23
23
  attr_accessor :bank_phone_number
24
24
 
25
+ #@attribute token
26
+ #@return [String] A token uniquely identifying the card. The token should consist of non-space printable ASCII characters.
27
+ attr_accessor :token
28
+
25
29
  # @attribute avs_result
26
30
  # @return [String] The address verification system (AVS) check result, as returned to you by the credit card processor
27
31
  attr_accessor :avs_result
@@ -41,6 +45,7 @@ module Minfraud
41
45
  @bank_phone_number = params[:bank_phone_number]
42
46
  @avs_result = params[:avs_result]
43
47
  @cvv_result = params[:cvv_result]
48
+ @token = params[:token]
44
49
  end
45
50
  end
46
51
  end
@@ -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
@@ -16,14 +16,19 @@ module Minfraud
16
16
  attr_accessor :time
17
17
 
18
18
  # @attribute type
19
- # @return [String] The type of event being scored. The valid types are:
20
- # => account_creation
21
- # => account_login
22
- # => purchase
23
- # => recurring_purchase
24
- # => referral
25
- # => survey
26
- enum_accessor :type, [:account_creation, :account_login, :purchase, :recurring_purchase, :referral, :survey]
19
+ # @return [String] The type of event being scored
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
+ ]
27
32
 
28
33
  # Creates Minfraud::Components::Event instance
29
34
  # @param [Hash] params hash of parameters
@@ -32,7 +37,7 @@ module Minfraud
32
37
  @transaction_id = params[:transaction_id]
33
38
  @shop_id = params[:shop_id]
34
39
  @time = params[:time]
35
- @type = params[:type]
40
+ self.type = params[:type]
36
41
  end
37
42
  end
38
43
  end
@@ -38,6 +38,7 @@ module Minfraud
38
38
  # @param [Hash] params hash of parameters
39
39
  # @return [Minfraud::Components::Order] an Order instance
40
40
  def initialize (params = {})
41
+ @amount = params[:amount]
41
42
  @has_gift_message = params[:has_gift_message]
42
43
  @affiliate_id = params[:affiliate_id]
43
44
  @subaffiliate_id = params[:subaffiliate_id]
@@ -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
@@ -33,7 +145,7 @@ module Minfraud
33
145
  def initialize(params = {})
34
146
  @was_authorized = params[:was_authorized]
35
147
  @decline_code = params[:decline_code]
36
- @processor = params[:processor]
148
+ self.processor = params[:processor]
37
149
  end
38
150
  end
39
151
  end