public async Task <IActionResult> CheckoutPayment(CheckoutVM model)
        {
            //register the user and sign them in if they are not already signed in
            ApplicationUser user = await CurrentUser();

            if (user == null)
            {
                var userresult = await CreateUser(model);

                if (userresult.HasErrors)
                {
                    CheckoutErrorVM errorVM = new CheckoutErrorVM()
                    {
                        ErrorMessage = userresult.ErrorMessage
                    };
                    return(RedirectToAction("CheckoutError", errorVM));
                }
                else
                {
                    //we now have a user
                    user = userresult.User;
                }
            }



            //hook up with the stripe service and get the payment intent
            //add this to the model and pass it on
            model.Cart = _cart;
            PaymentIntentResult result = await _stripeService.CreatePaymentIntent((model.Cart.Total * 100), model.Email);

            //add the user to the courses but with the PaymentSucceeded set to false for now
            //this is set when the webhook handles the payment success event
            var useraddedresult = AddUserToCourses(user, result.PaymentIntentId);

            if (!useraddedresult.Succeeded)
            {
                //we've been able to create the user but unable to add them to any courses
                //this is highly unlikely but in this event we don't want them to go through
                //to the payment form where the payment will be asked to be collected
                //from stripe.  So just send them to an error page
                CheckoutErrorVM errorVM = new CheckoutErrorVM()
                {
                    ErrorMessage = "There was a problem adding the user to the course(s).  This may be a system problem.  Please try again later."
                };
                return(RedirectToAction("CheckoutError", errorVM));
            }



            model.Cart.ClientSecret = result.ClientSecret;
            model.PublishableKey    = result.PublishableKey;
            return(View(model));
        }
 public IActionResult CheckoutError(CheckoutErrorVM model)
 {
     return(View(model));
 }