ach

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2018 License: Apache-2.0 Imports: 9 Imported by: 28

README

moov-io/ach

GoDoc Build Status Coverage Status Go Report Card Apache 2 licensed

Package 'moov-io/ach' implements a file reader and writer for parsing ACH Automated Clearing House files. ACH is the primary method of electronic money movement throughout the United States.

Project Status

ACH is under active development but already in production for multiple companies. Please star the project if you are interested in its progress.

  • Library currently supports the reading and writing
    • PPD (Prearranged payment and deposits)
    • WEB (Internet-initiated Entries )
    • CCD (Corporate credit or debit)
    • TEL (Telephone-Initiated Entry)
    • COR (Automated Notification of Change(NOC))
    • Return Entries

Project Roadmap

  • Additional SEC codes will be added based on library users needs. Please open an issue with a valid test file.
  • Review the project issues for more detailed information

Usage and examples

The following is a high level of reading and writing an ach file. Examples exist in projects example folder with more details.

Read a file
// open a file for reading or pass any io.Reader NewReader()
f, err := os.Open("name-of-your-ach-file.ach")
if err != nil {
	log.Panicf("Can not open local file: %s: \n", err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
	fmt.Printf("Issue reading file: %+v \n", err)
}
// ensure we have a validated file structure
if achFile.Validate(); err != nil {
	fmt.Printf("Could not validate entire read file: %v", err)
}
// Check if any Notifications Of Change exist in the file 
if len(achFile.NotificationOfChange) > 0 {
	for _, batch := range achFile.NotificationOfChange {
		a98 := batch.GetEntries()[0].Addendum[0].(*Addenda98)
		println(a98.CorrectedData)
	} 
} 
// Check if any Return Entries exist in the file 
if len(achFile.ReturnEntries) > 0 {
	for _, batch := range achFile.ReturnEntries {
		aReturn := batch.GetEntries()[0].Addendum[0].(*Addenda99)
		println(aReturn.ReturnCode)
	} 
}
Create a file

The following is based on simple file creation

   fh := ach.NewFileHeader()
   fh.ImmediateDestination = "9876543210" // A blank space followed by your ODFI's transit/routing number
   fh.ImmediateOrigin = "1234567890"      // Organization or Company FED ID usually 1 and FEIN/SSN. Assigned by your ODFI
   fh.FileCreationDate = time.Now()     // Todays Date
   fh.ImmediateDestinationName = "Federal Reserve Bank"
   fh.ImmediateOriginName = "My Bank Name")

   file := ach.NewFile()
   file.SetHeader(fh)

Explicitly create a PPD batch file.

Errors only if payment type is not supported

func mockBatchPPDHeader() *BatchHeader {
   bh := NewBatchHeader()
   bh.ServiceClassCode = 220
   bh.StandardEntryClassCode = "PPD"
   bh.CompanyName = "ACME Corporation"
   bh.CompanyIdentification = "123456789"
   bh.CompanyEntryDescription = "PAYROLL"
   bh.EffectiveEntryDate = time.Now()
   bh.ODFIIdentification = "6200001"
   return bh
}

mockBatch := NewBatch(mockBatchPPDHeader())

OR use the NewBatch factory

func mockBatchPPDHeader() *BatchHeader {
   bh := NewBatchHeader()
   bh.ServiceClassCode = 220
   bh.StandardEntryClassCode = "PPD"
   bh.CompanyName = "ACME Corporation"
   bh.CompanyIdentification = "123456789"
   bh.CompanyEntryDescription = "PAYROLL"
   bh.EffectiveEntryDate = time.Now()
   bh.ODFIIdentification = "6200001"
   return bh
}

mockBatch, _ := ach.NewBatch(mockBatchPPDHeader())

To create an entry

entry := ach.NewEntryDetail()
entry.TransactionCode = 22
entry.SetRDFI("009101298")
entry.DFIAccountNumber = "123456789"
entry.Amount = 100000000
entry.IndividualName = "Wade Arnold"
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.IdentificationNumber = "ABC##jvkdjfuiwn"
entry.Category = ach.CategoryForward

To add one or more optional addenda records for an entry

addenda := NewAddenda05()
addenda.PaymentRelatedInformation = "Bonus pay for amazing work on #OSS"

Add the addenda record to the detail entry

entry.AddAddenda(addenda)

Entries are added to batches like so:

batch.AddEntry(entry)

When all of the Entries are added to the batch we can create the batch.

if err := batch.Create(); err != nil {
   fmt.Printf("%T: %s", err, err)
}

And batches are added to files much the same way:

file.AddBatch(batch)

Now add a new batch for accepting payments on the WEB

func mockBatchWEBHeader() *BatchHeader {
	bh := NewBatchHeader()
	bh.ServiceClassCode = 220
	bh.StandardEntryClassCode = "WEB"
	bh.CompanyName = "Your Company, inc"
	bh.CompanyIdentification = "123456789"
	bh.CompanyEntryDescription = "Online Order"
	bh.ODFIIdentification = "6200001"
	return bh
}

batch2, _ := ach.NewBatch(mockBatchWEBHeader())

Add an entry and define if it is a single or reoccurring payment. The following is a reoccurring payment for $7.99

entry2 := ach.NewEntryDetail()
entry2.TransactionCode = 22
entry2.SetRDFI(102001017)
entry2.DFIAccountNumber = "5343121"
entry2.Amount = 799
entry2.IndividualName = "Wade Arnold"
entry2.SetTraceNumber(bh.ODFIIdentification, 1)
entry2.IdentificationNumber = "#123456"
entry.DiscretionaryData = "R"
entry2.Category = ach.CategoryForward


addenda2 := NewAddenda05()
addenda2.PaymentRelatedInformation = "Monthly Membership Subscription"

Add the entry to the batch

entry2.AddAddenda(addenda2)

Create and add the second batch

batch2.AddEntry(entry2)
if err := batch2.Create(); err != nil {
	fmt.Printf("%T: %s", err, err)
}
file.AddBatch(batch2)

Once we added all our batches we must build the file

if err := file.Create(); err != nil {
   fmt.Printf("%T: %s", err, err)
}

Finally we want to write the file to an io.Writer

w := ach.NewWriter(os.Stdout)
if err := w.Write(file); err != nil {
   fmt.Printf("%T: %s", err, err)
}
w.Flush()
}

Which will generate a well formed ACH flat file.

101 210000890 1234567891708290000A094101Your Bank              Your Company           #00000A1
5200Your Company                        123456789 PPDTrans. DesOct 23010101   1234567890000001
6271020010175343121          0000017500#456789        Bob Smith             B11234567890000001
705bonus pay for amazing work on #OSS                                              00010000001
82000000020010200101000000017500000000000000123456789                          234567890000001
5220Your Company                        123456789 WEBsubscr    Oct 23010101   1234567890000002
6221020010175343121          0000000799#123456        Wade Arnold           R 1234567890000001
705Monthly Membership Subscription                                                 00010000001
82200000020010200101000000000000000000000799123456789                          234567890000002
9000002000001000000040020400202000000017500000000000799 

Mailing lists

Users trade notes on the Google group moov-users (send mail to moov-users@googlegroups.com). You must join the moov-usersforumn in order to post.

Contributing

