public virtual JsonResult Pay(int orderId, int paymentGatewayId, string code) { var shortlink = _shortLinkBusiness.Value.Find(code); if (shortlink == null) { return(Json(new { IsSuccessful = false, Message = LocalMessage.RecordsNotFound })); } var gatewayRep = _paymentGatewayBusiness.GetPaymentGateway(paymentGatewayId); if (!gatewayRep.IsSuccessful) { return(Json(new { IsSuccessful = false, Message = LocalMessage.RecordsNotFound })); } var order = _orderBusiness.Find(orderId, "OrderItems,Transactions"); var result = PaymentFactory.GetInstance(gatewayRep.Result.BankName).Do(gatewayRep.Result, new TransactionModel { OrderId = orderId, PaymentGatewayId = paymentGatewayId, Price = order.TotalPrice() - order.Transactions.Where(x => x.IsSuccess).Sum(x => x.Price), UserId = shortlink.UserId }); return(Json(result)); }
public virtual ViewResult PayVerify(PayRedirectModel model) { ViewBag.PaymentGateway = BankNames.Pay; if (model.IsNotNull()) { var transaction = _transactionBusiness.Find(model.factorNumber); if (transaction.IsNull()) { ViewBag.ErrorMessage = LocalMessage.PaymentException; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } var gateWay = _paymentGatewayBusiness.Find(transaction.PaymentGatewayId); if (gateWay.IsNull()) { return(View(viewName: MVC.Transaction.Views.Failed, model: LocalMessage.PaymentException)); } var result = PaymentFactory.GetInstance(gateWay.BankName).Verify(gateWay, transaction, model); if (result.IsSuccessful) { return(View(viewName: MVC.Transaction.Views.Success, model: transaction)); } transaction.TrackingId = "0"; ViewBag.ErrorMessage = result.Message; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } ViewBag.ErrorMessage = LocalMessage.RedirectException; return(View(viewName: MVC.Transaction.Views.Failed, model: LocalMessage.RedirectException)); }
public virtual ViewResult PasargadVerify(int IN, string tref, string id) { ViewBag.PaymentGateway = BankNames.Pasargad; var transaction = _transactionBusiness.Find(IN); ViewBag.ReturnUrl = Url.Action(MVC.Home.ActionNames.AddOrder, MVC.Home.Name); if (transaction.IsNull()) { ViewBag.ErrorMessage = LocalMessage.PaymentException; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } var gateWay = _paymentGatewayBusiness.Find(transaction.PaymentGatewayId); if (gateWay.IsNull()) { ViewBag.ReturnUrl = $"/Home/{transaction.OrderId}/{transaction.Order.UserId}"; ViewBag.ErrorMessage = LocalMessage.OperationFailed; return(View(viewName: MVC.Transaction.Views.Failed, transaction)); } var result = PaymentFactory.GetInstance(gateWay.BankName).Verify(gateWay, transaction, tref); if (!result.IsSuccessful) { ViewBag.ReturnUrl = $"/Home/{transaction.OrderId}/{transaction.Order.UserId}"; transaction.TrackingId = "0"; ViewBag.ErrorMessage = result.Message; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } return(View(viewName: MVC.Transaction.Views.Success, model: transaction)); }
public virtual ViewResult ZarinPalVerify(string Status, string Authority) { ViewBag.PaymentGateway = BankNames.ZarinPal; if (!string.IsNullOrEmpty(Status) && !string.IsNullOrEmpty(Authority)) { var transaction = _transactionBusiness.Find(Authority.Trim()); if (transaction.IsNull()) { ViewBag.ErrorMessage = LocalMessage.PaymentException; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } var _order = _orderBusiness.Find(transaction.OrderId); var gateWay = _paymentGatewayBusiness.Find(transaction.PaymentGatewayId); if (gateWay.IsNull()) { ViewBag.ErrorMessage = LocalMessage.PaymentException; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } var result = PaymentFactory.GetInstance(gateWay.BankName).Verify(gateWay, transaction); if (result.IsSuccessful) { return(View(viewName: MVC.Transaction.Views.Success, model: transaction)); } ViewBag.ErrorMessage = result.Message; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } ViewBag.ErrorMessage = LocalMessage.RedirectException; return(View(viewName: MVC.Transaction.Views.Failed, model: new Transaction())); }
public virtual ViewResult SadadVerify(SadadPurchaseResult model) { // FileLoger.Info(JsonConvert.SerializeObject(model), GlobalVariable.LogPath); ViewBag.PaymentGateway = BankNames.Melli; if (model.IsNotNull()) { var transaction = _transactionBusiness.Find(model.OrderId); if (transaction.IsNull()) { ViewBag.ErrorMessage = LocalMessage.PaymentException; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } var gateWay = _paymentGatewayBusiness.Find(transaction.PaymentGatewayId); if (gateWay.IsNull()) { return(View(viewName: MVC.Transaction.Views.Failed, model: LocalMessage.PaymentException)); } var result = PaymentFactory.GetInstance(gateWay.BankName).Verify(gateWay, transaction, model); if (result.IsSuccessful) { return(View(viewName: MVC.Transaction.Views.Success, model: transaction)); } transaction.TrackingId = "0"; ViewBag.ErrorMessage = result.Message; return(View(viewName: MVC.Transaction.Views.Failed, model: transaction)); } ViewBag.ErrorMessage = LocalMessage.RedirectException; return(View(viewName: MVC.Transaction.Views.Failed, model: LocalMessage.RedirectException)); }
public virtual ActionResult Submit(CompleteOrderModel model) { try { #region Checking var gatewayRep = _paymentGatewayBusiness.GetPaymentGateway(model.PaymentGatewayId); if (!gatewayRep.IsSuccessful) { return(Json(new { IsSuccessful = false, Message = LocalMessage.RecordsNotFound })); } if (model.AddressId != null) { var addrRep = _addressBusiness.Find((User as ICurrentUserPrincipal).UserId, model.AddressId ?? 0); if (!addrRep.IsSuccessful) { return(Json(new { IsSuccessful = false, Message = LocalMessage.RecordsNotFound })); } } #endregion #region Fill Some Props of Model model.UserId = (User as ICurrentUserPrincipal).UserId; #endregion var findOrder = _orderBusiness.UpdateBeforePayment(model); if (!findOrder.IsSuccessful) { return(Json(findOrder)); } var result = PaymentFactory.GetInstance(gatewayRep.Result.BankName).Do(gatewayRep.Result, new TransactionModel { OrderId = model.OrderId, PaymentGatewayId = model.PaymentGatewayId, Price = findOrder.Result.Item2, UserId = (User as ICurrentUserPrincipal).UserId }); return(Json(result)); } catch (Exception e) { FileLoger.Error(e); return(Json(new { IsSuccessful = false, Message = LocalMessage.Error })); } }
public virtual JsonResult SubmitCompleteOrder(CompleteOrderModel model) { #region Checking var gatewayRep = _paymentGatewayBusiness.GetPaymentGateway(model.PaymentGatewayId); if (!gatewayRep.IsSuccessful) { return(Json(new { IsSuccessful = false, Message = LocalMessage.RecordsNotFound })); } if (model.AddressId != null) { var addrRep = _addressBusiness.Find((User as ICurrentUserPrincipal).UserId, model.AddressId ?? 0); if (!addrRep.IsSuccessful) { return(Json(new { IsSuccessful = false, Message = LocalMessage.RecordsNotFound })); } } #endregion #region Fill Some Props of Model model.UserId = (User as ICurrentUserPrincipal).UserId; #endregion var rep = _orderBusiness.CompleteOrder(model); if (!rep.IsSuccessful) { return(Json(rep)); } if (model.PaymentType == PaymentType.InPerson) { return(Json(new { rep.IsSuccessful, Result = Url.Action(MVC.Attachment.ActionNames.UploadAfterTransacttion, MVC.Attachment.Name, new { rep.Result.OrderId }) })); } var result = PaymentFactory.GetInstance(gatewayRep.Result.BankName).Do(gatewayRep.Result, new TransactionModel { OrderId = model.OrderId, PaymentGatewayId = model.PaymentGatewayId, Price = rep.Result.TotalPrice(), UserId = (User as ICurrentUserPrincipal).UserId }); return(Json(result)); }
public virtual JsonResult SubmitPayAllFactor(int orderId, PaymentType paymentType, int paymentGatewayId) { if (paymentType == PaymentType.InPerson) { return(Json(new { IsSuccessful = true, Result = Url.Action(MVC.Attachment.ActionNames.UploadAfterTransacttion, MVC.Attachment.Name, new { orderId }) })); } var gatewayRep = _paymentGatewayBusiness.GetPaymentGateway(paymentGatewayId); if (!gatewayRep.IsSuccessful) { return(Json(new { IsSuccessful = false, Message = LocalMessage.RecordsNotFound })); } var order = _orderBusiness.Find(orderId, "OrderItems,Transactions"); var result = PaymentFactory.GetInstance(gatewayRep.Result.BankName).Do(gatewayRep.Result, new TransactionModel { OrderId = orderId, PaymentGatewayId = paymentGatewayId, Price = order.TotalPrice() - order.Transactions.Where(x => x.IsSuccess).Sum(x => x.Price), UserId = (User as ICurrentUserPrincipal).UserId }); return(Json(result)); }