Пример #1
0
        private static void validateCountryCode(string iban)
        {
            if (iban.Length < Consts.IBAN_COUNTRY_CODE_LENGTH)
            {
                throw new IbanFormatException("Input must contain 2 letters for country code", IbanFormatViolation.COUNTRY_CODE_TWO_LETTERS, iban);
            }

            string countryCode = GetCountryCode(iban);

            if (!countryCode.Equals(countryCode.ToUpper()) || !char.IsLetter(iban[0]) || !char.IsLetter(iban[1]))
            {
                throw new IbanFormatException("IBAN's country code must contain upper case letters", IbanFormatViolation.COUNTRY_CODE_UPPER_CASE_LETTERS, iban);
            }

            CountryCodeEntry countryEntry = CountryCode.GetCountryCode(countryCode);

            if (countryEntry == null)
            {
                throw new IbanFormatException("IBAN contains non existing country code", IbanFormatViolation.COUNTRY_CODE_EXISTS, iban);
            }

            BBanStructure structure = Bban.GetStructureForCountry(countryEntry);

            if (structure == null)
            {
                throw new UnsupportedCountryException("IBAN contains not supported country code", countryCode);
            }
        }
Пример #2
0
        private static bool hasValidCountryCode(string iban, out IbanFormatViolation validationResult)
        {
            validationResult = IbanFormatViolation.NO_VIOLATION;

            if (iban.Length < Consts.IBAN_COUNTRY_CODE_LENGTH)
            {
                validationResult = IbanFormatViolation.COUNTRY_CODE_TWO_LETTERS;
            }
            else
            {
                string countryCode = GetCountryCode(iban);
                if (!countryCode.Equals(countryCode.ToUpper()) || !char.IsLetter(iban[0]) || !char.IsLetter(iban[1]))
                {
                    validationResult = IbanFormatViolation.COUNTRY_CODE_UPPER_CASE_LETTERS;
                }
                else
                {
                    CountryCodeEntry countryEntry = CountryCode.GetCountryCode(countryCode);
                    if (countryEntry == null)
                    {
                        validationResult = IbanFormatViolation.COUNTRY_CODE_EXISTS;
                    }
                    else
                    {
                        BBanStructure structure = Bban.GetStructureForCountry(countryEntry);
                        if (structure == null)
                        {
                            validationResult = IbanFormatViolation.COUNTRY_CODE_UNSUPPORTED;
                        }
                    }
                }
            }

            return(validationResult == IbanFormatViolation.NO_VIOLATION);
        }
Пример #3
0
        /// <summary>
        /// Format BBAN string
        /// </summary>
        /// <returns>BBAN string</returns>
        private string formatBban()
        {
            StringBuilder sb            = new StringBuilder();
            BBanStructure bbanStructure = Bban.GetStructureForCountry(_countryCodeEntry);

            if (bbanStructure == null)
            {
                throw new UnsupportedCountryException("Country code is not supported", _countryCodeEntry.Alpha2);
            }

            foreach (BBanEntry entry in bbanStructure.Entries)
            {
                switch (entry.EntryType)
                {
                case BBanEntryType.BANK_CODE:
                    reformatBankCode(entry.Length);
                    sb.Append(_bankCode);
                    break;

                case BBanEntryType.BRANCH_CODE:
                    sb.Append(_branchCode);
                    break;

                case BBanEntryType.BALANCE_ACCOUNT_NUMBER:
                    sb.Append(_balanceAccountNumber);
                    break;

                case BBanEntryType.ACCOUNT_NUMBER_PREFIX:
                    reformatAccountNumberPrefix(entry.Length);
                    sb.Append(_accountNumberPrefix);
                    break;

                case BBanEntryType.ACCOUNT_NUMBER:
                    reformatAccountNumber(entry.Length);
                    sb.Append(_accountNumber);
                    break;

                case BBanEntryType.NATIONAL_CHECK_DIGIT:
                    sb.Append(_nationalCheckDigit);
                    break;

                case BBanEntryType.ACCOUNT_TYPE:
                    sb.Append(_accountType);
                    break;

                case BBanEntryType.OWNER_ACCOUNT_NUMBER:
                    sb.Append(_ownerAccountType);
                    break;

                case BBanEntryType.IDENTIFICATION_NUMBER:
                    sb.Append(_identificationNumber);
                    break;
                }
            }

            return(sb.ToString());
        }
Пример #4
0
        /// <summary>
        /// Checks if specified BBAN entry is supported for given country code.
        /// </summary>
        /// <param name="alpha2Code">Alpha2 Country code</param>
        /// <param name="entryType">BBAN entry type</param>
        /// <returns>True if given country contains rule for specified entry</returns>
        public static bool IsBbanEntrySupported(string alpha2Code, BBanEntryType entryType)
        {
            Bban          bban      = new Bban();
            BBanStructure structure = GetStructureForCountry(alpha2Code);
            bool          result    = false;

            if (structure != null)
            {
                result = structure.Entries.Any(x => x.EntryType == entryType);
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        /// Search for BBAN structure of specified country
        /// </summary>
        /// <param name="alpha2Code">Alpha2 Country code</param>
        /// <returns>BBAN structure of defined country, or null if given country code is unsupported</returns>
        public static BBanStructure GetStructureForCountry(string alpha2Code)
        {
            Bban          bban   = new Bban();
            BBanStructure result = null;

            if (!string.IsNullOrEmpty(alpha2Code) && alpha2Code.Length == 2)
            {
                if (bban._bbanStructures != null)
                {
                    if (bban._bbanStructures.ContainsKey(alpha2Code.ToUpper()))
                    {
                        result = bban._bbanStructures[alpha2Code];
                    }
                }
            }

            return(result);
        }
Пример #6
0
        /// <summary>
        /// Search for BBAN structure of specified country
        /// </summary>
        /// <param name="countryCode">Country code object</param>
        /// <returns>BBAN structure of defined country, or null if given country code is unsupported</returns>
        public static BBanStructure GetStructureForCountry(CountryCodeEntry countryCode)
        {
            Bban          bban   = new Bban();
            BBanStructure result = null;

            if (countryCode != null)
            {
                if (bban._bbanStructures != null)
                {
                    if (bban._bbanStructures.ContainsKey(countryCode.Alpha2))
                    {
                        result = bban._bbanStructures[countryCode.Alpha2];
                    }
                }
            }

            return(result);
        }
Пример #7
0
 private static BBanStructure getBbanStructure(CountryCodeEntry countryCode) => Bban.GetStructureForCountry(countryCode);
Пример #8
0
 /// <summary>
 /// Checks whether country is supported.
 /// It is checked by trying to find the country code in defined BBAN structures.
 /// </summary>
 /// <param name="alpha2Code">Alpha2 code for country</param>
 /// <returns>True if country code is supported, othewise false</returns>
 public static bool IsSupportedCountry(string alpha2Code) => (CountryCode.GetCountryCode(alpha2Code) != null) && (Bban.GetStructureForCountry(alpha2Code) != null);
Пример #9
0
 /// <summary>
 /// Checks whether country is supported.
 /// It is checked by trying to find the country code in defined BBAN structures.
 /// </summary>
 /// <param name="countryCode">Country code object</param>
 /// <returns>True if country code is supported, othewise false</returns>
 public static bool IsSupportedCountry(CountryCodeEntry countryCode) => (CountryCode.GetCountryCode(countryCode?.Alpha2) != null) && (Bban.GetStructureForCountry(countryCode) != null);