public async Task <IActionResult> ZarinPalPaymentVerify(string Order, string Authority, string Status) { try { if (string.IsNullOrEmpty(Order)) { RedirectToAction("Orders"); } var iOrder = (from s in _context.Store_Orders where s.Id == int.Parse(Shared.Decrypt(Order)) select s).FirstOrDefault(); if (iOrder.Active != true) { RedirectToAction("Orders"); } Schools iUser = (from s in _context.Schools where s.Id == iOrder.School_Id select s).FirstOrDefault(); if (iOrder == null) { return(Content("مشکلی رخ داده")); } ViewBag.orderFinish = iOrder.Id; ViewBag.orderCodeFinish = iOrder.OrderCode; ViewBag.iSht = iOrder.ShippingType; ViewBag.iShc = iOrder.ShippingCost; var buyitems = (from s in _context.Store_Cart where s.Active == true && s.Order_Id == iOrder.Id select s).ToList(); string items = ""; for (var i = 0; i < buyitems.Count; i++) { if (i == 0) { items += buyitems[i].Item_Id + "-" + buyitems[i].Count; } else { items += "_" + buyitems[i].Item_Id + "-" + buyitems[i].Count; } } ViewBag.orderFinishCart = items; var pym = (from s in _context.Store_OrderPayment where s.Active == true && s.Order_Id == iOrder.Id select s).LastOrDefault(); if (Status == "NOK") { ViewBag.orderMes = "فرایند پرداخت دراگاه بانکی موفقیت آمیز نبود"; ViewBag.orderSuccess = "false"; ViewBag.pym = Shared.Encrypt(pym.Id.ToString()); ViewBag.balance = GetBalance(iUser.Id); var pymexist = (from s in _context.Store_Payment_Online where s.Authority == Authority.TrimStart('0') select s).LastOrDefault(); if (pymexist == null) { var payo = new Store_Payment_Online { Amount = pym.Money, Authority = Authority.TrimStart('0'), Gate = "ZarinGate", Payment_Id = pym.Id, Success = false, Description = "Status:NOK" }; await _context.AddAsync(payo); await _context.SaveChangesAsync(); } } else { var zi = new Zarinpal.Payment("b689de60-6707-11e8-a4b2-005056a205be", (pym.Money / 10)); var verification = await zi.Verification(Authority); //ارسال به صفحه خطا if (verification.Status == 100) { ViewBag.balance = GetBalance(iUser.Id); string mes1 = @"وی سی وی" + "\n" + iUser.SchoolNameFa + " سفارش شما به شماره پیگیری " + iOrder.OrderCode + " ثبت/پرداخت شد و منتظر پردازش و تایید توسط بخش فروش می باشد"; if (!string.IsNullOrEmpty(iUser.Email)) { //Shared.SendEmail(iUser.FnameFa + " " + iUser.LnameFa, iUser.Email, mes1, "Your Order from VCV"); } new Service(_context).SendSMS(iUser.Mobile, mes1); string mes3 = @"وی سی وی" + "\n" + "آموزشگاه " + iUser.SchoolNameFa + "، " + Shared.ReturnGender(iUser.Sex) + iUser.FnameFa + " " + iUser.LnameFa + " سفارشی را به شماره پیگیری " + iOrder.OrderCode + " به ثبت رسانده است. پیگیری کنید "; //Shared.SendEmail("VCV Gmail", "*****@*****.**", mes3, "An order submitted"); new Service(_context).SendSMS("09204204700", mes3); new Service(_context).SendSMS("09159714815", mes3); //ارسال کد تراکنش به جهت نمایش به کاربر var refId = verification.RefId; ViewBag.orderMes = "پرداخت با موفقیت انجام شد. کد پرداخت: " + refId.ToString(); ViewBag.orderSuccess = "true"; var pymexist = (from s in _context.Store_Payment_Online where s.Authority == Authority.TrimStart('0') select s).LastOrDefault(); if (pymexist == null) { var payo = new Store_Payment_Online { Amount = pym.Money, Authority = Authority.TrimStart('0'), Gate = "ZarinGate", Payment_Id = pym.Id, Success = true, Description = "Status:100", RefId = refId.ToString() }; await _context.AddAsync(payo); } // cost bal if (pym.Balance_Log_Id != 0) { var bal = (from s in _context.Store_Balance where s.Id == pym.Balance_Log_Id && s.Active != true select s).LastOrDefault(); if (bal != null) { bal.Active = true; } } iOrder.OrderStep = 2; await _context.SaveChangesAsync(); } else if (verification.Status == 101) { ViewBag.balance = GetBalance(iUser.Id); ViewBag.orderMes = "پرداخت با موفقیت انجام شد "; ViewBag.orderSuccess = "true"; } else { ViewBag.balance = GetBalance(iUser.Id); ViewBag.orderMes = "فرایند پرداخت دراگاه بانکی موفقیت آمیز نبود. کد خطا: " + verification.RefId + "--" + verification.Status; ViewBag.orderSuccess = "false"; var pymexist = (from s in _context.Store_Payment_Online where s.Authority == Authority.TrimStart('0') select s).LastOrDefault(); if (pymexist == null) { var payo = new Store_Payment_Online { Amount = pym.Money, Authority = Authority.TrimStart('0'), Gate = "ZarinGate", Payment_Id = pym.Id, Success = false, Description = "Status:" + verification.Status }; await _context.AddAsync(payo); await _context.SaveChangesAsync(); } else { return(RedirectToAction("Index", "Orders")); } } } var PassToView = new PassToOrders() { iUser = iUser }; PassToView.iStoreItems = (from s in _context.Store_Item where s.Active == true orderby s.VCV select s).ToList(); PassToView.iMessage = new Service(_context).getNewMessage(iUser.Id, "20"); PassToView.iNotification = Service.Getsystemnotification(); var ss = new Service(_context).getcity(iUser.City_Id); PassToView.city = ss.city; PassToView.province = ss.province; return(View("Index", PassToView)); } catch (Exception ex) { return(Content("<h1 style='text-align: center'>مشکلی پیش آمده است. لطفا با پشتیبانی در تماس باشید</h1>" + ex.ToString())); } }