public void Create(string userName, Plan plan, string stripeToken) { var user = UserManager.FindByName(userName); if (String.IsNullOrEmpty(user.StripeCustomerId)) //first time customer { //create customer which will create subscription if plan is set and cc info via token is provided var customer = new StripeCustomerCreateOptions() { Email = user.Email, Source = new StripeSourceOptions() { TokenId = stripeToken }, PlanId = plan.ExternalId //externalid is stripe plan.id }; StripeCustomer stripeCustomer = StripeCustomerService.Create(customer); user.StripeCustomerId = stripeCustomer.Id; user.ActiveUntil = DateTime.Now.AddDays((double)plan.TrialPeriodDays); UserManager.Update(user); //Invoice Created var invoiceService = new StripeInvoiceService(); // IEnumerable<StripeInvoice> response = invoiceService.List().Where(x=>x.CustomerId == stripeCustomer.Id && x.Paid == true && ; // SendPaymentReceivedFromChargeEmail() } else { var stripeSubscription = StripeSubscriptionService.Create(user.StripeCustomerId, plan.ExternalId); user.ActiveUntil = DateTime.Now.AddDays((double)plan.TrialPeriodDays); UserManager.Update(user); } }
private static void StripePlanToPlan(StripePlan stripePlan, Plan plan) { plan.Name = stripePlan.Name; plan.AmountInCents = stripePlan.Amount; plan.Currency = stripePlan.Currency; plan.Interval = stripePlan.Interval; plan.TrialPeriodDays = stripePlan.TrialPeriodDays; }