diff --git a/batchACK_test.go b/batchACK_test.go index e5a8c318c..14ac34d48 100644 --- a/batchACK_test.go +++ b/batchACK_test.go @@ -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" diff --git a/batchATX_test.go b/batchATX_test.go index 3b820256d..c5abba6b7 100644 --- a/batchATX_test.go +++ b/batchATX_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/entryDetail.go b/entryDetail.go index 3b10ab1eb..8e127def5 100644 --- a/entryDetail.go +++ b/entryDetail.go @@ -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 } diff --git a/test/ach-ack-read/ack-read.ach b/test/ach-ack-read/ack-read.ach new file mode 100644 index 000000000..f4ee7cf30 --- /dev/null +++ b/test/ach-ack-read/ack-read.ach @@ -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 \ No newline at end of file diff --git a/test/ach-ack-read/main.go b/test/ach-ack-read/main.go new file mode 100644 index 000000000..a8e1bd0bb --- /dev/null +++ b/test/ach-ack-read/main.go @@ -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()) +} diff --git a/test/ach-ack-read/main_test.go b/test/ach-ack-read/main_test.go new file mode 100644 index 000000000..45fcc779c --- /dev/null +++ b/test/ach-ack-read/main_test.go @@ -0,0 +1,7 @@ +package main + +import "testing" + +func Test(t *testing.T) { + main() +} diff --git a/test/ach-ack-write/main.go b/test/ach-ack-write/main.go new file mode 100644 index 000000000..3e0b7f6c5 --- /dev/null +++ b/test/ach-ack-write/main.go @@ -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() +} diff --git a/test/ach-ack-write/main_test.go b/test/ach-ack-write/main_test.go new file mode 100644 index 000000000..ceb689537 --- /dev/null +++ b/test/ach-ack-write/main_test.go @@ -0,0 +1,8 @@ +package main + +import "testing" + +func Test(t *testing.T) { + main() +} +