Skip to content

Commit

Permalink
fix: adjust TransactionCode code for prenote returns
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Mar 20, 2024
1 parent bdd3b1f commit f3eacd3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/response/entry_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func (t *ReturnTransformer) MorphEntry(fh ach.FileHeader, ed *ach.EntryDetail, a
switch ed.TransactionCode {
case ach.CheckingCredit, ach.CheckingDebit, ach.SavingsCredit, ach.SavingsDebit:
out.TransactionCode = ed.TransactionCode - 1

case ach.CheckingPrenoteCredit, ach.CheckingPrenoteDebit, ach.SavingsPrenoteCredit, ach.SavingsPrenoteDebit,
ach.GLPrenoteCredit, ach.GLPrenoteDebit, ach.LoanPrenoteCredit:
out.TransactionCode = ed.TransactionCode - 2

default:
out.TransactionCode = ed.TransactionCode
}
Expand Down
49 changes: 49 additions & 0 deletions pkg/response/entry_transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,52 @@ func TestMorphEntry__Return(t *testing.T) {
require.Equal(t, "R01", out.Addenda99.ReturnCode)
require.Equal(t, "23138010", out.Addenda99.OriginalDFI)
}

func TestMorphEntry__Prenote(t *testing.T) {
file, err := ach.ReadFile(filepath.Join("..", "..", "testdata", "prenote.ach"))
require.NoError(t, err)

t.Run("correction", func(t *testing.T) {
action := service.Action{
Correction: &service.Correction{
Code: "C01",
Data: "45111616",
},
}
ed := file.Batches[0].GetEntries()[0]
ed.TransactionCode = ach.CheckingPrenoteCredit

xform := &CorrectionTransformer{}
out, err := xform.MorphEntry(file.Header, ed, &action)
require.NoError(t, err)

require.Equal(t, ach.CheckingReturnNOCCredit, out.TransactionCode)
require.NotEqual(t, ed.TraceNumber, out.TraceNumber)
require.Equal(t, ed.TraceNumber, out.Addenda98.OriginalTrace)

require.NotNil(t, out.Addenda98)
require.Equal(t, "C01", out.Addenda98.ChangeCode)
require.Equal(t, "45111616", out.Addenda98.CorrectedData)
})

t.Run("return", func(t *testing.T) {
action := service.Action{
Return: &service.Return{
Code: "R01",
},
}
ed := file.Batches[0].GetEntries()[0]
ed.TransactionCode = ach.CheckingPrenoteCredit

xform := &ReturnTransformer{}
out, err := xform.MorphEntry(file.Header, ed, &action)
require.NoError(t, err)

require.Equal(t, ach.CheckingReturnNOCCredit, out.TransactionCode)
require.NotEqual(t, ed.TraceNumber, out.TraceNumber)

require.NotNil(t, out.Addenda99)
require.Equal(t, ed.TraceNumber, out.Addenda99.OriginalTrace)
require.Equal(t, "R01", out.Addenda99.ReturnCode)
})
}

0 comments on commit f3eacd3

Please sign in to comment.