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 @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageReference Include="Shared.EventStore" Version="2025.4.2" />
<PackageReference Include="Shared.EventStore" Version="2025.5.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ await context.VoucherProjectionStates.AddAsync(new VoucherProjectionState

VoucherManagementManager manager = new VoucherManagementManager(dbContextFactory.Object, aggregateService.Object);

Models.Voucher voucher = await manager.GetVoucherByCode(TestData.EstateId, TestData.VoucherCode, CancellationToken.None);

var result = await manager.GetVoucherByCode(TestData.EstateId, TestData.VoucherCode, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
Models.Voucher voucher = result.Data;
voucher.ShouldNotBeNull();
}

Expand Down Expand Up @@ -121,8 +122,9 @@ await context.VoucherProjectionStates.AddAsync(new VoucherProjectionState

VoucherManagementManager manager = new VoucherManagementManager(dbContextFactory.Object, aggregateService.Object);

Models.Voucher voucher = await manager.GetVoucherByTransactionId(TestData.EstateId, TestData.TransactionId, CancellationToken.None);

var result = await manager.GetVoucherByTransactionId(TestData.EstateId, TestData.TransactionId, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
Models.Voucher voucher = result.Data;
voucher.ShouldNotBeNull();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public async Task PataPawaPostPayProxy_ProcessLogonMessage_SuccessfulResponse_Me

PataPawaPostPayService.Setup(s => s.getLoginRequestAsync(It.IsAny<String>(), It.IsAny<String>())).ReturnsAsync(TestData.PataPawaPostPaidSuccessfulLoginResponse);

BusinessLogic.OperatorInterfaces.OperatorResponse logonResponse = await PataPawaPostPayProxy.ProcessLogonMessage(CancellationToken.None);

var logonResponseResult = await PataPawaPostPayProxy.ProcessLogonMessage(CancellationToken.None);
logonResponseResult.IsSuccess.ShouldBeTrue();
BusinessLogic.OperatorInterfaces.OperatorResponse logonResponse = logonResponseResult.Data;
logonResponse.ShouldNotBeNull();
logonResponse.IsSuccessful.ShouldBeTrue();
logonResponse.ResponseMessage.ShouldBe(TestData.PataPawaPostPaidSuccessfulLoginResponse.message);
Expand Down Expand Up @@ -88,14 +89,16 @@ public async Task PataPawaPostPayProxy_ProcessSaleMessage_VerifyAccount_Successf
.ReturnsAsync(TestData.PataPawaPostPaidSuccessfulVerifyAccountResponse);
MemoryCache.Set("PataPawaPostPayLogon", TestData.PataPawaPostPaidSuccessfulLoginOperatorResponse);

BusinessLogic.OperatorInterfaces.OperatorResponse saleResponse = await this.PataPawaPostPayProxy.ProcessSaleMessage(TestData.TransactionId,
var processSaleMessageResult = await this.PataPawaPostPayProxy.ProcessSaleMessage(TestData.TransactionId,
TestData.OperatorId,
TestData.Merchant,
TestData.TransactionDateTime,
TestData.TransactionReference,
TestData.AdditionalTransactionMetaDataForPataPawaVerifyAccount(),
CancellationToken.None);

processSaleMessageResult.IsSuccess.ShouldBeTrue();
BusinessLogic.OperatorInterfaces.OperatorResponse saleResponse = processSaleMessageResult.Data;
saleResponse.ShouldNotBeNull();
saleResponse.IsSuccessful.ShouldBeTrue();
saleResponse.ResponseMessage.ShouldBe("SUCCESS");
Expand Down Expand Up @@ -206,15 +209,16 @@ public async Task PataPawaPostPayProxy_ProcessSaleMessage_ProcessBill_Successful
.ReturnsAsync(TestData.PataPawaPostPaidSuccessfulProcessBillResponse);
this.MemoryCache.Set("PataPawaPostPayLogon", TestData.PataPawaPostPaidSuccessfulLoginOperatorResponse);

BusinessLogic.OperatorInterfaces.OperatorResponse saleResponse = await this.PataPawaPostPayProxy.ProcessSaleMessage(
var processSaleMessageResult = await this.PataPawaPostPayProxy.ProcessSaleMessage(
TestData.TransactionId,
TestData.OperatorId,
TestData.Merchant,
TestData.TransactionDateTime,
TestData.TransactionReference,
TestData.AdditionalTransactionMetaDataForPataPawaProcessBill(),
CancellationToken.None);

processSaleMessageResult.IsSuccess.ShouldBeTrue();
BusinessLogic.OperatorInterfaces.OperatorResponse saleResponse = processSaleMessageResult.Data;
saleResponse.ShouldNotBeNull();
saleResponse.IsSuccessful.ShouldBeTrue();
saleResponse.ResponseMessage.ShouldBe(TestData.PataPawaPostPaidSuccessfulProcessBillResponse.msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public async Task SafaricomPinlessProxy_ProcessLogonMessage_NullIsReturned() {
HttpClient httpClient = SetupMockHttpClient(responseMessage);

IOperatorProxy safaricomPinlessproxy = new SafaricomPinlessProxy(safaricomConfiguration, httpClient);
OperatorResponse operatorResponse = await safaricomPinlessproxy.ProcessLogonMessage(CancellationToken.None);
var processLogonMessageResult = await safaricomPinlessproxy.ProcessLogonMessage(CancellationToken.None);
processLogonMessageResult.IsSuccess.ShouldBeTrue();
OperatorResponse operatorResponse = processLogonMessageResult.Data;
operatorResponse.ShouldBeNull();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public async Task VoucherManagementProxy_ProcessLogonMessage_NullReturned() {

IOperatorProxy voucherManagementProxy = new VoucherManagementProxy(mediator.Object);

OperatorResponse operatorResponse = await voucherManagementProxy.ProcessLogonMessage(CancellationToken.None);

var processLogonMessageResult = await voucherManagementProxy.ProcessLogonMessage(CancellationToken.None);
processLogonMessageResult.IsSuccess.ShouldBeTrue();
OperatorResponse operatorResponse = processLogonMessageResult.Data;
operatorResponse.ShouldBeNull();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public async Task TransactionDomainService_ProcessReconciliationTransaction_Reco
TestData.MerchantId, TestData.DeviceIdentifier, TestData.TransactionDateTime,
TestData.ReconciliationTransactionCount, TestData.ReconciliationTransactionValue);

ProcessReconciliationTransactionResponse response = await this.TransactionDomainService.ProcessReconciliationTransaction(command, CancellationToken.None);
;
var result = await this.TransactionDomainService.ProcessReconciliationTransaction(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
ProcessReconciliationTransactionResponse response = result.Data;

response.EstateId.ShouldBe(TestData.EstateId);
response.MerchantId.ShouldBe(TestData.MerchantId);
Expand Down Expand Up @@ -209,8 +210,9 @@ public async Task TransactionDomainService_ProcessReconciliationTransaction_Vali
TestData.MerchantId, TestData.DeviceIdentifier, TestData.TransactionDateTime,
TestData.ReconciliationTransactionCount, TestData.ReconciliationTransactionValue);

ProcessReconciliationTransactionResponse response = await this.TransactionDomainService.ProcessReconciliationTransaction(command, CancellationToken.None);
;
var result = await this.TransactionDomainService.ProcessReconciliationTransaction(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var response = result.Data;

response.EstateId.ShouldBe(TestData.EstateId);
response.MerchantId.ShouldBe(TestData.MerchantId);
Expand Down Expand Up @@ -261,7 +263,9 @@ public async Task TransactionDomainService_ProcessSaleTransaction_DeclinedByOper
TestData.CustomerEmailAddress, TestData.AdditionalTransactionMetaDataForMobileTopup(),
TestData.ContractId, TestData.ProductId, TestData.TransactionSource, TestData.TransactionReceivedDateTime);

ProcessSaleTransactionResponse response = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
var result = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var response = result.Data;

response.EstateId.ShouldBe(TestData.EstateId);
response.MerchantId.ShouldBe(TestData.MerchantId);
Expand Down Expand Up @@ -302,7 +306,9 @@ public async Task TransactionDomainService_ProcessSaleTransaction_OperatorProxyT
TestData.CustomerEmailAddress, TestData.AdditionalTransactionMetaDataForMobileTopup(),
TestData.ContractId, TestData.ProductId, TestData.TransactionSource, TestData.TransactionReceivedDateTime);

ProcessSaleTransactionResponse response = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
var result = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var response = result.Data;

response.EstateId.ShouldBe(TestData.EstateId);
response.MerchantId.ShouldBe(TestData.MerchantId);
Expand Down Expand Up @@ -360,7 +366,9 @@ public async Task TransactionDomainService_ProcessSaleTransaction_TransactionIsP
TestData.CustomerEmailAddress, TestData.AdditionalTransactionMetaDataForMobileTopup(),
TestData.ContractId, TestData.ProductId, TestData.TransactionSource, TestData.TransactionReceivedDateTime);

ProcessSaleTransactionResponse response = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
var result = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var response = result.Data;

response.EstateId.ShouldBe(TestData.EstateId);
response.MerchantId.ShouldBe(TestData.MerchantId);
Expand Down Expand Up @@ -422,7 +430,9 @@ public async Task TransactionDomainService_ProcessSaleTransaction_NoFloatFound_T
TestData.CustomerEmailAddress, TestData.AdditionalTransactionMetaDataForMobileTopup(),
TestData.ContractId, TestData.ProductId, TestData.TransactionSource, TestData.TransactionReceivedDateTime);

ProcessSaleTransactionResponse response = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
var result = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var response = result.Data;

response.EstateId.ShouldBe(TestData.EstateId);
response.MerchantId.ShouldBe(TestData.MerchantId);
Expand Down Expand Up @@ -464,7 +474,9 @@ public async Task TransactionDomainService_ProcessSaleTransaction_ValidationFail
TestData.CustomerEmailAddress, TestData.AdditionalTransactionMetaDataForMobileTopup(),
TestData.ContractId, TestData.ProductId, TestData.TransactionSource, TestData.TransactionReceivedDateTime);

ProcessSaleTransactionResponse response = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
var result = await this.TransactionDomainService.ProcessSaleTransaction(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var response = result.Data;

response.EstateId.ShouldBe(TestData.EstateId);
response.MerchantId.ShouldBe(TestData.MerchantId);
Expand Down
20 changes: 14 additions & 6 deletions TransactionProcessor.BusinessLogic/Common/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Shared.Results;
using SimpleResults;

namespace TransactionProcessor.BusinessLogic.Common
{
Expand All @@ -23,7 +25,7 @@ public static Guid CalculateSettlementAggregateId(DateTime settlementDate,
return aggregateId;
}

public static async Task<TokenResponse> GetToken(TokenResponse currentToken, ISecurityServiceClient securityServiceClient, CancellationToken cancellationToken)
public static async Task<Result<TokenResponse>> GetToken(TokenResponse currentToken, ISecurityServiceClient securityServiceClient, CancellationToken cancellationToken)
{
// Get a token to talk to the estate service
String clientId = ConfigurationReader.GetValue("AppSettings", "ClientId");
Expand All @@ -33,20 +35,26 @@ public static async Task<TokenResponse> GetToken(TokenResponse currentToken, ISe

if (currentToken == null)
{
TokenResponse token = await securityServiceClient.GetToken(clientId, clientSecret, cancellationToken);
Result<TokenResponse> tokenResult= await securityServiceClient.GetToken(clientId, clientSecret, cancellationToken);
if (tokenResult.IsFailed)
return ResultHelpers.CreateFailure(tokenResult);
TokenResponse token =tokenResult.Data;
Logger.LogDebug($"Token is {token.AccessToken}");
return token;
return Result.Success(token);
}

if (currentToken.Expires.UtcDateTime.Subtract(DateTime.UtcNow) < TimeSpan.FromMinutes(2))
{
Logger.LogDebug($"Token is about to expire at {currentToken.Expires.DateTime:O}");
TokenResponse token = await securityServiceClient.GetToken(clientId, clientSecret, cancellationToken);
Result<TokenResponse> tokenResult = await securityServiceClient.GetToken(clientId, clientSecret, cancellationToken);
if (tokenResult.IsFailed)
return ResultHelpers.CreateFailure(tokenResult);
TokenResponse token = tokenResult.Data;
Logger.LogDebug($"Token is {token.AccessToken}");
return token;
return Result.Success(token);
}

return currentToken;
return Result.Success(currentToken);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ private async Task<Result> HandleSpecificDomainEvent(VoucherDomainEvents.Voucher
return ResultHelpers.CreateFailure(voucherAggregateResult);

Models.Voucher voucherModel = voucherAggregateResult.Data.GetVoucher();
this.TokenResponse = await Helpers.GetToken(this.TokenResponse, this.SecurityServiceClient, cancellationToken);
Result<TokenResponse> getTokenResult = await Helpers.GetToken(this.TokenResponse, this.SecurityServiceClient, cancellationToken);
if (getTokenResult.IsFailed)
return ResultHelpers.CreateFailure(getTokenResult);
this.TokenResponse = getTokenResult.Data;
if (string.IsNullOrEmpty(voucherModel.RecipientEmail) == false)
{
String message = await this.GetEmailVoucherMessage(voucherModel, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ public async Task<Result<Contract>> GetContract(Guid estateId,
{
foreach (Operator @operator in estateModel.Operators)
{
OperatorAggregate operatorAggregate = await this.AggregateService.GetLatest<OperatorAggregate>(@operator.OperatorId, cancellationToken);
@operator.Name = operatorAggregate.Name;
var getOperatorResult = await this.AggregateService.GetLatest<OperatorAggregate>(@operator.OperatorId, cancellationToken);
if (getOperatorResult.IsSuccess) {
OperatorAggregate operatorAggregate = getOperatorResult.Data;
@operator.Name = operatorAggregate.Name;
}
}
}

Expand Down Expand Up @@ -132,7 +135,10 @@ public async Task<Result<Merchant>> GetMerchant(Guid estateId,
List<Models.Merchant.Operator> operators = new();
foreach (Models.Merchant.Operator @operator in merchantModel.Operators)
{
OperatorAggregate operatorAggregate = await this.AggregateService.GetLatest<OperatorAggregate>(@operator.OperatorId, cancellationToken);
var getOperatorResult = await this.AggregateService.GetLatest<OperatorAggregate>(@operator.OperatorId, cancellationToken);
if (getOperatorResult.IsFailed)
return ResultHelpers.CreateFailure(getOperatorResult);
OperatorAggregate operatorAggregate = getOperatorResult.Data;
Models.Merchant.Operator newOperator = @operator with { Name = operatorAggregate.Name };
operators.Add(newOperator);
}
Expand Down
Loading
Loading