Skip to content

Commit

Permalink
Support acknowledgment entries - ACK & ATX #327
Browse files Browse the repository at this point in the history
read and write test
change SetOriginalTraceNumber argument from int to string
  • Loading branch information
bkmoovio committed Oct 26, 2018
1 parent 3c3b14c commit bb1e9fa
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 10 deletions.
2 changes: 1 addition & 1 deletion batchACK_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func mockACKEntryDetail() *EntryDetail {
entry.SetRDFI("121042882")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber(121042880000001)
entry.SetOriginalTraceNumber("121042880000001")
entry.SetReceivingCompany("Best Co. #23")
entry.SetTraceNumber(mockBatchACKHeader().ODFIIdentification, 1)
entry.DiscretionaryData = "S"
Expand Down
12 changes: 6 additions & 6 deletions batchATX_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func mockATXEntryDetail() *EntryDetail {
entry.SetRDFI("121042882")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber(121042880000001)
entry.SetOriginalTraceNumber("121042880000001")
entry.SetCATXAddendaRecords(1)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchATXHeader().ODFIIdentification, 1)
Expand Down Expand Up @@ -309,7 +309,7 @@ func testBatchATXAddenda10000(t testing.TB) {
entry.SetRDFI("121042882")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber(121042880000001)
entry.SetOriginalTraceNumber("121042880000001")
entry.SetCATXAddendaRecords(9999)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchATXHeader().ODFIIdentification, 1)
Expand Down Expand Up @@ -362,7 +362,7 @@ func testBatchATXAddendaRecords(t testing.TB) {
entry.SetRDFI("121042882")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber(121042880000001)
entry.SetOriginalTraceNumber("121042880000001")
entry.SetCATXAddendaRecords(500)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchATXHeader().ODFIIdentification, 1)
Expand Down Expand Up @@ -460,7 +460,7 @@ func testBatchATXZeroAddendaRecords(t testing.TB) {
entry.SetRDFI("121042882")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber(121042880000001)
entry.SetOriginalTraceNumber("121042880000001")
entry.SetCATXAddendaRecords(1)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchATXHeader().ODFIIdentification, 1)
Expand Down Expand Up @@ -510,7 +510,7 @@ func testBatchATXTransactionCode(t testing.TB) {
entry.SetRDFI("121042882")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber(121042880000001)
entry.SetOriginalTraceNumber("121042880000001")
entry.SetCATXAddendaRecords(1)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchATXHeader().ODFIIdentification, 1)
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestBatchATXAmount(t *testing.T) {
entry.SetRDFI("121042882")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 25000
entry.SetOriginalTraceNumber(121042880000001)
entry.SetOriginalTraceNumber("121042880000001")
entry.SetCATXAddendaRecords(1)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(mockBatchATXHeader().ODFIIdentification, 1)
Expand Down
4 changes: 1 addition & 3 deletions entryDetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ func (ed *EntryDetail) OriginalTraceNumberField() string {
}

// SetOriginalTraceNumber setter for ACK and ATX OriginalTraceNumber which is underlying IdentificationNumber
func (ed *EntryDetail) SetOriginalTraceNumber(i int) {
s := strconv.Itoa(i)
//ed.IdentificationNumber = ed.numericField(i, 15)
func (ed *EntryDetail) SetOriginalTraceNumber(s string) {
ed.IdentificationNumber = s
}

Expand Down
10 changes: 10 additions & 0 deletions test/ach-ack-read/ack-read.ach
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
101 031300012 2313801041810260000A094101Federal Reserve Bank My Bank Name
5220Name on Account 231380104 ACKVndr Pay 181027 0231380100000001
624031300012744-5678-99 0000000000031300010000001Best. #1 S 0231380100000001
624031300012744-5678-99 0000000000031300010000002Best. #1 S 0231380100000002
82200000020006260002000000000000000000000000231380104 231380100000001
9000001000001000000020006260002000000000000000000000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
35 changes: 35 additions & 0 deletions test/ach-ack-read/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"log"
"os"

"github.com/moov-io/ach"
)

func main() {
// open a file for reading. Any io.Reader Can be used
f, err := os.Open("ack-read.ach")
if err != nil {
log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
fmt.Printf("Issue reading file: %+v \n", err)
}
// ensure we have a validated file structure
if achFile.Validate(); err != nil {
fmt.Printf("Could not validate entire read file: %v", err)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if achFile.Create(); err != nil {
fmt.Printf("Could not build file with read properties: %v", err)
}

fmt.Printf("Credit Total Amount: %v \n", achFile.Control.TotalCreditEntryDollarAmountInFile)
fmt.Printf("Total Amount: %v \n", achFile.Batches[0].GetEntries()[0].Amount)
fmt.Printf("SEC Code: %v \n", achFile.Batches[0].GetHeader().StandardEntryClassCode)
fmt.Printf("Original Trace Number: %v \n", achFile.Batches[0].GetEntries()[0].OriginalTraceNumberField())
}
7 changes: 7 additions & 0 deletions test/ach-ack-read/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "testing"

func Test(t *testing.T) {
main()
}
79 changes: 79 additions & 0 deletions test/ach-ack-write/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package main

import (
"log"
"os"
"time"

"github.com/moov-io/ach"
)

func main() {
// Example transfer to write an ACH ACK file acknowledging a credit
// Important: All financial institutions are different and will require registration and exact field values.

// Set originator bank ODFI and destination Operator for the financial institution
// this is the funding/receiving source of the transfer
fh := ach.NewFileHeader()
fh.ImmediateDestination = "031300012" // Routing Number of the ACH Operator or receiving point to which the file is being sent
fh.ImmediateOrigin = "231380104" // Routing Number of the ACH Operator or sending point that is sending the file
fh.FileCreationDate = time.Now() // Today's Date
fh.ImmediateDestinationName = "Federal Reserve Bank"
fh.ImmediateOriginName = "My Bank Name"

// BatchHeader identifies the originating entity and the type of transactions contained in the batch
bh := ach.NewBatchHeader()
bh.ServiceClassCode = 220 // ACH credit pushes money out, 225 debits/pulls money in.
bh.CompanyName = "Name on Account" // The name of the company/person that has relationship with receiver
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = "ACK" // Consumer destination vs Company CCD
bh.CompanyEntryDescription = "Vndr Pay" // will be on receiving accounts statement
bh.EffectiveEntryDate = time.Now().AddDate(0, 0, 1)
bh.ODFIIdentification = "23138010" // Originating Routing Number

// Identifies the receivers account information
// can be multiple entry's per batch
entry := ach.NewEntryDetail()
// Identifies the entry as a debit and credit entry AND to what type of account (Savings, DDA, Loan, GL)
entry.TransactionCode = 24 // Code 22: Demand Debit(deposit) to checking account
entry.SetRDFI("031300012") // Receivers bank transit routing number
entry.DFIAccountNumber = "744-5678-99" // Receivers bank account number
entry.Amount = 0 // Amount of transaction with no decimal. One dollar and eleven cents = 111
entry.SetOriginalTraceNumber("031300010000001")
entry.SetReceivingCompany("Best. #1")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.DiscretionaryData = "S"

entryOne := ach.NewEntryDetail() // Fee Entry
entryOne.TransactionCode = 24 // Demand Credit
entryOne.SetRDFI("031300012") // Receivers bank transit routing number
entryOne.DFIAccountNumber = "744-5678-99" // Receivers bank account number
entryOne.Amount = 0 // Amount of transaction with no decimal. One dollar and eleven cents = 111
entryOne.SetOriginalTraceNumber("031300010000002")
entryOne.SetReceivingCompany("Best. #1")
entryOne.SetTraceNumber(bh.ODFIIdentification, 2)
entryOne.DiscretionaryData = "S"

// build the batch
batch := ach.NewBatchACK(bh)
batch.AddEntry(entry)
batch.AddEntry(entryOne)
if err := batch.Create(); err != nil {
log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
log.Fatalf("Unexpected error building file: %s\n", err)
}

// write the file to std out. Anything io.Writer
w := ach.NewWriter(os.Stdout)
if err := w.Write(file); err != nil {
log.Fatalf("Unexpected error: %s\n", err)
}
w.Flush()
}
8 changes: 8 additions & 0 deletions test/ach-ack-write/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "testing"

func Test(t *testing.T) {
main()
}

0 comments on commit bb1e9fa

Please sign in to comment.