minfraud 2.10.0 → 2.11.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e9a3d34fdcba8b336c22ccfb3088f42cf08e9debccc2a9f97e80cefe5f2c79d
4
- data.tar.gz: 851ce59eec3a798f76821ddcd06e73840d5911735aa0f8be802c95caa340005f
3
+ metadata.gz: 6a88f0e4c000a338fa1048e0849bb717b4c28b2318d6cfc89cdef230ceb9539d
4
+ data.tar.gz: 40510ef4654ae52b4fdcf6fbf4a472e9b22797636e1940c16751b40f0a87bcd1
5
5
  SHA512:
6
- metadata.gz: 4d5832ed02bbfe75d68e1232629815a1fe18be611f62d01b04c361d99efdc6125970abde150bd8ff52be2725c177bd72ac4600fee9030cabb53913eb552c7131
7
- data.tar.gz: 9a8e36fb6925f617296fc4d5c472f3fed5d73a95715aaf3f5c098987ffb74e6218e7509a24fb0b38c73458e149969fdbcf05052a8b9b86ef9d631d921b13b211
6
+ metadata.gz: 03b6ed822052decb4c17c5c50f30368567f0178d69f9566bedea35e01fd1778a9851353094380e41cba44ed347bd49e5d69025312508e187f774c61855e39ca8
7
+ data.tar.gz: 3d32d446b59488f0d558582b384b8c4b18fcd4730eae606a28af69056eb2afe112bd7f8516edca3e1c73d5569860cded86461883ebc087970bbcb16363a6d658
data/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.11.0 (2026-11-18)
4
+
5
+ * Added the `phone_verification_method`,
6
+ `phone_was_verification_successful`, and `phone_verification_time`
7
+ attributes to `Minfraud::Components::Billing` and
8
+ `Minfraud::Components::Shipping`. They describe the most recent
9
+ verification of the billing or shipping phone number.
10
+ * Added the `verification_time` and `was_verification_successful`
11
+ attributes to `Minfraud::Components::Email`. They describe the most
12
+ recent verification of the email address.
13
+ * Boolean inputs are now always sent as JSON booleans, and `false` is no
14
+ longer dropped. Previously, every input set to `false` was omitted.
15
+ Now only `nil` inputs are omitted. In particular:
16
+ * `true` for `/credit_card/was_3d_secure_successful` was sent as the
17
+ string `"true"`, which the web service rejected and dropped. It is
18
+ now sent as a JSON boolean, so it reaches the web service.
19
+ * Custom input values of `true` and `false` are now sent as JSON
20
+ booleans, and `false` is no longer dropped.
21
+ * **Warning:** If a custom input is a string type on your account, a
22
+ Ruby `true` or `false` for it is now sent as a JSON boolean. The web
23
+ service rejects a boolean for a string custom input with an
24
+ `INPUT_INVALID` warning. Pass a string, such as `'true'`, instead.
25
+ * With validation on, `true` or `false` for a non-boolean input now
26
+ raises `InvalidInputError`. This includes `token` on
27
+ `Minfraud::Components::CreditCard`, `tracking_token` on
28
+ `Minfraud::Components::Device`, and `chargeback_code`, `notes`, and
29
+ `transaction_id` on `Minfraud::Components::Report::Transaction`.
30
+ Previously, these accepted a boolean, and `transaction_id: false`
31
+ raised `NoMethodError`.
32
+ * `/order/has_gift_message`, `/order/is_gift`, and
33
+ `/payment/was_authorized` already sent `true` as a JSON boolean.
34
+ * The `*_values` class methods of enum attributes, such as
35
+ `Minfraud::Components::Event.type_values`, now exist only on the class
36
+ that declares the enum and its subclasses. Previously, every class
37
+ responded to them. `mapping` on a subclass now includes the enums of
38
+ its parent class.
39
+ * Enum setters, such as `Minfraud::Components::Event#type=`, now raise
40
+ `NotEnumValueError` for a value that is not a String, a Symbol, or
41
+ `nil`. Previously, `false` cleared the attribute, and `true` raised
42
+ `NoMethodError`. The `*_values` class methods now return a frozen
43
+ array.
44
+ * With validation on, `Minfraud::Components::Event` now rejects a `time`
45
+ that the web service rejects. Previously, the client accepted hour 24,
46
+ second 60, a UTC offset of 24 hours or more, and a lowercase `t` or
47
+ `z`.
48
+ * Added the processor `:ryft` to `Minfraud::Components::Payment`.
49
+ * The minimum version of the `maxmind-geoip2` gem is now 1.7.0. It
50
+ requires `maxmind-db` 1.5.0, which limits the work and memory of each
51
+ decode of a crafted database and makes lookups faster. See the
52
+ [maxmind-geoip2 1.7.0 changelog](https://github.com/maxmind/GeoIP2-ruby/blob/v1.7.0/CHANGELOG.md).
53
+
3
54
  ## v2.10.0 (2026-07-21)
4
55
 
5
56
  * Added the `residential` attribute to the `anonymizer` object on
data/README.md CHANGED
@@ -90,7 +90,7 @@ assessment = Minfraud::Assessments.new(
90
90
  party: :customer,
91
91
  transaction_id: 'txn3134133',
92
92
  shop_id: 's2123',
93
- time: '2012-04-12T23:20:50+00:00',
93
+ time: '2026-10-05T23:20:50+00:00',
94
94
  type: :purchase,
95
95
  },
96
96
  account: {
@@ -98,35 +98,43 @@ assessment = Minfraud::Assessments.new(
98
98
  username_md5: '4f9726678c438914fa04bdb8c1a24088',
99
99
  },
100
100
  email: {
101
- address: 'test@maxmind.com',
102
- domain: 'maxmind.com',
101
+ address: 'test@maxmind.com',
102
+ domain: 'maxmind.com',
103
+ verification_time: '2026-10-01T14:30:00Z',
104
+ was_verification_successful: true,
103
105
  },
104
106
  billing: {
105
- first_name: 'First',
106
- last_name: 'Last',
107
- company: 'Company',
108
- address: '101 Address Rd.',
109
- address_2: 'Unit 5',
110
- city: 'New Haven',
111
- region: 'CT',
112
- country: 'US',
113
- postal: '06510',
114
- phone_number: '123-456-7890',
115
- phone_country_code: '1',
107
+ first_name: 'First',
108
+ last_name: 'Last',
109
+ company: 'Company',
110
+ address: '101 Address Rd.',
111
+ address_2: 'Unit 5',
112
+ city: 'New Haven',
113
+ region: 'CT',
114
+ country: 'US',
115
+ postal: '06510',
116
+ phone_number: '123-456-7890',
117
+ phone_country_code: '1',
118
+ phone_verification_method: :delivered_code,
119
+ phone_verification_time: '2026-10-01T14:30:00Z',
120
+ phone_was_verification_successful: true,
116
121
  },
117
122
  shipping: {
118
- first_name: 'ShipFirst',
119
- last_name: 'ShipLast',
120
- company: 'ShipCo',
121
- address: '322 Ship Addr. Ln.',
122
- address_2: 'St. 43',
123
- city: 'Nowhere',
124
- region: 'OK',
125
- country: 'US',
126
- postal: '73003',
127
- phone_number: '123-456-0000',
128
- phone_country_code: '1',
129
- delivery_speed: :same_day,
123
+ first_name: 'ShipFirst',
124
+ last_name: 'ShipLast',
125
+ company: 'ShipCo',
126
+ address: '322 Ship Addr. Ln.',
127
+ address_2: 'St. 43',
128
+ city: 'Nowhere',
129
+ region: 'OK',
130
+ country: 'US',
131
+ postal: '73003',
132
+ phone_number: '123-456-0000',
133
+ phone_country_code: '1',
134
+ delivery_speed: :same_day,
135
+ phone_verification_method: :delivered_code,
136
+ phone_verification_time: '2026-10-01T14:30:00Z',
137
+ phone_was_verification_successful: true,
130
138
  },
131
139
  payment: {
132
140
  method: :card,
@@ -5,6 +5,7 @@ module Minfraud
5
5
  # This is a parent class for the Billing and Shipping components.
6
6
  class Addressable < Base
7
7
  include Minfraud::Validates
8
+ include ::Minfraud::Enum
8
9
 
9
10
  # The first name of the end user as provided in their billing / shipping
10
11
  # information.
@@ -74,20 +75,52 @@ module Minfraud
74
75
  # @return [String, nil]
75
76
  attr_accessor :phone_country_code
76
77
 
78
+ # The most recent method used to verify the phone number. This must be
79
+ # one of +:delivered_code+, +:network+, or +:other+.
80
+ # +:delivered_code+ is a code delivered to the phone, such as by SMS,
81
+ # voice call, or messaging app. +:network+ is verification through the
82
+ # mobile network operator, such as silent network authentication.
83
+ #
84
+ # @!attribute phone_verification_method
85
+ #
86
+ # @return [Symbol, nil]
87
+ enum_accessor :phone_verification_method, %i[delivered_code network other]
88
+
89
+ # Whether the most recent verification of the phone number
90
+ # succeeded. Do not include this field if no verification was
91
+ # attempted.
92
+ #
93
+ # @return [Boolean, nil]
94
+ attr_accessor :phone_was_verification_successful
95
+
96
+ # The date and time of the most recent verification of the phone
97
+ # number. The string must be in the RFC 3339 date-time format, e.g.,
98
+ # "2012-04-12T23:20:50.52Z". The time must not be before
99
+ # 1970-01-01T00:00:00Z or more than two days in the future. The web
100
+ # service ignores a time outside this range and returns a warning.
101
+ #
102
+ # @see https://datatracker.ietf.org/doc/html/rfc3339
103
+ #
104
+ # @return [String, nil]
105
+ attr_accessor :phone_verification_time
106
+
77
107
  # @param params [Hash] Hash of parameters. Each key/value should
78
108
  # correspond to one of the available attributes.
79
109
  def initialize(params = {})
80
- @first_name = params[:first_name]
81
- @last_name = params[:last_name]
82
- @company = params[:company]
83
- @address = params[:address]
84
- @address_2 = params[:address_2]
85
- @city = params[:city]
86
- @region = params[:region]
87
- @country = params[:country]
88
- @postal = params[:postal]
89
- @phone_number = params[:phone_number]
90
- @phone_country_code = params[:phone_country_code]
110
+ @first_name = params[:first_name]
111
+ @last_name = params[:last_name]
112
+ @company = params[:company]
113
+ @address = params[:address]
114
+ @address_2 = params[:address_2]
115
+ @city = params[:city]
116
+ @region = params[:region]
117
+ @country = params[:country]
118
+ @postal = params[:postal]
119
+ @phone_number = params[:phone_number]
120
+ @phone_country_code = params[:phone_country_code]
121
+ self.phone_verification_method = params[:phone_verification_method]
122
+ @phone_was_verification_successful = params[:phone_was_verification_successful]
123
+ @phone_verification_time = params[:phone_verification_time]
91
124
 
92
125
  validate
93
126
  end
@@ -108,6 +141,8 @@ module Minfraud
108
141
  validate_string('postal', 255, @postal)
109
142
  validate_string('phone_number', 255, @phone_number)
110
143
  validate_telephone_country_code('phone_country_code', @phone_country_code)
144
+ validate_boolean('phone_was_verification_successful', @phone_was_verification_successful)
145
+ validate_rfc3339('phone_verification_time', @phone_verification_time)
111
146
  end
112
147
  end
113
148
  end
@@ -26,27 +26,22 @@ module Minfraud
26
26
  #
27
27
  # @return [Hash]
28
28
  def populate!(hash, v_sym)
29
- return hash unless (value = instance_variable_get(v_sym))
29
+ value = instance_variable_get(v_sym)
30
+ return hash if value.nil?
30
31
 
31
- key = v_sym.to_s.gsub(/@/, '')
32
- hash.merge!(key => represent(key, value))
32
+ key = v_sym.to_s.delete_prefix('@')
33
+ hash.merge!(key => represent(value))
33
34
  end
34
35
 
35
- # Return the value according to the request format.
36
- #
37
- # @param key [Symbol] An instance variable symbol.
36
+ # Return the value according to the request format. Booleans stay
37
+ # booleans. Other values become strings.
38
38
  #
39
39
  # @param value [Object] An instance variable value.
40
40
  #
41
41
  # @return [Object]
42
- def represent(key, value)
43
- BOOLS.include?(key) ? value : value.to_s
42
+ def represent(value)
43
+ Minfraud::Validates.boolean?(value) ? value : value.to_s
44
44
  end
45
-
46
- # Keys that have to remain boolean
47
- BOOLS = %w[was_authorized is_gift has_gift_message].freeze
48
-
49
- private_constant :BOOLS
50
45
  end
51
46
  end
52
47
  end
@@ -69,6 +69,7 @@ module Minfraud
69
69
  validate_string('accept_language', 255, @accept_language)
70
70
  validate_nonnegative_number('session_age', @session_age)
71
71
  validate_string('session_id', 255, @session_id)
72
+ validate_not_boolean('tracking_token', @tracking_token)
72
73
  end
73
74
  end
74
75
  end
@@ -31,12 +31,32 @@ module Minfraud
31
31
  # @return [Boolean, nil]
32
32
  attr_accessor :hash_address
33
33
 
34
+ # The date and time of the most recent attempt to verify the email
35
+ # address, if known. The string must be in the RFC 3339 date-time
36
+ # format, e.g., "2012-04-12T23:20:50.52Z". The time must not be before
37
+ # 1970-01-01T00:00:00Z or more than two days in the future. The web
38
+ # service ignores a time outside this range and returns a warning.
39
+ #
40
+ # @see https://datatracker.ietf.org/doc/html/rfc3339
41
+ #
42
+ # @return [String, nil]
43
+ attr_accessor :verification_time
44
+
45
+ # Whether the most recent verification that the end user controls the
46
+ # email address succeeded, for example by confirming a link sent to the
47
+ # address. Do not include this field if no verification was attempted.
48
+ #
49
+ # @return [Boolean, nil]
50
+ attr_accessor :was_verification_successful
51
+
34
52
  # @param params [Hash] Hash of parameters. Each key/value should
35
53
  # correspond to one of the available attributes.
36
54
  def initialize(params = {})
37
- @address = params[:address]
38
- @domain = params[:domain]
39
- @hash_address = params[:hash_address]
55
+ @address = params[:address]
56
+ @domain = params[:domain]
57
+ @hash_address = params[:hash_address]
58
+ @verification_time = params[:verification_time]
59
+ @was_verification_successful = params[:was_verification_successful]
40
60
 
41
61
  validate
42
62
  end
@@ -72,6 +92,8 @@ module Minfraud
72
92
 
73
93
  validate_email('email', @address)
74
94
  validate_string('domain', 255, @domain)
95
+ validate_rfc3339('verification_time', @verification_time)
96
+ validate_boolean('was_verification_successful', @was_verification_successful)
75
97
  end
76
98
 
77
99
  def hash_email_address(address)
@@ -222,6 +244,7 @@ module Minfraud
222
244
  'fastemailer.com' => true,
223
245
  'fastest.cc' => true,
224
246
  'fastimap.com' => true,
247
+ 'fastmail.ca' => true,
225
248
  'fastmail.cn' => true,
226
249
  'fastmail.co.uk' => true,
227
250
  'fastmail.com' => true,
@@ -316,6 +339,7 @@ module Minfraud
316
339
  private_constant :FASTMAIL_DOMAINS
317
340
 
318
341
  YAHOO_DOMAINS = {
342
+ 'myyahoo.com' => true,
319
343
  'y7mail.com' => true,
320
344
  'yahoo.at' => true,
321
345
  'yahoo.be' => true,
@@ -169,6 +169,7 @@ module Minfraud
169
169
  rede
170
170
  redpagos
171
171
  rewardspay
172
+ ryft
172
173
  safecharge
173
174
  sagepay
174
175
  securepay
@@ -94,6 +94,9 @@ module Minfraud
94
94
  validate_ip('ip_address', @ip_address)
95
95
  validate_string('maxmind_id', 8, @maxmind_id)
96
96
  validate_uuid('minfraud_id', @minfraud_id)
97
+ validate_not_boolean('chargeback_code', @chargeback_code)
98
+ validate_not_boolean('notes', @notes)
99
+ validate_not_boolean('transaction_id', @transaction_id)
97
100
 
98
101
  if ip_address.nil? &&
99
102
  (minfraud_id.nil? || empty_uuid?(minfraud_id)) &&
@@ -6,8 +6,6 @@ module Minfraud
6
6
  #
7
7
  # @see https://dev.maxmind.com/minfraud/api-documentation/requests/?lang=en#schema--request--shipping
8
8
  class Shipping < Addressable
9
- include ::Minfraud::Enum
10
-
11
9
  # The shipping delivery speed for the order. Must be one of +:same_day+,
12
10
  # +:overnight+, +:expedited+, or +:standard+.
13
11
  #
data/lib/minfraud/enum.rb CHANGED
@@ -17,14 +17,22 @@ module Minfraud
17
17
  # types.
18
18
  module ClassMethods
19
19
  # Returns a hash in the following format: attribute_name =>
20
- # permitted_values
20
+ # permitted_values. It includes the attributes declared on parent
21
+ # classes.
21
22
  #
22
23
  # @return [Hash]
23
24
  def mapping
24
25
  # rubocop:disable ThreadSafety/ClassInstanceVariable
25
- # This is a false positive - this is set during class definition and then only read
26
- @mapping ||= {}
26
+ # This is a false positive - this only reads the mapping that
27
+ # enum_accessor sets during class definition
28
+ declared = @declared_mapping || {}
27
29
  # rubocop:enable ThreadSafety/ClassInstanceVariable
30
+
31
+ if superclass.respond_to?(:mapping)
32
+ superclass.mapping.merge(declared)
33
+ else
34
+ declared.dup
35
+ end
28
36
  end
29
37
 
30
38
  # Create a set of methods for enum-like behavior of the attribute.
@@ -35,23 +43,33 @@ module Minfraud
35
43
  #
36
44
  # @return [nil]
37
45
  def enum_accessor(attribute, assignable_values)
38
- mapping[attribute] = assignable_values.map(&:intern)
46
+ values = assignable_values.map(&:intern).freeze
47
+ declared_mapping[attribute] = values
39
48
 
40
- self.class.instance_eval do
41
- define_method("#{attribute}_values") { mapping[attribute] }
42
- end
49
+ define_singleton_method("#{attribute}_values") { values }
43
50
 
44
51
  class_eval do
45
52
  define_method(attribute.to_s) { instance_variable_get("@#{attribute}") }
46
53
  define_method "#{attribute}=" do |value|
47
- raise NotEnumValueError, 'Value is not permitted' if value && !self.class.mapping[attribute].include?(value.intern)
54
+ value = value.intern if value.is_a?(String)
55
+ raise NotEnumValueError, 'Value is not permitted' if !value.nil? && !values.include?(value)
48
56
 
49
- instance_variable_set("@#{attribute}", value ? value.intern : nil)
57
+ instance_variable_set("@#{attribute}", value)
50
58
  end
51
59
  end
52
60
 
53
61
  nil
54
62
  end
63
+
64
+ private
65
+
66
+ def declared_mapping
67
+ # rubocop:disable ThreadSafety/ClassInstanceVariable
68
+ # This is a false positive - only enum_accessor calls this, during class
69
+ # definition
70
+ @declared_mapping ||= {}
71
+ # rubocop:enable ThreadSafety/ClassInstanceVariable
72
+ end
55
73
  end
56
74
  end
57
75
  end
@@ -8,8 +8,8 @@ module Minfraud
8
8
  class RiskScoreReason < Abstract
9
9
  # The factor by which the risk score is increased (if the value is greater than 1)
10
10
  # or decreased (if the value is less than 1) for given risk reason(s).
11
- # Multipliers greater than 1.5 and less than 0.66 are considered significant
12
- # and lead to risk reason(s) being present.
11
+ # Multipliers representing a significant percentage increase or decrease
12
+ # in the risk score lead to risk reason(s) being present.
13
13
  #
14
14
  # @return [Float]
15
15
  attr_reader :multiplier
@@ -12,6 +12,13 @@ module Minfraud
12
12
  #
13
13
  # rubocop:disable Metrics/ModuleLength
14
14
  module Validates
15
+ RFC3339_REGEX = /
16
+ \A(\d{4})-(\d{2})-(\d{2})
17
+ T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?
18
+ (?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)\z
19
+ /x
20
+ private_constant :RFC3339_REGEX
21
+
15
22
  # Validates that a string value does not exceed a maximum length.
16
23
  #
17
24
  # @param field [String] The field name for error messages.
@@ -22,7 +29,9 @@ module Minfraud
22
29
  #
23
30
  # @return [nil]
24
31
  def validate_string(field, length, value)
25
- return if !value
32
+ return if value.nil?
33
+
34
+ validate_not_boolean(field, value)
26
35
 
27
36
  if value.to_s.length > length
28
37
  raise InvalidInputError, "The #{field} value is not valid. The maximum length is #{length}."
@@ -38,7 +47,9 @@ module Minfraud
38
47
  #
39
48
  # @return [nil]
40
49
  def validate_md5(field, value)
41
- return if !value
50
+ return if value.nil?
51
+
52
+ validate_not_boolean(field, value)
42
53
 
43
54
  if !value.to_s.match(/\A[a-fA-F0-9]{32}\z/)
44
55
  raise InvalidInputError, "The #{field} value is not valid. It must be an MD5 hash as a string."
@@ -54,7 +65,9 @@ module Minfraud
54
65
  #
55
66
  # @return [nil]
56
67
  def validate_uuid(field, value)
57
- return if !value
68
+ return if value.nil?
69
+
70
+ validate_not_boolean(field, value)
58
71
 
59
72
  stripped_value = value.to_s.delete('-')
60
73
 
@@ -75,7 +88,9 @@ module Minfraud
75
88
  #
76
89
  # @return [nil]
77
90
  def validate_subdivision_code(field, value)
78
- return if !value
91
+ return if value.nil?
92
+
93
+ validate_not_boolean(field, value)
79
94
 
80
95
  if !value.to_s.match(/\A[0-9A-Z]{1,4}\z/)
81
96
  raise InvalidInputError, "The #{field} value is not valid. It must be an ISO 3166-2 subdivision code."
@@ -91,7 +106,9 @@ module Minfraud
91
106
  #
92
107
  # @return [nil]
93
108
  def validate_country_code(field, value)
94
- return if !value
109
+ return if value.nil?
110
+
111
+ validate_not_boolean(field, value)
95
112
 
96
113
  if !value.to_s.match(/\A[A-Z]{2}\z/)
97
114
  raise InvalidInputError, "The #{field} value is not valid. It must be an ISO 3166-1 alpha-2 country code."
@@ -108,7 +125,9 @@ module Minfraud
108
125
  #
109
126
  # @return [nil]
110
127
  def validate_telephone_country_code(field, value)
111
- return if !value
128
+ return if value.nil?
129
+
130
+ validate_not_boolean(field, value)
112
131
 
113
132
  if !value.to_s.match(/\A[0-9]{1,4}\z/)
114
133
  raise InvalidInputError, "The #{field} value is not valid. It must be at most 4 digits."
@@ -125,7 +144,9 @@ module Minfraud
125
144
  #
126
145
  # @return [nil]
127
146
  def validate_regex(field, regex, value)
128
- return if !value
147
+ return if value.nil?
148
+
149
+ validate_not_boolean(field, value)
129
150
 
130
151
  if !regex.match(value.to_s)
131
152
  raise InvalidInputError, "The #{field} value is not valid. It must match the pattern #{regex}."
@@ -141,7 +162,9 @@ module Minfraud
141
162
  #
142
163
  # @return [nil]
143
164
  def validate_credit_card_token(field, value)
144
- return if !value
165
+ return if value.nil?
166
+
167
+ validate_not_boolean(field, value)
145
168
 
146
169
  s = value.to_s
147
170
 
@@ -163,11 +186,9 @@ module Minfraud
163
186
  #
164
187
  # @return [nil]
165
188
  def validate_custom_input_value(field, value)
166
- return if !value
189
+ return if value.nil?
167
190
 
168
- if [true, false].include?(value)
169
- return
170
- end
191
+ return if boolean?(value)
171
192
 
172
193
  if value.is_a? Numeric
173
194
  if value < -1e13 + 1 || value > 1e13 - 1
@@ -189,20 +210,21 @@ module Minfraud
189
210
  #
190
211
  # @return [nil]
191
212
  def validate_ip(field, value)
192
- return if !value
213
+ return if value.nil?
214
+
215
+ validate_not_boolean(field, value)
193
216
 
194
217
  s = value.to_s
195
218
  if s.include? '/'
196
219
  raise InvalidInputError, "The #{field} value is not valid. It must be an individual IP address."
197
220
  end
198
221
 
199
- # rubocop:disable Style/RescueStandardError
222
+ # rubocop:disable-next Style/RescueStandardError
200
223
  begin
201
224
  IPAddr.new(s)
202
225
  rescue
203
226
  raise InvalidInputError, "The #{field} value is not valid. It must be an IPv4 or IPv6 address."
204
227
  end
205
- # rubocop:enable Style/RescueStandardError
206
228
 
207
229
  nil
208
230
  end
@@ -217,7 +239,9 @@ module Minfraud
217
239
  #
218
240
  # @return [nil]
219
241
  def validate_nonnegative_number(field, value)
220
- return if !value
242
+ return if value.nil?
243
+
244
+ validate_not_boolean(field, value)
221
245
 
222
246
  if !value.is_a? Numeric
223
247
  raise InvalidInputError, "The #{field} value is not valid. It must be numeric."
@@ -238,7 +262,9 @@ module Minfraud
238
262
  #
239
263
  # @return [nil]
240
264
  def validate_nonnegative_integer(field, value)
241
- return if !value
265
+ return if value.nil?
266
+
267
+ validate_not_boolean(field, value)
242
268
 
243
269
  if !value.is_a? Integer
244
270
  raise InvalidInputError, "The #{field} is not valid. It must be an integer."
@@ -258,9 +284,9 @@ module Minfraud
258
284
  #
259
285
  # @return [nil]
260
286
  def validate_email(field, value)
261
- return if !value
287
+ return if value.nil?
262
288
 
263
- if /.@./.match?(value)
289
+ if /.@./.match?(value.to_s)
264
290
  validate_string(field, 255, value)
265
291
  return
266
292
  end
@@ -277,15 +303,18 @@ module Minfraud
277
303
  #
278
304
  # @return [nil]
279
305
  def validate_rfc3339(field, value)
280
- return if !value
306
+ return if value.nil?
281
307
 
282
- # rubocop:disable Style/RescueStandardError
283
- begin
284
- DateTime.rfc3339(value)
285
- rescue
308
+ validate_not_boolean(field, value)
309
+
310
+ # The regex checks the format, time, and offset that the web service
311
+ # requires. valid_date? rejects dates that do not exist, such as
312
+ # February 30. The web service uses the Gregorian calendar for all
313
+ # years.
314
+ match = RFC3339_REGEX.match(value.to_s)
315
+ if !match || !Date.valid_date?(match[1].to_i, match[2].to_i, match[3].to_i, Date::GREGORIAN)
286
316
  raise InvalidInputError, "The #{field} value is not valid. It must be in the RFC 3339 date-time format."
287
317
  end
288
- # rubocop:enable Style/RescueStandardError
289
318
 
290
319
  nil
291
320
  end
@@ -299,9 +328,9 @@ module Minfraud
299
328
  #
300
329
  # @return [nil]
301
330
  def validate_boolean(field, value)
302
- return if !value
331
+ return if value.nil?
303
332
 
304
- if ![false, true].include? value
333
+ if !boolean?(value)
305
334
  raise InvalidInputError, "The #{field} value is not valid. It must be boolean."
306
335
  end
307
336
  end
@@ -315,13 +344,15 @@ module Minfraud
315
344
  #
316
345
  # @return [nil]
317
346
  def validate_uri(field, value)
318
- return if !value
347
+ return if value.nil?
348
+
349
+ validate_not_boolean(field, value)
319
350
 
320
351
  if value.to_s.length > 1_024
321
352
  raise InvalidInputError, "The #{field} value is not valid. It must not exceed 1024 characters."
322
353
  end
323
354
 
324
- # rubocop:disable Style/RescueStandardError
355
+ # rubocop:disable-next Style/RescueStandardError
325
356
  begin
326
357
  u = URI(value)
327
358
  if !u.scheme
@@ -330,8 +361,31 @@ module Minfraud
330
361
  rescue
331
362
  raise InvalidInputError, "The #{field} value is not valid. It must be an absolute URI."
332
363
  end
333
- # rubocop:enable Style/RescueStandardError
334
364
  end
365
+
366
+ # Validates that a value is not a boolean.
367
+ #
368
+ # @param field [String] The field name for error messages.
369
+ # @param value [Object] The value to validate.
370
+ #
371
+ # @raise [InvalidInputError] If the value is true or false.
372
+ #
373
+ # @return [nil]
374
+ def validate_not_boolean(field, value)
375
+ if boolean?(value)
376
+ raise InvalidInputError, "The #{field} value is not valid. It must not be a boolean."
377
+ end
378
+ end
379
+
380
+ # Returns true if the value is true or false.
381
+ #
382
+ # @param value [Object] The value to check.
383
+ #
384
+ # @return [Boolean]
385
+ def boolean?(value)
386
+ [true, false].include?(value)
387
+ end
388
+ module_function :boolean?
335
389
  # rubocop:enable Metrics/ModuleLength
336
390
  end
337
391
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Minfraud
4
4
  # The Gem version.
5
- VERSION = '2.10.0'
5
+ VERSION = '2.11.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minfraud
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kushnir.yb
@@ -56,14 +56,14 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '1.6'
59
+ version: '1.7'
60
60
  type: :runtime
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '1.6'
66
+ version: '1.7'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: simpleidn
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  - !ruby/object:Gem::Version
293
293
  version: '0'
294
294
  requirements: []
295
- rubygems_version: 4.0.16
295
+ rubygems_version: 4.0.20
296
296
  specification_version: 4
297
297
  summary: Ruby API for the minFraud Score, Insights, Factors, and Report Transactions
298
298
  services