From ae041317a70465989d7dcda8dfa7fbd2579b61a3 Mon Sep 17 00:00:00 2001 From: Brooke E Kline Jr Date: Tue, 19 Jun 2018 11:47:13 -0400 Subject: [PATCH] #207 Add write and read SHR Test Add write and read SHR Test --- batchSHR_test.go | 2 +- test/ach-shr-read/main.go | 35 ++++++++++++++ test/ach-shr-read/main_test.go | 7 +++ test/ach-shr-read/shr-debit.ach | 10 ++++ test/ach-shr-write/main.go | 81 +++++++++++++++++++++++++++++++++ test/ach-shr-write/main_test.go | 7 +++ 6 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 test/ach-shr-read/main.go create mode 100644 test/ach-shr-read/main_test.go create mode 100644 test/ach-shr-read/shr-debit.ach create mode 100644 test/ach-shr-write/main.go create mode 100644 test/ach-shr-write/main_test.go diff --git a/batchSHR_test.go b/batchSHR_test.go index 52ea69ddc..ac9bb1db6 100644 --- a/batchSHR_test.go +++ b/batchSHR_test.go @@ -443,7 +443,7 @@ func BenchmarkBatchSHRCardTransactionType(b *testing.B) { func testBatchSHRCardExpirationDateField(t testing.TB) { mockBatch := mockBatchSHR() ts := mockBatch.Entries[0].SHRCardExpirationDateField() - if ts != "0718" { + if ts != "0722" { t.Error("Card Expiration Date is invalid") } } diff --git a/test/ach-shr-read/main.go b/test/ach-shr-read/main.go new file mode 100644 index 000000000..5fe7ccb8d --- /dev/null +++ b/test/ach-shr-read/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "github.com/moov-io/ach" + "log" + "os" +) + +func main() { + // open a file for reading. Any io.Reader Can be used + f, err := os.Open("shr-debit.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("Total Amount Debit: %v \n", achFile.Control.TotalDebitEntryDollarAmountInFile) + fmt.Printf("SEC Code: %v \n", achFile.Batches[0].GetHeader().StandardEntryClassCode) + fmt.Printf("SHR Card Expiration Date: %v \n", achFile.Batches[0].GetEntries()[0].SHRCardExpirationDateField()) + fmt.Printf("SHR Document Reference Number: %v \n", achFile.Batches[0].GetEntries()[0].SHRDocumentReferenceNumberField()) + fmt.Printf("SHR Individual Card Account Number: %v \n", achFile.Batches[0].GetEntries()[0].SHRIndividualCardAccountNumberField()) +} diff --git a/test/ach-shr-read/main_test.go b/test/ach-shr-read/main_test.go new file mode 100644 index 000000000..45fcc779c --- /dev/null +++ b/test/ach-shr-read/main_test.go @@ -0,0 +1,7 @@ +package main + +import "testing" + +func Test(t *testing.T) { + main() +} diff --git a/test/ach-shr-read/shr-debit.ach b/test/ach-shr-read/shr-debit.ach new file mode 100644 index 000000000..b756514cc --- /dev/null +++ b/test/ach-shr-read/shr-debit.ach @@ -0,0 +1,10 @@ +101 231380104 1210428821806190000A094101Federal Reserve Bank My Bank Name +5225Name on Account 121042882 SHRPayment 180620 0121042880000001 +62723138010412345678 01000000000722123456789100001234567891123456789011121042880000001 +702REFONEAREFTERM021000490614123456Target Store 0049 PHILADELPHIA PA121042880000001 +82250000020023138010000100000000000000000000121042882 121042880000001 +9000001000001000000020023138010000100000000000000000000 +9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 +9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 +9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 +9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 \ No newline at end of file diff --git a/test/ach-shr-write/main.go b/test/ach-shr-write/main.go new file mode 100644 index 000000000..2e42bc9a4 --- /dev/null +++ b/test/ach-shr-write/main.go @@ -0,0 +1,81 @@ +package main + +import ( + "github.com/moov-io/ach" + "log" + "os" + "time" +) + +func main() { + // Example transfer to write an ACH SHR file to send/credit a external institutions account + // 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 = "231380104" // Routing Number of the ACH Operator or receiving point to which the file is being sent + fh.ImmediateOrigin = "121042882" // 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 = 225 // 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 = "SHR" // Consumer destination vs Company CCD + bh.CompanyEntryDescription = "Payment" // will be on receiving accounts statement + bh.EffectiveEntryDate = time.Now().AddDate(0, 0, 1) + bh.ODFIIdentification = "121042882" // 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 = 27 // Code 22: Debit (withdrawal) from checking account + entry.SetRDFI("231380104") // Receivers bank transit routing number + entry.DFIAccountNumber = "12345678" // Receivers bank account number + entry.Amount = 100000000 // Amount of transaction with no decimal. One dollar and eleven cents = 111 + entry.SetTraceNumber(bh.ODFIIdentification, 1) + entry.SetSHRCardExpirationDate("0722") + entry.SetSHRDocumentReferenceNumber("12345678910") + entry.SetSHRIndividualCardAccountNumber("1234567891123456789") + entry.DiscretionaryData = "01" + + addenda02 := ach.NewAddenda02() + addenda02.ReferenceInformationOne = "REFONEA" + addenda02.ReferenceInformationTwo = "REF" + addenda02.TerminalIdentificationCode = "TERM02" + addenda02.TransactionSerialNumber = "100049" + addenda02.TransactionDate = "0614" + addenda02.AuthorizationCodeOrExpireDate = "123456" + addenda02.TerminalLocation = "Target Store 0049" + addenda02.TerminalCity = "PHILADELPHIA" + addenda02.TerminalState = "PA" + addenda02.TraceNumber = 121042880000001 + + // build the batch + batch := ach.NewBatchSHR(bh) + batch.AddEntry(entry) + batch.GetEntries()[0].AddAddenda(addenda02) + 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.WriteAll([]*ach.File{file}); err != nil { + log.Fatalf("Unexpected error: %s\n", err) + } + w.Flush() +} diff --git a/test/ach-shr-write/main_test.go b/test/ach-shr-write/main_test.go new file mode 100644 index 000000000..45fcc779c --- /dev/null +++ b/test/ach-shr-write/main_test.go @@ -0,0 +1,7 @@ +package main + +import "testing" + +func Test(t *testing.T) { + main() +}