Repository: moov-io/ach
Pull request #230 (2018-07-26 16:01:03)

211 test package


Patch:
diff --git a/iatBatch.go b/iatBatch.go
index 22eccb13..7b7723ed 100644
--- a/iatBatch.go
+++ b/iatBatch.go
@@ -41,8 +41,8 @@ type IATBatch struct {
 	converters
 }
 
-// IATNewBatch takes a BatchHeader and returns a matching SEC code batch type that is a batcher. Returns an error if the SEC code is not supported.
-func IATNewBatch(bh *IATBatchHeader) IATBatch {
+// NewIATBatch takes a BatchHeader and returns a matching SEC code batch type that is a batcher. Returns an error if the SEC code is not supported.
+func NewIATBatch(bh *IATBatchHeader) IATBatch {
 	iatBatch := IATBatch{}
 	iatBatch.SetControl(NewBatchControl())
 	iatBatch.SetHeader(bh)
diff --git a/reader.go b/reader.go
index 3af43a33..6e12b280 100644
--- a/reader.go
+++ b/reader.go
@@ -393,7 +393,7 @@ func (r *Reader) parseIATBatchHeader() error {
 	}
 
 	// Passing BatchHeader into NewBatchIAT creates a Batcher of IAT SEC code type.
-	iatBatch := IATNewBatch(bh)
+	iatBatch := NewIATBatch(bh)
 
 	r.addIATCurrentBatch(iatBatch)
 


Test patch:
diff --git a/iatEntryDetail_test.go b/iatEntryDetail_test.go
index b6ceed1b..117b2de8 100644
--- a/iatEntryDetail_test.go
+++ b/iatEntryDetail_test.go
@@ -78,7 +78,7 @@ func BenchmarkIATMockEntryDetail(b *testing.B) {
 func testParseIATEntryDetail(t testing.TB) {
 	var line = "6221210428820007             000010000012345678901234567890123456789012345    1231380100000001"
 	r := NewReader(strings.NewReader(line))
-	r.addIATCurrentBatch(IATNewBatch(mockIATBatchHeaderFF()))
+	r.addIATCurrentBatch(NewIATBatch(mockIATBatchHeaderFF()))
 	r.IATCurrentBatch.SetHeader(mockIATBatchHeaderFF())
 	r.line = line
 	if err := r.parseIATEntryDetail(); err != nil {
@@ -134,7 +134,7 @@ func BenchmarkParseIATEntryDetail(b *testing.B) {
 func testIATEDString(t testing.TB) {
 	var line = "6221210428820007             000010000012345678901234567890123456789012345    1231380100000001"
 	r := NewReader(strings.NewReader(line))
-	r.addIATCurrentBatch(IATNewBatch(mockIATBatchHeaderFF()))
+	r.addIATCurrentBatch(NewIATBatch(mockIATBatchHeaderFF()))
 	r.IATCurrentBatch.SetHeader(mockIATBatchHeaderFF())
 	r.line = line
 	if err := r.parseIATEntryDetail(); err != nil {
diff --git a/test/ach-iat-read/iat-ach.ach b/test/ach-iat-read/iat-ach.ach
new file mode 100644
index 00000000..838ccda7
--- /dev/null
+++ b/test/ach-iat-read/iat-ach.ach
@@ -0,0 +1,20 @@
+101 121042882 2313801041807260000A094101Bank                   My Bank Name                   
+5220                FF3               US123456789 IATTRADEPAYMTCADUSD010101   0231380100000001
+6271210428820007             0000100000123456789                              1231380100000001
+710ANN000000000000100000928383-23938          BEK Enterprises                          0000001
+711BEK Solutions                      15 West Place Street                             0000001
+712JacobsTown*PA\                     US*19305\                                        0000001
+713Wells Fargo                        01231380104                         US           0000001
+714Citadel Bank                       01121042882                         CA           0000001
+7159874654932139872121 Front Street                                                    0000001
+716LetterTown*AB\                     CA*80014\                                        0000001
+717This is an international payment                                                00010000001
+718Bank of France                     01456456456987987                   FR       00010000001
+82200000100012104288000000100000000000000000                                   231380100000001
+9000001000002000000100012104288000000100000000000000000                                       
+9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
+9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
+9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
+9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
+9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
+9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
\ No newline at end of file
diff --git a/test/ach-iat-read/main.go b/test/ach-iat-read/main.go
new file mode 100644
index 00000000..8dabd960
--- /dev/null
+++ b/test/ach-iat-read/main.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+	"fmt"
+	"github.com/moov-io/ach"
+	"log"
+	"os"
+)
+
+func main() {
+	// open a file for reading. Any io.Reader Can be used
+	f, err := os.Open("iat-ach.ach")
+	if err != nil {
+		log.Fatal(err)
+	}
+	r := ach.NewReader(f)
+	achFile, err := r.Read()
+	if err != nil {
+		fmt.Printf("Issue reading file: %+v \n", err)
+	}
+	// ensure we have a validated file structure
+	if achFile.Validate(); err != nil {
+		fmt.Printf("Could not validate entire read file: %v", err)
+	}
+	// If you trust the file but it's formatting is off building will probably resolve the malformed file.
+	if achFile.Create(); err != nil {
+		fmt.Printf("Could not build file with read properties: %v", err)
+	}
+
+	fmt.Printf("Total Amount Debit: %v \n", achFile.Control.TotalDebitEntryDollarAmountInFile)
+	fmt.Printf("SEC Code: %v \n", achFile.IATBatches[0].GetHeader().StandardEntryClassCode)
+	fmt.Printf("Entry: %v \n", achFile.IATBatches[0].GetEntries()[0])
+	fmt.Printf("Addenda Record Indicator: %v \n", achFile.IATBatches[0].GetEntries()[0].AddendaRecordIndicator)
+	fmt.Printf("Addenda10: %v \n", achFile.IATBatches[0].GetEntries()[0].Addenda10)
+	fmt.Printf("Addenda11: %v \n", achFile.IATBatches[0].GetEntries()[0].Addenda11)
+	fmt.Printf("Addenda12: %v \n", achFile.IATBatches[0].GetEntries()[0].Addenda12)
+	fmt.Printf("Addenda13: %v \n", achFile.IATBatches[0].GetEntries()[0].Addenda13)
+	fmt.Printf("Addenda14: %v \n", achFile.IATBatches[0].GetEntries()[0].Addenda14)
+	fmt.Printf("Addenda15: %v \n", achFile.IATBatches[0].GetEntries()[0].Addenda15)
+	fmt.Printf("Addenda16: %v \n", achFile.IATBatches[0].GetEntries()[0].Addenda16)
+	fmt.Printf("Addenda17: %v \n", achFile.IATBatches[0].GetEntries()[0].Addendum[0].String())
+	fmt.Printf("Addenda18: %v \n", achFile.IATBatches[0].GetEntries()[0].Addendum[1].String())
+}
diff --git a/test/ach-iat-read/main_test.go b/test/ach-iat-read/main_test.go
new file mode 100644
index 00000000..45fcc779
--- /dev/null
+++ b/test/ach-iat-read/main_test.go
@@ -0,0 +1,7 @@
+package main
+
+import "testing"
+
+func Test(t *testing.T) {
+	main()
+}
diff --git a/test/ach-iat-write/main.go b/test/ach-iat-write/main.go
new file mode 100644
index 00000000..90608201
--- /dev/null
+++ b/test/ach-iat-write/main.go
@@ -0,0 +1,133 @@
+package main
+
+import (
+	"time"
+	"github.com/moov-io/ach"
+	"log"
+	"os"
+)
+
+func main() {
+	// Example transfer to write an ACH IAT file to debit a external institutions account
+	// Important: All financial institutions are different and will require registration and exact field values.
+
+	// Set originator bank ODFI and destination Operator for the financial institution
+	// this is the funding/receiving source of the transfer
+	fh := ach.NewFileHeader()
+	fh.ImmediateDestination = "121042882" // Routing Number of the ACH Operator or receiving point to which the file is being sent
+	fh.ImmediateOrigin = "231380104" // Routing Number of the ACH Operator or sending point that is sending the file
+	fh.FileCreationDate = time.Now()      // Today's Date
+	fh.ImmediateDestinationName = "Bank"
+	fh.ImmediateOriginName = "My Bank Name"
+
+	// BatchHeader identifies the originating entity and the type of transactions contained in the batch
+	bh := ach.NewIATBatchHeader()
+	bh.ServiceClassCode = 220
+	bh.ForeignExchangeIndicator = "FF"
+	bh.ForeignExchangeReferenceIndicator = 3
+	bh.ISODestinationCountryCode = "US"
+	bh.OriginatorIdentification = "123456789"
+	bh.StandardEntryClassCode = "IAT"
+	bh.CompanyEntryDescription = "TRADEPAYMT"
+	bh.ISOOriginatingCurrencyCode = "CAD"
+	bh.ISODestinationCurrencyCode = "USD"
+	bh.ODFIIdentification = "23138010"
+
+	// Identifies the receivers account information
+	// can be multiple entry's per batch
+	entry := ach.NewIATEntryDetail()
+	entry.TransactionCode = 27
+	entry.SetRDFI("121042882")
+	entry.AddendaRecords = 007
+	entry.DFIAccountNumber = "123456789"
+	entry.Amount = 100000 // 1000.00
+	entry.SetTraceNumber("23138010", 1)
+	entry.Category = ach.CategoryForward
+
+	//addenda
+
+	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.AddIATAddenda(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.AddIATAddenda(addenda18)
+
+	// build the batch
+	batch := ach.NewIATBatch(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.AddIATBatch(batch)
+	if err := file.Create(); err != nil {
+		log.Fatalf("Unexpected error building file: %s\n", err)
+	}
+
+	// write the file to std out. Anything io.Writer
+	w := ach.NewWriter(os.Stdout)
+	if err := w.Write(file); err != nil {
+		log.Fatalf("Unexpected error: %s\n", err)
+	}
+	w.Flush()
+}
diff --git a/test/ach-iat-write/main_test.go b/test/ach-iat-write/main_test.go
new file mode 100644
index 00000000..45fcc779
--- /dev/null
+++ b/test/ach-iat-write/main_test.go
@@ -0,0 +1,7 @@
+package main
+
+import "testing"
+
+func Test(t *testing.T) {
+	main()
+}