minfraud 1.0.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/rubocop.yml +12 -0
  3. data/.github/workflows/test.yml +32 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +108 -0
  6. data/CHANGELOG.md +70 -2
  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 +245 -59
  12. data/Rakefile +9 -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 +233 -0
  28. data/lib/minfraud.rb +48 -8
  29. data/lib/minfraud/assessments.rb +118 -49
  30. data/lib/minfraud/components/account.rb +31 -9
  31. data/lib/minfraud/components/addressable.rb +73 -26
  32. data/lib/minfraud/components/base.rb +35 -11
  33. data/lib/minfraud/components/billing.rb +5 -0
  34. data/lib/minfraud/components/credit_card.rb +64 -20
  35. data/lib/minfraud/components/custom_inputs.rb +25 -0
  36. data/lib/minfraud/components/device.rb +51 -10
  37. data/lib/minfraud/components/email.rb +29 -7
  38. data/lib/minfraud/components/event.rb +60 -13
  39. data/lib/minfraud/components/order.rb +60 -22
  40. data/lib/minfraud/components/payment.rb +166 -21
  41. data/lib/minfraud/components/report/transaction.rb +80 -0
  42. data/lib/minfraud/components/shipping.rb +14 -5
  43. data/lib/minfraud/components/shopping_cart.rb +19 -12
  44. data/lib/minfraud/components/shopping_cart_item.rb +42 -13
  45. data/lib/minfraud/enum.rb +22 -8
  46. data/lib/minfraud/error_handler.rb +45 -18
  47. data/lib/minfraud/errors.rb +22 -2
  48. data/lib/minfraud/http_service.rb +22 -8
  49. data/lib/minfraud/http_service/request.rb +19 -18
  50. data/lib/minfraud/http_service/response.rb +49 -12
  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 +178 -0
  69. data/lib/minfraud/model/warning.rb +63 -0
  70. data/lib/minfraud/report.rb +58 -0
  71. data/lib/minfraud/resolver.rb +25 -16
  72. data/lib/minfraud/validates.rb +187 -0
  73. data/lib/minfraud/version.rb +4 -1
  74. data/minfraud.gemspec +23 -18
  75. metadata +113 -39
  76. data/.travis.yml +0 -5
@@ -1,23 +1,47 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
3
- # @note This class is used as a parent class for all other components
4
- # @note It defines a method which is used for basic JSON representation of PORO objects
5
+ # This is a parent class for all components. It defines a method which is
6
+ # used for basic JSON representation of the component objects.
5
7
  class Base
6
- # @return [Hash] a JSON representation of component attributes
7
- def to_json
8
- instance_variables.inject({}) { |mem, e| populate!(mem, e) }
8
+ # A JSON representation of component attributes.
9
+ #
10
+ # @return [Hash]
11
+ def to_json(*_args)
12
+ instance_variables.reduce({}) { |mem, e| populate!(mem, e) }
9
13
  end
10
14
 
11
15
  private
12
16
 
13
- # @note This method may modify passed hash. Non-existing instance variables are ignored
14
- # @param [Hash] hash an accumulator
15
- # @param [Symbol] v_sym an instance variable symbol
16
- # @return [Hash] a hash containing a JSON representation of instance variable name and it's value
17
+ # Create a hash containing a JSON representation of instance variable
18
+ # name and its value.
19
+ #
20
+ # @param hash [Hash] An accumulator.
21
+ #
22
+ # @param v_sym [Symbol] An instance variable symbol.
23
+ #
24
+ # @return [Hash]
17
25
  def populate!(hash, v_sym)
18
- return hash unless value = instance_variable_get(v_sym)
19
- hash.merge!(v_sym.to_s.gsub(/@/, '') => value.to_s)
26
+ return hash unless (value = instance_variable_get(v_sym))
27
+
28
+ key = v_sym.to_s.gsub(/@/, '')
29
+ hash.merge!(key => represent(key, value))
20
30
  end
