Module: EWS::Transaction::Validator

Included in:
Request
Defined in:
lib/ews/transaction/validator.rb

Constant Summary collapse

@@valid_lengths =
{
  :authorization_num => 8,
  :cardholder_name => 30,
  :cc_number => 19,
  :cc_expiry => 4,
  :cavv => 40,
  :client_email => 30,
  :client_ip => 15,
  :customer_ref => 20,
  :gateway_id => 10,
  :pan => 39,
  :password => 30,
  :reference_3 => 30,
  :reference_no => 20,
  :tax1_number => 20,
  :tax2_number => 20,
  :track1 => 79,
  :track2 => 40,
  :transaction_type => 2,
  :cc_verification_str1 => 40,
  :cc_verification_str2 => 4,
  :xid => 40,
  :zip_code => 10
}.freeze

Instance Method Summary collapse

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ews/transaction/validator.rb', line 30

def valid?
  @errors = {}

  append_error(:transaction_type, "transaction_type must be supplied") if self.transaction_type.blank?

  # need to authenticate
  append_error(:gateway_id, "gateway_id must be supplied") if self.gateway_id.blank?
  append_error(:password, "password must be supplied") if self.password.blank?

  validate_lengths
  
  if self.transaction_type == "CR"
    append_error(:transaction_tag, "transaction_tag must be supplied") if self.transaction_tag.to_i < 1
  elsif %w(80 81).include?(self.transaction_type)
    # do nothing, no validation required
  elsif %w(50 54).include?(self.transaction_type)
    validate_for_pan
  elsif !self.transaction_tag.blank?
    validate_for_transaction_tag
  elsif !self.cc_number.blank?
    validate_for_cc_number
  elsif !self.track1.blank?
    validate_for_track1
  elsif !self.track2.blank?
    validate_for_track2
  else
    append_error(:base, "One of the following must be supplied: cc_number, track1, track2 or transaction_tag.")
  end
  
  # ensure we've been given valid amounts
  append_error(:amount, "invalid amount supplied") unless valid_amount?(self.amount)
  append_error(:surcharge_amount, "invalid surcharge_amount supplied") unless valid_amount?(self.surcharge_amount)
  append_error(:tax1_amount, "invalid tax1_amount supplied") unless valid_amount?(self.tax1_amount)
  append_error(:tax2_amount, "invalid tax2_amount supplied") unless valid_amount?(self.tax2_amount)

  # ensure our amounts are within range
  append_error(:amount, "amount must be between 0.00 and 99999.99") unless amount_in_range?(self.amount)
  append_error(:surcharge_amount, "surcharge_amount must be between 0.00 and 99999.99") unless amount_in_range?(self.surcharge_amount)
  append_error(:tax1_amount, "tax1_amount must be between 0.00 and 99999.99") unless amount_in_range?(self.tax1_amount)
  append_error(:tax2_amount, "tax2_amount must be between 0.00 and 99999.99") unless amount_in_range?(self.tax2_amount)
  
  # ensure our credit card information is valid
  append_error(:cc_number, "invalid cc_number supplied") unless valid_card_number?
  append_error(:cc_expiry, "invalid cc_expiry supplied") unless valid_expiry_date?
  
  @errors.empty?
end