-
Notifications
You must be signed in to change notification settings - Fork 39
/
fiPaymentMethodToBeneficiary.go
134 lines (114 loc) · 4.07 KB
/
fiPaymentMethodToBeneficiary.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
// 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"
)
// FIPaymentMethodToBeneficiary is the financial institution payment method to beneficiary
type FIPaymentMethodToBeneficiary struct {
// tag
tag string
// PaymentMethod is payment method
PaymentMethod string `json:"paymentMethod,omitempty"`
// Additional is additional information
AdditionalInformation string `json:"Additional,omitempty"`
// validator is composed for data validation
validator
// converters is composed for WIRE to GoLang Converters
converters
}
// NewFIPaymentMethodToBeneficiary returns a new FIPaymentMethodToBeneficiary
func NewFIPaymentMethodToBeneficiary() *FIPaymentMethodToBeneficiary {
pm := &FIPaymentMethodToBeneficiary{
tag: TagFIPaymentMethodToBeneficiary,
PaymentMethod: "CHECK",
}
return pm
}
// Parse takes the input string and parses the FIPaymentMethodToBeneficiary 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 (pm *FIPaymentMethodToBeneficiary) Parse(record string) error {
if utf8.RuneCountInString(record) < 11 {
return NewTagMinLengthErr(11, len(record))
}
pm.tag = record[:6]
pm.PaymentMethod = pm.parseStringField(record[6:11])
length := 11
value, read, err := pm.parseVariableStringField(record[length:], 30)
if err != nil {
return fieldError("AdditionalInformation", err)
}
pm.AdditionalInformation = value
length += read
if err := pm.verifyDataWithReadLength(record, length); err != nil {
return NewTagMaxLengthErr(err)
}
return nil
}
func (pm *FIPaymentMethodToBeneficiary) UnmarshalJSON(data []byte) error {
type Alias FIPaymentMethodToBeneficiary
aux := struct {
*Alias
}{
(*Alias)(pm),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
pm.tag = TagFIPaymentMethodToBeneficiary
return nil
}
// String returns a fixed-width FIPaymentMethodToBeneficiary record
func (pm *FIPaymentMethodToBeneficiary) String() string {
return pm.Format(FormatOptions{
VariableLengthFields: false,
})
}
// Format returns a FIPaymentMethodToBeneficiary record formatted according to the FormatOptions
func (pm *FIPaymentMethodToBeneficiary) Format(options FormatOptions) string {
var buf strings.Builder
buf.Grow(41)
buf.WriteString(pm.tag)
buf.WriteString(pm.PaymentMethodField())
buf.WriteString(pm.FormatAdditionalInformation(options) + Delimiter)
return buf.String()
}
// Validate performs WIRE format rule checks on FIPaymentMethodToBeneficiary and returns an error if not Validated
// The first error encountered is returned and stops that parsing.
func (pm *FIPaymentMethodToBeneficiary) Validate() error {
if err := pm.fieldInclusion(); err != nil {
return err
}
if pm.tag != TagFIPaymentMethodToBeneficiary {
return fieldError("tag", ErrValidTagForType, pm.tag)
}
if err := pm.isAlphanumeric(pm.AdditionalInformation); err != nil {
return fieldError("AdditionalInformation", err, pm.AdditionalInformation)
}
return nil
}
// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
func (pm *FIPaymentMethodToBeneficiary) fieldInclusion() error {
if pm.PaymentMethod != PaymentMethod {
return fieldError("PaymentMethod", ErrFieldInclusion, pm.PaymentMethod)
}
return nil
}
// PaymentMethodField gets a string of the PaymentMethod field
func (pm *FIPaymentMethodToBeneficiary) PaymentMethodField() string {
return pm.alphaField(pm.PaymentMethod, 5)
}
// AdditionalInformationField gets a string of the AdditionalInformation field
func (pm *FIPaymentMethodToBeneficiary) AdditionalInformationField() string {
return pm.alphaField(pm.AdditionalInformation, 30)
}
// FormatAdditionalInformation returns AdditionalInformation formatted according to the FormatOptions
func (pm *FIPaymentMethodToBeneficiary) FormatAdditionalInformation(options FormatOptions) string {
return pm.formatAlphaField(pm.AdditionalInformation, 30, options)
}