-
Notifications
You must be signed in to change notification settings - Fork 150
/
main.go
64 lines (56 loc) · 2.55 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"github.com/moov-io/ach"
"log"
"os"
"time"
)
func main() {
// Example transfer to write an ACH ARC file to debit an external institutions account
// Important: All financial institutions are different and will require registration and exact field values.
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 = 225 // ACH credit pushes money out, 225 debits/pulls money in.
bh.CompanyName = "Payee Name" // The name of the company/person that has relationship with receiver
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = "ARC" // Consumer destination vs Company CCD
bh.CompanyEntryDescription = "ACH ARC" // 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 27: Debit (withdrawal) from checking account
entry.SetRDFI("231380104") // Receivers bank transit routing number
entry.DFIAccountNumber = "12345678" // Receivers bank account number
entry.Amount = 250000 // Amount of transaction with no decimal. One dollar and eleven cents = 111
entry.SetCheckSerialNumber("123879654")
entry.SetReceivingCompany("ABC Company")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
// build the batch
batch := ach.NewBatchARC(bh)
batch.AddEntry(entry)
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.Write(file); err != nil {
log.Fatalf("Unexpected error: %s\n", err)
}
w.Flush()
}