Skip to content

Commit 9231a16

Browse files
committed
Validate individual transaction report parameters
1 parent 678eea7 commit 9231a16

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
`ip_address` parameter optional. Now the `tag` and at least one of the
77
following parameters must be supplied: `ip_address`, `maxmind_id`,
88
`minfraud_id`, `transaction_id`.
9+
* Updated the validation for the Report Transactions API to check that
10+
`ip_address`, `maxmind_id`, and `minfraud_id` contain valid values.
911

1012
## v2.5.0 (2024-04-16)
1113

lib/minfraud/components/report/transaction.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Report
88
# @see https://dev.maxmind.com/minfraud/report-a-transaction?lang=en
99
class Transaction < Base
1010
include ::Minfraud::Enum
11+
include ::Minfraud::Validates
1112

1213
# The IP address of the customer placing the order. This should be
1314
# passed as a string like "152.216.7.110". This field is not required
@@ -89,6 +90,10 @@ def initialize(params = {})
8990
def validate
9091
return if !Minfraud.enable_validation
9192

93+
validate_ip('ip_address', @ip_address)
94+
validate_string('maxmind_id', 8, @maxmind_id)
95+
validate_uuid('minfraud_id', @minfraud_id)
96+
9297
if ip_address.nil? &&
9398
minfraud_id.nil? &&
9499
(maxmind_id.nil? || maxmind_id.empty?) &&

lib/minfraud/validates.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ def validate_md5(field, value)
2424
end
2525
end
2626

27+
def validate_uuid(field, value)
28+
return if !value
29+
30+
stripped_value = value.to_s.gsub('-', '')
31+
32+
# Define a regex pattern for a valid UUID without dashes
33+
uuid_regex = /\A[0-9a-f]{32}\z/i
34+
35+
unless uuid_regex.match(stripped_value)
36+
raise InvalidInputError, "The #{field} value is not valid. It must be a UUID string."
37+
end
38+
end
39+
2740
def validate_subdivision_code(field, value)
2841
return if !value
2942

0 commit comments

Comments
 (0)