ach icon indicating copy to clipboard operation
ach copied to clipboard

Addenda 99 Dishonored ReturnTraceNumberField method returns truncated value when a file is read

Open sunnygill-stash opened this issue 10 months ago • 2 comments
trafficstars

ACH Version

v1.45.3

What were you trying to do?

The project I work on reads ACH files and then converts them to CSV. When an Addenda 99 Dishonor is parsed, the value is truncated. This is happening because the parser is grabbing the 3 blank spaces that proceed the Return Trace Number. The ReturnTraceNumberField method takes the first 15 characters of the ReturnTraceNumber value, which drops off the last 3 characters.

The problem appears to be with the Parse method

func (Addenda99Dishonored *Addenda99Dishonored) Parse(record string) {
	runeCount := utf8.RuneCountInString(record)
	if runeCount != 94 {
		return
	}

	buf := getBuffer()
	defer saveBuffer(buf)

	reset := func() string {
		out := buf.String()
		buf.Reset()
		return out
	}

	// We're going to process the record rune-by-rune and at each field cutoff save the value.
	var idx int
	for _, r := range record {
		idx++

		// Append rune to buffer
		buf.WriteRune(r)

		// At each cutoff save the buffer and reset
		switch idx {
		case 0, 1:
			// 1-1 Always 7
			reset()
		case 3:
			Addenda99Dishonored.TypeCode = reset()
		case 6:
			Addenda99Dishonored.DishonoredReturnReasonCode = reset()
		case 21:
			Addenda99Dishonored.OriginalEntryTraceNumber = reset()
		case 35:
			Addenda99Dishonored.OriginalReceivingDFIIdentification = reset()
		case 53:
			Addenda99Dishonored.ReturnTraceNumber = reset()
		case 56:
			Addenda99Dishonored.ReturnSettlementDate = reset()
		case 58:
			Addenda99Dishonored.ReturnReasonCode = reset()
		case 79:
			Addenda99Dishonored.AddendaInformation = reset()
		case 94:
			Addenda99Dishonored.TraceNumber = reset()
		}
	}
}

The blank spaces between the Original Receiving DFI Identification and Return Trace Number are unaccounted. Adding the following fixes the issue

		case 38:
			// 36-38 reserved - Leave blank
			reset()

What did you expect to see?

The ReturnTraceNumberField method would return all 15 digits of the Trace Number

What did you see?

A string with 3 leading blank spaces and missing the last 3 digits was returned.

How can we reproduce the problem?

Read an ACH file that has an Addenda 99 Dishonor. Then call the ReturnTraceNumberField method on the field. The value will be wrong. Using ReturnTraceNumber works, so there is a workaround.

sunnygill-stash avatar Jan 23 '25 19:01 sunnygill-stash

Do you have a sample (can be masked) record we can use as a test case for this? I can get this fixed and released today.

adamdecaf avatar Jan 23 '25 20:01 adamdecaf

I double checked the Nacha standards book and don't see any issues with our parsing logic. We have that 38 case already (it was out of order).

https://github.com/moov-io/ach/commit/456deff0199efec6a3c37f11a9e95fefd18f25e3

adamdecaf avatar Jan 23 '25 20:01 adamdecaf