minfraud 1.1.0 → 1.5.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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +12 -0
  3. data/.github/workflows/test.yml +33 -0
  4. data/.rubocop.yml +108 -0
  5. data/CHANGELOG.md +57 -0
  6. data/Gemfile +4 -2
  7. data/README.dev.md +1 -1
  8. data/README.md +170 -55
  9. data/Rakefile +9 -3
  10. data/bin/console +4 -3
  11. data/lib/maxmind/geoip2/model/city.rb +3 -3
  12. data/lib/maxmind/geoip2/model/country.rb +5 -5
  13. data/lib/maxmind/geoip2/record/traits.rb +13 -4
  14. data/lib/minfraud.rb +44 -6
  15. data/lib/minfraud/assessments.rb +113 -53
  16. data/lib/minfraud/components/account.rb +31 -9
  17. data/lib/minfraud/components/addressable.rb +73 -26
  18. data/lib/minfraud/components/base.rb +26 -14
  19. data/lib/minfraud/components/billing.rb +5 -0
  20. data/lib/minfraud/components/credit_card.rb +64 -20
  21. data/lib/minfraud/components/custom_inputs.rb +14 -3
  22. data/lib/minfraud/components/device.rb +45 -15
  23. data/lib/minfraud/components/email.rb +120 -9
  24. data/lib/minfraud/components/event.rb +60 -24
  25. data/lib/minfraud/components/order.rb +59 -22
  26. data/lib/minfraud/components/payment.rb +44 -9
  27. data/lib/minfraud/components/report/transaction.rb +50 -39
  28. data/lib/minfraud/components/shipping.rb +14 -5
  29. data/lib/minfraud/components/shopping_cart.rb +19 -12
  30. data/lib/minfraud/components/shopping_cart_item.rb +42 -13
  31. data/lib/minfraud/enum.rb +22 -8
  32. data/lib/minfraud/error_handler.rb +32 -25
  33. data/lib/minfraud/errors.rb +22 -2
  34. data/lib/minfraud/http_service.rb +23 -8
  35. data/lib/minfraud/http_service/request.rb +19 -18
  36. data/lib/minfraud/http_service/response.rb +19 -14
  37. data/lib/minfraud/model/address.rb +4 -4
  38. data/lib/minfraud/model/credit_card.rb +7 -7
  39. data/lib/minfraud/model/device.rb +2 -2
  40. data/lib/minfraud/model/email.rb +4 -4
  41. data/lib/minfraud/model/error.rb +1 -1
  42. data/lib/minfraud/model/insights.rb +5 -5
  43. data/lib/minfraud/model/ip_address.rb +20 -1
  44. data/lib/minfraud/model/ip_risk_reason.rb +48 -0
  45. data/lib/minfraud/model/issuer.rb +3 -3
  46. data/lib/minfraud/model/score.rb +6 -6
  47. data/lib/minfraud/model/shipping_address.rb +1 -1
  48. data/lib/minfraud/model/subscores.rb +38 -16
  49. data/lib/minfraud/model/warning.rb +2 -2
  50. data/lib/minfraud/report.rb +33 -13
  51. data/lib/minfraud/resolver.rb +25 -17
  52. data/lib/minfraud/validates.rb +187 -0
  53. data/lib/minfraud/version.rb +4 -1
  54. data/minfraud.gemspec +8 -2
  55. metadata +77 -10
  56. data/.travis.yml +0 -22
@@ -1,43 +1,79 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
5
+ # Event corresponds to the event object of a minFraud request.
6
+ #
7
+ # @see https://dev.maxmind.com/minfraud/#Event_(/event)
3
8
  class Event < Base
4
9
  include ::Minfraud::Enum
5
- # @attribute transaction_id
6
- # @return [String] Internal ID for the transaction. Used to locate a specific transaction in minFraud logs
10
+ include Minfraud::Validates
11
+
12
+ # Your internal ID for the transaction. MaxMind can use this to locate a
13
+ # specific transaction in logs, and it will also show up in email alerts
14
+ # and notifications from MaxMind to you. No specific format is required.
15
+ #
16
+ # @return [String, nil]
7
17
  attr_accessor :transaction_id
8
18
 
