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 @@ -42,32 +42,31 @@ public PataPawaPostPayProxy(PataPawaPostPayServiceClient serviceClient,
#region Methods

public async Task<Result<OperatorResponse>> ProcessLogonMessage(CancellationToken cancellationToken) {
try {
// Check if we need to do a logon with the operator
OperatorResponse operatorResponse = this.MemoryCache.Get<OperatorResponse>("PataPawaPostPayLogon");
if (operatorResponse != null) {
return operatorResponse;
}

// Check if we need to do a logon with the operator
OperatorResponse operatorResponse = this.MemoryCache.Get<OperatorResponse>("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<String, String>()
};
operatorResponse = new OperatorResponse { IsSuccessful = true, ResponseCode = "0000", ResponseMessage = logonResponse.message, AdditionalTransactionResponseMetadata = new Dictionary<String, String>() };

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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,37 @@ public PataPawaPrePayProxy(PataPawaPrePaidConfiguration configuration,
}

public async Task<Result<OperatorResponse>> ProcessLogonMessage(CancellationToken cancellationToken){
// Check if we need to do a logon with the operator
OperatorResponse operatorResponse = this.MemoryCache.Get<OperatorResponse>("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<OperatorResponse>("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<Result<OperatorResponse>> ProcessSaleMessage(Guid transactionId, Guid operatorId,
Expand Down
6 changes: 0 additions & 6 deletions TransactionProcessor/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, IOperatorProxy> resolver = Startup.ServiceProvider.GetService<Func<String, IOperatorProxy>>();
IOperatorProxy proxy = resolver(operatorId);
Expand All @@ -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());
}
}
}
}
Loading