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 @@ -33,6 +33,7 @@ public MediatorTests()
this.Requests.Add(TestData.VersionCheckCommand);
this.Requests.Add(TestData.GetVoucherQuery);
this.Requests.Add(TestData.RedeemVoucherCommand);
this.Requests.Add(TestData.GetMerchantContractsQuery);
}

[Fact]
Expand Down Expand Up @@ -142,5 +143,11 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
{
return new RedeemVoucherResponse();
}

public async Task<Result<List<ContractResponse>>> GetMerchantContracts(Guid estateId,
Guid merchantId,
CancellationToken cancellationToken) {
return Result.Success(new List<ContractResponse>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,21 @@ 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 @@ -35,4 +35,10 @@ public record ProcessReconciliationCommand(Guid EstateId,
Int32 TransactionCount,
Decimal TransactionValue)
: IRequest<Result<ProcessReconciliationResponse>>;
}

[ExcludeFromCodeCoverage]
public record MerchantQueries {
public record GetMerchantContractsQuery(Guid EstateId,Guid MerchantId) : IRequest<Result<List<ContractResponse>>>;

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
Guid contractId,
String voucherCode,
CancellationToken cancellationToken);

Task<Result<List<Models.ContractResponse>>> GetMerchantContracts(Guid estateId,
Guid merchantId,
CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SimpleResults;
using TransactionProcessor.DataTransferObjects.Responses.Contract;

namespace TransactionProcessorACL.BusinessLogic.Services
{
Expand Down Expand Up @@ -476,6 +477,79 @@
return response;
}

public async Task<Result<List<Models.ContractResponse>>> GetMerchantContracts(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;

Check notice on line 489 in TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs#L489

Remove the unused local variable 'response'.

Result<List<TransactionProcessor.DataTransferObjects.Responses.Contract.ContractResponse>> result = await this.TransactionProcessorClient.GetMerchantContracts(accessToken.AccessToken, estateId, merchantId, cancellationToken);

if (result.IsFailed)

Check failure on line 493 in TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs#L493

Add curly braces around the nested statement(s) in this 'if' block.
return Result.Failure($"Error getting merchant contracts {result.Message}");

List<Models.ContractResponse> models = new();

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractResponse contractResponse in result.Data) {
var contractModel = new ContractResponse {
ContractId = contractResponse.ContractId,
ContractReportingId = contractResponse.ContractReportingId,
Description = contractResponse.Description,
EstateId = contractResponse.EstateId,
EstateReportingId = contractResponse.EstateReportingId,
OperatorId = contractResponse.OperatorId,
OperatorName = contractResponse.OperatorName,
Products = new()
};

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProduct contractResponseProduct in contractResponse.Products) {
var productModel = new ContractProduct {
Value = contractResponseProduct.Value,
DisplayText = contractResponseProduct.DisplayText,
Name = contractResponseProduct.Name,
ProductId = contractResponseProduct.ProductId,
ProductReportingId = contractResponseProduct.ProductReportingId,
ProductType = contractResponseProduct.ProductType switch {
TransactionProcessor.DataTransferObjects.Responses.Contract.ProductType.BillPayment => ProductType.BillPayment,
TransactionProcessor.DataTransferObjects.Responses.Contract.ProductType.MobileTopup => ProductType.MobileTopup,
TransactionProcessor.DataTransferObjects.Responses.Contract.ProductType.Voucher => ProductType.Voucher,
_ => ProductType.NotSet
},
TransactionFees = new()
};

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProductTransactionFee contractProductTransactionFee in contractResponseProduct.TransactionFees) {
var transactionFeeModel = new ContractProductTransactionFee {
Value = contractProductTransactionFee.Value,
Description = contractProductTransactionFee.Description,
CalculationType = contractProductTransactionFee.CalculationType switch {

Check notice on line 530 in TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs#L530

Replace this 'switch' expression with a ternary conditional operator to increase readability.
TransactionProcessor.DataTransferObjects.Responses.Contract.CalculationType.Fixed => CalculationType.Fixed,
_ => CalculationType.Percentage,
},
FeeType = contractProductTransactionFee.FeeType switch {

Check notice on line 534 in TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs#L534

Replace this 'switch' expression with a ternary conditional operator to increase readability.
TransactionProcessor.DataTransferObjects.Responses.Contract.FeeType.Merchant => FeeType.Merchant,
_ => FeeType.ServiceProvider,
},
TransactionFeeId = contractProductTransactionFee.TransactionFeeId,
TransactionFeeReportingId = contractProductTransactionFee.TransactionFeeReportingId
};
productModel.TransactionFees.Add(transactionFeeModel);
}

contractModel.Products.Add(productModel);
}

models.Add(contractModel);
}

return Result.Success(models);
}

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

