Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
using System;
using System;
using CSharpFunctionalExtensions;

namespace AppifySheets.Immutable.BankIntegrationTypes;

public class BankAccountWithCurrencyV(BankAccountV bankAccountNumber, CurrencyV currencyV)
{
// public static Result<BankAccountWithCurrencyV> Create(BankAccountV bankAccountNumber, CurrencyV currencyV) => Result.Try(() => new BankAccountWithCurrencyV(bankAccountNumber, currencyV));
/// <summary>
/// Type aliases for backward compatibility
/// These are kept for backward compatibility only
/// New code should use Iban, Currency, and BankAccount instead
/// </summary>

public BankAccountV BankAccountNumber { get; } = bankAccountNumber ?? throw new ArgumentNullException(nameof(bankAccountNumber));
public CurrencyV CurrencyV { get; } = currencyV ?? throw new ArgumentNullException(nameof(currencyV));
// Keep original classes but mark as obsolete
[Obsolete("Use Iban instead")]
public record BankAccountV
{
public BankAccountV(string accountNumber)
{
const string pattern2Match = @"(^[a-zA-Z]{2}\d{2}[a-zA-Z]{2}\d{16})(\w{3})?$";
var iban = System.Text.RegularExpressions.Regex.Match(accountNumber, pattern2Match).Groups[1].Value;
AccountNumber = accountNumber;
}

public override string ToString() => $"{BankAccountNumber}{CurrencyV}";
public string AccountNumber { get; }
public override string ToString() => AccountNumber;
}

[Obsolete("Use Currency instead")]
public record CurrencyV
{
public static readonly CurrencyV GEL = new CurrencyV("GEL");
Expand All @@ -27,4 +40,16 @@ public CurrencyV(string code)
}

public override string ToString() => Code;
}

[Obsolete("Use BankAccount instead")]
public class BankAccountWithCurrencyV(BankAccountV bankAccountNumber, CurrencyV currencyV)
{
public BankAccountV BankAccountNumber { get; } = bankAccountNumber ?? throw new ArgumentNullException(nameof(bankAccountNumber));
public CurrencyV CurrencyV { get; } = currencyV ?? throw new ArgumentNullException(nameof(currencyV));

public static Result<BankAccountWithCurrencyV> Create(BankAccountV bankAccountNumber, CurrencyV currencyV)
=> Result.Try(() => new BankAccountWithCurrencyV(bankAccountNumber, currencyV));

public override string ToString() => $"{BankAccountNumber}{CurrencyV}";
}
54 changes: 54 additions & 0 deletions AppifySheets.Immutable.BankIntegrationTypes/BankAccount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using CSharpFunctionalExtensions;

namespace AppifySheets.Immutable.BankIntegrationTypes;

/// <summary>
/// Represents a bank account with IBAN and currency
/// </summary>
public record BankAccount
{
BankAccount(Iban iban, Currency currency)
{
Iban = iban;
Currency = currency;
}

public Iban Iban { get; }
public Currency Currency { get; }

/// <summary>
/// Creates a bank account with validation
/// </summary>
public static Result<BankAccount> Create(string iban, string currencyCode)
{
var ibanResult = Iban.Create(iban);
if (ibanResult.IsFailure)
return Result.Failure<BankAccount>($"Invalid IBAN: {ibanResult.Error}");

var currencyResult = Currency.Create(currencyCode);
if (currencyResult.IsFailure)
return Result.Failure<BankAccount>($"Invalid currency: {currencyResult.Error}");

return Result.Success(new BankAccount(ibanResult.Value, currencyResult.Value));
}

/// <summary>
/// Creates a bank account with pre-validated components
/// </summary>
public static Result<BankAccount> Create(Iban iban, Currency currency)
{
if (iban == null)
return Result.Failure<BankAccount>("IBAN cannot be null");
if (currency == null)
return Result.Failure<BankAccount>("Currency cannot be null");

return Result.Success(new BankAccount(iban, currency));
}


public override string ToString() => $"{Iban}{Currency}";

// For backward compatibility - maps to old property names
public Iban BankAccountNumber => Iban;
public Currency CurrencyV => Currency;
}
23 changes: 0 additions & 23 deletions AppifySheets.Immutable.BankIntegrationTypes/BankAccountV.cs

This file was deleted.

69 changes: 69 additions & 0 deletions AppifySheets.Immutable.BankIntegrationTypes/Currency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Linq;
using CSharpFunctionalExtensions;

namespace AppifySheets.Immutable.BankIntegrationTypes;

