139 lines
3.7 KiB
C#
139 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using gehGassiApp.Domain.Common;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
namespace gehGassiApp.Domain.Payment
|
|
{
|
|
/// <summary>
|
|
/// Repräsentiert eine Bankverbindung eines App-Users
|
|
/// </summary>
|
|
public class BankAccount : ObservableObject
|
|
{
|
|
private string _ownerName;
|
|
private string _iban;
|
|
private string _bic;
|
|
|
|
/// <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 => _ownerName;
|
|
set
|
|
{
|
|
_ownerName = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
/// <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 => _iban;
|
|
set
|
|
{
|
|
_iban = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bic der Bankverbindung
|
|
/// </summary>
|
|
[MaxLength(255)]
|
|
public string Bic
|
|
{
|
|
get => _bic;
|
|
set
|
|
{
|
|
_bic = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
public BankAccount()
|
|
{
|
|
Address = new Address();
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
}
|
|
}
|