namespace TransactionProcessorACL.DataTransferObjects.Responses {
public class ContractResponse
{
[JsonProperty("contract_id")]
public Guid ContractId { get; set; }

[JsonProperty("contract_reporting_id")]
public int ContractReportingId { get; set; }

[JsonProperty("description")]
public string Description { get; set; }

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

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

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

[JsonProperty("operator_name")]
public string OperatorName { get; set; }

[JsonProperty("products")]
public List<ContractProduct> Products { get; set; }
}

public class ContractProduct
{
public string DisplayText { get; set; }

public string Name { get; set; }

public Guid ProductId { get; set; }

public int ProductReportingId { get; set; }

public List<ContractProductTransactionFee> TransactionFees { get; set; }

public Decimal? Value { get; set; }

public ProductType ProductType { get; set; }
}

public class ContractProductTransactionFee
{
public CalculationType CalculationType { get; set; }

public FeeType FeeType { get; set; }

public string Description { get; set; }

public Guid TransactionFeeId { get; set; }

public int TransactionFeeReportingId { get; set; }

public Decimal Value { get; set; }
}

public enum FeeType
{
Merchant,
ServiceProvider,
}

public enum CalculationType
{
Fixed,
Percentage,
}

public enum ProductType
{
NotSet,
MobileTopup,
Voucher,
BillPayment,
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace TransactionProcessorACL.DataTransferObjects.Responses{
using Newtonsoft.Json;
using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

[ExcludeFromCodeCoverage]
public class GetVoucherResponseMessage{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public async Task GivenIAmLoggedInAsWithPasswordForMerchantForEstateWithClient(S
public async Task GivenICreateAContractWithTheFollowingValues(DataTable table){
var estates = this.TestingContext.Estates.Select(e => e.EstateDetails).ToList();
List<(EstateDetails, CreateContractRequest)> requests = table.Rows.ToCreateContractRequests(estates);
List<ContractResponse> responses = await this.TransactionProcessorSteps.GivenICreateAContractWithTheFollowingValues(this.TestingContext.AccessToken, requests);
foreach (ContractResponse contractResponse in responses)
List<TransactionProcessor.DataTransferObjects.Responses.Contract.ContractResponse> responses = await this.TransactionProcessorSteps.GivenICreateAContractWithTheFollowingValues(this.TestingContext.AccessToken, requests);
foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractResponse contractResponse in responses)
{
var estate = this.TestingContext.Estates.Single(e => e.EstateDetails.EstateId == contractResponse.EstateId);
estate.EstateDetails.AddContract(contractResponse.ContractId, contractResponse.Description, contractResponse.OperatorId);
Expand Down
74 changes: 74 additions & 0 deletions TransactionProcessorACL.Models/ContractResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;

namespace TransactionProcessorACL.Models {
public class ContractResponse
{
public Guid ContractId { get; set; }
public int ContractReportingId { get; set; }

public string Description { get; set; }

public Guid EstateId { get; set; }

public int EstateReportingId { get; set; }

public Guid OperatorId { get; set; }

public string OperatorName { get; set; }

public List<ContractProduct> Products { get; set; }
}

public class ContractProduct
{
public string DisplayText { get; set; }

public string Name { get; set; }

public Guid ProductId { get; set; }

public int ProductReportingId { get; set; }

public List<ContractProductTransactionFee> TransactionFees { get; set; }

public Decimal? Value { get; set; }

public ProductType ProductType { get; set; }
}

public class ContractProductTransactionFee
{
public CalculationType CalculationType { get; set; }

public FeeType FeeType { get; set; }

public string Description { get; set; }

public Guid TransactionFeeId { get; set; }

public int TransactionFeeReportingId { get; set; }

public Decimal Value { get; set; }
}

public enum FeeType
{
Merchant,
ServiceProvider,
}

public enum CalculationType
{
Fixed,
Percentage,
}

public enum ProductType
{
NotSet,
MobileTopup,
Voucher,
BillPayment,
}
}
2 changes: 2 additions & 0 deletions TransactionProcessorACL.Testing/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ public class TestData

public static VersionCheckCommands.VersionCheckCommand VersionCheckCommand = new(TestData.ApplicationVersion);
public static VoucherCommands.RedeemVoucherCommand RedeemVoucherCommand => new(TestData.EstateId, TestData.ContractId, TestData.VoucherCode);
public static MerchantQueries.GetMerchantContractsQuery GetMerchantContractsQuery => new(EstateId,MerchantId);

public static VoucherQueries.GetVoucherQuery GetVoucherQuery => new(TestData.EstateId, TestData.ContractId, TestData.VoucherCode);

public static String VoucherCode = "1231231234";
Expand Down
5 changes: 4 additions & 1 deletion TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SimpleResults;
using System.Collections.Generic;
using SimpleResults;

namespace TransactionProcessorACL.Bootstrapper
{
Expand Down Expand Up @@ -34,6 +35,8 @@ public MediatorRegistry()

this.AddSingleton<IRequestHandler<VoucherQueries.GetVoucherQuery, Result<GetVoucherResponse>>, VoucherRequestHandler>();
this.AddSingleton<IRequestHandler<VoucherCommands.RedeemVoucherCommand, Result<RedeemVoucherResponse>>, VoucherRequestHandler>();

this.AddSingleton<IRequestHandler<MerchantQueries.GetMerchantContractsQuery, Result<List<ContractResponse>>>, MerchantRequestHandler>();
}

#endregion
Expand Down
6 changes: 3 additions & 3 deletions TransactionProcessorACL/Common/ClaimsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace TransactionProcessorACL.Common
using System.Security.Claims;
using Shared.Exceptions;

[ExcludeFromCodeCoverage]
public class ClaimsHelper
//[ExcludeFromCodeCoverage]
/*public class ClaimsHelper
{
#region Methods

Expand Down Expand Up @@ -111,5 +111,5 @@ public static Boolean IsUserRolesValid(ClaimsPrincipal user, String[] allowedRol
}

#endregion
}
}*/
}
Loading
Loading