examples

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Example (AckRead)

Example_ackRead reads a ACK file

f, err := os.Open(filepath.Join("testdata", "ack-read.ach"))
if err != nil {
	log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
	fmt.Printf("Issue reading file: %+v \n", err)
}

if err := achFile.Validate(); err != nil {
	fmt.Printf("Could not validate entire read file: %v", err)
}

if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Credit Total Amount: %v", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
fmt.Printf("Batch Credit Total Amount: %v", strconv.Itoa(achFile.Batches[0].GetEntries()[0].Amount)+"\n")
fmt.Printf("SEC Code: %v", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Original Trace Number: %v", achFile.Batches[0].GetEntries()[0].OriginalTraceNumberField())
Output:

Credit Total Amount: 0
Batch Credit Total Amount: 0
SEC Code: ACK
Original Trace Number: 031300010000001
Example (AckWrite)

Example_ackWrite writes an ACK File

fh := mockFileHeader()
bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.CreditsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.ACK
bh.CompanyEntryDescription = "Vndr Pay"
// need EffectiveEntryDate to be fixed so it can match output
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "23138010"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingZeroDollarRemittanceCredit
entry.SetRDFI("031300012")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber("031300010000001")
entry.SetReceivingCompany("Best. #1")
entry.SetTraceNumber(bh.ODFIIdentification, 1)

entryOne := ach.NewEntryDetail() // Fee Entry
entryOne.TransactionCode = ach.CheckingZeroDollarRemittanceCredit
entryOne.SetRDFI("031300012")
entryOne.DFIAccountNumber = "744-5678-99"
entryOne.Amount = 0
entryOne.SetOriginalTraceNumber("031300010000002")
entryOne.SetReceivingCompany("Best. #1")
entryOne.SetTraceNumber(bh.ODFIIdentification, 2)

// build the batch
batch := ach.NewBatchACK(bh)
batch.AddEntry(entry)
batch.AddEntry(entryOne)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[1].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5220Name on Account                     231380104 ACKVndr Pay        190816   1231380100000001
624031300012744-5678-99      0000000000031300010000001Best. #1                0231380100000001
624031300012744-5678-99      0000000000031300010000002Best. #1                0231380100000002
82200000020006260002000000000000000000000000231380104                          231380100000001
9000001000001000000020006260002000000000000000000000000
Example (AdvRead)
f, err := os.Open(filepath.Join("testdata", "adv-read.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Credit Total Amount:%s", strconv.Itoa(achFile.ADVControl.TotalCreditEntryDollarAmountInFile)+"\n")
fmt.Printf("Debit Total Amount:%s", strconv.Itoa(achFile.ADVControl.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("OriginatorStatusCode:%s", strconv.Itoa(achFile.Batches[0].GetHeader().OriginatorStatusCode)+"\n")
fmt.Printf("Batch Credit Total Amount:%s", strconv.Itoa(achFile.Batches[0].GetADVControl().TotalCreditEntryDollarAmount)+"\n")
fmt.Printf("Batch Debit Total Amount:%s", strconv.Itoa(achFile.Batches[0].GetADVControl().TotalDebitEntryDollarAmount)+"\n")
fmt.Printf("SEC Code:%s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Entry Amount:%s", strconv.Itoa(achFile.Batches[0].GetADVEntries()[0].Amount)+"\n")
fmt.Printf("Sequence Number:%s", strconv.Itoa(achFile.Batches[0].GetADVEntries()[0].SequenceNumber)+"\n")
fmt.Printf("EntryOne Amount:%s", strconv.Itoa(achFile.Batches[0].GetADVEntries()[1].Amount)+"\n")
fmt.Printf("EntryOne Sequence Number:%s", strconv.Itoa(achFile.Batches[0].GetADVEntries()[1].SequenceNumber)+"\n")
Output:

Credit Total Amount:50000
Debit Total Amount:250000
OriginatorStatusCode:0
Batch Credit Total Amount:50000
Batch Debit Total Amount:250000
SEC Code:ADV
Entry Amount:50000
Sequence Number:1
EntryOne Amount:250000
EntryOne Sequence Number:2
Example (AdvWrite)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.AutomatedAccountingAdvices
bh.CompanyName = "Company Name, Inc"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.ADV
bh.CompanyEntryDescription = "Accounting"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"
bh.OriginatorStatusCode = 0

entry := ach.NewADVEntryDetail()

entry.TransactionCode = ach.CreditForDebitsOriginated //
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 50000
entry.AdviceRoutingNumber = "121042882"
entry.FileIdentification = "11131"
entry.ACHOperatorData = ""
entry.IndividualName = "Name"
entry.DiscretionaryData = ""
entry.AddendaRecordIndicator = 0
entry.ACHOperatorRoutingNumber = "01100001"
entry.JulianDay = 50
entry.SequenceNumber = 1

entryOne := ach.NewADVEntryDetail()
entryOne.TransactionCode = ach.DebitForCreditsOriginated //
entryOne.SetRDFI("231380104")
entryOne.DFIAccountNumber = "744-5678-99"
entryOne.Amount = 250000
entryOne.AdviceRoutingNumber = "121042882"
entryOne.FileIdentification = "11139"
entryOne.ACHOperatorData = ""
entryOne.IndividualName = "Name"
entryOne.DiscretionaryData = ""
entryOne.AddendaRecordIndicator = 0
entryOne.ACHOperatorRoutingNumber = "01100001"
entryOne.JulianDay = 50
entryOne.SequenceNumber = 2

// build the batch
batch := ach.NewBatchADV(bh)
batch.AddADVEntry(entry)
batch.AddADVEntry(entryOne)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetADVEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetADVEntries()[1].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetADVControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5280Company Name, In                    231380104 ADVAccounting      190816   0121042880000001
681231380104744-5678-99    00000005000012104288211131 Name                    0011000010500001
682231380104744-5678-99    00000025000012104288211139 Name                    0011000010500002
828000000200462760200000000000000025000000000000000000050000Company Name, Inc  121042880000001
9000000000000000000000000000000000000000000000000000000
Example (ArcReadDebit)
f, err := os.Open(filepath.Join("testdata", "arc-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Check Serial Number: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber+"\n")
Output:

Total Amount Debit: 250000
SEC Code: ARC
Check Serial Number: 123879654
Example (ArcWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.ARC
bh.CompanyEntryDescription = "ACH ARC"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 250000
entry.SetCheckSerialNumber("123879654")
entry.SetReceivingCompany("ABC Company")
entry.SetTraceNumber(bh.ODFIIdentification, 1)

// build the batch
batch := ach.NewBatchARC(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Payee Name                          231380104 ARCACH ARC         190816   1121042880000001
62723138010412345678         0000250000123879654      ABC Company             0121042880000001
82250000010023138010000000250000000000000000231380104                          121042880000001
9000001000001000000010023138010000000250000000000000000
Example (AtxRead)
f, err := os.Open(filepath.Join("testdata", "atx-read.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Total Amount Credit: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Total Amount: %s", strconv.Itoa(achFile.Batches[0].GetEntries()[0].Amount)+"\n")
fmt.Printf("Original Trace Number: %s", achFile.Batches[0].GetEntries()[0].OriginalTraceNumberField()+"\n")
fmt.Printf("Addenda1: %s", achFile.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("Addenda2: %s", achFile.Batches[0].GetEntries()[0].Addenda05[1].String()+"\n")
fmt.Printf("Total Amount: %s", strconv.Itoa(achFile.Batches[0].GetEntries()[1].Amount)+"\n")
fmt.Printf("Original Trace Number: %s", achFile.Batches[0].GetEntries()[1].OriginalTraceNumberField()+"\n")
fmt.Printf("Addenda1: %s", achFile.Batches[0].GetEntries()[1].Addenda05[0].String()+"\n")
fmt.Printf("Addenda2: %s", achFile.Batches[0].GetEntries()[1].Addenda05[1].String()+"\n")
Output:

Total Amount Debit: 0
Total Amount Credit: 0
SEC Code: ATX
Total Amount: 0
Original Trace Number: 031300010000001
Addenda1: 705Credit account 1 for service                                                    00010000001
Addenda2: 705Credit account 2 for service                                                    00020000001
Total Amount: 0
Original Trace Number: 031300010000002
Addenda1: 705Credit account 1 for leadership                                                 00010000002
Addenda2: 705Credit account 2 for leadership                                                 00020000002
Example (AtxWrite)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.CreditsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.ATX
bh.CompanyEntryDescription = "Vndr Pay"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "23138010"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingZeroDollarRemittanceCredit
entry.SetRDFI("031300012")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber("031300010000001")
entry.SetCATXAddendaRecords(2)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.DiscretionaryData = "01"
entry.AddendaRecordIndicator = 1

entryOne := ach.NewEntryDetail() // Fee Entry
entryOne.TransactionCode = ach.CheckingZeroDollarRemittanceCredit
entryOne.SetRDFI("031300012")
entryOne.DFIAccountNumber = "744-5678-99"
entryOne.Amount = 0
entryOne.SetOriginalTraceNumber("031300010000002")
entryOne.SetCATXAddendaRecords(2)
entryOne.SetCATXReceivingCompany("Receiver Company")
entryOne.SetTraceNumber(bh.ODFIIdentification, 2)
entryOne.DiscretionaryData = "01"
entryOne.AddendaRecordIndicator = 1

entryAd1 := ach.NewAddenda05()
entryAd1.PaymentRelatedInformation = "Credit account 1 for service"
entryAd1.SequenceNumber = 1
entryAd1.EntryDetailSequenceNumber = 0000001

entryAd2 := ach.NewAddenda05()
entryAd2.PaymentRelatedInformation = "Credit account 2 for service"
entryAd2.SequenceNumber = 2
entryAd2.EntryDetailSequenceNumber = 0000001

entryOneAd1 := ach.NewAddenda05()
entryOneAd1.PaymentRelatedInformation = "Credit account 1 for leadership"
entryOneAd1.SequenceNumber = 1
entryOneAd1.EntryDetailSequenceNumber = 0000002

entryOneAd2 := ach.NewAddenda05()
entryOneAd2.PaymentRelatedInformation = "Credit account 2 for leadership"
entryOneAd2.SequenceNumber = 2
entryOneAd2.EntryDetailSequenceNumber = 0000002

// build the batch
batch := ach.NewBatchATX(bh)
batch.AddEntry(entry)
batch.GetEntries()[0].AddAddenda05(entryAd1)
batch.GetEntries()[0].AddAddenda05(entryAd2)
batch.AddEntry(entryOne)
batch.GetEntries()[1].AddAddenda05(entryOneAd1)
batch.GetEntries()[1].AddAddenda05(entryOneAd2)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[1].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[1].Addenda05[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5220Name on Account                     231380104 ATXVndr Pay        190816   1231380100000001
624031300012744-5678-99      00000000000313000100000010002Receiver Company  011231380100000001
705Credit account 1 for service                                                    00010000001
624031300012744-5678-99      00000000000313000100000020002Receiver Company  011231380100000002
705Credit account 1 for leadership                                                 00010000002
82200000060006260002000000000000000000000000231380104                          231380100000001
9000001000001000000060006260002000000000000000000000000
Example (BocReadDebit)
f, err := os.Open(filepath.Join("testdata", "boc-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Check Serial Number: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber+"\n")
Output:

Total Amount Debit: 250000
SEC Code: BOC
Check Serial Number: 123879654
Example (BocWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.BOC
bh.CompanyEntryDescription = "ACH BOC"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 250000
entry.SetCheckSerialNumber("123879654")
entry.SetReceivingCompany("ABC Company")
entry.SetTraceNumber(bh.ODFIIdentification, 1)

// build the batch
batch := ach.NewBatchBOC(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Payee Name                          231380104 BOCACH BOC         190816   1121042880000001
62723138010412345678         0000250000123879654      ABC Company             0121042880000001
82250000010023138010000000250000000000000000231380104                          121042880000001
9000001000001000000010023138010000000250000000000000000
Example (CcdReadDebit)
f, err := os.Open(filepath.Join("testdata", "ccd-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Total Amount Credit: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("CCD Entry Identification Number: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber+"\n")
fmt.Printf("CCD Entry Receiving Company: %s", achFile.Batches[0].GetEntries()[0].IndividualName+"\n")
fmt.Printf("CCD Entry Trace Number: %s", achFile.Batches[0].GetEntries()[0].TraceNumberField()+"\n")
fmt.Printf("CCD Fee Identification Number: %s", achFile.Batches[0].GetEntries()[1].IdentificationNumber+"\n")
fmt.Printf("CCD Fee Receiving Company: %s", achFile.Batches[0].GetEntries()[1].IndividualName+"\n")
fmt.Printf("CCD Fee Trace Number: %s", achFile.Batches[0].GetEntries()[1].TraceNumberField()+"\n")
Output:

Total Amount Debit: 500125
Total Amount Credit: 0
SEC Code: CCD
CCD Entry Identification Number: location1234567
CCD Entry Receiving Company: Best Co. #123456789012
CCD Entry Trace Number: 031300010000001
CCD Fee Identification Number: Fee123456789012
CCD Fee Receiving Company: Best Co. #123456789012
CCD Fee Trace Number: 031300010000002
Example (CcdWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.CCD
bh.CompanyEntryDescription = "Vndr Pay"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "031300012"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 500000
entry.IdentificationNumber = "location #1234"
entry.SetReceivingCompany("Best Co. #1")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.DiscretionaryData = "S"

entryOne := ach.NewEntryDetail()
entryOne.TransactionCode = ach.CheckingDebit
entryOne.SetRDFI("231380104")
entryOne.DFIAccountNumber = "744-5678-99"
entryOne.Amount = 125
entryOne.IdentificationNumber = "Fee #1"
entryOne.SetReceivingCompany("Best Co. #1")
entryOne.SetTraceNumber(bh.ODFIIdentification, 2)
entryOne.DiscretionaryData = "S"

// build the batch
batch := ach.NewBatchCCD(bh)
batch.AddEntry(entry)
batch.AddEntry(entryOne)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[1].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 CCDVndr Pay        190816   1031300010000001
627231380104744-5678-99      0000500000location #1234 Best Co. #1           S 0031300010000001
627231380104744-5678-99      0000000125Fee #1         Best Co. #1           S 0031300010000002
82250000020046276020000000500125000000000000231380104                          031300010000001
9000001000001000000020046276020000000500125000000000000
Example (CorReadCredit)

Example_corReadCredit reads a COR file

f, err := os.Open(filepath.Join("testdata", "cor-read.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %v", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Total Amount Credit: %v", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %v", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Entry Detail: %v", achFile.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("Addenda98: %v", achFile.Batches[0].GetEntries()[0].Addenda98.String()+"\n")
Output:

Total Amount Debit: 0
Total Amount Credit: 0
SEC Code: COR
Entry Detail: 621231380104744-5678-99      0000000000location #23   Best Co. #23            1121042880000001
Addenda98: 798C01121042880000001      121042881918171614                                  091012980000088
Example (CorWriteCredit)

Example_corWriteCredit writes a COR file

// Example transfer to write a COR File

fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.CreditsOnly
bh.StandardEntryClassCode = ach.COR
bh.CompanyName = "Your Company, inc"
bh.CompanyIdentification = "121042882"
bh.CompanyEntryDescription = "Vendor Pay"
bh.ODFIIdentification = "121042882" // Originating Routing Number

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingReturnNOCCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.IdentificationNumber = "location #23"
entry.SetReceivingCompany("Best Co. #23")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.AddendaRecordIndicator = 1

addenda98 := ach.NewAddenda98()
addenda98.ChangeCode = "C01"
addenda98.OriginalTrace = "121042880000001"
addenda98.OriginalDFI = "121042882"
addenda98.CorrectedData = "1918171614"
addenda98.TraceNumber = "91012980000088"

entry.Addenda98 = addenda98
entry.Category = ach.CategoryNOC

// build the batch
batch := ach.NewBatchCOR(bh)
batch.AddEntry(entry)

if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda98.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5220Your Company, in                    121042882 CORVendor Pay      000000   1121042880000001
621231380104744-5678-99      0000000000location #23   Best Co. #23            1121042880000001
798C01121042880000001      121042881918171614                                  091012980000088
82200000020023138010000000000000000000000000121042882                          121042880000001
9000001000001000000020023138010000000000000000000000000
Example (CtxReadDebit)
f, err := os.Open(filepath.Join("testdata", "ctx-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Total Amount Credit: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Addenda1: %s", achFile.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("Addenda2: %s", achFile.Batches[0].GetEntries()[0].Addenda05[1].String()+"\n")
Output:

Total Amount Debit: 100000000
Total Amount Credit: 0
SEC Code: CTX
Addenda1: 705Debit First Account                                                             00010000001
Addenda2: 705Debit Second Account                                                            00020000001
Example (CtxWriteDebit)

Example_ctxWriteDebit writes a CTX debit file

fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.CTX
bh.CompanyEntryDescription = "ACH CTX"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()

entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 100000000
entry.IdentificationNumber = "45689033"
entry.SetCATXAddendaRecords(2)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.DiscretionaryData = "01"

addenda1 := ach.NewAddenda05()
addenda1.PaymentRelatedInformation = "Debit First Account"
addenda1.SequenceNumber = 1
addenda1.EntryDetailSequenceNumber = 0000001

addenda2 := ach.NewAddenda05()
addenda2.PaymentRelatedInformation = "Debit Second Account"
addenda2.SequenceNumber = 2
addenda2.EntryDetailSequenceNumber = 0000001

// build the batch
batch := ach.NewBatchCTX(bh)
batch.AddEntry(entry)
batch.Entries[0].AddendaRecordIndicator = 1
batch.GetEntries()[0].AddAddenda05(addenda1)
batch.GetEntries()[0].AddAddenda05(addenda2)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda05[1].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 CTXACH CTX         190816   1121042880000001
62723138010412345678         010000000045689033       0002Receiver Company  011121042880000001
705Debit First Account                                                             00010000001
705Debit Second Account                                                            00020000001
82250000030023138010000100000000000000000000231380104                          121042880000001
9000001000001000000030023138010000100000000000000000000
Example (DneRead)

Example_dneRead reads a DNR file

f, err := os.Open(filepath.Join("testdata", "dne-read.ach"))
if err != nil {
	log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
	panic(fmt.Sprintf("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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount: %s", strconv.Itoa(achFile.Batches[0].GetEntries()[0].Amount)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Payment Related Information: %s", achFile.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
Output:

Total Amount: 0
SEC Code: DNE
Payment Related Information: 705DATE OF DEATH*010218*CUSTOMERSSN*#########*AMOUNT*$$$$.cc\                      00010000001
Example (DneWrite)

Example_dneWrite writes a DNR file

fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.CreditsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.DNE
bh.CompanyEntryDescription = "Death"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "23138010"
bh.OriginatorStatusCode = 2

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingReturnNOCCredit
entry.SetRDFI("031300012")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber("031300010000001")
entry.SetReceivingCompany("Best. #1")
entry.SetTraceNumber(bh.ODFIIdentification, 1)

addenda := ach.NewAddenda05()
addenda.PaymentRelatedInformation = `    DATE OF DEATH*010218*CUSTOMERSSN*#########*AMOUNT*$$$$.cc\`
entry.AddAddenda05(addenda)
entry.AddendaRecordIndicator = 1

// build the batch
batch := ach.NewBatchDNE(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5220Name on Account                     231380104 DNEDeath           190816   2231380100000001
621031300012744-5678-99      0000000000031300010000001Best. #1                1231380100000001
705    DATE OF DEATH*010218*CUSTOMERSSN*#########*AMOUNT*$$$$.cc\                  00010000001
82200000020003130001000000000000000000000000231380104                          231380100000001
9000001000001000000020003130001000000000000000000000000
Example (EnrRead)

Example_enrRead reads a ENR file

f, err := os.Open(filepath.Join("testdata", "enr-read.ach"))
if err != nil {
	log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
	panic(fmt.Sprintf("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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount: %s", strconv.Itoa(achFile.Batches[0].GetEntries()[0].Amount)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Payment Related Information: %s", achFile.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
Output:

Total Amount: 0
SEC Code: ENR
Payment Related Information: 70522*12200004*3*123987654321*777777777*DOE*JOHN*1\                                00010000001
Example (EnrWrite)

Example_enrWrite writes and ENR file

fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.ENR
bh.CompanyEntryDescription = "AUTOENROLL"
bh.ODFIIdentification = "23138010"

entry := ach.NewEntryDetail()

entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("031300012")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 0
entry.SetOriginalTraceNumber("031300010000001")
entry.SetReceivingCompany("Best. #1")
entry.SetTraceNumber(bh.ODFIIdentification, 1)

addenda05 := ach.NewAddenda05()
addenda05.PaymentRelatedInformation = `22*12200004*3*123987654321*777777777*DOE*JOHN*1\` // From NACHA 2013 Official Rules
entry.AddAddenda05(addenda05)
entry.AddendaRecordIndicator = 1

// build the batch
batch := ach.NewBatchENR(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 ENRAUTOENROLL               1231380100000001
627031300012744-5678-99      0000000000031300010000001Best. #1                1231380100000001
70522*12200004*3*123987654321*777777777*DOE*JOHN*1\                                00010000001
82250000020003130001000000000000000000000000231380104                          231380100000001
9000001000001000000020003130001000000000000000000000000
Example (IatReadMixedCreditDebit)

Example_iatReadMixedCreditDebit reads a ACK file

f, err := os.Open(filepath.Join("testdata", "iat-mixedCreditDebit.ach"))
if err != nil {
	log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
	fmt.Printf("Issue reading file: %+v \n", err)
}

if err := achFile.Validate(); err != nil {
	fmt.Printf("Could not validate entire read file: %v", err)
}

if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("SEC Code: %s", achFile.IATBatches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Debit Entry: %s", achFile.IATBatches[0].Entries[0].String()+"\n")
fmt.Printf("Addenda10: %s", achFile.IATBatches[0].Entries[0].Addenda10.String()+"\n")
fmt.Printf("Addenda11: %s", achFile.IATBatches[0].Entries[0].Addenda11.String()+"\n")
fmt.Printf("Addenda12: %s", achFile.IATBatches[0].Entries[0].Addenda12.String()+"\n")
fmt.Printf("Addenda13: %s", achFile.IATBatches[0].Entries[0].Addenda13.String()+"\n")
fmt.Printf("Addenda14: %s", achFile.IATBatches[0].Entries[0].Addenda14.String()+"\n")
fmt.Printf("Addenda15: %s", achFile.IATBatches[0].Entries[0].Addenda15.String()+"\n")
fmt.Printf("Addenda16: %s", achFile.IATBatches[0].Entries[0].Addenda16.String()+"\n")
fmt.Printf("Addenda17: %s", achFile.IATBatches[0].Entries[0].Addenda17[0].String()+"\n")
fmt.Printf("Addenda18: %s", achFile.IATBatches[0].Entries[0].Addenda18[0].String()+"\n")
fmt.Printf("Total File Debit Amount: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Credit Entry: %s", achFile.IATBatches[0].Entries[1].String()+"\n")
fmt.Printf("Addenda10: %s", achFile.IATBatches[0].Entries[1].Addenda10.String()+"\n")
fmt.Printf("Addenda11: %s", achFile.IATBatches[0].Entries[1].Addenda11.String()+"\n")
fmt.Printf("Addenda12: %s", achFile.IATBatches[0].Entries[1].Addenda12.String()+"\n")
fmt.Printf("Addenda13: %s", achFile.IATBatches[0].Entries[1].Addenda13.String()+"\n")
fmt.Printf("Addenda14: %s", achFile.IATBatches[0].Entries[1].Addenda14.String()+"\n")
fmt.Printf("Addenda15: %s", achFile.IATBatches[0].Entries[1].Addenda15.String()+"\n")
fmt.Printf("Addenda16: %s", achFile.IATBatches[0].Entries[1].Addenda16.String()+"\n")
fmt.Printf("Addenda17: %s", achFile.IATBatches[0].Entries[1].Addenda17[0].String()+"\n")
fmt.Printf("Addenda18: %s", achFile.IATBatches[0].Entries[1].Addenda18[0].String()+"\n")
fmt.Printf("Total File Credit Amount: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
Output:

SEC Code: IAT
Debit Entry: 6271210428820007             0000100000123456789                              1231380100000001
Addenda10: 710ANN000000000000100000928383-23938          BEK Enterprises                          0000001
Addenda11: 711BEK Solutions                      15 West Place Street                             0000001
Addenda12: 712JacobsTown*PA\                     US*19305\                                        0000001
Addenda13: 713Wells Fargo                        01231380104                         US           0000001
Addenda14: 714Citadel Bank                       01121042882                         CA           0000001
Addenda15: 7159874654932139872121 Front Street                                                    0000001
Addenda16: 716LetterTown*AB\                     CA*80014\                                        0000001
Addenda17: 717This is an international payment                                                00010000001
Addenda18: 718Bank of France                     01456456456987987                   FR       00010000001
Total File Debit Amount: 100000
Credit Entry: 6221210428820007             0000100000123456789                              1231380100000002
Addenda10: 710ANN000000000000100000928383-23938          ADCAF Enterprises                        0000002
Addenda11: 711ADCAF Solutions                    15 West Place Street                             0000002
Addenda12: 712JacobsTown*PA\                     US*19305\                                        0000002
Addenda13: 713Wells Fargo                        01231380104                         US           0000002
Addenda14: 714Citadel Bank                       01121042882                         CA           0000002
Addenda15: 71598746549321398718 Fifth Street                                                      0000002
Addenda16: 716LetterTown*AB\                     CA*80014\                                        0000002
Addenda17: 717This is an international payment                                                00010000002
Addenda18: 718Bank of France                     01456456456987987                   FR       00010000002
Total File Credit Amount: 100000
Example (IatWriteMixedCreditDebit)

Example_iatWriteMixedCreditDebit writes a IAT mixed debit and credit file

fh := mockFileHeader()

bh := ach.NewIATBatchHeader()
bh.ServiceClassCode = ach.MixedDebitsAndCredits
bh.ForeignExchangeIndicator = "FF"
bh.ForeignExchangeReferenceIndicator = 3
bh.ISODestinationCountryCode = "US"
bh.OriginatorIdentification = "123456789"
bh.StandardEntryClassCode = ach.IAT
bh.CompanyEntryDescription = "TRADEPAYMT"
bh.ISOOriginatingCurrencyCode = "CAD"
bh.ISODestinationCurrencyCode = "USD"
bh.ODFIIdentification = "23138010"
bh.EffectiveEntryDate = "190816"

entry := ach.NewIATEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("121042882")
entry.AddendaRecords = 007
entry.DFIAccountNumber = "123456789"
entry.Amount = 100000 // 1000.00
entry.SetTraceNumber("23138010", 1)
entry.Category = ach.CategoryForward

addenda10 := ach.NewAddenda10()
addenda10.TransactionTypeCode = "ANN"
addenda10.ForeignPaymentAmount = 100000
addenda10.ForeignTraceNumber = "928383-23938"
addenda10.Name = "BEK Enterprises"
addenda10.EntryDetailSequenceNumber = 00000001
entry.Addenda10 = addenda10

addenda11 := ach.NewAddenda11()
addenda11.OriginatorName = "BEK Solutions"
addenda11.OriginatorStreetAddress = "15 West Place Street"
addenda11.EntryDetailSequenceNumber = 00000001
entry.Addenda11 = addenda11

addenda12 := ach.NewAddenda12()
addenda12.OriginatorCityStateProvince = "JacobsTown*PA\\"
addenda12.OriginatorCountryPostalCode = "US*19305\\"
addenda12.EntryDetailSequenceNumber = 00000001
entry.Addenda12 = addenda12

addenda13 := ach.NewAddenda13()
addenda13.ODFIName = "Wells Fargo"
addenda13.ODFIIDNumberQualifier = "01"
addenda13.ODFIIdentification = "231380104"
addenda13.ODFIBranchCountryCode = "US"
addenda13.EntryDetailSequenceNumber = 00000001
entry.Addenda13 = addenda13

addenda14 := ach.NewAddenda14()
addenda14.RDFIName = "Citadel Bank"
addenda14.RDFIIDNumberQualifier = "01"
addenda14.RDFIIdentification = "121042882"
addenda14.RDFIBranchCountryCode = "CA"
addenda14.EntryDetailSequenceNumber = 00000001
entry.Addenda14 = addenda14

addenda15 := ach.NewAddenda15()
addenda15.ReceiverIDNumber = "987465493213987"
addenda15.ReceiverStreetAddress = "2121 Front Street"
addenda15.EntryDetailSequenceNumber = 00000001
entry.Addenda15 = addenda15

addenda16 := ach.NewAddenda16()
addenda16.ReceiverCityStateProvince = "LetterTown*AB\\"
addenda16.ReceiverCountryPostalCode = "CA*80014\\"
addenda16.EntryDetailSequenceNumber = 00000001
entry.Addenda16 = addenda16

addenda17 := ach.NewAddenda17()
addenda17.PaymentRelatedInformation = "This is an international payment"
addenda17.SequenceNumber = 1
addenda17.EntryDetailSequenceNumber = 0000001
entry.AddAddenda17(addenda17)

addenda18 := ach.NewAddenda18()
addenda18.ForeignCorrespondentBankName = "Bank of France"
addenda18.ForeignCorrespondentBankIDNumberQualifier = "01"
addenda18.ForeignCorrespondentBankIDNumber = "456456456987987"
addenda18.ForeignCorrespondentBankBranchCountryCode = "FR"
addenda18.SequenceNumber = 3
addenda18.EntryDetailSequenceNumber = 0000001
entry.AddAddenda18(addenda18)

entryTwo := ach.NewIATEntryDetail()
entryTwo.TransactionCode = ach.CheckingCredit
entryTwo.SetRDFI("121042882")
entryTwo.AddendaRecords = 007
entryTwo.DFIAccountNumber = "123456789"
entryTwo.Amount = 100000 // 1000.00
entryTwo.SetTraceNumber("23138010", 2)
entryTwo.Category = ach.CategoryForward

//addenda

addenda10Two := ach.NewAddenda10()
addenda10Two.TransactionTypeCode = "ANN"
addenda10Two.ForeignPaymentAmount = 100000
addenda10Two.ForeignTraceNumber = "928383-23938"
addenda10Two.Name = "ADCAF Enterprises"
addenda10Two.EntryDetailSequenceNumber = 00000002
entryTwo.Addenda10 = addenda10Two

addenda11Two := ach.NewAddenda11()
addenda11Two.OriginatorName = "ADCAF Solutions"
addenda11Two.OriginatorStreetAddress = "15 West Place Street"
addenda11Two.EntryDetailSequenceNumber = 00000002
entryTwo.Addenda11 = addenda11Two

addenda12Two := ach.NewAddenda12()
addenda12Two.OriginatorCityStateProvince = "JacobsTown*PA\\"
addenda12Two.OriginatorCountryPostalCode = "US*19305\\"
addenda12Two.EntryDetailSequenceNumber = 00000002
entryTwo.Addenda12 = addenda12Two

addenda13Two := ach.NewAddenda13()
addenda13Two.ODFIName = "Wells Fargo"
addenda13Two.ODFIIDNumberQualifier = "01"
addenda13Two.ODFIIdentification = "231380104"
addenda13Two.ODFIBranchCountryCode = "US"
addenda13Two.EntryDetailSequenceNumber = 00000002
entryTwo.Addenda13 = addenda13Two

addenda14Two := ach.NewAddenda14()
addenda14Two.RDFIName = "Citadel Bank"
addenda14Two.RDFIIDNumberQualifier = "01"
addenda14Two.RDFIIdentification = "121042882"
addenda14Two.RDFIBranchCountryCode = "CA"
addenda14Two.EntryDetailSequenceNumber = 00000002
entryTwo.Addenda14 = addenda14Two

addenda15Two := ach.NewAddenda15()
addenda15Two.ReceiverIDNumber = "987465493213987"
addenda15Two.ReceiverStreetAddress = "18 Fifth Street"
addenda15Two.EntryDetailSequenceNumber = 00000002
entryTwo.Addenda15 = addenda15Two

addenda16Two := ach.NewAddenda16()
addenda16Two.ReceiverCityStateProvince = "LetterTown*AB\\"
addenda16Two.ReceiverCountryPostalCode = "CA*80014\\"
addenda16Two.EntryDetailSequenceNumber = 00000002
entryTwo.Addenda16 = addenda16Two

addenda17Two := ach.NewAddenda17()
addenda17Two.PaymentRelatedInformation = "This is an international payment"
addenda17Two.SequenceNumber = 1
addenda17Two.EntryDetailSequenceNumber = 0000002
entryTwo.AddAddenda17(addenda17Two)

addenda18Two := ach.NewAddenda18()
addenda18Two.ForeignCorrespondentBankName = "Bank of France"
addenda18Two.ForeignCorrespondentBankIDNumberQualifier = "01"
addenda18Two.ForeignCorrespondentBankIDNumber = "456456456987987"
addenda18Two.ForeignCorrespondentBankBranchCountryCode = "FR"
addenda18Two.SequenceNumber = 3
addenda18Two.EntryDetailSequenceNumber = 0000002
entryTwo.AddAddenda18(addenda18Two)

// build the batch
batch := ach.NewIATBatch(bh)
batch.AddEntry(entry)
batch.AddEntry(entryTwo)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
achFile := ach.NewFile()
achFile.SetHeader(fh)
achFile.AddIATBatch(batch)
if err := achFile.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("SEC Code: %s", achFile.IATBatches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Debit Entry: %s", achFile.IATBatches[0].Entries[0].String()+"\n")
fmt.Printf("Addenda10: %s", achFile.IATBatches[0].Entries[0].Addenda10.String()+"\n")
fmt.Printf("Addenda11: %s", achFile.IATBatches[0].Entries[0].Addenda11.String()+"\n")
fmt.Printf("Addenda12: %s", achFile.IATBatches[0].Entries[0].Addenda12.String()+"\n")
fmt.Printf("Addenda13: %s", achFile.IATBatches[0].Entries[0].Addenda13.String()+"\n")
fmt.Printf("Addenda14: %s", achFile.IATBatches[0].Entries[0].Addenda14.String()+"\n")
fmt.Printf("Addenda15: %s", achFile.IATBatches[0].Entries[0].Addenda15.String()+"\n")
fmt.Printf("Addenda16: %s", achFile.IATBatches[0].Entries[0].Addenda16.String()+"\n")
fmt.Printf("Addenda17: %s", achFile.IATBatches[0].Entries[0].Addenda17[0].String()+"\n")
fmt.Printf("Addenda18: %s", achFile.IATBatches[0].Entries[0].Addenda18[0].String()+"\n")
fmt.Printf("Total File Debit Amount: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Credit Entry: %s", achFile.IATBatches[0].Entries[1].String()+"\n")
fmt.Printf("Addenda10: %s", achFile.IATBatches[0].Entries[1].Addenda10.String()+"\n")
fmt.Printf("Addenda11: %s", achFile.IATBatches[0].Entries[1].Addenda11.String()+"\n")
fmt.Printf("Addenda12: %s", achFile.IATBatches[0].Entries[1].Addenda12.String()+"\n")
fmt.Printf("Addenda13: %s", achFile.IATBatches[0].Entries[1].Addenda13.String()+"\n")
fmt.Printf("Addenda14: %s", achFile.IATBatches[0].Entries[1].Addenda14.String()+"\n")
fmt.Printf("Addenda15: %s", achFile.IATBatches[0].Entries[1].Addenda15.String()+"\n")
fmt.Printf("Addenda16: %s", achFile.IATBatches[0].Entries[1].Addenda16.String()+"\n")
fmt.Printf("Addenda17: %s", achFile.IATBatches[0].Entries[1].Addenda17[0].String()+"\n")
fmt.Printf("Addenda18: %s", achFile.IATBatches[0].Entries[1].Addenda18[0].String()+"\n")
fmt.Printf("Total File Credit Amount: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
Output:

SEC Code: IAT
Debit Entry: 6271210428820007             0000100000123456789                              1231380100000001
Addenda10: 710ANN000000000000100000928383-23938          BEK Enterprises                          0000001
Addenda11: 711BEK Solutions                      15 West Place Street                             0000001
Addenda12: 712JacobsTown*PA\                     US*19305\                                        0000001
Addenda13: 713Wells Fargo                        01231380104                         US           0000001
Addenda14: 714Citadel Bank                       01121042882                         CA           0000001
Addenda15: 7159874654932139872121 Front Street                                                    0000001
Addenda16: 716LetterTown*AB\                     CA*80014\                                        0000001
Addenda17: 717This is an international payment                                                00010000001
Addenda18: 718Bank of France                     01456456456987987                   FR       00010000001
Total File Debit Amount: 100000
Credit Entry: 6221210428820007             0000100000123456789                              1231380100000002
Addenda10: 710ANN000000000000100000928383-23938          ADCAF Enterprises                        0000002
Addenda11: 711ADCAF Solutions                    15 West Place Street                             0000002
Addenda12: 712JacobsTown*PA\                     US*19305\                                        0000002
Addenda13: 713Wells Fargo                        01231380104                         US           0000002
Addenda14: 714Citadel Bank                       01121042882                         CA           0000002
Addenda15: 71598746549321398718 Fifth Street                                                      0000002
Addenda16: 716LetterTown*AB\                     CA*80014\                                        0000002
Addenda17: 717This is an international payment                                                00010000002
Addenda18: 718Bank of France                     01456456456987987                   FR       00010000002
Total File Credit Amount: 100000
Example (MteReadDebit)
f, err := os.Open(filepath.Join("testdata", "mte-read.ach"))
if err != nil {
	log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
	panic(fmt.Sprintf("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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount: %s", strconv.Itoa(achFile.Batches[0].GetEntries()[0].Amount)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Addenda02: %s", achFile.Batches[0].GetEntries()[0].Addenda02.String()+"\n")
Output:

Total Amount: 10000
SEC Code: MTE
Addenda02: 702          2005091234561224      321 East Market Street     ANYTOWN        VA231380100000001
Example (MteWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Merchant with ATM" // Merchant with the ATM
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.MTE
bh.CompanyEntryDescription = "CASH WITHDRAW"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "23138010"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("031300012")
entry.DFIAccountNumber = "744-5678-99"
entry.Amount = 10000
entry.SetOriginalTraceNumber("031300010000001")
entry.SetReceivingCompany("JANE DOE")
entry.SetTraceNumber(bh.ODFIIdentification, 1)

addenda02 := ach.NewAddenda02()
addenda02.TerminalIdentificationCode = "200509"
addenda02.TerminalLocation = "321 East Market Street"
addenda02.TerminalCity = "ANYTOWN"
addenda02.TerminalState = "VA"

addenda02.TransactionSerialNumber = "123456"
addenda02.TransactionDate = "1224"
addenda02.TraceNumber = entry.TraceNumber
entry.Addenda02 = addenda02
entry.AddendaRecordIndicator = 1

// build the batch
batch := ach.NewBatchMTE(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Merchant with AT                    231380104 MTECASH WITHD      190816   1231380100000001
627031300012744-5678-99      0000010000031300010000001JANE DOE                1231380100000001
82250000020003130001000000010000000000000000231380104                          231380100000001
9000001000001000000020003130001000000010000000000000000
Example (PopReadDebit)
f, err := os.Open(filepath.Join("testdata", "pop-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("POP Check Serial Number: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber[0:9]+"\n")
fmt.Printf("POP Terminal City: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber[9:13]+"\n")
fmt.Printf("POP Terminal State: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber[13:15]+"\n")
Output:

Total Amount Debit: 250500
SEC Code: POP
POP Check Serial Number: 123456789
POP Terminal City: PHIL
POP Terminal State: PA
Example (PopWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Originator"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.POP
bh.CompanyEntryDescription = "ACH POP"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 250500
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.IndividualName = "Wade Arnold"
entry.SetPOPCheckSerialNumber("123456")
entry.SetPOPTerminalCity("PHIL")
entry.SetPOPTerminalState("PA")

// build the batch
batch := ach.NewBatchPOP(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Originator                          231380104 POPACH POP         190816   1121042880000001
62723138010412345678         0000250500123456   PHILPAWade Arnold             0121042880000001
82250000010023138010000000250500000000000000231380104                          121042880000001
9000001000001000000010023138010000000250500000000000000
Example (PosReadDebit)
f, err := os.Open(filepath.Join("testdata", "pos-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("POS Card Transaction Type: %s", achFile.Batches[0].GetEntries()[0].DiscretionaryData+"\n")
fmt.Printf("POS Trace Number: %s", achFile.Batches[0].GetEntries()[0].TraceNumber+"\n")
Output:

Total Amount Debit: 100000000
SEC Code: POS
POS Card Transaction Type: 01
POS Trace Number: 121042880000001
Example (PosWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.POS
bh.CompanyEntryDescription = "Sale"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 100000000
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.IndividualName = "Receiver Account Name"
entry.DiscretionaryData = "01"
entry.AddendaRecordIndicator = 1

addenda02 := ach.NewAddenda02()
addenda02.ReferenceInformationOne = "REFONEA"
addenda02.ReferenceInformationTwo = "REF"
addenda02.TerminalIdentificationCode = "TERM02"
addenda02.TransactionSerialNumber = "100049"
addenda02.TransactionDate = "0614"
addenda02.AuthorizationCodeOrExpireDate = "123456"
addenda02.TerminalLocation = "Target Store 0049"
addenda02.TerminalCity = "PHILADELPHIA"
addenda02.TerminalState = "PA"
addenda02.TraceNumber = "121042880000001"

// build the batch
batch := ach.NewBatchPOS(bh)
batch.AddEntry(entry)
batch.GetEntries()[0].Addenda02 = addenda02
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda02.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 POSSale            190816   1121042880000001
62723138010412345678         0100000000               Receiver Account Name 011121042880000001
702REFONEAREFTERM021000490614123456Target Store 0049          PHILADELPHIA   PA121042880000001
82250000020023138010000100000000000000000000231380104                          121042880000001
9000001000001000000020023138010000100000000000000000000
Example (PpdReadCredit)

Example_ppdReadCredit reads a PPD credit file

f, err := os.Open(filepath.Join("testdata", "ppd-credit.ach"))
if err != nil {
	log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
	fmt.Printf("Issue reading file: %+v \n", err)
}

if achFile.Validate(); err != nil {
	fmt.Printf("Could not validate entire read file: %v", err)
}

if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Total File Debit Amount: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Total File Credit Amount: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
Output:

SEC Code: PPD
Total File Debit Amount: 0
Total File Credit Amount: 100000000
Example (PpdReadDebit)

Example_ppdReadDebit reads a PPD debit file

f, err := os.Open(filepath.Join("testdata", "ppd-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Total File Debit Amount: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Total File Credit Amount: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
Output:

SEC Code: PPD
Total File Debit Amount: 200000000
Total File Credit Amount: 0
Example (PpdReadSegmentFile)
// open a file for reading. Any io.Reader Can be used
fCredit, err := os.Open(filepath.Join("testdata", "segmentFile-ppd-credit.ach"))
if err != nil {
	log.Fatal(err)
}
r := ach.NewReader(fCredit)
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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

// open a file for reading. Any io.Reader Can be used
fDebit, err := os.Open(filepath.Join("testdata", "segmentFile-ppd-debit.ach"))
if err != nil {
	log.Fatal(err)
}
rDebit := ach.NewReader(fDebit)
achFileDebit, err := rDebit.Read()
if err != nil {
	fmt.Printf("Issue reading file: %+v \n", err)
}
// ensure we have a validated file structure
if achFileDebit.Validate(); err != nil {
	fmt.Printf("Could not validate entire read file: %v", err)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if achFileDebit.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Credit Amount: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Total Debit Amount: %s", strconv.Itoa(achFileDebit.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFileDebit.Batches[0].GetHeader().StandardEntryClassCode+"\n")
Output:

Total Credit Amount: 200000000
SEC Code: PPD
Total Debit Amount: 200000000
SEC Code: PPD
Example (PpdWriteCredit)

Example_ppdWriteCredit writes a PPD credit file

fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.CreditsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.PPD
bh.CompanyEntryDescription = "REG.SALARY"
// need EffectiveEntryDate to be fixed so it can match output
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "987654321"
entry.Amount = 100000000
entry.SetTraceNumber(bh.ODFIIdentification, 2)
entry.IndividualName = "Credit Account 1"

// build the batch
batch := ach.NewBatchPPD(bh)
batch.AddEntry(entry)

if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5220Name on Account                     231380104 PPDREG.SALARY      190816   1121042880000001
622231380104987654321        0100000000               Credit Account 1        0121042880000002
82200000010023138010000000000000000100000000231380104                          121042880000001
9000001000001000000010023138010000000000000000100000000
Example (PpdWriteDebit)

// Example_ppdWriteDebit writes a PPD debit file

fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.PPD
bh.CompanyEntryDescription = "REG.SALARY"
// need EffectiveEntryDate to be fixed so it can match output
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")           // Receivers bank transit routing number
entry.DFIAccountNumber = "123456789" // Receivers bank account number
entry.Amount = 200000000             // Amount of transaction with no decimal. One dollar and eleven cents = 111
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.IndividualName = "Debit Account" // Identifies the receiver of the transaction

// build the batch
batch := ach.NewBatchPPD(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 PPDREG.SALARY      190816   1121042880000001
627231380104123456789        0200000000               Debit Account           0121042880000001
82250000010023138010000200000000000000000000231380104                          121042880000001
9000001000001000000010023138010000200000000000000000000
Example (PpdWriteSegmentFile)
// open a file for reading. Any io.Reader Can be used
f, err := os.Open(filepath.Join("testdata", "ppd-mixedDebitCredit.ach"))
if err != nil {
	log.Fatal(err)
}
r := ach.NewReader(f)
achFile, err := r.Read()
if err != nil {
	fmt.Printf("Issue reading file: %+v \n", err)
}

// verify a TraceNumber is set
for i := range achFile.Batches {
	ed := achFile.Batches[i].GetEntries()
	for j := range ed {
		if ed[j].TraceNumber == "" {
			log.Fatalf("Batch[%d].Entries[%d] is missing a TraceNumber", i, j)
		}
	}
}

// ensure we have a validated file structure
if achFile.Validate(); err != nil {
	fmt.Printf("Could not validate entire read file: %v", err)
}

sfc := ach.NewSegmentFileConfiguration()
creditFile, debitFile, err := achFile.SegmentFile(sfc)

if err != nil {
	fmt.Printf("Could not segment the file: %v", err)
}

if err := creditFile.Validate(); err != nil {
	log.Fatal(err)
}
if err := debitFile.Validate(); err != nil {
	log.Fatal(err)
}

ed := creditFile.Batches[0].GetEntries()
for i := range ed {
	fmt.Printf("credit %d: %s\n", i, ed[i].String())
}

ed = debitFile.Batches[0].GetEntries()
for i := range ed {
	fmt.Printf("debit %d: %s\n", i, ed[i].String())
}
Output:

credit 0: 622231380104987654321        0100000000               Credit Account 1        0121042880000002
credit 1: 622231380104837098765        0100000000               Credit Account 2        0121042880000003
debit 0: 627231380104123456789        0200000000               Debit Account           0121042880000001
Example (RckReadDebit)
// open a file for reading. Any io.Reader Can be used
f, err := os.Open(filepath.Join("testdata", "rck-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Check Serial Number: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber+"\n")
Output:

Total Amount Debit: 2400
SEC Code: RCK
Check Serial Number: 123123123
Example (RckWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.RCK
bh.CompanyEntryDescription = "REDEPCHECK"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

// Identifies the receivers account information
// can be multiple entry's per batch
entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 2400
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.IndividualName = "Wade Arnold"
entry.SetCheckSerialNumber("123123123")

// build the batch
batch := ach.NewBatchRCK(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 RCKREDEPCHECK      190816   1121042880000001
62723138010412345678         0000002400123123123      Wade Arnold             0121042880000001
82250000010023138010000000002400000000000000231380104                          121042880000001
9000001000001000000010023138010000000002400000000000000
Example (ServerFileCreate)
repo := server.NewRepositoryInMemory(24*time.Hour, nil)
service := server.NewService(repo)
logger := log.NewLogfmtLogger(os.Stderr)
handler := server.MakeHTTPHandler(service, repo, logger)

// Spin up a local HTTP server
server := httptest.NewServer(handler)
defer server.Close()

// Read an Example ach.File in text/plain format
file, err := os.Open(filepath.Join("testdata", "ppd-credit.ach"))
if err != nil {
	lg.Fatal(err)
}

// Make our request
req, err := http.NewRequest("POST", server.URL+"/files/create", file)
if err != nil {
	lg.Fatal(err)
}
req.Header.Set("Content-Type", "text/plain")
resp, err := server.Client().Do(req)
if err != nil {
	lg.Fatal(err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
	lg.Fatalf("got %d HTTP status code", resp.StatusCode)
}

fmt.Printf("%s", strconv.Itoa(resp.StatusCode)+"\n")
Output:

200
Example (ServerFileCreateJSON)
repo := server.NewRepositoryInMemory(24*time.Hour, nil)
service := server.NewService(repo)
logger := log.NewLogfmtLogger(os.Stderr)
handler := server.MakeHTTPHandler(service, repo, logger)

// Spin up a local HTTP server
server := httptest.NewServer(handler)
defer server.Close()

// Read an Example ach.File in JSON format
file, err := os.Open(filepath.Join("testdata", "ppd-valid.json"))
if err != nil {
	lg.Fatal(err)
}

// Make our request
req, err := http.NewRequest("POST", server.URL+"/files/create", file)
if err != nil {
	lg.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := server.Client().Do(req)
if err != nil {
	lg.Fatal(err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
	lg.Fatalf("got %d HTTP status code", resp.StatusCode)
}

fmt.Printf("%s", strconv.Itoa(resp.StatusCode)+"\n")
Output:

200
Example (ShrReadDebit)
f, err := os.Open(filepath.Join("testdata", "shr-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("SHR Card Expiration Date: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber[0:4]+"\n")
fmt.Printf("SHR Document Reference Number: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber[4:15]+"\n")
fmt.Printf("SHR Individual Card Account Number: %s", achFile.Batches[0].GetEntries()[0].IndividualName)
Output:

Total Amount Debit: 100000000
SEC Code: SHR
SHR Card Expiration Date: 0722
SHR Document Reference Number: 12345678910
SHR Individual Card Account Number: 0001234567891123456789
Example (ShrWrite)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.SHR
bh.CompanyEntryDescription = "Payment"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 100000000
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.SetSHRCardExpirationDate("0722")
entry.SetSHRDocumentReferenceNumber("12345678910")
entry.SetSHRIndividualCardAccountNumber("1234567891123456789")
entry.DiscretionaryData = "01"
entry.AddendaRecordIndicator = 1

addenda02 := ach.NewAddenda02()
addenda02.ReferenceInformationOne = "REFONEA"
addenda02.ReferenceInformationTwo = "REF"
addenda02.TerminalIdentificationCode = "TERM02"
addenda02.TransactionSerialNumber = "100049"
addenda02.TransactionDate = "0614"
addenda02.AuthorizationCodeOrExpireDate = "123456"
addenda02.TerminalLocation = "Target Store 0049"
addenda02.TerminalCity = "PHILADELPHIA"
addenda02.TerminalState = "PA"
addenda02.TraceNumber = "121042880000001"

// build the batch
batch := ach.NewBatchSHR(bh)
batch.AddEntry(entry)
batch.GetEntries()[0].Addenda02 = addenda02
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda02.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 SHRPayment         190816   1121042880000001
62723138010412345678         01000000000722123456789100001234567891123456789011121042880000001
702REFONEAREFTERM021000490614123456Target Store 0049          PHILADELPHIA   PA121042880000001
82250000020023138010000100000000000000000000231380104                          121042880000001
9000001000001000000020023138010000100000000000000000000
Example (TelReadDebit)
f, err := os.Open(filepath.Join("testdata", "tel-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
Output:

Total Amount Debit: 50000
SEC Code: TEL
Example (TelWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.TEL
bh.CompanyEntryDescription = "Payment"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 50000
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.IndividualName = "Receiver Account Name"

// build the batch
batch := ach.NewBatchTEL(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 TELPayment         190816   1121042880000001
62723138010412345678         0000050000               Receiver Account Name   0121042880000001
82250000010023138010000000050000000000000000231380104                          121042880000001
9000001000001000000010023138010000000050000000000000000
Example (TrcReadDebit)
f, err := os.Open(filepath.Join("testdata", "trc-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Check Serial Number: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber+"\n")
fmt.Printf("Process Control Field: %s", achFile.Batches[0].GetEntries()[0].IndividualName[0:6]+"\n")
fmt.Printf("Item Research Number: %s", achFile.Batches[0].GetEntries()[0].IndividualName[6:22]+"\n")
fmt.Printf("Item Type Indicator: %s", achFile.Batches[0].GetEntries()[0].DiscretionaryData+"\n")
Output:

Total Amount Debit: 250000
SEC Code: TRC
Check Serial Number: 123456789012345
Process Control Field: CHECK1
Item Research Number: 1234567890123456
Item Type Indicator: 01
Example (TrcWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.TRC
bh.CompanyEntryDescription = "ACH TRC"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 250000
entry.SetCheckSerialNumber("123456789012345")
entry.SetProcessControlField("CHECK1")
entry.SetItemResearchNumber("1234567890123456")
entry.SetItemTypeIndicator("01")
entry.SetTraceNumber(bh.ODFIIdentification, 1)

// build the batch
batch := ach.NewBatchTRC(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Payee Name                          231380104 TRCACH TRC         190816   1121042880000001
62723138010412345678         0000250000123456789012345CHECK11234567890123456010121042880000001
82250000010023138010000000250000000000000000231380104                          121042880000001
9000001000001000000010023138010000000250000000000000000
Example (TrxReadDebit)
f, err := os.Open(filepath.Join("testdata", "trx-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Total Amount Credit: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Item Type Indicator: %s", achFile.Batches[0].GetEntries()[0].ItemTypeIndicator()+"\n")
fmt.Printf("Addenda1: %s", achFile.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("Addenda2: %s", achFile.Batches[0].GetEntries()[0].Addenda05[1].String()+"\n")
Output:

Total Amount Debit: 250000
Total Amount Credit: 0
SEC Code: TRX
Item Type Indicator: 01
Addenda1: 705Debit First Account                                                             00010000001
Addenda2: 705Debit Second Account                                                            00020000001
Example (TrxWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.TRX
bh.CompanyEntryDescription = "ACH TRX"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 250000
entry.IdentificationNumber = "45689033"
entry.SetCATXAddendaRecords(2)
entry.SetCATXReceivingCompany("Receiver Company")
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.SetItemTypeIndicator("01")

addenda1 := ach.NewAddenda05()
addenda1.PaymentRelatedInformation = "Debit First Account"
addenda1.SequenceNumber = 1
addenda1.EntryDetailSequenceNumber = 0000001

addenda2 := ach.NewAddenda05()
addenda2.PaymentRelatedInformation = "Debit Second Account"
addenda2.SequenceNumber = 2
addenda2.EntryDetailSequenceNumber = 0000001

// build the batch
batch := ach.NewBatchTRX(bh)
batch.AddEntry(entry)
batch.Entries[0].AddendaRecordIndicator = 1
batch.GetEntries()[0].AddAddenda05(addenda1)
batch.GetEntries()[0].AddAddenda05(addenda2)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda05[1].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Name on Account                     231380104 TRXACH TRX         190816   1121042880000001
62723138010412345678         000025000045689033       0002Receiver Company  011121042880000001
705Debit First Account                                                             00010000001
705Debit Second Account                                                            00020000001
82250000030023138010000000250000000000000000231380104                          121042880000001
9000001000001000000030023138010000000250000000000000000
Example (WebReadCredit)

Example_webReadCredit reads a WEB credit file

// open a file for reading. Any io.Reader Can be used
f, err := os.Open(filepath.Join("testdata", "web-credit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Total File Debit Amount: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("Total File Credit Amount: %s", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile)+"\n")
Output:

SEC Code: WEB
Total File Debit Amount: 0
Total File Credit Amount: 10000
Example (WebWriteCredit)

Example_webWriteCredit writes a WEB credit file

fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.CreditsOnly
bh.CompanyName = "Name on Account"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.WEB
bh.CompanyEntryDescription = "Subscribe"
// need EffectiveEntryDate to be fixed so it can match output
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingCredit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 10000
entry.IndividualName = "John Doe"
entry.SetTraceNumber(bh.ODFIIdentification, 1)
entry.IdentificationNumber = "#789654"
entry.DiscretionaryData = "S"
entry.Category = ach.CategoryForward
entry.AddendaRecordIndicator = 1

addenda1 := ach.NewAddenda05()
addenda1.PaymentRelatedInformation = "PAY-GATE payment\\"
entry.AddAddenda05(addenda1)

// build the batch
batch := ach.NewBatchWEB(bh)
batch.AddEntry(entry)

if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].Addenda05[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5220Name on Account                     231380104 WEBSubscribe       190816   1121042880000001
62223138010412345678         0000010000#789654        John Doe              S 1121042880000001
705PAY-GATE payment\                                                               00010000001
82200000020023138010000000000000000000010000231380104                          121042880000001
9000001000001000000020023138010000000000000000000010000
Example (XckReadDebit)
f, err := os.Open(filepath.Join("testdata", "xck-debit.ach"))
if err != nil {
	log.Fatal(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)
}
// If you trust the file but it's formatting is off building will probably resolve the malformed file.
if err := achFile.Create(); err != nil {
	fmt.Printf("Could not create file with read properties: %v", err)
}

fmt.Printf("Total Amount Debit: %s", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)+"\n")
fmt.Printf("SEC Code: %s", achFile.Batches[0].GetHeader().StandardEntryClassCode+"\n")
fmt.Printf("Check Serial Number: %s", achFile.Batches[0].GetEntries()[0].IdentificationNumber+"\n")
fmt.Printf("Process Control Field: %s", achFile.Batches[0].GetEntries()[0].IndividualName[0:6]+"\n")
fmt.Printf("Item Research Number: %s", achFile.Batches[0].GetEntries()[0].IndividualName[6:22]+"\n")
Output:

Total Amount Debit: 250000
SEC Code: XCK
Check Serial Number: 123456789012345
Process Control Field: CHECK1
Item Research Number: 1234567890123456
Example (XckWriteDebit)
fh := mockFileHeader()

bh := ach.NewBatchHeader()
bh.ServiceClassCode = ach.DebitsOnly
bh.CompanyName = "Payee Name"
bh.CompanyIdentification = fh.ImmediateOrigin
bh.StandardEntryClassCode = ach.XCK
bh.CompanyEntryDescription = "ACH XCK"
bh.EffectiveEntryDate = "190816"
bh.ODFIIdentification = "121042882"

entry := ach.NewEntryDetail()
entry.TransactionCode = ach.CheckingDebit
entry.SetRDFI("231380104")
entry.DFIAccountNumber = "12345678"
entry.Amount = 250000
entry.SetCheckSerialNumber("123456789012345")
entry.SetProcessControlField("CHECK1")
entry.SetItemResearchNumber("1234567890123456")
entry.SetTraceNumber(bh.ODFIIdentification, 1)

// build the batch
batch := ach.NewBatchXCK(bh)
batch.AddEntry(entry)
if err := batch.Create(); err != nil {
	log.Fatalf("Unexpected error building batch: %s\n", err)
}

// build the file
file := ach.NewFile()
file.SetHeader(fh)
file.AddBatch(batch)
if err := file.Create(); err != nil {
	log.Fatalf("Unexpected error building file: %s\n", err)
}

fmt.Printf("%s", file.Header.String()+"\n")
fmt.Printf("%s", file.Batches[0].GetHeader().String()+"\n")
fmt.Printf("%s", file.Batches[0].GetEntries()[0].String()+"\n")
fmt.Printf("%s", file.Batches[0].GetControl().String()+"\n")
fmt.Printf("%s", file.Control.String()+"\n")
Output:

101 031300012 2313801041908161055A094101Federal Reserve Bank   My Bank Name           12345678
5225Payee Name                          231380104 XCKACH XCK         190816   1121042880000001
62723138010412345678         0000250000123456789012345CHECK11234567890123456  0121042880000001
82250000010023138010000000250000000000000000231380104                          121042880000001
9000001000001000000010023138010000000250000000000000000

Directories

Path Synopsis
Package main is an example for creating an Automated Clearing House (ACH) file with Moov's HTTP service.
Package main is an example for creating an Automated Clearing House (ACH) file with Moov's HTTP service.

Jump to

Keyboard shortcuts

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