9
- # @attribute shop_id
10
- # @return [String] Internal ID for the shop, affiliate, or merchant this order is coming from
19
+ # Your internal ID for the shop, affiliate, or merchant this order is
20
+ # coming from. Required for minFraud users who are resellers, payment
21
+ # providers, gateways and affiliate networks. No specific format is
22
+ # required.
23
+ #
24
+ # @return [String, nil]
11
25
  attr_accessor :shop_id
12
26
 
13
- # @attribute time
14
- # @return [String] The date and time the event occurred. The string must be in the RFC 3339 date-time format.
15
- # If this field is not in the request, the current time will be used
27
+ # The date and time the event occurred. The string must be in the RFC
28
+ # 3339 date-time format, e.g., "2012-04-12T23:20:50.52Z". The time must
29
+ # be within the past 10 years. If this field is not in the request, the
30
+ # current time will be used.
31
+ #
32
+ # @see https://tools.ietf.org/html/rfc3339
33
+ #
34
+ # @return [String, nil]
16
35
  attr_accessor :time
17
36
 
18
- # @attribute type
19
- # @return [String] The type of event being scored
37
+ # The type of event being scored. This must be one of
38
+ # +:account_creation+, +:account_login+, +:email_change+,
39
+ # +:password_reset+, +:payout_change+, +:purchase+,
40
+ # +:recurring_purchase+, +:referral+, or +:survey+.
41
+ #
42
+ # @!attribute type
43
+ #
44
+ # @return [Symbol, nil]
20
45
  enum_accessor :type,
21
- [
22
- :account_creation,
23
- :account_login,
24
- :email_change,
25
- :password_reset,
26
- :payout_change,
27
- :purchase,
28
- :recurring_purchase,
29
- :referral,
30
- :survey,
31
- ]
32
-
33
- # Creates Minfraud::Components::Event instance
34
- # @param [Hash] params hash of parameters
35
- # @return [Minfraud::Components::Event] an Event instance
46
+ [
47
+ :account_creation,
48
+ :account_login,
49
+ :email_change,
50
+ :password_reset,
51
+ :payout_change,
52
+ :purchase,
53
+ :recurring_purchase,
54
+ :referral,
55
+ :survey,
56
+ ]
57
+
58
+ # @param params [Hash] Hash of parameters. Each key/value should
59
+ # correspond to one of the available attributes.
36
60
  def initialize(params = {})
37
61
  @transaction_id = params[:transaction_id]
38
62
  @shop_id = params[:shop_id]
39
63
  @time = params[:time]
40
64
  self.type = params[:type]
65
+
66
+ validate
67
+ end
68
+
69
+ private
70
+
71
+ def validate
72
+ return if !Minfraud.enable_validation
73
+
74
+ validate_string('transaction_id', 255, @transaction_id)
75
+ validate_string('shop_id', 255, @shop_id)
76
+ validate_rfc3339('time', @time)
41
77
  end
42
78
  end
43
79
  end
@@ -1,51 +1,88 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
5
+ # Order corresponds to the order object of a minFraud request.
6
+ #
7
+ # @see https://dev.maxmind.com/minfraud/#Order_(/order)
3
8
  class Order < Base
4
- # @attribute amount
5
- # @return [Decimal] The total order amount for the transaction
9
+ include Minfraud::Validates
10
+
11
+ # The total order amount for the transaction before taxes and discounts.
12
+ # The value must be at least 0 and at most 1e14 - 1.
13
+ #
14
+ # @return [Float, nil]
6
15
  attr_accessor :amount
7
16
 
8
- # @attribute currency
9
- # @return [String] The ISO 4217 currency code for the currency used in the transaction
17
+ # The ISO 4217 currency code for the currency used in the transaction.
18
+ #
19
+ # @see https://en.wikipedia.org/wiki/ISO_4217
20
+ #
21
+ # @return [String, nil]
10
22
  attr_accessor :currency
11
23
 
12
- # @attribute discount_code
13
- # @return [String] The discount code applied to the transaction. If multiple discount codes are used,
14
- # please separate them with a comma.
24
+ # The discount code applied to the transaction. If multiple discount
25
+ # codes are used, please separate them with a comma.
26
+ #
27
+ # @return [String, nil]
15
28
  attr_accessor :discount_code
