|
|
|
@ -2,16 +2,16 @@ import { Country } from '@/classes/Enum/Country' |
|
|
|
|
|
|
|
|
|
export class IbanGenerator { |
|
|
|
|
generate (country: Country) { |
|
|
|
|
const t = this.getBankAccount(country) |
|
|
|
|
const n = this.getNationalCheckDigit(t) |
|
|
|
|
const r = this.getBankCode(country) |
|
|
|
|
const shortBankAccount = this.getBankAccount(country) |
|
|
|
|
const bankCode = this.getBankCode(country) |
|
|
|
|
const estonianCheckDigit = this.getEstonianCheckDigit(bankCode + shortBankAccount) |
|
|
|
|
switch (country) { |
|
|
|
|
case Country.ESTONIA: |
|
|
|
|
return country.toUpperCase() + this.getIbanCheckDigits(r + t + n + '141400') + r + t + n |
|
|
|
|
return country.toUpperCase() + this.getIbanCheckDigits(bankCode + shortBankAccount + estonianCheckDigit + '141400') + bankCode + shortBankAccount + estonianCheckDigit |
|
|
|
|
case Country.LITHUANIA: |
|
|
|
|
return country.toUpperCase() + this.getIbanCheckDigits(r + t + '212900') + r + t |
|
|
|
|
return country.toUpperCase() + this.getIbanCheckDigits(bankCode + shortBankAccount + '212900') + bankCode + shortBankAccount |
|
|
|
|
default: |
|
|
|
|
return country.toUpperCase() + this.getIbanCheckDigits(r + t + '252100') + r + t |
|
|
|
|
return country.toUpperCase() + this.getIbanCheckDigits(bankCode + shortBankAccount + '252100') + bankCode + shortBankAccount |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -26,36 +26,50 @@ export class IbanGenerator { |
|
|
|
|
return t + String(i - (o % i)).padStart(2, '0') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getNationalCheckDigit (e: string) { |
|
|
|
|
const t = [7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7] |
|
|
|
|
const n = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
|
|
|
|
let r = 0 |
|
|
|
|
const i = e.length |
|
|
|
|
let o = 18 |
|
|
|
|
for (let a = i - 1; a > -1; a--) { |
|
|
|
|
n[o] = t[o] * +e[a] |
|
|
|
|
o-- |
|
|
|
|
} |
|
|
|
|
o = 18 |
|
|
|
|
for (let a = i - 1; a > -1; a--) { |
|
|
|
|
r -= -n[o] |
|
|
|
|
o-- |
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param bban c 5 знака 16 символов |
|
|
|
|
* @return одну цифру |
|
|
|
|
*/ |
|
|
|
|
getEstonianCheckDigit (bban: string) { |
|
|
|
|
const toCheck = bban.substring(2, 15) |
|
|
|
|
const weights = [7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7] |
|
|
|
|
|
|
|
|
|
let sum = 0 |
|
|
|
|
for (let index = 0; index < toCheck.length; index++) { |
|
|
|
|
sum += parseInt(toCheck.charAt(index), 10) * weights[index] |
|
|
|
|
} |
|
|
|
|
const remainder = sum % 10 |
|
|
|
|
|
|
|
|
|
return String(r % 10 !== 0 ? 10 - r % 10 : 0) |
|
|
|
|
} |
|
|
|
|
return remainder === 0 ? 0 : 10 - remainder |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
getBankCode (e: Country) { |
|
|
|
|
const t = ['16000003', '11602231', '10301612', '18900002', '15002240', '19401018', '19101152'] |
|
|
|
|
const n = ['2200', '1010', '3300', '7700', '1700', '4204'] |
|
|
|
|
const r = ['20900', '72900', '74000', '40100', '21200', '72300', '21700', '21400', '70440', '71800', '73000'] |
|
|
|
|
switch (e) { |
|
|
|
|
getBankCode (country: Country) { |
|
|
|
|
const plBankCodes = [ |
|
|
|
|
'16000003', // (BNPPL Centrala) BNP PARIBAS BANK POLSKA SA Centrala
|
|
|
|
|
'11602231', // Bank Millennium SA Bankowy Punkt Rozlicze Nr 4
|
|
|
|
|
'10301612', // BH Regionalne Centrum Rozliczeń
|
|
|
|
|
'18900002', // HYPO Centrala
|
|
|
|
|
'15002240', // KBSA O. w Ełku
|
|
|
|
|
'19401018', // CABP F. nr 3 we Wrocławiu
|
|
|
|
|
'19101152' |
|
|
|
|
] |
|
|
|
|
const eeBankCodes = [ |
|
|
|
|
'2200', // Swedbank
|
|
|
|
|
'1010', // SEB
|
|
|
|
|
'3300', // Danske Bank A/S Eesti filiaal (Sampo Pank)
|
|
|
|
|
'7700', // LHV Pank
|
|
|
|
|
'1700', // Luminor
|
|
|
|
|
'4204' // COOP Bank
|
|
|
|
|
] |
|
|
|
|
const ltBankCodes = ['20900', '72900', '74000', '40100', '21200', '72300', '21700', '21400', '70440', '71800', '73000'] |
|
|
|
|
switch (country) { |
|
|
|
|
case Country.POLAND: |
|
|
|
|
return t[Math.floor(Math.random() * t.length)] |
|
|
|
|
return plBankCodes[Math.floor(Math.random() * plBankCodes.length)] |
|
|
|
|
case Country.ESTONIA: |
|
|
|
|
return n[Math.floor(Math.random() * n.length)] |
|
|
|
|
return eeBankCodes[Math.floor(Math.random() * eeBankCodes.length)] |
|
|
|
|
default: |
|
|
|
|
return r[Math.floor(Math.random() * r.length)] |
|
|
|
|
return ltBankCodes[Math.floor(Math.random() * ltBankCodes.length)] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|