Skip to content

Commit

Permalink
Merge pull request #218 from bkmoovio/SHRTest
Browse files Browse the repository at this point in the history
#207 SHR Write and Read tests
  • Loading branch information
wadearnold authored Jun 19, 2018
2 parents 2a0be3d + ae04131 commit b7622ba
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 1 deletion.
2 changes: 1 addition & 1 deletion batchSHR_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
35 changes: 35 additions & 0 deletions test/ach-shr-read/main.go
Original file line number Diff line number Diff line change
@@ -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())
}
7 changes: 7 additions & 0 deletions test/ach-shr-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()
}
10 changes: 10 additions & 0 deletions test/ach-shr-read/shr-debit.ach
Original file line number Diff line number Diff line change
@@ -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
81 changes: 81 additions & 0 deletions test/ach-shr-write/main.go
Original file line number Diff line number Diff line change
@@ -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()
}
7 changes: 7 additions & 0 deletions test/ach-shr-write/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()
}

0 comments on commit b7622ba

Please sign in to comment.