#ser
1 messages · Page 1 of 1 (latest)
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?
I haven't implemented it yet, my idea was to create only 1 product with maybe 0$ by default and then for each checkout session dynamically change the price, could that work
it's a 1 time payment for 1 product
Awesome, in that case you can just use our price_data parameter when creating the checkout session https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
I don't see the price_data param
is it a sub parameter?
session.create price is basically the product ID right?
line_items.price_data so yes it is a subparameter
Apologies my link should have linked directly to the pictured section
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
??
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',
})```
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',
})```
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
I'll have to try out, in the docs I do not see a line_items.unit_amount available
The docs that I sent show line_items.price_data.unit_amount
so the last piece of code I sent is correct?
You might benefit from using our API explorer https://stripe.com/docs?shell=true&api=true&resource=checkout sessions&action=create
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
yeah tested and it works, thanks a lot for your time and help