public async Task <ValidationResponse> Initialize(MonerisAdminRequest monerisAdminRequest) { try { var client = _clientFactory.CreateClient(); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var monerisRequest = new { apiToken = _config["Moneris:apiToken"], postbackUrl = _config["Moneris:postbackUrl"], storeId = monerisAdminRequest.StoreId, terminalId = monerisAdminRequest.TerminalId, txnType = "initialization" }; var requestString = JsonConvert.SerializeObject(monerisRequest); var response = await client.PostAsync( _config["Moneris:baseUrl"], new StringContent( requestString, Encoding.UTF8, "application/json")); var result = await response.Content .ReadAsAsync <ValidationResponse>(); var date = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Pacific Standard Time"); var monerisLog = new MonerisTransactionLog { ClientIp = monerisAdminRequest.ClientIp, OrderId = null, Amount = 0, CreatedDate = date, Request = requestString, Response = JsonConvert.SerializeObject(result), ResponseCode = result.Receipt.ResponseCode, ResponseMessage = result.Receipt.Message, StoreId = monerisRequest.storeId, TerminalId = monerisRequest.terminalId, TransactionType = monerisRequest.txnType, UserId = monerisAdminRequest.UserId, }; await _context.MonerisTransactionLog.AddAsync(monerisLog); await _context.SaveChangesAsync(); return(result); } catch (Exception ex) { _telemetryClient.TrackException(ex); return(null); } }
public async Task <IActionResult> BatchClose([FromBody] MonerisAdminRequest monerisAdminRequest) { System.Security.Claims.ClaimsPrincipal currentUser = User; var clientIp = _accessor.HttpContext.Connection.RemoteIpAddress.ToString().Replace("{", "").Replace("}", ""); monerisAdminRequest.ClientIp = clientIp; monerisAdminRequest.UserId = currentUser.Identity.Name; var result = await _monerisService.BatchClose(monerisAdminRequest); if (result != null && result.Receipt.Error.Equals("false", StringComparison.InvariantCultureIgnoreCase)) { return(Ok()); } return(BadRequest(result?.Receipt?.Message)); }