-
Notifications
You must be signed in to change notification settings - Fork 151
/
main.go
88 lines (77 loc) · 3.46 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Licensed to The Moov Authors under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. The Moov Authors licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package main
import (
"log"
"os"
"time"
"github.com/moov-io/ach"
)
func main() {
// Example transfer to write an ACH ENR file acknowledging a credit
// Important: All financial institutions are different and will require registration and exact field values.
// Set originator bank ODFI and destination Operator for the financial institution
// this is the funding/receiving source of the transfer
fh := ach.NewFileHeader()
fh.ImmediateDestination = "031300012" // Routing Number of the ACH Operator or receiving point to which the file is being sent
fh.ImmediateOrigin = "231380104" // Routing Number of the ACH Operator or sending point that is sending the file
fh.ImmediateDestinationName = "Federal Reserve Bank"
fh.ImmediateOriginName = "My Bank Name"
fh.FileCreationDate = time.Now().Format("060102")
// BatchHeader identifies the originating entity and the type of transactions contained in the batch
bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account" // The name of the company/person that has relationship with receiver
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.ENR
bh.CompanyEntryDescription = "AUTOENROLL"
bh.ODFIIdentification = "23138010" // Originating Routing Number
// Identifies the receiver's account information
// can be multiple entries 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 = ach.CheckingDebit
entry.SetRDFI("031300012") // Receiver's bank transit routing number
entry.DFIAccountNumber = "744-5678-99" // Receiver's bank account number
entry.Amount = 0 // Amount of transaction with no decimal. One dollar and eleven cents = 111
entry.SetOriginalTraceNumber("031300010000001")
entry.SetReceivingCompany("Best. #1")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
addenda05 := ach.NewAddenda05()
addenda05.PaymentRelatedInformation = `22*12200004*3*123987654321*777777777*DOE*JOHN*1\` // From NACHA 2013 Official Rules
entry.AddAddenda05(addenda05)
entry.AddendaRecordIndicator = 1
// build the batch
batch := ach.NewBatchENR(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 stdout, any io.Writer can be used
w := ach.NewWriter(os.Stdout)
if err := w.Write(file); err != nil {
log.Fatalf("Unexpected error writing file: %s\n", err)
}
w.Flush()
}