Skip to content

Commit

Permalink
Merge pull request #220 from bkmoovio/CIE-Test
Browse files Browse the repository at this point in the history
#209 CIE Test
  • Loading branch information
wadearnold authored Jun 20, 2018
2 parents 9a19e94 + cc286bd commit d790296
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 6 deletions.
2 changes: 1 addition & 1 deletion batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
)

// Batch holds the Batch Header and Batch Control and all Entry Records for PPD Entries
// Batch holds the Batch Header and Batch Control and all Entry Records
type batch struct {
// ID is a client defined string used as a reference to this record.
ID string `json:"id"`
Expand Down
2 changes: 1 addition & 1 deletion batchCIE_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func mockCIEEntryDetail() *EntryDetail {
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 25000
entry.IdentificationNumber = "45689033"
entry.IndividualName = "Wade Arnold"
entry.IndividualName = "Receiver Account Name"
entry.SetTraceNumber(mockBatchCIEHeader().ODFIIdentification, 1)
entry.DiscretionaryData = "01"
entry.Category = CategoryForward
Expand Down
10 changes: 10 additions & 0 deletions test/ach-cie-read/cie-credit.ach
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
101 231380104 1210428821806200000A094101Federal Reserve Bank My Bank Name
5220Name on Account 121042882 CIEPayment 180621 0121042880000001
62223138010412345678 0100000000 Receiver Account Name 011121042880000001
705Credit Store Account 00010000001
82200000020023138010000000000000000100000000121042882 121042880000001
9000001000001000000020023138010000000000000000100000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
34 changes: 34 additions & 0 deletions test/ach-cie-read/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"
"github.com/bkmoovio/ach"
"log"
"os"
)

func main() {
// open a file for reading. Any io.Reader Can be used
f, err := os.Open("cie-credit.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("Total Amount Credit: %v \n", achFile.Control.TotalCreditEntryDollarAmountInFile)
fmt.Printf("SEC Code: %v \n", achFile.Batches[0].GetHeader().StandardEntryClassCode)
fmt.Printf("Addenda05: %v \n", achFile.Batches[0].GetEntries()[0].Addendum[0].String())
}
7 changes: 7 additions & 0 deletions test/ach-cie-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()
}
72 changes: 72 additions & 0 deletions test/ach-cie-write/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"github.com/bkmoovio/ach"
"log"
"os"
"time"
)

func main() {
// Example transfer to write an ACH CIE 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 = 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 = "CIE" // 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 = 22 // Code 22: Credit to Store 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.IndividualName = "Receiver Account Name" // Identifies the receiver of the transaction
entry.DiscretionaryData = "01"

addenda05 := ach.NewAddenda05()
addenda05.PaymentRelatedInformation = "Credit Store Account"
addenda05.SequenceNumber = 1
addenda05.EntryDetailSequenceNumber = 0000001

// build the batch
batch := ach.NewBatchCIE(bh)
batch.AddEntry(entry)
batch.GetEntries()[0].AddAddenda(addenda05)
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-cie-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()
}
2 changes: 1 addition & 1 deletion test/ach-pos-read/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func main() {

fmt.Printf("Total Amount Debit: %v \n", achFile.Control.TotalDebitEntryDollarAmountInFile)
fmt.Printf("SEC Code: %v \n", achFile.Batches[0].GetHeader().StandardEntryClassCode)
fmt.Printf("POS Card Transaction Type : %v \n", achFile.Batches[0].GetEntries()[0].DiscretionaryDataField())
fmt.Printf("POS Card Transaction Type: %v \n", achFile.Batches[0].GetEntries()[0].DiscretionaryDataField())
fmt.Printf("POS Trace Number: %v \n", achFile.Batches[0].GetEntries()[0].TraceNumberField())
}
6 changes: 3 additions & 3 deletions test/ach-pos-write/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ func main() {
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 = "POS" // Consumer destination vs Company CCD
bh.CompanyEntryDescription = "REG.SALARY" // will be on receiving accounts statement
bh.StandardEntryClassCode = "POS" // Consumer destination vs Company CCD
bh.CompanyEntryDescription = "Sale" // 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.TransactionCode = 27 // Code 27: 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
Expand Down

0 comments on commit d790296

Please sign in to comment.