public ActionResult PaywallRefundOrder(DisplayInvoice invoice)
        {
            try
            {
                bool isSuccess = false;
                var sg = new Paywall();
                PaymentGateway pg = new PaymentGateway();
                var f = pg.StartInvoiceWizard().Initalize(invoice.Merchant.MerchantId, "USD", invoice.PaymentProvider, PaymentMode.Live, ChargeTypeEnum.Refund_Paywall)
                    .SetInvoiceId(invoice.InvoiceId)
                .SetRefundAmount(invoice.RefundAmount)
                .SetNotes(null, invoice.AdminNote);

                var response = f.FinalizeInvoice();
                if (response.Status == InvoiceStatus.Refunded)
                    isSuccess = true;

                if (isSuccess)
                    return Redirect(Url.Content("~/paywall/order/" + invoice.Merchant.PrivateManagerId.ToString().Replace("-", "") + "/" + invoice.Merchant.MerchantId.ToString().Replace("-", "") + "/" + invoice.InvoiceId.ToString().Replace("-", "") + "?u=" + SiteMessagesEnum.ro));
                else
                    return Redirect(Url.Content("~/paywall/order/" + invoice.Merchant.PrivateManagerId.ToString().Replace("-", "") + "/" + invoice.Merchant.MerchantId.ToString().Replace("-", "") + "/" + invoice.InvoiceId.ToString().Replace("-", "") + "?u=" + SiteMessagesEnum.sww));
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
        public ActionResult PaywallOrder(DisplayInvoice invoice)
        {
            try
            {


                var sg = new Paywall();
                sg.UpdatePaywallOrder(invoice);
                return Redirect(Url.Content("~/paywall/order/" + invoice.Merchant.PrivateManagerId.ToString().Replace("-", "") + "/" + invoice.Merchant.MerchantId.ToString().Replace("-", "") + "/" + invoice.InvoiceId.ToString().Replace("-", "") + "?u=" + SiteMessagesEnum.s));
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
        public bool UpdateCurrentlyViewing(long paywallId, string password)
        {
            if (instance.Paywalls == null)
                instance.Paywalls = new List<Paywall>();

            var wall = instance.Paywalls.Where(x => x.PaywallId == paywallId && x.PasswordForPaywall == password).FirstOrDefault();
            if (wall != null)
            {
                wall.LastViewedPaywall = DateTime.UtcNow.AddMinutes(2);
            }
            else
            {
                Paywall w = new Paywall();
                w.PaywallId = paywallId;
                w.PasswordForPaywall = password;
                w.LastViewedPaywall = DateTime.UtcNow.AddMinutes(2);
                instance.Paywalls.Add(w);
            }
            return true;
        }
 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 Index(GameOutModel crap)
        {
            try
            {
                if (!String.IsNullOrEmpty(crap.Paywall.PasswordForPaywall))
                    crap.Paywall.PasswordForPaywall = crap.Paywall.PasswordForPaywall.Trim();
                GameOutModel game = new GameOutModel();
                game.Game = GameServerViewModel.GetGameFromCache(crap.Game.GameId);
                Paywall wall = new Paywall();
                game.Paywall = wall.GetPaywall(game.Game.PaywallId);
                if (game.Paywall == null)
                    game.Paywall = new Paywall();

                bool isPaid = GameServerViewModel.CheckGamePaywallIsPaid(game.Game.GameId, crap.Paywall.PasswordForPaywall);
                game.Paywall.IsPaid = isPaid;
                if (PaywallViewers.Instance.Paywalls == null)
                    PaywallViewers.Instance.Paywalls = new List<Paywall>();
                bool isCurrentlyViewing = PaywallViewers.Instance.IsCurrentlyViewingPaywall(crap.Paywall.PaywallId, crap.Paywall.PasswordForPaywall);
                if (isCurrentlyViewing)
                {
                    game.Paywall.IsPaid = false;
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Warning;
                    message.Message = "You are currently viewing this from another device. You can only view this from one device at a time.";
                    this.AddMessage(message);
                }

                ViewData["merchantId"] = game.Game.SelectedShop;
                game.StripeKey = "Stripe.setPublishableKey('" + ServerConfig.STRIPE_LIVE_KEY + "');";
                if (game != null)
                    return View(game);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
        // GET: /Game/
        public ActionResult Index(string id, string gameName, string team1, string team2)
        {
            try
            {
                NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.Url.Query);
                string u = nameValueCollection["u"];
                if (u == SiteMessagesEnum.sww.ToString())
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Error;
                    message.Message = "Something Went Wrong, Problem Sent to the Developers.";
                    this.AddMessage(message);
                }


                GameOutModel game = new GameOutModel();
                game.Game = GameServerViewModel.GetGameFromCache(new Guid(id));
                Paywall wall = new Paywall();
                game.Paywall = wall.GetPaywall(game.Game.PaywallId);
                if (game.Paywall == null)
                    game.Paywall = new Paywall();

                ViewData["merchantId"] = game.Game.SelectedShop;
                if (!String.IsNullOrEmpty(game.Paywall.StripePublishableKey))
                    game.StripeKey = "Stripe.setPublishableKey('" + game.Paywall.StripePublishableKey + "');";
                else
                    game.StripeKey = "Stripe.setPublishableKey('" + ServerConfig.STRIPE_LIVE_KEY + "');";
                if (game != null)
                    return View(game);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/roller-derby-games?u=" + SiteMessagesEnum.dex));
        }
Example #7
0
 public Paywall UpdatePaywall(Paywall pw)
 {
     try
     {
         ManagementContext dc = new ManagementContext();
         var npw = dc.Paywalls.Where(x => x.PaywallId == pw.PaywallId).FirstOrDefault();
         if (npw.Merchant.InternalReference == RDN.Library.Classes.Account.User.GetMemberId())
         {
             npw.DailyPrice = pw.DailyPrice;
             npw.DescriptionOfPaywall = pw.DescriptionOfPaywall;
             npw.EndDate = pw.EndDate;
             npw.IsEnabled = pw.IsEnabled;
             npw.StartDate = pw.StartDate;
             npw.TimespanPrice = pw.TimespanPrice;
             npw.PaywallId = pw.PaywallId;
             dc.SaveChanges();
             return pw;
         }
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return null;
 }
Example #8
0
        private static Paywall DisplayPaywall(DataModels.PaymentGateway.Paywall.Paywall pw)
        {
            Paywall npw = new Paywall();
            try
            {
                npw.DailyPrice = pw.DailyPrice;
                npw.DescriptionOfPaywall = pw.DescriptionOfPaywall;
                npw.EndDate = pw.EndDate;
                if (npw.EndDate.HasValue)
                    npw.EndDateDisplay = pw.EndDate.Value.ToShortDateString();
                npw.IsEnabled = pw.IsEnabled;

                npw.StartDate = pw.StartDate;
                if (npw.StartDate.HasValue)
                    npw.StartDateDisplay = pw.StartDate.Value.ToShortDateString();
                npw.TimespanPrice = pw.TimespanPrice;
                npw.PaywallId = pw.PaywallId;
                npw.AcceptPaypal = pw.Merchant.AcceptPaymentsViaPaypal;
                npw.AcceptStripe = pw.Merchant.AcceptPaymentsViaStripe;
                npw.StripePublishableKey = pw.Merchant.StripePublishableKey;
                npw.MerchantId = pw.Merchant.MerchantId;

                Guid memId = RDN.Library.Classes.Account.User.GetMemberId();
                foreach (var wall in pw.PaywallInvoices)
                {
                    if (wall.MemberPaidId == memId)
                        if (wall.Invoice.InvoiceStatus == (byte)InvoiceStatus.Payment_Successful || wall.Invoice.InvoiceStatus == (byte)InvoiceStatus.Pending_Payment_From_Paypal)
                        {
                            npw.IsPaid = true;
                            break;
                        }
                }

                foreach (var voice in pw.Merchant.Invoices.Where(x => x.Items.Count > 0).OrderByDescending(x => x.Created))
                {
                    DisplayInvoice v = DisplayInvoice(voice);
                    npw.Invoices.Add(v);
                }

                var dc = new ManagementContext();
                foreach (var game in pw.Games)
                {
                    npw.Games.Add(Game.GameManager.DisplayGame(game));
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return npw;
        }
Example #9
0
 public Paywall AddPaywall(Paywall pw)
 {
     try
     {
         ManagementContext dc = new ManagementContext();
         DataModels.PaymentGateway.Paywall.Paywall npw = new DataModels.PaymentGateway.Paywall.Paywall();
         npw.DailyPrice = pw.DailyPrice;
         npw.DescriptionOfPaywall = pw.DescriptionOfPaywall;
         npw.EndDate = pw.EndDate;
         npw.IsEnabled = pw.IsEnabled;
         npw.Merchant = dc.Merchants.Where(x => x.InternalReference == pw.OwnerId).FirstOrDefault();
         npw.StartDate = pw.StartDate;
         npw.TimespanPrice = pw.TimespanPrice;
         dc.Paywalls.Add(npw);
         dc.SaveChanges();
         pw.PaywallId = npw.PaywallId;
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return pw;
 }
        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));
        }
        public ActionResult AddPaywall()
        {
            try
            {
                Paywall pw = new Paywall();

                return View(pw);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
 public ActionResult Paywalls()
 {
     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 Added New Paywall.";
             this.AddMessage(message);
         }
         if (u == SiteMessagesEnum.su.ToString())
         {
             SiteMessage message = new SiteMessage();
             message.MessageType = SiteMessageType.Success;
             message.Message = "Successfully Updated Paywall.";
             this.AddMessage(message);
         }
         if (u == SiteMessagesEnum.sus.ToString())
         {
             SiteMessage message = new SiteMessage();
             message.MessageType = SiteMessageType.Success;
             message.Message = "Successfully Updated Settings.";
             this.AddMessage(message);
         }
         //DisplayPaywall pw = new DisplayPaywall();
         Paywall pw = new Paywall();
         Guid ownerId = RDN.Library.Classes.Account.User.GetMemberId();
         DisplayPaywall dpw = pw.GetPaywalls(ownerId);
         dpw.InternalReference = ownerId;
         if (!dpw.AcceptPaymentsViaPaypal && !dpw.AcceptPaymentsViaStripe)
         {
             SiteMessage message = new SiteMessage();
             message.MessageType = SiteMessageType.Info;
             message.Message = "Please setup a payment processor under Merchant Settings.";
             this.AddMessage(message);
         }
         dpw.ReturnUrl = Url.Encode(Request.RawUrl);
         return View(dpw);
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
 }
 public Tournament()
 {
     Owners = new List<MemberDisplayBasic>();
     Paywall = new Paywall();
     Games = new List<Game>();
     AssistLeaders = new List<AssistViewModel>();
     BlockLeaders = new List<BlockViewModel>();
     PenaltyLeaders = new List<PenaltyViewModel>();
     AllSkaters = new List<TeamMembersViewModel>();
     Photos = new List<PhotoItem>();
     TeamsForTournament = new List<TeamViewModel>();
     TournamentRounds = new List<TournamentRoundsClass>();
     Rankings = new List<TournamentApi.TournamentRanking>();
     TeamsForTournamentApi = new List<TournamentApi.TournamentTeam>();
     TournamentRoundsApi = new List<TournamentApi.TournamentRound>();
     RankingsForSeededRounds = new List<TournamentApi.TournamentRanking>();
     TournamentRoundsForSeedingGameplay = new List<TournamentRoundsClass>();
     TournamentRoundsApiForSeeding = new List<TournamentApi.TournamentRound>();
 }
        public ActionResult EditPaywall(Paywall pw)
        {
            try
            {
                string priceDaily = HttpContext.Request.Form["Price"];
                string priceFull = HttpContext.Request.Form["FullPrice"];
                if (!String.IsNullOrEmpty(priceDaily))
                    pw.DailyPrice = Convert.ToDecimal(priceDaily);
                if (!String.IsNullOrEmpty(priceFull))
                    pw.TimespanPrice = Convert.ToDecimal(priceFull);
                pw.OwnerId = RDN.Library.Classes.Account.User.GetMemberId();
                DateTime sd = new DateTime();

                bool successsd = DateTime.TryParse(pw.StartDateDisplay, out sd);
                if (successsd)
                    pw.StartDate = sd;
                else
                    pw.StartDate = null;

                DateTime ed = new DateTime();

                bool successed = DateTime.TryParse(pw.EndDateDisplay, out ed);
                if (successed)
                    pw.EndDate = ed;
                else
                    pw.EndDate = null;



                var wall = pw.UpdatePaywall(pw);

                if (wall == null)
                    return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.na));
                return Redirect(Url.Content("~/paywall/all?u=" + SiteMessagesEnum.su));
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
 public ActionResult EditPaywall(string paywallid)
 {
     try
     {
         Paywall pw = new Paywall();
         var wall = pw.GetOwnedPaywall(Convert.ToInt64(paywallid));
         if (wall == null)
             return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.na));
         return View(wall);
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
 }
 public ActionResult AddPaywall(Paywall pw)
 {
     try
     {
         string priceDaily = HttpContext.Request.Form["Price"];
         string priceFull = HttpContext.Request.Form["FullPrice"];
         if (!String.IsNullOrEmpty(priceDaily))
             pw.DailyPrice = Convert.ToDecimal(priceDaily);
         if (!String.IsNullOrEmpty(priceFull))
             pw.TimespanPrice = Convert.ToDecimal(priceFull);
         pw.OwnerId = RDN.Library.Classes.Account.User.GetMemberId();
         pw.AddPaywall(pw);
         return Redirect(Url.Content("~/paywall/all?u=" + SiteMessagesEnum.s));
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
 }
        public ActionResult MakePaywallPayment(GameOutModel crap)
        {
            var memId = RDN.Library.Classes.Account.User.GetMemberId();
            GameOutModel game = new GameOutModel();
            game.Game = GameServerViewModel.GetGameFromCache(crap.Game.GameId);
            Paywall wall = new Paywall();
            game.Paywall = wall.GetPaywall(game.Game.PaywallId);

            try
            {
                string paymentProvider = Request.Form["PaymentType"].ToString();
                string stripeToken = "none";

                PaymentProvider provider = PaymentProvider.None;
                if (paymentProvider == PaymentProvider.Stripe.ToString())
                {
                    provider = PaymentProvider.Stripe;
                    stripeToken = Request.Form["stripeToken"].ToString();
                }
                else if (paymentProvider == PaymentProvider.Paypal.ToString())
                {
                    provider = PaymentProvider.Paypal;
                }
                string subType = Request.Form["PaymentCost"].ToString();
                PaywallPriceTypeEnum sub = (PaywallPriceTypeEnum)Enum.Parse(typeof(PaywallPriceTypeEnum), subType);
                decimal price = .99M;

                DateTime now = DateTime.UtcNow;
                DateTime validTill = DateTime.UtcNow.AddDays(1);

                if (sub == PaywallPriceTypeEnum.Daily_Payment)
                {
                    validTill = DateTime.UtcNow.AddDays(1);
                }
                else if (sub == PaywallPriceTypeEnum.Full_Payment)
                {
                    validTill = game.Paywall.EndDate.Value.AddDays(1);
                }

                PaymentGateway pg = new PaymentGateway();
                var f = pg.StartInvoiceWizard().Initalize(game.Paywall.MerchantId, "USD", provider, PaymentMode.Live, ChargeTypeEnum.Paywall)
                    .SetInvoiceId(Guid.NewGuid())
                    .SetPaywall(new InvoicePaywall
                    {
                        ValidUntil = validTill,
                        PaywallId = game.Paywall.PaywallId,
                        PriceType = sub,
                        Description = "Paid For " + game.Game.GameName + " with a " + RDN.Utilities.Enums.EnumExt.ToFreindlyName(sub) + " Pass",
                        Name = "Game Streaming Paid",
                        Price = price,
                        InternalObject = game.Game.GameId,
                        MemberPaidId = memId,
                        PaywallLocation = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-game/" + game.Game.GameId.ToString().Replace("-", "") + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(game.Game.GameName) + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(game.Game.Team1.TeamName) + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(game.Game.Team2.TeamName)
                    })
                    .SetInvoiceContactData(new InvoiceContactInfo
                    {
                        Email = crap.Paywall.EmailAddress,
                        Phone = crap.Paywall.PhoneNumber,
                    });

                if (provider == PaymentProvider.Stripe)
                    f.SetStripeTokenId(stripeToken);

                var response = f.FinalizeInvoice();

                //succesfully charged.
                if (response.Status == InvoiceStatus.Payment_Successful)
                    return Redirect(ServerConfig.PAYWALL_RECEIPT_URL + response.InvoiceId.ToString().Replace("-", ""));
                else if (response.Status == InvoiceStatus.Pending_Payment_From_Paypal)
                    return Redirect(response.RedirectLink);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/roller-derby-game/" + game.Game.GameId.ToString().Replace("-", "") + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(game.Game.GameName) + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(game.Game.Team1.TeamName) + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(game.Game.Team2.TeamName) + "?u=" + SiteMessagesEnum.sww));

        }
        public ActionResult PaywallOrder(Guid privId, Guid storeId, Guid invoiceId)
        {
            DisplayInvoice invoice = null;
            try
            {
                NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.Url.Query);
                string updated = nameValueCollection["u"];

                if (!String.IsNullOrEmpty(updated) && updated == SiteMessagesEnum.s.ToString())
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Success;
                    message.Message = "Successfully Updated.";
                    this.AddMessage(message);
                }
                if (!String.IsNullOrEmpty(updated) && updated == SiteMessagesEnum.ro.ToString())
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Success;
                    message.Message = "Refunded Order.";
                    this.AddMessage(message);
                }
                if (!String.IsNullOrEmpty(updated) && updated == SiteMessagesEnum.sww.ToString())
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Error;
                    message.Message = "Order Not Refunded. Error Sent to Developers.";
                    this.AddMessage(message);
                }

                var sg = new Paywall();
                invoice = sg.GetInvoiceForManager(storeId, privId, invoiceId);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return View(invoice);
        }
        private void HandleStripePayments(CreateInvoiceReturn output)
        {
            if (invoice.ChargeType == ChargeTypeEnum.Refund_Paywall)
            {
                invoice.InvoiceStatus = InvoiceStatus.Refund_Started;

                // Create the Stripe Request and get the data back.
                var response = PerformStripeRefund();
                // If it was successful we will now have a redirect link
                if (response != null)
                {
                    // Try to save the data to our database
                    if (response.AmountInCentsRefunded.HasValue && response.AmountInCentsRefunded.Value > 0)
                    {
                        PaymentGateway pg = new PaymentGateway();
                        var voice = pg.GetDisplayInvoice(invoice.InvoiceId);
                        if (voice.Refunds.Sum(x => x.RefundAmount) + invoice.FinancialData.RefundAmount == voice.TotalIncludingTax)
                            pg.UpdateInvoiceForRefund(invoice.InvoiceId, InvoiceStatus.Refunded, invoice.FinancialData.RefundAmount, invoice.AdminNote);
                        else
                            pg.UpdateInvoiceForRefund(invoice.InvoiceId, InvoiceStatus.Partially_Refunded, invoice.FinancialData.RefundAmount, invoice.AdminNote);

                        voice.RefundAmount = invoice.FinancialData.RefundAmount;
                        Paywall.Paywall pw = new Paywall.Paywall();
                        pw.HandlePaywallRefund(voice);
                        output.Status = InvoiceStatus.Refunded;
                    }
                    else
                    {
                        // Could not save to our database
                        output.Error = "Failed to save to RDN database";
                        output.Status = InvoiceStatus.Failed;
                    }
                }
                else
                    output.Status = InvoiceStatus.Failed;
            }
            else if (invoice.ChargeType == ChargeTypeEnum.Subscription)
            {
                CompleteNewStripeSubscription(output);
            }
            else if (invoice.ChargeType == ChargeTypeEnum.Paywall)
            {
                CalculateRDNationFeesForPaywallPurchasesStripe();
                // Create the Stripe Request and get the data back.
                var response = PerformStripePaywallPurchaseCheckout();
                // If it was successful we will now have a redirect link
                if (response != null)
                {
                    // Try to save the data to our database
                    var result = AddInvoiceToDatabase();

                    if (result)
                    {
                        output.InvoiceId = invoice.InvoiceId;
                        output.Status = InvoiceStatus.Payment_Successful;

                        PaymentGateway pg = new PaymentGateway();
                        var voice = pg.GetDisplayInvoice(invoice.InvoiceId);
                        Paywall.Paywall pw = new Paywall.Paywall();
                        pw.HandlePaywallPayments(voice);
                    }
                    else
                    {
                        // Could not save to our database
                        output.Error = "Failed to save to RDN database";
                        output.Status = InvoiceStatus.Failed;
                    }
                }
                else
                    output.Status = InvoiceStatus.Failed;
            }
            else if (invoice.ChargeType == ChargeTypeEnum.Cancel_Subscription)
            {
                CancelStripeSubscription(output);
            }
            else if (invoice.ChargeType == ChargeTypeEnum.SubscriptionUpdated)
            {
                CompleteStripeSubscriptionUpdated(output);
            }
            else if (invoice.ChargeType == ChargeTypeEnum.InStorePurchase)
            {
                CalculateRDNationFeesForInStorePurchasesStripe();
                // Create the Stripe Request and get the data back.
                var response = PerformStripeInStorePurchaseCheckout();
                // If it was successful we will now have a redirect link
                if (response != null)
                {
                    // Try to save the data to our database
                    var result = AddInvoiceToDatabase();

                    if (result)
                    {
                        output.InvoiceId = invoice.InvoiceId;
                        output.Status = InvoiceStatus.Payment_Successful;

                        PaymentGateway pg = new PaymentGateway();
                        var voice = pg.GetDisplayInvoice(invoice.InvoiceId);
                        Store.StoreGateway sg = new Store.StoreGateway();
                        sg.HandleStoreItemPayments(voice);
                    }
                    else
                    {
                        // Could not save to our database
                        output.Error = "Failed to save to RDN database";
                        output.Status = InvoiceStatus.Failed;
                    }
                }
                else
                {
                    // Could not create a google link
                    //output.Error = response.Error;
                    output.Status = InvoiceStatus.Failed;
                }
            }
            else if (invoice.ChargeType == ChargeTypeEnum.Stripe_Checkout)
            {

                // Create the Stripe Request and get the data back.
                var response = ChargeStripeCheckoutPayment();
                // If it was successful we will now have a redirect link
                if (response != null)
                {
                    // Try to save the data to our database
                    var result = AddInvoiceToDatabase();

                    if (result)
                    {
                        output.InvoiceId = invoice.InvoiceId;
                        output.Status = InvoiceStatus.Payment_Successful;

                        var emailData = new Dictionary<string, string>
                                        {
                                            { "Why: ", invoice.Note }, 
                                            { "invoiceId",invoice.InvoiceId.ToString().Replace("-","") },
                                            { "Paid",invoice.FinancialData.TotalIncludingTax.ToString("N2")}
                                        };
                        EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN, EmailServer.EmailServer.DEFAULT_SUBJECT + " Receipt For League Subscription", emailData, EmailServer.EmailServerLayoutsEnum.Default);
                        EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_KRIS_WORLIDGE_EMAIL_ADMIN, EmailServer.EmailServer.DEFAULT_SUBJECT + " New Payment Made", emailData, EmailServer.EmailServerLayoutsEnum.Default);

                    }
                    else
                    {
                        // Could not save to our database
                        output.Error = "Failed to save to RDN database";
                        output.Status = InvoiceStatus.Failed;
                    }
                }
                else
                {
                    // Could not create a google link
                    //output.Error = response.Error;
                    output.Status = InvoiceStatus.Failed;
                }
            }
        }
        public ActionResult PaywallPayments(Guid privId, Guid storeId)
        {
            List<DisplayInvoice> invoices = null;
            try
            {

                Paywall pw = new Paywall();
                invoices = pw.GetPaywallInvoices(privId, storeId);

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return View(invoices);

        }