Skip to content

Commit

Permalink
Merge branch 'release/moov-1.8.25'
Browse files Browse the repository at this point in the history
  • Loading branch information
sipsorcery committed Oct 16, 2024
2 parents d672596 + 5188c2e commit dcc1723
Show file tree
Hide file tree
Showing 26 changed files with 394 additions and 72 deletions.
44 changes: 27 additions & 17 deletions src/NoFrixion.MoneyMoov/Enums/MerchantTokenPermissionsEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,80 +34,90 @@ public enum MerchantTokenPermissionsEnum
/// <summary>
/// Permission to edit a payment request
/// </summary>
EditPaymentRequest = 2,
EditPaymentRequest = 1 << 1,

/// <summary>
/// Permission to delete a payment request
/// </summary>
DeletePaymentRequest = 4,
DeletePaymentRequest = 1 << 2,

/// <summary>
/// Permission to create a rule
/// </summary>
CreateRule = 8,
CreateRule = 1 << 3,

/// <summary>
/// Permission to edit a rule
/// </summary>
EditRule = 16,
EditRule = 1 << 4,

/// <summary>
/// Permission to delete a rule
/// </summary>
DeleteRule = 32,
DeleteRule = 1 << 5,

/// <summary>
/// Permission to create a payout
/// </summary>
CreatePayout = 64,
CreatePayout = 1 << 6,

/// <summary>
/// Permission to edit a payout
/// </summary>
EditPayout = 128,
EditPayout = 1 << 7,

/// <summary>
/// Permission to delete a payout
/// </summary>
DeletePayout = 256,
DeletePayout = 1 << 8,

/// <summary>
/// Permission to create a report.
/// </summary>
CreateReport = 512,
CreateReport = 1 << 9,

/// <summary>
/// Permission to edit, retrieve and initiate a report.
/// </summary>
EditReport = 1024,
EditReport = 1 << 10,

/// <summary>
/// Permission to delete a report.
/// </summary>
DeleteReport = 2048,
DeleteReport = 1 << 11,

/// <summary>
/// Permission to execute and get report results.
/// </summary>
ExecuteReport = 4096,
ExecuteReport = 1 << 12,

/// <summary>
/// Permission to create a new payment account.
/// </summary>
CreatePaymentAccount = 8192,
CreatePaymentAccount = 1 << 13,

/// <summary>
/// Permission to edit details on a payment account.
/// </summary>
EditPaymentAccount = 16384,
EditPaymentAccount = 1 << 14,

/// <summary>
/// Permission to create and submit a payout from a trusted source.
/// </summary>
TrustedSubmitPayout = 32768,
TrustedSubmitPayout = 1 << 15,

/// <summary>
/// Permission to perfrom open banking account information actions.
/// Permission to perform open banking account information actions.
/// </summary>
OpenBankingAccountInformation = 65536
OpenBankingAccountInformation = 1 << 16,

/// <summary>
/// Permission to create a direct debit mandate.
/// </summary>
CreateDirectDebitMandate = 1 << 17,

/// <summary>
/// Permission to submit a direct debit payment attempt.
/// </summary>
SubmitDirectDebitPayment = 1 << 18
}
4 changes: 3 additions & 1 deletion src/NoFrixion.MoneyMoov/Enums/PayrunEventTypeEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ public enum PayrunEventTypeEnum

Archived = 10,

Unarchived = 11
Unarchived = 11,

Cancelled = 12,
}
7 changes: 6 additions & 1 deletion src/NoFrixion.MoneyMoov/Enums/WebhookResourceTypesEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public enum WebhookResourceTypesEnum
/// <summary>
/// Will trigger notifications for report, including account statement, related events.
/// </summary>
Report = 64
Report = 64,

/// <summary>
/// Will trigger notifications for tribe load event
/// </summary>
TribeLoad = 128,
}

