Class: TokenValidation
- Inherits:
-
Object
- Object
- TokenValidation
- Defined in:
- lib/util/validation/token.rb
Class Method Summary collapse
Class Method Details
.create(data) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/util/validation/token.rb', line 9 def self.create(data) # Validate card number raise CustomException.new('Invalid card number.') unless HelperValidation.is_valid_card_number(data[:card_number]) # Validate CVV raise CustomException.new('Invalid CVV.') unless data[:cvv]&.match?(/^\d{3,4}$/) # Validate email raise CustomException.new('Invalid email.') unless HelperValidation.is_valid_email(data[:email]) # Validate expiration month raise 'Invalid expiration month.' unless data[:expiration_month].to_s.match?(/^(0?[1-9]|1[012])$/) # Validate expiration year current_year = Date.today.year if !data[:expiration_year].to_s.match?(/^\d{4}$/) || data[:expiration_year].to_s.to_i < current_year raise 'Invalid expiration year.' end # Check if the card is expired exp_date = Date.strptime("#{data[:expiration_year]}-#{data[:expiration_month]}", '%Y-%m') raise 'Card has expired.' if exp_date < Date.today end |
.create_token_yape_validation(data) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/util/validation/token.rb', line 33 def self.create_token_yape_validation(data) # Validate amount unless data[:amount].is_a?(Numeric) && data[:amount].to_i == data[:amount] raise CustomException.new('Invalid amount.') end end |
.list(data) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/util/validation/token.rb', line 40 def self.list(data) if data.key?('device_type') allowed_device_values = ['desktop', 'mobile', 'tablet'] HelperValidation.validate_value(data[:device_type], allowed_device_values) end if data.key?('card_brand') allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners'] HelperValidation.validate_value(data[:card_brand], allowed_brand_values) end if data.key?('card_type') allowed_card_type_values = ['credito', 'debito', 'internacional'] HelperValidation.validate_value(data[:card_type], allowed_card_type_values) end if data.key?('country_code') HelperValidation.validate_value(data[:country_code], get_country_codes) end if data.key?('creation_date_from') && data.key?('creation_date_to') HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to]) end end |