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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ namespace TransactionProcessor.BusinessLogic.Tests.OperatorInterfaces
using BusinessLogic.OperatorInterfaces.SafaricomPinless;
using Moq;
using Moq.Protected;
using Shared.Logger;
using Shouldly;
using Testing;
using Xunit;

public class SafaricomPinlessProxyTests
{
public SafaricomPinlessProxyTests(){
Logger.Initialise(NullLogger.Instance);
}

[Fact]
public async Task SafaricomPinlessProxy_ProcessLogonMessage_NullIsReturned() {
HttpResponseMessage responseMessage = new HttpResponseMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_OperatorProxyT

response.EstateId.ShouldBe(TestData.EstateId);
response.MerchantId.ShouldBe(TestData.MerchantId);
response.ResponseCode.ShouldBe("0000");
response.ResponseMessage.ShouldBe("SUCCESS");
response.ResponseCode.ShouldBe("1010");
response.ResponseMessage.ShouldBe("OPERATOR COMMS ERROR");
response.TransactionId.ShouldBe(TestData.TransactionId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class PataPawaPostPayProxy : IOperatorProxy

private readonly PataPawaPostPayServiceClient ServiceClient;

private readonly Func<PataPawaPostPayServiceClient, String, IPataPawaPostPayService> ChannelResolver;
private readonly Func<PataPawaPostPayServiceClient, String,String, IPataPawaPostPayService> ChannelResolver;

#endregion

#region Constructors

public PataPawaPostPayProxy(PataPawaPostPayServiceClient serviceClient,
Func<PataPawaPostPayServiceClient, String, IPataPawaPostPayService> channelResolver,
Func<PataPawaPostPayServiceClient, String, String, IPataPawaPostPayService> channelResolver,
PataPawaPostPaidConfiguration configuration,
IMemoryCache memoryCache) {
this.ServiceClient = serviceClient;
Expand All @@ -42,7 +42,7 @@ public PataPawaPostPayProxy(PataPawaPostPayServiceClient serviceClient,

public async Task<OperatorResponse> ProcessLogonMessage(String accessToken,
CancellationToken cancellationToken) {
IPataPawaPostPayService channel = this.ChannelResolver(this.ServiceClient, this.Configuration.Url);
IPataPawaPostPayService channel = this.ChannelResolver(this.ServiceClient, "PataPawaPostPay", this.Configuration.Url);
login logonResponse = await channel.getLoginRequestAsync(this.Configuration.Username, this.Configuration.Password);
if (logonResponse.status != 0) {
return new OperatorResponse {
Expand Down Expand Up @@ -146,13 +146,13 @@ private async Task<OperatorResponse> PerformProcessBillTransaction(String accoun
}

Decimal operatorTransactionAmount = amountAsDecimal * 100;
IPataPawaPostPayService channel = this.ChannelResolver(this.ServiceClient, this.Configuration.Url);
IPataPawaPostPayService channel = this.ChannelResolver(this.ServiceClient, "PataPawaPostPay", this.Configuration.Url);
paybill payBillResponse = await channel.getPayBillRequestAsync(this.Configuration.Username,
apiKey,
accountNumber,
mobileNumber,
customerName,
operatorTransactionAmount);
apiKey,
accountNumber,
mobileNumber,
customerName,
operatorTransactionAmount);

if (payBillResponse.status != 0) {
throw new Exception($"Error paying bill for account number {accountNumber}");
Expand All @@ -169,7 +169,7 @@ private async Task<OperatorResponse> PerformProcessBillTransaction(String accoun
private async Task<OperatorResponse> PerformVerifyAccountTransaction(String accountNumber,
String apiKey) {

IPataPawaPostPayService channel = this.ChannelResolver(this.ServiceClient, this.Configuration.Url);
IPataPawaPostPayService channel = this.ChannelResolver(this.ServiceClient, "PataPawaPostPay", this.Configuration.Url);
verify verifyResponse = await channel.getVerifyRequestAsync(this.Configuration.Username, apiKey, accountNumber);

if (String.IsNullOrEmpty(verifyResponse.account_name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Xml.Serialization;
using Common;
using EstateManagement.DataTransferObjects.Responses;
using Shared.Logger;

/// <summary>
///
Expand Down Expand Up @@ -104,6 +105,8 @@ public async Task<OperatorResponse> ProcessSaleMessage(String accessToken,

String requestUrl = this.BuildRequest(transactionDateTime, transactionReference, customerMsisdn, operatorTransactionAmount);

Logger.LogInformation($"Sending message to Safaricom [{requestUrl}]");

// Concatenate the request message
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri(requestUrl));

Expand All @@ -119,6 +122,8 @@ public async Task<OperatorResponse> ProcessSaleMessage(String accessToken,
// Get the response
String responseContent = await responseMessage.Content.ReadAsStringAsync();

Logger.LogInformation($"Received response message from Safaricom [{responseContent}]");

return this.CreateFrom(responseContent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace TransactionProcessor.BusinessLogic.OperatorInterfaces.VoucherManagemen
using System.Threading.Tasks;
using Common;
using EstateManagement.DataTransferObjects.Responses;
using IdentityModel.Client;
using MediatR;
//using global::VoucherManagement.Client;
//using global::VoucherManagement.DataTransferObjects;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using Microsoft.Identity.Client;
using Models;
using Requests;

Expand Down Expand Up @@ -84,6 +86,7 @@ public async Task<OperatorResponse> ProcessSaleMessage(String accessToken,
amountAsDecimal,
recipientEmail,
recipientMobile);

IssueVoucherResponse response = await this.Mediator.Send(request, cancellationToken);

if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ await this.ValidateSaleTransaction(estateId,
TransactionResponseCode transactionResponseCode = TransactionResponseCode.OperatorCommsError;
String responseMessage = "OPERATOR COMMS ERROR";

transactionAggregate.DeclineTransactionLocally(((Int32)validationResult.responseCode).ToString().PadLeft(4, '0'), validationResult.responseMessage);
transactionAggregate.DeclineTransactionLocally(((Int32)transactionResponseCode).ToString().PadLeft(4, '0'), responseMessage);
}
else {
if (operatorResponse.IsSuccessful) {
Expand Down
8 changes: 6 additions & 2 deletions TransactionProcessor/Bootstrapper/OperatorRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using BusinessLogic.OperatorInterfaces;
using BusinessLogic.OperatorInterfaces.PataPawaPostPay;
using BusinessLogic.OperatorInterfaces.SafaricomPinless;
using BusinessLogic.OperatorInterfaces.VoucherManagement;
using Common;
using Lamar;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -40,8 +44,9 @@ public OperatorRegistry()
this.For<IOperatorProxy>().Add<PataPawaPostPayProxy>().Named("PataPawaPostPay").Singleton();
this.For<IOperatorProxy>().Add<VoucherManagementProxy>().Named("Voucher").Singleton();

this.AddTransient<Func<PataPawaPostPayServiceClient, String, IPataPawaPostPayService>>(context => (client,
this.AddTransient<Func<PataPawaPostPayServiceClient, String,String, IPataPawaPostPayService>>(context => (client,clientName,
url) => {
client.Endpoint.SetTraceLogging(clientName);
IPataPawaPostPayService channel =
client.ChannelFactory.CreateChannel(new EndpointAddress(url));
return channel;
Expand All @@ -50,7 +55,6 @@ public OperatorRegistry()

this.AddTransient<Func<String, IOperatorProxy>>(context => operatorIdentifier => {
return Startup.Container.GetInstance<IOperatorProxy>(operatorIdentifier);

});
}

Expand Down
37 changes: 37 additions & 0 deletions TransactionProcessor/Common/ClientMessageLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace TransactionProcessor.Common;

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using Shared.Logger;

internal sealed class ClientMessageLogger :
IClientMessageInspector{
#region Fields

private readonly String ClientName;

#endregion

#region Constructors

public ClientMessageLogger(String clientName){
this.ClientName = clientName;
}

#endregion

#region Methods

public void AfterReceiveReply(ref Message reply, Object correlationState){
Logger.LogInformation($"Received SOAP reply from {this.ClientName}:\r\n{reply}");
}

public Object BeforeSendRequest(ref Message request, IClientChannel channel){
Logger.LogInformation($"Sending SOAP request to {this.ClientName}:\r\n{request}");
return null;
}

#endregion
}
40 changes: 40 additions & 0 deletions TransactionProcessor/Common/ClientMessageLoggingBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace TransactionProcessor.Common;

using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

internal sealed class ClientMessageLoggingBehavior :
IEndpointBehavior{
#region Fields

private readonly String ClientName;

#endregion

#region Constructors

public ClientMessageLoggingBehavior(String clientName){
this.ClientName = clientName;
}

#endregion

#region Methods

public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters){
}

public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime){
clientRuntime.ClientMessageInspectors.Add(new ClientMessageLogger(this.ClientName));
}

public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher){
}

public void Validate(ServiceEndpoint endpoint){
}

#endregion
}
16 changes: 16 additions & 0 deletions TransactionProcessor/Common/ServiceEndpointExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TransactionProcessor.Common;

using System;
using System.ServiceModel.Description;

public static class ServiceEndpointExtensions{
#region Methods

public static void SetTraceLogging(this ServiceEndpoint serviceEndpoint, String clientName){
if (serviceEndpoint.EndpointBehaviors.Contains(typeof(ClientMessageLoggingBehavior)) == false){
serviceEndpoint.EndpointBehaviors.Add(new ClientMessageLoggingBehavior(clientName));
}
}

#endregion
}