16
29
 
17
- # @attribute affiliate_id
18
- # @return [String] The ID of the affiliate where the order is coming from
30
+ # The ID of the affiliate where the order is coming from. No specific
31
+ # format is required.
32
+ #
33
+ # @return [String, nil]
19
34
  attr_accessor :affiliate_id
20
35
 
21
- # @attribute subaffiliate_id
22
- # @return [String] The ID of the sub-affiliate where the order is coming from
36
+ # The ID of the sub-affiliate where the order is coming from. No specific
37
+ # format is required.
38
+ #
39
+ # @return [String, nil]
23
40
  attr_accessor :subaffiliate_id
24
41
 
25
- # @attribute :referrer_uri
26
- # @return [String] The URI of the referring site for this order
42
+ # The URI of the referring site for this order. Needs to be absolute and
43
+ # have a URI scheme such as +https://+.
44
+ #
45
+ # @return [String, nil]
27
46
  attr_accessor :referrer_uri
28
47
 
29
- # @attribute :is_gift
30
- # @return [Boolean] Whether order was marked as a gift by the purchaser
48
+ # Whether order was marked as a gift by the purchaser.
49
+ #
50
+ # @return [Boolean, nil]
31
51
  attr_accessor :is_gift
32
52
 
33
- # @attribute :has_gift_message
34
- # @return [Boolean] Whether the purchaser included a gift message
53
+ # Whether the purchaser included a gift message.
54
+ #
55
+ # @return [Boolean, nil]
35
56
  attr_accessor :has_gift_message
36
57
 
37
- # Creates Minfraud::Components::Order instance
38
- # @param [Hash] params hash of parameters
39
- # @return [Minfraud::Components::Order] an Order instance
40
- def initialize (params = {})
58
+ # @param params [Hash] Hash of parameters. Each key/value should
59
+ # correspond to one of the available attributes.
60
+ def initialize(params = {})
41
61
  @amount = params[:amount]
42
62
  @has_gift_message = params[:has_gift_message]
43
63
  @affiliate_id = params[:affiliate_id]
44
64
  @subaffiliate_id = params[:subaffiliate_id]
45
65
  @currency = params[:currency]
46
- @discount_code = params[:discount_cide]
66
+ @discount_code = params[:discount_code]
47
67
  @referrer_uri = params[:referrer_uri]
48
68
  @is_gift = params[:is_gift]
69
+
70
+ validate
71
+ end
72
+
73
+ private
74
+
75
+ def validate
76
+ return if !Minfraud.enable_validation
77
+
78
+ validate_nonnegative_number('amount', @amount)
79
+ validate_boolean('has_gift_message', @has_gift_message)
80
+ validate_string('affiliate_id', 255, @affiliate_id)
81
+ validate_string('subaffiliate_id', 255, @subaffiliate_id)
82
+ validate_regex('currency', /\A[A-Z]{3}\z/, @currency)
83
+ validate_string('discount_code', 255, @discount_code)
84
+ validate_uri('referrer_uri', @referrer_uri)
85
+ validate_boolean('is_gift', @is_gift)
49
86
  end
50
87
  end
51
88
  end
@@ -1,9 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
5
+ # Payment corresponds to the payment object of a minFraud request.
6
+ #
7
+ # @see https://dev.maxmind.com/minfraud/#Payment_(/payment)
3
8
  class Payment < Base
4
9
  include ::Minfraud::Enum
