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
Original file line number Diff line number Diff line change
Expand Up @@ -480,22 +480,29 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
public async Task<Result<List<Models.ContractResponse>>> GetMerchantContracts(Guid estateId,
Guid merchantId,
CancellationToken cancellationToken) {
Logger.LogInformation($"GetMerchantContracts: {estateId} {merchantId}");
// 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;
if (accessToken == null) {
Logger.LogInformation($"token is null");
return Result.Failure("Error getting access token");
}
Logger.LogInformation($"{JsonConvert.SerializeObject(accessToken)}");

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

if (result.IsFailed)
return Result.Failure($"Error getting merchant contracts {result.Message}");

Logger.LogInformation($"Got the merchant contracts {result.Data.Count}");
List<Models.ContractResponse> models = new();

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractResponse contractResponse in result.Data) {
Logger.LogInformation($"Processing contract {contractResponse.OperatorName}");

ContractResponse contractModel = new ContractResponse {
ContractId = contractResponse.ContractId,
ContractReportingId = contractResponse.ContractReportingId,
Expand All @@ -508,6 +515,7 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
};

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProduct contractResponseProduct in contractResponse.Products) {
Logger.LogInformation($"Processing contract product {contractResponseProduct.DisplayText}");
ContractProduct productModel = new ContractProduct {
Value = contractResponseProduct.Value,
DisplayText = contractResponseProduct.DisplayText,
Expand All @@ -523,23 +531,25 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
TransactionFees = new()
};

foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProductTransactionFee contractProductTransactionFee in contractResponseProduct.TransactionFees) {
ContractProductTransactionFee transactionFeeModel = new ContractProductTransactionFee {
Value = contractProductTransactionFee.Value,
Description = contractProductTransactionFee.Description,
CalculationType = contractProductTransactionFee.CalculationType switch {
TransactionProcessor.DataTransferObjects.Responses.Contract.CalculationType.Fixed => CalculationType.Fixed,
_ => CalculationType.Percentage,
},
FeeType = contractProductTransactionFee.FeeType switch {
TransactionProcessor.DataTransferObjects.Responses.Contract.FeeType.Merchant => FeeType.Merchant,
_ => FeeType.ServiceProvider,
},
TransactionFeeId = contractProductTransactionFee.TransactionFeeId,
TransactionFeeReportingId = contractProductTransactionFee.TransactionFeeReportingId
};
productModel.TransactionFees.Add(transactionFeeModel);
}
// Leave here but not used atm
//foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProductTransactionFee contractProductTransactionFee in contractResponseProduct.TransactionFees) {
// Logger.LogInformation($"Processing contract product fee {contractProductTransactionFee.Description}");
// ContractProductTransactionFee transactionFeeModel = new ContractProductTransactionFee {
// Value = contractProductTransactionFee.Value,
// Description = contractProductTransactionFee.Description,
// CalculationType = contractProductTransactionFee.CalculationType switch {
// TransactionProcessor.DataTransferObjects.Responses.Contract.CalculationType.Fixed => CalculationType.Fixed,
// _ => CalculationType.Percentage,
// },
// FeeType = contractProductTransactionFee.FeeType switch {
// TransactionProcessor.DataTransferObjects.Responses.Contract.FeeType.Merchant => FeeType.Merchant,
// _ => FeeType.ServiceProvider,
// },
// TransactionFeeId = contractProductTransactionFee.TransactionFeeId,
// TransactionFeeReportingId = contractProductTransactionFee.TransactionFeeReportingId
// };
// productModel.TransactionFees.Add(transactionFeeModel);
//}

contractModel.Products.Add(productModel);
}
Expand Down
15 changes: 12 additions & 3 deletions TransactionProcessorACL/Controllers/MerchantController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Shared.Logger;
using TransactionProcessorACL.BusinessLogic.Requests;
using TransactionProcessorACL.Factories;
using TransactionProcessorACL.Models;
Expand Down Expand Up @@ -49,28 +50,36 @@ public MerchantController(IMediator mediator,
[Route("contracts")]
public async Task<IActionResult> GetMerchantContracts([FromQuery] String applicationVersion,
CancellationToken cancellationToken) {
Logger.LogInformation($"Application version {applicationVersion}");

if (ClaimsHelper.IsPasswordToken(this.User) == false) {
return this.Forbid();
}

Logger.LogInformation($"user is nto null");
// Do the software version check
VersionCheckCommand versionCheckCommand = new(applicationVersion);
Result versionCheckResult = await this.Mediator.Send(versionCheckCommand, cancellationToken);
if (versionCheckResult.IsFailed)
return this.StatusCode(505);

Logger.LogInformation($"version check ok");
Result<(Guid estateId, Guid merchantId)> claimsResult = TransactionController.GetRequiredClaims(this.User);
if (claimsResult.IsFailed)
return this.Forbid();

Logger.LogInformation($"got claims ok");
Logger.LogInformation($"estate id {claimsResult.Data.estateId}");
Logger.LogInformation($"merchant id {claimsResult.Data.merchantId}");

MerchantQueries.GetMerchantContractsQuery query = new(claimsResult.Data.estateId, claimsResult.Data.merchantId);
Result<List<ContractResponse>> result = await this.Mediator.Send(query, cancellationToken);

Logger.LogInformation($"request sent");
if (result.IsFailed)
return ResultHelpers.CreateFailure(result).ToActionResultX();

Logger.LogInformation($"result was not failed");
List<DataTransferObjects.Responses.ContractResponse> responses = new();
// Now need to convert to the DTO type for returning to the caller
Logger.LogInformation($"record count is {result.Data.Count}");
foreach (ContractResponse contractModel in result.Data)
{
DataTransferObjects.Responses.ContractResponse contractResponse = new() {
Expand Down
Loading