-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_ackWrite_test.go
70 lines (60 loc) · 2.34 KB
/
example_ackWrite_test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"log"
"github.com/moov-io/ach"
)
func Example_ackWrite() {
fh := mockFileHeader()
bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.CreditsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.ACK
bh.CompanyEntryDescription = "Vndr Pay"
bh.EffectiveEntryDate = "190816" // need EffectiveEntryDate to be fixed so it can match output
bh.ODFIIdentification = "23138010"
entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingZeroDollarRemittanceCredit
entry.SetRDFI("031300012")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber("031300010000001")
entry.SetReceivingCompany("Best. #1")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entryOne := ach.NewEntryDetail() // Fee Entry
entryOne.TransactionCode = ach.CheckingZeroDollarRemittanceCredit
entryOne.SetRDFI("031300012")
entryOne.DFIAccountNumber = "744-5678-99"
entryOne.Amount = 0
entryOne.SetOriginalTraceNumber("031300010000002")
entryOne.SetReceivingCompany("Best. #1")
entryOne.SetTraceNumber(bh.ODFIIdentification, 2)
// build the batch
batch := ach.NewBatchACK(bh)
batch.AddEntry(entry)
batch.AddEntry(entryOne)
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)
}
fmt.Println(file.Header.String())
fmt.Println(file.Batches[0].GetHeader().String())
fmt.Println(file.Batches[0].GetEntries()[0].String())
fmt.Println(file.Batches[0].GetEntries()[1].String())
fmt.Println(file.Batches[0].GetControl().String())
fmt.Println(file.Control.String())
// Output:
// 101 031300012 2313801041908161055A094101Federal Reserve Bank My Bank Name 12345678
// 5220Name on Account 231380104 ACKVndr Pay 190816 1231380100000001
// 624031300012744-5678-99 0000000000031300010000001Best. #1 0231380100000001
// 624031300012744-5678-99 0000000000031300010000002Best. #1 0231380100000002
// 82200000020006260002000000000000000000000000231380104 231380100000001
// 9000001000001000000020006260002000000000000000000000000
}