Skip to content

Commit

Permalink
Merge branch 'release/moov-1.1.271'
Browse files Browse the repository at this point in the history
  • Loading branch information
sipsorcery committed May 27, 2024
2 parents 0f9f05a + 911967c commit c881264
Show file tree
Hide file tree
Showing 35 changed files with 700 additions and 117 deletions.
5 changes: 5 additions & 0 deletions src/NoFrixion.MoneyMoov/ApiClients/MoneyMoovClient.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public interface IMoneyMoovClient

IBeneficiaryClient BeneficiaryClient();

IStatementClient StatementClient();

Uri? GetBaseUrl();
}

Expand Down Expand Up @@ -102,6 +104,9 @@ public IReportClient ReportClient()
public IRuleClient RuleClient()
=> new RuleClient(new RestApiClient(_httpClientFactory, MONEYMOOV_HTTP_CLIENT_NAME));

public IStatementClient StatementClient()
=> new StatementClient(new RestApiClient(_httpClientFactory, MONEYMOOV_HTTP_CLIENT_NAME));

public IUserClient UserClient()
=> new UserClient(new RestApiClient(_httpClientFactory, MONEYMOOV_HTTP_CLIENT_NAME));

Expand Down
84 changes: 84 additions & 0 deletions src/NoFrixion.MoneyMoov/ApiClients/StatementClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//-----------------------------------------------------------------------------
// Filename: StatementClient.cs
//
// Description: An API client to call the MoneyMoov Statements API end point.
//
// Author(s):
// Aaron Clauson ([email protected])
//
// History:
// 25 May 2024 Aaron Clauson Created, Harcourt St, Dublin, Ireland.
//
// License:
// MIT.
//-----------------------------------------------------------------------------

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using NoFrixion.MoneyMoov.Models;
using System.Net;
using System.Net.Http.Headers;

namespace NoFrixion.MoneyMoov;

public interface IStatementClient
{
Task<RestApiFileResponse> GetStatementAsync(string accessToken, Guid statementID);
}

public class StatementClient : IStatementClient
{
private readonly ILogger _logger;
private readonly IRestApiClient _apiClient;

public StatementClient(IRestApiClient apiClient)
{
_apiClient = apiClient;
_logger = NullLogger.Instance;
}

public StatementClient(IRestApiClient apiClient, ILogger<StatementClient> logger)
{
_apiClient = apiClient;
_logger = logger;
}

/// <summary>
/// Calls the MoneyMoov statements endpoint to get a statement file.
/// </summary>
/// <param name="accessToken">A User or Merchant scoped JWT access token.</param>
/// <param name="statementID">The ID of the report to retrieve the result for.</param>
/// <returns>If successful, the statement result.</returns>
public async Task<RestApiFileResponse> GetStatementAsync(string accessToken, Guid statementID)
{
var url = MoneyMoovUrlBuilder.StatementsApi.StatementsUrl(_apiClient.GetBaseUri().ToString(), statementID);
var prob = _apiClient.CheckAccessToken(accessToken, nameof(GetStatementAsync));

if (!prob.IsEmpty)
{
return new RestApiFileResponse(HttpStatusCode.PreconditionFailed, new Uri(url), prob);
}

using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = await httpClient.GetAsync(url);

if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsByteArrayAsync();
var contentType = response.Content.Headers.ContentType?.ToString() ?? "application/pdf";
var fileName = response.Content.Headers.ContentDisposition?.FileName?.Trim('\"') ?? "downloaded_file";

return new RestApiFileResponse(HttpStatusCode.OK, new Uri(url), response.Headers, content, contentType, fileName);
}
else
{
return new RestApiFileResponse(
response.StatusCode,
new Uri(url),
new NoFrixionProblem(response.ReasonPhrase ?? "File download failed.", (int)response.StatusCode));
}
}
}
}
6 changes: 6 additions & 0 deletions src/NoFrixion.MoneyMoov/Claims/IdentityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,16 @@ public static string WhoAmI(this ClaimsPrincipal claimsPrincipal)

