コード例 #1
0
        public ActionResult ViewOrderDetail(int orderId)
        {
            ViewBag.Title = "Chi tiết đơn hàng";

            var orderDB = (from order in db.Orders
                           where order.Id == orderId
                           select order).FirstOrDefault();

            //found order
            var             list            = db.OrderDetails.Where(order => order.OrderId == orderId).ToList();
            OrderInfomation orderInfomation = new OrderInfomation()
            {
                OrderCode       = orderDB.OrderCode,
                OrderDate       = orderDB.OrderDate,
                CustomerName    = orderDB.Customer.Name,
                CustomerEmail   = orderDB.Customer.Email,
                CustomerPhone   = orderDB.Customer.Phone,
                CustomerAddress = orderDB.Customer.Address,
                Status          = orderDB.OrderStatus.Status,
                Total           = orderDB.Total,
                ListOrderDetail = list
            };

            if (orderDB.Delivery != null)
            {
                orderInfomation.DeliveryName    = orderDB.Delivery.Name;
                orderInfomation.DeliveryEmail   = orderDB.Delivery.Email;
                orderInfomation.DeliveryPhone   = orderDB.Delivery.Phone;
                orderInfomation.DeliveryAddress = orderDB.Delivery.Address;
                return(View(orderInfomation));
            }
            return(View(orderInfomation));
        }
コード例 #2
0
 public ActionResult Order(OrderInfomation model)
 {
     if (ModelState.IsValid)
     {
         if (OrderHelper.Ordered(HttpContext.User.Identity.Name, HttpContext.Session["ShoppingCart"] as ShoppingCart, model))
         {
             HttpContext.Session["ShoppingCart"] = new ShoppingCart();
             return(Content("success"));
         }
         ModelState.AddModelError("", "Có lỗi xảy ra, vui lòng thử lại sau");
     }
     return(PartialView("FormInfo", model));
 }
