Skip to content

Commit

Permalink
Merge branch 'release/moov-1.8.28'
Browse files Browse the repository at this point in the history
  • Loading branch information
sipsorcery committed Oct 24, 2024
2 parents 0eaf573 + 6a92d20 commit da15bf0
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 39 deletions.
22 changes: 22 additions & 0 deletions src/NoFrixion.MoneyMoov/Constants/PayrunConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//-----------------------------------------------------------------------------
// Filename: PayrunConstants.cs
//
// Description: Constants for Payrun.
//
// Author(s):
// Saurav Maiti ([email protected])
//
// History:
// 23 Oct 2024 Saurav Maiti Created, Harcourt St, Dublin, Ireland.
//
// License:
// MIT
//-----------------------------------------------------------------------------

namespace NoFrixion.MoneyMoov.Constants;

public static class PayrunConstants
{
public const string REMMITANCE_EMAIL_ADDRESSES_ERROR_MESSAGE =
"One or more of the remittance email addresses are invalid. Addresses can be separated by a comma, semi-colon or space.";
}
15 changes: 2 additions & 13 deletions src/NoFrixion.MoneyMoov/Enums/WebhookResourceTypesEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@ public enum WebhookResourceTypesEnum

/// <summary>
/// Represents a new transaction that corresponds to funds being received.
/// This is a special case of Transaction. If both in and out transactions are
/// desired the Transaction option can be used.
/// This is a duplicate of the TransactionPayin resource and was used in version 1
/// webhooks. It's recommended to use TransactionPayin instead.
/// </summary>
Payin = 1,

/// <summary>
/// Will trigger notifications for payout related events.
/// </summary>
/// <remarks>
/// Note due to unfortunate naming if a merchant is using version 1 webhooks
/// this webhook type corresponds to a transaction and NOT a payout where funds
/// are being sent out i.e. the opposite of payin.
/// </remarks>
Payout = 2,

/// <summary>
Expand All @@ -51,17 +46,11 @@ public enum WebhookResourceTypesEnum
/// <summary>
/// Will trigger notifications for a transaction that is receiving funds.
/// </summary>
/// <remarks>
/// This is the equivalent of the webhooks version 1 Payin.
/// </remarks>
TransactionPayin = 16,

/// <summary>
/// Will trigger notifications for a transaction that is sending funds.
/// </summary>
/// <remarks>
/// This is the equivalent of the webhooks version 1 Payout.
/// </remarks>
TransactionPayout = 32,

/// <summary>
Expand Down
42 changes: 42 additions & 0 deletions src/NoFrixion.MoneyMoov/Extensions/CurrencyExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//-----------------------------------------------------------------------------
// Filename: CurrencyExtensions.cs
//
// Description: Contains extension methods for the Currency enum.
//
// Author(s):
// Aaron Clauson ([email protected])
//
// History:
// 23 Oct 2024 Aaron Clauson Created, Carne, Wexford, Ireland.
//
// License:
// MIT
//-----------------------------------------------------------------------------

namespace NoFrixion.MoneyMoov;

public static class CurrencyExtensions
{
public static string GetCurrencySymbol(this CurrencyTypeEnum currency) =>
currency switch
{
CurrencyTypeEnum.BTC => "₿",
CurrencyTypeEnum.GBP => "£",
CurrencyTypeEnum.EUR => "€",
_ => "€"
};

public static bool IsFiat(this CurrencyTypeEnum currency) =>
currency switch
{
CurrencyTypeEnum.BTC => false,
_ => true
};

public static int GetDecimalPlaces(this CurrencyTypeEnum currency) =>
currency switch
{
CurrencyTypeEnum.BTC => PaymentsConstants.BITCOIN_ROUNDING_DECIMAL_PLACES,
_ => PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES
};
}
22 changes: 3 additions & 19 deletions src/NoFrixion.MoneyMoov/Extensions/PaymentAmount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,12 @@ public static class PaymentAmount
/// Combines the display currency symbol and amount.
/// </summary>
public static string DisplayCurrencyAndAmount(CurrencyTypeEnum currency, decimal amount) =>
GetCurrencySymbol(currency) + " " + GetDisplayAmount(currency, amount);
currency.GetCurrencySymbol() + " " + GetDisplayAmount(currency, amount);

public static string GetDisplayAmount(CurrencyTypeEnum currency, decimal amount) =>
IsFiat(currency) ? amount.ToString("N2") : amount.ToString("N8");
currency.IsFiat() ? amount.ToString("N2") : amount.ToString("N8");

