-
Notifications
You must be signed in to change notification settings - Fork 39
/
beneficiaryFI.go
195 lines (162 loc) · 6.13 KB
/
beneficiaryFI.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
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package wire
import (
"encoding/json"
"strings"
"unicode/utf8"
)
// BeneficiaryFI is the financial institution of the beneficiary
type BeneficiaryFI struct {
// tag
tag string
// Financial Institution
FinancialInstitution FinancialInstitution `json:"financialInstitution,omitempty"`
// converters is composed for WIRE to GoLang Converters
converters
}
// NewBeneficiaryFI returns a new BeneficiaryFI
func NewBeneficiaryFI() *BeneficiaryFI {
bfi := &BeneficiaryFI{
tag: TagBeneficiaryFI,
}
return bfi
}
// Parse takes the input string and parses the BeneficiaryFI values
//
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (bfi *BeneficiaryFI) Parse(record string) error {
if utf8.RuneCountInString(record) < 7 {
return NewTagMinLengthErr(7, len(record))
}
bfi.tag = record[:6]
bfi.FinancialInstitution.IdentificationCode = bfi.parseStringField(record[6:7])
length := 7
value, read, err := bfi.parseVariableStringField(record[length:], 34)
if err != nil {
return fieldError("Identifier", err)
}
bfi.FinancialInstitution.Identifier = value
length += read
value, read, err = bfi.parseVariableStringField(record[length:], 35)
if err != nil {
return fieldError("Name", err)
}
bfi.FinancialInstitution.Name = value
length += read
value, read, err = bfi.parseVariableStringField(record[length:], 35)
if err != nil {
return fieldError("AddressLineOne", err)
}
bfi.FinancialInstitution.Address.AddressLineOne = value
length += read
value, read, err = bfi.parseVariableStringField(record[length:], 35)
if err != nil {
return fieldError("AddressLineTwo", err)
}
bfi.FinancialInstitution.Address.AddressLineTwo = value
length += read
value, read, err = bfi.parseVariableStringField(record[length:], 35)
if err != nil {
return fieldError("AddressLineThree", err)
}
bfi.FinancialInstitution.Address.AddressLineThree = value
length += read
if err := bfi.verifyDataWithReadLength(record, length); err != nil {
return NewTagMaxLengthErr(err)
}
return nil
}
func (bfi *BeneficiaryFI) UnmarshalJSON(data []byte) error {
type Alias BeneficiaryFI
aux := struct {
*Alias
}{
(*Alias)(bfi),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
bfi.tag = TagBeneficiaryFI
return nil
}
// String returns a fixed-width BeneficiaryFI record
func (bfi *BeneficiaryFI) String() string {
return bfi.Format(FormatOptions{
VariableLengthFields: false,
})
}
// Format returns a BeneficiaryFI record formatted according to the FormatOptions
func (bfi *BeneficiaryFI) Format(options FormatOptions) string {
var buf strings.Builder
buf.Grow(181)
buf.WriteString(bfi.tag)
buf.WriteString(bfi.IdentificationCodeField())
buf.WriteString(bfi.FormatIdentifier(options) + Delimiter)
buf.WriteString(bfi.FormatName(options) + Delimiter)
buf.WriteString(bfi.FormatAddressLineOne(options) + Delimiter)
buf.WriteString(bfi.FormatAddressLineTwo(options) + Delimiter)
buf.WriteString(bfi.FormatAddressLineThree(options) + Delimiter)
if options.VariableLengthFields {
return bfi.stripDelimiters(buf.String())
} else {
return buf.String()
}
}
// Validate performs WIRE format rule checks on BeneficiaryFI and returns an error if not Validated
// The first error encountered is returned and stops that parsing.
func (bfi *BeneficiaryFI) Validate() error {
if bfi.tag != TagBeneficiaryFI {
return fieldError("tag", ErrValidTagForType, bfi.tag)
}
if err := bfi.FinancialInstitution.Validate(); err != nil {
return err
}
return nil
}
// IdentificationCodeField gets a string of the IdentificationCode field
func (bfi *BeneficiaryFI) IdentificationCodeField() string {
return bfi.alphaField(bfi.FinancialInstitution.IdentificationCode, 1)
}
// IdentifierField gets a string of the Identifier field
func (bfi *BeneficiaryFI) IdentifierField() string {
return bfi.alphaField(bfi.FinancialInstitution.Identifier, 34)
}
// NameField gets a string of the Name field
func (bfi *BeneficiaryFI) NameField() string {
return bfi.alphaField(bfi.FinancialInstitution.Name, 35)
}
// AddressLineOneField gets a string of AddressLineOne field
func (bfi *BeneficiaryFI) AddressLineOneField() string {
return bfi.alphaField(bfi.FinancialInstitution.Address.AddressLineOne, 35)
}
// AddressLineTwoField gets a string of AddressLineTwo field
func (bfi *BeneficiaryFI) AddressLineTwoField() string {
return bfi.alphaField(bfi.FinancialInstitution.Address.AddressLineTwo, 35)
}
// AddressLineThreeField gets a string of AddressLineThree field
func (bfi *BeneficiaryFI) AddressLineThreeField() string {
return bfi.alphaField(bfi.FinancialInstitution.Address.AddressLineThree, 35)
}
// FormatIdentifier returns FinancialInstitution.Identifier formatted according to the FormatOptions
func (bfi *BeneficiaryFI) FormatIdentifier(options FormatOptions) string {
return bfi.formatAlphaField(bfi.FinancialInstitution.Identifier, 34, options)
}
// FormatName returns FinancialInstitution.Name formatted according to the FormatOptions
func (bfi *BeneficiaryFI) FormatName(options FormatOptions) string {
return bfi.formatAlphaField(bfi.FinancialInstitution.Name, 35, options)
}
// FormatAddressLineOne returns FinancialInstitution.Address.AddressLineOne formatted according to the FormatOptions
func (bfi *BeneficiaryFI) FormatAddressLineOne(options FormatOptions) string {
return bfi.formatAlphaField(bfi.FinancialInstitution.Address.AddressLineOne, 35, options)
}
// FormatAddressLineTwo returns FinancialInstitution.Address.AddressLineTwo formatted according to the FormatOptions
func (bfi *BeneficiaryFI) FormatAddressLineTwo(options FormatOptions) string {
return bfi.formatAlphaField(bfi.FinancialInstitution.Address.AddressLineTwo, 35, options)
}
// FormatAddressLineThree returns FinancialInstitution.Address.AddressLineThree formatted according to the FormatOptions
func (bfi *BeneficiaryFI) FormatAddressLineThree(options FormatOptions) string {
return bfi.formatAlphaField(bfi.FinancialInstitution.Address.AddressLineThree, 35, options)
}