Beispiel #1
0
        public string CreateCustomer(RechargeInput c)
        {
            var user        = AuthHelper.GetCurrentUser();
            var usermanager = AuthHelper.GetUserManager();

            try
            {
                StripeConfiguration.SetApiKey(System.Configuration.ConfigurationManager.AppSettings["StripeApiKey"]);

                var myCustomer = new StripeCustomerCreateOptions();
                myCustomer.Email       = user.Email;
                myCustomer.Description = user.Organization + " (" + user.Email + ")";
                myCustomer.SourceToken = c.AuthorizationCode;
                myCustomer.PlanId      = c.PlanID;

                var            customerService = new StripeCustomerService();
                StripeCustomer customer        = customerService.Create(myCustomer);

                //Update the user with the stripe customer id and plan info
                user.StripeCustomerId = customer.Id;
                user.StripePlanId     = c.PlanID;
                user.AccountBalance   = PlanHelper.GetPlan(c.PlanID).Hours;
                usermanager.Update(user);

                return(customer.Id);
            }
            catch (Exception ex)
            {
                //log the exception and return the message to the caller
                throw ex;
            }

            //Create a JIRA epic and store it with the user
            try
            {
                WorkItemController wic = new WorkItemController();
                wic.CreateCustomerBacklog();
            }
            catch { }
        }
Beispiel #2
0
        public ActionResult Index()
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            //if the user does not have a valid stripe customer id
            //redirect to the payment page so a customer can be created in stripe
            var usermanager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();

            if (usermanager == null)
            {
                throw new ApplicationException("Could not retrieve user manager");
            }
            var user = usermanager.FindByName(HttpContext.User.Identity.Name);

            if (user == null)
            {
                throw new ApplicationException("Could not retrieve user account");
            }

            //if there is no link to a stripe customer, redirect to payment page
            if (string.IsNullOrEmpty(user.StripeCustomerId))
            {
                return(RedirectToAction("CreateCustomer", "Payment"));
            }

            //if there is no jira epic link for the customer, try and create one
            if (string.IsNullOrEmpty(user.JIRAEpicId))
            {
                WorkItemController wic = new WorkItemController();
                wic.CreateCustomerBacklog();
            }

            return(View());
        }