From f3eacd3226cb41cc5bd9d0fa5cdce4c7394deb16 Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Wed, 20 Mar 2024 09:47:24 -0500 Subject: [PATCH] fix: adjust TransactionCode code for prenote returns See: https://moov-io.slack.com/archives/CD9J8EJKX/p1710827043313929 --- pkg/response/entry_transformer.go | 5 +++ pkg/response/entry_transformer_test.go | 49 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/pkg/response/entry_transformer.go b/pkg/response/entry_transformer.go index 6bf26bd5..11c86e71 100644 --- a/pkg/response/entry_transformer.go +++ b/pkg/response/entry_transformer.go @@ -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 } diff --git a/pkg/response/entry_transformer_test.go b/pkg/response/entry_transformer_test.go index 950edb89..b54cc4fb 100644 --- a/pkg/response/entry_transformer_test.go +++ b/pkg/response/entry_transformer_test.go @@ -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) + }) +}