Exemple #1
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.";
            }
        }
Exemple #2
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());
        }
        //[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));
        }
        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.";
            }
        }