diff --git a/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPostPay/PataPawaPostPayProxy.cs b/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPostPay/PataPawaPostPayProxy.cs index eb77d2f9..aef0e3c6 100644 --- a/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPostPay/PataPawaPostPayProxy.cs +++ b/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPostPay/PataPawaPostPayProxy.cs @@ -42,32 +42,31 @@ public PataPawaPostPayProxy(PataPawaPostPayServiceClient serviceClient, #region Methods public async Task> ProcessLogonMessage(CancellationToken cancellationToken) { + try { + // Check if we need to do a logon with the operator + OperatorResponse operatorResponse = this.MemoryCache.Get("PataPawaPostPayLogon"); + if (operatorResponse != null) { + return operatorResponse; + } - // Check if we need to do a logon with the operator - OperatorResponse operatorResponse = this.MemoryCache.Get("PataPawaPostPayLogon"); - if (operatorResponse != null){ - return operatorResponse; - } + 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 Result.Failure($"Error logging on with PataPawa Post Paid API, Response is {logonResponse.status}"); + } - 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 Result.Failure($"Error logging on with PataPawa Post Paid API, Response is {logonResponse.status}"); - } - - operatorResponse = new OperatorResponse { - IsSuccessful = true, - ResponseCode = "0000", - ResponseMessage = logonResponse.message, - AdditionalTransactionResponseMetadata = new Dictionary() - }; + operatorResponse = new OperatorResponse { IsSuccessful = true, ResponseCode = "0000", ResponseMessage = logonResponse.message, AdditionalTransactionResponseMetadata = new Dictionary() }; - operatorResponse.AdditionalTransactionResponseMetadata.Add("PataPawaPostPaidAPIKey", logonResponse.api_key); - operatorResponse.AdditionalTransactionResponseMetadata.Add("PataPawaPostPaidBalance", logonResponse.balance.ToString()); + operatorResponse.AdditionalTransactionResponseMetadata.Add("PataPawaPostPaidAPIKey", logonResponse.api_key); + operatorResponse.AdditionalTransactionResponseMetadata.Add("PataPawaPostPaidBalance", logonResponse.balance.ToString()); - this.MemoryCache.Set("PataPawaPostPayLogon", operatorResponse, MemoryCacheEntryOptions); + this.MemoryCache.Set("PataPawaPostPayLogon", operatorResponse, MemoryCacheEntryOptions); - return Result.Success(operatorResponse); + return Result.Success(operatorResponse); + } + catch (Exception ex) { + return Result.Failure($"Error processing logon message for PataPawaPostPay [{ex.Message}]"); + } } private MemoryCacheEntryOptions MemoryCacheEntryOptions => diff --git a/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPrePay/PataPawaPrePayProxy.cs b/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPrePay/PataPawaPrePayProxy.cs index e204ccf1..48e4f498 100644 --- a/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPrePay/PataPawaPrePayProxy.cs +++ b/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPrePay/PataPawaPrePayProxy.cs @@ -29,32 +29,37 @@ public PataPawaPrePayProxy(PataPawaPrePaidConfiguration configuration, } public async Task> ProcessLogonMessage(CancellationToken cancellationToken){ - // Check if we need to do a logon with the operator - OperatorResponse operatorResponse = this.MemoryCache.Get("PataPawaPrePayLogon"); - if (operatorResponse != null){ - return Result.Success(operatorResponse); - } + try { + // Check if we need to do a logon with the operator + OperatorResponse operatorResponse = this.MemoryCache.Get("PataPawaPrePayLogon"); + if (operatorResponse != null) { + return Result.Success(operatorResponse); + } - HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, this.Configuration.Url); - MultipartFormDataContent content = new MultipartFormDataContent(); - content.Add(new StringContent("login"), "request"); - content.Add(new StringContent(this.Configuration.Username), "username"); - content.Add(new StringContent(this.Configuration.Password), "password"); - requestMessage.Content = content; + HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, this.Configuration.Url); + MultipartFormDataContent content = new MultipartFormDataContent(); + content.Add(new StringContent("login"), "request"); + content.Add(new StringContent(this.Configuration.Username), "username"); + content.Add(new StringContent(this.Configuration.Password), "password"); + requestMessage.Content = content; - HttpResponseMessage responseMessage = await this.HttpClient.SendAsync(requestMessage, cancellationToken); + HttpResponseMessage responseMessage = await this.HttpClient.SendAsync(requestMessage, cancellationToken); - // Check the send was successful - if (responseMessage.IsSuccessStatusCode == false){ - return Result.Failure($"Error sending logon request to Patapawa. Status Code [{responseMessage.StatusCode}]"); - } + // Check the send was successful + if (responseMessage.IsSuccessStatusCode == false) { + return Result.Failure($"Error sending logon request to Patapawa. Status Code [{responseMessage.StatusCode}]"); + } - // Get the response - String responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken); + // Get the response + String responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken); - Logger.LogInformation($"Received response message from Patapawa [{responseContent}]"); + Logger.LogInformation($"Received response message from Patapawa [{responseContent}]"); - return this.CreateFromLogon(responseContent); + return this.CreateFromLogon(responseContent); + } + catch (Exception ex) { + return Result.Failure($"Error processing logon message for PataPawaPrePay [{ex.Message}]"); + } } public async Task> ProcessSaleMessage(Guid transactionId, Guid operatorId, diff --git a/TransactionProcessor/Extensions.cs b/TransactionProcessor/Extensions.cs index c3dc242d..1b6751c7 100644 --- a/TransactionProcessor/Extensions.cs +++ b/TransactionProcessor/Extensions.cs @@ -218,7 +218,6 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { } private static void OperatorLogon(String operatorId) { - try { Logger.LogInformation($"About to do auto logon for operator Id [{operatorId}]"); Func resolver = Startup.ServiceProvider.GetService>(); IOperatorProxy proxy = resolver(operatorId); @@ -232,11 +231,6 @@ private static void OperatorLogon(String operatorId) { if (logonResult.IsFailed) { Logger.LogWarning($"Auto logon for operator Id [{operatorId}] status [{logonResult.Message}]"); } - } - catch (Exception ex) { - Logger.LogWarning($"Auto logon for operator Id [{operatorId}] failed."); - Logger.LogWarning(ex.ToString()); - } } } } \ No newline at end of file