public ActionResult ConfirmFromStripe()
        {
            try
            {
                var stateId = HttpContext.Request.Params["state"];
                if (String.IsNullOrEmpty(stateId))
                    return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.na));

                string returnType = stateId.Split('-')[0];
                string privId = stateId.Split('-')[1];

                StripeStateReturnCodeEnum typeOfReturn = (StripeStateReturnCodeEnum)Enum.Parse(typeof(StripeStateReturnCodeEnum), returnType);

                var errorCode = HttpContext.Request.Params["error"];
                if (!String.IsNullOrEmpty(errorCode))
                {
                    if (errorCode == StripeConnectCodes.access_denied.ToString())
                    {
                        var sg = new MerchantGateway();
                        var store = sg.GetMerchant(new Guid(privId));

                        if (store != null && typeOfReturn == StripeStateReturnCodeEnum.store)
                            return Redirect(Url.Content("~/store/settings/" + privId + "/" + store.MerchantId.ToString().Replace("-", "") + "?u=" + SiteMessagesEnum.sced));
                        else if (store != null && typeOfReturn == StripeStateReturnCodeEnum.merchant)
                            return Redirect(Url.Content("~/merchant/settings?u=" + SiteMessagesEnum.sced));

                    }
                }
                var stripeCode = HttpContext.Request.Params["code"];
                if (!String.IsNullOrEmpty(stripeCode))
                {
                    var sg = new StoreGateway();
                    sg.UpdateStripeKey(stripeCode, new Guid(privId));
                    var mg = new MerchantGateway();
                    var store = mg.GetMerchant(new Guid(privId));

                    if (store != null && typeOfReturn == StripeStateReturnCodeEnum.store)
                        return Redirect(Url.Content("~/store/settings/" + privId + "/" + store.MerchantId.ToString().Replace("-", "") + "?u=" + SiteMessagesEnum.sca));
                    else if (store != null && typeOfReturn == StripeStateReturnCodeEnum.merchant)
                        return Redirect(Url.Content("~/merchant/settings?u=" + SiteMessagesEnum.sca));

                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
        public ActionResult MerchantSettings()
        {
            try
            {
                NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.Url.Query);
                string updated = nameValueCollection["u"];

                if (!String.IsNullOrEmpty(updated) && updated == SiteMessagesEnum.sced.ToString())
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Error;
                    message.Message = "You did not Connect to Stripe. In order to Accept Customer Credit Cards, you should connect to Stripe.";
                    this.AddMessage(message);
                }
                if (!String.IsNullOrEmpty(updated) && updated == SiteMessagesEnum.sca.ToString())
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Success;
                    message.Message = "Stripe Connected Successfully.";
                    this.AddMessage(message);
                }
                if (!String.IsNullOrEmpty(updated) && updated == SiteMessagesEnum.sus.ToString())
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Success;
                    message.Message = "Updated Settings Successfully.";
                    this.AddMessage(message);
                }

                MerchantGateway mg = new MerchantGateway();
                var memId = RDN.Library.Classes.Account.User.GetMemberId();
                var merchant = mg.GetMerchantSettings(memId);
                string stripe = "https://connect.stripe.com/oauth/authorize?response_type=code&client_id=" + ServerConfig.STRIPE_CONNECT_LIVE_KEY + "&scope=read_write&state=" + StripeStateReturnCodeEnum.merchant + "-" + merchant.PrivateManagerId.ToString().Replace("-", "");
                
                string u = nameValueCollection["return"];
                if (!String.IsNullOrEmpty(u))
                {
                    merchant.ReturnUrl = u;
                }

                ViewBag.StripeUrl = stripe;
                return View(merchant);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
 public ActionResult MerchantSettings(OverviewMerchant merchant)
 {
     try
     {
         MerchantGateway mg = new MerchantGateway();
         mg.UpdateMerchantSettings(merchant);
         NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);
         string u = nameValueCollection["return"];
         if (!String.IsNullOrEmpty(u))
         {
             return Redirect(u + "?u=" + SiteMessagesEnum.sus);
         }
         return Redirect(Url.Content("~/merchant/settings?u=" + SiteMessagesEnum.sus));
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
 }
 public ActionResult ViewTournament(string pid, string id)
 {
     try
     {
         NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.Url.Query);
         string u = nameValueCollection["u"];
         if (u == SiteMessagesEnum.s.ToString())
         {
             SiteMessage message = new SiteMessage();
             message.MessageType = SiteMessageType.Success;
             message.Message = "Successfully Updated Tournament.";
             this.AddMessage(message);
         }
         if (u == SiteMessagesEnum.sup.ToString())
         {
             SiteMessage message = new SiteMessage();
             message.MessageType = SiteMessageType.Success;
             message.Message = "Successfully Updated Logo.";
             this.AddMessage(message);
         }
         Guid memId = RDN.Library.Classes.Account.User.GetMemberId();
         var tourny = Tournament.GetTournamentToManage(new Guid(id), new Guid(pid));
         Paywall pw = new Paywall();
         var pws = pw.GetPaywalls(memId);
         Dictionary<int, string> countries = LocationFactory.GetCountriesDictionary();
         var counTemp = countries.Select(item => new SelectListItem { Text = item.Value, Value = item.Key.ToString() }).ToList();
         //ViewData["TournamentClass"] = tourny.TournamentClass.ToSelectListDropDown();
         //var list =    Enum.GetValues(typeof(TournamentTypeEnum)).Cast<TournamentTypeEnum>().ToList();
         MerchantGateway mg = new MerchantGateway();
         tourny.AvailableShops = mg.GetPublicMerchants();
         ViewBag.Countries = new SelectList(counTemp, "Value", "Text", tourny.CountryId);
         ViewBag.PayWalls = new SelectList(pws.Paywalls, "PaywallId", "DescriptionOfPaywall", tourny.PaywallId);
         return View(tourny);
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
 }
        public ActionResult CreatePaywall(DisplayPaywall paywall)
        {
            try
            {
                var sg = new MerchantGateway();
                var merchant = sg.CreateMerchantAccount(paywall.InternalReference, MerchantInternalReference.Member);
                var id = RDN.Library.Classes.Account.User.GetMemberId();
                MemberCache.Clear(id);
                MemberCache.ClearApiCache(id);

                return Redirect(Url.Content("~/paywall/all"));
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
        public ActionResult Manage(string pid, string id)
        {
            try
            {
                NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.Url.Query);
                string u = nameValueCollection["u"];
                if (u == SiteMessagesEnum.s.ToString())
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Success;
                    message.Message = "Successfully Updated Game.";
                    this.AddMessage(message);
                }
                var memId = RDN.Library.Classes.Account.User.GetMemberId();
                var game = GameManager.GetGameForManagement(new Guid(id), new Guid(pid), memId);
                Paywall pw = new Paywall();
                var pws = pw.GetPaywalls(memId);
                game.Paywalls = pws.Paywalls;
                MerchantGateway mg = new MerchantGateway();
                game.AvailableShops = mg.GetPublicMerchants();



                ViewBag.PayWalls = new SelectList(game.Paywalls, "PaywallId", "DescriptionOfPaywall", game.SelectedPaywall);
                if (game != null)
                    return View(game);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.na));
        }