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
77
78
|
# 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?
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 self.transaction_type == "36"
validate_referenced_void
elsif %w(80 81).include?(self.transaction_type)
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
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)
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)
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
|