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); }
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); } }
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); }
private CountryCodeEntry getByAlpha3(string code) { CountryCodeEntry result = null; if (_alpha3Map != null) { result = _alpha3Map.Values.Where(x => x.Alpha3.Equals(code)).SingleOrDefault(); } return(result); }
/// <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); }
private CountryCodeEntry getByAlpha2(string code) { CountryCodeEntry result = null; if (_alpha3Map != null) { if (_alpha3Map.ContainsKey(code)) { result = _alpha3Map[code]; } } return(result); }
/// <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); }
/// <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); } }
/// <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); }
/// <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); }
/// <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; }
/// <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; }
/// <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); }
private static BBanStructure getBbanStructure(CountryCodeEntry countryCode) => Bban.GetStructureForCountry(countryCode);
private static BBanStructure getBbanStructure (CountryCodeEntry countryCode) => Bban.GetStructureForCountry( countryCode );
/// <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);
/// <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);
/// <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 ); } }
/// <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; }