ach

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2017 License: Apache-2.0 Imports: 9 Imported by: 46

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 at an early stage and under active development but is already in product 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)
    • COR (Automated Notification of Change(NOC))
    • Return Entires

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 {
		aNOC := batch.GetEntries()[0].Addendum[0].(*AddendaNOC)
		println(aNOC.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].(*AddendaReturn)
		println(aReturn.ReturnCode)
	} 
}
Create a file

The following is based on simple file creation

file := ach.NewFile(ach.FileParam{
   ImmediateDestination:     "0210000890",
   ImmediateOrigin:          "123456789",
   ImmediateDestinationName: "Your Bank",
   ImmediateOriginName:      "Your Company",
   ReferenceCode:            "#00000A1"})

To create a batch

Errors only if payment type is not supported

batch := ach.NewBatch(ach.BatchParam{
   ServiceClassCode:        "220",
   CompanyName:             "Your Company",
   StandardEntryClass:      "PPD",
   CompanyIdentification:   "123456789",
   CompanyEntryDescription: "Trans. Description",
   CompanyDescriptiveDate:  "Oct 23",
   ODFIIdentification:      "123456789"})

To create an entry

entry := ach.NewEntryDetail(ach.EntryParam{
   ReceivingDFI:      "102001017",
   RDFIAccount:       "5343121",
   Amount:            "17500",
   TransactionCode:   "27",
   IDNumber:          "ABC##jvkdjfuiwn",
   IndividualName:    "Bob Smith",
   DiscretionaryData: "B1"})

To add one or more optional addenda records for an entry

addenda := ach.NewAddenda(ach.AddendaParam{
   PaymentRelatedInfo: "bonus pay for amazing work on #OSS"})
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

batch2, _ := ach.NewBatch(ach.BatchParam{
	ServiceClassCode:        "220",
	CompanyName:             "Your Company",
	StandardEntryClass:      "WEB",
	CompanyIdentification:   "123456789",
	CompanyEntryDescription: "subscr",
	CompanyDescriptiveDate:  "Oct 23",
	ODFIIdentification:      "123456789"})

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(ach.EntryParam{
	ReceivingDFI:      "102001017",
	RDFIAccount:       "5343121",
	Amount:            "799",
	TransactionCode:   "22",
	IDNumber:          "#123456",
	IndividualName:    "Wade Arnold",
	PaymentType: 		"R"})

