forked from moov-io/ach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (40 loc) · 1.29 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
42
43
44
45
46
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("enr-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)
batch, ok := achFile.Batches[0].(*ach.BatchENR)
if !ok {
log.Fatalf("Batch not ENR, got %T %#v", achFile.Batches[0], achFile.Batches[0])
}
add := batch.GetEntries()[0].Addenda05[0]
fmt.Printf("Payment Related Information: %v \n", add.PaymentRelatedInformation)
info, err := batch.ParsePaymentInformation(add)
if err != nil {
log.Fatalf("Problem Parsing ENR Addenda05 PaymentRelatedInformation: %v", err)
}
fmt.Println(info.String())
}