コード例 #3
0
        public ActionResult CheckOrderWithoutLogin(string orderCode)
        {
            ViewBag.Title = "Kiểm tra đơn hàng";

            var orderDB = (from order in db.Orders
                           where order.OrderCode.Equals(orderCode)
                           select order).FirstOrDefault();

            if (orderDB != null)
            {
                //found order
                ViewBag.OrderCode = orderCode;
                var             list            = db.OrderDetails.Where(order => order.Order.OrderCode.Equals(orderCode)).ToList();
                OrderInfomation orderInfomation = new OrderInfomation()
                {
                    OrderCode       = orderCode,
                    OrderDate       = orderDB.OrderDate,
                    CustomerName    = orderDB.Customer.Name,
                    CustomerEmail   = orderDB.Customer.Email,
                    CustomerPhone   = orderDB.Customer.Phone,
                    CustomerAddress = orderDB.Customer.Address,
                    Status          = orderDB.OrderStatus.Status,
                    Total           = orderDB.Total,
                    ListOrderDetail = list
                };
                if (orderDB.Delivery == null)
                {
                    //no shipping
                    return(View(orderInfomation));
                }
                else
                {
                    //have shiping
                    orderInfomation.DeliveryName    = orderDB.Delivery.Name;
                    orderInfomation.DeliveryEmail   = orderDB.Delivery.Email;
                    orderInfomation.DeliveryPhone   = orderDB.Delivery.Phone;
                    orderInfomation.DeliveryAddress = orderDB.Delivery.Address;
                    return(View(orderInfomation));
                }
            }
            else
            {
                //order not found
                ViewBag.Message   = "Cannot find your order code, please try again!";
                ViewBag.OrderCode = orderCode;
                return(View());
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            X509Certificate2 customerCertificate, merchantCertificate, gatewayCertificate;
            string           customerPrivateKey, merchantPublicKey, gatewayPublicKey;
            bool             verify;
            Common           c      = new Common();
            IPEndPoint       iep    = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234);
            Socket           client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            client.Connect(iep);
            //tạo init request gửi tới merchant
            InitiateRequest initiateRequest = new InitiateRequest();

            c.send(initiateRequest.ToMessage(), client);
            //nhận init response từ merchant
            string receiveMessage = c.receive(client);

            string[] initRES = receiveMessage.Split('-');
            merchantCertificate = new X509Certificate2(c.StringToByteArray(initRES[2]));
            gatewayCertificate  = new X509Certificate2(c.StringToByteArray(initRES[3]));
            merchantPublicKey   = merchantCertificate.GetRSAPublicKey().ToXmlString(false);
            gatewayPublicKey    = gatewayCertificate.GetRSAPublicKey().ToXmlString(false);
            verify = c.Verify(merchantPublicKey, initRES[1], initRES[0]);
            Console.WriteLine("verify init response: " + verify);
            //tạo purchase request
            string[]            value            = File.ReadAllLines("d:/file/input.txt");
            string[]            initREQValue     = initRES[0].Split(':');
            InitiateResponse    initiateResponse = new InitiateResponse(initREQValue[0], initREQValue[1], initREQValue[2]);
            OrderInfomation     oi = new OrderInfomation(Convert.ToInt32(value[0]), Convert.ToInt32(value[1]), DateTime.Now.ToString("ddMMyyyy"), initiateResponse.getTransID(), initiateResponse.getBrandID(), Convert.ToDouble(value[2]));
            PaymentInstructions pi = new PaymentInstructions(value[3], value[4], value[5], Convert.ToDouble(value[2]), initiateResponse.getTransID(), initiateResponse.getBrandID());

            customerPrivateKey  = File.ReadAllText(value[6]);
            customerCertificate = new X509Certificate2(value[7], "123456");
            PurchaseRequest purchaseRequest = new PurchaseRequest(oi.OIToString(), pi.PIToString(), customerPrivateKey, gatewayPublicKey, c.ByteArrayToString(customerCertificate.GetRawCertData()));

            c.send(purchaseRequest.ToMessage(), client);
            //nhận purchase response
            receiveMessage = c.receive(client);
            string[]         splitRES         = receiveMessage.Split('-');
            PurchaseResponse purchaseResponse = new PurchaseResponse(splitRES[0], splitRES[1], splitRES[2]);

            Console.WriteLine("verify purchase response: " + purchaseResponse.verify());
            //Console.WriteLine(purchaseResponse.getMessage());
            Console.Read();
        }
