using System; using Amazon.Lambda.Core; using Amazon.Lambda.APIGatewayEvents; using Newtonsoft.Json; using MySqlConnector; using classes; using System.Threading.Tasks; using System.Net.Http; using System.Net; using System.Text; using Model.ResponseModel; namespace PMF { public class PayEnatis: Pmfbase { public async Task PayExternalInfringement(APIGatewayProxyRequest request, ILambdaContext context) { string statement = "eNatis::PayExternalInfringement"; string userId = ""; APIGatewayProxyResponse response; try { string validationMessage = string.Empty; if (!Helper.IsRequestEmpty(request)) { var validRequest = Helper.ValidateRequestParameters(ref validationMessage, request.QueryStringParameters, "userId"); if (validRequest) { userId = request.QueryStringParameters["userId"]; if (request != null && request.Body != null) { var handler = new HttpClientHandler { ServerCertificateCustomValidationCallback = Helper.ServerCertificateCustomValidation }; var client = new HttpClient(handler) { BaseAddress = new Uri(baseUrl) }; var content = new StringContent(request.Body, Encoding.UTF8, "application/json"); var eNatisResponse = await client.PostAsync("infringement/payinfringement", content); var body = await eNatisResponse.Content.ReadAsStringAsync(); if (eNatisResponse.StatusCode == HttpStatusCode.OK) { response = HttpService.CreateResponse(200, payload: body, serializeToJson: false); } else { var error = JsonConvert.DeserializeObject(body); return HttpService.CreateResponse(error.statusCode, payload: error.message); } } else { response = HttpService.CreateResponse(400, payload: "Request body is invalid"); } } else { response = HttpService.CreateResponse(400, payload: $"{validationMessage}"); } } else { _logger.LogMessage(context, $"Processing request failed invalid request"); response = HttpService.CreateResponse(400, payload: "No parameters provided"); } } catch (Exception ex) { _logger.WriteLog(userId, statement, ex.Message, "eNATiS"); return HttpService.CreateResponse(500, payload: ex.Message); } _logger.WriteLog(userId, statement, response.Body, "eNATiS"); return response; } } }