minfraud 1.0.1 → 1.2.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 (74) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +46 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +127 -0
  5. data/.travis.yml +20 -3
  6. data/CHANGELOG.md +56 -0
  7. data/CODE_OF_CONDUCT.md +4 -4
  8. data/Gemfile +11 -2
  9. data/LICENSE.txt +2 -1
  10. data/README.dev.md +4 -0
  11. data/README.md +107 -36
  12. data/Rakefile +18 -3
  13. data/bin/console +4 -3
  14. data/lib/maxmind/geoip2/model/city.rb +99 -0
  15. data/lib/maxmind/geoip2/model/country.rb +94 -0
  16. data/lib/maxmind/geoip2/model/insights.rb +38 -0
  17. data/lib/maxmind/geoip2/record/abstract.rb +46 -0
  18. data/lib/maxmind/geoip2/record/city.rb +62 -0
  19. data/lib/maxmind/geoip2/record/continent.rb +61 -0
  20. data/lib/maxmind/geoip2/record/country.rb +78 -0
  21. data/lib/maxmind/geoip2/record/location.rb +97 -0
  22. data/lib/maxmind/geoip2/record/maxmind.rb +41 -0
  23. data/lib/maxmind/geoip2/record/place.rb +52 -0
  24. data/lib/maxmind/geoip2/record/postal.rb +54 -0
  25. data/lib/maxmind/geoip2/record/represented_country.rb +47 -0
  26. data/lib/maxmind/geoip2/record/subdivision.rb +72 -0
  27. data/lib/maxmind/geoip2/record/traits.rb +224 -0
  28. data/lib/minfraud.rb +33 -8
  29. data/lib/minfraud/assessments.rb +25 -10
  30. data/lib/minfraud/components/account.rb +3 -1
  31. data/lib/minfraud/components/addressable.rb +11 -9
  32. data/lib/minfraud/components/base.rb +29 -5
  33. data/lib/minfraud/components/billing.rb +2 -0
  34. data/lib/minfraud/components/credit_card.rb +8 -1
  35. data/lib/minfraud/components/custom_inputs.rb +16 -0
  36. data/lib/minfraud/components/device.rb +13 -0
  37. data/lib/minfraud/components/email.rb +2 -0
  38. data/lib/minfraud/components/event.rb +15 -8
  39. data/lib/minfraud/components/order.rb +4 -1
  40. data/lib/minfraud/components/payment.rb +138 -14
  41. data/lib/minfraud/components/report/transaction.rb +69 -0
  42. data/lib/minfraud/components/shipping.rb +2 -4
  43. data/lib/minfraud/components/shopping_cart.rb +4 -1
  44. data/lib/minfraud/components/shopping_cart_item.rb +2 -2
  45. data/lib/minfraud/enum.rb +7 -4
  46. data/lib/minfraud/error_handler.rb +29 -9
  47. data/lib/minfraud/errors.rb +2 -0
  48. data/lib/minfraud/http_service.rb +13 -4
  49. data/lib/minfraud/http_service/request.rb +4 -1
  50. data/lib/minfraud/http_service/response.rb +40 -6
  51. data/lib/minfraud/model/abstract.rb +20 -0
  52. data/lib/minfraud/model/address.rb +52 -0
  53. data/lib/minfraud/model/billing_address.rb +11 -0
  54. data/lib/minfraud/model/credit_card.rb +75 -0
  55. data/lib/minfraud/model/device.rb +54 -0
  56. data/lib/minfraud/model/disposition.rb +35 -0
  57. data/lib/minfraud/model/email.rb +54 -0
  58. data/lib/minfraud/model/email_domain.rb +24 -0
  59. data/lib/minfraud/model/error.rb +28 -0
  60. data/lib/minfraud/model/factors.rb +24 -0
  61. data/lib/minfraud/model/geoip2_location.rb +25 -0
  62. data/lib/minfraud/model/insights.rb +68 -0
  63. data/lib/minfraud/model/ip_address.rb +82 -0
  64. data/lib/minfraud/model/issuer.rb +49 -0
  65. data/lib/minfraud/model/score.rb +76 -0
  66. data/lib/minfraud/model/score_ip_address.rb +23 -0
  67. data/lib/minfraud/model/shipping_address.rb +30 -0
  68. data/lib/minfraud/model/subscores.rb +175 -0
  69. data/lib/minfraud/model/warning.rb +63 -0
  70. data/lib/minfraud/report.rb +40 -0
  71. data/lib/minfraud/resolver.rb +16 -13
  72. data/lib/minfraud/version.rb +3 -1
  73. data/minfraud.gemspec +21 -15
  74. metadata +84 -19
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Billing < Addressable; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class CreditCard < Base
@@ -18,10 +20,14 @@ module Minfraud
18
20
  # @return [String] The phone country code for the issuing bank as provided by the end user
