moov-io / ach

ACH implements a reader, writer, and validator for Automated Clearing House (ACH) files. The HTTP server is available in a Docker image and the Go package is available.
https://moov-io.github.io/ach/
Apache License 2.0
459 stars 152 forks source link

file: writing a File with no batches will error #881

Closed vxio closed 3 years ago

vxio commented 3 years ago

What were you trying to do? Write an empty File with a file header and control using NewWriter(io.Writer).Write(f *File)

What did you expect to see The ACH file written to io.Writer

What did you see? Error: BatchCount calculated 0 is out-of-balance with file control 1

What's the use-case? An FI wants an empty file with a file header/control and no transactions to be able to confirm that a communication path with the originator is alive.

vxio commented 3 years ago

Potential implementation: add this as an option in ValidateOpts to bypass the error.

adamdecaf commented 3 years ago

Another implementation for this could be:

fh := ach.NewFileHeader() 
// fill in fields

fc := ach.NewFileControl()
// fill in fields (tricky with EntryHash, etc)

var buf bytes.Buffer
buf.WriteString(fh.String() + "\n")
buf.WriteString(fc.String() + "\n")

// ioutil.WriteFile(path, buf.Bytes(), 0644) 

This would create a two-line file with the fields properly padded. I'm not sure how the file needs to match up with the Nacha spec (e.g. 10 lines with padding, etc)

wadearnold commented 3 years ago

@adamdecaf That is exactly what I was going to recommend when I saw the thread in Slack.

vxio commented 3 years ago

Appreciate the ideas! The Slack member mentioned he's using the HTTP server, so we'll need to enable this there.