52
52
)
53
53
54
54
type (
55
- // CountryCode Required length 2.
55
+ // CountryCode required length 2.
56
56
CountryCode int
57
57
58
58
// UnitConditionalNumber required length 2.
@@ -62,40 +62,74 @@ type (
62
62
// or the conditional number of the structural division of the Bank of Russia.
63
63
UnitConditionalNumber int
64
64
65
- // LastAccountNumbers required length 3. It is last correspondent account of the bank. Possible values [050, 999]
65
+ // LastAccountNumbers required length 3.
66
+ // It is last correspondent account of the bank. Possible values [050, 999]
66
67
LastAccountNumbers int
67
68
)
68
69
69
- const codeLength = 9
70
+ func (cc CountryCode ) IsValid () bool {
71
+ if cc < minCountryCodeLength || cc > maxCountryCodeLength {
72
+ return false
73
+ }
70
74
71
- type BIKStruct struct {
72
- country CountryCode
73
- territoryCode okato.StateCode
74
- unitNumber UnitConditionalNumber
75
- lastNumber LastAccountNumbers
75
+ _ , ok := supportedCountryCodes [cc ]
76
+ return ok
76
77
}
77
78
78
- // generateOptions TODO
79
- type generateOptions struct {
79
+ func (cc CountryCode ) String () string {
80
+ _ , ok := supportedCountryCodes [cc ]
81
+ if ! ok {
82
+ return RussiaCountryCode .String ()
83
+ }
84
+
85
+ return utils .StrCode (int (cc ), countryCodeLength )
80
86
}
81
87
82
- type GenerateOpt func (options * generateOptions )
88
+ func (cc CountryCode ) GetName () string {
89
+ codeName , ok := supportedCountryCodes [cc ]
90
+ if ! ok {
91
+ return unspecifiedCountryCode
92
+ }
83
93
84
- func NewBIK ( opts ... GenerateOpt ) * BIKStruct {
85
- var options generateOptions
94
+ return codeName
95
+ }
86
96
87
- for _ , o := range opts {
88
- o ( & options )
89
- }
97
+ func GenerateCountryCode () CountryCode {
98
+ return countryCodes [ utils . Random ( 0 , len ( countryCodes ) - 1 )]
99
+ }
90
100
91
- return & BIKStruct {
92
- country : GenerateCountryCode (),
93
- territoryCode : okato .GenerateStateCode (),
94
- unitNumber : GenerateUnitConditionalNumber (),
95
- lastNumber : GenerateLastAccountNumbers (),
101
+ func (ucn UnitConditionalNumber ) IsValid () bool {
102
+ return ucn >= minUnitConditionalNumber && ucn <= maxUnitConditionalNumber
103
+ }
104
+
105
+ func (ucn UnitConditionalNumber ) String () string {
106
+ return utils .StrCode (int (ucn ), unitConditionalNumberLength )
107
+ }
108
+
109
+ func GenerateUnitConditionalNumber () UnitConditionalNumber {
110
+ return UnitConditionalNumber (utils .Random (minUnitConditionalNumber , maxUnitConditionalNumber ))
111
+ }
112
+
113
+ const specialCode = 12
114
+
115
+ func (lan LastAccountNumbers ) IsValid () bool {
116
+ if lan == specialCode {
117
+ return true
96
118
}
119
+
120
+ return lan >= minLastAccountNumbers && lan <= maxLastAccountNumbers
121
+ }
122
+
123
+ func (lan LastAccountNumbers ) String () string {
124
+ return utils .StrCode (int (lan ), lastAccountNumbersLength )
97
125
}
98
126
127
+ func GenerateLastAccountNumbers () LastAccountNumbers {
128
+ return LastAccountNumbers (utils .Random (minLastAccountNumbers , maxLastAccountNumbers ))
129
+ }
130
+
131
+ const codeLength = 9
132
+
99
133
func ParseBIK (bik string ) (* BIKStruct , error ) {
100
134
if len (bik ) != codeLength {
101
135
return nil , & models.CommonError {
@@ -117,6 +151,34 @@ func ParseBIK(bik string) (*BIKStruct, error) {
117
151
}, nil
118
152
}
119
153
154
+ type BIKStruct struct {
155
+ country CountryCode
156
+ territoryCode okato.StateCode
157
+ unitNumber UnitConditionalNumber
158
+ lastNumber LastAccountNumbers
159
+ }
160
+
161
+ // generateOptions TODO
162
+ type generateOptions struct {
163
+ }
164
+
165
+ type GenerateOpt func (options * generateOptions )
166
+
167
+ func NewBIK (opts ... GenerateOpt ) * BIKStruct {
168
+ var options generateOptions
169
+
170
+ for _ , o := range opts {
171
+ o (& options )
172
+ }
173
+
174
+ return & BIKStruct {
175
+ country : GenerateCountryCode (),
176
+ territoryCode : okato .GenerateStateCode (),
177
+ unitNumber : GenerateUnitConditionalNumber (),
178
+ lastNumber : GenerateLastAccountNumbers (),
179
+ }
180
+ }
181
+
120
182
func (bs * BIKStruct ) IsValid () (bool , error ) {
121
183
if bs == nil {
122
184
return false , ErrNilBIK
@@ -161,64 +223,3 @@ func (bs *BIKStruct) Exists() (bool, error) {
161
223
_ , ok := existsBIKs [bs .String ()]
162
224
return ok , nil
163
225
}
164
-
165
- func GenerateCountryCode () CountryCode {
166
- return countryCodes [utils .Random (0 , len (countryCodes )- 1 )]
167
- }
168
-
169
- func GenerateUnitConditionalNumber () UnitConditionalNumber {
170
- return UnitConditionalNumber (utils .Random (minUnitConditionalNumber , maxUnitConditionalNumber ))
171
- }
172
-
173
- func GenerateLastAccountNumbers () LastAccountNumbers {
174
- return LastAccountNumbers (utils .Random (minLastAccountNumbers , maxLastAccountNumbers ))
175
- }
176
-
177
- func (cc CountryCode ) IsValid () bool {
178
- if cc < minCountryCodeLength || cc > maxCountryCodeLength {
179
- return false
180
- }
181
-
182
- _ , ok := supportedCountryCodes [cc ]
183
- return ok
184
- }
185
-
186
- func (cc CountryCode ) String () string {
187
- _ , ok := supportedCountryCodes [cc ]
188
- if ! ok {
189
- return RussiaCountryCode .String ()
190
- }
191
-
192
- return utils .StrCode (int (cc ), countryCodeLength )
193
- }
194
-
195
- func (cc CountryCode ) GetName () string {
196
- codeName , ok := supportedCountryCodes [cc ]
197
- if ! ok {
198
- return unspecifiedCountryCode
199
- }
200
-
201
- return codeName
202
- }
203
-
204
- func (ucn UnitConditionalNumber ) IsValid () bool {
205
- return ucn >= minUnitConditionalNumber && ucn <= maxUnitConditionalNumber
206
- }
207
-
208
- func (ucn UnitConditionalNumber ) String () string {
209
- return utils .StrCode (int (ucn ), unitConditionalNumberLength )
210
- }
211
-
212
- const specialCode = 12
213
-
214
- func (lan LastAccountNumbers ) IsValid () bool {
215
- if lan == specialCode {
216
- return true
217
- }
218
-
219
- return lan >= minLastAccountNumbers && lan <= maxLastAccountNumbers
220
- }
221
-
222
- func (lan LastAccountNumbers ) String () string {
223
- return utils .StrCode (int (lan ), lastAccountNumbersLength )
224
- }
0 commit comments