19
21
  attr_accessor :bank_phone_country_code
20
22
 
21
- # @attribute phone_phone_number
23
+ # @attribute bank_phone_number
22
24
  # @return [String] The phone number, without the country code, for the issuing bank as provided by the end user
23
25
  attr_accessor :bank_phone_number
24
26
 
27
+ # @attribute token
28
+ # @return [String] A token uniquely identifying the card. The token should consist of non-space printable ASCII characters.
29
+ attr_accessor :token
30
+
25
31
  # @attribute avs_result
26
32
  # @return [String] The address verification system (AVS) check result, as returned to you by the credit card processor
27
33
  attr_accessor :avs_result
@@ -41,6 +47,7 @@ module Minfraud
41
47
  @bank_phone_number = params[:bank_phone_number]
42
48
  @avs_result = params[:avs_result]
43
49
  @cvv_result = params[:cvv_result]
50
+ @token = params[:token]
44
51
  end
45
52
  end
46
53
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minfraud
4
+ module Components
5
+ class CustomInputs < Base
6
+ # Creates Minfraud::Components::CustomInputs instance
7
+ # @param [Hash] params hash with keys that match your created custom input keys
8
+ # @return [Minfraud::Components::CustomInputs] a CustomInputs instance
9
+ def initialize(params = {})
10
+ params.each do |name, value|
11
+ instance_variable_set("@#{name}", value)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Device < Base
@@ -14,6 +16,15 @@ module Minfraud
14
16
  # @return [String] The HTTP "Accept-Language" header of the browser used in the transaction
15
17
  attr_accessor :accept_language
16
18
 
19
+ # @attribute :session_age
20
+ # @return [Decimal] The number of seconds between the creation of the user's session and the time of the transaction.
21
+ # Note that session_age is not the duration of the current visit, but the time since the start of the first visit.
22
+ attr_accessor :session_age
23
+
24
+ # @attribute :session_id
25
+ # @return [String] An ID that uniquely identifies a visitor's session on the site.
26
+ attr_accessor :session_id
27
+
17
28
  # Creates Minfraud::Components::Device instance
18
29
  # @param [Hash] params hash of parameters
19
30
  # @return [Minfraud::Components::Device] a Device instance
@@ -21,6 +32,8 @@ module Minfraud
21
32
  @ip_address = params[:ip_address]
22
33
  @user_agent = params[:user_agent]
23
34
  @accept_language = params[:accept_language]
35
+ @session_age = params[:session_age]
36
+ @session_id = params[:session_id]
24
37
  end
25
38
  end
26
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Email < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Event < Base
@@ -16,14 +18,19 @@ module Minfraud
16
18
  attr_accessor :time
17
19
 
18
20
  # @attribute type
19
- # @return [String] The type of event being scored. The valid types are:
20
- # => account_creation
21
- # => account_login
22
- # => purchase
23
- # => recurring_purchase
24
- # => referral
25
- # => survey
26
- enum_accessor :type, [:account_creation, :account_login, :purchase, :recurring_purchase, :referral, :survey]
21
+ # @return [String] The type of event being scored
22
+ enum_accessor :type,
23
+ [
24
+ :account_creation,
25
+ :account_login,
26
+ :email_change,
27
+ :password_reset,
28
+ :payout_change,
29
+ :purchase,
30
+ :recurring_purchase,
31
+ :referral,
32
+ :survey,
33
+ ]
27
34
 
28
35
  # Creates Minfraud::Components::Event instance
29
36
  # @param [Hash] params hash of parameters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Order < Base
@@ -37,7 +39,8 @@ module Minfraud
37
39
  # Creates Minfraud::Components::Order instance
38
40
  # @param [Hash] params hash of parameters
39
41
  # @return [Minfraud::Components::Order] an Order instance
40
- def initialize (params = {})
42
+ def initialize(params = {})
43
+ @amount = params[:amount]
41
44
  @has_gift_message = params[:has_gift_message]
42
45
  @affiliate_id = params[:affiliate_id]
43
46
  @subaffiliate_id = params[:subaffiliate_id]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Payment < Base
@@ -5,26 +7,148 @@ module Minfraud
5
7
  # @attribute processor
6
8
  # @return [String] The payment processor used for the transaction