We use GitHub to manage reviews of pull requests.

  • If you have a trivial fix or improvement, go ahead and create a pull request, addressing (with @...) one or more of the maintainers (see AUTHORS.md) in the description of the pull request.

  • If you plan to do something more involved, first propose your ideas in a Github issue. This will avoid unnecessary work and surely give you and us a good deal of inspiration.

  • Relevant coding style guidelines are the Go Code Review Comments and the Formatting and style section of Peter Bourgon's Go: Best Practices for Production Environments.

Additional SEC (Standard Entry Class) code batch types.

SEC type's in the Batch Header record define the payment type of the following Entry Details and Addenda. The format of the records in the batch is the same between all payment types but NACHA defines different rules for the values that are held in each record field. To add support for an additional SEC type you will need to implement NACHA rules for that type. The vast majority of rules are implemented in ach.batch and then composed into Batch(SEC) for reuse. All Batch(SEC) types must be a ach.Batcher.

  1. Create a milestone for the new SEC type that you want supported.
  2. Add issues to that milestone to meet the NACHA rules for the batch type.
  3. Create a new struct of the batch type. In the following example we will use MTE(Machine Transfer Entry) as our example.
  4. The following code would be place in a new file batchMTE.go next to the existing batch types.
  5. The code is stub code and the MTE type is not implemented. For concrete examples review the existing batch types in the source.

Create a new struct and compose ach.batch

type BatchMTE struct {
	batch
}

Add the ability for the new type to be created.

func NewBatchMTE(bh *BatchHeader) *BatchMTE {
	batch := new(BatchMTE)
	batch.setControl(NewBatchControl)
	batch.SetHeader(bh)
	return batch
}

To support the Batcher interface you must add the following functions that are not implemented in ach.batch.

  • Validate() error
  • Create() error

Validate is designed to enforce the NACHA rules for the MTE payment type. Validate is run after a batch of this type is read from a file. If you are creating a batch from code call validate afterwards.

// Validate checks valid NACHA batch rules. Assumes properly parsed records.
func (batch *BatchMTE) Validate() error {
	// basic verification of the batch before we validate specific rules.
	if err := batch.verify(); err != nil {
		return err
	}
	// Add configuration based validation for this type.
	// ... batch.isAddendaCount(1)
	// Add type specific validation.
	// ...
	return nil
}

Create takes the Batch Header and Entry details and creates the proper sequence number and batch control. If additional logic specific to the SEC type is required it building a batch file it should be added here.

// Create takes Batch Header and Entries and builds a valid batch
func (batch *BatchMTE) Create() error {
	// generates sequence numbers and batch control
	if err := batch.build(); err != nil {
		return err
	}
	// Additional steps specific to batch type
	// ...

	if err := batch.Validate(); err != nil {
		return err
	}
	return nil
}

Finally add the batch type to the NewBatch factory in batch.go.

//...
case "MTE":
		return NewBatchMTE(bh), nil
//...

Pull request require a batchMTE_test.go file that covers the logic of the type.

References

Format Specification

ACH File Layout

Inspiration

License

Apache License 2.0 See LICENSE for details.

Documentation

Overview

Package ach reads and writes (ACH) Automated Clearing House files. ACH is the primary method of electronic money movement through the United States.

https://en.wikipedia.org/wiki/Automated_Clearing_House

Index

Constants

View Source
const (
	CategoryForward = "Forward"
	CategoryReturn  = "Return"
	CategoryNOC     = "NOC"
)
View Source
const (

	// RecordLength character count of each line representing a letter in a file
	RecordLength = 94
)

First position of all Record Types. These codes are uniquely assigned to the first byte of each row in a file.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addenda05 added in v0.2.0

type Addenda05 struct {

	// PaymentRelatedInformation
	PaymentRelatedInformation string
	// SequenceNumber is consecutively assigned to each Addenda05 Record following
	// an Entry Detail Record. The first addenda05 sequence number must always
	// be a "1".
	SequenceNumber int
	// EntryDetailSequenceNumber contains the ascending sequence number section of the Entry
	// Detail or Corporate Entry Detail Record's trace number This number is
	// the same as the last seven digits of the trace number of the related
	// Entry Detail Record or Corporate Entry Detail Record.
	EntryDetailSequenceNumber int
	// contains filtered or unexported fields
}

func NewAddenda05 added in v0.2.0

func NewAddenda05() *Addenda05

func (*Addenda05) CalculateCheckDigit added in v0.2.0

func (v *Addenda05) CalculateCheckDigit(routingNumber string) int

CalculateCheckDigit returns a check digit for a routing number Multiply each digit in the Routing number by a weighting factor. The weighting factors for each digit are: Position: 1 2 3 4 5 6 7 8 Weights : 3 7 1 3 7 1 3 7 Add the results of the eight multiplications Subtract the sum from the next highest multiple of 10. The result is the Check Digit

func (*Addenda05) EntryDetailSequenceNumberField added in v0.2.0

func (addenda05 *Addenda05) EntryDetailSequenceNumberField() string

EntryDetailSequenceNumberField returns a zero padded EntryDetailSequenceNumber string

func (*Addenda05) Parse added in v0.2.0

func (addenda05 *Addenda05) Parse(record string)

Parse takes the input record string and parses the Addenda05 values

func (*Addenda05) PaymentRelatedInformationField added in v0.2.0

func (addenda05 *Addenda05) PaymentRelatedInformationField() string

PaymentRelatedInformationField returns a zero padded PaymentRelatedInformation string

func (*Addenda05) SequenceNumberField added in v0.2.0

func (addenda05 *Addenda05) SequenceNumberField() string

SequenceNumberField returns a zero padded SequenceNumber string

func (*Addenda05) SetPaymentRelatedInformation added in v0.2.0

func (addenda05 *Addenda05) SetPaymentRelatedInformation(s string) *Addenda05

SetPaymentRealtedInformation

func (*Addenda05) String added in v0.2.0

func (addenda05 *Addenda05) String() string

String writes the Addenda05 struct to a 94 character string.

func (*Addenda05) TypeCode added in v0.2.0

func (addenda05 *Addenda05) TypeCode() string

TypeCode Defines the specific explanation and format for the addenda05 information

func (*Addenda05) Validate added in v0.2.0

func (addenda05 *Addenda05) Validate() error

Validate performs NACHA format rule checks on the record and returns an error if not Validated The first error encountered is returned and stops that parsing.

type Addenda98 added in v0.2.0

type Addenda98 struct {

	// ChangeCode field contains a standard code used by an ACH Operator or RDFI to describe the reason for a change Entry.
	// Must exist in changeCodeDict
	ChangeCode string
	// OriginalTrace This field contains the Trace Number as originally included on the forward Entry or Prenotification.
	// The RDFI must include the Original Entry Trace Number in the Addenda Record of an Entry being returned to an ODFI,
	// in the Addenda Record of an 98, within an Acknowledgment Entry, or with an RDFI request for a copy of an authorization.
	OriginalTrace int
	// OriginalDFI field contains the Receiving DFI Identification (addenda.RDFIIdentification) as originally included on the forward Entry or Prenotification that the RDFI is returning or correcting.
	OriginalDFI string
	// CorrectedData
	CorrectedData string
	// TraceNumber matches the Entry Detail Trace Number of the entry being returned.
	TraceNumber int
	// contains filtered or unexported fields
}

Addenda98 is a Addendumer addenda record format for Notification OF Change(98) The field contents for Notification of Change Entries must match the field contents of the original Entries

