Skip to content

Commit 9375d39

Browse files
Fix: Prevent Addenda17 and Addenda18 in IAT return entries (#1747)
This PR adds validation to prevent Addenda17 and Addenda18 records from being included in IAT return entries, which causes Federal Reserve rejections with return code R25 (Addenda error). Fixes #1746
1 parent c9c1647 commit 9375d39

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

iatBatch.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ func (iatBatch *IATBatch) isFieldInclusion() error {
352352
if err := entry.Addenda99.Validate(); err != nil {
353353
return err
354354
}
355+
356+
// IAT Return entries must not include Addenda17 or Addenda18
357+
// Per NACHA rules, only Addenda10-16 and Addenda99 are allowed in IAT returns
358+
// Including Addenda17/18 in returns will cause Fed rejection with R25 (Addenda error)
359+
if len(entry.Addenda17) > 0 {
360+
return fieldError("Addenda17", ErrFieldInclusion)
361+
}
362+
if len(entry.Addenda18) > 0 {
363+
return fieldError("Addenda18", ErrFieldInclusion)
364+
}
355365
}
356366
}
357367
return iatBatch.Control.Validate()

iatBatch_test.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ func testIATBatchAddenda99Count(t testing.TB) {
17481748
mockBatch.Entries[0].Addenda14 = mockAddenda14()
17491749
mockBatch.Entries[0].Addenda15 = mockAddenda15()
17501750
mockBatch.Entries[0].Addenda16 = mockAddenda16()
1751-
mockBatch.Entries[0].AddAddenda17(mockAddenda17())
1751+
// Addenda17 and Addenda18 must not be included in IAT return entries
17521752
mockBatch.Entries[0].Addenda99 = mockIATAddenda99()
17531753
mockBatch.category = CategoryReturn
17541754

@@ -1757,7 +1757,6 @@ func testIATBatchAddenda99Count(t testing.TB) {
17571757
}
17581758

17591759
err := mockBatch.Validate()
1760-
// TODO: are we expecting there to be no errors here?
17611760
if !base.Match(err, nil) {
17621761
t.Errorf("%T: %s", err, err)
17631762
}
@@ -1777,6 +1776,54 @@ func BenchmarkIATBatchAddenda99Count(b *testing.B) {
17771776
}
17781777
}
17791778

1779+
// TestIATBatchReturnAddendaError tests that Addenda17 and Addenda18 are not allowed in IAT return entries
1780+
func TestIATBatchReturnAddendaError(t *testing.T) {
1781+
tests := []struct {
1782+
name string
1783+
setupEntry func(*IATEntryDetail)
1784+
description string
1785+
}{
1786+
{
1787+
name: "Addenda17",
1788+
setupEntry: func(entry *IATEntryDetail) {
1789+
entry.AddAddenda17(mockAddenda17())
1790+
},
1791+
description: "Addenda17 should not be allowed in IAT return entries",
1792+
},
1793+
{
1794+
name: "Addenda18",
1795+
setupEntry: func(entry *IATEntryDetail) {
1796+
entry.AddAddenda18(mockAddenda18())
1797+
},
1798+
description: "Addenda18 should not be allowed in IAT return entries",
1799+
},
1800+
}
1801+
1802+
for _, tt := range tests {
1803+
t.Run(tt.name, func(t *testing.T) {
1804+
mockBatch := IATBatch{}
1805+
mockBatch.SetHeader(mockIATReturnBatchHeaderFF())
1806+
mockBatch.AddEntry(mockIATEntryDetail())
1807+
mockBatch.GetEntries()[0].Category = CategoryReturn
1808+
mockBatch.Entries[0].Addenda10 = mockAddenda10()
1809+
mockBatch.Entries[0].Addenda11 = mockAddenda11()
1810+
mockBatch.Entries[0].Addenda12 = mockAddenda12()
1811+
mockBatch.Entries[0].Addenda13 = mockAddenda13()
1812+
mockBatch.Entries[0].Addenda14 = mockAddenda14()
1813+
mockBatch.Entries[0].Addenda15 = mockAddenda15()
1814+
mockBatch.Entries[0].Addenda16 = mockAddenda16()
1815+
tt.setupEntry(mockBatch.Entries[0])
1816+
mockBatch.Entries[0].Addenda99 = mockIATAddenda99()
1817+
mockBatch.category = CategoryReturn
1818+
1819+
err := mockBatch.Validate()
1820+
if !base.Match(err, ErrFieldInclusion) {
1821+
t.Errorf("%s: %T: %s", tt.description, err, err)
1822+
}
1823+
})
1824+
}
1825+
}
1826+
17801827
// TestIATBatchAddenda98TotalCount validates IATBatch Addenda98 TotalCount
17811828
func TestIATBatchAddenda98TotalCount(t *testing.T) {
17821829
mockBatch := IATBatch{}

0 commit comments

Comments
 (0)