#brian_code

1 messages ¡ Page 1 of 1 (latest)

spark karmaBOT
#

👋 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.

small iris
#
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

inland bridge
#

Looks like you hardcoded the priceId to 0, is this intentional ?

#

Also, a product can exist without a default_price

small iris
#

intentional for that example as it was even erroring out trying to fetch the default price

inland bridge
#

Have you set a default_price to that product?

small iris
#

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
inland bridge
#

OK, looks like you haven't set a default_price yet

small iris
#

hm what's the difference between a regular price and default price?

inland bridge
#

In another word, you can retrieve product from price, not price from product, unless the product has a default_price

small iris
#

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

inland bridge
#

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

small iris
#

yeah, we want a base subscription cost, and then additional cost for metered usage and or per-seat

spark karmaBOT