minfraud 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +46 -0
  3. data/.rubocop.yml +127 -0
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +4 -2
  6. data/README.md +1 -1
  7. data/Rakefile +18 -3
  8. data/bin/console +4 -3
  9. data/lib/maxmind/geoip2/model/city.rb +3 -3
  10. data/lib/maxmind/geoip2/model/country.rb +5 -5
  11. data/lib/maxmind/geoip2/record/traits.rb +1 -1
  12. data/lib/minfraud.rb +29 -6
  13. data/lib/minfraud/assessments.rb +6 -2
  14. data/lib/minfraud/components/account.rb +2 -0
  15. data/lib/minfraud/components/addressable.rb +9 -7
  16. data/lib/minfraud/components/base.rb +6 -4
  17. data/lib/minfraud/components/billing.rb +2 -0
  18. data/lib/minfraud/components/credit_card.rb +4 -2
  19. data/lib/minfraud/components/custom_inputs.rb +2 -0
  20. data/lib/minfraud/components/device.rb +4 -2
  21. data/lib/minfraud/components/email.rb +2 -0
  22. data/lib/minfraud/components/event.rb +13 -11
  23. data/lib/minfraud/components/order.rb +3 -1
  24. data/lib/minfraud/components/payment.rb +14 -2
  25. data/lib/minfraud/components/report/transaction.rb +6 -6
  26. data/lib/minfraud/components/shipping.rb +2 -0
  27. data/lib/minfraud/components/shopping_cart.rb +4 -1
  28. data/lib/minfraud/components/shopping_cart_item.rb +2 -2
  29. data/lib/minfraud/enum.rb +6 -3
  30. data/lib/minfraud/error_handler.rb +15 -15
  31. data/lib/minfraud/errors.rb +2 -0
  32. data/lib/minfraud/http_service.rb +14 -4
  33. data/lib/minfraud/http_service/request.rb +3 -0
  34. data/lib/minfraud/http_service/response.rb +4 -2
  35. data/lib/minfraud/model/address.rb +4 -4
  36. data/lib/minfraud/model/credit_card.rb +7 -7
  37. data/lib/minfraud/model/device.rb +2 -2
  38. data/lib/minfraud/model/email.rb +4 -4
  39. data/lib/minfraud/model/error.rb +1 -1
  40. data/lib/minfraud/model/insights.rb +5 -5
  41. data/lib/minfraud/model/issuer.rb +3 -3
  42. data/lib/minfraud/model/score.rb +6 -6
  43. data/lib/minfraud/model/shipping_address.rb +1 -1
  44. data/lib/minfraud/model/subscores.rb +35 -16
  45. data/lib/minfraud/model/warning.rb +2 -2
  46. data/lib/minfraud/report.rb +5 -3
  47. data/lib/minfraud/resolver.rb +14 -12
  48. data/lib/minfraud/version.rb +3 -1
  49. data/minfraud.gemspec +4 -1
  50. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 992486331731cfd910c7ae3da4039bfa3b776277ff3eb3fb44ae62816299d2cb
4
- data.tar.gz: db10a19261bdca8cb64df6f0992a2d102859c670fc47568cdc01e299c17318a6
3
+ metadata.gz: 5523cb6babed5c559ba622141b2db65a2396cbb016c6215ec641ba765fc01d10
4
+ data.tar.gz: 54dbf8b2cc34be45a428da2017f09b7cb2d7445c94ff7f37dda0a26c28a3fbfe
5
5
  SHA512:
6
- metadata.gz: bd6e8c22d6557f26233b1f5c306ab3d358adb9f661f1452d02471ce0b705cd0037ecafc235af86646894bc4ab953c595989011148aa4f658132f6ec7c7218a4f
7
- data.tar.gz: f8e53c39ef6a07271297e8555808682b9cb662efe43057ea6da9ea9400418b7a59bd168051888e8c69ebda1d9ed6947729e48de5b3a61df25b26536f13589bef
6
+ metadata.gz: 80142ac976fb6df365a3192a96dbf62c8ea7935f4ca9fea89333d0e2f2e64f5e4af402dc03814f58f268e354ed7adcb5c61134fb2d526c0a06b48581cad3fc54
7
+ data.tar.gz: a9b6caf26aaee87f5ebc479391cda46d3489cf591315772c481d722b343399edfc5ad40fca8eac0d740d826c0021bcf33d3aade2419247d26d1787328763599b
@@ -0,0 +1,46 @@
1
+ name: ruby-versions
2
+ on:
3
+ push:
4
+ paths-ignore:
5
+ - "**.md"
6
+ pull_request:
7
+ paths-ignore:
8
+ - "**.md"
9
+ jobs:
10
+ run:
11
+ name: ruby
12
+ runs-on: ${{ matrix.os }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ os: [ubuntu-latest, windows-latest, macos-latest]
17
+ version:
18
+ [
19
+ "2.2",
20
+ "2.3",
21
+ "2.4",
22
+ "2.5",
23
+ "2.6",
24
+ "2.7",
25
+ "head",
26
+ "jruby",
27
+ "jruby-head",
28
+ ]
29
+ exclude:
30
+ - os: windows-latest
31
+ version: "jruby"
32
+ - os: windows-latest
33
+ version: "jruby-head"
34
+ steps:
35
+ - name: checkout
36
+ uses: actions/checkout@v2
37
+
38
+ - uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: ${{ matrix.version }}
41
+ - name: ruby version
42
+ run: ruby -v
43
+ - run: bundler install
44
+ name: install
45
+ - run: bundler exec rake -t
46
+ name: test
@@ -0,0 +1,127 @@
1
+ Gemspec/RequiredRubyVersion:
2
+ Enabled: false # We support 1.9, but newer rubocops don't.
3
+
4
+ # Metrics.
5
+
6
+ Metrics/BlockLength:
7
+ Enabled: false # Default is true, but mostly hit in tests.
8
+
9
+ Metrics/AbcSize:
10
+ Enabled: false # To allow for pre-existing code.
11
+
12
+ Metrics/ClassLength:
13
+ Enabled: false # To allow for pre-existing code.
14
+
15
+ Metrics/CyclomaticComplexity:
16
+ Enabled: false # To allow for pre-existing code.
17
+
18
+ Metrics/MethodLength:
19
+ Enabled: false # To allow for pre-existing code.
20
+
21
+ Metrics/PerceivedComplexity:
22
+ Enabled: false # To allow for pre-existing code.
23
+
24
+ # Layout.
25
+
26
+ Layout/LineLength:
27
+ Max: 150 # Default is 120.
28
+
29
+ Layout/HashAlignment:
30
+ EnforcedHashRocketStyle: table # Default is key.
31
+ EnforcedColonStyle: table # Default is key.
32
+
33
+ Layout/ExtraSpacing:
34
+ ForceEqualSignAlignment: true # Default is false.
35
+
36
+ Layout/IndentationStyle:
37
+ IndentationWidth: 2 # Default is <none>.
38
+
39
+ # Style.
40
+
41
+ Style/HashSyntax:
42
+ EnforcedStyle: ruby19_no_mixed_keys # Default is ruby19.
43
+
44
+ Style/CollectionMethods:
45
+ Enabled: true # Default is false.
46
+
47
+ Style/NumericLiterals:
48
+ MinDigits: 4 # Default is 5.
49
+
50
+ Style/NegatedIf: # I disagree with this.
51
+ Enabled: false
52
+
53
+ Style/IfUnlessModifier: # This doesn't always make sense.
54
+ Enabled: false
55
+
56
+ Style/SymbolArray:
57
+ EnforcedStyle: brackets # Default is percent, but 1.9 doesn't support that.
58
+
59
+ # Trailing commas are often good.
60
+ Style/TrailingCommaInArguments:
61
+ Enabled: false
62
+ Style/TrailingCommaInArrayLiteral:
63
+ Enabled: false
64
+ Style/TrailingCommaInHashLiteral:
65
+ Enabled: false
66
+
67
+ Style/SafeNavigation:
68
+ Enabled: false # Default is true, but this 1.9 doesn't support it.
69
+
70
+ # Default is both which is probably fine, but it changes code and I don't want
71
+ # to investigate any possible behavior change right now.
72
+ Style/EmptyElse:
73
+ EnforcedStyle: empty
74
+
75
+ Style/ConditionalAssignment:
76
+ Enabled: false # This produces kind of strange results.
77
+
78
+ Style/Dir:
79
+ Enabled: false # This is good, but not supported on 1.9.
80
+
81
+ Style/ExpandPathArguments:
82
+ Enabled: false # This causes us to use __dir__ which 1.9 doesn't support.
83
+
84
+ Style/GuardClause:
85
+ Enabled: false # Doesn't always make sense.
86
+
87
+ Style/Documentation:
88
+ Enabled: false # We should enable this, but allow for pre-existing code.
89
+
90
+ Style/FormatStringToken:
91
+ Enabled: false # Seems unnecessary.
92
+
93
+ # Naming.
94
+
95
+ Naming/VariableNumber:
96
+ Enabled: false # Doesn't always make sense.
97
+
98
+ # These are new and rubocop warns if you don't configure them.
99
+
100
+ Layout/EmptyLinesAroundAttributeAccessor:
101
+ Enabled: true
102
+ Layout/SpaceAroundMethodCallOperator:
103
+ Enabled: true
104
+ Lint/DeprecatedOpenSSLConstant:
105
+ Enabled: true
106
+ Lint/MixedRegexpCaptureTypes:
107
+ Enabled: true
108
+ Lint/RaiseException:
109
+ Enabled: true
110
+ Lint/StructNewOverride:
111
+ Enabled: true
112
+ Style/ExponentialNotation:
113
+ Enabled: true
114
+ Style/HashEachMethods:
115
+ Enabled: true
116
+ Style/HashTransformKeys:
117
+ Enabled: true
118
+ Style/HashTransformValues:
119
+ Enabled: true
120
+ Style/RedundantFetchBlock:
121
+ Enabled: true
122
+ Style/RedundantRegexpCharacterClass:
123
+ Enabled: true
124
+ Style/RedundantRegexpEscape:
125
+ Enabled: true
126
+ Style/SlicingWithRange:
127
+ Enabled: true
@@ -1,5 +1,19 @@
1
1
  # Minfraud Changelog
2
2
 
3
+ ## v1.2.0 (2020-07-15)
4
+
5
+ * Adds new processor types to `Minfraud::Components::Payment`: `:cashfree`,
6
+ `:first_atlantic_commerce`, `:komoju`, `:paytm`, `:razorpay`, and
7
+ `:systempay`.
8
+ * Adds support for three new Factors outputs: `/subscores/device` (the risk
9
+ associated with the device), `/subscores/email_local_part` (the risk
10
+ associated with the part of the email address before the @ symbol) and
11
+ `/subscores/shipping_address` (the risk associated with the shipping
12
+ address).
13
+ * Adds support for providing your MaxMind account ID using the `account_id`
14
+ attribute instead of the `user_id` attribute. In a future release,
15
+ support for the `user_id` attribute will be removed.
16
+
3
17
  ## v1.1.0 (2020-06-19)
4
18
 
5
19
  * Adds support for the minFraud Report Transaction API. Reporting
data/Gemfile CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # coveralls fails on Ruby 1.9. My understanding is we don't need to run this on
4
6
  # more than one version anyway, so restrict to the current latest.
5
7
  version_pieces = RUBY_VERSION.split('.')
6
- major_version = version_pieces[0]
7
- minor_version = version_pieces[1]
8
+ major_version = version_pieces[0]
9
+ minor_version = version_pieces[1]
8
10
  if major_version == '2' && minor_version == '7'
9
11
  gem 'coveralls', require: false
10
12
  end
data/README.md CHANGED
@@ -41,8 +41,8 @@ An account ID and license key are required to work with the web services.
41
41
 
42
42
  ```ruby
43
43
  Minfraud.configure do |c|
44
+ c.account_id = 12345
44
45
  c.license_key = 'your_license_key'
45
- c.user_id = 'your_user_id'
46
46
  end
47
47
  ````
48
48
 
data/Rakefile CHANGED
@@ -1,6 +1,21 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec)
5
8
 
6
- task :default => :spec
9
+ RuboCop::RakeTask.new
10
+
11
+ task default: :spec
12
+
13
+ # The current version of rubocop supports Ruby 2.4+. While we could run its
14
+ # older versions, the config isn't backwards compatible. Let's run it only for
15
+ # 2.4+. This isn't perfect, but as long as 1.9+ tests pass we should be okay.
16
+ version_pieces = RUBY_VERSION.split('.')
17
+ major_version = version_pieces[0]
18
+ minor_version = version_pieces[1]
19
+ if major_version == '2' && minor_version.to_i >= 4
20
+ task default: :rubocop
21
+ end
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "minfraud"
4
+ require 'bundler/setup'
5
+ require 'minfraud'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "minfraud"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start
@@ -68,9 +68,9 @@ module MaxMind
68
68
  # @!visibility private
69
69
  def initialize(record, locales)
70
70
  super(record, locales)
71
- @city = MaxMind::GeoIP2::Record::City.new(record['city'], locales)
72
- @location = MaxMind::GeoIP2::Record::Location.new(record['location'])
73
- @postal = MaxMind::GeoIP2::Record::Postal.new(record['postal'])
71
+ @city = MaxMind::GeoIP2::Record::City.new(record['city'], locales)
72
+ @location = MaxMind::GeoIP2::Record::Location.new(record['location'])
73
+ @postal = MaxMind::GeoIP2::Record::Postal.new(record['postal'])
74
74
  @subdivisions = create_subdivisions(record['subdivisions'], locales)
75
75
  end
76
76
 
@@ -69,16 +69,16 @@ module MaxMind
69
69
 
70
70
  # @!visibility private
71
71
  def initialize(record, locales)
72
- @continent = MaxMind::GeoIP2::Record::Continent.new(
72
+ @continent = MaxMind::GeoIP2::Record::Continent.new(
73
73
  record['continent'],
74
74
  locales,
75
75
  )
76
- @country = MaxMind::GeoIP2::Record::Country.new(
76
+ @country = MaxMind::GeoIP2::Record::Country.new(
77
77
  record['country'],
78
78
  locales,
79
79
  )
80
- @maxmind = MaxMind::GeoIP2::Record::MaxMind.new(record['maxmind'])
81
- @registered_country = MaxMind::GeoIP2::Record::Country.new(
80
+ @maxmind = MaxMind::GeoIP2::Record::MaxMind.new(record['maxmind'])
81
+ @registered_country = MaxMind::GeoIP2::Record::Country.new(
82
82
  record['registered_country'],
83
83
  locales,
84
84
  )
@@ -86,7 +86,7 @@ module MaxMind
86
86
  record['represented_country'],
87
87
  locales,
88
88
  )
89
- @traits = MaxMind::GeoIP2::Record::Traits.new(record['traits'])
89
+ @traits = MaxMind::GeoIP2::Record::Traits.new(record['traits'])
90
90
  end
91
91
  end
92
92
  end
@@ -35,7 +35,7 @@ module MaxMind
35
35
  super(record)
36
36
  if !record.key?('network') && record.key?('ip_address') &&
37
37
  record.key?('prefix_length')
38
- ip = IPAddr.new(record['ip_address']).mask(record['prefix_length'])
38
+ ip = IPAddr.new(record['ip_address']).mask(record['prefix_length'])
39
39
  # We could use ip.prefix instead of record['prefix_length'], but that
40
40
  # method only becomes available in Ruby 2.5+.
41
41
  record['network'] = format('%s/%d', ip.to_s, record['prefix_length'])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minfraud'
2
4
  require 'minfraud/enum'
3
5
  require 'minfraud/components/base'
@@ -27,20 +29,41 @@ require 'minfraud/report'
27
29
 
28
30
  module Minfraud
29
31
  class << self
30
- # @!attribute user_id
31
- # @return [String] MaxMind account ID that is used for authorization
32
+ # The MaxMind account ID that is used for authorization.
33
+ #
34
+ # @return [Integer, nil]
35
+ attr_accessor :account_id
36
+
37
+ # The host to use when connecting to the web service.
38
+ #
39
+ # @return [String, nil]
40
+ attr_accessor :host
41
+
42
+ # The MaxMind account ID that is used for authorization.
43
+ #
44
+ # @deprecated Use {::account_id} instead. This will be removed in the next
45
+ # major version.
46
+ #
47
+ # @return [Integer, nil]
32
48
  attr_accessor :user_id
33
49
 
34
- # @!attribute license_key
35
- # @return [String] MaxMind license key that is used for authorization
50
+ # The MaxMind license key that is used for authorization.
51
+ #
52
+ # @return [String, nil]
36
53
  attr_accessor :license_key
37
54
 
38
- # @yield [self] to accept configuration settings
55
+ # Yield self to accept configuration settings.
56
+ #
57
+ # @yield [self]
39
58
  def configure
40
59
  yield self
41
60
  end
42
61
 
43
- # @return [Hash] current Minfraud configuration
62
+ # The current Minfraud configuration.
63
+ #
64
+ # @deprecated This will be removed in the next major version.
65
+ #
66
+ # @return [Hash]
44
67
  def configuration
45
68
  {
46
69
  user_id: @user_id,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  class Assessments
3
5
  include ::Minfraud::HTTPService
@@ -83,11 +85,13 @@ module Minfraud
83
85
  define :factors
84
86
 
85
87
  private
88
+
86
89
  # Creates a unified request body from components converted to JSON
87
90
  # @return [Hash] Request body
88
91
  def request_body
89
- MAPPING.keys.inject({}) do |mem, e|
90
- next mem unless value = send(e)
92
+ MAPPING.keys.reduce({}) do |mem, e|
93
+ next mem unless (value = send(e))
94
+
91
95
  mem.merge!(e.to_s => value.to_json)
92
96
  end
93
97
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Account < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Addressable < Base
@@ -14,11 +16,11 @@ module Minfraud
14
16
  attr_accessor :company
15
17
 
16
18
  # @attribute address
17
- # @return [String] The first line of the users billing / shipping address
19
+ # @return [String] The first line of the user's billing / shipping address
18
20
  attr_accessor :address
19
21
 
20
22
  # @attribute address_2
21
- # @return [String] The second line of the users billing / shipping address
23
+ # @return [String] The second line of the user's billing / shipping address
22
24
  attr_accessor :address_2
23
25
 
24
26
  # @attribute city
@@ -26,23 +28,23 @@ module Minfraud
26
28
  attr_accessor :city
27
29
 
28
30
  # @attribute region
29
- # @return [String] The ISO 3166-2 subdivision code for the users billing / shipping address
31
+ # @return [String] The ISO 3166-2 subdivision code for the user's billing / shipping address
30
32
  attr_accessor :region
31
33
 
32
34
  # @attribute country
33
- # @return [String] The two character ISO 3166-1 alpha-2 country code of the users billing / shipping address
35
+ # @return [String] The two character ISO 3166-1 alpha-2 country code of the user's billing / shipping address
34
36
  attr_accessor :country
35
37
 
36
38
  # @attribute postal
37
- # @return [String] The postal code of the users billing / shipping address
39
+ # @return [String] The postal code of the user's billing / shipping address
38
40
  attr_accessor :postal
39
41
 
40
42
  # @attribute phone_number
41
- # @return [String] The phone number without the country code for the users billing / shipping address
43
+ # @return [String] The phone number without the country code for the user's billing / shipping address
42
44
  attr_accessor :phone_number
43
45
 
44
46
  # @attribute phone_country_code
45
- # @return [String] The country code for phone number associated with the users billing / shipping address
47
+ # @return [String] The country code for phone number associated with the user's billing / shipping address
46
48
  attr_accessor :phone_country_code
47
49
 
48
50
  # Creates Minfraud::Components::Addressable instance