./lib/ews/transaction/validator.rb in exact4r-1.2 vs ./lib/ews/transaction/validator.rb in exact4r-1.4

- old
+ new

@@ -38,10 +38,12 @@ 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) # do nothing, no validation required elsif %w(50 54).include?(self.transaction_type) validate_for_pan elsif !self.transaction_tag.blank? @@ -164,16 +166,17 @@ end def validate_for_transaction_tag tt = self.transaction_type - # mandatory: transaction_type must == (30, 31, 32, 33, 34, 35) - append_error(:transaction_tag, "transaction_tag must only be set for tagged transactions") unless %w(30 31 32 33 34 35 CR).include?(tt) + # mandatory: transaction_type must == (30, 31, 32, 33, 34, 35, 37, CR) + append_error(:transaction_tag, "transaction_tag must only be set for tagged transactions") unless %w(30 31 32 33 34 35 37 CR).include?(tt) # transaction_tag, auth_num & amount mandatory mandatory = [:transaction_tag] - mandatory << [:authorization_num, :amount] unless tt == 'CR' + mandatory << :authorization_num unless tt == 'CR' + mandatory << :amount unless %w(CR 37).include?(tt) # ensure no cc details sent append_error(:cc_number, "do not set cc_number for tagged transactions") unless self.cc_number.blank? append_error(:cc_expiry, "do not set cc_expiry for tagged transactions") unless self.cc_expiry.blank? append_error(:cardholder_name, "do not set cardholder_name for tagged transactions") unless self.cardholder_name.blank? @@ -224,9 +227,18 @@ # track2, expiry_date, cardholder_name, amount mandatory mandatory = [:pan, :cardholder_name, :amount] check_mandatory(mandatory) end + + def validate_referenced_void + [:cc_number, :pan, :track1, :track2, :transaction_tag].each do |attr_name| + append_error(attr_name, "#{attr_name} must not be set for referenced_void transactions") unless self.send(attr_name).nil? + end + + check_mandatory([:reference_no, :customer_ref, :amount]) + end + def check_mandatory(mandatory) mandatory.each do |key| append_error(key, "#{key} must be supplied") if self.send(key).blank? end \ No newline at end of file