public async Task <IActionResult> BookPaymentInfo(CustomerBook customerBook) { try { var book = await PersianNovComponent.Instance.BookFacade.GetAsync(customerBook.BookId); var customer = await PersianNovComponent.Instance.CustomerFacade.GetAsync(customerBook.CustomerId); if (book != null && book.Price != 0) { 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 result = payment.PaymentRequest("پرداخت کتاب " + book.Name, $"{config.GetSection("OrginUrl").Value}/فاکتور/{customerBook.BookId}/{customerBook.CustomerId}", customer.Email); if (result.Result.Status == 100) { return(Redirect("https://zarinpal.com/pg/StartPay/" + result.Result.Authority)); } else { throw new KnownException("خطایی در روند پرداخت رخ داده است لطفا با واحد پشتیبانی تماس بگیرید"); } } customerBook.Book = book; customerBook.Customer = customer; return(View(customerBook)); } catch (Exception ex) { ViewBag.Message = ex.Message; return(View(customerBook)); } }
public async Task <IActionResult> BookPaymentInfo(Guid id, string title) { var customerId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id")?.Value; var isVip = PersianNovComponent.Instance.CustomerBookFacade.Any(x => x.BookId == id && x.CustomerId == customerId.ToGuid()); if (isVip) { return(Redirect($"/رمان-فارسی/{title}")); } var model = new CustomerBook() { BookId = id, Book = await PersianNovComponent.Instance.BookFacade.GetAsync(id), CustomerId = customerId.ToGuid(), Customer = await PersianNovComponent.Instance.CustomerFacade.GetAsync(customerId.ToGuid()) }; return(View(model)); }
public bool InsertPayment(Guid bookId, Guid customerId, long number) { base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var book = new BookBO().Get(base.ConnectionHandler, bookId); var sum = book.Discount > 0 ? book.Price.Value - (book.Price.Value * book.Discount / 100) : book.Price.Value; try { var customerBook = new CustomerBook() { BookId = bookId, CustomerId = customerId, VIP = true }; if (!new CustomerBookBO().Insert(base.ConnectionHandler, customerBook)) { throw new KnownException("خطا در ذخیره اطلاعات"); } var order = new Order() { Number = number, OrderDate = DateTime.Now.ShamsiDate(), TotalAmount = book.Price.Value, Discount = book.Discount, Amount = sum, Status = PaymentStatus.Success, CustomerId = customerId, BookId = bookId }; if (!new OrderBO().Insert(base.ConnectionHandler, order)) { throw new KnownException("خطا در ذخیره اطلاعات"); } var peyment = new Payment() { Number = number, OrderId = order.Id, Amount = sum, PaymentDate = DateTime.Now.ShamsiDate(), PaymentStatus = PaymentStatus.Success, PaymentType = PaymentType.Online, PaymentRole = PaymentRole.Success, AuthorId = book.AuthorId, CustomerId = customerId }; if (!new PaymentBO().Insert(base.ConnectionHandler, peyment)) { throw new KnownException("خطا در ذخیره اطلاعات"); } var walletBo = new WalletBO(); var amount = sum * book.Percent / 100; var wa = new Wallet() { AuthorId = book.AuthorId, Amount = amount, Input = amount, Number = number, BookId = bookId }; if (!walletBo.Insert(base.ConnectionHandler, wa)) { throw new KnownException("خطا در ذخیره اطلاعات"); } base.ConnectionHandler.CommitTransaction(); return(true); } catch (Exception ex) { base.ConnectionHandler.RollBack(); throw new KnownException(ex.Message); } }