コード例 #5
0
        private void button3_Click(object sender, EventArgs e)
        {
            bool       verify;
            string     s;
            Common     c      = new Common();
            IPEndPoint iep    = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234);
            Socket     client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            client.Connect(iep);

            //tạo init request gửi tới merchant
            InitiateRequest initiateRequest = new InitiateRequest();

            c.send(initiateRequest.ToMessage(), ref client);
            //nhận init response từ merchant
            string receiveMessage = c.receive(ref client);

            string[] initRES = receiveMessage.Split('-');
            merchantCertificate = new X509Certificate2(c.StringToByteArray(initRES[2]));
            gatewayCertificate  = new X509Certificate2(c.StringToByteArray(initRES[3]));
            if (c.VerifyCertificate(caCertificate, merchantCertificate) == false || c.VerifyCertificate(caCertificate, gatewayCertificate) == false)//xác thực chứng chỉ nhận được
            {
                s = "Xác thực kết nối thất bại";
                openThongBaoForm(s);
            }
            else
            {
                merchantPublicKey = merchantCertificate.GetRSAPublicKey().ToXmlString(false);
                gatewayPublicKey  = gatewayCertificate.GetRSAPublicKey().ToXmlString(false);
                verify            = c.Verify(merchantPublicKey, initRES[1], initRES[0]);
                if (verify == false)
                {
                    s = "Xác thực kết nối thất bại";
                    openThongBaoForm(s);
                }
                else
                {
                    //tạo purchase request
                    string[]            initREQValue     = initRES[0].Split(':');
                    InitiateResponse    initiateResponse = new InitiateResponse(initREQValue[0], initREQValue[1], initREQValue[2]);
                    OrderInfomation     oi = new OrderInfomation(maDH, maKH, DateTime.Now.ToString("ddMMyyyy"), initiateResponse.getTransID(), initiateResponse.getBrandID(), soTien);
                    PaymentInstructions pi = new PaymentInstructions(cardNumber, CVV, dateValid, soTien, initiateResponse.getTransID(), initiateResponse.getBrandID());
                    PurchaseRequest     purchaseRequest = new PurchaseRequest(oi.OIToString(), pi.PIToString(), customerPrivateKey, gatewayPublicKey, c.ByteArrayToString(customerCertificate.GetRawCertData()));
                    c.send(purchaseRequest.ToMessage(), ref client);
                    //nhận purchase response
                    receiveMessage = c.receive(ref client);
                    string[]         splitRES         = receiveMessage.Split('-');
                    PurchaseResponse purchaseResponse = new PurchaseResponse(splitRES[0], splitRES[1], splitRES[2]);
                    merchantCertificate = new X509Certificate2(c.StringToByteArray(purchaseResponse.getCertificate()));
                    if (c.VerifyCertificate(caCertificate, merchantCertificate) == false)//xác thực chứng chỉ từ purchase response
                    {
                        s = "Xác thực kết nối thất bại";
                        openThongBaoForm(s);
                    }
                    else
                    {
                        if (purchaseResponse.verify() == false)
                        {
                            s = "Xác thực kết nối thất bại";
                            openThongBaoForm(s);
                        }
                        else
                        {
                            string[] splitPurchase = purchaseResponse.getMessage().Split(':');//message = transid:RRPID:maKQ:KQ
                            if (splitPurchase[2].CompareTo("1") == 0)
                            {
                                KetQua form = new KetQua("Thanh toán thành công");
                                form.Show();
                                this.Hide();
                                this.Close();
                            }
                            else if (splitPurchase[2].CompareTo("2") == 0)
                            {
                                s = "Thông tin tài khoản không đúng";
                                openThongBaoForm(s);
                            }
                            else
                            {
                                s = "Xác thực kết nối thất bại";
                                openThongBaoForm(s);
                            }
                        }
                    }

                    client.Close();
                }
            }
        }
