forked from moov-io/ach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (37 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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("mte-read.ach")
if err != nil {
log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
panic(fmt.Sprintf("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 err := achFile.Create(); err != nil {
fmt.Printf("Could not create file with read properties: %v", err)
}
fmt.Printf("Total Amount: %v \n", achFile.Batches[0].GetEntries()[0].Amount)
fmt.Printf("SEC Code: %v \n", achFile.Batches[0].GetHeader().StandardEntryClassCode)
fmt.Println("Terminal:")
addenda02 := achFile.Batches[0].GetEntries()[0].Addenda02
fmt.Printf(" IdentificationCode: %s\n", addenda02.TerminalIdentificationCode)
fmt.Printf(" Location: %s\n", addenda02.TerminalLocation)
fmt.Printf(" City: %s\n", addenda02.TerminalCity)
fmt.Printf(" State: %s\n", addenda02.TerminalState)
fmt.Printf(" TransactionSerialNumber: %s\n", addenda02.TransactionSerialNumber)
fmt.Printf("TransactionDate: %s\n", addenda02.TransactionDate)
}