Пример #1
0
        protected void SubmitPayment(object sender, EventArgs e)
        {
            clearShoppingCart();

            //Assign the values for the properties we need to pass to the service
            String AppId          = ConfigurationManager.AppSettings["CreditAppId"];
            String SharedKey      = ConfigurationManager.AppSettings["CreditAppSharedKey"];
            String AppTransId     = "20";
            String AppTransAmount = Session["PurchaseTotal"].ToString();

            // Hash the values so the server can verify the values are original
            String hash = HttpUtility.UrlEncode(CreditAuthorizationClient.GenerateClientRequestHash(SharedKey, AppId, AppTransId, AppTransAmount));

            //Create the URL and  concatenate  the Query String values
            String url = "http://ectweb2.cs.depaul.edu/ECTCreditGateway/Authorize.aspx";

            url = url + "?AppId=" + AppId;
            url = url + "&TransId=" + AppTransId;
            url = url + "&AppTransAmount=" + AppTransAmount;
            url = url + "&AppHash=" + hash;

            //Redirect the User to the Service
            Response.Redirect(url);

            // Response.Redirect("OrderHistory.aspx");
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String AppId      = System.Configuration.ConfigurationManager.AppSettings["CreditAppId"];
            String SharedKey  = System.Configuration.ConfigurationManager.AppSettings["CreditAppSharedKey"];
            String AppTransId = Request.QueryString["TransId"].ToString();

            //To be safe, you shoudl check the value from the DB.
            String AppTransAmount = getPrice().ToString();

            String status = Request.QueryString["StatusCode"].ToString();
            String hash   = Request.QueryString["AppHash"].ToString();

            if (CreditAuthorizationClient.VerifyServerResponseHash(hash, SharedKey, AppId, AppTransId, AppTransAmount, status))
            {
                switch (status)
                {
                case ("A"): lblStatus.Text = "Transaction Approved!"; break;

                case ("C"):
                    lblStatus.Text = "Transaction Denied!"; break;
                    ;
                }
            }
            else
            {
                lblStatus.Text = "Hash Verification failed... something went wrong.";
            }
        }
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                AppUser user = UserManager.FindByEmail(model.Email);
                if (user != null)
                {
                    ModelState.AddModelError("", "User with this email address has already existed! Please try another email address!");
                    return(View(model));
                }
                user = UserManager.FindByName(model.UserName);
                if (user != null)
                {
                    ModelState.AddModelError("", "The User Name you specified is already existing! Please try with another user name!");
                    return(View(model));
                }
                Session["Register"] = model;
                //Assign the values for the properties we need to pass to the service
                String AppId          = ConfigurationHelper.GetAppId();
                String SharedKey      = ConfigurationHelper.GetSharedKey();
                String AppTransId     = "20";
                String AppTransAmount = "";
                if (model.Membership.Equals("Regular"))
                {
                    AppTransAmount = "49.99";
                }
                else
                {
                    AppTransAmount = "99.99";
                }

                // Hash the values so the server can verify the values are original
                String hash = HttpUtility.UrlEncode(CreditAuthorizationClient.GenerateClientRequestHash(SharedKey, AppId, AppTransId, AppTransAmount));

                //Create the URL and  concatenate  the Query String values
                String url = "http://ectweb2.cs.depaul.edu/ECTCreditGateway/Authorize.aspx";
                url = url + "?AppId=" + AppId;
                url = url + "&TransId=" + AppTransId;
                url = url + "&AppTransAmount=" + AppTransAmount;
                url = url + "&AppHash=" + hash;

                return(Redirect(url));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #4
