@@ -8,9 +8,13 @@ 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
13- # passed as a string like "152.216.7.110".
14+ # passed as a string like "152.216.7.110". This field is not required
15+ # if you provide at least one of the transaction's minfraud_id,
16+ # maxmind_id, or transaction_id. You are encouraged to provide it, if
17+ # possible.
1418 #
1519 # @return [String, nil]
1620 attr_accessor :ip_address
@@ -34,16 +38,19 @@ class Transaction < Base
3438
3539 # A unique eight character string identifying a minFraud Standard or
3640 # Premium request. These IDs are returned in the maxmindID field of a
37- # response for a successful minFraud request. This field is not
38- # required, but you are encouraged to provide it, if possible.
41+ # response for a successful minFraud request. This field is not required
42+ # if you provide at least one of the transaction's ip_address,
43+ # minfraud_id, or transaction_id. You are encouraged to provide it, if
44+ # possible.
3945 #
4046 # @return [String, nil]
4147 attr_accessor :maxmind_id
4248
4349 # A UUID that identifies a minFraud Score, minFraud Insights, or
4450 # minFraud Factors request. This ID is returned at /id in the response.
45- # This field is not required, but you are encouraged to provide it if
46- # the request was made to one of these services.
51+ # This field is not required if you provide at least one of the
52+ # transaction's ip_address, maxmind_id, or transaction_id. You are
53+ # encouraged to provide it, if possible.
4754 #
4855 # @return [String, nil]
4956 attr_accessor :minfraud_id
@@ -56,9 +63,10 @@ class Transaction < Base
5663 # @return [String, nil]
5764 attr_accessor :notes
5865
59- # The transaction ID you originally passed to minFraud. This field is
60- # not required, but you are encouraged to provide it or the
61- # transaction's maxmind_id or minfraud_id.
66+ # The transaction ID you originally passed to minFraud. This field
67+ # is not required if you provide at least one of the transaction's
68+ # ip_address, maxmind_id, or minfraud_id. You are encouraged to
69+ # provide it, if possible.
6270 #
6371 # @return [String, nil]
6472 attr_accessor :transaction_id
@@ -73,6 +81,30 @@ def initialize(params = {})
7381 @notes = params [ :notes ]
7482 @transaction_id = params [ :transaction_id ]
7583 self . tag = params [ :tag ]
84+
85+ validate
86+ end
87+
88+ private
89+
90+ def validate
91+ return if !Minfraud . enable_validation
92+
93+ validate_ip ( 'ip_address' , @ip_address )
94+ validate_string ( 'maxmind_id' , 8 , @maxmind_id )
95+ validate_uuid ( 'minfraud_id' , @minfraud_id )
96+
97+ if ip_address . nil? &&
98+ ( minfraud_id . nil? || empty_uuid ( minfraud_id ) ) &&
99+ ( maxmind_id . nil? || maxmind_id . empty? ) &&
100+ ( transaction_id . nil? || transaction_id . empty? )
101+ raise ArgumentError , 'At least one of the following is required: ip_address, minfraud_id, maxmind_id, transaction_id.'
102+ end
103+ end
104+
105+ def empty_uuid ( value )
106+ stripped_value = value . to_s . gsub ( '-' , '' )
107+ stripped_value == '0' * 32
76108 end
77109 end
78110 end
0 commit comments