public async Task<ActionResult> GetToken(StripeModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Home");
            }

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var stripeCustomer = getCustomer();
            if(stripeCustomer == null)
            {
                await CreateCustomer(model);
                return RedirectToAction("Index", "Home");
            }
            else if(stripeCustomer.HasSubscription == false && stripeCustomer.SubscriptionType=="standard")
            {
                await CreateCustomer(model);
                return RedirectToAction("Index", "Home");
            }
       
            return RedirectToAction("Index", "Home");
        }
        private async Task CreateCustomer(StripeModel model)
        {
            await Task.Run(() =>
            {
                // create customer based on validated token from stripe.js 
                var myCustomer = new StripeCustomerCreateOptions();

                // assign token to a credit card option for a user
                myCustomer.Card = new StripeCreditCardOptions()
                {
                    TokenId = model.Token
                };

                myCustomer.Email = User.Identity.Name;
                myCustomer.Description = User.Identity.Name;
                myCustomer.PlanId = model.SubscriptionType.ToString();
                myCustomer.Quantity = 1;
                
                // create customer in stripe service
                var customerService = new StripeCustomerService();
                StripeCustomer stripeCustomer = customerService.Create(myCustomer);

                // get subscription Id from created user
                var subscriptionID = stripeCustomer.StripeSubscriptionList.StripeSubscriptions.FirstOrDefault().Id;              
                       
             // save credit card optional details 
                StripeCustomerService customerServic = new StripeCustomerService();
                stripeCustomer = customerService.Get(stripeCustomer.Id);
                var cardId = stripeCustomer.StripeDefaultCardId; // get card id
                var myCard = new StripeCardUpdateOptions();

                myCard.Name = model.CardHolderName;
                myCard.AddressLine1 = model.AddressLine1;
                myCard.AddressLine2 = model.AddressLine2;
                myCard.AddressCity = model.AddressCity;
                myCard.AddressZip = model.AddressPostcode;
                myCard.AddressCountry = model.AddressCountry;

                var cardService = new StripeCardService();
                StripeCard stripeCard = cardService.Update(stripeCustomer.Id, cardId, myCard);
            //........................
                
                // record customer in database
                var cust = getCustomer();
                if(cust == null) // new users
                {
                    // get values to create a new record in StripeCustomer table
                    StripeCustomers customer = new StripeCustomers();
                
                    customer.CustomerName = User.Identity.Name;
                    customer.StripeCustomerID = stripeCustomer.Id;
                    customer.StripeSubscriptionID = subscriptionID;
                    customer.SubscriptionType = model.SubscriptionType.ToString();
                    customer.HasSubscription = true;
                    customer.Interval = "Monthly";
                    customer.StartDate = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");
                    if (model.SubscriptionType.ToString() == "standard")
                    {
                        customer.TrialValidUntil = currentTime.AddDays(30);
                    }
                    db.StripeCustomers.Add(customer);
                    }
                    else // user with db records
                    {
                        StripeCustomers newRecord = new StripeCustomers();

                        // take the data from current user
                        newRecord.StripeCustomerID = stripeCustomer.Id;
                        newRecord.CustomerName = User.Identity.Name;
                        newRecord.StripeSubscriptionID = subscriptionID;
                        newRecord.SubscriptionType = model.SubscriptionType.ToString();
                        newRecord.HasSubscription = true;
                        newRecord.Interval = "Monthly";
                        newRecord.StartDate = currentTime;
                        if (model.SubscriptionType.ToString() == "standard")
                        {
                            newRecord.TrialValidUntil = currentTime.AddDays(30);
                        }
                        db.StripeCustomers.Add(newRecord);

                        // delete customer's old record in database
                        db.StripeCustomers.Remove(cust);
                    }
                db.SaveChanges();
            });
        }