public ActionResult XacThucDatVe() { if (Session["maXacThuc"] == null) { return(RedirectToAction("VeXeThanhToan", "VeXeKhach")); } var model = new ThanhToanVeXeModel(); return(View(model)); }
public ActionResult XacThucDatVe(ThanhToanVeXeModel model) { if (Session["maXacThuc"] == null) { return(RedirectToAction("VeXeThanhToan", "VeXeKhach")); } var customer = _workContext.CurrentCustomer; var countries = new List <Nop.Core.Domain.Directory.Country>(); countries.Add(_countryService.GetCountryById(NhaXesController.CountryID)); var diachigiaohang = _workContext.CurrentCustomer.ShippingAddress; if (_workContext.CurrentCustomer.Addresses.Count > 0) { diachigiaohang = _workContext.CurrentCustomer.Addresses.First(); } model.diachigiaohang.PrepareModel( address: diachigiaohang, excludeProperties: false, addressSettings: _addressSettings, localizationService: _localizationService, stateProvinceService: _stateProvinceService, diachiService: _diachiService, addressAttributeFormatter: _addressAttributeFormatter, loadCountries: () => countries); if (diachigiaohang == null) { model.diachigiaohang.FirstName = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.FirstName); model.diachigiaohang.LastName = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.LastName); model.diachigiaohang.FullName = string.Format("{0} {1}", model.diachigiaohang.FirstName, model.diachigiaohang.LastName); model.diachigiaohang.Email = _workContext.CurrentCustomer.Email; model.diachigiaohang.PhoneNumber = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.Phone); } model.phoiveinfos = _phoiveService.GetPhoiVeGiuChoBySession(Session["DAT_MUA_VE_XE_ID"]); int OrderId = 0; Address address = null; if (model.diachigiaohang.Id > 0) { address = _addressService.GetAddressById(model.diachigiaohang.Id); } address = model.diachigiaohang.ToEntity(address); address.CreatedOnUtc = DateTime.UtcNow; //some validation if (address.CountryId == 0) { address.CountryId = null; } if (address.StateProvinceId == 0) { address.StateProvinceId = null; } if (address.QuanHuyenId == 0) { address.QuanHuyenId = null; } if (model.MaXacThuc != null && model.MaXacThuc.Equals(Session["maXacThuc"].ToString())) { vn.worldsms.wcf.APISMS apisms = new vn.worldsms.wcf.APISMS(); var phoive = _phoiveService.GetPhoiVeById(model.phoiveinfos[0].Id); var Sender = "CHONVE.VN"; var Msg = "Chúc mừng " + model.diachigiaohang.FullName + " đã thanh toán thành công, mã vé của bạn là: " + phoive.MaVe; var Phone = address.PhoneNumber; var Username = "******"; var Password = "******"; string result = apisms.PushMsg2Phone(Sender, Msg, Phone, Username, Password); _phoiveService.ThanhToan(Session["DAT_MUA_VE_XE_ID"].ToString(), _workContext.CurrentCustomer.Id, address, out OrderId); SuccessNotification("Bạn đã thanh toán thành công"); return(RedirectToAction("ThanhToanThanhCong", "VeXeKhach")); } int solannhap = 0; if (Session["SoLanXacThuc"] != null) { solannhap = Convert.ToInt32(Session["SoLanXacThuc"]); } solannhap++; if (solannhap >= 3) { return(RedirectToAction("VeXeThanhToan", "VeXeKhach")); } Session["SoLanXacThuc"] = solannhap; return(View(model)); }
/// <summary> /// Thanh toan cac ve xe da chon, dua vao sesssion id de lay thong tin ve da chon mua /// </summary> /// <returns></returns> public ActionResult VeXeThanhToan() { if (Session["DAT_MUA_VE_XE_ID"] == null) { return(RedirectToRoute("HomePage")); } //kiem tra dang nhap hay chua if (!_workContext.CurrentCustomer.IsRegistered()) { return(new HttpUnauthorizedResult()); } //lay thong tin nguon ve xe, tu session id var model = new ThanhToanVeXeModel(); model.MaXacThuc = "0"; //thiet dat thong tin noi nhan var countries = new List <Nop.Core.Domain.Directory.Country>(); countries.Add(_countryService.GetCountryById(NhaXesController.CountryID)); var diachigiaohang = _workContext.CurrentCustomer.ShippingAddress; if (_workContext.CurrentCustomer.Addresses.Count > 0) { diachigiaohang = _workContext.CurrentCustomer.Addresses.First(); } model.diachigiaohang.PrepareModel( address: diachigiaohang, excludeProperties: false, addressSettings: _addressSettings, localizationService: _localizationService, stateProvinceService: _stateProvinceService, diachiService: _diachiService, addressAttributeFormatter: _addressAttributeFormatter, loadCountries: () => countries); if (diachigiaohang == null) { model.diachigiaohang.FirstName = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.FirstName); model.diachigiaohang.LastName = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.LastName); model.diachigiaohang.FullName = string.Format("{0} {1}", model.diachigiaohang.FirstName, model.diachigiaohang.LastName); model.diachigiaohang.Email = _workContext.CurrentCustomer.Email; model.diachigiaohang.PhoneNumber = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.Phone); } //lay thong tin ve xe model.phoiveinfos = _phoiveService.GetPhoiVeGiuChoBySession(Session["DAT_MUA_VE_XE_ID"]); //cho thanh toan qua lau, nen het han giu cho ve if (model.phoiveinfos.Count == 0) { return(RedirectToRoute("HomePage")); } model.nguonvexeinfo = _vexeService.GetNguonVeXeById(model.phoiveinfos[0].NguonVeXeId.GetValueOrDefault(0)); model.nhaxeinfo = _nhaxeService.GetNhaXeById(model.nguonvexeinfo.NhaXeId); model.NgayDi = model.phoiveinfos[0].NgayDi; model.NgayDi = model.NgayDi.AddHours(model.nguonvexeinfo.ThoiGianDi.Hour).AddMinutes(model.nguonvexeinfo.ThoiGianDi.Minute); model.NgayVe = model.NgayDi.AddHours(Convert.ToDouble(model.nguonvexeinfo.LichTrinhInfo.SoGioChay)); model.TongTien = decimal.Zero; model.KyHieuGhe = ""; foreach (var pv in model.phoiveinfos) { if (string.IsNullOrEmpty(model.KyHieuGhe)) { model.KyHieuGhe = pv.sodoghexequytac.Val; } else { model.KyHieuGhe += "," + pv.sodoghexequytac.Val; } model.TongTien += pv.GiaVeHienTai; } return(View(model)); }
public ActionResult VeXeThanhToan(ThanhToanVeXeModel model, FormCollection form) { if (Session["DAT_MUA_VE_XE_ID"] == null) { return(Loi()); } var customer = _workContext.CurrentCustomer; Address address = null; if (model.diachigiaohang.Id > 0) { address = _addressService.GetAddressById(model.diachigiaohang.Id); } address = model.diachigiaohang.ToEntity(address); address.CreatedOnUtc = DateTime.UtcNow; //some validation if (address.CountryId == 0) { address.CountryId = null; } if (address.StateProvinceId == 0) { address.StateProvinceId = null; } if (address.QuanHuyenId == 0) { address.QuanHuyenId = null; } if (address.Id > 0) { _addressService.UpdateAddress(address); } else { customer.Addresses.Add(address); _customerService.UpdateCustomer(customer); } int OrderId = 0; if (model.HinhThucThanhToan == "CHONVE") { // Đơn hàng do chonve.vn xử lý // chờ xác nhận điện thoại // return vn.worldsms.wcf.APISMS apisms = new vn.worldsms.wcf.APISMS(); var Sender = "CHONVE.VN"; Random rdn = new Random(); Session["maXacThuc"] = rdn.Next(1000, 9999); var Msg = "Ma xac thuc cua ban la: " + Session["maXacThuc"]; var Phone = model.diachigiaohang.PhoneNumber; var Username = "******"; var Password = "******"; string result = apisms.PushMsg2Phone(Sender, Msg, Phone, Username, Password); int kq = Convert.ToInt32(result); if (kq == 1) { return(RedirectToAction("XacThucDatVe", "VeXeKhach")); } else { return(RedirectToAction("VeXeThanhToan", "VeXeKhach")); } } else { _phoiveService.ThanhToan(Session["DAT_MUA_VE_XE_ID"].ToString(), _workContext.CurrentCustomer.Id, address, out OrderId); //gửi đơn hàng cho ngân lượng.vn RequestInfo info = new RequestInfo(); info.Merchant_id = CommonHelper.Merchant_Id; info.Merchant_password = CommonHelper.Merchant_Password; info.Receiver_email = "*****@*****.**"; info.cur_code = "vnd"; info.bank_code = model.BankCode; info.Payment_method = model.HinhThucThanhToan; info.Order_code = OrderId.ToString(); info.Total_amount = model.TongTien.ToString(); info.time_limit = CommonHelper.Time_Limit; info.return_url = CommonHelper.Return_Url; info.cancel_url = CommonHelper.Cancel_Url; info.Buyer_fullname = model.diachigiaohang.FullName; info.Buyer_email = model.diachigiaohang.Email; info.Buyer_mobile = model.diachigiaohang.PhoneNumber; APICheckoutV3 objNLChecout = new APICheckoutV3(); ResponseInfo result = objNLChecout.GetUrlCheckout(info, model.HinhThucThanhToan); if (result.Error_code == "00") { Response.Redirect(result.Checkout_url); } else { model.ErrorSentOrder = objNLChecout.GetErrorMessage(result.Error_code); return(View(model)); } } return(null); }
public ActionResult ThanhToanThanhCong() { int orderId = 0; var model = new ThanhToanVeXeModel(); var _token = Request["token"]; if (!string.IsNullOrWhiteSpace(_token)) { RequestCheckOrder info = new RequestCheckOrder(); info.Merchant_id = CommonHelper.Merchant_Id; info.Merchant_password = CommonHelper.Merchant_Password; info.Token = _token; APICheckoutV3 objNLChecout = new APICheckoutV3(); ResponseCheckOrder result = objNLChecout.GetTransactionDetail(info); if (result.errorCode == "00") { orderId = Convert.ToInt32(result.order_code); model.HinhThucThanhToan = result.paymentMethod; if (result.paymentMethod != "CHONVE") { var _order = _orderService.GetOrderById(orderId); if (result.transactionStatus == "00") { _order.PaymentStatusId = (int)PaymentStatus.Paid; } else { _order.PaymentStatusId = (int)PaymentStatus.Authorized; } _orderService.UpdateOrder(_order); var phoives = _phoiveService.GetPhoiVeByOrderId(orderId); foreach (var item in phoives) { item.TrangThaiId = (int)ENTrangThaiPhoiVe.DaThanhToan; _phoiveService.UpdatePhoiVe(item); } } else { //update trang thai phoi vé về chưa thanh toán } } } //thiet dat thong tin noi nhan var countries = new List <Nop.Core.Domain.Directory.Country>(); countries.Add(_countryService.GetCountryById(NhaXesController.CountryID)); var diachigiaohang = _workContext.CurrentCustomer.ShippingAddress; if (_workContext.CurrentCustomer.Addresses.Count > 0) { diachigiaohang = _workContext.CurrentCustomer.Addresses.First(); } model.diachigiaohang.PrepareModel( address: diachigiaohang, excludeProperties: false, addressSettings: _addressSettings, localizationService: _localizationService, stateProvinceService: _stateProvinceService, diachiService: _diachiService, addressAttributeFormatter: _addressAttributeFormatter, loadCountries: () => countries); //lay thong tin ve xe var phoive = _phoiveService.GetPhoiVeByCustomer(_workContext.CurrentCustomer.Id); for (int i = 0; i < phoive.Count(); i++) { orderId = phoive[i].OrderId; } model.phoiveinfos = _phoiveService.GetPhoiVeByOrderId(orderId); //cho thanh toan qua lau, nen het han giu cho ve if (model.phoiveinfos.Count == 0) { return(RedirectToRoute("HomePage")); } model.nguonvexeinfo = _vexeService.GetNguonVeXeById(model.phoiveinfos[0].NguonVeXeId.GetValueOrDefault(0)); model.nhaxeinfo = _nhaxeService.GetNhaXeById(model.nguonvexeinfo.NhaXeId); model.NgayDi = model.phoiveinfos[0].NgayDi; model.NgayDi = model.NgayDi.AddHours(model.nguonvexeinfo.ThoiGianDi.Hour).AddMinutes(model.nguonvexeinfo.ThoiGianDi.Minute); model.NgayVe = model.NgayDi.AddHours(Convert.ToDouble(model.nguonvexeinfo.LichTrinhInfo.SoGioChay)); model.TongTien = decimal.Zero; model.KyHieuGhe = ""; foreach (var pv in model.phoiveinfos) { if (string.IsNullOrEmpty(model.KyHieuGhe)) { model.KyHieuGhe = pv.sodoghexequytac.Val; } else { model.KyHieuGhe += "," + pv.sodoghexequytac.Val; } model.TongTien += pv.GiaVeHienTai; } ViewBag.OrderId = orderId; return(View(model)); }