public static decimal GetRoundedAmount(CurrencyTypeEnum currency, decimal amount) =>
Math.Round(amount, IsFiat(currency) ? PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES : PaymentsConstants.BITCOIN_ROUNDING_DECIMAL_PLACES);

public static string GetCurrencySymbol(CurrencyTypeEnum currency) =>
currency switch
{
CurrencyTypeEnum.BTC => "₿",
CurrencyTypeEnum.GBP => "£",
CurrencyTypeEnum.EUR => "€",
_ => "€"
};

private static bool IsFiat(CurrencyTypeEnum currency) =>
currency switch
{
CurrencyTypeEnum.BTC => false,
_ => true
};
Math.Round(amount, currency.IsFiat() ? PaymentsConstants.FIAT_ROUNDING_DECIMAL_PLACES : PaymentsConstants.BITCOIN_ROUNDING_DECIMAL_PLACES);
}

Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public PaymentMethodTypeEnum PaymentMethodTypes
/// <summary>
/// Gets the symbol for the payment request currency.
/// </summary>
public string DisplayCurrencySymbol() => PaymentAmount.GetCurrencySymbol(Currency);
public string DisplayCurrencySymbol() => Currency.GetCurrencySymbol();

/// <summary>
/// Gets the amount to display with the correct number of decimal places based on the currency type.
Expand Down
7 changes: 5 additions & 2 deletions src/NoFrixion.MoneyMoov/Models/Payouts/Payout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ public Counterparty? DestinationAccount
/// </summary>
public PaymentRailEnum PaymentRail { get; set; }

public string? Nonce { get; set; }

public NoFrixionProblem Validate()
{
var context = new ValidationContext(this, serviceProvider: null, items: null);
Expand Down Expand Up @@ -436,10 +438,11 @@ public string GetApprovalHash()
ID.ToString() +
AccountID.ToString() +
Currency +
Math.Round(Amount, 2).ToString() +
Math.Round(Amount, Currency.GetDecimalPlaces()).ToString() +
Destination.GetApprovalHash() +
Scheduled.GetValueOrDefault().ToString() +
ScheduleDate?.ToString("o");
ScheduleDate?.ToString("o") +
(string.IsNullOrEmpty(Nonce) ? string.Empty : Nonce);

return HashHelper.CreateHash(input);
}
Expand Down
6 changes: 4 additions & 2 deletions src/NoFrixion.MoneyMoov/Models/Payruns/PayrunInvoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//-----------------------------------------------------------------------------

using System.ComponentModel.DataAnnotations;
using NoFrixion.MoneyMoov.Attributes;
using NoFrixion.MoneyMoov.Constants;
using NoFrixion.MoneyMoov.Models.Invoices;

namespace NoFrixion.MoneyMoov.Models;
Expand Down Expand Up @@ -63,8 +65,8 @@ public class PayrunInvoice : IValidatableObject
public decimal? SubTotal { get; set; }

public string? Status { get; set; }

[EmailAddress]
[EmailAddressMultiple(ErrorMessage = PayrunConstants.REMMITANCE_EMAIL_ADDRESSES_ERROR_MESSAGE)]
public string? RemittanceEmail { get; set; }

public Guid? XeroInvoiceID { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/NoFrixion.MoneyMoov/NoFrixion.MoneyMoov.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyVersion>1.8.26.0</AssemblyVersion>
<FileVersion>1.8.26.0</FileVersion>
<AssemblyVersion>1.8.28.0</AssemblyVersion>
<FileVersion>1.8.28.0</FileVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);1591</NoWarn>
Expand Down
30 changes: 30 additions & 0 deletions src/NoFrixion.MoneyMoov/NonceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//-----------------------------------------------------------------------------
// Filename: NonceHelper.cs
//
// Description: Helper functions for dealing with nonces.
//
// Author(s):
// Aaron Clauson ([email protected])
//
// History:
// 23 Oct 2024 Aaron Clauson Created, Carne, Wexford, Ireland.
//
// License:
// MIT.
//-----------------------------------------------------------------------------

using System.Security.Cryptography;

namespace NoFrixion.MoneyMoov;

public static class NonceHelper
{
public static string GenerateRandomNonce()
{
var nonce = new byte[64];
var random = RandomNumberGenerator.Create();
random.GetBytes(nonce);

return Convert.ToBase64String(nonce);
}
}

0 comments on commit da15bf0

Please sign in to comment.