31
+
32
+ # Return the value according to the request format.
33
+ #
34
+ # @param key [Symbol] An instance variable symbol.
35
+ #
36
+ # @param value [Object] An instance variable value.
37
+ #
38
+ # @return [Object]
39
+ def represent(key, value)
40
+ BOOLS.include?(key) ? value : value.to_s
41
+ end
42
+
43
+ # Keys that have to remain boolean
44
+ BOOLS = %w[was_authorized is_gift has_gift_message].freeze
21
45
  end
22
46
  end
23
47
  end
@@ -1,5 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
5
+ # Billing corresponds to the billing object of a minFraud request.
6
+ #
7
+ # @see https://dev.maxmind.com/minfraud/#Billing_(/billing)
3
8
  class Billing < Addressable; end
4
9
  end
5
10
  end
@@ -1,42 +1,69 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
5
+ # CreditCard corresponds to the credit_card object of a minFraud request.
6
+ #
7
+ # @see https://dev.maxmind.com/minfraud/#Credit_Card_(/creditcard)
3
8
  class CreditCard < Base
4
- # @attribute issuer_id_number
5
- # # @return [String] The issuer ID number for the credit card. This is the first 6 digits of the credit card number.
6
- # It identifies the issuing bank
9
+ include Minfraud::Validates
10
+
11
+ # The issuer ID number for the credit card. This is the first 6 digits of
12
+ # the credit card number. It identifies the issuing bank.
13
+ #
14
+ # @return [String, nil]
7
15
  attr_accessor :issuer_id_number
8
16
 
9
- # @attribute last_4_digits
10
- # @return [String] The last four digits of the credit card number
17
+ # The last four digits of the credit card number.
18
+ #
19
+ # @return [String, nil]
11
20
  attr_accessor :last_4_digits
12
21
 
13
- # @attribute bank_name
14
- # @return [String] The name of the issuing bank as provided by the end user
22
+ # The name of the issuing bank as provided by the end user.
23
+ #
24
+ # @return [String, nil]
15
25
  attr_accessor :bank_name
16
26
 
17
- # @attribute bank_phone_country_code
18
- # @return [String] The phone country code for the issuing bank as provided by the end user
27
+ # The phone country code for the issuing bank as provided by the end
28
+ # user. If you provide this information then you must provide at least
29
+ # one digit.
30
+ #
31
+ # @return [String, nil]
19
32
  attr_accessor :bank_phone_country_code
20
33
 
21
- # @attribute bank_phone_number
22
- # @return [String] The phone number, without the country code, for the issuing bank as provided by the end user
34
+ # The phone number, without the country code, for the issuing bank as
35
+ # provided by the end user. Punctuation characters will be stripped.
36
+ # After stripping punctuation characters, the number must contain only
37
+ # digits.
38
+ #
39
+ # @return [String, nil]
23
40
  attr_accessor :bank_phone_number
24
41
 
25
- #@attribute token
26
- #@return [String] A token uniquely identifying the card. The token should consist of non-space printable ASCII characters.
42
+ # A token uniquely identifying the card. The token should consist of
43
+ # non-space printable ASCII characters. If the token is all digits, it
44
+ # must be more than 19 characters long. The token must not be a primary
45
+ # account number (PAN) or a simple transformation of it. If you have a
46
+ # valid token that looks like a PAN but is not one, you may prefix that
47
+ # token with a fixed string, e.g., +token-+.
48
+ #
49
+ # @return [String, nil]
27
50
  attr_accessor :token
28
51
 
29
- # @attribute avs_result
30
- # @return [String] The address verification system (AVS) check result, as returned to you by the credit card processor
52
+ # The address verification system (AVS) check result, as returned to you
53
+ # by the credit card processor. The minFraud service supports the
54
+ # standard AVS codes.
55
+ #
56
+ # @return [String, nil]
31
57
  attr_accessor :avs_result
32
58
 
33
- # @attribute cvv_result
34
- # @return [String] The card verification value (CVV) code as provided by the payment processor
59
+ # The card verification value (CVV) code as provided by the payment
60
+ # processor.
61
+ #
62
+ # @return [String, nil]
35
63
  attr_accessor :cvv_result