5
- # @attribute processor
6
- # @return [String] The payment processor used for the transaction
10
+ include Minfraud::Validates
11
+
12
+ # The payment processor used for the transaction. The value is one
13
+ # listed as a valid value, as a symbol.
14
+ #
15
+ # @!attribute processor
16
+ #
17
+ # @return [Symbol, nil]
7
18
  enum_accessor :processor, [
8
19
  :adyen,
9
20
  :affirm,
@@ -11,6 +22,8 @@ module Minfraud
11
22
  :altapay,
12
23
  :amazon_payments,
13
24
  :american_express_payment_gateway,
25
+ :apple_pay,
26
+ :aps_payments,
14
27
  :authorizenet,
15
28
  :balanced,
16
29
  :beanstream,
@@ -19,6 +32,7 @@ module Minfraud
19
32
  :bpoint,
20
33
  :braintree,
21
34
  :cardpay,
35
+ :cashfree,
22
36
  :ccavenue,
23
37
  :ccnow,
24
38
  :cetelem,
@@ -50,6 +64,7 @@ module Minfraud
50
64
  :epx,
51
65
  :eway,
52
66
  :exact,
67
+ :first_atlantic_commerce,
53
68
  :first_data,
54
69
  :g2a_pay,
55
70
  :global_payments,
@@ -62,6 +77,7 @@ module Minfraud
62
77
  :intuit_quickbooks_payments,
63
78
  :iugu,
64
79
  :klarna,
80
+ :komoju,
65
81
  :lemon_way,
66
82
  :mastercard_payment_gateway,
67
83
  :mercadopago,
@@ -89,6 +105,7 @@ module Minfraud
89
105
  :payplus,
90
106
  :paysafecard,
91
107
  :paystation,
108
+ :paytm,
92
109
  :paytrace,
93
110
  :paytrail,
94
111
  :payture,
@@ -103,6 +120,7 @@ module Minfraud
103
120
  :qiwi,
104
121
  :quickpay,
105
122
  :raberil,
123
+ :razorpay,
106
124
  :rede,
107
125
  :redpagos,
108
126
  :rewardspay,
@@ -116,9 +134,11 @@ module Minfraud
116
134
  :sps_decidir,
117
135
  :stripe,
118
136
  :synapsefi,
137
+ :systempay,
119
138
  :telerecargas,
120
139
  :towah,
121
140
  :transact_pro,
141
+ :tsys,
122
142
  :usa_epay,
123
143
  :vantiv,
124
144
  :verepay,
@@ -131,21 +151,36 @@ module Minfraud
131
151
  :worldpay
132
152
  ]
133
153
 
134
- # @attribute was_authorized
135
- # @return [Boolean] The authorization outcome from the payment processor. If the transaction has not yet been approved or denied, do not include this field
154
+ # The authorization outcome from the payment processor. If the
155
+ # transaction has not yet been approved or denied, do not include this
156
+ # field.
157
+ #
158
+ # @return [Boolean, nil]
136
159
  attr_accessor :was_authorized
137
160
 
138
- # @attribute decline_code
139
- # @return [String] The decline code as provided by your payment processor. If the transaction was not declined, do not include this field
161
+ # The decline code as provided by your payment processor. If the
162
+ # transaction was not declined, do not include this field.
163
+ #
164
+ # @return [String, nil]
140
165
  attr_accessor :decline_code
141
166
 
142
- # Creates Minfraud::Components::Payment instance
143
- # @param [Hash] params hash of parameters
144
- # @return [Minfraud::Components::Payment] Payment instance
167
+ # @param params [Hash] Hash of parameters. Each key/value should
168
+ # correspond to one of the available attributes.
145
169
  def initialize(params = {})
146
170
  @was_authorized = params[:was_authorized]
147
171
  @decline_code = params[:decline_code]
148
172
  self.processor = params[:processor]
173
+
174
+ validate
175
+ end
176
+
177
+ private
178
+
179
+ def validate
180
+ return if !Minfraud.enable_validation
181
+
182
+ validate_boolean('was_authorized', @was_authorized)
183
+ validate_string('decline_code', 255, @decline_code)
149
184
  end
150
185
  end
151
186
  end
@@ -3,65 +3,76 @@
3
3
  module Minfraud
4
4
  module Components
5
5
  module Report
6
- # Contains all of the fields which are used in the report transaction API
6
+ # Contains the fields used in the Report Transaction API.
7
+ #
8
+ # @see https://dev.maxmind.com/minfraud/report-transaction/
7
9
  class Transaction < Base
8
10
  include ::Minfraud::Enum
9
11
 
10
- # @!attribute ip_address
11
- # @return [String, nil] The IP address of the customer placing the order. This
12
- # should be passed as a string like "44.55.66.77" or "2001:db8::2:1".
12
+ # The IP address of the customer placing the order. This should be
13
+ # passed as a string like "152.216.7.110".
14
+ #
15
+ # @return [String, nil]
13
16
  attr_accessor :ip_address