7
9
  enum_accessor :processor, [
8
- :adyen, :altapay, :amazon_payments, :authorizenet, :balanced, :beanstream,
9
- :bluepay, :braintree, :ccnow, :chase_paymentech, :cielo, :collector, :compropago,
10
- :concept_payments, :conekta, :cuentadigital, :dalpay, :dibs, :digital_river, :ecomm365,
11
- :elavon, :epay, :eprocessing_network, :eway, :first_data, :global_payments, :ingenico,
12
- :internetsecure, :intuit_quickbooks_payments, :iugu, :mastercard_payment_gateway,
13
- :mercadopago, :merchant_esolutions, :mirjeh, :mollie, :moneris_solutions, :nmi,
14
- :openpaymx, :optimal_payments, :orangepay, :other, :pacnet_services, :payfast,
15
- :paygate, :payone, :paypal, :payplus, :paystation, :paytrace, :paytrail, :payture,
16
- :payu, :payulatam, :pinpayments, :princeton_payment_solutions, :psigate, :qiwi,
17
- :quickpay, :raberil, :rede, :redpagos, :rewardspay, :sagepay, :simplify_commerce,
18
- :skrill, :smartcoin, :sps_decidir, :stripe, :telerecargas, :towah, :usa_epay,
19
- :verepay, :vindicia, :virtual_card_services, :vme, :worldpay
10
+ :adyen,
11
+ :affirm,
12
+ :afterpay,
13
+ :altapay,
14
+ :amazon_payments,
15
+ :american_express_payment_gateway,
16
+ :authorizenet,
17
+ :balanced,
18
+ :beanstream,
19
+ :bluepay,
20
+ :bluesnap,
21
+ :bpoint,
22
+ :braintree,
23
+ :cardpay,
24
+ :cashfree,
25
+ :ccavenue,
26
+ :ccnow,
27
+ :cetelem,
28
+ :chase_paymentech,
29
+ :checkout_com,
30
+ :cielo,
31
+ :collector,
32
+ :commdoo,
33
+ :compropago,
34
+ :concept_payments,
35
+ :conekta,
36
+ :ct_payments,
37
+ :cuentadigital,
38
+ :curopayments,
39
+ :cybersource,
40
+ :dalenys,
41
+ :dalpay,
42
+ :datacash,
43
+ :dibs,
44
+ :digital_river,
45
+ :dotpay,
46
+ :ebs,
47
+ :ecomm365,
48
+ :ecommpay,
49
+ :elavon,
50
+ :emerchantpay,
51
+ :epay,
52
+ :eprocessing_network,
53
+ :epx,
54
+ :eway,
55
+ :exact,
56
+ :first_atlantic_commerce,
57
+ :first_data,
58
+ :g2a_pay,
59
+ :global_payments,
60
+ :gocardless,
61
+ :heartland,
62
+ :hipay,
63
+ :ingenico,
64
+ :interac,
65
+ :internetsecure,
66
+ :intuit_quickbooks_payments,
67
+ :iugu,
68
+ :klarna,
69
+ :komoju,
70
+ :lemon_way,
71
+ :mastercard_payment_gateway,
72
+ :mercadopago,
73
+ :mercanet,
74
+ :merchant_esolutions,
75
+ :mirjeh,
76
+ :mollie,
77
+ :moneris_solutions,
78
+ :nmi,
79
+ :oceanpayment,
80
+ :oney,
81
+ :openpaymx,
82
+ :optimal_payments,
83
+ :orangepay,
84
+ :other,
85
+ :pacnet_services,
86
+ :payeezy,
87
+ :payfast,
88
+ :paygate,
89
+ :paylike,
90
+ :payment_express,
91
+ :paymentwall,
92
+ :payone,
93
+ :paypal,
94
+ :payplus,
95
+ :paysafecard,
96
+ :paystation,
97
+ :paytm,
98
+ :paytrace,
99
+ :paytrail,
100
+ :payture,
101
+ :payu,
102
+ :payulatam,
103
+ :payway,
104
+ :payza,
105
+ :pinpayments,
106
+ :posconnect,
107
+ :princeton_payment_solutions,
108
+ :psigate,
109
+ :qiwi,
110
+ :quickpay,
111
+ :raberil,
112
+ :razorpay,
113
+ :rede,
114
+ :redpagos,
115
+ :rewardspay,
116
+ :sagepay,
117
+ :securetrading,
118
+ :simplify_commerce,
119
+ :skrill,
120
+ :smartcoin,
121
+ :smartdebit,
122
+ :solidtrust_pay,
123
+ :sps_decidir,
124
+ :stripe,
125
+ :synapsefi,
126
+ :systempay,
127
+ :telerecargas,
128
+ :towah,
129
+ :transact_pro,
130
+ :usa_epay,
131
+ :vantiv,
132
+ :verepay,
133
+ :vericheck,
134
+ :vindicia,
135
+ :virtual_card_services,
136
+ :vme,
137
+ :vpos,
138
+ :wirecard,
139
+ :worldpay
20
140
  ]
