Documentation ¶
Overview ¶
Example (AckRead) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "ack-read.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Credit Total Amount: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile) fmt.Printf("Batch Credit Total Amount: %d\n", achFile.Batches[0].GetEntries()[0].Amount) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Original Trace Number: %s\n", 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) ¶
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" bh.EffectiveEntryDate = "190816" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[1].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "adv-read.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Credit Total Amount: %d\n", achFile.ADVControl.TotalCreditEntryDollarAmountInFile) fmt.Printf("Debit Total Amount: %d\n", achFile.ADVControl.TotalDebitEntryDollarAmountInFile) fmt.Printf("OriginatorStatusCode: %d\n", achFile.Batches[0].GetHeader().OriginatorStatusCode) fmt.Printf("Batch Credit Total Amount: %d\n", achFile.Batches[0].GetADVControl().TotalCreditEntryDollarAmount) fmt.Printf("Batch Debit Total Amount: %d\n", achFile.Batches[0].GetADVControl().TotalDebitEntryDollarAmount) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Entry Amount: %d\n", achFile.Batches[0].GetADVEntries()[0].Amount) fmt.Printf("Sequence Number: %d\n", achFile.Batches[0].GetADVEntries()[0].SequenceNumber) fmt.Printf("EntryOne Amount: %d\n", achFile.Batches[0].GetADVEntries()[1].Amount) fmt.Printf("EntryOne Sequence Number: %d\n", achFile.Batches[0].GetADVEntries()[1].SequenceNumber)
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetADVEntries()[0].String()) fmt.Println(file.Batches[0].GetADVEntries()[1].String()) fmt.Println(file.Batches[0].GetADVControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "arc-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Check Serial Number: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber)
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "atx-read.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total Amount Credit: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Total Amount: %d\n", achFile.Batches[0].GetEntries()[0].Amount) fmt.Printf("Original Trace Number: %s\n", achFile.Batches[0].GetEntries()[0].OriginalTraceNumberField()) fmt.Printf("Addenda1: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Printf("Addenda2: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[1].String()) fmt.Printf("Total Amount: %d\n", achFile.Batches[0].GetEntries()[1].Amount) fmt.Printf("Original Trace Number: %s\n", achFile.Batches[0].GetEntries()[1].OriginalTraceNumberField()) fmt.Printf("Addenda1: %s\n", achFile.Batches[0].GetEntries()[1].Addenda05[0].String()) fmt.Printf("Addenda2: %s\n", achFile.Batches[0].GetEntries()[1].Addenda05[1].String())
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Println(file.Batches[0].GetEntries()[1].String()) fmt.Println(file.Batches[0].GetEntries()[1].Addenda05[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "boc-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Check Serial Number: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber)
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "ccd-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total Amount Credit: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("CCD Entry Identification Number: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber) fmt.Printf("CCD Entry Receiving Company: %s\n", achFile.Batches[0].GetEntries()[0].IndividualName) fmt.Printf("CCD Entry Trace Number: %s\n", achFile.Batches[0].GetEntries()[0].TraceNumberField()) fmt.Printf("CCD Fee Identification Number: %s\n", achFile.Batches[0].GetEntries()[1].IdentificationNumber) fmt.Printf("CCD Fee Receiving Company: %s\n", achFile.Batches[0].GetEntries()[1].IndividualName) fmt.Printf("CCD Fee Trace Number: %s\n", achFile.Batches[0].GetEntries()[1].TraceNumberField())
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[1].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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 (CieReadCredit) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "cie-credit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total Amount Credit: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Addenda05: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[0].String())
Output: Total Amount Debit: 0 Total Amount Credit: 100000000 SEC Code: CIE Addenda05: 705Credit Store Account 00010000001
Example (CieWriteCredit) ¶
fh := mockFileHeader() bh := ach.NewBatchHeader() bh.ServiceClassCode = ach.CreditsOnly bh.CompanyName = "Name on Account" bh.CompanyIdentification = fh.ImmediateOrigin bh.StandardEntryClassCode = ach.CIE bh.CompanyEntryDescription = "Payment" bh.EffectiveEntryDate = "190816" // need EffectiveEntryDate to be fixed so it can match output bh.ODFIIdentification = "121042882" entry := ach.NewEntryDetail() entry.TransactionCode = ach.CheckingCredit 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 addenda05 := ach.NewAddenda05() addenda05.PaymentRelatedInformation = "Credit Store Account" addenda05.SequenceNumber = 1 addenda05.EntryDetailSequenceNumber = 0000001 // build the batch batch := ach.NewBatchCIE(bh) batch.AddEntry(entry) batch.GetEntries()[0].AddAddenda05(addenda05) 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
Output: 101 031300012 2313801041908161055A094101Federal Reserve Bank My Bank Name 12345678 5220Name on Account 231380104 CIEPayment 190816 1121042880000001 62223138010412345678 0100000000 Receiver Account Name 011121042880000001 705Credit Store Account 00010000001 82200000020023138010000000000000000100000000231380104 121042880000001 9000001000001000000020023138010000000000000000100000000
Example (CorReadCredit) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "cor-read.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total Amount Credit: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Entry Detail: %s\n", achFile.Batches[0].GetEntries()[0].String()) fmt.Printf("Addenda98: %s\n", achFile.Batches[0].GetEntries()[0].Addenda98.String())
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) ¶
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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda98.String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "ctx-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total Amount Credit: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Addenda1: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Printf("Addenda2: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[1].String())
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[1].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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 (CustomReturnCode) ¶
Example_customReturnCode writes an ACH file with a non-standard Return Code
fh := mockFileHeader() bh := ach.NewBatchHeader() bh.ServiceClassCode = ach.CreditsOnly bh.CompanyName = "My Company" bh.CompanyIdentification = fh.ImmediateOrigin bh.StandardEntryClassCode = ach.PPD bh.CompanyEntryDescription = "Cash Back" bh.EffectiveEntryDate = "190816" // need EffectiveEntryDate to be fixed so it can match output bh.ODFIIdentification = "987654320" entry := ach.NewEntryDetail() entry.TransactionCode = 22 // example of a custom code entry.SetRDFI("123456780") entry.DFIAccountNumber = "12567" entry.Amount = 100000000 entry.SetTraceNumber(bh.ODFIIdentification, 2) entry.IndividualName = "Jane Smith" addenda99 := ach.NewAddenda99() addenda99.ReturnCode = "abc" entry.Addenda99 = addenda99 entry.Category = ach.CategoryReturn entry.AddendaRecordIndicator = 1 entry.Addenda99.SetValidation(&ach.ValidateOpts{ CustomReturnCodes: true, }) // 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("TransactionCode=%d\n", file.Batches[0].GetEntries()[0].TransactionCode) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Printf("ReturnCode=%s\n", strings.TrimSpace(file.Batches[0].GetEntries()[0].Addenda99.ReturnCode))
Output: TransactionCode=22 62212345678012567 0100000000 Jane Smith 1987654320000002 ReturnCode=abc
Example (CustomTraceNumber) ¶
Example_customTraceNumber writes an ACH file with a non-standard NACHA TraceNumber
fh := mockFileHeader() bh := ach.NewBatchHeader() bh.ServiceClassCode = ach.CreditsOnly bh.CompanyName = "My Company" bh.CompanyIdentification = fh.ImmediateOrigin bh.StandardEntryClassCode = ach.PPD bh.CompanyEntryDescription = "Cash Back" // fix EffectiveEntryDate for consistent output bh.EffectiveEntryDate = "190816" bh.ODFIIdentification = "987654320" entry := ach.NewEntryDetail() entry.TransactionCode = ach.CheckingCredit entry.SetRDFI("123456780") entry.DFIAccountNumber = "12567" entry.Amount = 100000000 entry.TraceNumber = "321888" entry.IndividualName = "Jane Smith" // build the batch batch := ach.NewBatchPPD(bh) batch.SetValidation(&ach.ValidateOpts{ CustomTraceNumbers: true, }) 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) } if err := file.Validate(); err != nil { log.Fatalf("Unexpected validation error: %v", err) } if trace := file.Batches[0].GetEntries()[0].TraceNumber; trace != "321888" { log.Fatalf("Unexpected trace number: %s", trace) } fmt.Printf("TransactionCode=%d\n", file.Batches[0].GetEntries()[0].TransactionCode) fmt.Printf("%s\n", file.Batches[0].GetEntries()[0].String())
Output: TransactionCode=22 62212345678012567 0100000000 Jane Smith 0000000000321888
Example (CustomTransactionCode) ¶
Example_customTransactionCode writes an ACH file with a non-standard NACHA TransactionCodes
validationOpts := &ach.ValidateOpts{ // CheckTransactionCode lets us override the standard set of NACHA // codes for applications which use custom TransactionCode values. CheckTransactionCode: func(code int) error { // Is it a custom TransactionCode of ours? if code == 78 { return nil } // Is it a NACHA standard code? return ach.StandardTransactionCode(code) }, } fh := mockFileHeader() bh := ach.NewBatchHeader() bh.ServiceClassCode = ach.CreditsOnly bh.CompanyName = "My Company" bh.CompanyIdentification = fh.ImmediateOrigin bh.StandardEntryClassCode = ach.PPD bh.CompanyEntryDescription = "Cash Back" bh.EffectiveEntryDate = "190816" // need EffectiveEntryDate to be fixed so it can match output bh.ODFIIdentification = "987654320" bh.SetValidation(validationOpts) entry := ach.NewEntryDetail() entry.TransactionCode = 78 // example of a custom code entry.SetRDFI("123456780") entry.DFIAccountNumber = "12567" entry.Amount = 100000000 entry.SetTraceNumber(bh.ODFIIdentification, 2) entry.IndividualName = "Jane Smith" entry.SetValidation(validationOpts) // 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("TransactionCode=%d\n", file.Batches[0].GetEntries()[0].TransactionCode) fmt.Println(file.Batches[0].GetEntries()[0].String())
Output: TransactionCode=78 67812345678012567 0100000000 Jane Smith 0987654320000002
Example (DneRead) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "dne-read.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount: %d\n", achFile.Batches[0].GetEntries()[0].Amount) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Payment Related Information: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[0].String())
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "enr-read.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount: %d\n", achFile.Batches[0].GetEntries()[0].Amount) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Payment Related Information: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[0].String())
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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "iat-mixedCreditDebit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("SEC Code: %s\n", achFile.IATBatches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Debit Entry: %s\n", achFile.IATBatches[0].Entries[0].String()) fmt.Printf("Addenda10: %s\n", achFile.IATBatches[0].Entries[0].Addenda10.String()) fmt.Printf("Addenda11: %s\n", achFile.IATBatches[0].Entries[0].Addenda11.String()) fmt.Printf("Addenda12: %s\n", achFile.IATBatches[0].Entries[0].Addenda12.String()) fmt.Printf("Addenda13: %s\n", achFile.IATBatches[0].Entries[0].Addenda13.String()) fmt.Printf("Addenda14: %s\n", achFile.IATBatches[0].Entries[0].Addenda14.String()) fmt.Printf("Addenda15: %s\n", achFile.IATBatches[0].Entries[0].Addenda15.String()) fmt.Printf("Addenda16: %s\n", achFile.IATBatches[0].Entries[0].Addenda16.String()) fmt.Printf("Addenda17: %s\n", achFile.IATBatches[0].Entries[0].Addenda17[0].String()) fmt.Printf("Addenda18: %s\n", achFile.IATBatches[0].Entries[0].Addenda18[0].String()) fmt.Printf("Total File Debit Amount: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Credit Entry: %s\n", achFile.IATBatches[0].Entries[1].String()) fmt.Printf("Addenda10: %s\n", achFile.IATBatches[0].Entries[1].Addenda10.String()) fmt.Printf("Addenda11: %s\n", achFile.IATBatches[0].Entries[1].Addenda11.String()) fmt.Printf("Addenda12: %s\n", achFile.IATBatches[0].Entries[1].Addenda12.String()) fmt.Printf("Addenda13: %s\n", achFile.IATBatches[0].Entries[1].Addenda13.String()) fmt.Printf("Addenda14: %s\n", achFile.IATBatches[0].Entries[1].Addenda14.String()) fmt.Printf("Addenda15: %s\n", achFile.IATBatches[0].Entries[1].Addenda15.String()) fmt.Printf("Addenda16: %s\n", achFile.IATBatches[0].Entries[1].Addenda16.String()) fmt.Printf("Addenda17: %s\n", achFile.IATBatches[0].Entries[1].Addenda17[0].String()) fmt.Printf("Addenda18: %s\n", achFile.IATBatches[0].Entries[1].Addenda18[0].String()) fmt.Printf("Total File Credit Amount: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile)
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" // need EffectiveEntryDate to be fixed so it can match output 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 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\n", achFile.IATBatches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Debit Entry: %s\n", achFile.IATBatches[0].Entries[0].String()) fmt.Printf("Addenda10: %s\n", achFile.IATBatches[0].Entries[0].Addenda10.String()) fmt.Printf("Addenda11: %s\n", achFile.IATBatches[0].Entries[0].Addenda11.String()) fmt.Printf("Addenda12: %s\n", achFile.IATBatches[0].Entries[0].Addenda12.String()) fmt.Printf("Addenda13: %s\n", achFile.IATBatches[0].Entries[0].Addenda13.String()) fmt.Printf("Addenda14: %s\n", achFile.IATBatches[0].Entries[0].Addenda14.String()) fmt.Printf("Addenda15: %s\n", achFile.IATBatches[0].Entries[0].Addenda15.String()) fmt.Printf("Addenda16: %s\n", achFile.IATBatches[0].Entries[0].Addenda16.String()) fmt.Printf("Addenda17: %s\n", achFile.IATBatches[0].Entries[0].Addenda17[0].String()) fmt.Printf("Addenda18: %s\n", achFile.IATBatches[0].Entries[0].Addenda18[0].String()) fmt.Printf("Total File Debit Amount: %s\n", strconv.Itoa(achFile.Control.TotalDebitEntryDollarAmountInFile)) fmt.Printf("Credit Entry: %s\n", achFile.IATBatches[0].Entries[1].String()) fmt.Printf("Addenda10: %s\n", achFile.IATBatches[0].Entries[1].Addenda10.String()) fmt.Printf("Addenda11: %s\n", achFile.IATBatches[0].Entries[1].Addenda11.String()) fmt.Printf("Addenda12: %s\n", achFile.IATBatches[0].Entries[1].Addenda12.String()) fmt.Printf("Addenda13: %s\n", achFile.IATBatches[0].Entries[1].Addenda13.String()) fmt.Printf("Addenda14: %s\n", achFile.IATBatches[0].Entries[1].Addenda14.String()) fmt.Printf("Addenda15: %s\n", achFile.IATBatches[0].Entries[1].Addenda15.String()) fmt.Printf("Addenda16: %s\n", achFile.IATBatches[0].Entries[1].Addenda16.String()) fmt.Printf("Addenda17: %s\n", achFile.IATBatches[0].Entries[1].Addenda17[0].String()) fmt.Printf("Addenda18: %s\n", achFile.IATBatches[0].Entries[1].Addenda18[0].String()) fmt.Printf("Total File Credit Amount: %s\n", strconv.Itoa(achFile.Control.TotalCreditEntryDollarAmountInFile))
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "mte-read.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount: %d\n", achFile.Batches[0].GetEntries()[0].Amount) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Addenda02: %s\n", achFile.Batches[0].GetEntries()[0].Addenda02.String())
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "pop-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("POP Check Serial Number: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber[0:9]) fmt.Printf("POP Terminal City: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber[9:13]) fmt.Printf("POP Terminal State: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber[13:15])
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "pos-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("POS Card Transaction Type: %s\n", achFile.Batches[0].GetEntries()[0].DiscretionaryData) fmt.Printf("POS Trace Number: %s\n", achFile.Batches[0].GetEntries()[0].TraceNumber)
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda02.String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "ppd-credit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Total File Debit Amount: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total File Credit Amount: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile)
Output: SEC Code: PPD Total File Debit Amount: 0 Total File Credit Amount: 100000000
Example (PpdReadDebit) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "ppd-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Total File Debit Amount: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total File Credit Amount: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile)
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.Fatalln(err) } rCredit := ach.NewReader(fCredit) achFileCredit, err := rCredit.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFileCredit.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFileCredit.Validate(); err != nil { log.Fatalf("validating file: %v\n", 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.Fatalln(err) } rDebit := ach.NewReader(fDebit) achFileDebit, err := rDebit.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFileDebit.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFileDebit.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Credit Amount: %d\n", achFileCredit.Control.TotalCreditEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFileCredit.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Total Debit Amount: %d\n", achFileDebit.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFileDebit.Batches[0].GetHeader().StandardEntryClassCode)
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" bh.EffectiveEntryDate = "190816" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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" bh.EffectiveEntryDate = "190816" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Check Serial Number: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber)
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" // need EffectiveEntryDate to be fixed so it can match output bh.ODFIIdentification = "121042882" // Identifies the receivers account information // can be multiple entries 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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(log.NewSyncWriter(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(log.NewSyncWriter(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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "shr-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("SHR Card Expiration Date: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber[0:4]) fmt.Printf("SHR Document Reference Number: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber[4:15]) fmt.Printf("SHR Individual Card Account Number: %s\n", 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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda02.String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "tel-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode)
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "trc-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Check Serial Number: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber) fmt.Printf("Process Control Field: %s\n", achFile.Batches[0].GetEntries()[0].IndividualName[0:6]) fmt.Printf("Item Research Number: %s\n", achFile.Batches[0].GetEntries()[0].IndividualName[6:22]) fmt.Printf("Item Type Indicator: %s\n", achFile.Batches[0].GetEntries()[0].DiscretionaryData)
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
Output: 101 031300012 2313801041908161055A094101Federal Reserve Bank My Bank Name 12345678 5225Payee Name 231380104 TRCACH TRC 190816 1121042880000001 62723138010412345678 0000250000123456789012345CHECK11234567890123456010121042880000001 82250000010023138010000000250000000000000000231380104 121042880000001 9000001000001000000010023138010000000250000000000000000
Example (TrxReadDebit) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "trx-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total Amount Credit: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Item Type Indicator: %s\n", achFile.Batches[0].GetEntries()[0].ItemTypeIndicator()) fmt.Printf("Addenda1: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Printf("Addenda2: %s\n", achFile.Batches[0].GetEntries()[0].Addenda05[1].String())
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[1].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// 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.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Total File Debit Amount: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("Total File Credit Amount: %d\n", achFile.Control.TotalCreditEntryDollarAmountInFile)
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" bh.EffectiveEntryDate = "190816" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetEntries()[0].Addenda05[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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) ¶
// Open a file for reading, any io.Reader can be used f, err := os.Open(filepath.Join("testdata", "xck-debit.ach")) if err != nil { log.Fatalln(err) } r := ach.NewReader(f) achFile, err := r.Read() if err != nil { log.Fatalf("reading file: %v\n", err) } // If you trust the file but its formatting is off, building will probably resolve the malformed file if err := achFile.Create(); err != nil { log.Fatalf("creating file: %v\n", err) } // Validate the ACH file if err := achFile.Validate(); err != nil { log.Fatalf("validating file: %v\n", err) } fmt.Printf("Total Amount Debit: %d\n", achFile.Control.TotalDebitEntryDollarAmountInFile) fmt.Printf("SEC Code: %s\n", achFile.Batches[0].GetHeader().StandardEntryClassCode) fmt.Printf("Check Serial Number: %s\n", achFile.Batches[0].GetEntries()[0].IdentificationNumber) fmt.Printf("Process Control Field: %s\n", achFile.Batches[0].GetEntries()[0].IndividualName[0:6]) fmt.Printf("Item Research Number: %s\n", achFile.Batches[0].GetEntries()[0].IndividualName[6:22])
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" // need EffectiveEntryDate to be fixed so it can match output 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.Println(file.Header.String()) fmt.Println(file.Batches[0].GetHeader().String()) fmt.Println(file.Batches[0].GetEntries()[0].String()) fmt.Println(file.Batches[0].GetControl().String()) fmt.Println(file.Control.String())
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. |
Package main shows an example of creating micro-deposits to validate an account.
|
Package main shows an example of creating micro-deposits to validate an account. |
Click to show internal directories.
Click to hide internal directories.