addenda2 := ach.NewAddenda(ach.AddendaParam{
	PaymentRelatedInfo: "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(params ...BatchParam) *BatchMTE {
	batch := new(BatchMTE)
	batch.setControl(NewBatchControl)

	if len(params) > 0 {
		bh := NewBatchHeader(params[0])
		bh.StandardEntryClassCode = "MTE"
		batch.SetHeader(bh)
		return batch
	}
	bh := NewBatchHeader()
	bh.StandardEntryClassCode = "MTE"
	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(bp), nil
//...

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

References

Format Specification

ACH File Layout

Insperation

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 Addenda

type Addenda struct {

	// PaymentRelatedInformation
	PaymentRelatedInformation string
	// SequenceNumber is consecutively assigned to each Addenda Record following
	// an Entry Detail Record. The first addenda 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
}

Addenda provides business transaction information in a machine readable format. It is usually formatted according to ANSI, ASC, X12 Standard

func (*Addenda) CalculateCheckDigit

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

CalculateCheckDigit returns a check digit for a rounting 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 (*Addenda) EntryDetailSequenceNumberField

func (addenda *Addenda) EntryDetailSequenceNumberField() string

EntryDetailSequenceNumberField returns a zero padded EntryDetailSequenceNumber string

func (*Addenda) Parse

func (addenda *Addenda) Parse(record string)

Parse takes the input record string and parses the Addenda values

func (*Addenda) PaymentRelatedInformationField

func (addenda *Addenda) PaymentRelatedInformationField() string

PaymentRelatedInformationField returns a zero padded PaymentRelatedInformation string

func (*Addenda) SequenceNumberField

func (addenda *Addenda) SequenceNumberField() string

SequenceNumberField returns a zero padded SequenceNumber string

func (*Addenda) String

func (addenda *Addenda) String() string

String writes the Addenda struct to a 94 character string.

func (*Addenda) TypeCode

func (addenda *Addenda) TypeCode() string

TypeCode Defines the specific explanation and format for the addenda information

func (*Addenda) Validate

func (addenda *Addenda) 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 AddendaNOC

type AddendaNOC 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 NOC, 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 int
	// CorrectedData
	CorrectedData string
	// TraceNumber matches the Entry Detail Trace Number of the entry being returned.
	TraceNumber int
	// contains filtered or unexported fields
}

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

func NewAddendaNOC

func NewAddendaNOC(params ...AddendaParam) *AddendaNOC

NewAddendaNOC returns an reference to an instantiated AddendaNOC with default values

func (*AddendaNOC) CalculateCheckDigit

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

CalculateCheckDigit returns a check digit for a rounting 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 (*AddendaNOC) CorrectedDataField

func (addendaNOC *AddendaNOC) CorrectedDataField() string

CorrectedDataField returns a space padded CorrectedData string

func (*AddendaNOC) OriginalDFIField

func (addendaNOC *AddendaNOC) OriginalDFIField() string

OriginalDFIField returns a zero padded OriginalDFI string

func (*AddendaNOC) OriginalTraceField

func (addendaNOC *AddendaNOC) OriginalTraceField() string

OriginalTraceField returns a zero padded OriginalTrace string

func (*AddendaNOC) Parse

func (addendaNOC *AddendaNOC) Parse(record string)

Parse takes the input record string and parses the AddendaNOC values

func (*AddendaNOC) String

func (addendaNOC *AddendaNOC) String() string

String writes the AddendaNOC struct to a 94 character string

func (*AddendaNOC) TraceNumberField

func (addendaNOC *AddendaNOC) TraceNumberField() string

TraceNumberField returns a zero padded traceNumber string

func (*AddendaNOC) TypeCode

func (addendaNOC *AddendaNOC) TypeCode() string

TypeCode defines the format of the underlying addenda record

func (*AddendaNOC) Validate

func (addendaNOC *AddendaNOC) Validate() error

Validate verifies NACHA rules for AddendaNOC

type AddendaParam

type AddendaParam struct {
	TypeCode           string `json:"type_code,omitempty"`
	PaymentRelatedInfo string `json:"payment_related_info,omitempty"`
	TraceNumber        string `json:"trace_number,omitempty"`
	// Following Fields are used for Return addenda
	ReturnCode    string `json:"return_code,omitempty"`
	OriginalTrace string `json:"original_trace,omitempty"`
	AddendaInfo   string `json:"addenda_info,omitempty"`
	OriginalDFI   string `json:"original_dfi,omitempty"`
	// Following fields are used for NOC(notification of change) addenda w/ return fields
	ChangeCode    string `json:"change_code,omitempty"`
	CorrectedData string `json:"corrected_data,omitempty"`
}

AddendaParam is the minimal fields required to make a ach addenda

type AddendaReturn

type AddendaReturn 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 NOC, 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 int
	// AddendaInformation
	AddendaInformation string
	// TraceNumber matches the Entry Detail Trace Number of the entry being returned.
	TraceNumber int
	// contains filtered or unexported fields
}

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

func NewAddendaReturn

func NewAddendaReturn(params ...AddendaParam) *AddendaReturn

NewAddendaReturn returns a new AddendaReturn with default values for none exported fields

func (*AddendaReturn) AddendaInformationField

func (addendaReturn *AddendaReturn) AddendaInformationField() string

AddendaInformationField returns a space padded AddendaInformation string

func (*AddendaReturn) CalculateCheckDigit

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

CalculateCheckDigit returns a check digit for a rounting 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 (*AddendaReturn) DateOfDeathField

func (addendaReturn *AddendaReturn) DateOfDeathField() string

DateOfDeathField returns a space padded DateOfDeath string

func (*AddendaReturn) OriginalDFIField

func (addendaReturn *AddendaReturn) OriginalDFIField() string

OriginalDFIField returns a zero padded OriginalDFI string

func (*AddendaReturn) OriginalTraceField

func (addendaReturn *AddendaReturn) OriginalTraceField() string

OriginalTraceField returns a zero padded OriginalTrace string

func (*AddendaReturn) Parse

func (addendaReturn *AddendaReturn) Parse(record string)

Parse takes the input record string and parses the AddendaReturn values

func (*AddendaReturn) String

func (addendaReturn *AddendaReturn) String() string

String writes the AddendaReturn struct to a 94 character string

func (*AddendaReturn) TraceNumberField

func (addendaReturn *AddendaReturn) TraceNumberField() string

TraceNumberField returns a zero padded traceNumber string

func (*AddendaReturn) TypeCode

func (addendaReturn *AddendaReturn) TypeCode() string

TypeCode defines the format of the underlying addenda record

func (*AddendaReturn) Validate

func (addendaReturn *AddendaReturn) Validate() error

Validate verifies NACHA rules for AddendaReturn

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

func NewAddenda

func NewAddenda(params ...AddendaParam) (Addendumer, error)

NewAddenda returns a new Addenda with default values for none exported fields TypeCode in AddendaParam for none ACK, ATX, CCD, CIE, CTX, DNE, ENR, PPD, TRX and WEB Entries

