public ActionResult CallBack(string authority, string status) { String Status = status; CallBackViewModel callBack = new CallBackViewModel() { }; if (Status != "OK") { callBack.IsSuccess = false; } else { try { string merchantId = db.ShopConfigurations.FirstOrDefault(c => c.Name == "zarinpal").Value; var zarinpal = ZarinPal.ZarinPal.Get(); zarinpal.EnableSandboxMode(); String Authority = authority; long Amount = GetAmountByAuthority(Authority); var verificationRequest = new ZarinPal.PaymentVerification(merchantId, Amount, Authority); var verificationResponse = zarinpal.InvokePaymentVerification(verificationRequest); if (verificationResponse.Status == 100) { Order order = GetOrderByAuthority(authority); if (order != null) { order.IsPaid = true; order.PaymentDate = DateTime.Now; order.RefId = verificationResponse.RefID; order.LastModifiedDate = DateTime.Now; db.SaveChanges(); callBack.IsSuccess = true; callBack.OrderCode = order.Code.ToString(); callBack.RefrenceId = verificationResponse.RefID; callBack.TotalAmount = order.TotalAmount.ToString("N0") + " تومان"; // UpdateUserPoint(order); } else { callBack.IsSuccess = false; callBack.RefrenceId = "سفارش پیدا نشد"; } } else { callBack.IsSuccess = false; callBack.RefrenceId = verificationResponse.Status.ToString(); } } catch (Exception e) { callBack.IsSuccess = false; callBack.RefrenceId = "خطا سیستمی. لطفا با پشتیبانی سایت تماس بگیرید"; } } return(View(callBack)); }
public ActionResult CallBack(string authority, string status) { String Status = status; CallBackViewModel callBack = new CallBackViewModel() { Menu = menuHelper.ReturnMenu(), FooterLink = menuHelper.GetFooterLink() }; if (Status != "OK") { callBack.IsSuccess = false; } else { try { var zarinpal = ZarinPal.ZarinPal.Get(); zarinpal.DisableSandboxMode(); String Authority = authority; long Amount = GetAmountByAuthority(Authority); var verificationRequest = new ZarinPal.PaymentVerification(MerchantId, Amount, Authority); var verificationResponse = zarinpal.InvokePaymentVerification(verificationRequest); if (verificationResponse.Status == 100 || verificationResponse.Status == 101) { Order order = GetOrderByAuthority(authority); if (order != null) { order.IsPaid = true; order.PaymentDate = DateTime.Now; order.RefId = verificationResponse.RefID; db.SaveChanges(); callBack.IsSuccess = true; callBack.OrderCode = order.Code.ToString(); callBack.RefrenceId = verificationResponse.RefID; // UpdateUserPoint(order); OrderDetail orderDetail = db.OrderDetails.FirstOrDefault(current => current.OrderId == order.Id); if (orderDetail != null) { Product product = db.Products.Find(orderDetail.ProductId); if (product != null) { User user = db.Users.Find(order.UserId); string message = "سفارش شما با شماره پیگیری " + callBack.RefrenceId + " در وب سایت راش وب ثبت گردید "; SendSms.SendCommonSms(user.CellNum, message); List <User> admins = db.Users.Where(current => current.IsActive && !current.IsDeleted && current.Role.Name == "Administrator").ToList(); foreach (User admin in admins) { message = "یک سفارش با کد " + order.Code + " در وب سایت راش وب ثبت شده است."; SendSms.SendCommonSms(admin.CellNum, message); } //ViewBag.Email = order.DeliverEmail; //CreateEmail(order.Email, fileLink, orderType); } } } else { callBack.IsSuccess = false; callBack.RefrenceId = "سفارش پیدا نشد"; } } else { callBack.IsSuccess = false; callBack.RefrenceId = verificationResponse.Status.ToString(); } } catch (Exception e) { callBack.IsSuccess = false; callBack.RefrenceId = "خطا سیستمی. لطفا با پشتیبانی سایت تماس بگیرید"; } } return(View(callBack)); }
public ActionResult CallBack(string authority, string status) { String Status = status; CallBackViewModel callBack = new CallBackViewModel(); if (Status != "OK") { callBack.IsSuccess = false; callBack.RefrenceId = "414"; Order order = GetOrderByAuthority(authority); if (order != null) { callBack.Order = order; callBack.OrderDetails = db.OrderDetails .Where(c => c.OrderId == order.Id && c.IsDeleted == false).Include(c => c.Product).ToList(); } } else { try { var zarinpal = ZarinPal.ZarinPal.Get(); zarinpal.EnableSandboxMode(); String Authority = authority; long Amount = GetAmountByAuthority(Authority); var verificationRequest = new ZarinPal.PaymentVerification(MerchantId, Amount, Authority); var verificationResponse = zarinpal.InvokePaymentVerification(verificationRequest); if (verificationResponse.Status == 100 || verificationResponse.Status == 101) { Order order = GetOrderByAuthority(authority); if (order != null) { order.IsPaid = true; order.PaymentDate = DateTime.Now; order.RefId = verificationResponse.RefID; db.SaveChanges(); callBack.Order = order; callBack.IsSuccess = true; callBack.OrderCode = order.Code.ToString(); callBack.RefrenceId = verificationResponse.RefID; callBack.OrderDetails = db.OrderDetails .Where(c => c.OrderId == order.Id && c.IsDeleted == false).Include(c => c.Product).ToList(); foreach (OrderDetail orderDetail in callBack.OrderDetails) { Product product = orderDetail.Product; product.Quantity = orderDetail.Product.Quantity - 1; if (product.Quantity == 0) { product.IsAvailable = false; } db.SaveChanges(); } } else { callBack.IsSuccess = false; callBack.RefrenceId = "سفارش پیدا نشد"; } } else { callBack.IsSuccess = false; callBack.RefrenceId = verificationResponse.Status.ToString(); } } catch (Exception e) { callBack.IsSuccess = false; callBack.RefrenceId = "خطا سیستمی. لطفا با پشتیبانی سایت تماس بگیرید"; } } ViewBag.HeaderImage = db.Texts.Where(x => x.TextType.Name == "returnfrombank").FirstOrDefault().ImageUrl; return(View(callBack)); }
public ActionResult CallBack(string authority, string status) { String Status = status; CallBackViewModel callBack = new CallBackViewModel(); callBack.MenuProductGroups = baseViewModel.GetMenu(); callBack.MenuServiceGroups = baseViewModel.GetMenuServices(); callBack.FooterRecentBlog = baseViewModel.GetFooterRecentBlog(); Deletecookie(); if (Status != "OK") { callBack.IsSuccess = false; } else { try { var zarinpal = ZarinPal.ZarinPal.Get(); // zarinpal.DisableSandboxMode(); zarinpal.DisableSandboxMode(); String Authority = authority; long Amount = GetAmountByAuthority(Authority); var verificationRequest = new ZarinPal.PaymentVerification(MerchantId, Amount, Authority); var verificationResponse = zarinpal.InvokePaymentVerification(verificationRequest); if (verificationResponse.Status == 100) { Order order = GetOrderByAuthority(authority); if (order != null) { order.IsPaid = true; order.PaymentDate = DateTime.Now; order.SaleReferenceId = verificationResponse.RefID; order.OrderStatusId = db.OrderStatuses.FirstOrDefault(current => current.Code == 1).Id; db.SaveChanges(); List <Product> products = RetrunProducts(order.Id); callBack.IsSuccess = true; callBack.OrderCode = order.Code.ToString(); callBack.RefrenceId = verificationResponse.RefID; callBack.Products = products; callBack.CreationDate = order.CreationDateStr; String onlineConsult = WebConfigurationManager.AppSettings["online-consult"]; string productType = products.FirstOrDefault()?.ProductGroup.UrlParam; callBack.ProductType = productType; if (productType == onlineConsult) { UpdateQuestionOrderId(order.Id); } CreateSucessMessage("", order.User.CellNum, order.User.FullName); } else { callBack.IsSuccess = false; callBack.RefrenceId = "سفارش پیدا نشد"; callBack.Products = null; } } else { callBack.IsSuccess = false; callBack.RefrenceId = verificationResponse.Status.ToString(); callBack.Products = null; } } catch (Exception e) { callBack.IsSuccess = false; callBack.RefrenceId = "خطا سیستمی. لطفا با پشتیبانی سایت تماس بگیرید"; callBack.Products = null; } } return(View(callBack)); }