Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public MediatorTests()
this.Requests.Add(TestData.GetVoucherQuery);
this.Requests.Add(TestData.RedeemVoucherCommand);
this.Requests.Add(TestData.GetMerchantContractsQuery);
this.Requests.Add(TestData.GetMerchantQuery);
}

[Fact]
Expand Down Expand Up @@ -149,5 +150,11 @@ public async Task<Result<List<ContractResponse>>> GetMerchantContracts(Guid esta
CancellationToken cancellationToken) {
return Result.Success(new List<ContractResponse>());
}

public async Task<Result<MerchantResponse>> GetMerchant(Guid estateId,
Guid merchantId,
CancellationToken cancellationToken) {
return Result.Success(new MerchantResponse());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using SimpleResults;
using TransactionProcessorACL.BusinessLogic.Requests;
using TransactionProcessorACL.BusinessLogic.Services;
using TransactionProcessorACL.Models;

namespace TransactionProcessorACL.BusinessLogic.RequestHandlers;

public class MerchantRequestHandler : IRequestHandler<MerchantQueries.GetMerchantContractsQuery, Result<List<ContractResponse>>>,
IRequestHandler<MerchantQueries.GetMerchantQuery, Result<MerchantResponse>> {
#region Fields

private readonly ITransactionProcessorACLApplicationService ApplicationService;

#endregion

public MerchantRequestHandler(ITransactionProcessorACLApplicationService applicationService) {
this.ApplicationService = applicationService;
}

public async Task<Result<List<ContractResponse>>> Handle(MerchantQueries.GetMerchantContractsQuery request,
CancellationToken cancellationToken) {
return await this.ApplicationService.GetMerchantContracts(request.EstateId, request.MerchantId, cancellationToken);
}

public async Task<Result<MerchantResponse>> Handle(MerchantQueries.GetMerchantQuery request,
CancellationToken cancellationToken) {
return await this.ApplicationService.GetMerchant(request.EstateId, request.MerchantId, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -50,21 +49,4 @@ public async Task<Result<RedeemVoucherResponse>> Handle(VoucherCommands.RedeemVo

#endregion
}

public class MerchantRequestHandler : IRequestHandler<MerchantQueries.GetMerchantContractsQuery, Result<List<ContractResponse>>> {
#region Fields

private readonly ITransactionProcessorACLApplicationService ApplicationService;

#endregion

public MerchantRequestHandler(ITransactionProcessorACLApplicationService applicationService) {
this.ApplicationService = applicationService;
}

public async Task<Result<List<ContractResponse>>> Handle(MerchantQueries.GetMerchantContractsQuery request,
CancellationToken cancellationToken) {
return await this.ApplicationService.GetMerchantContracts(request.EstateId, request.MerchantId, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Diagnostics.CodeAnalysis;
using MediatR;
using SimpleResults;
using TransactionProcessor.DataTransferObjects.Responses.Merchant;
using TransactionProcessorACL.Models;
using MerchantResponse = TransactionProcessorACL.Models.MerchantResponse;

namespace TransactionProcessorACL.BusinessLogic.Requests;

Expand Down Expand Up @@ -40,5 +42,6 @@ public record ProcessReconciliationCommand(Guid EstateId,
[ExcludeFromCodeCoverage]
public record MerchantQueries {
public record GetMerchantContractsQuery(Guid EstateId,Guid MerchantId) : IRequest<Result<List<ContractResponse>>>;
public record GetMerchantQuery(Guid EstateId, Guid MerchantId) : IRequest<Result<MerchantResponse>>;

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,9 @@ Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
Task<Result<List<Models.ContractResponse>>> GetMerchantContracts(Guid estateId,
Guid merchantId,
CancellationToken cancellationToken);

Task<Result<Models.MerchantResponse>> GetMerchant(Guid estateId,
Guid merchantId,
CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
List<Models.ContractResponse> models = new();

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractResponse contractResponse in result.Data) {
var contractModel = new ContractResponse {
ContractResponse contractModel = new ContractResponse {
ContractId = contractResponse.ContractId,
ContractReportingId = contractResponse.ContractReportingId,
Description = contractResponse.Description,
Expand All @@ -508,7 +508,7 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
};

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProduct contractResponseProduct in contractResponse.Products) {
var productModel = new ContractProduct {
ContractProduct productModel = new ContractProduct {
Value = contractResponseProduct.Value,
DisplayText = contractResponseProduct.DisplayText,
Name = contractResponseProduct.Name,
Expand All @@ -524,7 +524,7 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
};

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProductTransactionFee contractProductTransactionFee in contractResponseProduct.TransactionFees) {
var transactionFeeModel = new ContractProductTransactionFee {
ContractProductTransactionFee transactionFeeModel = new ContractProductTransactionFee {
Value = contractProductTransactionFee.Value,
Description = contractProductTransactionFee.Description,
CalculationType = contractProductTransactionFee.CalculationType switch {
Expand All @@ -550,6 +550,103 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
return Result.Success(models);
}

public async Task<Result<MerchantResponse>> GetMerchant(Guid estateId,
Guid merchantId,
CancellationToken cancellationToken) {
// Get a client token to call the Transaction Processor
String clientId = ConfigurationReader.GetValue("AppSettings", "ClientId");
String clientSecret = ConfigurationReader.GetValue("AppSettings", "ClientSecret");

TokenResponse accessToken = await this.SecurityServiceClient.GetToken(clientId, clientSecret, cancellationToken);

ProcessLogonTransactionResponse response = null;

Result<TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantResponse> result = await this.TransactionProcessorClient.GetMerchant(accessToken.AccessToken, estateId, merchantId, cancellationToken);

if (result.IsFailed)
return Result.Failure($"Error getting merchant contracts {result.Message}");
MerchantResponse merchantResponse = new();
merchantResponse.MerchantId = result.Data.MerchantId;
merchantResponse.EstateId = result.Data.EstateId;
merchantResponse.MerchantName = result.Data.MerchantName;
merchantResponse.EstateReportingId = result.Data.EstateReportingId;
merchantResponse.MerchantReference = result.Data.MerchantReference;
merchantResponse.NextStatementDate = result.Data.NextStatementDate;
merchantResponse.SettlementSchedule = result.Data.SettlementSchedule switch {
TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Immediate => Models.SettlementSchedule.Immediate,
TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Weekly => SettlementSchedule.Weekly,
TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Monthly => SettlementSchedule.Monthly,
_ => SettlementSchedule.NotSet
};
merchantResponse.Contracts = new();
merchantResponse.Contacts = new();
merchantResponse.Addresses = new();
merchantResponse.Devices = new();
merchantResponse.Operators = new();

foreach (TransactionProcessor.DataTransferObjects.Responses.Merchant.AddressResponse address in result.Data.Addresses)
{
AddressResponse addressResponse = new()
{
AddressId = address.AddressId,
AddressLine1 = address.AddressLine1,
AddressLine2 = address.AddressLine2,
AddressLine3 = address.AddressLine3,
AddressLine4 = address.AddressLine4,
Country = address.Country,
PostalCode = address.PostalCode,
Region = address.Region,
Town = address.Town
};
merchantResponse.Addresses.Add(addressResponse);
}

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse contact in result.Data.Contacts)
{
merchantResponse.Contacts.Add(new ContactResponse
{
ContactId = contact.ContactId,
ContactName = contact.ContactName,
ContactPhoneNumber = contact.ContactPhoneNumber,
ContactEmailAddress = contact.ContactEmailAddress
});
}

foreach (var merchantContract in result.Data.Contracts)
{
var contract = new MerchantContractResponse
{
ContractId = merchantContract.ContractId,
IsDeleted = merchantContract.IsDeleted,
ContractProducts = new()
};
foreach (Guid contractProduct in merchantContract.ContractProducts)
{
contract.ContractProducts.Add(contractProduct);
}
merchantResponse.Contracts.Add(contract);
}

foreach (KeyValuePair<Guid, string> device in result.Data.Devices)
{
merchantResponse.Devices.Add(device.Key, device.Value);
}

foreach (var merchantOperator in result.Data.Operators)
{
merchantResponse.Operators.Add(new MerchantOperatorResponse
{
OperatorId = merchantOperator.OperatorId,
IsDeleted = merchantOperator.IsDeleted,
MerchantNumber = merchantOperator.MerchantNumber,
Name = merchantOperator.Name,
TerminalNumber = merchantOperator.TerminalNumber
});
}

return merchantResponse;
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace TransactionProcessorACL.DataTransferObjects.Responses {

[ExcludeFromCodeCoverage]
public class MerchantResponse
{
[JsonProperty("addresses")]
public List<AddressResponse> Addresses { get; set; }

[JsonProperty("contacts")]
public List<ContactResponse> Contacts { get; set; }

[JsonProperty("devices")]
public Dictionary<Guid, string> Devices { get; set; }

[JsonProperty("estate_id")]
public Guid EstateId { get; set; }

[JsonProperty("estate_reporting_id")]
public int EstateReportingId { get; set; }

[JsonProperty("merchant_id")]
public Guid MerchantId { get; set; }

[JsonProperty("merchant_reporting_id")]
public int MerchantReportingId { get; set; }

[JsonProperty("merchant_name")]
public string MerchantName { get; set; }

[JsonProperty("merchant_reference")]
public string MerchantReference { get; set; }

[JsonProperty("next_statement_date")]
public DateTime NextStatementDate { get; set; }

[JsonProperty("operators")]
public List<MerchantOperatorResponse> Operators { get; set; }

[JsonProperty("settlement_schedule")]
public SettlementSchedule SettlementSchedule { get; set; }

[JsonProperty("contracts")]
public List<MerchantContractResponse> Contracts { get; set; }
}

[ExcludeFromCodeCoverage]
public class AddressResponse
{
[JsonProperty("address_id")]
public Guid AddressId { get; set; }

[JsonProperty("address_line_1")]
public string AddressLine1 { get; set; }

[JsonProperty("address_line_2")]
public string AddressLine2 { get; set; }

[JsonProperty("address_line_3")]
public string AddressLine3 { get; set; }

[JsonProperty("address_line_4")]
public string AddressLine4 { get; set; }

[JsonProperty("country")]
public string Country { get; set; }

[JsonProperty("postal_code")]
public string PostalCode { get; set; }

[JsonProperty("region")]
public string Region { get; set; }

[JsonProperty("town")]
public string Town { get; set; }
}

[ExcludeFromCodeCoverage]
public class ContactResponse
{
[JsonProperty("contact_email_address")]
public string ContactEmailAddress { get; set; }

[JsonProperty("contact_id")]
public Guid ContactId { get; set; }

[JsonProperty("contact_name")]
public string ContactName { get; set; }

[JsonProperty("contact_phone_number")]
public string ContactPhoneNumber { get; set; }
}

[ExcludeFromCodeCoverage]
public class MerchantOperatorResponse
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("operator_id")]
public Guid OperatorId { get; set; }

[JsonProperty("merchant_number")]
public string MerchantNumber { get; set; }

[JsonProperty("terminal_number")]
public string TerminalNumber { get; set; }

[JsonProperty("is_deleted")]
public bool IsDeleted { get; set; }
}

[ExcludeFromCodeCoverage]
public class MerchantContractResponse
{
[JsonProperty("contract_id")]
public Guid ContractId { get; set; }

[JsonProperty("is_deleted")]
public bool IsDeleted { get; set; }

[JsonProperty("contract_products")]
public List<Guid> ContractProducts { get; set; }

public MerchantContractResponse() => this.ContractProducts = new List<Guid>();
}

public enum SettlementSchedule
{
NotSet,
Immediate,
Weekly,
Monthly,
}
}
Loading
Loading