public async Task <string> CreateSubcritionProduct() { StripeConfiguration.ApiKey = this._configuration.GetSection("Stripe")["SecretKey"]; var productoptions = new ProductCreateOptions { Name = "Quick Order Subcription", Active = true, Description = "Quick Order Admin System Subcription", Type = "service" }; var productservice = new ProductService(); var producttoken = await productservice.CreateAsync(productoptions); var priceoptions = new PriceCreateOptions { UnitAmount = 200, Currency = "usd", Recurring = new PriceRecurringOptions { Interval = "month", }, Product = producttoken.Id, }; var priceservice = new PriceService(); var pricetoken = await priceservice.CreateAsync(priceoptions); if (!string.IsNullOrEmpty(producttoken.Id)) { return(producttoken.Id); } else { return(string.Empty); } }
public async Task <string> CreateACustomerSubcription(string customerId) { try { StripeConfiguration.ApiKey = this._configuration.GetSection("Stripe")["SecretKey"]; //================================================================== // Create Product Subcription var productoptions = new ProductCreateOptions { Name = "Quick Order Subcription", Active = true, Description = "Quick Order Admin System Subcription", Type = "service" }; var productservice = new ProductService(); var producttoken = await productservice.CreateAsync(productoptions); var priceoptions = new PriceCreateOptions { UnitAmount = 200, Currency = "usd", Recurring = new PriceRecurringOptions { Interval = "month", }, Product = producttoken.Id, }; var priceservice = new PriceService(); var priceservicetoken = await priceservice.CreateAsync(priceoptions); //======================================================================= End Create Product Subcription //=================================================================================== //Create Subcription to store var options = new SubscriptionCreateOptions { Customer = customerId, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = priceservicetoken.Id, }, }, }; var service = new SubscriptionService(); Subscription subscription = await service.CreateAsync(options); if (!string.IsNullOrEmpty(subscription.Id)) { //var newSubcription = new Subcription() //{ // StripeCustomerId = customerId, // StripeSubCriptionID = subscription.Id //}; //_context.Subcriptions.Add(newSubcription); //try //{ //_context.SaveChanges(); //} //catch (Exception e) //{ // Console.WriteLine(e); //} return(subscription.Id); } else { return(string.Empty); } } catch (Exception e) { Console.WriteLine(e); return(string.Empty); } }