public static string WhoAmI(this ClaimsIdentity claimsIdentity)
{
if(claimsIdentity == null)
{
return "Empty claims identity";
}

if (claimsIdentity.IsComplianceOfficer())
{
return "Compliance " + claimsIdentity.GetEmailAddress();
}

if (claimsIdentity.IsOperationsOfficer())
{
return "Operations " + claimsIdentity.GetEmailAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace NoFrixion.MoneyMoov;
[Flags]
public enum MerchantTokenPermissionsEnum
{
/// <summary>
/// Permission to deny all actions. This won't be assigned in practice but when
/// checking whether a permission is granted, this can be used to specify that merchant
/// tokens are not allowed to perform any actions.
/// </summary>
Deny = 0,

/// <summary>
/// Permission to create a payment request
/// </summary>
Expand Down Expand Up @@ -97,5 +104,5 @@ public enum MerchantTokenPermissionsEnum
/// <summary>
/// Permission to create and submit a payout from a trusted source.
/// </summary>
TrustedSubmitPayout = 32768
TrustedSubmitPayout = 32768,
}
14 changes: 12 additions & 2 deletions src/NoFrixion.MoneyMoov/Enums/ReportTypesEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ public enum ReportTypesEnum
SafeGuardingReconciliation = 3,

/// <summary>
/// A report for merchant account balances.
/// A report for the balance of all accounts for a merchant.
/// </summary>
MerchantAccountBalances = 4,
MerchantAccountsBalance = 4,

/// <summary>
/// A report for the transactions for all accounts for a merchant.
/// </summary>
MerchantAccountsTransaction = 5,

/// <summary>
/// Custom report to export transactions for VisionBlue.
/// </summary>
VisionBlueTransaction = 6
}
25 changes: 21 additions & 4 deletions src/NoFrixion.MoneyMoov/Enums/RuleEventTypesEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ namespace NoFrixion.MoneyMoov;
public enum RuleEventTypesEnum
{
None,

/// <summary>
/// The rule was created.
/// </summary>
Created,

/// <summary>
/// The rule status changed to approved.
/// </summary>
Approved,

/// <summary>
/// The rule was edited.
/// </summary>
Edited,

/// <summary>
/// The rule was disabled.
/// </summary>
Disabled,

/// <summary>
/// The rule was executed successfully.
Expand All @@ -33,8 +53,5 @@ public enum RuleEventTypesEnum
/// </summary>
ExecutionError,

/// <summary>
/// The rule status changed to approved.
/// </summary>
Approved,

}
23 changes: 23 additions & 0 deletions src/NoFrixion.MoneyMoov/Enums/StatementGenerationStatusEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// -----------------------------------------------------------------------------
// Filename: StatementGenerationStatusEnum.cs
//
// Description: Enum for the status of a transaction statement generation.
//
// Author(s):
// Axel Granillo ([email protected])
//
// History:
// 09 05 2024 Axel Granillo Created, Remote, Mexico City, Mexico.
//
// License:
// Proprietary NoFrixion.
// -----------------------------------------------------------------------------

namespace NoFrixion.MoneyMoov.Enums;

public enum StatementGenerationStatusEnum
{
Unknown,
Generating,
Ready
}
22 changes: 22 additions & 0 deletions src/NoFrixion.MoneyMoov/Enums/TransactionStatementFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -----------------------------------------------------------------------------
// Filename: TransactionStatementFormat.cs
//
// Description: Enum for the format of a transaction statement.
//
// Author(s):
// Axel Granillo ([email protected])
//
// History:
// 03 05 2024 Axel Granillo Created, Mexico City, Mexico.
//
// License:
// Proprietary NoFrixion.
// -----------------------------------------------------------------------------

namespace NoFrixion.MoneyMoov.Enums;

public enum TransactionStatementFormat
{
Pdf,
Csv
}
4 changes: 3 additions & 1 deletion src/NoFrixion.MoneyMoov/Mapping/CounterpartyMappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static Counterparty ToCounterparty(this CounterpartyCreate counterpartyCr
Name = counterpartyCreate.Name,
EmailAddress = counterpartyCreate.EmailAddress,
PhoneNumber = counterpartyCreate.PhoneNumber,
Identifier = counterpartyCreate.Identifier?.ToAccountIdentifier(currency)
BeneficiaryID = counterpartyCreate.BeneficiaryID,
Identifier = counterpartyCreate.Identifier?.ToAccountIdentifier(currency),
};
}

