130 lines
4.2 KiB
C#
130 lines
4.2 KiB
C#
using gehGassi.Dto.Common;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Text.RegularExpressions;
|
|
using gehGassi.Domain.Common;
|
|
|
|
namespace gehGassi.Domain.Payment
|
|
{
|
|
/// <summary>
|
|
/// Objekt für das Anlegen oder Aktualisieren einer Bankverbindung eines AppUsers
|
|
/// </summary>
|
|
public class BankAccount
|
|
{
|
|
/// <summary>
|
|
/// ID des AppUsers
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(128)]
|
|
public string AppUserId { get; set; }
|
|
|
|
/// <summary>
|
|
/// ID des AppUsers bei MangoPay
|
|
/// </summary>
|
|
[MaxLength(128)]
|
|
public string PaymentId { get; set; }
|
|
|
|
/// <summary>
|
|
/// ID der Bankverbindung bei MangoPay
|
|
/// </summary>
|
|
[MaxLength(128)]
|
|
public string BankId { get; set; }
|
|
|
|
/// <summary>
|
|
/// Name des Inhabers der Bankverbindung
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(255)]
|
|
public string OwnerName { get; set; }
|
|
|
|
/// <summary>
|
|
/// Adresse des Inhabers der Bankverbindung
|
|
/// </summary>
|
|
[Required]
|
|
public Address Address { get; set; }
|
|
|
|
/// <summary>
|
|
/// Iban der Bankverbindung
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(255)]
|
|
public string Iban { get; set; }
|
|
|
|
/// <summary>
|
|
/// Bic der Bankverbindung
|
|
/// </summary>
|
|
[MaxLength(255)]
|
|
public string Bic { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gibt zurück ob der Iban gültig ist
|
|
/// </summary>
|
|
/// <returns>true wenn gültig, false sonst</returns>
|
|
public bool IsIbanValid()
|
|
{
|
|
if (string.IsNullOrEmpty(Iban))
|
|
return false;
|
|
|
|
var iban = Iban.ToUpper().Replace(" ", "").Replace("-", "");
|
|
if (!Regex.IsMatch(iban, @"^[A-Z]{2}[0-9]{2}[A-Z0-9]{4}[0-9]{7}([A-Z0-9]?){0,16}$"))
|
|
return false;
|
|
|
|
var ibanWithoutCountryAndChecksum = iban.Substring(4) + iban.Substring(0, 4);
|
|
var ibanWithoutCountryAndChecksumAsNumber = string.Concat(ibanWithoutCountryAndChecksum.Select(c => char.IsLetter(c) ? c - 55 : c - '0'));
|
|
|
|
var checksum = BigInteger.Parse(ibanWithoutCountryAndChecksumAsNumber) % 97;
|
|
return checksum == 1;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt zurück ob der Bic gültig ist.
|
|
/// Der BIC ist optional und wird nur geprüft wenn er nicht leer ist
|
|
/// </summary>
|
|
/// <returns>true wenn gültig, false sonst</returns>
|
|
public bool IsBicValid()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Bic))
|
|
return true;
|
|
|
|
var bic = Bic.ToUpper().Replace(" ", "").Replace("-", "");
|
|
if (!Regex.IsMatch(bic, @"^[A-Z]{6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$"))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt zurück ob die Bankverbindung geändert wurde
|
|
/// </summary>
|
|
/// <param name="bankAccount">Bankverbindung für den Vergleich</param>
|
|
/// <returns>true wenn geändert, false sonst</returns>
|
|
public bool HasChanged(BankAccount bankAccount)
|
|
{
|
|
if (bankAccount == null)
|
|
return true;
|
|
|
|
if(OwnerName != bankAccount.OwnerName)
|
|
return true;
|
|
if(Iban.ToUpper().Replace(" ", "").Replace("-", "") != bankAccount.Iban.ToUpper().Replace(" ", "").Replace("-", ""))
|
|
return true;
|
|
if(Bic.ToUpper().Replace(" ", "").Replace("-", "") != bankAccount.Bic.ToUpper().Replace(" ", "").Replace("-", ""))
|
|
return true;
|
|
if(Address.AddressLine1 != bankAccount.Address.AddressLine1)
|
|
return true;
|
|
if(Address.AddressLine2 != bankAccount.Address.AddressLine2)
|
|
return true;
|
|
if(Address.City != bankAccount.Address.City)
|
|
return true;
|
|
if(Address.CountryCode != bankAccount.Address.CountryCode)
|
|
return true;
|
|
if(Address.Zip != bankAccount.Address.Zip)
|
|
return true;
|
|
if(Address.State != bankAccount.Address.State)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|