/// <summary>
/// Represents a currency with ISO 4217 3-letter code
/// </summary>
public record Currency
{
// Common currencies as static instances
// ReSharper disable once InconsistentNaming
public static readonly Currency GEL = new("GEL");
// ReSharper disable once InconsistentNaming
public static readonly Currency USD = new("USD");
// ReSharper disable once InconsistentNaming
public static readonly Currency EUR = new("EUR");
// ReSharper disable once InconsistentNaming
public static readonly Currency GBP = new("GBP");
// ReSharper disable once InconsistentNaming
public static readonly Currency CHF = new("CHF");
// ReSharper disable once InconsistentNaming
public static readonly Currency JPY = new("JPY");
// ReSharper disable once InconsistentNaming
public static readonly Currency CNY = new("CNY");

Currency(string code)
{
Code = code;
}

public string Code { get; }

/// <summary>
/// Creates a currency instance with validation
/// </summary>
public static Result<Currency> Create(string code)
{
if (string.IsNullOrWhiteSpace(code))
return Result.Failure<Currency>("Currency code cannot be empty");

var normalized = code.Trim().ToUpperInvariant();

if (normalized.Length != 3)
return Result.Failure<Currency>("Currency code must be exactly 3 characters (ISO 4217)");

if (!normalized.All(char.IsLetter))
return Result.Failure<Currency>("Currency code must contain only letters");

return Result.Success(new Currency(normalized));
}

/// <summary>
/// Parses a currency code, throwing exception if invalid
/// </summary>
public static Currency Parse(string code)
{
var result = Create(code);
if (result.IsFailure)
throw new ArgumentException(result.Error, nameof(code));
return result.Value;
}

public override string ToString() => Code;

// Implicit conversion to string for convenience
public static implicit operator string(Currency currency) => currency.Code;
}
48 changes: 48 additions & 0 deletions AppifySheets.Immutable.BankIntegrationTypes/Iban.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Text.RegularExpressions;
using CSharpFunctionalExtensions;

namespace AppifySheets.Immutable.BankIntegrationTypes;

/// <summary>
/// Represents an International Bank Account Number (IBAN)
/// </summary>
public record Iban
{
const string IbanPattern = @"^[A-Z]{2}\d{2}[A-Z0-9]+$";
const int MinIbanLength = 15;
const int MaxIbanLength = 34;

Iban(string value)
{
Value = value;
}

public string Value { get; }

/// <summary>
/// Creates an IBAN instance with validation
/// </summary>
public static Result<Iban> Create(string value)
{
if (string.IsNullOrWhiteSpace(value))
return Result.Failure<Iban>("IBAN cannot be empty");

// Normalize: remove spaces and convert to uppercase
var normalized = value.Replace(" ", "").ToUpperInvariant();

if (normalized.Length is < MinIbanLength or > MaxIbanLength)
return Result.Failure<Iban>($"IBAN length must be between {MinIbanLength} and {MaxIbanLength} characters");

if (!Regex.IsMatch(normalized, IbanPattern))
return Result.Failure<Iban>("Invalid IBAN format");

return Result.Success(new Iban(normalized));
}


public override string ToString() => Value;

// Implicit conversion to string for convenience
public static implicit operator string(Iban iban) => iban.Value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<ProjectReference Include="..\AppifySheets.TBC.IntegrationService.Client\AppifySheets.TBC.IntegrationService.Client.csproj" />
<ProjectReference Include="..\AppifySheets.Immutable.BankIntegrationTypes\AppifySheets.Immutable.BankIntegrationTypes.csproj" />
</ItemGroup>

</Project>
32 changes: 16 additions & 16 deletions AppifySheets.TBC.IntegrationService.Client.DemoConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

var checkStatus2 = await tbcSoapCaller.GetDeserialized(new GetPaymentOrderStatusRequestIo(1632027071));

var ownAccountGEL = new BankAccountWithCurrencyV(new BankAccountV("GE31TB7467936080100003"), CurrencyV.GEL);
var ownAccountUSD = new BankAccountWithCurrencyV(new BankAccountV("GE47TB7467936170100001"), CurrencyV.USD);
var ownAccountGEL = BankAccount.Create("GE31TB7467936080100003", "GEL").Value;
var ownAccountUSD = BankAccount.Create("GE47TB7467936170100001", "USD").Value;

var transferTypeRecordSpecific = new TransferTypeRecordSpecific
var bankTransferCommonDetails = new BankTransferCommonDetails
{
DocumentNumber = 123,
Amount = 0.01m,
Expand All @@ -40,52 +40,52 @@
var withinBankGel2 = await tbcSoapCaller.GetDeserialized(new ImportSinglePaymentOrdersRequestIo(
new TransferWithinBankPaymentOrderIo
{
RecipientAccountWithCurrency = new BankAccountWithCurrencyV(new BankAccountV("GE86TB1144836120100002"), CurrencyV.GEL),
TransferTypeRecordSpecific = transferTypeRecordSpecific
RecipientAccountWithCurrency = BankAccount.Create("GE86TB1144836120100002", "GEL").Value,
BankTransferCommonDetails = bankTransferCommonDetails
}));

var withinBankCurrency = await tbcSoapCaller.GetDeserialized(new ImportSinglePaymentOrdersRequestIo(
new TransferWithinBankPaymentOrderIo
{
TransferTypeRecordSpecific = transferTypeRecordSpecific with
BankTransferCommonDetails = bankTransferCommonDetails with
{
SenderAccountWithCurrency = ownAccountUSD
},
RecipientAccountWithCurrency = new BankAccountWithCurrencyV(new BankAccountV("GE86TB1144836120100002"), CurrencyV.USD),
RecipientAccountWithCurrency = BankAccount.Create("GE86TB1144836120100002", "USD").Value,
}));

var toAnotherBankGel = await tbcSoapCaller.GetDeserialized(
new ImportSinglePaymentOrdersRequestIo(
new TransferToOtherBankNationalCurrencyPaymentOrderIo(
new BankAccountWithCurrencyV(new BankAccountV("GE33BG0000000263255500"), CurrencyV.GEL), "123123123")
BankAccount.Create("GE33BG0000000263255500", "GEL").Value, "123123123")
{
TransferTypeRecordSpecific = transferTypeRecordSpecific
BankTransferCommonDetails = bankTransferCommonDetails
}));

var toAnotherBankCurrencyGood = await tbcSoapCaller.GetDeserialized(
new ImportSinglePaymentOrdersRequestIo(
new TransferToOtherBankForeignCurrencyPaymentOrderIo("test", "test", "SHA", "TEST",
new BankAccountWithCurrencyV(new BankAccountV("GE33BG0000000263255500"), CurrencyV.USD))
BankAccount.Create("GE33BG0000000263255500", "USD").Value)
{
TransferTypeRecordSpecific = transferTypeRecordSpecific with { SenderAccountWithCurrency = ownAccountUSD }
BankTransferCommonDetails = bankTransferCommonDetails with { SenderAccountWithCurrency = ownAccountUSD }
}));

