Skip to content

About

Automated Clearing House (ACH) demo in ruby

Topics

Resources

Contributing

Security policy

Stars

16 stars

Watchers

5 watching

Forks

Repository files navigation

moov-io/ruby-ach-demo

Build Status Apache 2 licensed

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.

Prerequisites

Install these tools before you run the sample:

Run with Ruby

  1. Clone this repository and go to the project directory:

    git clone https://github.com/moov-io/ruby-ach-demo.git
    cd ruby-ach-demo
    
  2. Install the gems into vendor/bundle:

    bundle config set path vendor/bundle
    bundle install
    
  3. Start the ACH API in one terminal:

    docker run --rm -p 8080:8080 moov/ach:v1.69.1
    

    Or run the ach server binary and listen on port 8080:

    ach -http.addr :8080
    
  4. In a second terminal, run the sample:

    bundle exec ruby main.rb
    

    The sample calls http://localhost:8080 by default. To use a different ACH API, set the ACH_URL environment variable.

Run with Docker Compose

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.

Output

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.

What the sample does

  1. Wait until GET /ping returns PONG.
  2. Build one PPD credit batch for three employees. The company entry description is PAYROLL. effectiveEntryDate is the next weekday after today.
  3. POST the file to /files/create.
  4. GET the file contents and save them as payroll.ach.
  5. GET /files/{id}/validate and exit with an error when the error field 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.

Getting Help

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.

Supported and Tested Platforms

GitHub Actions tests this sample on 64-bit Ubuntu Linux.

Contributing

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.

License

Apache License 2.0. See LICENSE for details.

About

Automated Clearing House (ACH) demo in ruby

Topics

Resources

Contributing

Security policy

Stars

16 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages