Skip to content

Commit 5d79a54

Browse files
Enhance logging in GetMerchantContracts and MerchantController
Added detailed logging in the GetMerchantContracts method to track access token retrieval, contract counts, and processing steps. Commented out unused transaction fee processing code for potential future use. Improved logging in MerchantController to monitor application version, claims retrieval, and record counts, enhancing overall observability and traceability of application behavior.
1 parent 9beece0 commit 5d79a54

2 files changed

Lines changed: 41 additions & 22 deletions

File tree

TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,29 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
480480
public async Task<Result<List<Models.ContractResponse>>> GetMerchantContracts(Guid estateId,
481481
Guid merchantId,
482482
CancellationToken cancellationToken) {
483+
Logger.LogInformation($"GetMerchantContracts: {estateId} {merchantId}");
483484
// Get a client token to call the Transaction Processor
484485
String clientId = ConfigurationReader.GetValue("AppSettings", "ClientId");
485486
String clientSecret = ConfigurationReader.GetValue("AppSettings", "ClientSecret");
486487

487488
TokenResponse accessToken = await this.SecurityServiceClient.GetToken(clientId, clientSecret, cancellationToken);
488-
489-
ProcessLogonTransactionResponse response = null;
489+
if (accessToken == null) {
490+
Logger.LogInformation($"token is null");
491+
return Result.Failure("Error getting access token");
492+
}
493+
Logger.LogInformation($"{JsonConvert.SerializeObject(accessToken)}");
490494

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

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

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

498503
foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractResponse contractResponse in result.Data) {
504+
Logger.LogInformation($"Processing contract {contractResponse.OperatorName}");
505+
499506
ContractResponse contractModel = new ContractResponse {
500507
ContractId = contractResponse.ContractId,
501508
ContractReportingId = contractResponse.ContractReportingId,
@@ -508,6 +515,7 @@ public async Task<RedeemVoucherResponse> RedeemVoucher(Guid estateId,
508515
};
509516

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

526-
foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProductTransactionFee contractProductTransactionFee in contractResponseProduct.TransactionFees) {
527-
ContractProductTransactionFee transactionFeeModel = new ContractProductTransactionFee {
528-
Value = contractProductTransactionFee.Value,
529-
Description = contractProductTransactionFee.Description,
530-
CalculationType = contractProductTransactionFee.CalculationType switch {
531-
TransactionProcessor.DataTransferObjects.Responses.Contract.CalculationType.Fixed => CalculationType.Fixed,
532-
_ => CalculationType.Percentage,
533-
},
534-
FeeType = contractProductTransactionFee.FeeType switch {
535-
TransactionProcessor.DataTransferObjects.Responses.Contract.FeeType.Merchant => FeeType.Merchant,
536-
_ => FeeType.ServiceProvider,
537-
},
538-
TransactionFeeId = contractProductTransactionFee.TransactionFeeId,
539-
TransactionFeeReportingId = contractProductTransactionFee.TransactionFeeReportingId
540-
};
541-
productModel.TransactionFees.Add(transactionFeeModel);
542-
}
534+
// Leave here but not used atm
535+
//foreach (TransactionProcessor.DataTransferObjects.Responses.Contract.ContractProductTransactionFee contractProductTransactionFee in contractResponseProduct.TransactionFees) {
536+
// Logger.LogInformation($"Processing contract product fee {contractProductTransactionFee.Description}");
537+
// ContractProductTransactionFee transactionFeeModel = new ContractProductTransactionFee {
538+
// Value = contractProductTransactionFee.Value,
539+
// Description = contractProductTransactionFee.Description,
540+
// CalculationType = contractProductTransactionFee.CalculationType switch {
541+
// TransactionProcessor.DataTransferObjects.Responses.Contract.CalculationType.Fixed => CalculationType.Fixed,
542+
// _ => CalculationType.Percentage,
543+
// },
544+
// FeeType = contractProductTransactionFee.FeeType switch {
545+
// TransactionProcessor.DataTransferObjects.Responses.Contract.FeeType.Merchant => FeeType.Merchant,
546+
// _ => FeeType.ServiceProvider,
547+
// },
548+
// TransactionFeeId = contractProductTransactionFee.TransactionFeeId,
549+
// TransactionFeeReportingId = contractProductTransactionFee.TransactionFeeReportingId
550+
// };
551+
// productModel.TransactionFees.Add(transactionFeeModel);
552+
//}
543553

544554
contractModel.Products.Add(productModel);
545555
}

TransactionProcessorACL/Controllers/MerchantController.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Diagnostics.CodeAnalysis;
1212
using System.Threading;
1313
using System.Threading.Tasks;
14+
using Shared.Logger;
1415
using TransactionProcessorACL.BusinessLogic.Requests;
1516
using TransactionProcessorACL.Factories;
1617
using TransactionProcessorACL.Models;
@@ -49,28 +50,36 @@ public MerchantController(IMediator mediator,
4950
[Route("contracts")]
5051
public async Task<IActionResult> GetMerchantContracts([FromQuery] String applicationVersion,
5152
CancellationToken cancellationToken) {
53+
Logger.LogInformation($"Application version {applicationVersion}");
54+
5255
if (ClaimsHelper.IsPasswordToken(this.User) == false) {
5356
return this.Forbid();
5457
}
55-
58+
Logger.LogInformation($"user is nto null");
5659
// Do the software version check
5760
VersionCheckCommand versionCheckCommand = new(applicationVersion);
5861
Result versionCheckResult = await this.Mediator.Send(versionCheckCommand, cancellationToken);
5962
if (versionCheckResult.IsFailed)
6063
return this.StatusCode(505);
6164

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

70+
Logger.LogInformation($"got claims ok");
71+
Logger.LogInformation($"estate id {claimsResult.Data.estateId}");
72+
Logger.LogInformation($"merchant id {claimsResult.Data.merchantId}");
73+
6674
MerchantQueries.GetMerchantContractsQuery query = new(claimsResult.Data.estateId, claimsResult.Data.merchantId);
6775
Result<List<ContractResponse>> result = await this.Mediator.Send(query, cancellationToken);
68-
76+
Logger.LogInformation($"request sent");
6977
if (result.IsFailed)
7078
return ResultHelpers.CreateFailure(result).ToActionResultX();
71-
79+
Logger.LogInformation($"result was not failed");
7280
List<DataTransferObjects.Responses.ContractResponse> responses = new();
7381
// Now need to convert to the DTO type for returning to the caller
82+
Logger.LogInformation($"record count is {result.Data.Count}");
7483
foreach (ContractResponse contractModel in result.Data)
7584
{
7685
DataTransferObjects.Responses.ContractResponse contractResponse = new() {

0 commit comments

Comments
 (0)