36
64
 
37
- # Creates Minfraud::Components::CreditCard instance
38
- # @param [Hash] params hash of parameters
39
- # @return [Minfraud::Components::CreditCard] a CreditCard instance
65
+ # @param params [Hash] Hash of parameters. Each key/value should
66
+ # correspond to one of the available attributes.
40
67
  def initialize(params = {})
41
68
  @bank_phone_country_code = params[:bank_phone_country_code]
42
69
  @issuer_id_number = params[:issuer_id_number]
@@ -46,6 +73,23 @@ module Minfraud
46
73
  @avs_result = params[:avs_result]
47
74
  @cvv_result = params[:cvv_result]
48
75
  @token = params[:token]
76
+
77
+ validate
78
+ end
79
+
80
+ private
81
+
82
+ def validate
83
+ return if !Minfraud.enable_validation
84
+
85
+ validate_telephone_country_code('bank_phone_country_code', @bank_phone_country_code)
86
+ validate_regex('issuer_id_number', /\A[0-9]{6}\z/, @issuer_id_number)
87
+ validate_regex('last_4_digits', /\A[0-9]{4}\z/, @last_4_digits)
88
+ validate_string('bank_name', 255, @bank_name)
89
+ validate_string('bank_phone_number', 255, @bank_phone_number)
90
+ validate_string('avs_result', 1, @avs_result)
91
+ validate_string('cvv_result', 1, @cvv_result)
92
+ validate_credit_card_token('token', @token)
49
93
  end
50
94
  end
51
95
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minfraud
4
+ module Components
5
+ # CustomInputs corresponds to the custom_inputs object of a minFraud
6
+ # request.
7
+ #
8
+ # @see https://dev.maxmind.com/minfraud/#Custom_Inputs_(/custominputs)
9
+ class CustomInputs < Base
10
+ include Minfraud::Validates
11
+
12
+ # @param params [Hash] Each key/value should correspond to your defined
13
+ # custom inputs.
14
+ def initialize(params = {})
15
+ params.each do |name, value|
16
+ instance_variable_set("@#{name}", value)
17
+
18
+ if Minfraud.enable_validation
19
+ validate_custom_input_value(name, value)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,26 +1,67 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
5
+ # Device corresponds to the device object of a minFraud request.
6
+ #
7
+ # @see https://dev.maxmind.com/minfraud/#Device_(/device)
3
8
  class Device < Base
4
- # @!attribute ip_address
5
- # @return [String] The IP address associated with the device used by the customer in the transaction.
6
- # The IP address must be in IPv4 or IPv6 presentation format
9
+ include Minfraud::Validates
10
+
11
+ # The IP address associated with the device used by the customer in the
12
+ # transaction. The IP address must be in IPv4 or IPv6 presentation
13
+ # format, i.e., dotted-quad notation or the IPv6 hexadecimal-colon
14
+ # notation.
15
+ #
16
+ # @return [String, nil]
7
17
  attr_accessor :ip_address
8
18
 
9
- # @attribute user_agent
10
- # @return [String] The HTTP "User-Agent" header of the browser used in the transaction
19
+ # The HTTP "User-Agent" header of the browser used in the transaction.
20
+ #
21
+ # @return [String, nil]
11
22
  attr_accessor :user_agent
12
23
 
13
- # @attribute :accept_language
14
- # @return [String] The HTTP "Accept-Language" header of the browser used in the transaction
24
+ # The HTTP "Accept-Language" header of the browser used in the
25
+ # transaction.
26
+ #
27
+ # @return [String, nil]
15
28
  attr_accessor :accept_language
16
29
 
17
- # Creates Minfraud::Components::Device instance
18
- # @param [Hash] params hash of parameters
19
- # @return [Minfraud::Components::Device] a Device instance
30
+ # The number of seconds between the creation of the user's session and
31
+ # the time of the transaction. Note that session_age is not the duration
32
+ # of the current visit, but the time since the start of the first visit.
33
+ # The value must be at least 0 and at most 10^13-1.
34
+ #
35
+ # @return [Float, nil]
36
+ attr_accessor :session_age
37
+
38
+ # An ID that uniquely identifies a visitor's session on the site.
39
+ #
40
+ # @return [String, nil]
41
+ attr_accessor :session_id
42
+
43
+ # @param params [Hash] Hash of parameters. Each key/value should
44
+ # correspond to one of the available attributes.
20
45
  def initialize(params = {})
