-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
700 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/NoFrixion.MoneyMoov/Enums/StatementGenerationStatusEnum.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
src/NoFrixion.MoneyMoov/Enums/TransactionStatementFormat.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.