minfraud 1.1.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 +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +22 -0
  5. data/CHANGELOG.md +42 -0
  6. data/CODE_OF_CONDUCT.md +49 -0
  7. data/Gemfile +12 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.dev.md +4 -0
  10. data/README.md +178 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  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 +51 -0
  29. data/lib/minfraud/assessments.rb +101 -0
  30. data/lib/minfraud/components/account.rb +23 -0
  31. data/lib/minfraud/components/addressable.rb +67 -0
  32. data/lib/minfraud/components/base.rb +35 -0
  33. data/lib/minfraud/components/billing.rb +5 -0
  34. data/lib/minfraud/components/credit_card.rb +52 -0
  35. data/lib/minfraud/components/custom_inputs.rb +14 -0
  36. data/lib/minfraud/components/device.rb +38 -0
  37. data/lib/minfraud/components/email.rb +21 -0
  38. data/lib/minfraud/components/event.rb +44 -0
  39. data/lib/minfraud/components/order.rb +52 -0
  40. data/lib/minfraud/components/payment.rb +152 -0
  41. data/lib/minfraud/components/report/transaction.rb +69 -0
  42. data/lib/minfraud/components/shipping.rb +18 -0
  43. data/lib/minfraud/components/shopping_cart.rb +30 -0
  44. data/lib/minfraud/components/shopping_cart_item.rb +33 -0
  45. data/lib/minfraud/enum.rb +34 -0
  46. data/lib/minfraud/error_handler.rb +65 -0
  47. data/lib/minfraud/errors.rb +10 -0
  48. data/lib/minfraud/http_service.rb +30 -0
  49. data/lib/minfraud/http_service/request.rb +37 -0
  50. data/lib/minfraud/http_service/response.rb +64 -0
  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 +156 -0
  69. data/lib/minfraud/model/warning.rb +63 -0
  70. data/lib/minfraud/report.rb +38 -0
  71. data/lib/minfraud/resolver.rb +33 -0
  72. data/lib/minfraud/version.rb +3 -0
  73. data/minfraud.gemspec +29 -0
  74. metadata +198 -0
