/// <summary> /// Calculates the modulo of 97 for a iban. /// </summary> /// <param name="iban">The given iban for which the modulo 97 should be calculated.</param> /// <returns>The calculated result.</returns> /// <exception cref="IbanException"> /// <list type="table"> /// <item> /// <term><see cref="RuleType"/></term> /// <description>IbanGeneratingCheckDigit</description> /// <description>When check digit could not be calculated.</description> /// </item> /// </list> /// </exception> protected int Modulo97(Iban iban) { try { if (string.IsNullOrWhiteSpace(iban.CheckDigit)) { iban.CheckDigit = "00"; } string input = this.BbanToNumber(iban.BBAN) + CountryCodeToNumber(iban.Country.CountryCode) + iban.CheckDigit; string output = string.Empty; for (int i = 0; i < input.Length; i++) { if (output.Length < 9) { output += input[i]; } else { output = (Int32.Parse(output) % 97).ToString() + input[i]; } } return(Int32.Parse(output) % 97); } catch (Exception ex) { throw new IbanException(ex, IbanExceptionType.IbanGeneratingCheckDigit); } }
public void IbanTest2() { var iban = new Iban("de", 68, "2105 0170 0012 3456 78"); Assert.AreEqual("DE", iban.CountryCode); Assert.AreEqual(68, iban.Checksum); Assert.AreEqual("210501700012345678", iban.Bban); }
/// <summary> /// Gets the iban code out of a Iban object (which does not contain the iban code yet). /// </summary> /// <param name="iban">The given iban object.</param> /// <returns>The iban code as string.</returns> /// /// <exception cref="IbanException"> /// <list type="table"> /// <item> /// <term><see cref="RuleType"/></term> /// <description>IbanGeneratingNotAllParameters</description> /// <description>If not all parameters are available for iban converting.</description> /// </item> /// <item> /// <term><see cref="RuleType"/></term> /// <description>IbanGeneratingFormatting</description> /// <description>If iban format is not valid.</description> /// </item> /// </list> /// </exception> protected string GetIban(Iban iban) { // Check if all necessary parameters are set if (string.IsNullOrWhiteSpace(iban.AccountNumber) || string.IsNullOrWhiteSpace(iban.Bank.BankIdentification) || string.IsNullOrWhiteSpace(iban.BBAN) || string.IsNullOrWhiteSpace(iban.CheckDigit) || iban.Country == null || string.IsNullOrWhiteSpace(iban.Country.CountryCode)) { throw new IbanException(IbanExceptionType.IbanGeneratingNotAllParameters); } // iban formatting: CountryCode || check digit || bank ident || account number string IBAN = iban.Country.CountryCode + iban.CheckDigit + iban.BBAN; iban.IBAN = IBAN; // check if iban is correct formatted if (!this.CheckIbanFormatting(iban)) { // iban not well formatted -> error throw new IbanException(IbanExceptionType.IbanGeneratingFormatting); } return(IBAN); }
public void Hashcode_Ignores_Whitespace() { var lhs = new Iban("BE71 0961 2345 6769"); var rhs = new Iban("BE 71 096123456769"); lhs.GetHashCode().Equals(rhs.GetHashCode()).Should().BeTrue(); }
static void Main(string[] args) { Dictionary <string, string> ibans = new Dictionary <string, string> { { "GB33BUKB20201555555555", "IBAN, longitud, checksum, código bancario, cuenta y estructura válidos" }, { "GB94BARC10201530093459", "IBAN válido, código bancario no encontrado (no se puede identificar el banco): longitud, checksum, código bancario, cuenta y estructura válidos" }, { "GB94BARC20201530093459", "Dígitos de verificación MOD-97 - 10 de IBAN inválidos según el estándar ISO / IEC 7064:2003" }, { "GB96BARC202015300934591", "Longitud de IBAN inválida, ¡debe tener una longitud de \"X\" caracteres!" }, { "GB02BARC20201530093451", "Número de cuenta inválido" }, { "GB68CITI18500483515538", "Número de cuenta inválido" }, { "GB24BARC20201630093459", "Código bancario no encontrado y número de cuenta inválido" }, { "GB12BARC20201530093A59", "Estructura de cuenta inválida" }, { "GB78BARCO0201530093459", "Código bancario no encontrado y estructura de código bancario inválida" }, { "GB2LABBY09012857201707", "Checksum de estructura de IBAN inválido" }, { "GB01BARC20714583608387", "Checksum de IBAN inválida" }, { "GB00HLFX11016111455365", "Checksum de IBAN inválida" }, { "US64SVBKUS6S3300958879", "¡País no compatible con IBAN!" }, // Medicos sin fronters { "ES8320480000273400106773", "Medicos Sin Fronteras (Liberbank )" }, // Genware { "ES9614348598260926732057", "GENWARE" } }; foreach (KeyValuePair <string, string> valor in ibans) { bool valid = Iban.Validate(valor.Key); Console.WriteLine(valor.Key + ": " + valid.ToString() + ": " + valor.Value); } }
/// <summary> /// Generates the payload for a SwissQrCode. (Don't forget to use ECC-Level M and set the Swiss flag icon to the final QR code.) /// </summary> /// <param name="iban">IBAN object</param> /// <param name="currency">Currency (either EUR or CHF)</param> /// <param name="creditor">Creditor (payee) information</param> /// <param name="reference">Reference information</param> /// <param name="debitor">Debitor (payer) information</param> /// <param name="amount">Amount</param> /// <param name="requestedDateOfPayment">Requested date of debitor's payment</param> /// <param name="ultimateCreditor">Ultimate creditor information (use only in consultation with your bank!)</param> /// <param name="alternativeProcedure1">Optional command for alternative processing mode - line 1</param> /// <param name="alternativeProcedure2">Optional command for alternative processing mode - line 2</param> public SwissQrCodePayload(Iban iban, Currency currency, Contact creditor, Reference reference, Contact debitor = null, decimal?amount = null, DateTime?requestedDateOfPayment = null, Contact ultimateCreditor = null, string alternativeProcedure1 = null, string alternativeProcedure2 = null) { this.iban = iban; this.creditor = creditor; this.ultimateCreditor = ultimateCreditor; if (amount != null && amount.ToString().Length > 12) { throw new SwissQrCodeException("Amount (including decimals) must be shorter than 13 places."); } this.amount = amount; this.currency = currency; this.requestedDateOfPayment = requestedDateOfPayment; this.debitor = debitor; if (iban.IsQrIban && reference.RefType.Equals(Reference.ReferenceType.NON)) { throw new SwissQrCodeException("If QR-IBAN is used, you have to choose \"QRR\" or \"SCOR\" as reference type!"); } this.reference = reference; if (alternativeProcedure1 != null && alternativeProcedure1.Length > 100) { throw new SwissQrCodeException("Alternative procedure information block 1 must be shorter than 101 chars."); } this.alternativeProcedure1 = alternativeProcedure1; if (alternativeProcedure2 != null && alternativeProcedure2.Length > 100) { throw new SwissQrCodeException("Alternative procedure information block 2 must be shorter than 101 chars."); } this.alternativeProcedure2 = alternativeProcedure2; }
public void Constructor_Splitter() { var countryResolver = new Mock <ICountryResolver>(); countryResolver .Setup(x => x.GetCountry(It.IsAny <string>())) .Returns(Country); var bban = new Mock <IBban>(); bban.Setup(x => x.Value()) .Returns(GetBban()); var bbanGenerator = new Mock <IBban>(); bbanGenerator .Setup( x => x.SplitBban( It.IsAny <ICountry>(), It.IsAny <string>(), It.IsAny <IValidators>(), It.IsAny <IBbanSplitter>())) .Returns(bban.Object); var iban = new Iban( GetIban(), countryResolver.Object, bbanGenerator.Object, ValidValidators, GetIBbanSplitter(), GetBbanSplitter()); AssertIban(iban); }
public BankAccountBuilder(OId <BankAccount, Guid> id) { this.id = id; employeeId = OId.Of <Employee, Guid>(Guid.Parse("309dc64d-bde5-4ee5-9e21-33a517e2fe35")); accountHolderId = OId.Of <AccountHolder, Guid>(Guid.Parse("59ed2782-881b-49a9-8230-d0b3bb1c9072")); iban = Iban.Of("DE37200505501340426749"); accountCurrency = Currency.Euro; }
public void Invalid_Iban_Must_Be_Serializable_And_Not_Throw_On_Deserialization() { var sut = Iban.Unsafe("BE71 0962 2345 6769"); // invalid check digit sut.Should().BeBinarySerializable(); sut.Should().BeXmlSerializable(); sut.Should().BeDataContractSerializable(); }
public void Serialization_Of_Iban() { var sut = new Iban("BE71 0961 2345 6769"); sut.Should().BeXmlSerializable(); sut.Should().BeBinarySerializable(); sut.Should().BeDataContractSerializable(); }
public CreateBankAccount(OId <AccountHolder, Guid> accountHolderId, OId <Employee, Guid> employeeId, Currency accountCurrency, Iban iban, TimeStamp timeStamp) : base(timeStamp) { AccountHolderId = accountHolderId; EmployeeId = employeeId; AccountCurrency = accountCurrency; Iban = iban; }
public BankAccountCreated(Guid bankAccountId, Guid userId, Iban iban, Currency currency, decimal balance, DateTimeOffset createDate) { AggregateRootId = bankAccountId; UserId = userId; Iban = iban; Currency = currency; Balance = balance; CreateDate = createDate; }
public void Equality_Ignores_Whitespace() { var lhs = new Iban("BE71 0961 2345 6769"); var rhs = new Iban("BE 71 096123456769"); lhs.Equals(rhs).Should().BeTrue(); (lhs == rhs).Should().BeTrue(); (lhs != rhs).Should().BeFalse(); }
public void Unsafe_Ignores_Validation() { // the check digits are incorrect. var sut = Iban.Unsafe("BE81 0961 2345 6769"); sut.CountryCode.Should().Be("BE"); sut.CheckDigits.Should().Be("81"); sut.BasicBankAccountNumber.Should().Be("096123456769"); sut.ToString().Should().Be("BE81 0961 2345 6769"); }
/// <summary> /// Synchronous method to get a bic to a given iban code. /// </summary> /// <param name="sIban">The given ibanc code.</param> /// <returns>The BIC that belongs to given iban.</returns> public BankIdentifierCode GetBic(string sIban) { // convert string to object Iban iban = this.ConvertStringToIban(sIban); // generate iban and compare to given iban IbanBic generated = this.GenerateIban(iban.Country.CountryType, iban.Bank.BankIdentification, iban.AccountNumber); return(generated.BIC); }
public void It_should_succeed() { var bankAccountNumber1 = new Iban(TestValues.ValidIban); string json = JsonConvert.SerializeObject(bankAccountNumber1); json.Should().Be($"\"{TestValues.ValidIban}\""); Iban bankAccountNumber2 = JsonConvert.DeserializeObject <Iban>(json); bankAccountNumber1.Should().Be(bankAccountNumber2); }
public void Constructor_Parameters() { var bban = new Mock <IBban>(); bban.Setup(x => x.Value()) .Returns(GetBban()); var iban = new Iban(Country, bban.Object); AssertIban(iban); }
public QRSwiss(QRSwissParameters parameters) { res = new MyRes("Messages,Swiss"); if (parameters.Iban == null) { throw new SwissQrCodeException(res.Get("SwissNullIban")); } if (parameters.Creditor == null) { throw new SwissQrCodeException(res.Get("SwissNullCreditor")); } if (parameters.Reference == null) { throw new SwissQrCodeException(res.Get("SwissNullReference")); } if (parameters.Currency == null) { throw new SwissQrCodeException(res.Get("SwissNullCurrency")); } this.iban = parameters.Iban; this.creditor = parameters.Creditor; this.additionalInformation = parameters.AdditionalInformation != null ? parameters.AdditionalInformation : new AdditionalInformation(null, null); if (parameters.Amount != null && parameters.Amount.ToString().Length > 12) { throw new SwissQrCodeException(res.Get("SwissAmountLength")); } this.amount = parameters.Amount; this.currency = parameters.Currency.Value; this.debitor = parameters.Debitor; if (iban.IsQrIban && parameters.Reference.RefType != Reference.ReferenceType.QRR) { throw new SwissQrCodeException(res.Get("SwissQRIban")); } if (!iban.IsQrIban && parameters.Reference.RefType == Reference.ReferenceType.QRR) { throw new SwissQrCodeException(res.Get("SwissNonQRIban")); } this.reference = parameters.Reference; if (parameters.AlternativeProcedure1 != null && parameters.AlternativeProcedure1.Length > 100) { throw new SwissQrCodeException(res.Get("SwissAltProcedureLength")); } this.alternativeProcedure1 = parameters.AlternativeProcedure1; if (parameters.AlternativeProcedure2 != null && parameters.AlternativeProcedure2.Length > 100) { throw new SwissQrCodeException(res.Get("SwissAltProcedureLength")); } this.alternativeProcedure2 = parameters.AlternativeProcedure2; }
public void Constructor_Empty() { var iban = new Iban(); Assert.IsNull(iban.Country); Assert.IsNotNullOrEmpty(iban.NationalCheckDigits); Assert.AreEqual(NationalCheckDigits, iban.NationalCheckDigits); Assert.IsNull(iban.Bban); Assert.IsNullOrEmpty(iban.Value()); Assert.IsNotNullOrEmpty(iban.ToString()); }
public void CuentaCorrienteVacia() { try { Iban.calcularIban(""); Assert.Fail("Cuenta Corriente Vacia, no se puede calcular el IBAN"); } catch { } }
/// <summary> /// Gets the bban out of an iban. /// </summary> /// <param name="iban">The given iban.</param> /// <returns>The bban.</returns> /// <exception cref="IbanException"> /// <list type="table"> /// <item> /// <term><see cref="RuleType"/></term> /// <description>BBANError</description> /// <description>When bban could not be calculated.</description> /// </item> /// </list> /// </exception> protected string GetBBAN(Iban iban) { if (string.IsNullOrWhiteSpace(iban.AccountNumber) || string.IsNullOrWhiteSpace(iban.Bank.BankIdentification)) { throw new IbanException(IbanExceptionType.BBANError); } string bban = iban.Bank.BankIdentification + iban.AccountNumber; return(bban); }
/// <summary> /// Checks if a iban code fits to the country format rules. /// </summary> /// <param name="iban">The given iban.</param> /// <returns>'True' if the format is ok, otherwise 'false'.</returns> private bool CheckIbanFormatting(Iban iban) { RegexHelper regexpheler = new RegexHelper(); if (regexpheler.RegexpMatch(iban.Country.RegExp, iban.IBAN)) { return(true); } return(false); }
public void TestShouldCreateIban_validated() { // Arrange const string iban = "123456789"; // Act var result = Iban.Of(iban); // Assert Assert.IsTrue(result.IsValid); Assert.AreEqual(iban, result.GetObject().Value); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (AdditionalAddressInfo != null) { hashCode = hashCode * 59 + AdditionalAddressInfo.GetHashCode(); } if (City != null) { hashCode = hashCode * 59 + City.GetHashCode(); } if (CountryCode != null) { hashCode = hashCode * 59 + CountryCode.GetHashCode(); } if (HouseNumber != null) { hashCode = hashCode * 59 + HouseNumber.GetHashCode(); } if (Iban != null) { hashCode = hashCode * 59 + Iban.GetHashCode(); } if (Id != null) { hashCode = hashCode * 59 + Id.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (ReferenceParty != null) { hashCode = hashCode * 59 + ReferenceParty.GetHashCode(); } if (ReferencePartyId != null) { hashCode = hashCode * 59 + ReferencePartyId.GetHashCode(); } if (Street != null) { hashCode = hashCode * 59 + Street.GetHashCode(); } if (Zip != null) { hashCode = hashCode * 59 + Zip.GetHashCode(); } return(hashCode); } }
public override int GetHashCode() { unchecked { int hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ ClientId.GetHashCode(); hashCode = (hashCode * 397) ^ Iban.GetHashCode(); hashCode = (hashCode * 397) ^ Currency.GetHashCode(); hashCode = (hashCode * 397) ^ CreatedByEmployee.GetHashCode(); return(hashCode); } }
private static Task CreateAccountAsync(IMediator mediator) { System.Console.Clear(); System.Console.Write("IBAN: "); var iban = Iban.Of(System.Console.ReadLine()); var createBankAccount = new CreateBankAccount(OId.Of <AccountHolder, Guid>(Guid.NewGuid()), OId.Of <Employee, Guid>(EmployeeId), Currency.Euro, iban, TimeStamp.Of(DateTimeOffset.Now.ToUnixTimeSeconds())); return(mediator.Send(createBankAccount)); }
public static BankAccount New( OId <BankAccount, Guid> id, OId <AccountHolder, Guid> accountHolderId, Iban iban, Currency accountCurrency, OId <Employee, Guid> employeeId, TimeStamp timeStamp) { var bankAccount = new BankAccount(id); bankAccount.Create(accountHolderId, iban, accountCurrency, employeeId, timeStamp); return(bankAccount); }
/// <summary> /// Synchronous method to validate an given iban code. /// </summary> /// <param name="sIban">The given i ban code as string, which should be validated.</param> /// <returns>'True' if iban code is valid, otherwise 'false'.</returns> public bool ValidateIban(string sIban) { // convert string to object Iban iban = this.ConvertStringToIban(sIban); // if modulo97 of iban is 1, the iban is valid if (this.Modulo97(iban) == 1) { return(true); } return(false); }
public IActionResult Save([FromBody] InputModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Iban iban = _parser.Parse(model.BankAccountNumber); // Do something with model... model.BankAccountNumber = iban.ToString(Iban.Formats.Partitioned); return(Ok(model)); }
public IActionResult OnPostAsync(RazorPageModel model) { if (!ModelState.IsValid) { return(Page()); } Iban iban = Iban.Parse(model.BankAccountNumber); // Do something with model... BankAccountNumber = iban.ToString(Iban.Formats.Partitioned); return(Page()); }
public IActionResult OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Iban iban = _parser.Parse(Model.BankAccountNumber); // Do something with model... Model.BankAccountNumber = iban.ToString(IbanFormat.Print); return(Page()); }
private void DisplayGermanySpecificInformation(Iban iban, StringBuilder sb) { sb.AppendLine(); if (!iban.IsValid) { sb.AppendLine("No information available (IBAN incorrect)"); return; } sb.AppendLine("German information"); var info = new Specialized.Germany.GermanyIbanInformationProvider(iban); sb.AppendLine(" Kontonummer: " + info.Kontonummer.Value); sb.AppendLine(" Bankleitzahl: " + info.Bankleitzahl.Value); sb.AppendLine(" Bankengruppe: " + info.Bankleitzahl.Bankengruppe); sb.AppendLine(" Clearing Area: " + info.Bankleitzahl.ClearingArea); sb.AppendLine("Individuelle Nummer: " + info.Bankleitzahl.IndividualNumber); }
private void DisplayCountryInformation(Iban iban) { if (iban == null) { ibanInformationLabel.Text = "No information available."; return; } var sb = new StringBuilder(); sb.AppendLine("Country code: " + iban.CountryCode); sb.AppendLine(" Checksum: " + iban.Checksum); sb.AppendLine(" Bban: " + iban.Bban); if (iban.CountryCode == "DE") DisplayGermanySpecificInformation(iban, sb); ibanInformationLabel.Text = sb.ToString(); }
public GermanyIbanInformationProvider(Iban iban) : base(iban) { const int blzLength = 8; const int ktoLength = 8; // DE00 2105 0170 0012 3456 78 // 210 501 70 - 0012 3456 78 // DEpp bbb bbb bb - kkkk kkkk kk // bbb bbb bb - kkkk kkkk kk (18 chars) var bbstr = iban.Bban; if (bbstr.Length != 18) throw new ArgumentException("Not a German IBAN."); var blzStr = bbstr.Substring(0, blzLength); var ktoStr = bbstr.Substring(18 - ktoLength, ktoLength); Bankleitzahl = Bankleitzahl.Parse(blzStr); Kontonummer = Kontonummer.Parse(ktoStr); }
protected IbanInformationProvider(Iban iban) { if (iban == null) throw new ArgumentNullException(nameof(iban)); IbanInteral = iban; }
public void ToString2() { var iban = new Iban("de", 68, "210501700012345678"); Assert.AreEqual("DE68 2105 0170 0012 3456 78", iban.ToString()); }
public void ToString4() { var iban = new Iban("de", 88, "200800000970375710"); Assert.AreEqual("DE88 2008 0000 0970 3757 10", iban.ToString()); }
public void IsValid2() { var iban = new Iban("de", 68, "2105 0170 0012 3456 78"); Assert.IsTrue(iban.IsValid); }
public void IsValid8() { var iban = new Iban("de", 88, "2008 0000 0970 3757 10"); Assert.IsFalse(iban.IsValid); }
public void IsValid5() { var iban = new Iban("de", 88, "2008 0000 0970 3757 00"); Assert.IsTrue(iban.IsValid); }