Skip to content

Commit 40579db

Browse files
Merge pull request #664 from nofrixion/feature/MOOV-4884-add-child-merchant
Added ParentMerchant to Merchant model
2 parents 7b31012 + 7b8feef commit 40579db

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

src/NoFrixion.MoneyMoov/ApiClients/MerchantClient.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ Task<RestApiResponse<MerchantPageResponse>> GetChildMerchantsAsync(string userAc
6666
Task<RestApiResponse<RoleUser>> GetRoleUserAssignmentAsync(string userAccessToken, Guid roleUserID);
6767

6868
Task<RestApiResponse> AuthoriseRoleUserAssignmentAsync(string strongUserAccessToken, Guid roleUserID);
69+
70+
Task<RestApiResponse<MerchantPageResponse>> GetMerchantsAsync(string userAccessToken,
71+
int pageNumber = 1,
72+
int pageSize = 20,
73+
string? search = null,
74+
string? sort = null);
75+
76+
Task<RestApiResponse> SetParentMerchantAsync(string userAccessToken, Guid merchantId, Guid parentMerchantId);
6977
}
7078

7179
public class MerchantClient : IMerchantClient
@@ -447,4 +455,57 @@ public Task<RestApiResponse> AuthoriseRoleUserAssignmentAsync(string strongUserA
447455
_ => Task.FromResult(new RestApiResponse(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
448456
};
449457
}
458+
459+
/// <summary>
460+
/// Calls the MoneyMoov merchant endpoint to get a paged list of merchants.
461+
/// </summary>
462+
/// <param name="userAccessToken">A user scoped JWT access token.</param>
463+
/// <param name="pageNumber">The page number of the result set to retrieve.</param>
464+
/// <param name="pageSize">The number of records to return per page.</param>
465+
/// <param name="search">A search filter to apply to the child merchant list. Typically searches against merchant name or ID.</param>
466+
/// <param name="sort">The sort expression for the result set, e.g., "Name asc".</param>
467+
/// <returns>A paged response containing a list of child merchants if successful.</returns>
468+
public Task<RestApiResponse<MerchantPageResponse>> GetMerchantsAsync(string userAccessToken,
469+
int pageNumber = 1,
470+
int pageSize = Int32.MaxValue,
471+
string? search = null,
472+
string? sort = null)
473+
{
474+
var url = MoneyMoovUrlBuilder.MerchantsApi.MerchantsPagedUrl(_apiClient.GetBaseUri().ToString(),
475+
pageNumber,
476+
pageSize,
477+
search,
478+
sort);
479+
480+
var prob = _apiClient.CheckAccessToken(userAccessToken, nameof(GetMerchantsAsync));
481+
482+
return prob switch
483+
{
484+
var p when p.IsEmpty => _apiClient.GetAsync<MerchantPageResponse>(url, userAccessToken),
485+
_ => Task.FromResult(new RestApiResponse<MerchantPageResponse>(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
486+
};
487+
}
488+
489+
/// <summary>
490+
/// Sets the parent merchant for a merchant.
491+
/// This will make the merchant a child merchant of the specified parent merchant.
492+
/// </summary>
493+
/// <param name="userAccessToken">A user scoped JWT access token.</param>
494+
/// <param name="merchantId">The id of the merchant to set the parent for. </param>
495+
/// <param name="parentMerchantId">The parent merchant id</param>
496+
/// <returns></returns>
497+
public Task<RestApiResponse> SetParentMerchantAsync(string userAccessToken, Guid merchantId, Guid parentMerchantId)
498+
{
499+
var url = MoneyMoovUrlBuilder.MerchantsApi.SetParentMerchantUrl(_apiClient.GetBaseUri().ToString(),
500+
merchantId,
501+
parentMerchantId);
502+
503+
var prob = _apiClient.CheckAccessToken(userAccessToken, nameof(GetMerchantsAsync));
504+
505+
return prob switch
506+
{
507+
var p when p.IsEmpty => _apiClient.PutAsync(url, userAccessToken),
508+
_ => Task.FromResult(new RestApiResponse(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
509+
};
510+
}
450511
}

src/NoFrixion.MoneyMoov/Models/Merchant/Merchant.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ public class Merchant
179179
/// </summary>
180180
public List<CurrencyTypeEnum> AccountCurrencies { get; set; } = [];
181181

182+
/// <summary>
183+
/// If the merchant is a child merchant, this property contains information about the parent merchant.
184+
/// </summary>
185+
public ParentMerchant? ParentMerchant { get; set; }
186+
182187
/// <summary>
183188
/// Gets the most appropriate display name for the merchant which
184189
/// means use the trading name if set and if not, default to the business name.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// -----------------------------------------------------------------------------
2+
// Filename: ParentMerchant.cs
3+
//
4+
// Description: Model to represent a Parent Merchant in MoneyMoov.:
5+
//
6+
// Author(s):
7+
// Donal O'Connor ([email protected])
8+
//
9+
// History:
10+
// 09 10 2025 Donal O'Connor Created, Harcourt St, Dublin, Ireland.
11+
//
12+
// License:
13+
// Proprietary NoFrixion.
14+
// -----------------------------------------------------------------------------
15+
16+
namespace NoFrixion.MoneyMoov.Models;
17+
18+
public class ParentMerchant
19+
{
20+
public Guid ID { get; set; }
21+
22+
public string? Name { get; set; }
23+
}

src/NoFrixion.MoneyMoov/MoneyMoovUrlBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ public static string ChildMerchantsUrl(string moneyMoovBaseUrl, Guid parentMerch
158158

159159
public static string MerchantRoleUserAssignmentsUrl(string moneyMoovBaseUrl, Guid roleUserID)
160160
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.merchants}/{MoneyMoovResources.roleusers}/{roleUserID}";
161+
162+
public static string MerchantsPagedUrl(string moneyMoovBaseUrl,
163+
int? pageNumber,
164+
int? pageSize,
165+
string? search,
166+
string? sort)
167+
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.merchants}/paged" +
168+
$"?pageNumber={pageNumber}&pageSize={pageSize}&search={search}&sort={sort}";
169+
170+
public static string SetParentMerchantUrl(string moneyMoovBaseUrl, Guid merchantID, Guid parentMerchantID)
171+
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.merchants}/{merchantID}/parent/{parentMerchantID}";
161172
}
162173

163174
/// <summary>

0 commit comments

Comments
 (0)