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
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minfraud/model/abstract'
4
+ require 'minfraud/model/disposition'
5
+ require 'minfraud/model/score_ip_address'
6
+ require 'minfraud/model/warning'
7
+
8
+ module Minfraud
9
+ module Model
10
+ # Model of the Score response.
11
+ class Score < Abstract
12
+ # An object containing the disposition set by custom rules.
13
+ #
14
+ # @return [Minfraud::Model::Disposition]
15
+ attr_reader :disposition
16
+
17
+ # The approximate US dollar value of the funds remaining on your MaxMind
18
+ # account.
19
+ #
20
+ # @return [Float]
21
+ attr_reader :funds_remaining
22
+
23
+ # This is a UUID that identifies the minFraud request. Please use this ID
24
+ # in bug reports or support requests to MaxMind so that we can easily
25
+ # identify a particular request.
26
+ #
27
+ # @return [String]
28
+ attr_reader :id
29
+
30
+ # An object containing the IP risk for the transaction.
31
+ #
32
+ # @return [Minfraud::Model::ScoreIPAddress]
33
+ attr_reader :ip_address
34
+
35
+ # The approximate number of queries remaining for this service before
36
+ # your account runs out of funds.
37
+ #
38
+ # @return [Integer]
39
+ attr_reader :queries_remaining
40
+
41
+ # This property contains the risk score, from 0.01 to 99. A higher score
42
+ # indicates a higher risk of fraud. For example, a score of 20 indicates
43
+ # a 20% chance that a transaction is fraudulent. We never return a risk
44
+ # score of 0, since all transactions have the possibility of being
45
+ # fraudulent. Likewise we never return a risk score of 100.
46
+ #
47
+ # @return [Float]
48
+ attr_reader :risk_score
49
+
50
+ # This array contains objects detailing issues with the request that was
51
+ # sent, such as invalid or unknown inputs. It is highly recommended that
52
+ # you check this array for issues when integrating the web service.
53
+ #
54
+ # @return [Array<Minfraud::Model::Warning>]
55
+ attr_reader :warnings
56
+
57
+ # @!visibility private
58
+ def initialize(record, _locales)
59
+ super(record)
60
+
61
+ @disposition = Minfraud::Model::Disposition.new(get('disposition'))
62
+ @funds_remaining = get('funds_remaining')
63
+ @id = get('id')
64
+ @ip_address = Minfraud::Model::ScoreIPAddress.new(get('ip_address'))
65
+ @queries_remaining = get('queries_remaining')
66
+ @risk_score = get('risk_score')
67
+ @warnings = []
68
+ if record && record.key?('warnings')
69
+ record['warnings'].each do |w|
70
+ @warnings << Minfraud::Model::Warning.new(w)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minfraud/model/abstract'
4
+
5
+ module Minfraud
6
+ module Model
7
+ # Model containing the IP address's risk for the Score response.
8
+ class ScoreIPAddress < Abstract
9
+ # This field contains the risk associated with the IP address. The value
10
+ # ranges from 0.01 to 99. A higher score indicates a higher risk.
11
+ #
12
+ # @return [Float]
13
+ attr_reader :risk
14
+
15
+ # @!visibility private
16
+ def initialize(record)
17
+ super(record)
18
+
19
+ @risk = get('risk')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minfraud/model/address'
4
+
5
+ module Minfraud
6
+ module Model
7
+ # Model containing information about the shipping address.
8
+ class ShippingAddress < Address
9
+ # The distance in kilometers from the shipping address to billing
10
+ # address.
11
+ #
12
+ # @return [Integer, nil]
13
+ attr_reader :distance_to_billing_address
14
+
15
+ # This field is true if the shipping address is an address associated
16
+ # with fraudulent transactions. The field is false when the address is
17
+ # not associated with increased risk. The key will only be present when a
18
+ # shipping address is provided.
19
+ attr_reader :is_high_risk
20
+
21
+ # @!visibility private
22
+ def initialize(record)
23
+ super(record)
24
+
25
+ @distance_to_billing_address = get('distance_to_billing_address')
26
+ @is_high_risk = get('is_high_risk')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minfraud/model/abstract'
4
+
5
+ module Minfraud
6
+ module Model
7
+ # Subscores for components that are used in calculating the riskScore.
8
+ class Subscores < Abstract
9
+ # The risk associated with the AVS result. If present, this is a value in
10
+ # the range 0.01 to 99.
11
+ #
12
+ # @return [Float, nil]
13
+ attr_reader :avs_result
14
+
15
+ # The risk associated with the billing address. If present, this is a
16
+ # value in the range 0.01 to 99.
17
+ #
18
+ # @return [Float, nil]
19
+ attr_reader :billing_address
20
+
21
+ # The risk associated with the distance between the billing address and
22
+ # the location for the given IP address. If present, this is a value in
23
+ # the range 0.01 to 99.
24
+ #
25
+ # @return [Float, nil]
26
+ attr_reader :billing_address_distance_to_ip_location
27
+
28
+ # The risk associated with the browser attributes such as the User-Agent
29
+ # and Accept-Language. If present, this is a value in the range 0.01 to
30
+ # 99.
31
+ #
32
+ # @return [Float, nil]
33
+ attr_reader :browser
34
+
35
+ # Individualized risk of chargeback for the given IP address given for
36
+ # your account and any shop ID passed. This is only available to users
37
+ # sending chargeback data to MaxMind. If present, this is a value in the
38
+ # range 0.01 to 99.
39
+ #
40
+ # @return [Float, nil]
41
+ attr_reader :chargeback
42
+
43
+ # The risk associated with the country the transaction originated from.
44
+ # If present, this is a value in the range 0.01 to 99.
45
+ #
46
+ # @return [Float, nil]
47
+ attr_reader :country
48
+
49
+ # The risk associated with the combination of IP country, card issuer
50
+ # country, billing country, and shipping country. If present, this is a
51
+ # value in the range 0.01 to 99.
52
+ #
53
+ # @return [Float, nil]
54
+ attr_reader :country_mismatch
55
+
56
+ # The risk associated with the CVV result. If present, this is a value in
57
+ # the range 0.01 to 99.
58
+ #
59
+ # @return [Float, nil]
60
+ attr_reader :cvv_result
61
+
62
+ # The risk associated with the particular email address. If present, this
63
+ # is a value in the range 0.01 to 99.
64
+ #
65
+ # @return [Float, nil]
66
+ attr_reader :email_address
67
+
68
+ # The general risk associated with the email domain. If present, this is
69
+ # a value in the range 0.01 to 99.
70
+ #
71
+ # @return [Float, nil]
72
+ attr_reader :email_domain
73
+
74
+ # The risk associated with the issuer ID number on the email domain. If
75
+ # present, this is a value in the range 0.01 to 99.
76
+ #
77
+ # Deprecated effective August 29, 2019. This subscore will default to 1
78
+ # and will be removed in a future release. The user tenure on email is
79
+ # reflected in the /subscores/email_address output.
80
+ #
81
+ # @return [Float, nil]
82
+ attr_reader :email_tenure
83
+
84
+ # The risk associated with the issuer ID number on the IP address. If
85
+ # present, this is a value in the range 0.01 to 99.
86
+ #
87
+ # Deprecated effective August 29, 2019. This subscore will default to 1
88
+ # and will be removed in a future release. The IP tenure is reflected in
89
+ # the overall risk score.
90
+ #
91
+ # @return [Float, nil]
92
+ attr_reader :ip_tenure
93
+
94
+ # The risk associated with the particular issuer ID number (IIN) given
95
+ # the billing location and the history of usage of the IIN on your
96
+ # account and shop ID. If present, this is a value in the range 0.01 to
97
+ # 99.
98
+ #
99
+ # @return [Float, nil]
100
+ attr_reader :issuer_id_number
101
+
102
+ # The risk associated with the particular order amount for your account
103
+ # and shop ID. If present, this is a value in the range 0.01 to 99.
104
+ #
105
+ # @return [Float, nil]
106
+ attr_reader :order_amount
107
+
108
+ # The risk associated with the particular phone number. If present, this
109
+ # is a value in the range 0.01 to 99.
110
+ #
111
+ # @return [Float, nil]
112
+ attr_reader :phone_number
113
+
114
+ # The risk associated with the distance between the shipping address and
115
+ # the IP location for the given IP address. If present, this is a value
116
+ # in the range 0.01 to 99.
117
+ #
118
+ # @return [Float, nil]
119
+ attr_reader :shipping_address_distance_to_ip_location
120
+
121
+ # The risk associated with the local time of day of the transaction in
122
+ # the IP address location. If present, this is a value in the range 0.01
123
+ # to 99.
124
+ #
125
+ # @return [Float, nil]
126
+ attr_reader :time_of_day
127
+
128
+ # @!visibility private
129
+ def initialize(record)
130
+ super(record)
131
+
132
+ @avs_result = get('avs_result')
133
+ @billing_address = get('billing_address')
134
+ @billing_address_distance_to_ip_location = get(
135
+ 'billing_address_distance_to_ip_location'
136
+ )
137
+ @browser = get('browser')
138
+ @chargeback = get('chargeback')
139
+ @country = get('country')
140
+ @country_mismatch = get('country_mismatch')
141
+ @cvv_result = get('cvv_result')
142
+ @email_address = get('email_address')
143
+ @email_domain = get('email_domain')
144
+ @email_tenure = get('email_tenure')
145
+ @ip_tenure = get('ip_tenure')
146
+ @issuer_id_number = get('issuer_id_number')
147
+ @order_amount = get('order_amount')
148
+ @phone_number = get('phone_number')
149
+ @shipping_address_distance_to_ip_location = get(
150
+ 'shipping_address_distance_to_ip_location'
151
+ )
152
+ @time_of_day = get('time_of_day')
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minfraud/model/abstract'
4
+
5
+ module Minfraud
6
+ module Model
7
+ # Warning about the minFraud request.
8
+ #
9
+ # Although more codes may be added in the future, the current warning codes
10
+ # are:
11
+ #
12
+ # * BILLING_CITY_NOT_FOUND - the billing city could not be found in our
13
+ # database.
14
+ # * BILLING_COUNTRY_MISSING - billing address information was provided
15
+ # without providing a billing country.
16
+ # * BILLING_COUNTRY_NOT_FOUND - the billing country could not be found in
17
+ # our database.
18
+ # * BILLING_POSTAL_NOT_FOUND - the billing postal could not be found in our
19
+ # database.
20
+ # * INPUT_INVALID - the value associated with the key does not meet the
21
+ # required constraints, e.g., "United States" in a field that requires a
22
+ # two-letter country code.
23
+ # * INPUT_UNKNOWN - an unknown key was encountered in the request body.
24
+ # * IP_ADDRESS_NOT_FOUND - the IP address could not be geolocated.
25
+ # * SHIPPING_COUNTRY_MISSING - shipping address information was provided
26
+ # without providing a shipping country.
27
+ # * SHIPPING_CITY_NOT_FOUND - the shipping city could not be found in our
28
+ # database.
29
+ # * SHIPPING_COUNTRY_NOT_FOUND - the shipping country could not be found in
30
+ # our database.
31
+ # * SHIPPING_POSTAL_NOT_FOUND - the shipping postal could not be found in
32
+ # our database.
33
+ class Warning < Abstract
34
+ # This value is a machine-readable code identifying the warning.
35
+ #
36
+ # @return [String]
37
+ attr_reader :code
38
+
39
+ # This property provides a human-readable explanation of the warning. The
40
+ # description may change at any time and should not be matched against.
41
+ #
42
+ # @return [String]
43
+ attr_reader :warning
44
+
45
+ # A JSON Pointer to the input field that the warning is associated with.
46
+ # For instance, if the warning was about the billing city, this would be
47
+ # '/billing/city'. If it was for the price in the second shopping cart
48
+ # item, it would be '/shopping_cart/1/price'.
49
+ #
50
+ # @return [String, nil]
51
+ attr_reader :input_pointer
52
+
53
+ # @!visibility private
54
+ def initialize(record)
55
+ super(record)
56
+
57
+ @code = get('code')
58
+ @warning = get('warning')
59
+ @input_pointer = get('input_pointer')
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,38 @@
1
+ module Minfraud
2
+ class Report
3
+ include ::Minfraud::HTTPService
4
+
5
+ # @!attribute transaction
6
+ # @return [Minfraud::Components::Report::Transaction] Report::Transaction component
7
+ attr_accessor :transaction
8
+
9
+ # @param [Hash] params hash of parameters
10
+ # @return [Minfraud::ReportTransaction] ReportTransaction instance
11
+ def initialize(params = {})
12
+ @transaction = params[:transaction]
13
+ end
14
+
15
+ # @method report_transaction
16
+ # Makes a request to the minFraud report transactions API.
17
+ # Raises an error in case of invalid response.
18
+ # @return [nil]
19
+ def report_transaction
20
+ raw = request.perform(verb: :post, endpoint: 'transactions/report', body: @transaction.to_json)
21
+
22
+ response = ::Minfraud::HTTPService::Response.new(
23
+ status: raw.status.to_i,
24
+ body: raw.body,
25
+ headers: raw.headers
26
+ )
27
+ ::Minfraud::ErrorHandler.examine(response)
28
+
29
+ return nil
30
+ end
31
+
32
+ # Creates memoized Minfraud::HTTPService::Request instance
33
+ # @return [Minfraud::HTTPService::Request] Request instance based on configuration params
34
+ def request
35
+ @request ||= Request.new(::Minfraud::HTTPService.configuration)
36
+ end
37
+ end
38
+ end
@@ -4,8 +4,8 @@ module Minfraud
4
4
  # @param [Object] context an object for variable assignment