func NewAddenda98 added in v0.2.0

func NewAddenda98() *Addenda98

NewAddenda98 returns an reference to an instantiated Addenda98 with default values

func (*Addenda98) CalculateCheckDigit added in v0.2.0

func (v *Addenda98) CalculateCheckDigit(routingNumber string) int

CalculateCheckDigit returns a check digit for a routing number Multiply each digit in the Routing number by a weighting factor. The weighting factors for each digit are: Position: 1 2 3 4 5 6 7 8 Weights : 3 7 1 3 7 1 3 7 Add the results of the eight multiplications Subtract the sum from the next highest multiple of 10. The result is the Check Digit

func (*Addenda98) CorrectedDataField added in v0.2.0

func (addenda98 *Addenda98) CorrectedDataField() string

CorrectedDataField returns a space padded CorrectedData string

func (*Addenda98) OriginalDFIField added in v0.2.0

func (addenda98 *Addenda98) OriginalDFIField() string

OriginalDFIField returns a zero padded OriginalDFI string

func (*Addenda98) OriginalTraceField added in v0.2.0

func (addenda98 *Addenda98) OriginalTraceField() string

OriginalTraceField returns a zero padded OriginalTrace string

func (*Addenda98) Parse added in v0.2.0

func (addenda98 *Addenda98) Parse(record string)

Parse takes the input record string and parses the Addenda98 values

func (*Addenda98) String added in v0.2.0

func (addenda98 *Addenda98) String() string

String writes the Addenda98 struct to a 94 character string

func (*Addenda98) TraceNumberField added in v0.2.0

func (addenda98 *Addenda98) TraceNumberField() string

TraceNumberField returns a zero padded traceNumber string

func (*Addenda98) TypeCode added in v0.2.0

func (addenda98 *Addenda98) TypeCode() string

TypeCode defines the format of the underlying addenda record

func (*Addenda98) Validate added in v0.2.0

func (addenda98 *Addenda98) Validate() error

Validate verifies NACHA rules for Addenda98

type Addenda99 added in v0.2.0

type Addenda99 struct {

	// ReturnCode field contains a standard code used by an ACH Operator or RDFI to describe the reason for returning an Entry.
	// Must exist in returnCodeDict
	ReturnCode string
	// OriginalTrace This field contains the Trace Number as originally included on the forward Entry or Prenotification.
	// The RDFI must include the Original Entry Trace Number in the Addenda Record of an Entry being returned to an ODFI,
	// in the Addenda Record of an 98, within an Acknowledgment Entry, or with an RDFI request for a copy of an authorization.
	OriginalTrace int
	// DateOfDeath The field date of death is to be supplied on Entries being returned for reason of death (return reason codes R14 and R15).
	DateOfDeath time.Time
	// OriginalDFI field contains the Receiving DFI Identification (addenda.RDFIIdentification) as originally included on the forward Entry or Prenotification that the RDFI is returning or correcting.
	OriginalDFI string
	// AddendaInformation
	AddendaInformation string
	// TraceNumber matches the Entry Detail Trace Number of the entry being returned.
	TraceNumber int
	// contains filtered or unexported fields
}

Addenda99 utilized for Notification of Change Entry (COR) and Return types.

func NewAddenda99 added in v0.2.0

func NewAddenda99() *Addenda99

NewAddenda99 returns a new Addenda99 with default values for none exported fields

func (*Addenda99) AddendaInformationField added in v0.2.0

func (Addenda99 *Addenda99) AddendaInformationField() string

AddendaInformationField returns a space padded AddendaInformation string

func (*Addenda99) CalculateCheckDigit added in v0.2.0

func (v *Addenda99) CalculateCheckDigit(routingNumber string) int

CalculateCheckDigit returns a check digit for a routing number Multiply each digit in the Routing number by a weighting factor. The weighting factors for each digit are: Position: 1 2 3 4 5 6 7 8 Weights : 3 7 1 3 7 1 3 7 Add the results of the eight multiplications Subtract the sum from the next highest multiple of 10. The result is the Check Digit

func (*Addenda99) DateOfDeathField added in v0.2.0

func (Addenda99 *Addenda99) DateOfDeathField() string

DateOfDeathField returns a space padded DateOfDeath string

func (*Addenda99) OriginalDFIField added in v0.2.0

func (Addenda99 *Addenda99) OriginalDFIField() string

OriginalDFIField returns a zero padded OriginalDFI string

func (*Addenda99) OriginalTraceField added in v0.2.0

func (Addenda99 *Addenda99) OriginalTraceField() string

OriginalTraceField returns a zero padded OriginalTrace string

func (*Addenda99) Parse added in v0.2.0

func (Addenda99 *Addenda99) Parse(record string)

Parse takes the input record string and parses the Addenda99 values

func (*Addenda99) String added in v0.2.0

func (Addenda99 *Addenda99) String() string

String writes the Addenda99 struct to a 94 character string

func (*Addenda99) TraceNumberField added in v0.2.0

func (Addenda99 *Addenda99) TraceNumberField() string

TraceNumberField returns a zero padded traceNumber string

func (*Addenda99) TypeCode added in v0.2.0

func (Addenda99 *Addenda99) TypeCode() string

TypeCode defines the format of the underlying addenda record

func (*Addenda99) Validate added in v0.2.0

func (Addenda99 *Addenda99) Validate() error

Validate verifies NACHA rules for Addenda99

type Addendumer

type Addendumer interface {
	Parse(string)
	//TypeCode Defines the specific explanation and format for the addenda information
	TypeCode() string
	String() string
	Validate() error
}

Addendumer abstracts the different ACH addendum types that can be added to an EntryDetail record

type BatchCCD

type BatchCCD struct {
	// contains filtered or unexported fields
}

BatchCCD is a batch file that handles SEC payment type CCD amd CCD+. Corporate credit or debit. Identifies an Entry initiated by an Organization to transfer funds to or from an account of that Organization or another Organization. For commercial accounts only.

func NewBatchCCD

func NewBatchCCD(bh *BatchHeader) *BatchCCD

NewBatchCCD returns a *BatchCCD

func (*BatchCCD) AddEntry

func (batch *BatchCCD) AddEntry(entry *EntryDetail)

AddEntry appends an EntryDetail to the Batch

func (*BatchCCD) Category

func (batch *BatchCCD) Category() string

IsReturn is true if the batch contains an Entry Return

func (*BatchCCD) Create

func (batch *BatchCCD) Create() error

Create builds the batch sequence numbers and batch control. Additional creation

func (*BatchCCD) GetControl

func (batch *BatchCCD) GetControl() *BatchControl

GetControl returns the current Batch Control

func (*BatchCCD) GetEntries

func (batch *BatchCCD) GetEntries() []*EntryDetail

GetEntries returns a slice of entry details for the batch

func (*BatchCCD) GetHeader

func (batch *BatchCCD) GetHeader() *BatchHeader

GetHeader returns the current Batch header

func (*BatchCCD) SetControl

func (batch *BatchCCD) SetControl(batchControl *BatchControl)

SetControl appends an BatchControl to the Batch

func (*BatchCCD) SetHeader

func (batch *BatchCCD) SetHeader(batchHeader *BatchHeader)

SetHeader appends an BatchHeader to the Batch

func (*BatchCCD) Validate

func (batch *BatchCCD) Validate() error

