Skip to content

Commit ba4c612

Browse files
Merge pull request #714 from TransactionProcessing/bug/#713_handle_voucher_issue_failure
Add logging and error handling for voucher issuance
2 parents 4e8a326 + ee1ffb2 commit ba4c612

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

TransactionProcessor.BusinessLogic.Tests/OperatorInterfaces/VoucherManagementProxyTests.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using SimpleResults;
1+
using Shared.Logger;
2+
using SimpleResults;
23

34
namespace TransactionProcessor.BusinessLogic.Tests.OperatorInterfaces
45
{
@@ -17,6 +18,10 @@ namespace TransactionProcessor.BusinessLogic.Tests.OperatorInterfaces
1718

1819
public class VoucherManagementProxyTests
1920
{
21+
public VoucherManagementProxyTests() {
22+
Logger.Initialise(new NullLogger());
23+
}
24+
2025
[Fact]
2126
public async Task VoucherManagementProxy_ProcessLogonMessage_NullReturned() {
2227
Mock<IMediator> mediator = new Mock<IMediator>();
@@ -50,7 +55,25 @@ public async Task VoucherManagementProxy_ProcessSaleMessage_VoucherIssueSuccessf
5055
operatorResponse.AdditionalTransactionResponseMetadata.ShouldContainKey("VoucherCode");
5156
operatorResponse.AdditionalTransactionResponseMetadata.ShouldContainKey("VoucherExpiryDate");
5257
}
53-
58+
59+
[Fact]
60+
public async Task VoucherManagementProxy_ProcessSaleMessage_VoucherIssueFailed_FailedResultReturned()
61+
{
62+
Mock<IMediator> mediator = new Mock<IMediator>();
63+
mediator.Setup(m => m.Send(It.IsAny<VoucherCommands.IssueVoucherCommand>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure("Some grim error"));
64+
IOperatorProxy voucherManagementProxy = new VoucherManagementProxy(mediator.Object);
65+
66+
var result = await voucherManagementProxy.ProcessSaleMessage(TestData.TransactionId,
67+
TestData.OperatorId,
68+
TestData.Merchant,
69+
TestData.TransactionDateTime,
70+
TestData.TransactionReference,
71+
TestData.AdditionalTransactionMetaDataForVoucher(),
72+
CancellationToken.None);
73+
74+
result.IsFailed.ShouldBeTrue();
75+
}
76+
5477
[Theory]
5578
[InlineData("")]
5679
[InlineData(null)]

TransactionProcessor.BusinessLogic/OperatorInterfaces/VoucherManagement/VoucherManagementProxy.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3+
using Shared.Logger;
4+
using Shared.Results;
35
using SimpleResults;
46

57
namespace TransactionProcessor.BusinessLogic.OperatorInterfaces.VoucherManagement
@@ -62,28 +64,30 @@ public async Task<Result<OperatorResponse>> ProcessSaleMessage(Guid transactionI
6264
recipientMobile);
6365

6466
Result<IssueVoucherResponse> result= await this.Mediator.Send(command, cancellationToken);
65-
66-
if (result.IsSuccess) {
67-
// Build the response metadata
68-
Dictionary<String, String> additionalTransactionResponseMetadata = new Dictionary<String, String>();
69-
additionalTransactionResponseMetadata.Add("VoucherCode", result.Data.VoucherCode);
70-
additionalTransactionResponseMetadata.Add("VoucherMessage", result.Data.Message);
71-
additionalTransactionResponseMetadata.Add("VoucherExpiryDate", result.Data.ExpiryDate.ToString("yyyy-MM-dd"));
7267

73-
return Result.Success(new OperatorResponse
74-
{
75-
TransactionId = transactionId.ToString("N"),
76-
ResponseCode = "0000",
77-
ResponseMessage = "SUCCESS",
78-
// This may contain the voucher details to be logged with the transaction, and for possible receipt email/print
79-
AdditionalTransactionResponseMetadata = additionalTransactionResponseMetadata,
80-
AuthorisationCode = "ABCD1234",
81-
IsSuccessful = true
82-
});
68+
if (result.IsFailed) {
69+
Logger.LogWarning($"Error issuing voucher {result.Message}");
70+
return ResultHelpers.CreateFailure(result);
8371
}
8472

85-
// TODO: handle a failed issue case
86-
return null;
73+
// Build the response metadata
74+
Dictionary<String, String> additionalTransactionResponseMetadata = new Dictionary<String, String>();
75+
additionalTransactionResponseMetadata.Add("VoucherCode", result.Data.VoucherCode);
76+
additionalTransactionResponseMetadata.Add("VoucherMessage", result.Data.Message);
77+
additionalTransactionResponseMetadata.Add("VoucherExpiryDate", result.Data.ExpiryDate.ToString("yyyy-MM-dd"));
78+
79+
return Result.Success(new OperatorResponse
80+
{
81+
TransactionId = transactionId.ToString("N"),
82+
ResponseCode = "0000",
83+
ResponseMessage = "SUCCESS",
84+
// This may contain the voucher details to be logged with the transaction, and for possible receipt email/print
85+
AdditionalTransactionResponseMetadata = additionalTransactionResponseMetadata,
86+
AuthorisationCode = "ABCD1234",
87+
IsSuccessful = true
88+
});
89+
90+
8791
}
8892
}
8993
}

0 commit comments

Comments
 (0)