#ser

1 messages · Page 1 of 1 (latest)

sudden cragBOT
loud viper
#

What are you using to charge here: Checkout? Subscriptions or Invoices?

#

We don't have a way to update price objects but for each of those we support "ad hoc" prices which is where you pass in the product ID but then pass in amount dynamically to the subscription/invoice/checkout session and we create a one-off price object for it

#

Does that sound like it may help in your situation?

vague quail
#

it's a 1 time payment for 1 product

loud viper
#

You don't even need a price defined before. Just the product, pass in its ID and the other required fields and we'll create a Price object automatically at that price

vague quail
#

I don't see the price_data param

#

is it a sub parameter?

#

session.create price is basically the product ID right?

loud viper
#

line_items.price_data so yes it is a subparameter

#

Apologies my link should have linked directly to the pictured section

vague quail
#
const session = await stripe.checkout.sessions.create({
  success_url: 'https://example.com/success',
  line_items: [{
      price: 'price_H5ggYwtDq4fbrJ', // the product without a price
      quantity: 1,
      price_data: {
        currency: 'usd',
        unit_amount: 500, // 5$ in cents to charge.
      }
}],
  mode: 'payment',
})```
#

would look something like this

#

??

loud viper
#

No, that is a price ID. It would look something more like:

const session = await stripe.checkout.sessions.create({
  success_url: 'https://example.com/success',
  line_items: [{
      price_date: {
        product: 'prod_123'
        unit_amount:  500,
        currency: 'usd'
      }
      quantity: 1,
      currency: 'usd',
      unit_amount: 500, // 5$ in cents to charge.
}],
  mode: 'payment',
})```
vague quail
#

the price written 2 times? and also the currency?

#
const session = await stripe.checkout.sessions.create({
  success_url: 'https://example.com/success',
  line_items: [{
      price_data: {
        product: 'prod_123'
        unit_amount:  500,  // 5$ in cents
        currency: 'usd'
      }
      quantity: 1,
}],
  mode: 'payment',
})```
loud viper
#

Products and prices are separate objects

#

Products have an ID that start with prod_ and prices have IDs starting with price_

#

Products have related prices but these objects are not interchangable

sudden cragBOT
vague quail
#

I'll have to try out, in the docs I do not see a line_items.unit_amount available

loud viper
#

The docs that I sent show line_items.price_data.unit_amount

vague quail
#

so the last piece of code I sent is correct?

loud viper
#

Unit amount is in the price data hash in the code that you sent. That is accurate as far as I know

#

But basically on that page you can build your request then select "Node" and click "Print SDK Code" to the left of the run request button

vague quail