Validate ensures the batch meets NACHA rules specific to this batch type.

type BatchCOR

type BatchCOR struct {
	// contains filtered or unexported fields
}

BatchCOR COR - Automated Notification of Change (NOC) or Refused Notification of Change This Standard Entry Class Code is used by an RDFI or ODFI when originating a Notification of Change or Refused Notification of Change in automated format. A Notification of Change may be created by an RDFI to notify the ODFI that a posted Entry or Prenotification Entry contains invalid or erroneous information and should be changed.

func NewBatchCOR

func NewBatchCOR(bh *BatchHeader) *BatchCOR

NewBatchCOR returns a *BatchCOR

func (*BatchCOR) AddEntry

func (batch *BatchCOR) AddEntry(entry *EntryDetail)

AddEntry appends an EntryDetail to the Batch

func (*BatchCOR) Category

func (batch *BatchCOR) Category() string

IsReturn is true if the batch contains an Entry Return

func (*BatchCOR) Create

func (batch *BatchCOR) Create() error

Create builds the batch sequence numbers and batch control. Additional creation

func (*BatchCOR) GetControl

func (batch *BatchCOR) GetControl() *BatchControl

GetControl returns the current Batch Control

func (*BatchCOR) GetEntries

func (batch *BatchCOR) GetEntries() []*EntryDetail

GetEntries returns a slice of entry details for the batch

func (*BatchCOR) GetHeader

func (batch *BatchCOR) GetHeader() *BatchHeader

GetHeader returns the current Batch header

func (*BatchCOR) SetControl

func (batch *BatchCOR) SetControl(batchControl *BatchControl)

SetControl appends an BatchControl to the Batch

func (*BatchCOR) SetHeader

func (batch *BatchCOR) SetHeader(batchHeader *BatchHeader)

SetHeader appends an BatchHeader to the Batch

func (*BatchCOR) Validate

func (batch *BatchCOR) Validate() error

Validate ensures the batch meets NACHA rules specific to this batch type.

type BatchControl

type BatchControl struct {

	// ServiceClassCode ACH Mixed Debits and Credits ‘200’
	// ACH Credits Only ‘220’
	// ACH Debits Only ‘225'
	// Same as 'ServiceClassCode' in BatchHeaderRecord
	ServiceClassCode int
	// EntryAddendaCount is a tally of each Entry Detail Record and each Addenda
	// Record processed, within either the batch or file as appropriate.
	EntryAddendaCount int
	// validate the Receiving DFI Identification in each Entry Detail Record is hashed
	// to provide a check against inadvertent alteration of data contents due
	// to hardware failure or program erro
	//
	// In this context the Entry Hash is the sum of the corresponding fields in the
	// Entry Detail Records on the file.
	EntryHash int
	// TotalDebitEntryDollarAmount Contains accumulated Entry debit totals within the batch.
	TotalDebitEntryDollarAmount int
	// TotalCreditEntryDollarAmount Contains accumulated Entry credit totals within the batch.
	TotalCreditEntryDollarAmount int
	// CompanyIdentification is an alphameric code used to identify an Originato
	// The Company Identification Field must be included on all
	// prenotification records and on each entry initiated puruant to such
	// prenotification. The Company ID may begin with the ANSI one-digit
	// Identification Code Designators (ICD), followed by the identification
	// numbe The ANSI Identification Numbers and related Identification Code
	// Designators (ICD) are:
	//
	// IRS Employer Identification Number (EIN) "1"
	// Data Universal Numbering Systems (DUNS) "3"
	// User Assigned Number "9"
	CompanyIdentification string
	// MessageAuthenticationCode the MAC is an eight character code derived from a special key used in
	// conjunction with the DES algorithm. The purpose of the MAC is to
	// validate the authenticity of ACH entries. The DES algorithm and key
	// message standards must be in accordance with standards adopted by the
	// American National Standards Institute. The remaining eleven characters
	// of this field are blank.
	MessageAuthenticationCode string

	// OdfiIdentification the routing number is used to identify the DFI originating entries within a given branch.
	ODFIIdentification string
	// BatchNumber this number is assigned in ascending sequence to each batch by the ODFI
	// or its Sending Point in a given file of entries. Since the batch number
	// in the Batch Header Record and the Batch Control Record is the same,
	// the ascending sequence number should be assigned by batch and not by record.
	BatchNumber int
	// contains filtered or unexported fields
}

BatchControl contains entry counts, dollar total and has totals for all entries contained in the preceding batch

func NewBatchControl

func NewBatchControl() *BatchControl

NewBatchControl returns a new BatchControl with default values for none exported fields

func (*BatchControl) BatchNumberField

func (bc *BatchControl) BatchNumberField() string

BatchNumberField gets a string of the batch number zero padded

func (*BatchControl) CalculateCheckDigit

func (v *BatchControl) CalculateCheckDigit(routingNumber string) int

CalculateCheckDigit returns a check digit for a routing number Multiply each digit in the Routing number by a weighting factor. The weighting factors for each digit are: Position: 1 2 3 4 5 6 7 8 Weights : 3 7 1 3 7 1 3 7 Add the results of the eight multiplications Subtract the sum from the next highest multiple of 10. The result is the Check Digit

func (*BatchControl) CompanyIdentificationField

func (bc *BatchControl) CompanyIdentificationField() string

CompanyIdentificationField get the CompanyIdentification righ padded

func (*BatchControl) EntryAddendaCountField

func (bc *BatchControl) EntryAddendaCountField() string

EntryAddendaCountField gets a string of the addenda count zero padded

func (*BatchControl) EntryHashField

func (bc *BatchControl) EntryHashField() string

EntryHashField get a zero padded EntryHash

func (*BatchControl) MessageAuthenticationCodeField

func (bc *BatchControl) MessageAuthenticationCodeField() string

MessageAuthenticationCodeField get the MessageAuthenticationCode right padded

func (*BatchControl) ODFIIdentificationField

func (bc *BatchControl) ODFIIdentificationField() string

ODFIIdentificationField get the odfi number zero padded

func (*BatchControl) Parse

func (bc *BatchControl) Parse(record string)

Parse takes the input record string and parses the EntryDetail values

func (*BatchControl) String

func (bc *BatchControl) String() string

String writes the BatchControl struct to a 94 character string.

func (*BatchControl) TotalCreditEntryDollarAmountField

func (bc *BatchControl) TotalCreditEntryDollarAmountField() string

TotalCreditEntryDollarAmountField get a zero padded Credit Entry Amount

func (*BatchControl) TotalDebitEntryDollarAmountField

func (bc *BatchControl) TotalDebitEntryDollarAmountField() string

TotalDebitEntryDollarAmountField get a zero padded Debity Entry Amount

func (*BatchControl) Validate

func (bc *BatchControl) Validate() error

Validate performs NACHA format rule checks on the record and returns an error if not Validated The first error encountered is returned and stops that parsing.

type BatchError

type BatchError struct {
	BatchNumber int
	FieldName   string
	Msg         string
}

BatchError is an Error that describes batch validation issues

func (*BatchError) Error

func (e *BatchError) Error() string

type BatchHeader

