public IActionResult AjaxCheckout(AjaxRequestModel model) { var data = JsonConvert.DeserializeObject <SSLCommerzInitRequest>(model.cart_json); NameValueCollection PostData = new NameValueCollection(); foreach (var item in GetProperties(data)) { PostData.Add(item.Key, item.Value); } var sslcz = new SSLCommerz(storeID, storePassword, true); var response = sslcz.InitiateTransaction(PostData); if (string.IsNullOrEmpty(response.GatewayPageURL)) { return(Ok(new { status = "fail", logo = response.storeLogo })); } return(Ok(new { status = "success", data = response.GatewayPageURL, logo = response.storeLogo })); }
public async Task AjaxRequestServiceGetResponseTrowsExceptionForMissingAjaxRequestModel() { // Arrange var requestModel = ValidRequestModel(); AjaxRequestModel ajaxRequest = null; using var httpClient = new HttpClient(); var ajaxRequestService = new AjaxRequestService(fakeLogger, fakeAppRegistryDataService, httpClient); // Act & Assert await Assert.ThrowsAnyAsync <ArgumentNullException>(async() => await ajaxRequestService.GetResponseAsync(requestModel, ajaxRequest)); }
public static bool RequiresHealthCheck(this AjaxRequestModel ajaxRequestModel) { return(!(ajaxRequestModel?.IsHealthy).GetValueOrDefault() && (ajaxRequestModel?.HealthCheckRequired).GetValueOrDefault()); }
public async Task <ResponseModel> GetResponseAsync(RequestModel requestModel, AjaxRequestModel ajaxRequest) { _ = requestModel ?? throw new ArgumentNullException(nameof(requestModel)); _ = ajaxRequest ?? throw new ArgumentNullException(nameof(ajaxRequest)); var appData = string.IsNullOrWhiteSpace(requestModel.AppData) ? string.Empty : "/" + Uri.EscapeDataString(requestModel.AppData); var url = ajaxRequest.AjaxEndpoint.Replace("/{0}", $"{appData}", StringComparison.OrdinalIgnoreCase); var responseModel = new ResponseModel { Status = HttpStatusCode.OK, StatusMessage = "Unhealthy", IsHealthy = ajaxRequest.IsHealthy, OfflineHtml = ajaxRequest.OfflineHtml, }; logger.LogInformation($"Ajax request using: {url}"); if (ajaxRequest.IsHealthy) { try { httpClient.DefaultRequestHeaders.Add(HeaderNames.Accept, MediaTypeNames.Application.Json); var response = await httpClient.GetAsync(new Uri(url, UriKind.Absolute)); responseModel.Status = response.StatusCode; responseModel.StatusMessage = response.ReasonPhrase; if (response.IsSuccessStatusCode) { logger.LogInformation($"Ajax request successful: {url}"); responseModel.Payload = await response.Content.ReadAsStringAsync(); responseModel.OfflineHtml = null; } else { logger.LogError($"Ajax request error: {responseModel.Status}: {responseModel.StatusMessage}, using: {url}"); } } catch (TaskCanceledException ex) { logger.LogError(ex, $"TaskCancelled: {url} - {ex.Message}"); responseModel.IsHealthy = false; if (ajaxRequest.HealthCheckRequired) { await appRegistryDataService.SetAjaxRequestHealthState(requestModel.Path, ajaxRequest.Name, false); } } } return(responseModel); }