public IActionResult PaymentResult(Guid id, Guid customerId) { var book = PersianNovComponent.Instance.BookFacade.Get(id); var customer = PersianNovComponent.Instance.CustomerFacade.Get(customerId); if (HttpContext.Request.Query["Status"] != "" && HttpContext.Request.Query["Status"].ToString().ToLower() == "ok" && HttpContext.Request.Query["Authority"] != "") { string authority = HttpContext.Request.Query["Authority"].ToString(); var sum = book.Discount > 0 ? book.Price - (book.Price * book.Discount / 100) : book.Price; var payment = new Zarinpal.Payment("b64b52e2-ac94-11ea-8aff-000c295eb8fc", System.Convert.ToInt32(sum)); var res = payment.Verification(authority).Result; ViewBag.code = res.RefId; ViewBag.Status = res.Status; if (res.Status == 100) { if (PersianNovComponent.Instance.PaymentFacade.InsertPayment(id, customerId, res.RefId)) { SetCookie(customer); return(View(book)); } } } SetCookie(customer); return(View(book)); }
public async Task <(bool succes, long refId)> IsPaymnetValid(int amount, string authority) { //"1b7662fc-5b33-11e8-9c88-005056a205be" var zp = new Zarinpal.Payment("1b7662fc-5b33-11e8-9c88-005056a205be", amount); // var zp = new ZarinpalSandbox.Payment(amount); var res = await zp.Verification(authority); return(res.Status == 100, res.RefId); }
public IActionResult OnlinePayment(int id) { string userNumber = User.FindFirst(ClaimTypes.Email)?.Value; string roleId = User.FindFirst(ClaimTypes.Role)?.Value; var order = _orderService.GetOrderByOrderId(id); #region admin pyment if (roleId == "1") { foreach (var item in order.OrderDetails) { _productService.UpdateCountProduct(item.ProductId, item.Count); } ViewBag.IsSuccess = true; order.IsFinaly = true; order.FinalyDate = DateTime.Now; _orderService.UpdateOrder(order); Sms.SendSms("09372796350", " خرید ادمین ." + userNumber); return(View()); } #endregion #region user payment if (HttpContext.Request.Query["Status"] != "" && HttpContext.Request.Query["Status"].ToString().ToLower() == "ok" && HttpContext.Request.Query["Authority"] != "") { string authority = HttpContext.Request.Query["Authority"]; string Name = User.FindFirst(ClaimTypes.Name)?.Value; var payment = new Zarinpal.Payment("054939ee-3bc1-11ea-9822-000c295eb8fc", order.OrderSum + 15000); var res = payment.Verification(authority).Result; if (res.Status == 100) { foreach (var item in order.OrderDetails) { _productService.UpdateCountProduct(item.ProductId, item.Count); } ViewBag.code = res.RefId; ViewBag.IsSuccess = true; order.IsFinaly = true; order.FinalyDate = DateTime.Now; _orderService.UpdateOrder(order); Sms.SendSms(userNumber, $"{Name} عزیز خرید شما با موفقیت انجام شد . کد پیگیری : {res.RefId} "); Sms.SendSms("09372796350", "پرداخت فاکتور ." + userNumber); return(View()); } return(View()); } #endregion return(View()); }
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())); } }