type BatchHeader struct {

	// ServiceClassCode ACH Mixed Debits and Credits ‘200’
	// ACH Credits Only ‘220’
	// ACH Debits Only ‘225'
	ServiceClassCode int

	// CompanyName the company originating the entries in the batch
	CompanyName string

	// CompanyDiscretionaryData allows Originators and/or ODFIs to include codes (one or more),
	// of significance only to them, to enable specialized handling of all
	// subsequent entries in that batch. There will be no standardized
	// interpretation for the value of the field. This field must be returned
	// intact on any return entry.
	CompanyDiscretionaryData string

	// CompanyIdentification The 9 digit FEIN number (proceeded by a predetermined
	// alpha or numeric character) of the entity in the company name field
	CompanyIdentification string

	// StandardEntryClassCode
	// Identifies the payment type (product) found within an ACH batch-using a 3-character code.
	// The SEC Code pertains to all items within batch.
	// Determines format of the detail records.
	// Determines addenda records (required or optional PLUS one or up to 9,999 records).
	// Determines rules to follow (return time frames).
	// Some SEC codes require specific data in predetermined fields within the ACH record
	StandardEntryClassCode string

	// CompanyEntryDescription A description of the entries contained in the batch
	//
	//The Originator establishes the value of this field to provide a
	// description of the purpose of the entry to be displayed back to
	// the receive For example, "GAS BILL," "REG. SALARY," "INS. PREM,"
	// "SOC. SEC.," "DTC," "TRADE PAY," "PURCHASE," etc.
	//
	// This field must contain the word "REVERSAL" (left justified) when the
	// batch contains reversing entries.
	//
	// This field must contain the word "RECLAIM" (left justified) when the
	// batch contains reclamation entries.
	//
	// This field must contain the word "NONSETTLED" (left justified) when the
	// batch contains entries which could not settle.
	CompanyEntryDescription string

	// CompanyDescriptiveDate except as otherwise noted below, the Originator establishes this field
	// as the date it would like to see displayed to the receiver for
	// descriptive purposes. This field is never used to control timing of any
	// computer or manual operation. It is solely for descriptive purposes.
	// The RDFI should not assume any specific format. Examples of possible
	// entries in this field are "011392,", "01 92," "JAN 13," "JAN 92," etc.
	CompanyDescriptiveDate string

	// EffectiveEntryDate the date on which the entries are to settle
	EffectiveEntryDate time.Time

	// OriginatorStatusCode refers to the ODFI initiating the Entry.
	// 0 ADV File prepared by an ACH Operator.
	// 1 This code identifies the Originator as a depository financial institution.
	// 2 This code identifies the Originator as a Federal Government entity or agency.
	OriginatorStatusCode int

	//ODFIIdentification First 8 digits of the originating DFI transit routing number
	ODFIIdentification string

	// BatchNumber is assigned in ascending sequence to each batch by the ODFI
	// or its Sending Point in a given file of entries. Since the batch number
	// in the Batch Header Record and the Batch Control Record is the same,
	// the ascending sequence number should be assigned by batch and not by
	// record.
	BatchNumber int
	// contains filtered or unexported fields
}

BatchHeader identifies the originating entity and the type of transactions contained in the batch (i.e., the standard entry class, PPD for consumer, CCD or CTX for corporate). This record also contains the effective date, or desired settlement date, for all entries contained in this batch. The settlement date field is not entered as it is determined by the ACH operator

func NewBatchHeader

func NewBatchHeader() *BatchHeader

NewBatchHeader returns a new BatchHeader with default values for non exported fields

func (*BatchHeader) BatchNumberField

func (bh *BatchHeader) BatchNumberField() string

BatchNumberField get the batch number zero padded

func (*BatchHeader) CalculateCheckDigit

func (v *BatchHeader) CalculateCheckDigit(routingNumber string) int

CalculateCheckDigit returns a check digit for a routing number Multiply each digit in the Routing number by a weighting factor. The weighting factors for each digit are: Position: 1 2 3 4 5 6 7 8 Weights : 3 7 1 3 7 1 3 7 Add the results of the eight multiplications Subtract the sum from the next highest multiple of 10. The result is the Check Digit

func (*BatchHeader) CompanyDescriptiveDateField

func (bh *BatchHeader) CompanyDescriptiveDateField() string

CompanyDescriptiveDateField get the CompanyDescriptiveDate left padded

func (*BatchHeader) CompanyDiscretionaryDataField

func (bh *BatchHeader) CompanyDiscretionaryDataField() string

CompanyDiscretionaryDataField get the CompanyDiscretionaryData left padded

func (*BatchHeader) CompanyEntryDescriptionField

func (bh *BatchHeader) CompanyEntryDescriptionField() string

CompanyEntryDescriptionField get the CompanyEntryDescription left padded

func (*BatchHeader) CompanyIdentificationField

func (bh *BatchHeader) CompanyIdentificationField() string

CompanyIdentificationField get the CompanyIdentification left padded

func (*BatchHeader) CompanyNameField

func (bh *BatchHeader) CompanyNameField() string

CompanyNameField get the CompanyName left padded

func (*BatchHeader) EffectiveEntryDateField

func (bh *BatchHeader) EffectiveEntryDateField() string

EffectiveEntryDateField get the EffectiveEntryDate in YYMMDD format

func (*BatchHeader) ODFIIdentificationField

func (bh *BatchHeader) ODFIIdentificationField() string

ODFIIdentificationField get the odfi number zero padded

func (*BatchHeader) Parse

func (bh *BatchHeader) Parse(record string)

Parse takes the input record string and parses the BatchHeader values

func (*BatchHeader) String

func (bh *BatchHeader) String() string

String writes the BatchHeader struct to a 94 character string.

func (*BatchHeader) Validate

func (bh *BatchHeader) Validate() error

Validate performs NACHA format rule checks on the record and returns an error if not Validated The first error encountered is returned and stops that parsing.

type BatchPPD

type BatchPPD struct {
	// contains filtered or unexported fields
}

BatchPPD holds the Batch Header and Batch Control and all Entry Records for PPD Entries

func NewBatchPPD

func NewBatchPPD(bh *BatchHeader) *BatchPPD

NewBatchPPD returns a *BatchPPD

func (*BatchPPD) AddEntry

func (batch *BatchPPD) AddEntry(entry *EntryDetail)

AddEntry appends an EntryDetail to the Batch

func (*BatchPPD) Category

func (batch *BatchPPD) Category() string

IsReturn is true if the batch contains an Entry Return

func (*BatchPPD) Create

func (batch *BatchPPD) Create() error

Create takes Batch Header and Entries and builds a valid batch

func (*BatchPPD) GetControl

func (batch *BatchPPD) GetControl() *BatchControl

GetControl returns the current Batch Control

func (*BatchPPD) GetEntries

func (batch *BatchPPD) GetEntries() []*EntryDetail

GetEntries returns a slice of entry details for the batch

func (*BatchPPD) GetHeader

func (batch *BatchPPD) GetHeader() *BatchHeader

GetHeader returns the current Batch header

func (*BatchPPD) SetControl

func (batch *BatchPPD) SetControl(batchControl *BatchControl)

SetControl appends an BatchControl to the Batch

func (*BatchPPD) SetHeader

func (batch *BatchPPD) SetHeader(batchHeader *BatchHeader)

SetHeader appends an BatchHeader to the Batch

func (*BatchPPD) Validate

func (batch *BatchPPD) Validate() error

Validate checks valid NACHA batch rules. Assumes properly parsed records.

type BatchTEL added in v0.2.0

