-
Notifications
You must be signed in to change notification settings - Fork 151
/
addenda99_contested_return.go
253 lines (207 loc) · 8.71 KB
/
addenda99_contested_return.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Licensed to The Moov Authors under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. The Moov Authors licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package ach
import (
"unicode/utf8"
)
type Addenda99Contested struct {
// ID is an identifier only used by the moov-io/ach HTTP server as a way to identify a batch.
ID string `json:"id"`
// TypeCode Addenda types code '99'
TypeCode string `json:"typeCode"`
// ContestedReturnCode is the return code explaining the contested dishonorment
ContestedReturnCode string `json:"contestedReturnCode"`
// OriginalEntryTraceNumber is the trace number specifieid in the initial entry
OriginalEntryTraceNumber string `json:"originalEntryTraceNumber"`
// DateOriginalEntryReturned is the original entry's date
DateOriginalEntryReturned string `json:"dateOriginalEntryReturned"`
// OriginalReceivingDFIIdentification is the DFI Identification specifieid in the initial entry
OriginalReceivingDFIIdentification string `json:"originalReceivingDFIIdentification"`
// OriginalSettlementDate is the initial date of settlement
OriginalSettlementDate string `json:"originalSettlementDate"`
// ReturnTraceNumber is the original returns trace number
ReturnTraceNumber string `json:"returnTraceNumber"`
// ReturnSettlementDate is the original return's settlement date
ReturnSettlementDate string `json:"returnSettlementDate"`
// ReturnReasonCode is the original return's code
ReturnReasonCode string `json:"returnReasonCode"`
// DishonoredReturnTraceNumber is the dishonorment's trace number
DishonoredReturnTraceNumber string `json:"dishonoredReturnTraceNumber"`
// DishonoredReturnSettlementDate is the dishonorment's settlement date
DishonoredReturnSettlementDate string `json:"dishonoredReturnSettlementDate"`
// DishonoredReturnReasonCode is the dishonorment's return code
DishonoredReturnReasonCode string `json:"dishonoredReturnReasonCode"`
// TraceNumber is the trace number for contesting
TraceNumber string `json:"traceNumber"`
// validator is composed for data validation
validator
// converters is composed for ACH to GoLang Converters
converters
validateOpts *ValidateOpts
}
// NewAddenda99Contested returns a new Addenda99Contested with default values for none exported fields
func NewAddenda99Contested() *Addenda99Contested {
Addenda99Contested := &Addenda99Contested{
TypeCode: "99",
}
return Addenda99Contested
}
func (Addenda99Contested *Addenda99Contested) 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:
Addenda99Contested.TypeCode = reset()
case 6:
Addenda99Contested.ContestedReturnCode = reset()
case 21:
Addenda99Contested.OriginalEntryTraceNumber = reset()
case 27:
Addenda99Contested.DateOriginalEntryReturned = reset()
case 35:
Addenda99Contested.OriginalReceivingDFIIdentification = reset()
case 38:
Addenda99Contested.OriginalSettlementDate = reset()
case 53:
Addenda99Contested.ReturnTraceNumber = reset()
case 56:
Addenda99Contested.ReturnSettlementDate = reset()
case 58:
Addenda99Contested.ReturnReasonCode = reset()
case 73:
Addenda99Contested.DishonoredReturnTraceNumber = reset()
case 76:
Addenda99Contested.DishonoredReturnSettlementDate = reset()
case 78:
Addenda99Contested.DishonoredReturnReasonCode = reset()
case 79:
reset() // reserved
case 94:
Addenda99Contested.TraceNumber = reset()
}
}
}
func (Addenda99Contested *Addenda99Contested) String() string {
if Addenda99Contested == nil {
return ""
}
buf := getBuffer()
defer saveBuffer(buf)
buf.WriteString(entryAddendaPos)
buf.WriteString(Addenda99Contested.TypeCode)
buf.WriteString(Addenda99Contested.ContestedReturnCodeField())
buf.WriteString(Addenda99Contested.OriginalEntryTraceNumberField())
buf.WriteString(Addenda99Contested.DateOriginalEntryReturnedField())
buf.WriteString(Addenda99Contested.OriginalReceivingDFIIdentificationField())
buf.WriteString(Addenda99Contested.OriginalSettlementDateField())
buf.WriteString(Addenda99Contested.ReturnTraceNumberField())
buf.WriteString(Addenda99Contested.ReturnSettlementDateField())
buf.WriteString(Addenda99Contested.ReturnReasonCodeField())
buf.WriteString(Addenda99Contested.DishonoredReturnTraceNumberField())
buf.WriteString(Addenda99Contested.DishonoredReturnSettlementDateField())
buf.WriteString(Addenda99Contested.DishonoredReturnReasonCodeField())
buf.WriteString(" ")
buf.WriteString(Addenda99Contested.TraceNumberField())
return buf.String()
}
// SetValidation stores ValidateOpts on the Batch which are to be used to override
// the default NACHA validation rules.
func (Addenda99Contested *Addenda99Contested) SetValidation(opts *ValidateOpts) {
if Addenda99Contested == nil {
return
}
Addenda99Contested.validateOpts = opts
}
// Validate verifies NACHA rules for Addenda99Contested
func (Addenda99Contested *Addenda99Contested) Validate() error {
if Addenda99Contested.TypeCode == "" {
return fieldError("TypeCode", ErrConstructor, Addenda99Contested.TypeCode)
}
if Addenda99Contested.TypeCode != "99" {
return fieldError("TypeCode", ErrAddendaTypeCode, Addenda99Contested.TypeCode)
}
// Verify the ContestedReturnReasonCode matches expected values
if Addenda99Contested.validateOpts == nil || !Addenda99Contested.validateOpts.CustomReturnCodes {
// We can validate the Contested ReturnCode
if !IsContestedReturnCode(Addenda99Contested.ContestedReturnCode) {
return fieldError("ContestedReturnCode", ErrAddenda99ContestedReturnCode, Addenda99Contested.ContestedReturnCode)
}
}
return nil
}
func IsContestedReturnCode(code string) bool {
switch code {
case "R71", "R72", "R73", "R74", "R75", "R76":
return true
}
return false
}
func (Addenda99Contested *Addenda99Contested) ContestedReturnCodeField() string {
return Addenda99Contested.stringField(Addenda99Contested.ContestedReturnCode, 3)
}
func (Addenda99Contested *Addenda99Contested) OriginalEntryTraceNumberField() string {
return Addenda99Contested.stringField(Addenda99Contested.OriginalEntryTraceNumber, 15)
}
func (Addenda99Contested *Addenda99Contested) DateOriginalEntryReturnedField() string {
return Addenda99Contested.stringField(Addenda99Contested.DateOriginalEntryReturned, 6)
}
func (Addenda99Contested *Addenda99Contested) OriginalReceivingDFIIdentificationField() string {
return Addenda99Contested.stringField(Addenda99Contested.OriginalReceivingDFIIdentification, 8)
}
func (Addenda99Contested *Addenda99Contested) OriginalSettlementDateField() string {
return Addenda99Contested.stringField(Addenda99Contested.OriginalSettlementDate, 3)
}
func (Addenda99Contested *Addenda99Contested) ReturnTraceNumberField() string {
return Addenda99Contested.stringField(Addenda99Contested.ReturnTraceNumber, 15)
}
func (Addenda99Contested *Addenda99Contested) ReturnSettlementDateField() string {
return Addenda99Contested.stringField(Addenda99Contested.ReturnSettlementDate, 3)
}
func (Addenda99Contested *Addenda99Contested) ReturnReasonCodeField() string {
return Addenda99Contested.stringField(Addenda99Contested.ReturnReasonCode, 2)
}
func (Addenda99Contested *Addenda99Contested) DishonoredReturnTraceNumberField() string {
return Addenda99Contested.stringField(Addenda99Contested.DishonoredReturnTraceNumber, 15)
}
func (Addenda99Contested *Addenda99Contested) DishonoredReturnSettlementDateField() string {
return Addenda99Contested.stringField(Addenda99Contested.DishonoredReturnSettlementDate, 3)
}
func (Addenda99Contested *Addenda99Contested) DishonoredReturnReasonCodeField() string {
return Addenda99Contested.stringField(Addenda99Contested.DishonoredReturnReasonCode, 2)
}
func (Addenda99Contested *Addenda99Contested) TraceNumberField() string {
return Addenda99Contested.stringField(Addenda99Contested.TraceNumber, 15)
}