diff --git a/README.md b/README.md index 1637fe07..50d13fa5 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ Moov's mission is to give developers an easy way to create and integrate bank pr Bai2 implements a reader, writer, and validator for the [Cash Management Balance Reporting Specifications Version 2](https://en.wikipedia.org/wiki/BAI_(file_format)) developed by [Bank Administration Institute](https://www.bai.org) (BAI). This project offers a HTTP server in a [Docker image](#docker) and a Go package `github.com/moov-io/bai2`. +BTRS (BTR3/BAI3) is also supported in this library. Behavior changes are made when the BTRS Version 3 header is detected. + +Specifications for [bai2](docs/specifications/Cash Management Balance Reporting Specifications Version 2.pdf) and [BTRS / BTR3](docs/specifications/ANSI-X9-121201-BTRS-Format-Guide-Version-3.pdf) are included in the repository. + ## Table of contents - [Project status](#project-status) diff --git a/docs/specifications/ANSI-X9-121201-BTRS-Format-Guide-Version-3.pdf b/docs/specifications/ANSI-X9-121201-BTRS-Format-Guide-Version-3.pdf new file mode 100644 index 00000000..70a76d53 Binary files /dev/null and b/docs/specifications/ANSI-X9-121201-BTRS-Format-Guide-Version-3.pdf differ diff --git a/docs/specifications/BTRS-BAI2-Transaction-Codes-and-Format-to-Support-Real-Time-Payments.pdf b/docs/specifications/BTRS-BAI2-Transaction-Codes-and-Format-to-Support-Real-Time-Payments.pdf new file mode 100644 index 00000000..8337e843 Binary files /dev/null and b/docs/specifications/BTRS-BAI2-Transaction-Codes-and-Format-to-Support-Real-Time-Payments.pdf differ diff --git a/docs/specifications/BTRS-Implementation-Planning-Tool-2.xlsx b/docs/specifications/BTRS-Implementation-Planning-Tool-2.xlsx new file mode 100644 index 00000000..50395ca1 Binary files /dev/null and b/docs/specifications/BTRS-Implementation-Planning-Tool-2.xlsx differ diff --git a/docs/specifications/BTRS-Version-3.3.1-Type-Codes-1.xlsx b/docs/specifications/BTRS-Version-3.3.1-Type-Codes-1.xlsx new file mode 100644 index 00000000..df71c7a6 Binary files /dev/null and b/docs/specifications/BTRS-Version-3.3.1-Type-Codes-1.xlsx differ diff --git a/docs/specifications/X9.121-2016-BTRS-Version-3.0.pdf b/docs/specifications/X9.121-2016-BTRS-Version-3.0.pdf new file mode 100644 index 00000000..806f182b Binary files /dev/null and b/docs/specifications/X9.121-2016-BTRS-Version-3.0.pdf differ diff --git a/pkg/lib/btrs_test.go b/pkg/lib/btrs_test.go new file mode 100644 index 00000000..df10f481 --- /dev/null +++ b/pkg/lib/btrs_test.go @@ -0,0 +1,24 @@ +package lib + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +// The following samples were pulled from examples in the BTRS V3 guide +// docs/specifications/ANSI-X9-121201-BTRS-Format-Guide-Version-3.pdf +func TestBTRSParse(t *testing.T) { + input := "01,122099999,123456789,150623,0200,1,,,3/" + var header fileHeader + _, err := header.parse(input) + require.NoError(t, err) + require.Equal(t, "122099999", header.Sender) + require.Equal(t, "123456789", header.Receiver) + require.Equal(t, "150623", header.FileCreatedDate) + require.Equal(t, "0200", header.FileCreatedTime) + require.Equal(t, "1", header.FileIdNumber) + require.Equal(t, int64(0), header.PhysicalRecordLength) + require.Equal(t, int64(0), header.BlockSize) + require.Equal(t, int64(3), header.VersionNumber) +} diff --git a/pkg/lib/file_test.go b/pkg/lib/file_test.go index 669c4fbf..be1ff6d6 100644 --- a/pkg/lib/file_test.go +++ b/pkg/lib/file_test.go @@ -18,6 +18,7 @@ import ( func TestFileWithSampleData(t *testing.T) { paths := []string{ "sample1.txt", + "sample1-btrs.txt", "sample2.txt", "sample3.txt", "sample4-continuations-newline-delimited.txt", diff --git a/pkg/lib/record_file_header.go b/pkg/lib/record_file_header.go index 24e4b7f1..5939bca9 100644 --- a/pkg/lib/record_file_header.go +++ b/pkg/lib/record_file_header.go @@ -47,7 +47,7 @@ func (h *fileHeader) validate() error { if h.FileIdNumber == "" { return fmt.Errorf(fmt.Sprintf(fhValidateErrorFmt, "FileIdNumber")) } - if h.VersionNumber != 2 { + if h.VersionNumber != 2 && h.VersionNumber != 3 { return fmt.Errorf(fmt.Sprintf(fhValidateErrorFmt, "VersionNumber")) } diff --git a/test/testdata/sample1-btrs.txt b/test/testdata/sample1-btrs.txt new file mode 100644 index 00000000..8c00669c --- /dev/null +++ b/test/testdata/sample1-btrs.txt @@ -0,0 +1,27 @@ +01,0004,12345,060321,0829,001,80,1,3/ +02,12345,0004,1,060317,,CAD,/ +03,10200123456,CAD,040,+000000000000,,,045,+000000000000,,/ +88,100,000000000208500,00003,V,060316,,400,000000000208500,00008,V,060316,/ +16,409,000000000002500,V,060316,,,,RETURNED CHEQUE / +16,409,000000000090000,V,060316,,,,RTN-UNKNOWN / +16,409,000000000000500,V,060316,,,,RTD CHQ SERVICE CHRG/ +16,108,000000000203500,V,060316,,,,TFR 1020 0345678 / +16,108,000000000002500,V,060316,,,,MACLEOD MALL / +16,108,000000000002500,V,060316,,,,MASCOUCHE QUE / +16,409,000000000020000,V,060316,,,,1000 ISLANDS MALL / +16,409,000000000090000,V,060316,,,,PENHORA MALL / +16,409,000000000002000,V,060316,,,,CAPILANO MALL / +16,409,000000000002500,V,060316,,,,GALERIES LA CAPITALE/ +16,409,000000000001000,V,060316,,,,PLAZA ROCK FOREST / +49,+00000000000834000,14/ +03,10200123456,CAD,040,+000000000000,,,045,+000000000000,,/ +88,100,000000000111500,00002,V,060317,,400,000000000111500,00004,V,060317,/ +16,108,000000000011500,V,060317,,,,TFR 1020 0345678 / +16,108,000000000100000,V,060317,,,,MONTREAL / +16,409,000000000100000,V,060317,,,,GRANDFALL NB / +16,409,000000000009000,V,060317,,,,HAMILTON ON / +16,409,000000000002000,V,060317,,,,WOODSTOCK NB / +16,409,000000000000500,V,060317,,,,GALERIES RICHELIEU / +49,+00000000000446000,9/ +98,+00000000001280000,2,25/ +99,+00000000001280000,1,27/ \ No newline at end of file