Skip to content

Commit 2b9d3db

Browse files
authored
Merge pull request #611 from nofrixion/feature/MOOV-1918-merchant-notifications
Feature/moov 1918 merchant notifications
2 parents 2db7eb3 + 2241e89 commit 2b9d3db

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// -----------------------------------------------------------------------------
2+
// Filename: NotificationMethodTypesEnum.cs
3+
//
4+
// Description: Types of notification methods that can be used for merchant notifications.
5+
//
6+
// Author(s):
7+
// Arif Matin ([email protected])
8+
//
9+
// History:
10+
// 11 Jul 2025 Arif Matin Created, Carrick on Shannon, Lietrim, Ireland.
11+
//
12+
// License:
13+
// MIT.
14+
// -----------------------------------------------------------------------------
15+
16+
namespace NoFrixion.MoneyMoov.Enums
17+
{
18+
public enum NotificationMethodTypesEnum
19+
{
20+
None = 0,
21+
22+
/// <summary>
23+
/// The notification will be sent via webhook.
24+
/// </summary>
25+
Webhook = 1,
26+
27+
/// <summary>
28+
/// The notification will be sent via email.
29+
/// </summary>
30+
Email = 2,
31+
}
32+
}

src/NoFrixion.MoneyMoov/Models/WebHook/Webhook.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// MIT.
1313
// -----------------------------------------------------------------------------
1414

15+
using NoFrixion.MoneyMoov.Enums;
1516
using System.Security.Cryptography;
1617
using System.Text;
1718

@@ -61,6 +62,11 @@ public WebhookResourceTypesEnum Type
6162
/// </summary>
6263
public Guid MerchantID { get; set; }
6364

65+
/// <summary>
66+
/// The type of notification that will be sent.
67+
/// </summary>
68+
public NotificationMethodTypesEnum NotificationMethod { get; set; }
69+
6470
public static string GetSignature(string secret, byte[] payloadBytes)
6571
{
6672
byte[] keyByte = Encoding.UTF8.GetBytes(secret);

src/NoFrixion.MoneyMoov/Models/WebHook/WebhookCreate.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//-----------------------------------------------------------------------------
1515

1616
using NoFrixion.MoneyMoov.Attributes;
17+
using NoFrixion.MoneyMoov.Enums;
1718
using System.ComponentModel.DataAnnotations;
1819

1920
namespace NoFrixion.MoneyMoov.Models;
@@ -51,16 +52,26 @@ public WebhookResourceTypesEnum Type
5152
/// </summary>
5253
public List<WebhookResourceTypesEnum> ResourceTypes { get; set; } = new List<WebhookResourceTypesEnum>();
5354

54-
[Required]
55+
/// <summary>
56+
/// The destination URL for the webhook.
57+
/// Required for webhook notifications.
58+
/// </summary>
5559
public string? DestinationUrl { get; set; }
5660

5761
public bool Retry { get; set; } = true;
5862

59-
[Required]
63+
/// <summary>
64+
/// The secret key required to authenticate webhook notifications.
65+
/// Required for webhook notifications.
66+
/// </summary>
6067
public string? Secret { get; set; }
6168

6269
public bool IsActive { get; set; } = true;
6370

71+
/// <summary>
72+
/// The recipient email address(es) for notifications. Multiple addresses can be separated by a comma, semicolon, or space.
73+
/// Reruired for email notifications.
74+
/// </summary>
6475
[EmailAddressMultiple(ErrorMessage = "One or more of the email addresses are invalid. Addresses can be separated by a comma, semi-colon or space.")]
6576
public string? EmailAddress { get; set; }
6677

@@ -70,6 +81,12 @@ public WebhookResourceTypesEnum Type
7081
[EmailAddressMultiple(ErrorMessage = "One or more of the email addresses are invalid. Addresses can be separated by a comma, semi-colon or space.")]
7182
public string? FailedNotificationEmailAddress { get; set; }
7283

84+
/// <summary>
85+
/// The type of notification that will be sent.
86+
/// </summary>
87+
[Required]
88+
public NotificationMethodTypesEnum NotificationMethod { get; set; }
89+
7390
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
7491
{
7592
if (Secret?.Length > SECRET_MAX_LENGTH)
@@ -86,6 +103,23 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
86103
{
87104
yield return new ValidationResult("Cannot create a webhook with a resource type of none.");
88105
}
106+
107+
if (NotificationMethod is NotificationMethodTypesEnum.None)
108+
{
109+
yield return new ValidationResult("Cannot create a webhook with a notification method type of none.");
110+
}
111+
112+
if (NotificationMethod is NotificationMethodTypesEnum.Email
113+
&& string.IsNullOrWhiteSpace(EmailAddress))
114+
{
115+
yield return new ValidationResult("Email address is required for email notification method.");
116+
}
117+
118+
if (NotificationMethod is NotificationMethodTypesEnum.Webhook
119+
&& (string.IsNullOrWhiteSpace(DestinationUrl) || string.IsNullOrWhiteSpace(Secret)))
120+
{
121+
yield return new ValidationResult("Destination URL and Secret are required for webhook notification method.");
122+
}
89123
}
90124

91125
public Dictionary<string, string> ToDictionary()
@@ -99,7 +133,8 @@ public Dictionary<string, string> ToDictionary()
99133
{ nameof(Secret), Secret ?? string.Empty },
100134
{ nameof(IsActive), IsActive.ToString() },
101135
{ nameof(EmailAddress), EmailAddress ?? string.Empty },
102-
{ nameof(FailedNotificationEmailAddress), FailedNotificationEmailAddress ?? string.Empty }
136+
{ nameof(FailedNotificationEmailAddress), FailedNotificationEmailAddress ?? string.Empty },
137+
{ nameof(NotificationMethod), NotificationMethod.ToString() }
103138
};
104139

105140
if (ResourceTypes?.Count() > 0)

0 commit comments

Comments
 (0)