-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from sshaplygin/ref-bik
ref BIK package
- Loading branch information
Showing
25 changed files
with
2,666 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
package bik | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/sshaplygin/docs-code/models" | ||
"github.com/sshaplygin/docs-code/utils" | ||
"fmt" | ||
) | ||
|
||
// Validate check to valid BIK format | ||
// example valid format is 044525225 | ||
// Validate check to valid BIK format. | ||
// Example valid format is 044525225 | ||
func Validate(bik string) (bool, error) { | ||
if len(bik) != 9 { | ||
return false, &models.CommonError{ | ||
Method: packageName, | ||
Err: models.ErrInvalidLength, | ||
} | ||
bikData, err := ParseBIK(bik) | ||
if err != nil { | ||
return false, fmt.Errorf("create %s model: %w", packageName, err) | ||
} | ||
|
||
bikArr, err := utils.StrToArr(bik) | ||
if err != nil { | ||
return false, err | ||
return bikData.IsValid() | ||
} | ||
|
||
// Exists check to valid BIK format and check to used code. | ||
// Example valid format is 044525677 - АО "Яндекс Банк". | ||
func Exists(bik string) (bool, error) { | ||
_, ok := existsBIKs[bik] | ||
if ok { | ||
return true, nil | ||
} | ||
|
||
if bikArr[0] != 0 || bikArr[1] != 4 { | ||
return false, ErrInvalidCountryCode | ||
bikData, err := ParseBIK(bik) | ||
if err != nil { | ||
return false, fmt.Errorf("create %s model: %w", packageName, err) | ||
} | ||
|
||
// special code | ||
if bikArr[6] == 0 && bikArr[7] == 1 && bikArr[8] == 2 { | ||
return true, nil | ||
isValid, err := bikData.IsValid() | ||
if err != nil { | ||
return false, fmt.Errorf("check valid %s model: %w", packageName, err) | ||
} | ||
|
||
latestTriadStr := bik[6:] | ||
code, _ := strconv.Atoi(latestTriadStr) | ||
if !isValid { | ||
return false, fmt.Errorf("invalid %s model", packageName) | ||
} | ||
|
||
return code >= 50 && code < 1000, nil | ||
return bikData.Exists() | ||
} | ||
|
||
func Generate() string { | ||
panic("not implemented!") | ||
// Generate method generate a valid BIK code, but possible usaged or not usaged in reality. | ||
// Method guaranteed that code will be valid, but not guaranteed that code will be exists. | ||
func Generate(opts ...GenerateOpt) string { | ||
return NewBIK(opts...).String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.