Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a new account identifier type of BIC #533

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/NoFrixion.MoneyMoov/Enums/AccountIdentifierType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ public enum AccountIdentifierType
/// <summary>
/// Bitcoin address.
/// </summary>
BTC = 4
BTC = 4,

/// <summary>
/// Bank Identifier Code. Used for international payments. In addition to the BIC an account number and country code are required.
/// </summary>
BIC = 5
}
Empty file modified src/NoFrixion.MoneyMoov/Mapping/CounterpartyMappers.cs
100644 → 100755
Empty file.
53 changes: 35 additions & 18 deletions src/NoFrixion.MoneyMoov/Models/Account/AccountIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// History:
// 21 10 2021 Donal O'Connor Created, Carmichael House, Dublin, Ireland.
// 19 09 2023 Aaron Clauson Added Bitcoin support.
// 20 03 2025 Aaron Clauson Added support for BIC identifier type.
//
// License:
// MIT.
Expand All @@ -30,14 +31,18 @@ public AccountIdentifierType Type
{
get
{
if(!string.IsNullOrWhiteSpace(IBAN))
if (!string.IsNullOrWhiteSpace(IBAN))
{
return AccountIdentifierType.IBAN;
}
else if(!string.IsNullOrWhiteSpace(SortCode) && !string.IsNullOrWhiteSpace(AccountNumber))
else if (!string.IsNullOrWhiteSpace(SortCode))
{
return AccountIdentifierType.SCAN;
}
else if (!string.IsNullOrWhiteSpace(BIC))
{
return AccountIdentifierType.BIC;
}

return AccountIdentifierType.Unknown;
}
Expand Down Expand Up @@ -157,6 +162,7 @@ public string BitcoinAddress
public string Summary =>
Type == AccountIdentifierType.IBAN ? Type.ToString() + ": " + IBAN :
Type == AccountIdentifierType.SCAN ? Type.ToString() + ": " + DisplayScanSummary :
Type == AccountIdentifierType.BIC ? Type.ToString() + ": " + DisplayBicSummary :
"No identifier.";

/// <summary>
Expand All @@ -165,13 +171,16 @@ public string BitcoinAddress
public string DisplaySummary =>
Type == AccountIdentifierType.IBAN ? IBAN :
Type == AccountIdentifierType.SCAN ? DisplayScanSummary :
Type == AccountIdentifierType.BIC ? DisplayBicSummary :
"No identifier.";

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

public string DisplayBicSummary => $"{BIC} {AccountNumber}";

public bool IsSameDestination(AccountIdentifier other)
{
if (other == null)
Expand All @@ -188,6 +197,7 @@ public bool IsSameDestination(AccountIdentifier other)
{
AccountIdentifierType.IBAN => IBAN == other.IBAN,
AccountIdentifierType.SCAN => SortCode == other.SortCode && AccountNumber == other.AccountNumber,
AccountIdentifierType.BIC => BIC == other.BIC && AccountNumber == other.AccountNumber,
_ => false
};
}
Expand All @@ -200,7 +210,8 @@ public virtual Dictionary<string, string> ToDictionary(string keyPrefix)
{ 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(AccountNumber), AccountNumber ?? string.Empty},
{ keyPrefix + nameof(BIC), BIC ?? string.Empty},
};
}

Expand Down Expand Up @@ -236,39 +247,45 @@ public NoFrixionProblem Validate()

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
switch (Currency)
switch (Type)
{
// GBP & USD support both IBAN and SCAN.
case CurrencyTypeEnum.GBP:
case CurrencyTypeEnum.USD:
case AccountIdentifierType.IBAN:
if (string.IsNullOrWhiteSpace(IBAN))
{
if (string.IsNullOrWhiteSpace(IBAN) &&
(string.IsNullOrWhiteSpace(SortCode) || string.IsNullOrWhiteSpace(AccountNumber)))
yield return new ValidationResult(
$"The IBAN value is required for a {AccountIdentifierType.IBAN} identifier.",
[nameof(IBAN)]);
}
break;

case AccountIdentifierType.SCAN:
{
if (string.IsNullOrWhiteSpace(SortCode) || string.IsNullOrWhiteSpace(AccountNumber))
{
yield return new ValidationResult(
$"Either the IBAN or Sort code and account number are required for a {Currency} account identifier.",
[nameof(IBAN), nameof(SortCode), nameof(AccountNumber)]);
$"The sort code and account number are required for a {AccountIdentifierType.SCAN} identifier.",
[nameof(SortCode), nameof(AccountNumber)]);
}

break;
}

// EUR only supports IBAN.
case CurrencyTypeEnum.EUR:
case AccountIdentifierType.BIC:
{
if (string.IsNullOrEmpty(IBAN))
if (string.IsNullOrWhiteSpace(BIC) || string.IsNullOrWhiteSpace(AccountNumber))
{
yield return new ValidationResult("IBAN is required for EUR account identifier.",
[nameof(IBAN)]);
yield return new ValidationResult(
$"The BIC and account number are required for a {AccountIdentifierType.BIC} identifier.",
[nameof(BIC), nameof(AccountNumber)]);
}

break;
}

default:
{
yield return new ValidationResult($"Currency {Currency} was not recognised when validating an account identifier.",
[nameof(Currency)]);
yield return new ValidationResult($"Identifier {Type} was not recognised when validating an account identifier.",
[nameof(Type)]);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public string SortCode
}

/// <summary>
/// Bank account number. Only applicable for SCAN identifiers.
/// Bank account number. Only applicable for SCAN and BIC identifiers.
/// </summary>
private string _accountNumber;
public string AccountNumber
Expand Down
11 changes: 10 additions & 1 deletion src/NoFrixion.MoneyMoov/Models/Account/CounterpartyCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ public class CounterpartyCreate
/// </summary>
public string? EmailAddress { get; set; }