コード例 #6
0
ファイル: HomeController.cs プロジェクト: n14dcat006/SET
        public ActionResult Index(FormCollection collection)
        {
            bool verify;

            cardNumber = collection["CardNumber"];
            CVV        = collection["CVV"];
            dateValid  = collection["DateValid"];
            Common c = new Common();
            //lấy dữ liệu

            /*
             * System.IO.Stream s=PrivateKey.InputStream;
             * byte[] buffer = new byte[1024];
             * using (MemoryStream ms = new MemoryStream())
             * {
             *  int read;
             *  while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
             *  {
             *      ms.Write(buffer, 0, read);
             *  }
             *  byte[] privateKeyByte = ms.ToArray();
             *  customerPrivateKey = System.Text.Encoding.ASCII.GetString(privateKeyByte);
             * }
             * s.Flush();
             * s = Certificate.InputStream;
             * using (MemoryStream ms = new MemoryStream())
             * {
             *  int read;
             *  while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
             *  {
             *      ms.Write(buffer, 0, read);
             *  }
             *  byte[] certificateByte = ms.ToArray();
             *  customerCertificate = new X509Certificate2(certificateByte);
             * }*/
            //khởi tạo kết nối đến customer
            IPEndPoint iep    = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234);
            Socket     client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            client.Connect(iep);
            //tạo init request gửi tới merchant
            InitiateRequest initiateRequest = new InitiateRequest();

            c.send(initiateRequest.ToMessage(), ref client);
            //nhận init response từ merchant
            string receiveMessage = c.receive(ref client);

            string[] initRES = receiveMessage.Split('-');
            merchantCertificate = new X509Certificate2(c.StringToByteArray(initRES[2]));
            gatewayCertificate  = new X509Certificate2(c.StringToByteArray(initRES[3]));
            if (c.VerifyCertificate(caCertificate, merchantCertificate) == false || c.VerifyCertificate(caCertificate, gatewayCertificate) == false)//xác thực chứng chỉ nhận được
            {
                ViewBag.thongbao = "Xác thực kết nối thất bại";
                ViewBag.TaiKhoan = tenKH;
                ViewBag.SoLuong  = soLuong;
                ViewBag.SoTien   = soTien;
                return(this.View());
            }
            else
            {
                merchantPublicKey = merchantCertificate.GetRSAPublicKey().ToXmlString(false);
                gatewayPublicKey  = gatewayCertificate.GetRSAPublicKey().ToXmlString(false);
                verify            = c.Verify(merchantPublicKey, initRES[1], initRES[0]);
                if (verify == false)
                {
                    ViewBag.thongbao = "Xác thực kết nối thất bại";
                    ViewBag.TaiKhoan = tenKH;
                    ViewBag.SoLuong  = soLuong;
                    ViewBag.SoTien   = soTien;
                    return(this.View());
                }
                else
                {
                    //tạo purchase request
                    string[]            initREQValue     = initRES[0].Split(':');
                    InitiateResponse    initiateResponse = new InitiateResponse(initREQValue[0], initREQValue[1], initREQValue[2]);
                    OrderInfomation     oi = new OrderInfomation(maDH, maKH, DateTime.Now.ToString("ddMMyyyy"), initiateResponse.getTransID(), initiateResponse.getBrandID(), soTien);
                    PaymentInstructions pi = new PaymentInstructions(cardNumber, CVV, dateValid, soTien, initiateResponse.getTransID(), initiateResponse.getBrandID());
                    PurchaseRequest     purchaseRequest = new PurchaseRequest(oi.OIToString(), pi.PIToString(), customerPrivateKey, gatewayPublicKey, c.ByteArrayToString(customerCertificate.GetRawCertData()));
                    c.send(purchaseRequest.ToMessage(), ref client);
                    //nhận purchase response
                    receiveMessage = c.receive(ref client);
                    string[]         splitRES         = receiveMessage.Split('-');
                    PurchaseResponse purchaseResponse = new PurchaseResponse(splitRES[0], splitRES[1], splitRES[2]);
                    merchantCertificate = new X509Certificate2(c.StringToByteArray(purchaseResponse.getCertificate()));
                    if (c.VerifyCertificate(caCertificate, merchantCertificate) == false)//xác thực chứng chỉ từ purchase response
                    {
                        ViewBag.thongbao = "Xác thực kết nối thất bại";
                        ViewBag.TaiKhoan = tenKH;
                        ViewBag.SoLuong  = soLuong;
                        ViewBag.SoTien   = soTien;
                        return(this.View());
                    }
                    else
                    {
                        if (purchaseResponse.verify() == false)
                        {
                            ViewBag.thongbao = "Xác thực kết nối thất bại";
                            ViewBag.TaiKhoan = tenKH;
                            ViewBag.SoLuong  = soLuong;
                            ViewBag.SoTien   = soTien;
                            return(this.View());
                        }
                        else
                        {
                            string[] splitPurchase = purchaseResponse.getMessage().Split(':');//message = transid:RRPID:maKQ:KQ
                            if (splitPurchase[2].CompareTo("1") == 0)
                            {
                                return(RedirectToAction("KetQua", new { kq = "Thanh toán thành công" }));
                            }
                            else if (splitPurchase[2].CompareTo("2") == 0)
                            {
                                ViewBag.thongbao = "Thông tin tài khoản không đúng";
                                ViewBag.TaiKhoan = tenKH;
                                ViewBag.SoLuong  = soLuong;
                                ViewBag.SoTien   = soTien;
                                return(this.View());
                            }
                            else if (splitPurchase[2].CompareTo("3") == 0)
                            {
                                ViewBag.thongbao = "Số tiền thanh toán vượt quá hạn mức của thẻ";
                                ViewBag.TaiKhoan = tenKH;
                                ViewBag.SoLuong  = soLuong;
                                ViewBag.SoTien   = soTien;
                                return(this.View());
                            }
                            else
                            {
                                ViewBag.thongbao = "Xác thực kết nối thất bại";
                                ViewBag.TaiKhoan = tenKH;
                                ViewBag.SoLuong  = soLuong;
                                ViewBag.SoTien   = soTien;
                                return(this.View());
                            }
                        }
                    }
                }
            }
        }