21
141
 
22
142
  # @attribute was_authorized
23
- # @return [Boolean] The authorization outcome from the payment processor. If the transaction has not yet been approved or denied, do not include this field
143
+ # @return [Boolean] The authorization outcome from the payment processor.
144
+ # If the transaction has not yet been approved or denied, do not include
145
+ # this field
24
146
  attr_accessor :was_authorized
25
147
 
26
148
  # @attribute decline_code
27
- # @return [String] The decline code as provided by your payment processor. If the transaction was not declined, do not include this field
149
+ # @return [String] The decline code as provided by your payment
150
+ # processor. If the transaction was not declined, do not include this
151
+ # field
28
152
  attr_accessor :decline_code
29
153
 
30
154
  # Creates Minfraud::Components::Payment instance
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minfraud
4
+ module Components
5
+ module Report
6
+ # Contains all of the fields which are used in the report transaction API
7
+ class Transaction < Base
8
+ include ::Minfraud::Enum
9
+
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".
13
+ attr_accessor :ip_address
14
+
15
+ # @!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.
19
+ enum_accessor :tag, [:chargeback, :not_fraud, :spam_or_abuse, :suspected_fraud]
20
+
21
+ # @attribute chargeback_code
22
+ # @return [String, nil] A string which is provided by your payment processor
23
+ # indicating the reason for the chargeback.
24
+ attr_accessor :chargeback_code
25
+
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.
31
+ attr_accessor :maxmind_id
32
+
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.
38
+ attr_accessor :minfraud_id
39
+
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.
45
+ attr_accessor :notes
46
+
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
51
+ attr_accessor :transaction_id
52
+
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
57
+ def initialize(params = {})
58
+ @ip_address = params[:ip_address]
59
+ @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]
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,13 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class Shipping < Addressable
4
6
  include ::Minfraud::Enum
5
7
  # @attribute delivery_speed
6
8
  # @return [String] The shipping delivery speed for the order. The valid values are:
7
- # => same_day
8
- # => overnight
9
- # => expedited
10
- # => standard
11
9
  enum_accessor :delivery_speed, [:same_day, :overnight, :expedited, :standard]
12
10
 
13
11
  # Creates Minfraud::Components::Shipping instance
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class ShoppingCart < Base
@@ -5,6 +7,7 @@ module Minfraud
5
7
  # @return [Array] An array of Minfraud::Components::ShoppingCartItem instances
6
8
 
7
9
  attr_accessor :items
10
+
8
11
  # Creates Minfraud::Components::ShoppingCart instance
9
12
  # @param [Hash] params hash of parameters
10
13
  # @return [Minfraud::Components::ShoppingCart] ShoppingCart instance
@@ -13,7 +16,7 @@ module Minfraud
13
16
  end
14
17
 
15
18
  # @return [Array] a JSON representation of Minfraud::Components::ShoppingCart items
16
- def to_json
19
+ def to_json(*_args)
17
20
  @items.map(&:to_json)
18
21
  end
19
22
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
5
  class ShoppingCartItem < Base
@@ -29,5 +31,3 @@ module Minfraud
29
31
  end
30
32
  end
31
33
  end
32
-
33
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Enum
3
5
  def self.included(base)
@@ -21,11 +23,12 @@ module Minfraud
21
23
  define_method("#{attribute}_values") { mapping[attribute] }
22
24
  end
23
25
 
24
- self.class_eval do
25
- define_method("#{attribute}") { instance_variable_get("@#{attribute}") }
26
+ class_eval do
27
+ define_method(attribute.to_s) { instance_variable_get("@#{attribute}") }
26
28
  define_method "#{attribute}=" do |value|
27
- raise NotEnumValueError, 'Value is not permitted' if value && !self.class.mapping[attribute].include?(value.intern)
28
- instance_variable_set("@#{attribute}", value&.intern)
29
+ raise NotEnumValueError, 'Value is not permitted' if value && !self.class.mapping[attribute].include?(value.intern)
30
+
31
+ instance_variable_set("@#{attribute}", value ? value.intern : nil)
29
32
  end
30
33
  end
31
34
  end