@@ -0,0 +1,52 @@
1
+ module Minfraud
2
+ module Components
3
+ class Order < Base
4
+ # @attribute amount
5
+ # @return [Decimal] The total order amount for the transaction
6
+ attr_accessor :amount
7
+
8
+ # @attribute currency
9
+ # @return [String] The ISO 4217 currency code for the currency used in the transaction
10
+ attr_accessor :currency
11
+
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.
15
+ attr_accessor :discount_code
16
+
17
+ # @attribute affiliate_id
18
+ # @return [String] The ID of the affiliate where the order is coming from
19
+ attr_accessor :affiliate_id
20
+
21
+ # @attribute subaffiliate_id
22
+ # @return [String] The ID of the sub-affiliate where the order is coming from
23
+ attr_accessor :subaffiliate_id
24
+
25
+ # @attribute :referrer_uri
26
+ # @return [String] The URI of the referring site for this order
27
+ attr_accessor :referrer_uri
28
+
29
+ # @attribute :is_gift
30
+ # @return [Boolean] Whether order was marked as a gift by the purchaser
31
+ attr_accessor :is_gift
32
+
33
+ # @attribute :has_gift_message
34
+ # @return [Boolean] Whether the purchaser included a gift message
35
+ attr_accessor :has_gift_message
36
+
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 = {})
41
+ @amount = params[:amount]
42
+ @has_gift_message = params[:has_gift_message]
43
+ @affiliate_id = params[:affiliate_id]
44
+ @subaffiliate_id = params[:subaffiliate_id]
45
+ @currency = params[:currency]
46
+ @discount_code = params[:discount_cide]
47
+ @referrer_uri = params[:referrer_uri]
48
+ @is_gift = params[:is_gift]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,152 @@
1
+ module Minfraud
2
+ module Components
3
+ class Payment < Base
4
+ include ::Minfraud::Enum
5
+ # @attribute processor
6
+ # @return [String] The payment processor used for the transaction
7
+ enum_accessor :processor, [
8
+ :adyen,
9
+ :affirm,
10
+ :afterpay,
11
+ :altapay,
12
+ :amazon_payments,
13
+ :american_express_payment_gateway,
14
+ :authorizenet,
15
+ :balanced,
16
+ :beanstream,
17
+ :bluepay,
18
+ :bluesnap,
19
+ :bpoint,
20
+ :braintree,
21
+ :cardpay,
22
+ :ccavenue,
23
+ :ccnow,
24
+ :cetelem,
25
+ :chase_paymentech,
26
+ :checkout_com,
27
+ :cielo,
28
+ :collector,
29
+ :commdoo,
30
+ :compropago,
31
+ :concept_payments,
32
+ :conekta,
33
+ :ct_payments,
34
+ :cuentadigital,
35
+ :curopayments,
36
+ :cybersource,
37
+ :dalenys,
38
+ :dalpay,
39
+ :datacash,
40
+ :dibs,
41
+ :digital_river,
42
+ :dotpay,
43
+ :ebs,
44
+ :ecomm365,
45
+ :ecommpay,
46
+ :elavon,
47
+ :emerchantpay,
48
+ :epay,
49
+ :eprocessing_network,
50
+ :epx,
51
+ :eway,
52
+ :exact,
53
+ :first_data,
54
+ :g2a_pay,
55
+ :global_payments,
56
+ :gocardless,
57
+ :heartland,
58
+ :hipay,
59
+ :ingenico,
60
+ :interac,
61
+ :internetsecure,
62
+ :intuit_quickbooks_payments,
63
+ :iugu,
64
+ :klarna,
65
+ :lemon_way,
66
+ :mastercard_payment_gateway,
67
+ :mercadopago,
68
+ :mercanet,
69
+ :merchant_esolutions,
70
+ :mirjeh,
71
+ :mollie,
72
+ :moneris_solutions,
73
+ :nmi,
74
+ :oceanpayment,
75
+ :oney,
76
+ :openpaymx,
77
+ :optimal_payments,
78
+ :orangepay,
79
+ :other,
80
+ :pacnet_services,
81
+ :payeezy,
82
+ :payfast,
83
+ :paygate,
84
+ :paylike,
85
+ :payment_express,
86
+ :paymentwall,
87
+ :payone,
88
+ :paypal,
89
+ :payplus,
90
+ :paysafecard,
91
+ :paystation,
92
+ :paytrace,
93
+ :paytrail,
94
+ :payture,
95
+ :payu,
96
+ :payulatam,
97
+ :payway,
98
+ :payza,
99
+ :pinpayments,
100
+ :posconnect,
101
+ :princeton_payment_solutions,
102
+ :psigate,
103
+ :qiwi,
104
+ :quickpay,
105
+ :raberil,
106
+ :rede,
107
+ :redpagos,
108
+ :rewardspay,
109
+ :sagepay,
110
+ :securetrading,
111
+ :simplify_commerce,
112
+ :skrill,
113
+ :smartcoin,
114
+ :smartdebit,
115
+ :solidtrust_pay,
116
+ :sps_decidir,
117
+ :stripe,
118
+ :synapsefi,
119
+ :telerecargas,
120
+ :towah,
121
+ :transact_pro,
122
+ :usa_epay,
123
+ :vantiv,
124
+ :verepay,
125
+ :vericheck,
126
+ :vindicia,
127
+ :virtual_card_services,
128
+ :vme,
129
+ :vpos,
130
+ :wirecard,
131
+ :worldpay
132
+ ]
133
+
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
136
+ attr_accessor :was_authorized
137
+
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
140
+ attr_accessor :decline_code
141
+
142
+ # Creates Minfraud::Components::Payment instance
143
+ # @param [Hash] params hash of parameters
144
+ # @return [Minfraud::Components::Payment] Payment instance
145
+ def initialize(params = {})
146
+ @was_authorized = params[:was_authorized]
147
+ @decline_code = params[:decline_code]
148
+ self.processor = params[:processor]
149
+ end
150
+ end
151
+ end
152
+ end
@@ -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
@@ -0,0 +1,18 @@
1
+ module Minfraud
2
+ module Components
3
+ class Shipping < Addressable
4
+ include ::Minfraud::Enum
5
+ # @attribute delivery_speed
6
+ # @return [String] The shipping delivery speed for the order. The valid values are:
7
+ enum_accessor :delivery_speed, [:same_day, :overnight, :expedited, :standard]
8
+
9
+ # Creates Minfraud::Components::Shipping instance
10
+ # @param [Hash] params hash of parameters
11
+ # @return [Minfraud::Components::Shipping] Shipping instance
12
+ def initialize(params = {})
13
+ self.delivery_speed = params[:delivery_speed]
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module Minfraud
2
+ module Components
3
+ class ShoppingCart < Base
4
+ # @attribute items
5
+ # @return [Array] An array of Minfraud::Components::ShoppingCartItem instances
6
+
7
+ attr_accessor :items
8
+ # Creates Minfraud::Components::ShoppingCart instance
9
+ # @param [Hash] params hash of parameters
10
+ # @return [Minfraud::Components::ShoppingCart] ShoppingCart instance
11
+ def initialize(params = {})
12
+ @items = params.map(&method(:resolve))
13
+ end
14
+
15
+ # @return [Array] a JSON representation of Minfraud::Components::ShoppingCart items
16
+ def to_json
17
+ @items.map(&:to_json)
18
+ end
19
+
20
+ private
21
+
22
+ # @param [Hash] params hash of parameters for Minfraud::Components::ShoppingCartItem
23
+ # or Minfraud::Components::ShoppingCartItem instance
24
+ # @return [Minfraud::Components::ShoppingCart] ShoppingCart instance
25
+ def resolve(params)
26
+ params.is_a?(ShoppingCartItem) ? params : ShoppingCartItem.new(params)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ module Minfraud
2
+ module Components
3
+ class ShoppingCartItem < Base
4
+ # @attribute category
5
+ # @return [String] The category of the item
6
+ attr_accessor :category
7
+
8
+ # @attribute item_id
9
+ # @return [String] The internal ID of the item
10
+ attr_accessor :item_id
11
+
12
+ # @attribute quantity
13
+ # @return [Integer] The quantity of the item in the shopping cart
14
+ attr_accessor :quantity
15
+
16
+ # @attribute price
17
+ # @return [Float] The per-unit price of this item in the shopping cart. This should use the same currency as the order currency
18
+ attr_accessor :price
19
+
20
+ # Creates Minfraud::Components::ShoppingCartItem instance
21
+ # @param [Hash] params hash of parameters
22
+ # @return [Minfraud::Components::ShoppingCartItem] ShoppingCartItem instance
23
+ def initialize(params = {})
24
+ @category = params[:category]
25
+ @item_id = params[:item_id]
26
+ @quantity = params[:quantity]
27
+ @price = params[:price]
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+
@@ -0,0 +1,34 @@
1
+ module Minfraud
2
+ module Enum
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ # Returns a hash with in the following format: attribute_name => permitted_values
9
+ # @return [Hash] mapping
10
+ def mapping
11
+ @mapping ||= {}
12
+ end
13
+
14
+ # Creates a set of methods for enum-like behaviour of the attribute
15
+ # @param [Symbol] attribute attribute name
16
+ # @param [Array] assignable_values a set of values which are permitted
17
+ def enum_accessor(attribute, assignable_values)
18
+ mapping[attribute] = assignable_values.map(&:intern)
19
+
20
+ self.class.instance_eval do
21
+ define_method("#{attribute}_values") { mapping[attribute] }
22
+ end
23
+
24
+ self.class_eval do
25
+ define_method("#{attribute}") { instance_variable_get("@#{attribute}") }
26
+ 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 ? value.intern : nil)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minfraud
4
+ module ErrorHandler
5
+ class << self
6
+ # Returns a response if status code is 2xx, raises an error otherwise
7
+ # @param [Minfraud::HTTPService::Response] response
8
+ # @return [Minfraud::HTTPService::Response] if status code is 200
9
+ def examine(response)
10
+ return response if response.status > 199 && response.status < 300
11
+
12
+ raise *STATUS_CODES.fetch(response.code, [ServerError, 'Server error'])
13
+ end
14
+
15
+ # A hash that maps status codes returned by minFraud with errors & messages
16
+ STATUS_CODES = {
17
+ IP_ADDRESS_INVALID: [
18
+ ClientError, 'You have not supplied a valid IPv4 or IPv6 address'
19
+ ],
20
+ IP_ADDRESS_REQUIRED: [
21
+ ClientError, 'You have not supplied an IP address which is a required field'
22
+ ],
23
+ IP_ADDRESS_RESERVED: [
24
+ ClientError, 'You have supplied an IP address which is reserved'
25
+ ],
26
+ JSON_INVALID: [
27
+ ClientError, 'JSON body cannot be decoded'
28
+ ],
29
+ MAXMIND_ID_INVALID: [
30
+ ClientError, 'You have not supplied a valid maxmind_id'
31
+ ],
32
+ MINFRAUD_ID_INVALID: [
33
+ ClientError, 'You have not supplied a valid minfraud_id'
34
+ ],
35
+ PARAMETER_UNKNOWN: [
36
+ ClientError, 'You have supplied an unknown parameter'
37
+ ],
38
+ TAG_REQUIRED: [
39
+ ClientError, 'You have not supplied a tag, which is a required field'
40
+ ],
41
+ TAG_INVALID: [
42
+ ClientError, 'You have not supplied a valid tag'
43
+ ],
44
+ ACCOUNT_ID_REQUIRED: [
45
+ AuthorizationError, 'You have not supplied a account ID'
46
+ ],
47
+ AUTHORIZATION_INVALID: [
48
+ AuthorizationError, 'Invalid license key and / or account ID'
49
+ ],
50
+ LICENSE_KEY_REQUIRED: [
51
+ AuthorizationError, 'You have not supplied a license key'
52
+ ],
53
+ USER_ID_REQUIRED: [
54
+ AuthorizationError, 'You have not supplied a account id'
55
+ ],
56
+ INSUFFICIENT_FUNDS: [
57
+ ClientError, 'The license key you have provided does not have a sufficient funds to use this service'
58
+ ],
59
+ PERMISSION_REQUIRED: [
60
+ ClientError, 'You do not have permission to use this service'
61
+ ]
62
+ }.freeze
63
+ end
64
+ end
65
+ end