This repository is a sample Ruby app. It is not an official Ruby SDK.
The sample uses the moov-io/ach HTTP API to build a NACHA-compliant PPD payroll ACH file. There is no official Ruby client library. This sample calls the API with Net::HTTP. You can also generate a client from the OpenAPI specification.
ACH is used to transfer trillions of dollars annually in the United States. The underlying format sends plaintext files between Financial Institutions and the United States FED.
Example use cases of ACH:
- Direct Deposit from your employer, and government benefits (Social Security)
- Paying a friend via apps (P2P payments)
- Stock / Retirement investments or withdrawals
We offer documentation on how ACH works and Gusto has an excellent four part series on "How ACH works: A developer perspective".
If you need a full stack service that sends ACH files to your bank, see achgateway.
Install these tools before you run the sample:
- Ruby matching the version in
.ruby-version(4.0.10), and Bundler 2.6.9 - The Moov ACH HTTP API, either:
- Docker and the
moov/ach:v1.69.1image, or - the
achserver binary from the moov-io/ach v1.69.1 release
- Docker and the
- Docker Compose v2, if you use the Compose path in this README
-
Clone this repository and go to the project directory:
git clone https://github.com/moov-io/ruby-ach-demo.git cd ruby-ach-demo -
Install the gems into
vendor/bundle:bundle config set path vendor/bundle bundle install -
Start the ACH API in one terminal:
docker run --rm -p 8080:8080 moov/ach:v1.69.1Or run the
achserver binary and listen on port 8080:ach -http.addr :8080 -
In a second terminal, run the sample:
bundle exec ruby main.rbThe sample calls
http://localhost:8080by default. To use a different ACH API, set theACH_URLenvironment variable.
From the project directory:
docker compose up --build --abort-on-container-exit
Compose builds the sample image, starts the ACH API, waits until GET /ping succeeds, and then runs the sample. In Compose, the sample uses ACH_URL=http://ach:8080.
You can also run make && make run. make builds the sample image locally. make run starts the same Compose path.
A successful run prints the file ID and the path of the NACHA file, for example:
Moov ACH Ruby Demo (version v0.1.0-dev)
File ea990a921f240eb71f29d80167a07755 created
Wrote NACHA file to payroll.ach
File validated successfully
The sample writes the NACHA file to payroll.ach in the project directory. Each line is a 94-character record. The file has one File Header, one PPD credit batch with three employee entries, the matching control records, and padding records so the file length is a multiple of 10.
You can also fetch the same file from /files/{id}/contents, or list files at http://localhost:8080/files.
- Wait until
GET /pingreturnsPONG. - Build one PPD credit batch for three employees. The company entry description is
PAYROLL.effectiveEntryDateis the next weekday after today. POSTthe file to/files/create.GETthe file contents and save them aspayroll.ach.GET /files/{id}/validateand exit with an error when theerrorfield is not null.
The sample sends batch and file control records with the entry count, entry hash, and debit and credit totals. POST /files/create recalculates those control records. To check client-supplied totals before Create, see Control totals in the custom validation documentation (ValidateTotals).
The ACH API reference describes every endpoint used in main.rb.
This tutorial is for people who already understand ACH files and want to build one with the Moov ACH API. It does not cover how you send a completed file to your bank.
| channel | info |
|---|---|
| Twitter @moov | You can follow Moov.io's Twitter feed to get updates on our project(s). You can also tweet us questions or just share blogs or stories. |
| GitHub Issue | If you are able to reproduce a problem please open a GitHub Issue under the specific project that caused the error. |
| moov-io slack | Join our slack channel to have an interactive discussion about the development of the project. |
GitHub Actions tests this sample on 64-bit Ubuntu Linux.
Yes please! Please review our Contributing guide and Code of Conduct to get started.
This project is a Ruby sample. Install the Ruby version in .ruby-version, then follow the "Run with Ruby" section in this README.
Apache License 2.0. See LICENSE for details.