21
46
  @ip_address = params[:ip_address]
22
47
  @user_agent = params[:user_agent]
23
48
  @accept_language = params[:accept_language]
49
+ @session_age = params[:session_age]
50
+ @session_id = params[:session_id]
51
+
52
+ validate
53
+ end
54
+
55
+ private
56
+
57
+ def validate
58
+ return if !Minfraud.enable_validation
59
+
60
+ validate_ip('ip_address', @ip_address)
61
+ validate_string('user_agent', 512, @user_agent)
62
+ validate_string('accept_language', 255, @accept_language)
63
+ validate_nonnegative_number('session_age', @session_age)
64
+ validate_string('session_id', 255, @session_id)
24
65
  end
25
66
  end
26
67
  end
@@ -1,20 +1,42 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfraud
2
4
  module Components
5
+ # Email corresponds to the email object of a minFraud request.
6
+ #
7
+ # @see https://dev.maxmind.com/minfraud/#Email_(/email)
3
8
  class Email < Base
4
- # @attribute address
5
- # @return [String] This field must be either a valid email address or an MD5 of the email used in the transaction
9
+ include Minfraud::Validates
10
+
11
+ # This field must be either be a valid email address or an MD5 of the
12
+ # lowercased email used in the transaction. Important: if using the MD5
13
+ # hash, please be sure to convert the email address to lowercase before
14
+ # calculating its MD5 hash.
15
+ #
16
+ # @return [String, nil]
6
17
  attr_accessor :address
7
18
 
8
- # @attribute domain
9
- # @return [String] The domain of the email address used in the transaction
19
+ # The domain of the email address used in the transaction.
20
+ #
21
+ # @return [String, nil]
10
22
  attr_accessor :domain
11
23
 
12
- # Creates Minfraud::Components::Email instance
13
- # @param [Hash] params hash of parameters
14
- # @return [Minfraud::Components::Email] an Email instance
24
+ # @param params [Hash] Hash of parameters. Each key/value should
25
+ # correspond to one of the available attributes.
15
26
  def initialize(params = {})
16
27
  @address = params[:address]
17
28
  @domain = params[:domain]
29
+
30
+ validate
31
+ end
32
+
33
+ private
34
+
35
+ def validate
36
+ return if !Minfraud.enable_validation
37
+
38
+ validate_email('email', @address)
39
+ validate_string('domain', 255, @domain)
18
40
  end
19
41
  end
20
42
  end
@@ -1,32 +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
20
- enum_accessor :type, [:account_creation, :account_login, :purchase, :recurring_purchase, :referral, :survey]
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]
45
+ enum_accessor :type,
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
+ ]
21
57
 
22
- # Creates Minfraud::Components::Event instance
23
- # @param [Hash] params hash of parameters
24
- # @return [Minfraud::Components::Event] an Event instance
58
+ # @param params [Hash] Hash of parameters. Each key/value should
59
+ # correspond to one of the available attributes.
25
60
  def initialize(params = {})
26
61
  @transaction_id = params[:transaction_id]
27
62
  @shop_id = params[:shop_id]
28
63
  @time = params[:time]
29
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)
30
77
  end
31
78
  end
32
79
  end
@@ -1,50 +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 = {})
61
+ @amount = params[:amount]
41
62
  @has_gift_message = params[:has_gift_message]
42
63
  @affiliate_id = params[:affiliate_id]
43
64
  @subaffiliate_id = params[:subaffiliate_id]
44
65
  @currency = params[:currency]
45
- @discount_code = params[:discount_cide]
66
+ @discount_code = params[:discount_code]
46
67
  @referrer_uri = params[:referrer_uri]
47
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)
48
86
  end
49
87
  end
50
88
  end