diff --git a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs index 54f1299..5189750 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -480,22 +480,29 @@ public async Task RedeemVoucher(Guid estateId, public async Task>> 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> 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 = 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, @@ -508,6 +515,7 @@ public async Task 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, @@ -523,23 +531,25 @@ public async Task 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); } diff --git a/TransactionProcessorACL/Controllers/MerchantController.cs b/TransactionProcessorACL/Controllers/MerchantController.cs index 780dae7..d66409a 100644 --- a/TransactionProcessorACL/Controllers/MerchantController.cs +++ b/TransactionProcessorACL/Controllers/MerchantController.cs @@ -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; @@ -49,28 +50,36 @@ public MerchantController(IMediator mediator, [Route("contracts")] public async Task 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> 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 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() {