Ejemplo n.º 1
0
        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);
        }