#brian_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1347068701048045650
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
export async function getStripeProducts() {
// Fetch all products that are active
const products = await stripe.products.list({
active: true,
expand: ["data.default_price"],
})
// Format the products with their prices
return products.data.map((product) => {
const price = product.default_price as any
console.log('product data', product)
return {
id: product.id,
name: product.name,
description: product.description,
priceId: 0,
price: 300,
currency: 'usd',
features: product.features?.map((feature) => feature.name) || [],
}
})
}
full product mapping function
Looks like you hardcoded the priceId to 0, is this intentional ?
Also, a product can exist without a default_price
intentional for that example as it was even erroring out trying to fetch the default price
Have you set a default_price to that product?
maybe I was misusing prices? I assumed doing:
{
name: "Enterprise Tier",
description: "Custom API usage limits",
price: 19999, // $199.99
metadata: {
features: JSON.stringify([
"Custom API usage limits",
"Dedicated support",
"Custom rate limits",
"SLA guarantees",
]),
},
lookup_key: "api-usage-enterprise",
},```
and referencing pricing here would have set the product price, given we alias the lookup key as well
OK, looks like you haven't set a default_price yet
hm what's the difference between a regular price and default price?
If you want to retrieve prices, you should use the List prices API https://docs.stripe.com/api/prices/list
In another word, you can retrieve product from price, not price from product, unless the product has a default_price
ah makes sense, my other question related to this as well, how can I do a hybrid billed item?
i.e base subscription being $10.99/month, but then charge an add-on price for certain modules, or perhaps even a usage fee if you go over a certain meter'd value?
would I have to combine multiple subscriptions, separately
You mean combining multiple prices (per-seat, metered-based) in one subscription? Yes that's totally possible as long as these prices have the same recurring interval
yeah, we want a base subscription cost, and then additional cost for metered usage and or per-seat