Permalink
Browse files

Added CTX transactions and addenda

  • Loading branch information...
1 parent c03fdfe commit c00d3a88db01239f3e0020fb251e0854ce350918 @joshpuetz joshpuetz committed Oct 22, 2012
Showing with 153 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +10 −0 Rakefile
  3. +13 −0 lib/ach/records/addendum.rb
  4. +39 −0 lib/ach/records/entry_detail.rb
  5. +12 −0 test/addendum_test.rb
  6. +78 −0 test/ctx_entry_detail_test.rb
View
@@ -1,3 +1,4 @@
+.rvmrc
*.sw?
.DS_Store
coverage
View
@@ -20,6 +20,13 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
+require 'rake/testtask'
+ Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/*test*.rb']
+ t.verbose = true
+ end
+
require 'micronaut/rake_task'
Micronaut::RakeTask.new(:examples) do |examples|
examples.pattern = 'examples/**/*_example.rb'
@@ -42,3 +49,6 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
+
+
+
@@ -0,0 +1,13 @@
+module ACH::Records
+ class Addendum < Record
+
+ @fields = []
+
+ const_field :record_type, '7'
+ const_field :type_code, '05'
+ field :payment_data, String, lambda { |f| left_justify(f, 80)}
+ field :sequence_number, Integer, lambda { |f| sprintf('%04d', f)}
+ field :entry_detail_sequence_number, Integer, lambda { |f| sprintf('%07d', f)}
+
+ end
+end
@@ -35,4 +35,43 @@ def amount_value
end
end
+
+ class CtxEntryDetail < EntryDetail
+
+ @fields = EntryDetail.fields.slice(0, 6)
+ field :number_of_addenda_records, Integer, lambda { |f| sprintf('%04d', f)}, 0
+ field :individual_name, String, lambda { |f| left_justify(f, 16)}
+ const_field :reserved, ' '
+ field :discretionary_data, String, lambda { |f| left_justify(f, 2)}, ' '
+ field :addenda_record_indicator, Integer,
+ lambda { |f| sprintf('%01d', f)}
+ field :originating_dfi_identification, String,
+ lambda {|f| f}, nil, /\A\d{8}\Z/
+ field :trace_number, Integer, lambda { |f| sprintf('%07d', f)}
+
+
+ attr_reader :addenda
+
+ def initialize
+ @addenda = []
+ end
+
+ def addenda_records?
+ return !self.addenda.empty?
+ end
+
+ def to_ach
+ self.addenda_record_indicator = (self.addenda.empty? ? 0 : 1)
+ self.number_of_addenda_records = self.addenda.length
+
+ ach_string = super
+
+ self.addenda.each {|a|
+ a.entry_detail_sequence_number = self.trace_number
+ ach_string << a.to_ach
+ }
+ return ach_string
+ end
+
+ end
end
View
@@ -0,0 +1,12 @@
+require 'rubygems'
+require 'ach'
+require 'test/unit'
+
+class AddendumTest < Test::Unit::TestCase
+
+ def test_stuff
+ assert true
+ end
+
+
+end
@@ -0,0 +1,78 @@
+require 'rubygems'
+require 'ach'
+require 'test/unit'
+
+class CtxEntryDetailTest < Test::Unit::TestCase
+
+ def setup
+ @entry = ACH::CtxEntryDetail.new
+ @entry.transaction_code = ACH::CHECKING_DEBIT
+ @entry.routing_number = '023456789'
+ @entry.account_number = '123456789'
+ @entry.amount = 10000
+ @entry.individual_name = "Bob Roberts"
+ @entry.originating_dfi_identification = '02345678'
+ @entry.individual_id_number = '1'
+ @entry.trace_number = 1
+ end
+
+ def test_addenda_records?
+ @entry = ACH::CtxEntryDetail.new
+ assert @entry.addenda_records? == false
+
+ @entry.addenda << ACH::Addendum.new
+ assert @entry.addenda_records? == true
+
+ end
+
+ def test_ctx_entry_prints_addenda
+ addendum_1 = ACH::Addendum.new
+ addendum_1.payment_data = ""
+ addendum_1.sequence_number = "1"
+ @entry.addenda << addendum_1
+ assert @entry.addenda.size == 1
+
+ addendum_2 = ACH::Addendum.new
+ addendum_2.payment_data = ""
+ addendum_2.sequence_number = "2"
+ @entry.addenda << addendum_2
+ assert @entry.addenda.size == 2
+
+ # 705 is the beginning of an addendum record
+ ach_string = @entry.to_ach
+ assert ach_string.scan("705").count == 2
+
+ end
+
+ def test_ctx_correct_fields
+ ach_string = @entry.to_ach
+ assert ach_string.slice(39, 15) == "1 "
+ assert ach_string.slice(58, 16) == "#{@entry.individual_name.upcase} "
+ end
+
+ def test_to_ach_set_addendum_count_and_entry_detail_sequence_number
+ #Set a trace number we expect to find in the addendum record
+ expected_trace_number = "474"
+ @entry.trace_number = expected_trace_number
+
+
+ addendum_1 = ACH::Addendum.new
+ addendum_1.payment_data = ""
+ addendum_1.sequence_number = "1"
+ @entry.addenda << addendum_1
+
+
+ ach_string = @entry.to_ach
+ # Test addenda record indicator
+ assert ach_string.slice(78, 1) == "1"
+ # Test number of addenda records
+ assert ach_string.slice(54, 4) == "0001"
+ # Test for trace number in each addendum record
+ assert ach_string.scan(expected_trace_number).count == 2
+
+ end
+
+
+
+
+end

0 comments on commit c00d3a8

Please sign in to comment.