/// An email address for the counterparty. Optional to set and depending on the payment
/// <summary>
/// A phone number for the counterparty. Optional to set and depending on the payment
/// network does not always get set for pay ins.
/// </summary>
public string? PhoneNumber { get; set; }

/// <summary>
/// A country code for the counterparty. Optional to set and depending on the payment
/// network does not always get set for pay ins
/// </summary>
public string? CountryCode { get; set; }

/// <summary>
/// The counterparty's account identifier. This identifier is what is used to send the payment
/// to them, or for a pay in is the source of the payment.
Expand All @@ -61,6 +69,7 @@ public virtual Dictionary<string, string> ToDictionary(string keyPrefix)
{ keyPrefix + nameof(Name), Name ?? string.Empty },
{ keyPrefix + nameof(EmailAddress), EmailAddress ?? string.Empty },
{ keyPrefix + nameof(PhoneNumber), PhoneNumber ?? string.Empty },
{ keyPrefix + nameof(CountryCode), CountryCode ?? string.Empty },
};

if(Identifier != null)
Expand Down
9 changes: 9 additions & 0 deletions src/NoFrixion.MoneyMoov/Models/Payouts/Payout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,22 @@ public Counterparty? DestinationAccount
/// For Bitcoin payouts, when this flag is set the network fee will be deducted from the send amount.
/// THis is particularly useful for sweeps where it can be difficult to calculate the exact fee required.
/// </summary>
[Obsolete]
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public bool BitcoinSubtractFeeFromAmount { get; set; }

/// <summary>
/// The Bitcoin fee rate to apply in Satoshis per virtual byte.
/// </summary>
[Obsolete]
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public int BitcoinFeeSatsPerVbyte { get; set; }

[Obsolete]
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public string FormattedBitcoinFee => $"{BitcoinFeeSatsPerVbyte} sats/vbyte" +
(BitcoinSubtractFeeFromAmount ? " (fee will be subtracted from amount)" : "");

Expand Down
4 changes: 3 additions & 1 deletion src/NoFrixion.MoneyMoov/Models/Payouts/PayoutCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class PayoutCreate
public CurrencyTypeEnum Currency { get; set; }

[Required(ErrorMessage = "Amount is required.")]
[Range(0.00001, double.MaxValue,ErrorMessage = "Minimum value of 0.00001 is required for Amount")]
[Range(0.00001, double.MaxValue,ErrorMessage = "Minimum value of 0.01 is required for Amount")]
public decimal Amount { get; set; }

/// <summary>
Expand Down Expand Up @@ -151,11 +151,13 @@ public CounterpartyCreate? DestinationAccount
/// <summary>
/// For Bitcoin payouts, when this flag is set the network fee will be deducted from the send amount. This is particularly useful for sweeps where it can be difficult to calculate the exact fee required.
/// </summary>
[Obsolete]
public bool BitcoinSubtractFeeFromAmount { get; set; }

/// <summary>
/// The Bitcoin fee rate to apply in Satoshis per virtual byte.
/// </summary>
[Obsolete]
public int BitcoinFeeSatsPerVbyte { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NoFrixion.MoneyMoov/Models/Payouts/PayoutsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public static IEnumerable<ValidationResult> Validate(Payout payout, ValidationCo
}

if (payout.Destination != null &&
!(payout.Type == AccountIdentifierType.IBAN || payout.Type == AccountIdentifierType.SCAN))
!(payout.Type == AccountIdentifierType.IBAN || payout.Type == AccountIdentifierType.SCAN || payout.Type == AccountIdentifierType.BIC))
{
yield return new ValidationResult("Only destination types of IBAN and SCAN are supported.", [ nameof(payout.Type) ]);
}
Expand Down
12 changes: 11 additions & 1 deletion src/NoFrixion.MoneyMoov/Models/Transaction/Counterparty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ public class Counterparty
/// </summary>
public string? EmailAddress { get; set; }

/// An email address for the counterparty. Optional to set and depending on the payment
/// <summary>
/// A phone number for the counterparty. Optional to set and depending on the payment
/// network does not always get set for pay ins.
/// </summary>
public string? PhoneNumber { get; set; }

/// <summary>
/// A country code for the counterparty. Optional to set and depending on the payment
/// network does not always get set for pay ins
/// </summary>
public string? CountryCode { get; set; }

/// <summary>
/// The counterparty's account identifier. This identifier is what is used to send the payment
/// to them, or for a pay in is the source of the payment.
Expand Down Expand Up @@ -113,6 +121,7 @@ public virtual Dictionary<string, string> ToDictionary(string keyPrefix)
{ keyPrefix + nameof(Name), Name ?? string.Empty },
{ keyPrefix + nameof(EmailAddress), EmailAddress ?? string.Empty },
{ keyPrefix + nameof(PhoneNumber), PhoneNumber ?? string.Empty },
{ keyPrefix + nameof(CountryCode), CountryCode ?? string.Empty },
};

if(Identifier != null)
Expand All @@ -135,6 +144,7 @@ public virtual string GetApprovalHash()
(!string.IsNullOrEmpty(Name) ? Name : string.Empty) +
(!string.IsNullOrEmpty(EmailAddress) ? EmailAddress : string.Empty) +
(!string.IsNullOrEmpty(PhoneNumber) ? PhoneNumber : string.Empty) +
(!string.IsNullOrEmpty(CountryCode) ? CountryCode : string.Empty) +
(Identifier != null ? Identifier.GetApprovalHash() : string.Empty);
return HashHelper.CreateHash(input);
}
Expand Down