0
        public void RedirectUser()
        {
            if (Session["ID"] != null)
            {
                int    id = Convert.ToInt32(Session["ID"]);
                int    orderId;
                double price;

                using (AABZContext context = new AABZContext())
                {
                    //This ensures that order is the most recent order the user has made.
                    Order order = (from o in context.Orders
                                   where o.user_id == id
                                   orderby o.Id descending
                                   select o).FirstOrDefault();
                    orderId = order.Id;
                    int        userId = Convert.ToInt32(Session["ID"].ToString());
                    Model.Cart cart   = (from c in context.Carts
                                         where c.user_id == userId
                                         select c).FirstOrDefault();
                    context.ProductsCarts.RemoveRange(context.ProductsCarts.Where(x => x.cart_id == cart.user_id));
                    context.SaveChanges();
                    price = getTotalOrderCost(order);
                }

                //Assign the values for the properties we need to pass to the service
                String AppId          = System.Configuration.ConfigurationManager.AppSettings["CreditAppId"];
                String SharedKey      = System.Configuration.ConfigurationManager.AppSettings["CreditAppSharedKey"];
                String AppTransId     = orderId.ToString();
                String AppTransAmount = price.ToString();

                // Hash the values so the server can verify the values are original
                String hash = HttpUtility.UrlEncode(CreditAuthorizationClient.GenerateClientRequestHash(SharedKey, AppId, AppTransId, AppTransAmount));

                //Create the URL and  concatenate  the Query String values
                String url = "http://ectweb2.cs.depaul.edu/ECTCreditGateway/Authorize.aspx";
                url = url + "?AppId=" + AppId;
                url = url + "&TransId=" + AppTransId;
                url = url + "&AppTransAmount=" + AppTransAmount;
                url = url + "&AppHash=" + hash;

                //Redirect the User to the Service
                //Response.Redirect(url);
                Response.Redirect("~/OrderHistory.aspx");
            }
        }
Пример #5
0
        public ActionResult InitiateCreditTransaction(double transAmount, int orderId)
        {
            //Assign the values for the properties we need to pass to the service
            String AppId          = ConfigurationManager.AppSettings["CreditAppId"];
            String SharedKey      = ConfigurationManager.AppSettings["CreditAppSharedKey"];
            String AppTransId     = orderId.ToString();     // "20";
            String AppTransAmount = transAmount.ToString(); //"12.50";

            // Hash the values so the server can verify the values are original
            String hash = HttpUtility.UrlEncode(CreditAuthorizationClient.GenerateClientRequestHash(SharedKey, AppId, AppTransId, AppTransAmount));

            //Create the URL and  concatenate  the Query String values
            String url = "http://ectweb2.cs.depaul.edu/ECTCreditGateway/Authorize.aspx";

            url = url + "?AppId=" + AppId;
            url = url + "&TransId=" + AppTransId;
            url = url + "&AppTransAmount=" + AppTransAmount;
            url = url + "&AppHash=" + hash;

            return(Redirect(url));
        }