type BatchTEL struct {
	// contains filtered or unexported fields
}

BatchTEL is a batch that handles SEC payment type Telephone-Initiated Entries (TEL) Telephone-Initiated Entries (TEL) are consumer debit transactions. The NACHA Operating Rules permit TEL entries when the Originator obtains the Receiver’s authorization for the debit entry orally via the telephone. An entry based upon a Receiver’s oral authorization must utilize the TEL (Telephone-Initiated Entry) Standard Entry Class (SEC) Code.

func NewBatchTEL added in v0.2.0

func NewBatchTEL(bh *BatchHeader) *BatchTEL

NewBatchTEL returns a *BatchTEL

func (*BatchTEL) AddEntry added in v0.2.0

func (batch *BatchTEL) AddEntry(entry *EntryDetail)

AddEntry appends an EntryDetail to the Batch

func (*BatchTEL) Category added in v0.2.0

func (batch *BatchTEL) Category() string

IsReturn is true if the batch contains an Entry Return

func (*BatchTEL) Create added in v0.2.0

func (batch *BatchTEL) Create() error

Create builds the batch sequence numbers and batch control. Additional creation

func (*BatchTEL) GetControl added in v0.2.0

func (batch *BatchTEL) GetControl() *BatchControl

GetControl returns the current Batch Control

func (*BatchTEL) GetEntries added in v0.2.0

func (batch *BatchTEL) GetEntries() []*EntryDetail

GetEntries returns a slice of entry details for the batch

func (*BatchTEL) GetHeader added in v0.2.0

func (batch *BatchTEL) GetHeader() *BatchHeader

GetHeader returns the current Batch header

func (*BatchTEL) SetControl added in v0.2.0

func (batch *BatchTEL) SetControl(batchControl *BatchControl)

SetControl appends an BatchControl to the Batch

func (*BatchTEL) SetHeader added in v0.2.0

func (batch *BatchTEL) SetHeader(batchHeader *BatchHeader)

SetHeader appends an BatchHeader to the Batch

func (*BatchTEL) Validate added in v0.2.0

func (batch *BatchTEL) Validate() error

Validate ensures the batch meets NACHA rules specific to the SEC type TEL

type BatchWEB

type BatchWEB struct {
	// contains filtered or unexported fields
}

BatchWEB creates a batch file that handles SEC payment type WEB. Entry submitted pursuant to an authorization obtained solely via the Internet or a wireless network For consumer accounts only.

func NewBatchWEB

func NewBatchWEB(bh *BatchHeader) *BatchWEB

NewBatchWEB returns a *BatchWEB

func (*BatchWEB) AddEntry

func (batch *BatchWEB) AddEntry(entry *EntryDetail)

AddEntry appends an EntryDetail to the Batch

func (*BatchWEB) Category

func (batch *BatchWEB) Category() string

IsReturn is true if the batch contains an Entry Return

func (*BatchWEB) Create

func (batch *BatchWEB) Create() error

Create builds the batch sequence numbers and batch control. Additional creation

func (*BatchWEB) GetControl

func (batch *BatchWEB) GetControl() *BatchControl

GetControl returns the current Batch Control

func (*BatchWEB) GetEntries

func (batch *BatchWEB) GetEntries() []*EntryDetail

GetEntries returns a slice of entry details for the batch

func (*BatchWEB) GetHeader

func (batch *BatchWEB) GetHeader() *BatchHeader

GetHeader returns the current Batch header

func (*BatchWEB) SetControl

func (batch *BatchWEB) SetControl(batchControl *BatchControl)

SetControl appends an BatchControl to the Batch

func (*BatchWEB) SetHeader

func (batch *BatchWEB) SetHeader(batchHeader *BatchHeader)

SetHeader appends an BatchHeader to the Batch

func (*BatchWEB) Validate

func (batch *BatchWEB) Validate() error

Validate ensures the batch meets NACHA rules specific to this batch type.

type Batcher

type Batcher interface {
	GetHeader() *BatchHeader
	SetHeader(*BatchHeader)
	GetControl() *BatchControl
	SetControl(*BatchControl)
	GetEntries() []*EntryDetail
	AddEntry(*EntryDetail)
	Create() error
	Validate() error
	// Category defines if a Forward or Return
	Category() string
}

Batcher abstract the different ACH batch types that can exist in a file. Each batch type is defined by SEC (Standard Entry Class) code in the Batch Header * SEC identifies the payment type (product) found within an ACH batch-using a 3-character code * The SEC Code pertains to all items within batch

  • Determines format of the entry detail records
  • Determines addenda records (required or optional PLUS one or up to 9,999 records)
  • Determines rules to follow (return timeframes)
  • Some SEC codes require specific data in predetermined fields within the ACH record

func NewBatch

func NewBatch(bh *BatchHeader) (Batcher, error)

NewBatch takes a BatchHeader and returns a matching SEC code batch type that is a batcher. Returns an error if the SEC code is not supported.

type EntryDetail

type EntryDetail struct {

	// TransactionCode if the receivers account is:
	// Credit (deposit) to checking account ‘22’
	// Prenote for credit to checking account ‘23’
	// Debit (withdrawal) to checking account ‘27’
	// Prenote for debit to checking account ‘28’
	// Credit to savings account ‘32’
	// Prenote for credit to savings account ‘33’
	// Debit to savings account ‘37’
	// Prenote for debit to savings account ‘38’
	TransactionCode int

	// RDFIIdentification is the RDFI's routing number without the last digit.
	// Receiving Depository Financial Institution
	RDFIIdentification string

	// CheckDigit the last digit of the RDFI's routing number
	CheckDigit string

	// DFIAccountNumber is the receiver's bank account number you are crediting/debiting.
	// It important to note that this is an alphanumeric field, so its space padded, no zero padded
	DFIAccountNumber string

	// Amount Number of cents you are debiting/crediting this account
	Amount int

	// IdentificationNumber n internal identification (alphanumeric) that
	// you use to uniquely identify this Entry Detail Record
	IdentificationNumber string

	// IndividualName The name of the receiver, usually the name on the bank account
	IndividualName string

	// DiscretionaryData allows ODFIs to include codes, of significance only to them,
	// to enable specialized handling of the entry. There will be no
	// standardized interpretation for the value of this field. It can either
	// be a single two-character code, or two distinct one-character codes,
	// according to the needs of the ODFI and/or Originator involved. This
	// field must be returned intact for any returned entry.
	//
	// WEB uses the Discretionary Data Field as the Payment Type Code
	DiscretionaryData string

	// AddendaRecordIndicator indicates the existence of an Addenda Record.
	// A value of "1" indicates that one ore more addenda records follow,
	// and "0" means no such record is present.
	AddendaRecordIndicator int

	// TraceNumber assigned by the ODFI in ascending sequence, is included in each
	// Entry Detail Record, Corporate Entry Detail Record, and addenda Record.
	// Trace Numbers uniquely identify each entry within a batch in an ACH input file.
	// In association with the Batch Number, transmission (File Creation) Date,
	// and File ID Modifier, the Trace Number uniquely identifies an entry within a given file.
	// For addenda Records, the Trace Number will be identical to the Trace Number
	// in the associated Entry Detail Record, since the Trace Number is associated
	// with an entry or item rather than a physical record.
	TraceNumber int

	// Addendum a list of Addenda for the Entry Detail
	Addendum []Addendumer
	// Category defines if the entry is a Forward, Return, or NOC
	Category string
	// contains filtered or unexported fields
}

