-
Notifications
You must be signed in to change notification settings - Fork 0
bank
Validate Iranian bank card numbers, resolve the issuing bank, and validate Sheba (IBAN) codes.
import "github.com/amiranmanesh/go-persian-tools/bank"name, err := bank.CardInfo("6037701689095443") // "keshavarzi", nilThe number must be 16 digits and pass the Luhn checksum; the bank is then resolved from the six-digit prefix (BIN).
| Error | When |
|---|---|
bank.ErrInvalidCard |
not 16 digits, or fails the Luhn checksum |
bank.ErrBankNotFound |
valid number, but no bank matches the prefix |
if _, err := bank.CardInfo(input); errors.Is(err, bank.ErrInvalidCard) {
// tell the user the number itself is wrong
}sheba := bank.ShebaCode{Code: "IR820540102680020817909002"}
sheba.IsValid() // structure + ISO 7064 MOD-97-10 checksum
info := sheba.IsSheba()
info.Name // Parsian Bank
info.PersianName // بانک پارسیان
info.Code // 054IsValid answers only "is this a well-formed Iranian IBAN". IsSheba
additionally looks the bank up and returns a zero ShebaResult when the code is
valid but the bank is unknown — so a true from IsValid with an empty
Name means "correct checksum, unrecognized bank".
type ShebaResult struct {
MergedInto string
Name string
Code string
NickName string
PersianName string
AccountNumber string
AccountNumberAvailable bool
FormattedAccountNumber string
Process func(str string) ShebaProcess
}AccountNumberAvailable reports whether the bank publishes enough structure to
recover the account number from the IBAN; when it does, Process extracts it.
Bank Sepah absorbed five institutions between 2019 and 2020:
| Code | Bank | |
|---|---|---|
| 052 | قوامین (Ghavamin) | → sepah |
| 063 | انصار (Ansar) | → sepah |
| 065 | حکمت ایرانیان (Hekmat Iranian) | → sepah |
| 073 | مؤسسه کوثر (Kosar) | → sepah |
| 079 | مهر اقتصاد (Mehr Eqtesad) | → sepah |
Their codes stay in the table because IBANs issued before the merger are still
valid and still have to resolve. Each is marked with MergedInto: "sepah", so
you can surface "this account has moved to Bank Sepah" instead of failing.
Packages
Project