-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cd45e1
commit 31f553d
Showing
27 changed files
with
605 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using System.Text.Json; | ||
using Mercoa.Client; | ||
using Mercoa.Client.EntityGroup; | ||
|
||
#nullable enable | ||
|
||
namespace Mercoa.Client.EntityGroup; | ||
|
||
public class EntityGroupClient | ||
{ | ||
private RawClient _client; | ||
|
||
public EntityGroupClient(RawClient client) | ||
{ | ||
_client = client; | ||
Invoice = new InvoiceClient(_client); | ||
} | ||
|
||
public InvoiceClient Invoice { get; } | ||
|
||
/// <summary> | ||
/// Get all entity groups. If using a JWT, will return all groups the entity is part of. If using an API key, will return all groups for the organization. | ||
/// </summary> | ||
public async Task<EntityGroupFindResponse> GetAllAsync(EntityGroupFindRequest request) | ||
{ | ||
var _query = new Dictionary<string, object>() { }; | ||
if (request.Limit != null) | ||
{ | ||
_query["limit"] = request.Limit; | ||
} | ||
if (request.StartingAfter != null) | ||
{ | ||
_query["startingAfter"] = request.StartingAfter; | ||
} | ||
var response = await _client.MakeRequestAsync( | ||
new RawClient.ApiRequest | ||
{ | ||
Method = HttpMethod.Get, | ||
Path = "/entityGroups", | ||
Query = _query | ||
} | ||
); | ||
string responseBody = await response.Raw.Content.ReadAsStringAsync(); | ||
if (response.StatusCode >= 200 && response.StatusCode < 400) | ||
{ | ||
return JsonSerializer.Deserialize<EntityGroupFindResponse>(responseBody); | ||
} | ||
throw new Exception(responseBody); | ||
} | ||
|
||
/// <summary> | ||
/// Create an entity group | ||
/// </summary> | ||
public async Task<EntityGroupResponse> CreateAsync(EntityGroupRequest request) | ||
{ | ||
var response = await _client.MakeRequestAsync( | ||
new RawClient.ApiRequest | ||
{ | ||
Method = HttpMethod.Post, | ||
Path = "/entityGroup", | ||
Body = request | ||
} | ||
); | ||
string responseBody = await response.Raw.Content.ReadAsStringAsync(); | ||
if (response.StatusCode >= 200 && response.StatusCode < 400) | ||
{ | ||
return JsonSerializer.Deserialize<EntityGroupResponse>(responseBody); | ||
} | ||
throw new Exception(responseBody); | ||
} | ||
|
||
/// <summary> | ||
/// Get an entity group | ||
/// </summary> | ||
public async Task<EntityGroupResponse> GetAsync(string entityGroupId) | ||
{ | ||
var response = await _client.MakeRequestAsync( | ||
new RawClient.ApiRequest | ||
{ | ||
Method = HttpMethod.Get, | ||
Path = $"/entityGroup/{entityGroupId}" | ||
} | ||
); | ||
string responseBody = await response.Raw.Content.ReadAsStringAsync(); | ||
if (response.StatusCode >= 200 && response.StatusCode < 400) | ||
{ | ||
return JsonSerializer.Deserialize<EntityGroupResponse>(responseBody); | ||
} | ||
throw new Exception(responseBody); | ||
} | ||
|
||
/// <summary> | ||
/// Update an entity group | ||
/// </summary> | ||
public async Task<EntityGroupResponse> UpdateAsync( | ||
string entityGroupId, | ||
EntityGroupRequest request | ||
) | ||
{ | ||
var response = await _client.MakeRequestAsync( | ||
new RawClient.ApiRequest | ||
{ | ||
Method = HttpMethod.Post, | ||
Path = $"/entityGroup/{entityGroupId}", | ||
Body = request | ||
} | ||
); | ||
string responseBody = await response.Raw.Content.ReadAsStringAsync(); | ||
if (response.StatusCode >= 200 && response.StatusCode < 400) | ||
{ | ||
return JsonSerializer.Deserialize<EntityGroupResponse>(responseBody); | ||
} | ||
throw new Exception(responseBody); | ||
} | ||
|
||
/// <summary> | ||
/// Delete an entity group | ||
/// </summary> | ||
public async void DeleteAsync(string entityGroupId) | ||
{ | ||
var response = await _client.MakeRequestAsync( | ||
new RawClient.ApiRequest | ||
{ | ||
Method = HttpMethod.Delete, | ||
Path = $"/entityGroup/{entityGroupId}" | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
using System.Text.Json; | ||
using Mercoa.Client; | ||
using Mercoa.Client.EntityGroup; | ||
|
||
#nullable enable | ||
|
||
namespace Mercoa.Client.EntityGroup; | ||
|
||
public class InvoiceClient | ||
{ | ||
private RawClient _client; | ||
|
||
public InvoiceClient(RawClient client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
/// <summary> | ||
/// Get invoices for an entity group with the given filters. | ||
/// </summary> | ||
public async Task<FindInvoiceResponse> FindAsync(EntityGetInvoicesRequest request) | ||
{ | ||
var _query = new Dictionary<string, object>() { }; | ||
if (request.ExcludePayables != null) | ||
{ | ||
_query["excludePayables"] = request.ExcludePayables; | ||
} | ||
if (request.ExcludeReceivables != null) | ||
{ | ||
_query["excludeReceivables"] = request.ExcludeReceivables; | ||
} | ||
if (request.StartDate != null) | ||
{ | ||
_query["startDate"] = request.StartDate; | ||
} | ||
if (request.EndDate != null) | ||
{ | ||
_query["endDate"] = request.EndDate; | ||
} | ||
if (request.OrderBy != null) | ||
{ | ||
_query["orderBy"] = request.OrderBy; | ||
} | ||
if (request.OrderDirection != null) | ||
{ | ||
_query["orderDirection"] = request.OrderDirection; | ||
} | ||
if (request.Limit != null) | ||
{ | ||
_query["limit"] = request.Limit; | ||
} | ||
if (request.StartingAfter != null) | ||
{ | ||
_query["startingAfter"] = request.StartingAfter; | ||
} | ||
if (request.Metadata != null) | ||
{ | ||
_query["metadata"] = request.Metadata; | ||
} | ||
if (request.Search != null) | ||
{ | ||
_query["search"] = request.Search; | ||
} | ||
if (request.PayerId != null) | ||
{ | ||
_query["payerId"] = request.PayerId; | ||
} | ||
if (request.VendorId != null) | ||
{ | ||
_query["vendorId"] = request.VendorId; | ||
} | ||
if (request.ApproverId != null) | ||
{ | ||
_query["approverId"] = request.ApproverId; | ||
} | ||
if (request.ApproverAction != null) | ||
{ | ||
_query["approverAction"] = request.ApproverAction; | ||
} | ||
if (request.InvoiceId != null) | ||
{ | ||
_query["invoiceId"] = request.InvoiceId; | ||
} | ||
if (request.Status != null) | ||
{ | ||
_query["status"] = request.Status; | ||
} | ||
var response = await _client.MakeRequestAsync( | ||
new RawClient.ApiRequest | ||
{ | ||
Method = HttpMethod.Get, | ||
Path = "/invoices", | ||
Query = _query | ||
} | ||
); | ||
string responseBody = await response.Raw.Content.ReadAsStringAsync(); | ||
if (response.StatusCode >= 200 && response.StatusCode < 400) | ||
{ | ||
return JsonSerializer.Deserialize<FindInvoiceResponse>(responseBody); | ||
} | ||
throw new Exception(responseBody); | ||
} | ||
|
||
/// <summary> | ||
/// Get invoice metrics for an entity group with the given filters. Invoices will be grouped by currency. If none of excludePayables, excludeReceivables, payerId, vendorId, or invoiceId status filters are provided, excludeReceivables will be set to true. | ||
/// </summary> | ||
public async Task<IEnumerable<InvoiceMetricsResponse>> MetricsAsync( | ||
GroupInvoiceMetricsRequest request | ||
) | ||
{ | ||
var _query = new Dictionary<string, object>() { }; | ||
if (request.Search != null) | ||
{ | ||
_query["search"] = request.Search; | ||
} | ||
if (request.ExcludePayables != null) | ||
{ | ||
_query["excludePayables"] = request.ExcludePayables; | ||
} | ||
if (request.ExcludeReceivables != null) | ||
{ | ||
_query["excludeReceivables"] = request.ExcludeReceivables; | ||
} | ||
if (request.ReturnByDate != null) | ||
{ | ||
_query["returnByDate"] = request.ReturnByDate; | ||
} | ||
if (request.PayerId != null) | ||
{ | ||
_query["payerId"] = request.PayerId; | ||
} | ||
if (request.VendorId != null) | ||
{ | ||
_query["vendorId"] = request.VendorId; | ||
} | ||
if (request.ApproverId != null) | ||
{ | ||
_query["approverId"] = request.ApproverId; | ||
} | ||
if (request.InvoiceId != null) | ||
{ | ||
_query["invoiceId"] = request.InvoiceId; | ||
} | ||
if (request.Status != null) | ||
{ | ||
_query["status"] = request.Status; | ||
} | ||
if (request.DueDateStart != null) | ||
{ | ||
_query["dueDateStart"] = request.DueDateStart; | ||
} | ||
if (request.DueDateEnd != null) | ||
{ | ||
_query["dueDateEnd"] = request.DueDateEnd; | ||
} | ||
if (request.CreatedDateStart != null) | ||
{ | ||
_query["createdDateStart"] = request.CreatedDateStart; | ||
} | ||
if (request.CreatedDateEnd != null) | ||
{ | ||
_query["createdDateEnd"] = request.CreatedDateEnd; | ||
} | ||
if (request.Currency != null) | ||
{ | ||
_query["currency"] = request.Currency; | ||
} | ||
var response = await _client.MakeRequestAsync( | ||
new RawClient.ApiRequest | ||
{ | ||
Method = HttpMethod.Get, | ||
Path = "/invoice-metrics", | ||
Query = _query | ||
} | ||
); | ||
string responseBody = await response.Raw.Content.ReadAsStringAsync(); | ||
if (response.StatusCode >= 200 && response.StatusCode < 400) | ||
{ | ||
return JsonSerializer.Deserialize<IEnumerable<InvoiceMetricsResponse>>(responseBody); | ||
} | ||
throw new Exception(responseBody); | ||
} | ||
} |
Oops, something went wrong.