type BatchCCD

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

BatchCCD creates 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(params ...BatchParam) *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(params ...BatchParam) *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 int
	// 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 rounting 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 PPD’ for consumer transactions, ‘CCD’ or ‘CTX’ for corporate
	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 int

	// 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(params ...BatchParam) *BatchHeader

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

func (*BatchHeader) BatchNumberField

func (bh *BatchHeader) BatchNumberField() string

BatchNumberField get the batch number zero padded

func (*BatchHeader) BatchParam

func (bh *BatchHeader) BatchParam() BatchParam

BatchParam returns a BatchParam with the values from BatchHeader

func (*BatchHeader) CalculateCheckDigit

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

CalculateCheckDigit returns a check digit for a rounting 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(params ...BatchParam) *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 BatchParam

type BatchParam struct {
	// ServiceClassCode a three digit code identifies:
	// 	- 200 mixed debits and credits
	// 	- 220 credits only
	// 	- 225 debits only
	ServiceClassCode string `json:"service_class_code"`
	// CompanyName is the legal company name making the transaction.
	CompanyName string `json:"company_name"`
	// CompanyIdentification is assigned by your bank to identify your company. Frequently the federal tax ID
	CompanyIdentification string `json:"company_identification"`
	// StandardEntryClass identifies the payment type (product) found within the batch using a 3-character code
	StandardEntryClass string `json:"standard_entry_class"`
	// CompanyEntryDescription describes the transaction. For example "PAYROLL"
	CompanyEntryDescription string `json:"company_entry_description"`
	// CompanyDescriptiveDate a date chosen to identify the transactions in YYMMDD format.
	CompanyDescriptiveDate string `json:"company_descriptive_date"`
	// Date transactions are to be posted to the receivers’ account in YYMMDD format.
	EffectiveEntryDate string `json:"effective_entry_date"`
	// ODFIIdentification originating ODFI's routing number without the last digit
	ODFIIdentification string `json:"ODFI_identification"`
}

BatchParam contains information about the company(Originator) and the type of detail records to follow. It is a subset of BatchHeader used for simplifying the client api build process.

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(params ...BatchParam) *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(bp BatchParam) (Batcher, error)

NewBatch takes a BatchParm and returns a matching SEC code batch type that is a batcher. Returns and 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 int

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

	// 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(params ...EntryParam) *EntryDetail

NewEntryDetail returns a new EntryDetail with default values for none 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 rounting 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) 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 (Reoccuring) all other values will result in S (single)

func (*EntryDetail) SetRDFI

func (ed *EntryDetail) SetRDFI(rdfi int) *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) 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 EntryParam

type EntryParam struct {
	ReceivingDFI      string `json:"receiving_dfi"`
	RDFIAccount       string `json:"rdfi_account"`
	Amount            string `json:"amount"`
	IDNumber          string `json:"id_number,omitempty"`
	IndividualName    string `json:"individual_name,omitempty"`
	ReceivingCompany  string `json:"receiving_company,omitempty"`
	DiscretionaryData string `json:"discretionary_data,omitempty"`
	PaymentType       string `json:"payment_type,omitempty"`
	TransactionCode   string `json:"transaction_code"`
}

EntryParam is the minimal fields required to make a ach entry

type FieldError

type FieldError struct {
	FieldName string // field name where error happend
	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(params ...FileParam) *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 rounting 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 10 character field begins with
	// a blank in the first position, followed by the four digit Federal Reserve
	// Routing Symbol, the four digit ABA Institution Identifier, and the Check
	// Digit (bTTTTAAAAC).
	ImmediateDestination int

	// ImmediateOrigin contains the Routing Number of the ACH Operator or sending
	// point that is sending the file. The 10 character field begins with
	// a blank in the first position, followed by the four digit Federal Reserve
	// Routing Symbol, the four digit ABA Institution Identifier, and the Check
	// Digit (bTTTTAAAAC).
	ImmediateOrigin int

	// 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(params ...FileParam) 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 rounting 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 FileParam

type FileParam struct {
	// ImmediateDestination is the originating banks ABA routing number. Frequently your banks ABA routing number.
	ImmediateDestination string `json:"immediate_destination"`
	// ImmediateOrigin
	ImmediateOrigin string `json:"immediate_origin"`
	// ImmediateDestinationName is the originating banks name.
	ImmediateDestinationName string `json:"immediate_destination_name"`
	ImmediateOriginName      string `json:"immediate_origin_name"`
	ReferenceCode            string `json:"reference_code,omitempty"`
}

FileParam is the minimal fields required to make a ach file header

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.fieles to w using Write and then calls Flush.

Directories

Path Synopsis
example
ach-ppd-read command
ach-ppd-write command

Jump to

Keyboard shortcuts

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