private async Task <ResponseVM> PinDownloadConfirmation(PinDownloadConfirmRequestVM model) { ResponseVM result = new ResponseVM(); using (HttpClient client = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); string endpoint = "https://riapimanagement.azure-api.net/api/pos-confirm-pin-ConfirmationV2"; client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "50185b70341b4f5aa5e1d3307a261798"); using (var Response = await client.PostAsync(endpoint, content)) { if (Response.StatusCode == System.Net.HttpStatusCode.OK) { string confirmation = await Response.Content.ReadAsStringAsync(); var confirmationresponse = JsonConvert.DeserializeObject(confirmation).ToString(); result = JsonConvert.DeserializeObject <ResponseVM>(confirmationresponse); return(result); } else { return(result); } } } }
private async Task DoProcess(TransactionModel transactionModel, PosAssignment posassignment, int iteration) { try { var merchant = transactionModel.Merchants.FirstOrDefault(x => x.Id == posassignment.MerchantId); var posUnits = transactionModel.PosUnits.FirstOrDefault(x => x.Id == posassignment.POSId); var posuser = transactionModel.PosUsers.FirstOrDefault(x => x.MerchantId == posassignment.MerchantId); var detail = new TestUtilityLoadTestDetail() { HdrId = transactionModel.TestUtilityHeader.Id, MerchantId = merchant.Id, PosUserId = posuser.Id, PosAssignmentId = posassignment.Id, PosId = posassignment.POSId, }; LoginModel user = new LoginModel() { merchant_id = merchant.Id, password = posuser.Password, pos_assignment_id = posassignment.Id, pos_id = posassignment.POSId, user_type = "pos-users", pos_version = "", username = posuser.UserId }; Token token = await GetToken(user); detail.ResponseCode = token.response_code; if (detail.ResponseCode == "00") { BusinessdayRequestVM businessdayRequest = new BusinessdayRequestVM() { merchant_id = merchant.Id, token = token.token, user_id = posuser.Id, pos_id = posassignment.POSId, }; BusinessDayResponseVM businessDay = await GetActiveBusinessDay(businessdayRequest); detail.ResponseCode = businessDay.response_code; if (detail.ResponseCode == "00") { var q = (from c in transactionModel.ProductAgentAssignments join p in transactionModel.Products on c.ProductId equals p.Id where c.AgentId == merchant.Id select p ).ToList(); var rand = new Random(); int count = rand.Next(1, q.Count() - 1); var product = q.Skip(count).Take(1).FirstOrDefault(); detail.ProductId = product.Id; PindownloadRequestVM downloadRequest = new PindownloadRequestVM() { business_date = businessDay.business_date, merchant_id = merchant.Id, mode = 1, pos_assignment_id = posassignment.Id, pos_id = posassignment.POSId, pos_user_id = posuser.Id, product_group_id = product.ProductGroupId, product_id = product.Id, qty = 1, request_id = 0, service_provider_id = product.ServiceProviderId, shift_no = businessDay.ShiftNo, token = token.token }; PinDownloadReponseVM downlaod = await PinDownload(downloadRequest); detail.ResponseCode = downlaod.response_code; if (detail.ResponseCode == "00") { detail.DownloadedPinId = downlaod.Pin.FirstOrDefault().download_pin_Id; detail.DownloadResponseTime = Convert.ToInt32(downlaod.Response_time.Replace("ms", "")); detail.IsDownloadCompleted = downlaod.response_code == "00"; detail.PinDownloadId = downlaod.download_Id ?? 0; PinDownloadConfirmRequestVM confirmationRequest = new PinDownloadConfirmRequestVM() { download_id = downlaod.download_Id ?? 0, merchant_id = merchant.Id, pos_assignment_id = posassignment.Id, pos_id = posassignment.POSId, pos_user_id = posuser.Id, token = token.token, txn = downlaod.Pin.Select(x => new PinDetails() { business_date = businessDay.business_date, download_pin_id = x.download_pin_Id, product_id = x.product_id, sale_txn_no = Convert.ToInt64("50" + DateTime.UtcNow.ToString("yyMMddHHmmssff") + posassignment.Id.ToString()), serial_no = x.serial_no, shift_no = businessDay.ShiftNo, user_id = posUnits.Id } ).ToList() }; detail.TxnNo = confirmationRequest.txn.FirstOrDefault().sale_txn_no?.ToString(); ResponseVM response = await PinDownloadConfirmation(confirmationRequest); detail.IsConfirmed = response.response_code == "00"; detail.ResponseCode = response.response_code; detail.ConfirmationReponseTime = Convert.ToInt32(response.Response_time); } } } transactionModel.TestUtilityHeader.EndTime = DateTime.UtcNow; transactionModel.TestUtilityHeader.TestUtilityLoadTestDetail.Add(detail); if (transactionModel.TestUtilityHeader.TestUtilityLoadTestDetail.Count == (transactionModel.Request.NumberOfTerminals * transactionModel.Request.NumberOfTransactionPerTerminal)) { await WriteTransactionLoad(transactionModel.TestUtilityHeader, transactionModel.URL); } } catch (Exception ex) { throw ex; } }