Example #1
0
 public IbanFormatException(string message, IbanFormatViolation formatViolation, char invalidCharacter, BBanEntryType entryType, object actual) : base(message)
 {
     FormatViolation  = formatViolation;
     InvalidCharacter = invalidCharacter;
     BBanEntryType    = entryType;
     ActualObject     = actual;
 }
Example #2
0
        private static string changeBbanEntry(string iban, string newValue, BBanEntryType entryType)
        {
            string bban    = GetBBan(iban);
            string newIban = GetCountryCode(iban) + Consts.IBAN_DEFAULT_CHECK_DIGIT;

            BBanStructure structure  = getBbanStructure(iban);
            int           bbanOffset = 0;
            StringBuilder sb         = new StringBuilder(bban);

            foreach (BBanEntry entry in structure.Entries)
            {
                if (entry.EntryType == entryType)
                {
                    if (newValue.Length > entry.Length)
                    {
                        throw new IbanFormatException($"New value for {Enum.GetName(typeof(BBanEntryType), entry.EntryType)} is too long.", IbanFormatViolation.BBAN_ENTRY_TOO_LONG);
                    }

                    sb.Remove(bbanOffset, entry.Length);
                    sb.Insert(bbanOffset, newValue.PadLeft(entry.Length, '0'));
                    break;
                }

                bbanOffset += entry.Length;
            }

            sb.Insert(0, newIban);
            newIban = sb.ToString();

            string newCheckDigit = CalculateCheckDigit(newIban);
            string result        = ReplaceCheckDigit(newIban, newCheckDigit);

            return(result);
        }
Example #3
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)
        {
            BBanStructure structure = GetStructureForCountry(alpha2Code);
            bool          result    = false;

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

            return(result);
        }
Example #4
0
        private static string extractBbanEntry(string iban, BBanEntryType entryType)
        {
            string result = "";

            string        bban       = GetBBan(iban);
            BBanStructure structure  = getBbanStructure(iban);
            int           bbanOffset = 0;

            foreach (BBanEntry entry in structure.Entries)
            {
                int    entryLength = entry.Length;
                string entryValue  = bban.Substring(bbanOffset, entryLength);

                bbanOffset += entryLength;

                if (entry.EntryType == entryType)
                {
                    result = entryValue;
                    break;
                }
            }

            return(result);
        }
Example #5
0
 private BBanEntry(BBanEntryType entryType, BBanEntryCharacterType characterType, int length)
 {
     EntryType     = entryType;
     CharacterType = characterType;
     Length        = length;
 }
Example #6
0
 public IbanFormatException(string message, IbanFormatViolation formatViolation, char invalidCharacter, BBanEntryType entryType, object actual)
     : base(message)
 {
     FormatViolation = formatViolation;
     InvalidCharacter = invalidCharacter;
     BBanEntryType = entryType;
     ActualObject = actual;
 }
Example #7
0
        private static string changeBbanEntry(string iban, string newValue, BBanEntryType entryType)
        {
            
            string bban = GetBBan( iban );
            string newIban = GetCountryCode( iban ) + Iban.DEFAULT_CHECK_DIGIT;

            BBanStructure structure = getBbanStructure( iban );
            int bbanOffset = 0;
            StringBuilder sb = new StringBuilder( bban );

            foreach (BBanEntry entry in structure.Entries)
            {                
                if (entry.EntryType == entryType)
                {

                    if (newValue.Length > entry.Length)
                    {
                        throw new IbanFormatException( $"New value for {Enum.GetName( typeof( BBanEntryType ), entry.EntryType )} is too long.", IbanFormatViolation.BBAN_ENTRY_TOO_LONG );
                    }

                    sb.Remove( bbanOffset, entry.Length );
                    sb.Insert( bbanOffset, newValue.PadLeft( entry.Length, '0' ) );
                    break;
                }

                bbanOffset += entry.Length;
            }

            sb.Insert( 0, newIban );
            newIban = sb.ToString();

            string newCheckDigit = CalculateCheckDigit( newIban );
            string result = ReplaceCheckDigit( newIban, newCheckDigit );

            return result;
            
        }
Example #8
0
        private static string extractBbanEntry (string iban, BBanEntryType entryType)
        {
            string result = "";

            string bban = GetBBan( iban );
            BBanStructure structure = getBbanStructure( iban );
            int bbanOffset = 0;

            foreach (BBanEntry entry in structure.Entries)
            {
                int entryLength = entry.Length;
                string entryValue = bban.Substring( bbanOffset, entryLength );

                bbanOffset += entryLength;

                if (entry.EntryType == entryType)
                {
                    result = entryValue;
                    break;
                }
            }

            return result;
        }
Example #9
0
 private BBanEntry (BBanEntryType entryType, BBanEntryCharacterType characterType, int length)
 {
     EntryType = entryType;
     CharacterType = characterType;
     Length = length;
 }
Example #10
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;
        }