Expand All @@ -38,6 +39,7 @@ public static CounterpartyCreate ToCounterpartyCreate(this Counterparty counterp
Name = counterparty.Name,
EmailAddress = counterparty.EmailAddress,
PhoneNumber = counterparty.PhoneNumber,
BeneficiaryID = counterparty.BeneficiaryID,
Identifier = counterparty.Identifier?.ToAccountIdentifierCreate()
};
}
Expand Down
21 changes: 21 additions & 0 deletions src/NoFrixion.MoneyMoov/Models/Account/AccountIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ public string BitcoinAddress
? $"{SortCode[..2]}-{SortCode.Substring(2, 2)}-{SortCode.Substring(4, 2)} {AccountNumber}"
: "No identifier.";

public bool IsSameDestination(AccountIdentifier other)
{
if(other == null)
{
return false;
}

if (Type != other.Type)
{
return false;
}

return Type switch
{
AccountIdentifierType.IBAN => IBAN == other.IBAN,
AccountIdentifierType.SCAN => SortCode == other.SortCode && AccountNumber == other.AccountNumber,
AccountIdentifierType.BTC => BitcoinAddress == other.BitcoinAddress,
_ => false
};
}

public virtual Dictionary<string, string> ToDictionary(string keyPrefix)
{
return new Dictionary<string, string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace NoFrixion.MoneyMoov.Models;

public class AccountIdentifierCreate
{

/// <summary>
/// The currency for the account.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/NoFrixion.MoneyMoov/Models/Account/CounterpartyCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ namespace NoFrixion.MoneyMoov.Models;

public class CounterpartyCreate
{
/// <summary>
/// If set it indicates that the counterparty is an internal belonging to the
/// same merchant as the source account.
/// </summary>
public Guid? AccountID { get; set; }

/// <summary>
/// If set it indicates that the counterparty is a beneficiary of the merchant.
/// </summary>
public Guid? BeneficiaryID { get; set; }

/// <summary>
/// The name of the counterparty. For a person this should be their full name. For a
/// company this should be their registered or trading name.
Expand Down Expand Up @@ -48,6 +57,7 @@ public virtual Dictionary<string, string> ToDictionary(string keyPrefix)
var dict = new Dictionary<string, string>
{
{ keyPrefix + nameof(AccountID), AccountID != null ? AccountID.Value.ToString() : string.Empty},
{ keyPrefix + nameof(BeneficiaryID), BeneficiaryID != null ? BeneficiaryID.Value.ToString() : string.Empty},
{ keyPrefix + nameof(Name), Name ?? string.Empty },
{ keyPrefix + nameof(EmailAddress), EmailAddress ?? string.Empty },
{ keyPrefix + nameof(PhoneNumber), PhoneNumber ?? string.Empty },
Expand Down
22 changes: 22 additions & 0 deletions src/NoFrixion.MoneyMoov/Models/ApiPageResponseBase.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ public TransactionPageResponse(List<Transaction> content,
{ }
}

public class PaymentAccountPageResponse : ApiPageResponseBase<PaymentAccount>
{
public PaymentAccountPageResponse(List<PaymentAccount> content,
int pageNumber = 1,
int pageSize = 10,
int totalPages = default,
long totalSize = default)
: base(content, pageNumber, pageSize, totalPages, totalSize)
{ }
}

public class MerchantPageResponse : ApiPageResponseBase<Merchant>
{
public MerchantPageResponse(List<Merchant> content,
int pageNumber = 1,
int pageSize = 10,
int totalPages = default,
long totalSize = default)
: base(content, pageNumber, pageSize, totalPages, totalSize)
{ }
}

public abstract class ApiPageResponseBase<T> : PageResponse<T>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
{
yield return new ValidationResult($"{nameof(AddressLine1)} must be provided.", new string[] { nameof(AddressLine1) });
}

if (!string.IsNullOrEmpty(AddressCountryCode) && AddressCountryCode.Length != 2)
{
yield return new ValidationResult($"{nameof(AddressCountryCode)} must be 2 characters.", new string[] { nameof(AddressCountryCode) });
}
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/NoFrixion.MoneyMoov/Models/Payouts/Payout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ public string GetApprovalHash()
Currency +
Math.Round(Amount, 2).ToString() +
Destination.GetApprovalHash() +
//Status.ToString() +
Scheduled.GetValueOrDefault().ToString() +
ScheduleDate?.ToString("o");

Expand Down
Loading

0 comments on commit c881264

Please sign in to comment.