85 changes: 85 additions & 0 deletions src/NoFrixion.MoneyMoov/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------------
// Filename: GuidExtensions.cs
//
// Description: Contains extension methods for Guid types:
//
// Author(s):
// Aaron Clauson ([email protected])
//
// History:
// 15 Oct 2024 Aaron Clauson Created, Carne, Wexford, Ireland.
//
// License:
// Proprietary NoFrixion.
//-----------------------------------------------------------------------------

namespace NoFrixion.MoneyMoov;

public static class EnumExtensions
{
/// <summary>
/// This method converts an Enum with the Flags attribute to a list of Enums.
/// </summary>
public static List<T> ToList<T>(this T flags) where T : Enum
{
if (!typeof(T).IsDefined(typeof(FlagsAttribute), false))
{
throw new ArgumentException("The type parameter T must have the Flags attribute.", nameof(flags));
}

// Check if the enum underlying type is ulong
var underlyingType = Enum.GetUnderlyingType(typeof(T));

if (underlyingType == typeof(ulong))
{
return Enum.GetValues(typeof(T))
.Cast<T>()
.Where(value => flags.HasFlag(value) && Convert.ToUInt64(value) != 0) // Exclude None or 0
.ToList();
}
else
{
return Enum.GetValues(typeof(T))
.Cast<T>()
.Where(value => flags.HasFlag(value) && Convert.ToInt32(value) != 0) // Exclude None or 0
.ToList();
}
}

/// <summary>
/// This method converts list of flag enum values to a single flag enum.
/// </summary>
public static T ToFlagEnum<T>(this IEnumerable<T> enumValues) where T : Enum
{
if (!typeof(T).IsDefined(typeof(FlagsAttribute), false))
{
throw new ArgumentException("The type parameter T must have the Flags attribute.", nameof(enumValues));
}

// Check if the enum underlying type is ulong
var underlyingType = Enum.GetUnderlyingType(typeof(T));

if (underlyingType == typeof(ulong))
{
ulong result = 0UL;

foreach (var value in enumValues)
{
result |= Convert.ToUInt64(value);
}

return (T)Enum.ToObject(typeof(T), result);
}
else
{
int result = 0;

foreach (var value in enumValues)
{
result |= Convert.ToInt32(value);
}

return (T)Enum.ToObject(typeof(T), result);
}
}
}
10 changes: 6 additions & 4 deletions src/NoFrixion.MoneyMoov/Extensions/PaymentRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,19 @@ PaymentRequestEventTypesEnum.direct_debit_failed or
PaymentMethod = PaymentMethodTypeEnum.directDebit,
Currency = createEvent.Currency,
AttemptedAmount = createEvent.Amount,
PaymentProcessor = createEvent.PaymentProcessorName
PaymentProcessor = createEvent.PaymentProcessorName,
AuthorisedAt = createEvent.Inserted,
AuthorisedAmount = createEvent.Amount
};

if (attempt.Any(x =>
x.EventType is PaymentRequestEventTypesEnum.direct_debit_paid))
{
var paidEvent = attempt.First(x =>
x.EventType is PaymentRequestEventTypesEnum.direct_debit_paid);

paymentAttempt.AuthorisedAt = paidEvent.Inserted;
paymentAttempt.AuthorisedAmount = paidEvent.Amount;
paymentAttempt.SettledAt = paidEvent.Inserted;
paymentAttempt.SettledAmount = paidEvent.Amount;
}
else if (attempt.Any(x =>
x.EventType is PaymentRequestEventTypesEnum.direct_debit_failed))
Expand Down
1 change: 0 additions & 1 deletion src/NoFrixion.MoneyMoov/JsonConverters/NumericConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// MIT.
//-----------------------------------------------------------------------------

using LanguageExt;
using System.ComponentModel;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down
9 changes: 6 additions & 3 deletions src/NoFrixion.MoneyMoov/Models/Mandates/Mandate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ public class Mandate
/// <summary>
/// Currency of this mandate.
/// </summary>
public CurrencyTypeEnum Currency { get; set; }
public CurrencyTypeEnum Currency { get; set; }

