public ActionResult ThanhToanOnline(int maDH) { HoaDon hd = db.HoaDon.Find(maDH); //Get Config Info string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat //Get payment input OrderInfo orderInfo = new OrderInfo(); //Save order to db orderInfo.OrderId = hd.MaDonHang; orderInfo.Amount = Convert.ToDecimal(hd.TongTien); orderInfo.OrderDescription = hd.DiaChi; orderInfo.CreatedDate = DateTime.Now; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); string locale = "vn"; if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", orderInfo.OrderId.ToString()); vnpay.AddRequestData("vnp_OrderId", hd.MaDonHang.ToString()); vnpay.AddRequestData("vnp_OrderInfo", hd.MaDonHang.ToString()); vnpay.AddRequestData("vnp_OrderType", "other"); //default value: other vnpay.AddRequestData("vnp_Amount", Math.Round(orderInfo.Amount * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", orderInfo.CreatedDate.ToString("yyyyMMddHHmmss")); //if (bank.SelectedItem != null && !string.IsNullOrEmpty(bank.SelectedItem.Value)) //{ vnpay.AddRequestData("vnp_BankCode", "NCB"); //} string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); Debug.WriteLine("VNPAY URL: {0}", paymentUrl); Session["cart"] = new List <Item>(); return(Redirect(paymentUrl)); //return RedirectToAction("Success"); }
protected void btnPay_Click(object sender, EventArgs e) { //Get Config Info string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat //Get payment input // OrderInfo order = new OrderInfo(); Tour tour = new Tour(); OrderInfo order = new OrderInfo(); //Save order to db order.OrderId = DateTime.Now.Ticks; order.Amount = Convert.ToDecimal(Amount.Text); order.OrderDescription = OrderDescription.Text; order.CreatedDate = DateTime.Now; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); string locale = language.SelectedItem.Value; if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", order.OrderId.ToString()); vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); vnpay.AddRequestData("vnp_OrderType", orderCategory.SelectedItem.Value); //default value: other vnpay.AddRequestData("vnp_Amount", (order.Amount * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", order.CreatedDate.ToString("yyyyMMddHHmmss")); if (bank.SelectedItem != null && !string.IsNullOrEmpty(bank.SelectedItem.Value)) { vnpay.AddRequestData("vnp_BankCode", bank.SelectedItem.Value); } string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); // log.InfoFormat("VNPAY URL: {0}", paymentUrl); Response.Redirect(paymentUrl); }
// private static readonly ILog log = // LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); protected void Page_Load(object sender, EventArgs e) { //Get Config Info string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat //Get payment input OrderInfo order = new OrderInfo(); //Save order to db order.OrderId = DateTime.Now.Ticks; order.Amount = Convert.ToDecimal(Request.QueryString["Amount"]); order.OrderDescription = Request.QueryString["OrderDescription"]; order.CreatedDate = DateTime.Now; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); string locale = "vn";//"en" if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", order.OrderId.ToString()); vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); vnpay.AddRequestData("vnp_OrderType", "insurance"); //default value: other vnpay.AddRequestData("vnp_Amount", (order.Amount * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", order.CreatedDate.ToString("yyyyMMddHHmmss")); //if (bank.SelectedItem != null && !string.IsNullOrEmpty(bank.SelectedItem.Value)) //{ // vnpay.AddRequestData("vnp_BankCode", bank.SelectedItem.Value); //} string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); //log.InfoFormat("VNPAY URL: {0}", paymentUrl); Response.Clear(); Response.Write("{\"code\":\"00\",\"Message\":\"Confirm Success\",\"data\":\"" + paymentUrl + "\"}"); Response.End(); }
public ActionResult Checkout(CheckoutViewModel model) { string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat //Get payment input OrderInfo order = new OrderInfo(); //Save order to db order.OrderId = DateTime.Now.Ticks; order.Amount = Convert.ToDecimal(model.Amount); order.OrderDescription = model.OrderDescription; order.CreatedDate = DateTime.Now; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); string locale = "vn"; if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", order.OrderId.ToString()); vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); vnpay.AddRequestData("vnp_OrderType", model.OrderCategory); //default value: other vnpay.AddRequestData("vnp_Amount", (order.Amount * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", order.CreatedDate.ToString("yyyyMMddHHmmss")); if (model.Bank != null && !string.IsNullOrEmpty(model.Bank)) { vnpay.AddRequestData("vnp_BankCode", model.Bank); } string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); log.InfoFormat("VNPAY URL: {0}", paymentUrl); return(Redirect(paymentUrl)); }
public IActionResult ShopOnline(OrderInfo orderInfo) { // Console.WriteLine(orderInfo.bank); //Get Config Info string vnp_Returnurl = _vnpay.vnp_Returnurl; //URL nhan ket qua tra ve string vnp_Url = _vnpay.vnp_Url; //URL thanh toan cua VNPAY string vnp_TmnCode = _vnpay.vnp_TmnCode; //Ma website string vnp_HashSecret = _vnpay.vnp_HashSecret; //Chuoi bi mat //Get payment input OrderInfo order = new OrderInfo(); //Save order to db order.OrderId = DateTime.Now.Ticks; order.Amount = Convert.ToDecimal(orderInfo.Amount); order.OrderDescription = orderInfo.OrderDescription; order.CreatedDate = DateTime.Now; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); string locale = orderInfo.language; if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } Utils utils = new Utils(_httpContextAccessor); vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", order.OrderId.ToString()); vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); vnpay.AddRequestData("vnp_OrderType", orderInfo.OrderCatory); //default value: other vnpay.AddRequestData("vnp_Amount", (order.Amount * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", utils.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", order.CreatedDate.ToString("yyyyMMddHHmmss")); if (orderInfo.bank != null && !string.IsNullOrEmpty(orderInfo.bank)) { vnpay.AddRequestData("vnp_BankCode", orderInfo.bank); } string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); log.InfoFormat("VNPAY URL: {0}", paymentUrl); Response.Redirect(paymentUrl); return View(); }
public void thanhToan(int id, int tien_, string bank) { //Get Config Info string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat // Debug.WriteLine(Convert.ToInt32(tienThanhToan_)); int maThanhToan = donDatTourController.themGiaoDich(id, tien_); if (maThanhToan != 0) { //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); vnpay.AddRequestData("vnp_Locale", "vn"); vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", maThanhToan.ToString()); vnpay.AddRequestData("vnp_OrderInfo", "ghi chu"); vnpay.AddRequestData("vnp_OrderType", "other"); //default value: other vnpay.AddRequestData("vnp_Amount", (tien_ * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", DateTime.Now.ToString("yyyyMMddHHmmss")); vnpay.AddRequestData("vnp_BankCode", bank); string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); // log.InfoFormat("VNPAY URL: {0}", paymentUrl); Debug.WriteLine(paymentUrl); Response.Redirect(paymentUrl); Debug.WriteLine("Dat TOur thanh Cong."); } else { Debug.WriteLine("Dat Tour THat Bai"); } }
public string GetUrl(int AppId) { //Get Config Info //Get payment input BuyPackageHistory order = cnn.BuyPackageHistories.Find(AppId); //Save order to db //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", SystemParam.vnp_TmnCode); string locale = "vn";//"en" if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", order.ID.ToString()); vnpay.AddRequestData("vnp_OrderInfo", order.ServicePackage.PackageName); vnpay.AddRequestData("vnp_OrderType", "insurance"); //default value: other vnpay.AddRequestData("vnp_Amount", (order.Price * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", SystemParam.vnp_Return_url); vnpay.AddRequestData("vnp_IpAddr", GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", DateTime.Now.ToString("yyyyMMddHHmmss")); //if (bank.SelectedItem != null && !string.IsNullOrEmpty(bank.SelectedItem.Value)) //{ // vnpay.AddRequestData("vnp_BankCode", bank.SelectedItem.Value); //} string paymentUrl = vnpay.CreateRequestUrl(SystemParam.vnp_Url, SystemParam.vnp_HashSecret); return(paymentUrl); }
public string paymentOrder(OrderInfor orderInfor) { //Get Config Info string vnp_Returnurl = "https://vnpay.vn/"; //URL nhan ket qua tra ve string vnp_Url = "http://sandbox.vnpayment.vn/paymentv2/vpcpay.html"; //URL thanh toan cua VNPAY string vnp_TmnCode = "52HMR9SZ"; //Ma website string vnp_HashSecret = "NAQYDDNIAKILYBXEAJBGBFCOPZTXLUYC"; //Chuoi bi mat //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); string locale = "vn"; if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", orderInfor.OrderId.ToString()); //Mã tham chiếu của giao dịch tại hệ thống của merchant. Mã này là duy nhất đùng để phân biệt các đơn hàng gửi sang VNPAY. Không được trùng lặp trong ngày. vnpay.AddRequestData("vnp_OrderInfo", "THANHTOAN"); vnpay.AddRequestData("vnp_OrderType", "130000"); //default value: other vnpay.AddRequestData("vnp_Amount", (orderInfor.Amount * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", DateTime.Now.ToString("yyyyMMddHHmmss")); vnpay.AddRequestData("vnp_BankCode", "NCB"); string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); return(paymentUrl); }
public async Task <IActionResult> Checkout(CheckoutViewModel model) { var sessions = HttpContext.Session.Get <List <ShoppingCartViewModel> >(CommonConstants.CartSession); if (ModelState.IsValid) { if (sessions != null) { var details = new List <BillDetailViewModel>(); decimal totalMoney = 0; bool canBuy = true; foreach (var item in sessions) { totalMoney += item.Price * item.Quantity; details.Add(new BillDetailViewModel() { Price = item.Price, ColorId = item.Color.Id, SizeId = item.Size.Id, Quantity = item.Quantity, ProductId = item.Product.Id }); canBuy = await _quantityService.SellProduct(item.Product.Id, item.Quantity); if (!canBuy) { break; } } if (canBuy) { var billViewModel = new BillViewModel() { CustomerMobile = model.CustomerMobile, BillStatus = BillStatus.New, CustomerAddress = model.CustomerAddress, CustomerName = model.CustomerName, CustomerMessage = model.CustomerMessage, BillDetails = details, DateCreated = DateTime.Now, PaymentMethod = model.PaymentMethod }; if (User.Identity.IsAuthenticated) { billViewModel.CustomerId = Guid.Parse(User.GetSpecificDefault("UserId")); } var dataReturn = await _billService.Create(billViewModel); _billService.Save(); HttpContext.Session.Set(CommonConstants.BillSession, dataReturn); string vnp_Returnurl = _configuration["VNPAY:vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = _configuration["VNPAY:vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = _configuration["VNPAY:vnp_TmnCode"]; //Ma website string vnp_HashSecret = _configuration["VNPAY:vnp_HashSecret"]; //Chuoi bi mat HttpContextAccessor accessor = new HttpContextAccessor(); VnPayLibrary vnpay = new VnPayLibrary(accessor); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); vnpay.AddRequestData("vnp_Locale", "vn"); vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", DateTime.Now.Ticks.ToString()); vnpay.AddRequestData("vnp_OrderInfo", "Noi dung thanh toan:20190421030204"); vnpay.AddRequestData("vnp_OrderType", "topup"); //default value: other vnpay.AddRequestData("vnp_Amount", ((int)totalMoney * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", vnpay.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", DateTime.Now.ToString("yyyyMMddHHmmss")); vnpay.AddRequestData("vnp_BankCode", "NCB"); string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); return(new OkObjectResult(new { status = true, url = paymentUrl })); } return(new OkObjectResult(new { status = false, message = "Hiện số lượng sản phẩm không đủ." })); } model.Carts = sessions; HttpContext.Session.Set(CommonConstants.CartSession, new List <ShoppingCartViewModel>()); return(View(model)); } return(new OkObjectResult("")); }
//string menhgia,string moblie,string nhamang,string type public ActionResult RePay(string moblie, string id) { var id_order = Int32.Parse(Request["id"]); var nhamang = Request["nhamang"]; var type = Request["type"]; var menhgia = Convert.ToInt32(Request["menhgia"]); var valueMenhgia = db.ShowDenomination().Find(c => c.ID == menhgia); var sdt = Int32.Parse(moblie); InforOrder inforOrder = new InforOrder(); inforOrder.phone = sdt; inforOrder.denomination = valueMenhgia.ID; inforOrder.network = nhamang; inforOrder.CardType = type; inforOrder.id_order = id_order; Session["InforOrder"] = inforOrder; ViewBag.mobile = sdt; ViewBag.menhgia = Request["menhgia"]; ViewBag.valueMenhgia = valueMenhgia; ViewBag.nhamang = Request["nhamang"]; ViewBag.type = Request["type"]; string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat //Get payment input OrderInfo order = new OrderInfo(); order.OrderId = DateTime.Now.Ticks; order.Phone = Convert.ToInt32(moblie); order.Amount = Convert.ToInt32(valueMenhgia.Price); order.OrderDescription = "aloalo thanh toan"; order.CreatedDate = DateTime.Now; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); string locale = "vn";//"en" if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", order.OrderId.ToString()); vnpay.AddRequestData("vnp_Phone", order.Phone.ToString()); vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); vnpay.AddRequestData("vnp_OrderType", "insurance"); //default value: other vnpay.AddRequestData("vnp_Amount", (order.Amount * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", order.CreatedDate.ToString("yyyyMMddHHmmss")); string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); ViewBag.demoUrl = paymentUrl; return(View()); }
public async Task <IActionResult> PaymentAsync() { //Get Config Info string vnp_Returnurl = _configuration.GetSection("VNPayInfo").GetSection("vnp_Returnurl").Value; //URL nhan ket qua tra ve string vnp_Url = _configuration.GetSection("VNPayInfo").GetSection("vnp_Url").Value; //URL thanh toan cua VNPAY string vnp_TmnCode = _configuration.GetSection("VNPayInfo").GetSection("vnp_TmnCode").Value; //Ma website string vnp_HashSecret = _configuration.GetSection("VNPayInfo").GetSection("vnp_HashSecret").Value; //Chuoi bi mat if (string.IsNullOrEmpty(vnp_TmnCode) || string.IsNullOrEmpty(vnp_HashSecret)) { return(Json("Vui lòng cấu hình các tham số: vnp_TmnCode,vnp_HashSecret trong file appsetting.json")); } //Get payment input OrderInfo order = new OrderInfo(); //Save order to db order.OrderId = Guid.NewGuid().ToString(); order.Amount = 10000; order.OrderDescription = "VIP1"; order.CreatedDate = DateTime.Now; order.BankCode = "NCB"; order.Status = 0; _context.Add(order); await _context.SaveChangesAsync(); string locale = "vn"; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); vnpay.AddRequestData("vnp_Amount", (order.Amount * 100).ToString()); //if (cboBankCode.SelectedItem != null && !string.IsNullOrEmpty(cboBankCode.SelectedItem.Value)) //{ // vnpay.AddRequestData("vnp_BankCode", cboBankCode.SelectedItem.Value); //} vnpay.AddRequestData("vnp_BankCode", "NCB"); vnpay.AddRequestData("vnp_CreateDate", order.CreatedDate.ToString("yyyyMMddHHmmss")); vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_IpAddr", Models.Utils.GetIpAddress()); if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); //vnpay.AddRequestData("vnp_OrderType", orderCategory.SelectedItem.Value); //default value: other vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_TxnRef", order.OrderId); string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); //log.InfoFormat("VNPAY URL: {0}", paymentUrl); Response.Redirect(paymentUrl); return(Json("Success")); }
// GET: Membership public ActionResult VnPayMembership(string amount, string description) { var getAmount = Convert.ToDecimal(amount); var listMemberType = db.Members.ToList(); var validate = false; foreach (var memberType in listMemberType) { if (description == memberType.MemberType && getAmount == memberType.Price) { validate = true; break; } } if (validate == false) { return(RedirectToAction("Index", "Home")); } //Get Config Info string vnp_Returnurl = "https://localhost:44302/Home"; //URL nhan ket qua tra ve string vnp_Url = "http://sandbox.vnpayment.vn/paymentv2/vpcpay.html"; //URL thanh toan cua VNPAY string vnp_TmnCode = "P1V8JH37"; //Ma website string vnp_HashSecret = "XAUJIMFNKYUUWWNWOLLNIHJCUGLOIGEF"; //Chuoi bi mat var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); //Get payment input OrderInfo order = new OrderInfo(); //Save order to db order.OrderId = "DH" + DateTime.Now.Ticks.ToString(); TempData["OrderId"] = order.OrderId; order.Status = Convert.ToInt16(OrderStatus.Pending); var userId = User.Identity.GetUserId(); order.UserId = userId; order.ApplicationUser = UserManager.FindById(userId); order.Amount = Math.Round(getAmount); order.OrderDescription = description; order.CreatedAt = DateTime.Now; db.OrderInfos.Add(order); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); throw; } //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); vnpay.AddRequestData("vnp_Amount", (order.Amount * 23145 * 100).ToString()); vnpay.AddRequestData("vnp_BankCode", "NCB"); vnpay.AddRequestData("vnp_CreateDate", DateTime.Now.ToString("yyyyMMddHHmmss")); vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_Locale", "vn"); vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); vnpay.AddRequestData("vnp_OrderType", "190002"); //default value: other vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_TxnRef", order.OrderId.ToString()); string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); log.InfoFormat("VNPAY URL: {0}", paymentUrl); return(Redirect(paymentUrl)); }
public ActionResult ThanhToan(string name, string diachi, string sdt) { sdt = sdt.Trim(); var db = new BookContext(); var kh = Session["KhachHang"] as KhachHang; var lstItem = Session["cart"] as List <Item>; // insert khach hang if (kh == null) { KhachHang khachHang = db.KhachHang.Where(item => item.TaiKhoan.Equals(sdt)).FirstOrDefault(); if (khachHang == null) { kh = new KhachHang(); kh.HoTen = name; kh.NgaySinh = DateTime.Now; kh.TaiKhoan = sdt.Trim(); kh.MatKhau = "123456"; kh.LoaiKH = "Khách Hàng"; kh.flag = false; db.KhachHang.Add(kh); db.SaveChanges(); } else { kh = khachHang; } } // insert hoa don HoaDon hd = new HoaDon(); hd.NgayTao = DateTime.Now; hd.DaThanhToan = false; hd.MaKH = kh.MaKH; hd.TongTien = lstItem.Sum(item => item.Quantity * item.sach.GiaBan); hd.SDT = sdt; hd.DiaChi = diachi; hd.flag = false; hd.DaGiaoHang = false; hd.TrangThai = 1; db.HoaDon.Add(hd); db.SaveChanges(); foreach (Item item in lstItem) { ChiTietHoaDon cthd = new ChiTietHoaDon(); cthd.MaDonHang = hd.MaDonHang; cthd.MaSach = item.sach.MaSach; cthd.SoLuong = item.Quantity; cthd.ThanhTien = item.sach.GiaBan * item.Quantity; cthd.flag = false; db.ChiTietHoaDon.Add(cthd); } // insert log Log log = new Log(); log.flag = false; log.ThoiGian = DateTime.Now; log.TaiKhoan = kh.TaiKhoan; log.TacVu = "Admin"; log.HanhDong = "Đã mua sách với hóa đơn có mã: " + hd.MaDonHang; db.Log.Add(log); db.SaveChanges(); //Get Config Info string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat //Get payment input OrderInfo orderInfo = new OrderInfo(); //Save order to db orderInfo.OrderId = hd.MaDonHang; orderInfo.Amount = Convert.ToDecimal(hd.TongTien); orderInfo.OrderDescription = hd.DiaChi; orderInfo.CreatedDate = DateTime.Now; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); string locale = "vn"; if (!string.IsNullOrEmpty(locale)) { vnpay.AddRequestData("vnp_Locale", locale); } else { vnpay.AddRequestData("vnp_Locale", "vn"); } vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", orderInfo.OrderId.ToString()); vnpay.AddRequestData("vnp_OrderId", hd.MaDonHang.ToString()); vnpay.AddRequestData("vnp_OrderInfo", hd.MaDonHang.ToString()); vnpay.AddRequestData("vnp_OrderType", "other"); //default value: other vnpay.AddRequestData("vnp_Amount", Math.Round(orderInfo.Amount * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", orderInfo.CreatedDate.ToString("yyyyMMddHHmmss")); //if (bank.SelectedItem != null && !string.IsNullOrEmpty(bank.SelectedItem.Value)) //{ vnpay.AddRequestData("vnp_BankCode", "NCB"); //} string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); Debug.WriteLine("VNPAY URL: {0}", paymentUrl); Session["cart"] = new List <Item>(); return(Redirect(paymentUrl)); //return RedirectToAction("Success"); }
public ActionResult PaymentByVNPay() { try { //Get Config Info //string vnp_Returnurl = ConfigurationManager.AppSettings["/VNPay/Index"]; //URL nhan ket qua tra ve //string vnp_Url = ConfigurationManager.AppSettings["http://sandbox.vnpayment.vn/paymentv2/vpcpay.html"]; //URL thanh toan cua VNPAY //string vnp_TmnCode = ConfigurationManager.AppSettings["V44NHFT4"]; //Ma website //string vnp_HashSecret = ConfigurationManager.AppSettings["YXYUPGHVVOYZGQQBUBUJCLSEUMIUPMKI"]; //Chuoi bi mat string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat if (string.IsNullOrEmpty(vnp_TmnCode) || string.IsNullOrEmpty(vnp_HashSecret)) { //lblMessage.Text = "Vui lòng cấu hình các tham số: vnp_TmnCode,vnp_HashSecret trong file web.config"; //return; } //Get payment input var cart = (List <CartModel>)Session[CartSession.CartSesstion]; Decimal Amount = 0; foreach (var item in cart) { Amount += item.SOLUONG * item.SANPHAM.GIABAN; } if (Amount < 300000) { Amount += 30000; } OrderInfo order = new OrderInfo(); //Save order to db order.OrderId = DateTime.Now.Ticks; order.Amount = Convert.ToInt64(Amount); order.OrderDescription = "abc"; order.CreatedDate = DateTime.Now; //string locale = cboLanguage.SelectedItem.Value; //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); vnpay.AddRequestData("vnp_Amount", (order.Amount * 100).ToString()); //if (cboBankCode.SelectedItem != null && !string.IsNullOrEmpty(cboBankCode.SelectedItem.Value)) //{ // vnpay.AddRequestData("vnp_BankCode", cboBankCode.SelectedItem.Value); //} vnpay.AddRequestData("vnp_CreateDate", order.CreatedDate.ToString("yyyyMMddHHmmss")); vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); //if (!string.IsNullOrEmpty(locale)) //{ // vnpay.AddRequestData("vnp_Locale", locale); //} //else //{ // vnpay.AddRequestData("vnp_Locale", "vn"); //} vnpay.AddRequestData("vnp_Locale", "vn"); vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); vnpay.AddRequestData("vnp_OrderType", "other"); //default value: vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_TxnRef", order.OrderId.ToString()); string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); log.InfoFormat("VNPAY URL: {0}", paymentUrl); return(Redirect(paymentUrl)); } catch { return(View("Index")); } }
protected void btnDatVe_Click(object sender, EventArgs e) { if (tour.Value != null && maTG.Value != null && iNL.Value != null && iTE.Value != null) { int i = Convert.ToInt32(tourController.kiemTraSoChoCon(tour.Value, maTG.Value)); int s = Convert.ToInt32(iTE.Value); Debug.WriteLine("idso " + i + " " + (Convert.ToInt32(iNL.Value) + Convert.ToInt32(iTE.Value))); if (i >= (Convert.ToInt32(iNL.Value) + Convert.ToInt32(iTE.Value))) { //Get Config Info string vnp_Returnurl = ConfigurationManager.AppSettings["vnp_Returnurl"]; //URL nhan ket qua tra ve string vnp_Url = ConfigurationManager.AppSettings["vnp_Url"]; //URL thanh toan cua VNPAY string vnp_TmnCode = ConfigurationManager.AppSettings["vnp_TmnCode"]; //Ma website string vnp_HashSecret = ConfigurationManager.AppSettings["vnp_HashSecret"]; //Chuoi bi mat if (!phanTramDat.Text.Equals("none")) { // Debug.WriteLine(Convert.ToInt32(tienThanhToan_)); DonDatTour donDatTour = new DonDatTour(); donDatTour.ChoNL = Convert.ToInt32(iNL.Value); donDatTour.ChoTE = Convert.ToInt32(iTE.Value); donDatTour.MaTour = Convert.ToInt32(tour.Value); donDatTour.GhiChu = txtGhiChu.Text; donDatTour.NgayDat = DateTime.Now; //DateTime.UtcNow.Date; donDatTour.TienDaThanhToan = Convert.ToInt32(tien_tt.Value); //tienThanhToan_(tour.Value.ToString(), Convert.ToInt32(iTE.Value), Convert.ToInt32(iNL.Value)); donDatTour.MaNgaydi = Convert.ToInt32(maTG.Value); donDatTour.TrangThai = 0; donDatTour.MaKH = Convert.ToInt32(Session["maKH"].ToString()); float phantram = (float)Convert.ToDouble(phanTramDat.SelectedValue); float tien_1 = Convert.ToInt32(tien_tt.Value) * phantram; int tien_ = Convert.ToInt32(tien_1); Debug.WriteLine(Convert.ToInt32(tien_tt.Value) + " tien " + tien_1 + " ma thoi gian : " + maTG.Value); int maThanhToan = datTourController.themDonDatTour(donDatTour, tien_); if (maThanhToan != 0) { //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); vnpay.AddRequestData("vnp_Locale", "vn"); vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_TxnRef", maThanhToan.ToString()); vnpay.AddRequestData("vnp_OrderInfo", "ghi chu"); vnpay.AddRequestData("vnp_OrderType", "other"); //default value: other vnpay.AddRequestData("vnp_Amount", (tien_ * 100).ToString()); vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_CreateDate", DateTime.Now.ToString("yyyyMMddHHmmss")); if (bank.SelectedItem != null && !string.IsNullOrEmpty(bank.SelectedItem.Value)) { vnpay.AddRequestData("vnp_BankCode", bank.SelectedItem.Value); Debug.WriteLine("bank " + bank.SelectedItem.Value); } string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); // log.InfoFormat("VNPAY URL: {0}", paymentUrl); Debug.WriteLine(paymentUrl); Response.Redirect(paymentUrl); Debug.WriteLine("Dat TOur thanh Cong."); } else { Debug.WriteLine("Dat Tour THat Bai"); } } } else { Response.Redirect("loi.aspx?id=0"); } } else { Response.Redirect("loi.aspx?id=1"); } }
public ActionResult VnPay(string amount, string description, List <int> listCourseId) { //Get Config Info string vnp_Returnurl = "https://localhost:44374/Home/Cart"; //URL nhan ket qua tra ve string vnp_Url = "http://sandbox.vnpayment.vn/paymentv2/vpcpay.html"; //URL thanh toan cua VNPAY string vnp_TmnCode = "P1V8JH37"; //Ma website string vnp_HashSecret = "XAUJIMFNKYUUWWNWOLLNIHJCUGLOIGEF"; //Chuoi bi mat //Get payment input OrderInfo order = new OrderInfo(); //Save order to db order.OrderId = "DH" + DateTime.Now.Ticks.ToString(); TempData["OrderId"] = order.OrderId; var orderDetails = new List <OrderDetail>(); foreach (var item in listCourseId) { var course = db.Courses.Find(item); if (course == null) { break; } var orderDetail = new OrderDetail(); orderDetail.CourseId = item; orderDetail.OrderId = order.OrderId; orderDetail.Price = course.Price; orderDetails.Add(orderDetail); } order.orderType = (int)OrderInfo.OrderType.BuyCourse; order.OrderDetails = orderDetails; order.Status = Convert.ToInt16(OrderInfo.OrderStatus.Pending); order.MemberId = User.Identity.GetUserId(); order.PaymentTypeId = Convert.ToInt16(OrderInfo.PaymentType.DirectTransfer); order.Amount = Convert.ToDecimal(amount); if (description == null) { description = "NA"; } order.OrderDescription = description; order.CreatedAt = DateTime.Now.ToString(); db.OrderInfos.Add(order); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); throw; } //Build URL for VNPAY VnPayLibrary vnpay = new VnPayLibrary(); vnpay.AddRequestData("vnp_Version", "2.0.0"); vnpay.AddRequestData("vnp_Command", "pay"); vnpay.AddRequestData("vnp_TmnCode", vnp_TmnCode); vnpay.AddRequestData("vnp_Amount", (order.Amount * 100).ToString()); vnpay.AddRequestData("vnp_BankCode", "NCB"); vnpay.AddRequestData("vnp_CreateDate", DateTime.Now.ToString("yyyyMMddHHmmss")); vnpay.AddRequestData("vnp_CurrCode", "VND"); vnpay.AddRequestData("vnp_IpAddr", Utils.GetIpAddress()); vnpay.AddRequestData("vnp_Locale", "vn"); vnpay.AddRequestData("vnp_OrderInfo", order.OrderDescription); vnpay.AddRequestData("vnp_OrderType", "190002"); //default value: other vnpay.AddRequestData("vnp_ReturnUrl", vnp_Returnurl); vnpay.AddRequestData("vnp_TxnRef", order.OrderId.ToString()); string paymentUrl = vnpay.CreateRequestUrl(vnp_Url, vnp_HashSecret); log.InfoFormat("VNPAY URL: {0}", paymentUrl); //Response.Redirect(paymentUrl); Debug.WriteLine(paymentUrl); Console.WriteLine(paymentUrl); return(Redirect(paymentUrl)); }