EntryDetail contains the actual transaction data for an individual entry. Fields include those designating the entry as a deposit (credit) or withdrawal (debit), the transit routing number for the entry recipient’s financial institution, the account number (left justify,no zero fill), name, and dollar amount.

func NewEntryDetail

func NewEntryDetail() *EntryDetail

NewEntryDetail returns a new EntryDetail with default values for non exported fields

func (*EntryDetail) AddAddenda

func (ed *EntryDetail) AddAddenda(addenda Addendumer) []Addendumer

AddAddenda appends an Addendumer to the EntryDetail

func (*EntryDetail) AmountField

func (ed *EntryDetail) AmountField() string

AmountField returns a zero padded string of amount

func (*EntryDetail) CalculateCheckDigit

func (v *EntryDetail) CalculateCheckDigit(routingNumber string) int

CalculateCheckDigit returns a check digit for a routing number Multiply each digit in the Routing number by a weighting factor. The weighting factors for each digit are: Position: 1 2 3 4 5 6 7 8 Weights : 3 7 1 3 7 1 3 7 Add the results of the eight multiplications Subtract the sum from the next highest multiple of 10. The result is the Check Digit

func (*EntryDetail) CreditOrDebit added in v0.2.0

func (ed *EntryDetail) CreditOrDebit() string

CreditOrDebit returns a "C" for credit or "D" for debit based on the entry TransactionCode

func (*EntryDetail) DFIAccountNumberField

func (ed *EntryDetail) DFIAccountNumberField() string

DFIAccountNumberField gets the DFIAccountNumber with space padding

func (*EntryDetail) DiscretionaryDataField

func (ed *EntryDetail) DiscretionaryDataField() string

DiscretionaryDataField returns a space padded string of DiscretionaryData

func (*EntryDetail) IdentificationNumberField

func (ed *EntryDetail) IdentificationNumberField() string

IdentificationNumberField returns a space padded string of IdentificationNumber

func (*EntryDetail) IndividualNameField

func (ed *EntryDetail) IndividualNameField() string

IndividualNameField returns a space padded string of IndividualName

func (*EntryDetail) Parse

func (ed *EntryDetail) Parse(record string)

Parse takes the input record string and parses the EntryDetail values

func (*EntryDetail) PaymentTypeField

func (ed *EntryDetail) PaymentTypeField() string

PaymentTypeField returns the discretionary data field used in WEB batch files

func (*EntryDetail) RDFIIdentificationField

func (ed *EntryDetail) RDFIIdentificationField() string

RDFIIdentificationField get the rdfiIdentification with zero padding

func (*EntryDetail) ReceivingCompanyField

func (ed *EntryDetail) ReceivingCompanyField() string

ReceivingCompanyField is used in CCD files but returns the underlying IndividualName field

func (*EntryDetail) SetPaymentType

func (ed *EntryDetail) SetPaymentType(t string)

SetPaymentType as R (Recurring) all other values will result in S (single)

func (*EntryDetail) SetRDFI

func (ed *EntryDetail) SetRDFI(rdfi string) *EntryDetail

SetRDFI takes the 9 digit RDFI account number and separates it for RDFIIdentification and CheckDigit

func (*EntryDetail) SetReceivingCompany

func (ed *EntryDetail) SetReceivingCompany(s string)

SetReceivingCompany setter for CCD receiving company individual name

func (*EntryDetail) SetTraceNumber added in v0.2.0

func (ed *EntryDetail) SetTraceNumber(ODFIIdentification string, seq int)

SetTraceNumber takes first 8 digits of ODFI and concatenates a sequence number onto the TraceNumber

func (*EntryDetail) String

func (ed *EntryDetail) String() string

String writes the EntryDetail struct to a 94 character string.

func (*EntryDetail) TraceNumberField

func (ed *EntryDetail) TraceNumberField() string

TraceNumberField returns a zero padded traceNumber string

func (*EntryDetail) Validate

func (ed *EntryDetail) Validate() error

Validate performs NACHA format rule checks on the record and returns an error if not Validated The first error encountered is returned and stops that parsing.

type FieldError

type FieldError struct {
	FieldName string // field name where error happened
	Value     string // value that cause error
	Msg       string // context of the error.
}

FieldError is returned for errors at a field level in a record

func (*FieldError) Error

func (e *FieldError) Error() string

Error message is constructed FieldName Msg Value Example1: BatchCount $% has none alphanumeric characters Example2: BatchCount 5 is out-of-balance with file count 6

type File

type File struct {
	Header  FileHeader
	Batches []Batcher
	Control FileControl

	// NotificationOfChange (Notification of change) is a slice of references to BatchCOR in file.Batches
	NotificationOfChange []*BatchCOR
	// ReturnEntries is a slice of references to file.Batches that contain return entires
	ReturnEntries []Batcher
	// contains filtered or unexported fields
}

File contains the structures of a parsed ACH File.

func NewFile

func NewFile() *File

NewFile constructs a file template.

func (*File) AddBatch

func (f *File) AddBatch(batch Batcher) []Batcher

AddBatch appends a Batch to the ach.File

func (*File) Create

func (f *File) Create() error

Create creates a valid file and requires that the FileHeader and at least one Batch

func (*File) SetHeader

func (f *File) SetHeader(h FileHeader) *File

SetHeader allows for header to be built.

func (*File) Validate

func (f *File) Validate() error

Validate NACHA rules on the entire batch before being added to a File

type FileControl

type FileControl struct {

	// BatchCount total number of batches (i.e., ‘5’ records) in the file
	BatchCount int

	// BlockCount total number of records in the file (include all headers and trailer) divided
	// by 10 (This number must be evenly divisible by 10. If not, additional records consisting of all 9’s are added to the file after the initial ‘9’ record to fill out the block 10.)
	BlockCount int

	// EntryAddendaCount total detail and addenda records in the file
	EntryAddendaCount int

	// EntryHash calculated in the same manner as the batch has total but includes total from entire file
	EntryHash int

	// TotalDebitEntryDollarAmountInFile contains accumulated Batch debit totals within the file.
	TotalDebitEntryDollarAmountInFile int

	// TotalCreditEntryDollarAmountInFile contains accumulated Batch credit totals within the file.
	TotalCreditEntryDollarAmountInFile int
	// contains filtered or unexported fields
}

FileControl record contains entry counts, dollar totals and hash totals accumulated from each batch control record in the file.

func NewFileControl

func NewFileControl() FileControl

NewFileControl returns a new FileControl with default values for none exported fields

func (*FileControl) BatchCountField

func (fc *FileControl) BatchCountField() string

BatchCountField gets a string of the batch count zero padded

func (*FileControl) BlockCountField

func (fc *FileControl) BlockCountField() string

BlockCountField gets a string of the block count zero padded

func (*FileControl) CalculateCheckDigit

func (v *FileControl) CalculateCheckDigit(routingNumber string) int

CalculateCheckDigit returns a check digit for a routing number Multiply each digit in the Routing number by a weighting factor. The weighting factors for each digit are: Position: 1 2 3 4 5 6 7 8 Weights : 3 7 1 3 7 1 3 7 Add the results of the eight multiplications Subtract the sum from the next highest multiple of 10. The result is the Check Digit