/// <summary>
/// Amount of this mandate.
/// This is an optional field that with mandates created via Account Information Services can be
/// used to do a balance check on the payer's account. We don't currenlty support the AIS workflow.
/// </summary>
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public decimal Amount { get; set; }

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions src/NoFrixion.MoneyMoov/Models/Mandates/MandateCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ public class MandateCreate
public CurrencyTypeEnum Currency { get; set; }

/// <summary>
/// Amount of the mandate.
/// This is an optional field that with mandates created via Account Information Services can be
/// used to do a balance check on the payer's account. We don't currenlty support the AIS workflow.
/// </summary>
[Required(ErrorMessage = "Please, specify an amount.")]
[Range(0.00001, double.MaxValue, ErrorMessage = "Minimum value of 0.00001 is required for Amount")]
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public decimal Amount { get; set; }

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion src/NoFrixion.MoneyMoov/Models/Merchant/Merchant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,19 @@ public class Merchant
/// For internal use only.
/// </summary>
public string? ModulrCustomerID { get; set; }

/// <summary>
/// The payment methods that are configured and supported for this merchant.
/// Returned as a comma-separated list of PaymentMethodTypeEnum values.
/// </summary>
[Obsolete("Please usse SupportedPaymentMethodsList instead.")]
public PaymentMethodTypeEnum SupportedPaymentMethods { get; set; }

/// <summary>
/// The payment methods that are configured and supported for this merchant.
/// </summary>
public List<PaymentMethodTypeEnum> SupportedPaymentMethodsList { get; set; } = new List<PaymentMethodTypeEnum>();

/// <summary>
/// The role of the identity that loaded the merchant record.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public interface IPaymentRequest

public string? OrderID { get; set; }

public PaymentMethodTypeEnum PaymentMethodTypes { get; set; }
[Obsolete("This field has been deprecated. Please use PaymentMethods instead.")]
public PaymentMethodTypeEnum PaymentMethodTypes { get; }

public List<PaymentMethodTypeEnum> PaymentMethods { get; set; }

public string? Description { get; set; }

Expand Down
16 changes: 13 additions & 3 deletions src/NoFrixion.MoneyMoov/Models/PaymentRequests/PaymentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public class PaymentRequest : IPaymentRequest, IWebhookPayload
/// The payment methods that the payment request supports. When setting using form data
/// should be supplied as a comma separated list, for example "card, pisp, lightning".
/// </summary>
public PaymentMethodTypeEnum PaymentMethodTypes { get; set; } = PaymentMethodTypeEnum.card;
[Obsolete("This field has been deprecated. Please use PaymentMethods instead.")]
public PaymentMethodTypeEnum PaymentMethodTypes
{
get =>
PaymentMethods.Any() ? PaymentMethods.ToFlagEnum() : PaymentMethodTypeEnum.None;
}

/// <summary>
/// The payment methods that the payment request supports.
/// </summary>
public List<PaymentMethodTypeEnum> PaymentMethods { get; set; } = new List<PaymentMethodTypeEnum>();

/// <summary>
/// An optional description for the payment request. If set this field will appear
Expand Down Expand Up @@ -226,7 +236,7 @@ public class PaymentRequest : IPaymentRequest, IWebhookPayload
public string? CardStripePaymentIntentSecret { get; set; }

[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonProperty]
[Newtonsoft.Json.JsonIgnore]
public Merchant? Merchant { get; set; }

public List<PaymentRequestAddress> Addresses { get; set; } = new List<PaymentRequestAddress>();
Expand Down Expand Up @@ -277,7 +287,7 @@ public class PaymentRequest : IPaymentRequest, IWebhookPayload
/// </summary>
/// <returns>The billing address or null if it's not set.</returns>
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonProperty]
[Newtonsoft.Json.JsonIgnore]
public PaymentRequestAddress? BillingAddress =>
Addresses?.Where(x => x.AddressType == AddressTypesEnum.Billing).FirstOrDefault();

Expand Down
Loading

0 comments on commit dcc1723

Please sign in to comment.