5
5
  # @param [Hash] params a hash of parameters
6
6
  # @return [Array] a list of supplied params
7
- # Note: Raises RequestFormatError once unpermitted key is met
8
- def assign(context:, params:)
7
+ # @note Raises RequestFormatError once unpermitted key is met
8
+ def assign(context, params)
9
9
  Array(params).each do |key, value|
10
10
  raise RequestFormatError, "#{key} does not belong to request document format" unless MAPPING[key]
11
11
 
@@ -20,13 +20,14 @@ module Minfraud
20
20
  account: ::Minfraud::Components::Account,
21
21
  billing: ::Minfraud::Components::Billing,
22
22
  credit_card: ::Minfraud::Components::CreditCard,
23
+ custom_inputs: ::Minfraud::Components::CustomInputs,
23
24
  device: ::Minfraud::Components::Device,
24
25
  email: ::Minfraud::Components::Email,
25
26
  event: ::Minfraud::Components::Event,
26
27
  order: ::Minfraud::Components::Order,
27
28
  payment: ::Minfraud::Components::Payment,
28
29
  shipping: ::Minfraud::Components::Shipping,
29
- shopping_cart: ::Minfraud::Components::ShoppingCart
30
+ shopping_cart: ::Minfraud::Components::ShoppingCart,
30
31
  }