Пример #6
0
        public ActionResult ProcessCreditResponse(String TransId, String TransAmount, String StatusCode, String AppHash)
        {
            String AppId     = ConfigurationManager.AppSettings["CreditAppId"];
            String SharedKey = ConfigurationManager.AppSettings["CreditAppSharedKey"];

            if (CreditAuthorizationClient.VerifyServerResponseHash(AppHash, SharedKey, AppId, TransId, TransAmount, StatusCode))
            {
                switch (StatusCode)
                {
                case ("A"): ViewBag.TransactionStatus = "Transaction Approved!"; break;

                case ("D"): ViewBag.TransactionStatus = "Transaction Denied!"; break;

                case ("C"): ViewBag.TransactionStatus = "Transaction Cancelled!"; break;
                }
            }
            else
            {
                ViewBag.TransactionStatus = "Hash Verification failed... something went wrong.";
            }

            return(View());
        }
        public ActionResult PlaceOrder(CheckoutViewModel value)
        {
            ShoppingCart cart = (ShoppingCart)Session["ShoppingCart"];

            if (cart == null)
            {
                ViewBag.Message = "Your cart is empty!";
                return(View("Index", "ShoppingCart"));
            }

            if (!ModelState.IsValid)
            {
                ViewBag.Message = "Please provide valid shipping address!";
                return(View("Checkout", "ShoppingCart"));
            }

            Session["Checkout"] = value;

            //Assign the values for the properties we need to pass to the service
            String AppId          = ConfigurationHelper.GetAppId2();
            String SharedKey      = ConfigurationHelper.GetSharedKey2();
            String AppTransId     = "20";
            String AppTransAmount = cart.GetTotalValue().ToString();

            // Hash the values so the server can verify the values are original
            String hash = HttpUtility.UrlEncode(CreditAuthorizationClient.GenerateClientRequestHash(SharedKey, AppId, AppTransId, AppTransAmount));

            //Create the URL and  concatenate  the Query String values
            String url = "http://ectweb2.cs.depaul.edu/ECTCreditGateway/Authorize.aspx";

            url = url + "?AppId=" + AppId;
            url = url + "&TransId=" + AppTransId;
            url = url + "&AppTransAmount=" + AppTransAmount;
            url = url + "&AppHash=" + hash;

            return(Redirect(url));
        }
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> ProcessCreditResponse(String TransId, String TransAmount, String StatusCode, String AppHash)
        {
            String AppId     = ConfigurationHelper.GetAppId();
            String SharedKey = ConfigurationHelper.GetSharedKey();

            if (CreditAuthorizationClient.VerifyServerResponseHash(AppHash, SharedKey, AppId, TransId, TransAmount, StatusCode))
            {
                switch (StatusCode)
                {
                case ("A"): ViewBag.TransactionStatus = "Transaction Approved!"; break;

                case ("D"): ViewBag.TransactionStatus = "Transaction Denied!"; break;

                case ("C"): ViewBag.TransactionStatus = "Transaction Cancelled!"; break;
                }
            }
            else
            {
                ViewBag.TransactionStatus = "Hash Verification failed... something went wrong.";
            }


            if (StatusCode.Equals("A"))
            {
                RegisterViewModel model = (RegisterViewModel)Session["Register"];
                if (model != null)
                {
                    var user = new AppUser {
                        Email = model.Email, UserName = model.UserName, Membership = model.Membership
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        var newUser  = UserManager.FindByEmail(model.Email);
                        var identity = await UserManager.CreateIdentityAsync(newUser, DefaultAuthenticationTypes.ApplicationCookie);

                        AuthenticationManager.SignIn(new AuthenticationProperties()
                        {
                            IsPersistent = false
                        }, identity);

                        System.Web.HttpContext.Current.Cache.Remove("UserList");
                        Session["Register"] = null;
                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View());
        }
        public ActionResult ProcessCreditResponse(String TransId, String TransAmount, String StatusCode, String AppHash)
        {
            String AppId     = ConfigurationHelper.GetAppId2();
            String SharedKey = ConfigurationHelper.GetSharedKey2();

            if (CreditAuthorizationClient.VerifyServerResponseHash(AppHash, SharedKey, AppId, TransId, TransAmount, StatusCode))
            {
                switch (StatusCode)
                {
                case ("A"): ViewBag.TransactionStatus = "Transaction Approved! Your order has been created!"; break;

                case ("D"): ViewBag.TransactionStatus = "Transaction Denied!"; break;

                case ("C"): ViewBag.TransactionStatus = "Transaction Cancelled!"; break;
                }
            }
            else
            {
                ViewBag.TransactionStatus = "Hash Verification failed... something went wrong.";
            }

            OrderViewModel model = new OrderViewModel();

            if (StatusCode.Equals("A"))
            {
                ShoppingCart      cart  = (ShoppingCart)Session["ShoppingCart"];
                CheckoutViewModel value = (CheckoutViewModel)Session["Checkout"];
                if (value != null)
                {
                    try
                    {
                        using (GameStoreDBContext context = new GameStoreDBContext())
                        {
                            Order newOrder = context.Orders.Create();
                            newOrder.FullName           = value.FullName;
                            newOrder.Address            = value.Address;
                            newOrder.City               = value.City;
                            newOrder.State              = value.State;
                            newOrder.Zip                = value.Zip;
                            newOrder.DeliveryDate       = DateTime.Now.AddDays(14);
                            newOrder.ConfirmationNumber = DateTime.Now.ToString("yyyyMMddHHmmss");
                            newOrder.UserId             = User.Identity.GetUserId();
                            context.Orders.Add(newOrder);
                            cart.GetItems().ForEach(c => context.OrderItems.Add(new OrderItem {
                                OrderId = newOrder.OrderId, ProductId = c.GetItemId(), Quantity = c.Quantity
                            }));
                            context.SaveChanges();
                            System.Web.HttpContext.Current.Cache.Remove("OrderList");
                            Session["ShoppingCart"] = null;
                            Session["CartCount"]    = 0;
                            Session["OrderCount"]   = (int)Session["OrderCount"] + 1;

                            var order = from o in context.Orders
                                        join u in context.Users
                                        on o.UserId equals u.Id
                                        where o.OrderId == newOrder.OrderId
                                        select new { o.OrderId, o.UserId, u.UserName, o.FullName, o.Address, o.City, o.State, o.Zip, o.ConfirmationNumber, o.DeliveryDate };
                            var ord = order.FirstOrDefault();
                            model = new OrderViewModel {
                                OrderId = ord.OrderId, UserId = ord.UserId, UserName = ord.UserName, FullName = ord.FullName, Address = ord.Address, City = ord.City, State = ord.State, Zip = ord.Zip, ConfirmationNumber = ord.ConfirmationNumber, DeliveryDate = ord.DeliveryDate
                            };

                            var orderitems = from i in context.OrderItems
                                             join p in context.Products
                                             on i.ProductId equals p.ProductId
                                             join c in context.Categories
                                             on p.CategoryId equals c.CategoryId
                                             where i.OrderId == newOrder.OrderId
                                             select new { i.OrderItemId, i.OrderId, i.ProductId, p.ProductName, p.CategoryId, c.CategoryName, p.Price, p.Image, p.Condition, p.Discount, i.Quantity };
                            model.Items = orderitems.Select(o => new OrderItemViewModel {
                                OrderItemId = o.OrderItemId, OrderId = o.OrderId, ProductId = o.ProductId, ProductName = o.ProductName, CategoryId = o.CategoryId, CategoryName = o.CategoryName, Price = o.Price, Image = o.Image, Condition = o.Condition, Discount = o.Discount, Quantity = o.Quantity
                            }).ToList();
                        }
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "Error Occurs:" + ex.Message;
                    }
                }
            }

            return(View("PlaceOrder", model));
        }
Пример #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String AppId      = ConfigurationManager.AppSettings["CreditAppId"];
            String SharedKey  = ConfigurationManager.AppSettings["CreditAppSharedKey"];
            String AppTransId = Request.QueryString["TransId"].ToString();

            //To be safe, you shoudl check the value from the DB.
            //String AppTransAmount = "12.50";
            String AppTransAmount = Session["PurchaseTotal"].ToString();

            String status = Request.QueryString["StatusCode"].ToString();
            String hash   = Request.QueryString["AppHash"].ToString();

            if (CreditAuthorizationClient.VerifyServerResponseHash(hash, SharedKey, AppId, AppTransId, AppTransAmount, status))
            {
                switch (status)
                {
                case ("A"): lblStatus.Text = "Transaction Approved!";
                    if (Session["LoggedInId"] == null)
                    {
                        Response.Redirect("Login.aspx");
                    }
                    else
                    {
                        /*
                         * int sessionName = (int)Session["LoggedInId"];
                         * //Open a Connection
                         * OleDbConnection conn = new OleDbConnection();
                         *
                         * //Assign a Connection String
                         * conn.ConnectionString = ConfigurationManager.ConnectionStrings["onlineStoreConnString"].ConnectionString;
                         *
                         * //Connection Open
                         * conn.Open();
                         *
                         * //Initialize a Command
                         * OleDbCommand comm = conn.CreateCommand();
                         * //Tell the command which connection it will use
                         * comm.Connection = conn;
                         * //Give the command SQL to execute
                         *
                         * //comm.CommandText = "Select StudentToCourse.CourseId, Courses.CourseName from Courses INNER JOIN StudentToCourse ON StudentToCourse.CourseID = Courses.ID WHERE StudentID=?";
                         *
                         *
                         * comm.CommandText = "SELECT ProductName, Price, OrderDate from Orders WHERE UserID = ? AND IsCart = False";
                         * OleDbParameter param;
                         * param = comm.CreateParameter();
                         * param.DbType = DbType.String;
                         * param.Direction = ParameterDirection.Input;
                         * param.Value = sessionName;
                         * comm.Parameters.Add(param);
                         *
                         * //Execute the command and get back the results via a reader
                         * OleDbDataReader reader = comm.ExecuteReader();
                         *
                         * //While we get results from the DB, add a row to the Table
                         * while (reader.Read())
                         * {
                         *  TableRow row = new TableRow();
                         *  TableCell cell;
                         *
                         *  cell = new TableCell();
                         *  cell.Text = reader["ProductName"].ToString();
                         *  row.Cells.Add(cell);
                         *
                         *  cell = new TableCell();
                         *  cell.Text = reader["Price"].ToString();
                         *  row.Cells.Add(cell);
                         *
                         *  cell = new TableCell();
                         *  cell.Text = reader["OrderDate"].ToString();
                         *  row.Cells.Add(cell);
                         *
                         *  OrderTransaction.Rows.Add(row);
                         * }
                         * //Free up the connection
                         * conn.Close();
                         */
                    }
                    break;

                case ("D"): lblStatus.Text = "Transaction Denied!"; break;

                case ("C"):
                    lblStatus.Text = "Transaction Cancelled!"; break;
                }
            }
            else
            {
                lblStatus.Text = "Hash Verification failed... something went wrong.";
            }
        }