public ActionResult Withdraw(CreateWithdrawViewModel model) { if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); var user = _userProfileService.GetUserProfile(u => u.Id == userId); var withdraw = Mapper.Map <CreateWithdrawViewModel, Withdraw>(model); withdraw.User = user; if (user.Balance >= withdraw.Amount && withdraw.Amount > 50) { user.Balance -= withdraw.Amount; _withdrawService.CreateWithdraw(withdraw); _withdrawService.SaveWithdraw(); return(View("SuccessWithdraw")); } return(View("ErrorWithdraw")); } return(HttpNotFound()); //data.Add("details", det); //HttpClient client = new HttpClient(); ////client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; //client.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes("5ac35eb73b1eaf90618b456b:49YehvH0IJr19yCNtmWxBR3TbuwKCCaN"))); //client.DefaultRequestHeaders.Add("Ik-Api-Account-Id", "5ac35ee33c1eafbd6d8b4572"); //data.Add("calcKey", "ikPayerPrice"); //data.Add("action", "process"); //data.Add("paymentNo", Guid.NewGuid().ToString("n")); //data.Add("purseId", "407835843341"); //var q = QueryStringBuilder.BuildQueryString(new //{ // details = det, // calcKey = "ikPayerPrice", // action = "process", // purseId = "407835843341", // paymentNo = Guid.NewGuid().ToString("n"), // amount = data["amount"], // paywayId = data["paywayId"] //}); //var stringContent = new StringContent(q, // UnicodeEncoding.UTF8, // "application/x-www-form-urlencoded"); //var resp = await client.PostAsync("https://api.interkassa.com/v1/withdraw", stringContent); //var responseString = System.Text.RegularExpressions.Regex.Unescape(await resp.Content.ReadAsStringAsync()); //var jObject = JObject.Parse(responseString.Replace(@"\", @"\\")); //if (jObject["status"].Value<string>() == "ok" && jObject["message"].Value<string>() == "Success") //{ // decimal amount = Decimal.Parse(jObject["data"]["withdraww"]["psAmount"].Value<string>()); //} }
public async Task <ActionResult> Withdraw(CreateWithdrawViewModel model) { if (ModelState.IsValid) { var userId = User.Identity.GetUserId <int>(); var user = await userProfileService.GetUserProfileByIdAsync(userId); var withdraw = Mapper.Map <CreateWithdrawViewModel, Withdraw>(model); withdraw.User = user; if (user.Balance >= withdraw.Amount && withdraw.Amount > 50) { user.Balance -= withdraw.Amount; withdrawService.CreateWithdraw(withdraw); withdrawService.SaveWithdraw(); return(View("SuccessWithdraw")); } return(View("ErrorWithdraw")); } return(HttpNotFound()); }