class PayCertify::Gateway::Transaction::Validation
Constants
- ALLOWED_CURRENCIES
- ALLOWED_TYPES
- ALL_VALIDATIONS
- CAPTURE_VALIDATIONS
- VOID_VALIDATIONS
Public Class Methods
new(attributes={})
click to toggle source
Calls superclass method
PayCertify::Gateway::Base::Validation::new
# File lib/paycertify/gateway/transaction.rb, line 74 def initialize(attributes={}) super(attributes) validations.each do |attribute| presence_validation(attribute) if attribute[:required] send(attribute[:validation], attribute) if value_for(attribute).present? end end
Public Instance Methods
currency_validation(attribute)
click to toggle source
# File lib/paycertify/gateway/transaction.rb, line 100 def currency_validation(attribute) set_attribute(attribute, value_for(attribute).upcase) unless value_for(attribute).try(:to_s).in?(ALLOWED_CURRENCIES) add_error(attribute, "Must be one of #{ALLOWED_CURRENCIES.join(', ')}") end end
ip_validation(attribute)
click to toggle source
# File lib/paycertify/gateway/transaction.rb, line 108 def ip_validation(attribute) IPAddr.new(value_for(attribute)) rescue IPAddr::InvalidAddressError add_error(attribute, "Doesn't validate as an IP.") end
type_validation(attribute)
click to toggle source
# File lib/paycertify/gateway/transaction.rb, line 94 def type_validation(attribute) unless value_for(attribute).try(:to_s).in?(ALLOWED_TYPES) add_error(attribute, "Must be one of #{ALLOWED_TYPES.join(', ')}") end end
validations()
click to toggle source
# File lib/paycertify/gateway/transaction.rb, line 83 def validations case attributes[:type] when 'force' CAPTURE_VALIDATIONS when 'void', 'return' VOID_VALIDATIONS else ALL_VALIDATIONS end end