31
32
  end
32
33
  end
@@ -1,3 +1,3 @@
1
1
  module Minfraud
2
- VERSION = "1.0.0"
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,26 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', File.dirname(File.realpath(__FILE__)))
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
4
  require 'minfraud/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "minfraud"
7
+ spec.name = 'minfraud'
8
8
  spec.version = Minfraud::VERSION
9
- spec.authors = ["kushnir.yb"]
10
- spec.email = ["kushnir.yb@gmail.com"]
9
+ spec.authors = ['kushnir.yb']
10
+ spec.email = ['support@maxmind.com']
11
+
12
+ spec.summary = %q(Ruby interface to the MaxMind minFraud v2.0 API services)
13
+ spec.homepage = 'https://github.com/maxmind/minfraud-api-ruby'
14
+ spec.license = 'MIT'
11
15
 
12
- spec.summary = %q{Ruby interface to the MaxMind minFraud v2.0 API services}
13
- spec.homepage = "https://github.com/kushniryb/minfraud-api-v2"
14
- spec.license = "MIT"
16
+ spec.required_ruby_version = '>= 1.9'
15
17
 
16
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
19
+ spec.bindir = 'exe'
18
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'faraday', '>= 0.9.1', '< 2.0'
24
+ spec.add_runtime_dependency 'faraday_middleware', '>= 0.9.1', '< 2.0'
20
25
 
21
- spec.add_runtime_dependency 'faraday'
22
- spec.add_runtime_dependency 'faraday_middleware'
23
- spec.add_development_dependency "bundler", "~> 1.12"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency 'bundler', '>= 1.16'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
29
  end