var toAnotherBankCurrencyBad = await tbcSoapCaller.GetDeserialized(
new ImportSinglePaymentOrdersRequestIo(
new TransferToOtherBankForeignCurrencyPaymentOrderIo("test", "test", "SHA", "TEST",
new BankAccountWithCurrencyV(new BankAccountV("GE33BG0000000263255500"), CurrencyV.USD))
BankAccount.Create("GE33BG0000000263255500", "USD").Value)
{
TransferTypeRecordSpecific = transferTypeRecordSpecific with { SenderAccountWithCurrency = ownAccountUSD }
BankTransferCommonDetails = bankTransferCommonDetails with { SenderAccountWithCurrency = ownAccountUSD }
}));

var toChina = await tbcSoapCaller.GetDeserialized(
new ImportSinglePaymentOrdersRequestIo(
new TransferToOtherBankForeignCurrencyPaymentOrderIo( "China",
// "ICBKCNBJSZN", "INDUSTRIAL AND COMMERCIAL BANK OF CHINA SHENZHEN BRANCH", "SHA", "Invoice(LZSK202311028)",
"ICBKCNBJSZN", "INDUSTRIAL AND COMMERCIAL BANK OF CHINA SHENZHEN BRANCH", "SHA",
new BankAccountWithCurrencyV(new BankAccountV("4000109819100186641"), CurrencyV.USD))
BankAccount.Create("4000109819100186641", "USD").Value)
{
TransferTypeRecordSpecific = transferTypeRecordSpecific with
BankTransferCommonDetails = bankTransferCommonDetails with
{
SenderAccountWithCurrency = ownAccountUSD,
BeneficiaryName = "Shenzhen Shinekoo Supply Chain Co.,Ltd"
Expand All @@ -95,6 +95,6 @@
var toTreasury = await tbcSoapCaller.GetDeserialized(
new ImportSinglePaymentOrdersRequestIo(
new TreasuryTransferPaymentOrderIo(101001000)
{ TransferTypeRecordSpecific = transferTypeRecordSpecific }));
{ BankTransferCommonDetails = bankTransferCommonDetails }));

Debugger.Break();
Loading
Loading