I'm trying to retrieve the tiered pricing details from my Stripe product using the Stripe SDK. I’m passing the correct product_id and successfully retrieving a Price object that has billing_scheme = tiered.
However, the tiers field on the Price object is null, even though the price is set up with multiple tiers in the Stripe Dashboard (see attached screenshot).
My question is how can I get the tiered pricing price, the min and max seats from a given tiered price from my product?
Here's my code
fun getEnterprisePriceForSeats(seats: Int): Price {
// List all active prices for the Enterprise product
val params = PriceListParams.builder()
.setProduct(stripeEnterpriseSubscriptionProductId)
.setActive(true)
.setLimit(100)
.build()
val prices = Price.list(params).data
// Find the price whose metadata range matches the seat count
return prices.firstOrNull { price ->
val min = price.metadata["min_seats"]?.toInt() ?: 0
val max = price.metadata["max_seats"]?.toInt() ?: Int.MAX_VALUE
seats in min..max
} ?: throw IllegalArgumentException("No Enterprise price found for $seats seats")
}
You need to expand tiers
[0] when retrieving Prices to reveal the different tiered pricing (example: $39,99, $35.99, $29.55). This will return a list that contains the up_to
[1] param that you can use to determine the min and max price.
Based on the code snippet, you can add `addExpand("data.tiers")
under PriceListParams.builder()
[0] https://docs.stripe.com/api/prices/object#price_object-tiers
[1] https://docs.stripe.com/api/prices/object#price_object-tiers-up_to