Skip to content

Commit

Permalink
Resolved merge conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
sipsorcery committed Apr 19, 2024
2 parents ea708a9 + 54fa24b commit ca0f2b0
Show file tree
Hide file tree
Showing 20 changed files with 806 additions and 93 deletions.
46 changes: 46 additions & 0 deletions src/NoFrixion.MoneyMoov/Mapping/AccountIdentifierMappers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// -----------------------------------------------------------------------------
// Filename: AccountIdentifierMapper.cs
//
// Description: Mapping extensions for AccountIdentifier model
// Author(s):
// [email protected] ([email protected])
//
// History:
// 16 04 2024 Saurav Maiti Created, Harcourt street, Dublin, Ireland.
//
// License:
// MIT.
// -----------------------------------------------------------------------------

using NoFrixion.MoneyMoov.Models;

namespace NoFrixion.MoneyMoov;

public static class AccountIdentifierMapper
{
public static AccountIdentifier ToAccountIdentifier(this AccountIdentifierCreate accountIdentifierCreate, CurrencyTypeEnum currency)
{
return new AccountIdentifier
{
AccountNumber = accountIdentifierCreate.AccountNumber,
IBAN = accountIdentifierCreate.IBAN,
BIC = accountIdentifierCreate.BIC,
SortCode = accountIdentifierCreate.SortCode,
BitcoinAddress = accountIdentifierCreate.BitcoinAddress,
Currency = accountIdentifierCreate.Currency ?? currency
};
}

public static AccountIdentifierCreate ToAccountIdentifierCreate(this AccountIdentifier accountIdentifier)
{
return new AccountIdentifierCreate
{
AccountNumber = accountIdentifier.AccountNumber,
IBAN = accountIdentifier.IBAN,
BIC = accountIdentifier.BIC,
SortCode = accountIdentifier.SortCode,
BitcoinAddress = accountIdentifier.BitcoinAddress,
Currency = accountIdentifier.Currency
};
}
}
44 changes: 44 additions & 0 deletions src/NoFrixion.MoneyMoov/Mapping/CounterpartyMappers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// -----------------------------------------------------------------------------
// Filename: CounterpartyMapper.cs
//
// Description: Mapping extensions for Counterparty model
// Author(s):
// [email protected] ([email protected])
//
// History:
// 16 04 2024 Saurav Maiti Created, Harcourt street, Dublin, Ireland.
//
// License:
// MIT.
// -----------------------------------------------------------------------------

using NoFrixion.MoneyMoov.Models;

namespace NoFrixion.MoneyMoov;

public static class CounterpartyMapper
{
public static Counterparty ToCounterparty(this CounterpartyCreate counterpartyCreate, CurrencyTypeEnum currency)
{
return new Counterparty
{
AccountID = counterpartyCreate.AccountID,
Name = counterpartyCreate.Name,
EmailAddress = counterpartyCreate.EmailAddress,
PhoneNumber = counterpartyCreate.PhoneNumber,
Identifier = counterpartyCreate.Identifier?.ToAccountIdentifier(currency)
};
}

public static CounterpartyCreate ToCounterpartyCreate(this Counterparty counterparty)
{
return new CounterpartyCreate
{
AccountID = counterparty.AccountID,
Name = counterparty.Name,
EmailAddress = counterparty.EmailAddress,
PhoneNumber = counterparty.PhoneNumber,
Identifier = counterparty.Identifier?.ToAccountIdentifierCreate()
};
}
}
79 changes: 72 additions & 7 deletions src/NoFrixion.MoneyMoov/Models/Account/AccountIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
// MIT.
// -----------------------------------------------------------------------------

using System.ComponentModel.DataAnnotations;

namespace NoFrixion.MoneyMoov.Models;

#nullable disable