func (*FileControl) EntryAddendaCountField

func (fc *FileControl) EntryAddendaCountField() string

EntryAddendaCountField gets a string of entry addenda batch count zero padded

func (*FileControl) EntryHashField

func (fc *FileControl) EntryHashField() string

EntryHashField gets a string of entry hash zero padded

func (*FileControl) Parse

func (fc *FileControl) Parse(record string)

Parse takes the input record string and parses the FileControl values

func (*FileControl) String

func (fc *FileControl) String() string

String writes the FileControl struct to a 94 character string.

func (*FileControl) TotalCreditEntryDollarAmountInFileField

func (fc *FileControl) TotalCreditEntryDollarAmountInFileField() string

TotalCreditEntryDollarAmountInFileField get a zero padded Total credit Entry Amount

func (*FileControl) TotalDebitEntryDollarAmountInFileField

func (fc *FileControl) TotalDebitEntryDollarAmountInFileField() string

TotalDebitEntryDollarAmountInFileField get a zero padded Total debit Entry Amount

func (*FileControl) Validate

func (fc *FileControl) Validate() error

Validate performs NACHA format rule checks on the record and returns an error if not Validated The first error encountered is returned and stops that parsing.

type FileError

type FileError struct {
	FieldName string
	Value     string
	Msg       string
}

FileError is an error describing issues validating a file

func (*FileError) Error

func (e *FileError) Error() string

type FileHeader

type FileHeader struct {

	// ImmediateDestination contains the Routing Number of the ACH Operator or receiving
	// point to which the file is being sent.  The ach file format specifies a 10 character
	// field  begins with a blank space in the first position, followed by the four digit
	// Federal Reserve Routing Symbol, the four digit ABA Institution Identifier, and the Check
	// Digit (bTTTTAAAAC).  ImmediateDestinationField() will append the blank space to the
	// routing number.
	ImmediateDestination string

	// ImmediateOrigin contains the Routing Number of the ACH Operator or sending
	// point that is sending the file. The ach file format specifies a 10 character field
	// which begins with a blank space in the first position, followed by the four digit
	// Federal Reserve Routing Symbol, the four digit ABA Institution Identifier, and the Check
	// Digit (bTTTTAAAAC).  ImmediateOriginField() will append the blank space to the routing
	// number.
	ImmediateOrigin string

	// FileCreationDate is expressed in a "YYMMDD" format. The File Creation
	// Date is the date on which the file is prepared by an ODFI (ACH input files)
	// or the date (exchange date) on which a file is transmitted from ACH Operator
	// to ACH Operator, or from ACH Operator to RDFIs (ACH output files).
	FileCreationDate time.Time

	// FileCreationTime is expressed ina n "HHMM" (24 hour clock) format.
	// The system time when the ACH file was created
	FileCreationTime time.Time

	// This field should start at zero and increment by 1 (up to 9) and then go to
	// letters starting at A through Z for each subsequent file that is created for
	// a single system date. (34-34) 1 numeric 0-9 or uppercase alpha A-Z.
	// I have yet to see this ID not A
	FileIDModifier string

	// ImmediateDestinationName us the name of the ACH or receiving point for which that
	// file is destined. Name corresponding to the ImmediateDestination
	ImmediateDestinationName string

	// ImmediateOriginName is the name of the ACH operator or sending point that is
	// sending the file. Name corresponding to the ImmediateOrigin
	ImmediateOriginName string

	// ReferenceCode is reserved for information pertinent to the Originator.
	ReferenceCode string
	// contains filtered or unexported fields
}

FileHeader is a Record designating physical file characteristics and identify the origin (sending point) and destination (receiving point) of the entries contained in the file. The file header also includes creation date and time fields which can be used to uniquely identify a file.

func NewFileHeader

func NewFileHeader() FileHeader

NewFileHeader returns a new FileHeader with default values for none exported fields

func (*FileHeader) CalculateCheckDigit

func (v *FileHeader) CalculateCheckDigit(routingNumber string) int

CalculateCheckDigit returns a check digit for a routing number Multiply each digit in the Routing number by a weighting factor. The weighting factors for each digit are: Position: 1 2 3 4 5 6 7 8 Weights : 3 7 1 3 7 1 3 7 Add the results of the eight multiplications Subtract the sum from the next highest multiple of 10. The result is the Check Digit

func (*FileHeader) FileCreationDateField

func (fh *FileHeader) FileCreationDateField() string

FileCreationDateField gets the file creation date in YYMMDD format

func (*FileHeader) FileCreationTimeField

func (fh *FileHeader) FileCreationTimeField() string

FileCreationTimeField gets the file creation time in HHMM format

func (*FileHeader) ImmediateDestinationField

func (fh *FileHeader) ImmediateDestinationField() string

ImmediateDestinationField gets the immediate destination number with zero padding

func (*FileHeader) ImmediateDestinationNameField

func (fh *FileHeader) ImmediateDestinationNameField() string

ImmediateDestinationNameField gets the ImmediateDestinationName field padded

func (*FileHeader) ImmediateOriginField

func (fh *FileHeader) ImmediateOriginField() string

ImmediateOriginField gets the immediate origin number with 0 padding

func (*FileHeader) ImmediateOriginNameField

func (fh *FileHeader) ImmediateOriginNameField() string

ImmediateOriginNameField gets the ImmImmediateOriginName field padded

func (*FileHeader) Parse

func (fh *FileHeader) Parse(record string)

Parse takes the input record string and parses the FileHeader values

func (*FileHeader) ReferenceCodeField

func (fh *FileHeader) ReferenceCodeField() string

ReferenceCodeField gets the ReferenceCode field padded

func (*FileHeader) String

func (fh *FileHeader) String() string

String writes the FileHeader struct to a 94 character string.

func (*FileHeader) Validate

func (fh *FileHeader) Validate() error

Validate performs NACHA format rule checks on the record and returns an error if not Validated The first error encountered is returned and stops the parsing.

type ParseError

type ParseError struct {
	Line   int    // Line number where the error accurd
	Record string // Name of the record type being parsed
	Err    error  // The actual error
}

ParseError is returned for parsing reader errors. The first line is 1.

func (*ParseError) Error

func (e *ParseError) Error() string

type Reader

type Reader struct {

	// file is ach.file model being built as r is parsed.
	File File
	// contains filtered or unexported fields
}

Reader reads records from a ACH-encoded file.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a new ACH Reader that reads from r.

func (*Reader) Read

func (r *Reader) Read() (File, error)

Read reads each line of the ACH file and defines which parser to use based on the first character of each line. It also enforces ACH formating rules and returns the appropriate error if issues are found.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

A Writer writes an ach.file to a NACHA encoded file.

As returned by NewWriter, a Writer writes ach.file structs into NACHA formted files.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a new Writer that writes to w.

func (*Writer) Error

func (w *Writer) Error() error

Error reports any error that has occurred during a previous Write or Flush.

func (*Writer) Flush

func (w *Writer) Flush()

Flush writes any buffered data to the underlying io.Writer. To check if an error occurred during the Flush, call Error.

func (*Writer) Write

func (w *Writer) Write(file *File) error

Writer writes a single ach.file record to w

func (*Writer) WriteAll

func (w *Writer) WriteAll(files []*File) error

WriteAll writes multiple ach.files to w using Write and then calls Flush.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL