public IActionResult GetAllProducts() { StripeConfiguration.ApiKey = "****************"; List <object> resultList = new List <object>(); try { var options = new PriceListOptions { Currency = "sgd" }; var service = new PriceService(); StripeList <Price> prices = service.List(options); foreach (Price p in prices) { float amount = (float)p.UnitAmount / 100; string id = p.Id; resultList.Add(new { id = id, amount = amount, }); } } catch { return(BadRequest()); } return(Ok(new JsonResult(resultList))); }
public override Task Execute(MessageData data) { var options = new PriceListOptions { Limit = 10 }; var service = new PriceService(); StripeList <Price> prices = service.List(options); return(data.SendBack(new MessageData("pricesResponse", JsonConvert.SerializeObject(prices), A_HOUR))); }
private StripeList <Price> GetStripePricesByProductId(string productId) { StripeConfiguration.ApiKey = _appKeys.StripeApiKey; var options = new PriceListOptions { Product = productId, Active = true }; var service = new PriceService(); var listOfPrices = service.List(options); return(listOfPrices); }
public IActionResult GetAllProducts() { StripeConfiguration.ApiKey = API_KEY; List <object> resultList = new List <object>(); try { var options = new ProductListOptions { Active = true, }; var service = new ProductService(); StripeList <Product> products = service.List( options ); foreach (Product p in products) { var priceOptions = new PriceListOptions { Currency = "sgd", Active = true, Product = p.Id }; var priceService = new PriceService(); StripeList <Price> prices = priceService.List(priceOptions); float amount = 0.0F; string priceId = ""; foreach (Price pr in prices) { priceId = pr.Id; amount = (float)pr.UnitAmount / 100; } string id = p.Id; string name = p.Name; resultList.Add(new { id = id, priceId = priceId, name = name, amount = amount, }); } } catch { return(BadRequest()); } return(Ok(new JsonResult(resultList))); }
public ActionResult <ConfigResponse> GetConfig() { var options = new PriceListOptions { LookupKeys = new List <string> { "sample_basic", "sample_premium" } }; var service = new PriceService(); var prices = service.List(options); return(new ConfigResponse { PublishableKey = this.options.Value.PublishableKey, Prices = prices.Data }); }
public async Task <Price> GetPriceAsync(string product) { var options = new PriceListOptions { Limit = 100, Active = true, Product = product }; var service = new PriceService(); try { var prices = (await service.ListAsync(options)).OrderByDescending(p => p.UnitAmount); return(prices.FirstOrDefault()); } catch (StripeException ex) { return(null); } }
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", }, }; }