Skip to content

Commit a40e407

Browse files
committed
Merge branch 'release/txm-1.8.20'
2 parents f00d222 + 8302866 commit a40e407

File tree

6 files changed

+144
-17
lines changed

6 files changed

+144
-17
lines changed

src/NoFrixion.MoneyMoov/ApiClients/AccountClient.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Extensions.Logging.Abstractions;
1818
using NoFrixion.MoneyMoov.Models;
1919
using System.Net;
20+
using System.Net.Http.Headers;
2021

2122
namespace NoFrixion.MoneyMoov;
2223

@@ -25,6 +26,10 @@ public interface IAccountClient
2526
Task<RestApiResponse<PaymentAccount>> GetAccountAsync(string userAccessToken, Guid accountID);
2627

2728
Task<RestApiResponse<PaymentAccount>> CreateAccountAsync(string userAccessToken, PaymentAccountCreate accountCreate);
29+
30+
Task<RestApiFileResponse> GetStatementAsync(string accessToken, Guid accountID, Guid statementID);
31+
32+
Task<RestApiResponse> ClearStatementsAsync(string accessToken);
2833
}
2934

3035
public class AccountClient : IAccountClient
@@ -81,4 +86,62 @@ public Task<RestApiResponse<PaymentAccount>> CreateAccountAsync(string userAcces
8186
_ => Task.FromResult(new RestApiResponse<PaymentAccount>(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
8287
};
8388
}
89+
90+
/// <summary>
91+
/// Calls the MoneyMoov statements endpoint to get a statement file.
92+
/// </summary>
93+
/// <param name="accessToken">A User or Merchant scoped JWT access token.</param>
94+
/// <param name="accountID">The account ID</param>
95+
/// <param name="statementID">The ID of the report to retrieve the result for.</param>
96+
/// <returns>If successful, the statement result.</returns>
97+
public async Task<RestApiFileResponse> GetStatementAsync(string accessToken, Guid accountID, Guid statementID)
98+
{
99+
var url = MoneyMoovUrlBuilder.AccountsApi.StatementsUrl(_apiClient.GetBaseUri().ToString(), accountID, statementID);
100+
var prob = _apiClient.CheckAccessToken(accessToken, nameof(GetStatementAsync));
101+
102+
if (!prob.IsEmpty)
103+
{
104+
return new RestApiFileResponse(HttpStatusCode.PreconditionFailed, new Uri(url), prob);
105+
}
106+
107+
using (var httpClient = new HttpClient())
108+
{
109+
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
110+
var response = await httpClient.GetAsync(url);
111+
112+
if (response.IsSuccessStatusCode)
113+
{
114+
var content = await response.Content.ReadAsByteArrayAsync();
115+
var contentType = response.Content.Headers.ContentType?.ToString() ?? "application/pdf";
116+
var fileName = response.Content.Headers.ContentDisposition?.FileName?.Trim('\"') ?? "downloaded_file";
117+
118+
return new RestApiFileResponse(HttpStatusCode.OK, new Uri(url), response.Headers, content, contentType, fileName);
119+
}
120+
else
121+
{
122+
return new RestApiFileResponse(
123+
response.StatusCode,
124+
new Uri(url),
125+
new NoFrixionProblem(response.ReasonPhrase ?? "File download failed.", (int)response.StatusCode));
126+
}
127+
}
128+
}
129+
130+
/// <summary>
131+
/// Calls the MoneyMoov Statements endpoint to clear the user's cached statements. This allows them to be re-generated, for example
132+
/// if the statement was for the current month and the month has not yet completed.
133+
/// </summary>
134+
/// <param name="accessToken">The user token deleting the payout.</param>
135+
public Task<RestApiResponse> ClearStatementsAsync(string accessToken)
136+
{
137+
var url = MoneyMoovUrlBuilder.AccountsApi.StatementsUrl(_apiClient.GetBaseUri().ToString());
138+
139+
var prob = _apiClient.CheckAccessToken(accessToken, nameof(ClearStatementsAsync));
140+
141+
return prob switch
142+
{
143+
var p when p.IsEmpty => _apiClient.DeleteAsync(url, accessToken),
144+
_ => Task.FromResult(new RestApiResponse(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
145+
};
146+
}
84147
}

src/NoFrixion.MoneyMoov/ApiClients/StatementClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public StatementClient(IRestApiClient apiClient, ILogger<StatementClient> logger
5050
/// <param name="accessToken">A User or Merchant scoped JWT access token.</param>
5151
/// <param name="statementID">The ID of the report to retrieve the result for.</param>
5252
/// <returns>If successful, the statement result.</returns>
53+
[Obsolete("Use AccountClient.GetStatementAsync instead.")]
5354
public async Task<RestApiFileResponse> GetStatementAsync(string accessToken, Guid statementID)
5455
{
5556
var url = MoneyMoovUrlBuilder.StatementsApi.StatementsUrl(_apiClient.GetBaseUri().ToString(), statementID);
@@ -88,6 +89,7 @@ public async Task<RestApiFileResponse> GetStatementAsync(string accessToken, Gui
8889
/// if the statement was for the current month and the month has not yet completed.
8990
/// </summary>
9091
/// <param name="accessToken">The user token deleting the payout.</param>
92+
[Obsolete("Use AccountClient.ClearStatementsAsync instead.")]
9193
public Task<RestApiResponse> ClearStatementsAsync(string accessToken)
9294
{
9395
var url = MoneyMoovUrlBuilder.StatementsApi.StatementsUrl(_apiClient.GetBaseUri().ToString());
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// -----------------------------------------------------------------------------
2+
// Filename: XeroBankFeedConnectionStatusEnum.cs
3+
//
4+
// Description: Defines all the possible statuses for a Xero bank feed connection.
5+
//
6+
// Author(s):
7+
// Axel Granillo ([email protected])
8+
//
9+
// History:
10+
// 09 09 2024 Axel Granillo Created, Remote, Mexico City, Mexico.
11+
//
12+
// License:
13+
// MIT.
14+
// -----------------------------------------------------------------------------
15+
16+
namespace NoFrixion.MoneyMoov.Enums;
17+
18+
/// <summary>
19+
/// Defines all the possible statuses for a Xero bank feed connection.
20+
/// </summary>
21+
public enum XeroBankFeedConnectionStatusEnum
22+
{
23+
/// <summary>
24+
/// Default status. No status has been set.
25+
/// </summary>
26+
None,
27+
28+
/// <summary>
29+
/// The bank feed connection has been queued for processing.
30+
/// </summary>
31+
Pending,
32+
33+
/// <summary>
34+
/// The bank feed connection is fully operational.
35+
/// </summary>
36+
Active,
37+
38+
/// <summary>
39+
/// This means that the respective account on Xero has been Archived/Deleted.
40+
/// This status will be used when the Xero bank feed connection ID can no longer be found on Xero.
41+
/// </summary>
42+
Inactive,
43+
44+
/// <summary>
45+
/// The bank feed had a failure during the connection process.
46+
/// </summary>
47+
Failed
48+
}

src/NoFrixion.MoneyMoov/Models/Account/PaymentAccount.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,14 @@ public string Summary
165165
/// <summary>
166166
/// Indicates if the payment account is connected to a Xero bank feed.
167167
/// </summary>
168+
[Obsolete("Please use the XeroBankFeedConnectionStatus property.")]
168169
public bool IsXeroBankFeed { get; set; }
169170

171+
/// <summary>
172+
/// States the status of the Xero bank feed connection, if applicable.
173+
/// </summary>
174+
public XeroBankFeedConnectionStatusEnum? XeroBankFeedConnectionStatus { get; set; }
175+
170176
public XeroBankFeedSyncStatusEnum XeroBankFeedSyncStatus { get; set; }
171177

172178
public DateTimeOffset? XeroBankFeedLastSyncedAt { get; set; }
@@ -184,6 +190,7 @@ public string Summary
184190
/// Indicates that the bank feed connection can no longer be found in Xero.
185191
/// This can mean that the respective account was archived/deleted in Xero.
186192
/// </summary>
193+
[Obsolete("Please use the XeroBankFeedConnectionStatus property.")]
187194
public bool XeroBankFeedConnectionInactive { get; set; }
188195

189196
/// <summary>

src/NoFrixion.MoneyMoov/MoneyMoovUrlBuilder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public static string AccountsUrl(string moneyMoovBaseUrl)
7676

7777
public static string AccountPayoutsUrl(string moneyMoovBaseUrl, Guid accountID)
7878
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.accounts}/{accountID}/{MoneyMoovResources.payouts}";
79+
80+
public static string StatementsUrl(string moneyMoovBaseUrl)
81+
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.accounts}/{MoneyMoovResources.statements}";
82+
83+
public static string StatementsUrlWithAccountPlaceholder(string moneyMoovBaseUrl)
84+
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.accounts}/##account##/{MoneyMoovResources.statements}";
85+
86+
public static string StatementsUrl(string moneyMoovBaseUrl, Guid accountID, Guid statementID)
87+
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.accounts}/{accountID}/{MoneyMoovResources.statements}/{statementID}";
7988
}
8089

8190
/// <summary>

src/NoFrixion.MoneyMoov/Permissions/Permissions.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,35 +83,33 @@ public enum MerchantPermissions : ulong
8383

8484
// Users
8585
CanViewUsers = 1L << 18,
86-
CanViewUserInvites = 1L << 19,
87-
CanEditUsers = 1L << 20,
8886

8987
// Webhooks
90-
CanViewWebhooks = 1L << 21,
91-
CanCreateWebhooks = 1L << 22,
92-
CanDeleteWebhooks = 1L << 23,
88+
CanViewWebhooks = 1L << 19,
89+
CanCreateWebhooks = 1L << 20,
90+
CanDeleteWebhooks = 1L << 21,
9391

9492
// Merchants
95-
CanViewMerchant = 1L << 24,
96-
CanUpdateMerchant = 1L << 25,
93+
CanViewMerchant = 1L << 22,
94+
CanUpdateMerchant = 1L << 23,
9795

9896
// Payment requests
99-
CanCreatePaymentRequests = 1L << 26,
100-
CanViewPaymentRequests = 1L << 27,
101-
CanUpdatePaymentRequests = 1L << 28,
97+
CanCreatePaymentRequests = 1L << 24,
98+
CanViewPaymentRequests = 1L << 25,
99+
CanUpdatePaymentRequests = 1L << 26,
102100

103101
// Mandates
104-
CanViewMandates = 1L << 29,
105-
CanCreateMandates = 1L << 30,
102+
CanViewMandates = 1L << 27,
103+
CanCreateMandates = 1L << 28,
106104

107105
// Permissions
108-
CanViewRoles = 1L << 31,
109-
CanCreateRoles = 1L << 32,
110-
CanEditRoles = 1L << 33,
106+
CanViewRoles = 1L << 29,
107+
CanCreateRoles = 1L << 30,
108+
CanEditRoles = 1L << 31,
111109

112110
// Reports
113-
CanCreateReports = 1L << 34,
114-
CanViewReports = 1L << 35,
111+
CanCreateReports = 1L << 32,
112+
CanViewReports = 1L << 33,
115113
}
116114

117115
public static class ClaimTypePrefixes

0 commit comments

Comments
 (0)