14
17
 
18
+ # A symbol indicating the likelihood that a transaction may be
19
+ # fraudulent.
20
+ #
21
+ # This may be one of +:chargeback+, +:not_fraud+, +:spam_or_abuse+, or
22
+ # +:suspected_fraud+.
23
+ #
15
24
  # @!attribute tag
16
- # This may be one of +:chargeback+, +:not_fraud+, +:spam_or_abuse+ or +:suspected_fraud+
17
- # @return [Symbol, nil] A symbol indicating the likelihood that a transaction
18
- # may be fraudulent.
25
+ #
26
+ # @return [Symbol, nil]
19
27
  enum_accessor :tag, [:chargeback, :not_fraud, :spam_or_abuse, :suspected_fraud]
20
28
 
21
- # @attribute chargeback_code
22
- # @return [String, nil] A string which is provided by your payment processor
23
- # indicating the reason for the chargeback.
29
+ # A string which is provided by your payment processor indicating the
30
+ # reason for the chargeback.
31
+ #
32
+ # @return [String, nil]
24
33
  attr_accessor :chargeback_code
25
34
 
26
- # @attribute maxmind_id
27
- # @return [String, nil] A unique eight character string identifying a minFraud
28
- # Standard or Premium request. These IDs are returned in the maxmindID
29
- # field of a response for a successful minFraud request. This field is
30
- # not required, but you are encouraged to provide it, if possible.
35
+ # A unique eight character string identifying a minFraud Standard or
36
+ # 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.
39
+ #
40
+ # @return [String, nil]
31
41
  attr_accessor :maxmind_id
32
42
 
33
- # @attribute minfraud_id
34
- # @return [String, nil] A UUID that identifies a minFraud Score, minFraud
35
- # Insights, or minFraud Factors request. This ID is returned at /id in
36
- # the response. This field is not required, but you are encouraged to
37
- # provide it if the request was made to one of these services.
43
+ # A UUID that identifies a minFraud Score, minFraud Insights, or
44
+ # 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.
47
+ #
48
+ # @return [String, nil]
38
49
  attr_accessor :minfraud_id
39
50
 
40
- # @attribute notes
41
- # @return [String, nil] Your notes on the fraud tag associated with the
42
- # transaction. We manually review many reported transactions to improve
43
- # our scoring for you so any additional details to help us understand
44
- # context are helpful.
51
+ # Your notes on the fraud tag associated with the transaction. We
52
+ # manually review many reported transactions to improve our scoring for
53
+ # you so any additional details to help us understand context are
54
+ # helpful.
55
+ #
56
+ # @return [String, nil]
45
57
  attr_accessor :notes
46
58
 
47
- # @attribute transaction_id
48
- # @return [String, nil] The transaction ID you originally passed to minFraud.
49
- # This field is not required, but you are encouraged to provide it or
50
- # the transaction's maxmind_id or minfraud_id
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.
62
+ #
63
+ # @return [String, nil]
51
64
  attr_accessor :transaction_id
52
65
 
53
- # Creates Minfraud::Components::Report::Transaction instance
54
- # @param [Hash] params hash of parameters
55
- # @return [Minfraud::Components::Report::Transaction] a Report::Transaction
56
- # instance
66
+ # @param params [Hash] Hash of parameters. Each key/value should
67
+ # correspond to one of the available attributes.
57
68
  def initialize(params = {})
58
- @ip_address = params[:ip_address]
69
+ @ip_address = params[:ip_address]
59
70
  @chargeback_code = params[:chargeback_code]
60
- @maxmind_id = params[:maxmind_id]
61
- @minfraud_id = params[:minfraud_id]
62
- @notes = params[:notes]
63
- @transaction_id = params[:transaction_id]
64
- self.tag = params[:tag]
71
+ @maxmind_id = params[:maxmind_id]
72
+ @minfraud_id = params[:minfraud_id]
73
+ @notes = params[:notes]
74
+ @transaction_id = params[:transaction_id]
75
+ self.tag = params[:tag]
65
76
  end
66
77
  end
67
78
  end