public void SerializeDecimalTiersProperly() { var options = new PriceCreateOptions { Tiers = new List <PriceTierOptions> { new PriceTierOptions { UnitAmountDecimal = 0.003m, FlatAmountDecimal = 0.12m, UpTo = 10, }, new PriceTierOptions { UnitAmountDecimal = 0.004m, FlatAmountDecimal = 0.24m, UpTo = PriceTierUpTo.Inf, }, }, }; Assert.Equal( "tiers[0][flat_amount_decimal]=0.12&tiers[0][unit_amount_decimal]=0.003&tiers[0][up_to]=10&" + "tiers[1][flat_amount_decimal]=0.24&tiers[1][unit_amount_decimal]=0.004&tiers[1][up_to]=inf", FormEncoder.CreateQueryString(options)); }
public static Product CreateProduct(StripeProductInfoModel model) { var stripeKey = StripeApiKey(); var options = new ProductCreateOptions { Description = model.Description, Name = model.Name, Active = model.Active, }; var service = new ProductService(); var product = service.Create(options); var priceOption = new PriceCreateOptions { Product = product.Id, UnitAmount = long.Parse(model.Price), Currency = "usd", }; var priceService = new PriceService(); var price = priceService.Create(priceOption); return(product); }
private Stripe.Price CreateStripeProductPrice(string productId, long price) { StripeConfiguration.ApiKey = _appKeys.StripeApiKey; var options = new PriceCreateOptions { UnitAmount = price, Currency = "usd", Product = productId, }; var service = new PriceService(); var stripePrice = service.Create(options); return(stripePrice); }
public Price CreatePrice(long productPrice, Product product) { var options = new PriceCreateOptions { UnitAmount = productPrice * 100, Currency = "dkk", Recurring = new PriceRecurringOptions { Interval = "month", }, Product = product.Id, }; var service = new PriceService(); var price = service.Create(options); return(price); }
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 void SerializeTiersProperly() { var options = new PriceCreateOptions { Tiers = new List <PriceTierOptions> { new PriceTierOptions { UnitAmount = 1000, UpTo = 10, }, new PriceTierOptions { UnitAmount = 2000, UpTo = PriceTierUpTo.Inf, }, }, }; Assert.Equal( "tiers[0][unit_amount]=1000&tiers[0][up_to]=10&" + "tiers[1][unit_amount]=2000&tiers[1][up_to]=inf", FormEncoder.CreateQueryString(options)); }
public PriceServiceTest( StripeMockFixture stripeMockFixture, MockHttpClientFixture mockHttpClientFixture) : base(stripeMockFixture, mockHttpClientFixture) { this.service = new PriceService(this.StripeClient); this.createOptions = new PriceCreateOptions { Currency = "usd", Nickname = "Price Nickmame", ProductData = new PriceProductDataOptions { Name = "Product Name", }, Recurring = new PriceRecurringOptions { Interval = "day", IntervalCount = 15, }, UnitAmountDecimal = 0.01234567890m, // Ensure decimals work }; this.createDecimalTierOptions = new PriceCreateOptions { Currency = "usd", Nickname = "Price Nickmame", ProductData = new PriceProductDataOptions { Name = "Product Name", }, Recurring = new PriceRecurringOptions { Interval = "day", IntervalCount = 15, }, Tiers = new List <PriceTierOptions> { new PriceTierOptions { UnitAmountDecimal = 0.01234567890m, UpTo = 10, }, new PriceTierOptions { UnitAmountDecimal = 0.02223m, UpTo = PriceTierUpTo.Inf, }, }, TiersMode = "graduated", }; this.updateOptions = new PriceUpdateOptions { Metadata = new Dictionary <string, string> { { "key", "value" }, }, }; this.listOptions = new PriceListOptions { Limit = 1, LookupKeys = new List <string> { "lookup_1", "lookup_2", }, }; }
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); } }