Skip to content

Commit 44d63fe

Browse files
committed
Merge branch 'release/moov-1.8.101'
2 parents 3d55c91 + 63aca6c commit 44d63fe

24 files changed

+266
-52
lines changed

src/NoFrixion.MoneyMoov/ApiClients/MerchantClient.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Task<RestApiResponse<MerchantPageResponse>> GetChildMerchantsAsync(string userAc
6262
int pageSize = 20,
6363
string? search = null,
6464
string? sort = null);
65+
66+
Task<RestApiResponse<RoleUser>> GetRoleUserAssignmentAsync(string userAccessToken, Guid roleUserID);
67+
68+
Task<RestApiResponse> AuthoriseRoleUserAssignmentAsync(string strongUserAccessToken, Guid roleUserID);
6569
}
6670

6771
public class MerchantClient : IMerchantClient
@@ -403,4 +407,44 @@ public Task<RestApiResponse<MerchantPageResponse>> GetChildMerchantsAsync(string
403407
_ => Task.FromResult(new RestApiResponse<MerchantPageResponse>(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
404408
};
405409
}
410+
411+
/// <summary>
412+
/// Gets a specific role user assignment by its ID.
413+
/// </summary>
414+
/// <param name="userAccessToken">A user scoped JWT access token.</param>
415+
/// <param name="roleUserID">The ID of the role user assignment to get.</param>
416+
/// <returns>If successful, the role user assignment.</returns>
417+
public Task<RestApiResponse<RoleUser>> GetRoleUserAssignmentAsync(string userAccessToken, Guid roleUserID)
418+
{
419+
var url = MoneyMoovUrlBuilder.MerchantsApi.MerchantRoleUserAssignmentsUrl(_apiClient.GetBaseUri().ToString(), roleUserID);
420+
421+
var prob = _apiClient.CheckAccessToken(userAccessToken, nameof(GetRolesAsync));
422+
423+
return prob switch
424+
{
425+
var p when p.IsEmpty => _apiClient.GetAsync<RoleUser>(url, userAccessToken),
426+
_ => Task.FromResult(new RestApiResponse<RoleUser>(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
427+
};
428+
}
429+
430+
/// <summary>
431+
/// Calls the MoneyMoov merchant endpoint to authorise a role user assignment.
432+
/// </summary>
433+
/// <param name="strongUserAccessToken">The strong user access token acquired to authorise the role suer assignment. Strong
434+
/// tokens can only be acquired from a strong customer authentication flow, are short lived (typically 5 minute expiry)
435+
/// and are specific to the role user assignment.</param>
436+
/// <param name="roleUserID">The ID of the role user assignment to authorise.</param>
437+
/// <returns>An API response indicating the result of the authorise attempt.</returns>
438+
public Task<RestApiResponse> AuthoriseRoleUserAssignmentAsync(string strongUserAccessToken, Guid roleUserID)
439+
{
440+
var url = MoneyMoovUrlBuilder.MerchantsApi.MerchantRoleUserAssignmentsUrl(_apiClient.GetBaseUri().ToString(), roleUserID);
441+
442+
var prob = _apiClient.CheckAccessToken(strongUserAccessToken, nameof(AuthoriseRoleUserAssignmentAsync));
443+
444+
return prob switch
445+
{
446+
var p when p.IsEmpty => _apiClient.PostAsync(url, strongUserAccessToken),
447+
_ => Task.FromResult(new RestApiResponse(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
448+
};
449+
}
406450
}

src/NoFrixion.MoneyMoov/Constants/PaymentsConstants.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ namespace NoFrixion.MoneyMoov;
1919
public static class PaymentsConstants
2020
{
2121
/// <summary>
22-
/// Round fiat (EUR, GBP etc) amounts to this many decimal places.
22+
/// Round fiat (EUR, GBP etc) amounts to this many decimal places for external payouts.
2323
/// </summary>
24-
public const int FIAT_ROUNDING_DECIMAL_PLACES = 2;
24+
public const int FIAT_ROUNDING_DECIMAL_PLACES_EXTERNAL = 2;
25+
26+
/// <summary>
27+
/// Internal payouts and transactions can optionally be specified down to 4 decimal places.
28+
/// </summary>
29+
public const int FIAT_ROUNDING_DECIMAL_PLACES_INTERNAL = 4;
2530

2631
/// <summary>
2732
/// Bitcoin Satoshis use 8 decimal places.

src/NoFrixion.MoneyMoov/Enums/MerchantTokenEventTypeEnum.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@ public enum MerchantTokenEventTypeEnum
4040
/// <summary>
4141
/// A merchant token was archived.
4242
/// </summary>
43-
Archive = 4
43+
Archive = 4,
44+
45+
/// <summary>
46+
/// A merchant token was edited.
47+
/// </summary>
48+
Edited = 5
4449
}

src/NoFrixion.MoneyMoov/Enums/PayoutEventTypesEnum.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,10 @@ public enum PayoutEventTypesEnum
9797
/// A payout's associated beneficiary was enabled.
9898
/// </summary>
9999
BeneficiaryEnabled = 15,
100+
101+
/// <summary>
102+
/// An error that occurred during an attempt to submit a payout for processing. This is not a terminal error
103+
/// and the attempt can be tried again. Errors after the payout's IsSubmitted flag is set are terminal.
104+
/// </summary>
105+
SubmitAttemptError = 16
100106
}

src/NoFrixion.MoneyMoov/Extensions/AmountMinorUnitExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static long ToAmountMinorUnits(this decimal amount, CurrencyTypeEnum curr
2222
{
2323
decimal units = currency switch
2424
{
25-
var c when c.IsFiat() => amount * (int)Math.Pow(10, PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES),
25+
var c when c.IsFiat() => amount * (int)Math.Pow(10, PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES_EXTERNAL),
2626
CurrencyTypeEnum.BTC => amount * (int)Math.Pow(10, PaymentsConstants.BITCOIN_ROUNDING_DECIMAL_PLACES),
2727
_ => throw new ApplicationException($"Currency {currency} was not recognised in {nameof(ToAmountMinorUnits)}.")
2828
};

src/NoFrixion.MoneyMoov/Extensions/CurrencyExtensions.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,4 @@ public static bool IsFiat(this CurrencyTypeEnum currency) =>
3434
CurrencyTypeEnum.BTC => false,
3535
_ => true
3636
};
37-
38-
public static int GetDecimalPlaces(this CurrencyTypeEnum currency) =>
39-
currency switch
40-
{
41-
CurrencyTypeEnum.BTC => PaymentsConstants.BITCOIN_ROUNDING_DECIMAL_PLACES,
42-
_ => PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES
43-
};
4437
}

src/NoFrixion.MoneyMoov/Extensions/PaymentAmount.cs

100644100755
Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// Proprietary NoFrixion.
1414
//-----------------------------------------------------------------------------
1515

16+
using System.Globalization;
17+
1618
namespace NoFrixion.MoneyMoov;
1719

1820
public static class PaymentAmount
@@ -23,10 +25,29 @@ public static class PaymentAmount
2325
public static string DisplayCurrencyAndAmount(CurrencyTypeEnum currency, decimal amount) =>
2426
currency.GetCurrencySymbol() + " " + GetDisplayAmount(currency, amount);
2527

26-
public static string GetDisplayAmount(CurrencyTypeEnum currency, decimal amount) =>
27-
currency.IsFiat() ? amount.ToString("N2") : amount.ToString("N8");
28+
// Decide decimals once, reuse everywhere.
29+
private static int GetDecimalPlaces(CurrencyTypeEnum currency, decimal amount)
30+
{
31+
if (!currency.IsFiat())
32+
{
33+
return PaymentsConstants.BITCOIN_ROUNDING_DECIMAL_PLACES;
34+
}
35+
36+
return decimal.Remainder(decimal.Abs(amount), 0.01m) != 0m
37+
? PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES_INTERNAL // 4 decimal places option for internal payouts.
38+
: PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES_EXTERNAL; // 2 decimal places for external payouts.
39+
}
40+
41+
public static string GetDisplayAmount(CurrencyTypeEnum currency, decimal amount, IFormatProvider? culture = null)
42+
{
43+
var dps = GetDecimalPlaces(currency, amount);
44+
return amount.ToString($"N{dps}", culture ?? CultureInfo.CurrentCulture);
45+
}
2846

29-
public static decimal GetRoundedAmount(CurrencyTypeEnum currency, decimal amount) =>
30-
Math.Round(amount, currency.IsFiat() ? PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES : PaymentsConstants.BITCOIN_ROUNDING_DECIMAL_PLACES);
47+
public static decimal GetRoundedAmount(CurrencyTypeEnum currency, decimal amount, MidpointRounding mode = MidpointRounding.ToEven)
48+
{
49+
var dps = GetDecimalPlaces(currency, amount);
50+
return Math.Round(amount, dps, mode);
51+
}
3152
}
3253

src/NoFrixion.MoneyMoov/Extensions/PaymentRequestExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ PaymentRequestEventTypesEnum.pisp_callback or
243243
var settleFailedEvent = attempt.First(x => x.EventType is PaymentRequestEventTypesEnum.pisp_settle_failure);
244244

245245
paymentAttempt.SettleFailedAt = settleFailedEvent.Inserted;
246+
247+
//Set authorised amount to zero when there is settlement failure for this attempt.
248+
paymentAttempt.AuthorisedAmount = 0;
249+
246250
}
247251

248252
pispPaymentAttempts.Add(paymentAttempt);

src/NoFrixion.MoneyMoov/Models/ApiPageResponseBase.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ public MerchantPageResponse(List<Merchant> content,
9191
{ }
9292
}
9393

94+
public class UserPageResponse : ApiPageResponseBase<User>
95+
{
96+
public UserPageResponse(List<User> content,
97+
int pageNumber = 1,
98+
int pageSize = 10,
99+
long totalPages = default,
100+
long totalSize = default)
101+
: base(content, pageNumber, pageSize, totalPages, totalSize)
102+
{ }
103+
}
104+
105+
public class UserInvitePageResponse : ApiPageResponseBase<UserInvite>
106+
{
107+
public UserInvitePageResponse(List<UserInvite> content,
108+
int pageNumber = 1,
109+
int pageSize = 10,
110+
long totalPages = default,
111+
long totalSize = default)
112+
: base(content, pageNumber, pageSize, totalPages, totalSize)
113+
{ }
114+
}
115+
94116
public abstract class ApiPageResponseBase<T> : PageResponse<T>
95117
{
96118
/// <summary>

src/NoFrixion.MoneyMoov/Models/PaymentRequests/PaymentRequestEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public decimal DisplayAmount()
209209
return EventType switch
210210
{
211211
PaymentRequestEventTypesEnum.lightning_invoice_created => Math.Round(Amount, PaymentsConstants.BITCOIN_LIGHTNING_ROUNDING_DECIMAL_PLACES),
212-
_ => Math.Round(Amount, PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES)
212+
_ => Math.Round(Amount, PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES_EXTERNAL)
213213
};
214214
}
215215

0 commit comments

Comments
 (0)