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)); }
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); }