public class AccountIdentifier
public class AccountIdentifier: IValidatableObject
{
/// <summary>
/// The type of the account identifier.
Expand All @@ -27,7 +29,7 @@ public AccountIdentifierType Type
{
get
{
if(Currency == CurrencyTypeEnum.GBP.ToString())
if(Currency == CurrencyTypeEnum.GBP)
{
// UK Faster Payments can support both SCAN and IBAN identifiers. Default to SCAN.
if (!string.IsNullOrEmpty(SortCode) && !string.IsNullOrEmpty(AccountNumber))
Expand Down Expand Up @@ -63,7 +65,7 @@ public AccountIdentifierType Type
/// <summary>
/// The currency for the account.
/// </summary>
public string Currency { get; set; }
public required CurrencyTypeEnum Currency { get; set; }

/// <summary>
/// The Bank Identifier Code for an IBAN.
Expand Down Expand Up @@ -171,7 +173,7 @@ public string BitcoinAddress
/// </summary>
public string Summary =>
Type == AccountIdentifierType.IBAN ? Type.ToString() + ": " + IBAN :
Type == AccountIdentifierType.SCAN ? Type.ToString() + ": " + SortCode + " / " + AccountNumber :
Type == AccountIdentifierType.SCAN ? Type.ToString() + ": " + DisplayScanSummary :
Type == AccountIdentifierType.BTC ? Type.ToString() + ": " + BitcoinAddress :
"No identifier.";

Expand All @@ -180,15 +182,20 @@ public string BitcoinAddress
/// </summary>
public string DisplaySummary =>
Type == AccountIdentifierType.IBAN ? IBAN :
Type == AccountIdentifierType.SCAN ? SortCode + " / " + AccountNumber :
Type == AccountIdentifierType.SCAN ? DisplayScanSummary :
Type == AccountIdentifierType.BTC ? BitcoinAddress :
"No identifier.";

public string DisplayScanSummary =>
!string.IsNullOrEmpty(SortCode) && !string.IsNullOrEmpty(AccountNumber) && SortCode.Length == 6
? $"{SortCode[..2]}-{SortCode.Substring(2, 2)}-{SortCode.Substring(4, 2)} {AccountNumber}"
: "No identifier.";

public virtual Dictionary<string, string> ToDictionary(string keyPrefix)
{
return new Dictionary<string, string>
{
{ keyPrefix + nameof(Currency), Currency ?? string.Empty},
{ keyPrefix + nameof(Currency), Currency.ToString()},
{ keyPrefix + nameof(BIC), BIC ?? string.Empty},
{ keyPrefix + nameof(IBAN), IBAN ?? string.Empty},
{ keyPrefix + nameof(SortCode), SortCode ?? string.Empty},
Expand All @@ -200,7 +207,7 @@ public virtual Dictionary<string, string> ToDictionary(string keyPrefix)
public string GetApprovalHash()
{
string input =
(!string.IsNullOrEmpty(Currency) ? Currency.ToString() : string.Empty) +
Currency +
(!string.IsNullOrEmpty(BIC) ? BIC : string.Empty) +
(!string.IsNullOrEmpty(IBAN) ? IBAN : string.Empty) +
(!string.IsNullOrEmpty(SortCode) ? SortCode : string.Empty) +
Expand All @@ -213,4 +220,62 @@ public override string ToString()
{
return $"Type: {Type}, Currency: {Currency}, BIC: {BIC}, IBAN: {IBAN}, SortCode: {SortCode}, AccountNumber: {AccountNumber}, Bitcoin Address: {BitcoinAddress}, Summary: {Summary}";
}

public NoFrixionProblem Validate()
{
var validationResults = new List<ValidationResult>();
var validationContext = new ValidationContext(this, serviceProvider: null, items: null);
var isValid = Validator.TryValidateObject(this, validationContext, validationResults, true);

if (!isValid)
{
return new NoFrixionProblem($"The {nameof(AccountIdentifier)} had one or more validation errors.", validationResults);
}

return NoFrixionProblem.Empty;
}

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
switch (Currency)
{
case CurrencyTypeEnum.GBP:
{
if (string.IsNullOrEmpty(SortCode) || string.IsNullOrEmpty(AccountNumber))
{
yield return new ValidationResult(
"Sort code and account number are required for GBP account identifier.",
new[] { nameof(SortCode), nameof(AccountNumber) });
}

break;
}
case CurrencyTypeEnum.EUR:
{
if (string.IsNullOrEmpty(IBAN))
{
yield return new ValidationResult("IBAN is required for EUR account identifier.",
new[] { nameof(IBAN) });
}

break;
}
case CurrencyTypeEnum.BTC:
{
if (string.IsNullOrEmpty(BitcoinAddress))
{
yield return new ValidationResult("Bitcoin address is required for BTC account identifier.",
new[] { nameof(BitcoinAddress) });
}

break;
}
default:
{
yield return new ValidationResult("Currency is required for account identifier.",
new[] { nameof(Currency) });
break;
}
}
}
}
146 changes: 146 additions & 0 deletions src/NoFrixion.MoneyMoov/Models/Account/AccountIdentifierCreate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// -----------------------------------------------------------------------------
// Filename: AccountIdentifierCreate.cs
//
// Description: Account identifier Create model
// Author(s):
// [email protected] ([email protected])
//
// History:
// 16 04 2024 Saurav Maiti Created, Harcourt street, Dublin, Ireland.
//
// License:
// MIT.
// -----------------------------------------------------------------------------

namespace NoFrixion.MoneyMoov.Models;

#nullable disable

public class AccountIdentifierCreate
{

/// <summary>
/// The currency for the account.
/// </summary>
public CurrencyTypeEnum? Currency { get; set; }

/// <summary>
/// The Bank Identifier Code for an IBAN.
/// </summary>
private string _bic;
public string BIC
{
get => _bic;
set
{
if (!string.IsNullOrEmpty(value))
{
_bic = value.Trim().Replace(" ", string.Empty);
}
else
{
_bic = value;
}
}
}

/// <summary>
/// The International Bank Account Number for the identifier. Only applicable
/// for IBAN identifiers.
/// </summary>
private string _iban;
public string IBAN
{
get => _iban;
set
{
if (!string.IsNullOrEmpty(value))
{
_iban = value.Trim().Replace(" ", string.Empty);
}
else
{
_iban = value;
}
}
}

/// <summary>
/// The account Sort Code. Only applicable for SCAN identifiers.
/// </summary>
private string _sortCode;
public string SortCode
{
get => _sortCode;
set
{
if (!string.IsNullOrEmpty(value))
{
_sortCode = value.Trim().Replace(" ", string.Empty);
}
else
{
_sortCode = value;
}
}
}

/// <summary>
/// Bank account number. Only applicable for SCAN identifiers.
/// </summary>
private string _accountNumber;
public string AccountNumber
{
get => _accountNumber;
set
{
if (!string.IsNullOrEmpty(value))
{
_accountNumber = value.Trim().Replace(" ", string.Empty);
}
else
{
_accountNumber = value;
}
}
}

/// <summary>
/// Bitcoin address destination.
/// </summary>
private string _bitcoinAddress;
public string BitcoinAddress
{
get => _bitcoinAddress;
set
{
if (!string.IsNullOrEmpty(value))
{
_bitcoinAddress = value.Trim();
}
else
{
_bitcoinAddress = value;
}
}
}

public virtual Dictionary<string, string> ToDictionary(string keyPrefix)
{
return new Dictionary<string, string>
{
{ keyPrefix + nameof(Currency), Currency.ToString()},
{ keyPrefix + nameof(BIC), BIC ?? string.Empty},
{ keyPrefix + nameof(IBAN), IBAN ?? string.Empty},
{ keyPrefix + nameof(SortCode), SortCode ?? string.Empty},
{ keyPrefix + nameof(AccountNumber), AccountNumber ?? string.Empty},
{ keyPrefix + nameof(BitcoinAddress), BitcoinAddress ?? string.Empty}
};
}

/// <summary>
/// Summary of the account identifier's most important properties.
/// </summary>
public string Summary =>
$"IBAN: {IBAN}, BIC: {BIC}, SortCode: {SortCode}, AccountNumber: {AccountNumber}, BitcoinAddress: {BitcoinAddress}";
}
Loading

0 comments on commit ca0f2b0

Please sign in to comment.