Esempio n. 1
0
        private static bool hasValidCountryCode(string iban, out IbanFormatViolation validationResult)
        {
            validationResult = IbanFormatViolation.NO_VIOLATION;

            if (iban.Length < _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);
        }
Esempio n. 2
0
        private static void validateCountryCode(string iban)
        {
            if (iban.Length < _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);
            }
        }
Esempio n. 3
0
        public override bool Equals(object obj)
        {
            if (obj is CountryCodeEntry)
            {
                CountryCodeEntry other = obj as CountryCodeEntry;
                return(Alpha2.Equals(other.Alpha2) & Alpha3.Equals(other.Alpha3) & CountryName.Equals(other.CountryName));
            }

            return(false);
        }
Esempio n. 4
0
        private CountryCodeEntry getByAlpha3(string code)
        {
            CountryCodeEntry result = null;

            if (_alpha3Map != null)
            {
                result = _alpha3Map.Values.Where(x => x.Alpha3.Equals(code)).SingleOrDefault();
            }

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Returns IBAN length for the specified country
        /// </summary>
        /// <param name="countryCode">Country code object</param>
        /// <returns>The length of IBAN for the specified country</returns>
        public static int GetIbanLength(CountryCodeEntry countryCode)
        {
            int           result    = 0;
            BBanStructure structure = getBbanStructure(countryCode);

            if (structure != null)
            {
                result = _COUNTRY_CODE_LENGTH + _CHECK_DIGIT_LENGTH + structure.GetBBanLength();
            }

            return(result);
        }
Esempio n. 6
0
        private CountryCodeEntry getByAlpha2(string code)
        {
            CountryCodeEntry result = null;

            if (_alpha3Map != null)
            {
                if (_alpha3Map.ContainsKey(code))
                {
                    result = _alpha3Map[code];
                }
            }

            return(result);
        }
Esempio n. 7
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)
        {
            BBanStructure result = null;

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

            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Check for required fields.
        /// Every broken rule throws exception
        /// </summary>
        /// <param name="countryCodeEntry">Country code Entry</param>
        /// <param name="bankCode">Bank code</param>
        /// <param name="accountNumber">Account number</param>
        /// <exception cref="IbanFormatException">Thrown when one of the parameters is not supplied</exception>
        private void require(CountryCodeEntry countryCodeEntry, string bankCode, string accountNumber)
        {
            if (_countryCodeEntry == null)
            {
                throw new IbanFormatException("Country code is required, it cannot be null.", IbanFormatViolation.COUNTRY_CODE_NOT_NULL);
            }

            if (string.IsNullOrEmpty(bankCode))
            {
                throw new IbanFormatException("Bank code is required, it cannot be empty.", IbanFormatViolation.BANK_CODE_NOT_NULL);
            }

            if (string.IsNullOrEmpty(accountNumber))
            {
                throw new IbanFormatException("Account number is required, it cannot be empty.", IbanFormatViolation.ACCOUNT_NUMBER_NOT_NULL);
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        /// <summary>
        /// Gets CountryCode object from map
        /// </summary>
        /// <param name="code">2 or 3 letters code for country</param>
        /// <returns>Found CountryCodeItem object or null if it is not found</returns>
        public static CountryCodeEntry GetCountryCode(string code)
        {
            CountryCodeEntry result = null;

            if (!string.IsNullOrEmpty(code))
            {
                switch (code.Length)
                {
                case 2:
                    result = getByAlpha2(code.ToUpper());
                    break;

                case 3:
                    result = getByAlpha3(code.ToUpper());
                    break;
                }
            }

            return(result);
        }
Esempio n. 11
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;
        }
Esempio n. 12
0
        /// <summary>
        /// Returns IBAN length for the specified country
        /// </summary>
        /// <param name="countryCode">Country code object</param>
        /// <returns>The length of IBAN for the specified country</returns>
        public static int GetIbanLength (CountryCodeEntry countryCode)
        {
            int result = 0;
            BBanStructure structure = getBbanStructure( countryCode );

            if (structure != null)
            {
                result = _COUNTRY_CODE_LENGTH + _CHECK_DIGIT_LENGTH + structure.GetBBanLength();
            }

            return result;
        }
Esempio n. 13
0
 /// <summary>
 /// Sets iban's Country code
 /// </summary>
 /// <param name="countryCode">Country code entry</param>
 /// <returns>Builder instance</returns>
 public IbanBuilder CountryCode(CountryCodeEntry countryCode)
 {
     this._countryCodeEntry = countryCode;
     return(this);
 }
Esempio n. 14
0
 private static BBanStructure getBbanStructure(CountryCodeEntry countryCode) => Bban.GetStructureForCountry(countryCode);
Esempio n. 15
0
 private static BBanStructure getBbanStructure (CountryCodeEntry countryCode) => Bban.GetStructureForCountry( countryCode );
Esempio n. 16
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);
Esempio n. 17
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);
Esempio n. 18
0
        /// <summary>
        /// Check for required fields.
        /// Every broken rule throws exception
        /// </summary>
        /// <param name="countryCodeEntry">Country code Entry</param>
        /// <param name="bankCode">Bank code</param>
        /// <param name="accountNumber">Account number</param>
        /// <exception cref="IbanFormatException">Thrown when one of the parameters is not supplied</exception>
        private void require(CountryCodeEntry countryCodeEntry, string bankCode, string accountNumber)
        {
            if (_countryCodeEntry == null)
            {
                throw new IbanFormatException( "Country code is required, it cannot be null.", IbanFormatViolation.COUNTRY_CODE_NOT_NULL );
            }

            if (string.IsNullOrEmpty(bankCode))
            {
                throw new IbanFormatException( "Bank code is required, it cannot be empty.", IbanFormatViolation.BANK_CODE_NOT_NULL );
            }

            if (string.IsNullOrEmpty(accountNumber))
            {
                throw new IbanFormatException( "Account number is required, it cannot be empty.", IbanFormatViolation.ACCOUNT_NUMBER_NOT_NULL );
            }
        }
Esempio n. 19
0
 /// <summary>
 /// Sets iban's Country code 
 /// </summary>
 /// <param name="countryCode">Country code entry</param>
 /// <returns>Builder instance</returns>
 public IbanBuilder CountryCode(CountryCodeEntry countryCode)
 {
     this._countryCodeEntry = countryCode;
     return this;
 }