forked from moov-io/ach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (38 loc) · 1.66 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"
"github.com/moov-io/ach"
"log"
"os"
)
func main() {
// open a file for reading. Any io.Reader Can be used
f, err := os.Open("atx-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 err := achFile.Create(); err != nil {
fmt.Printf("Could not create 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("Total Amount: %v \n", achFile.Batches[0].GetEntries()[0].Amount)
fmt.Printf("Original Trace Number: %v \n", achFile.Batches[0].GetEntries()[0].OriginalTraceNumberField())
fmt.Printf("Addenda1: %v \n", achFile.Batches[0].GetEntries()[0].Addenda05[0].String())
fmt.Printf("Addenda2: %v \n", achFile.Batches[0].GetEntries()[0].Addenda05[1].String())
fmt.Printf("Total Amount: %v \n", achFile.Batches[0].GetEntries()[1].Amount)
fmt.Printf("Original Trace Number: %v \n", achFile.Batches[0].GetEntries()[1].OriginalTraceNumberField())
fmt.Printf("Addenda1: %v \n", achFile.Batches[0].GetEntries()[1].Addenda05[0].String())
fmt.Printf("Addenda2: %v \n", achFile.Batches[0].GetEntries()[1].Addenda05[1].String())
}