#rdhp
1 messages · Page 1 of 1 (latest)
Hi, do you have a question?
Yes I'm creating a checkout session
and my price actually is dynamic, I don't have a fixed price
price = price_generator(duration) * 100
# Crea un nuovo pagamento utilizzando la libreria Stripe
payment_intent = stripe.PaymentIntent.create(amount=price,currency='eur')
cancel_url = 'https://localhost:4200/cancel'
success_url = 'https://localhost:4200/success?voucher=' + upload_key
# Genera l'URL di checkout di Stripe
checkout_session = stripe.checkout.Session.create(payment_method_types=['card'],
line_items=[{
'price': price,
'quantity': 1,
}],
success_url=success_url,cancel_url=cancel_url)
Is there a question there? I'm not sure what to do with this information
Yes in the error that stripe give me
"The price parameter should be the ID of a price object, rather than the literal numerical price."
stripe ask for a product id, but actually I dont have a product id
what I should do to create a checkout session with a dynamic price?
You create a new Price and Product in-line when you create the Checkout Session using 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.
so instead of use the key "price" I can use "price_data"?
Yup, you define the Price attributes in-line during the Checkout Session creation
Ok thank you dude, but all the time stripe will add this product into my Dashboard? Cuz I don't need that
like in a sort of table with all products that i sold
Correct. If you want to define a static list of Prices and Products, then you need to create them ahead of time and use the Price ID when creating the Checkout Session
So your code would look something like:
` checkout_session = stripe.checkout.Session.create(payment_method_types=['card'],
line_items=[{
'price': "price_abc123",
'quantity': 1,
}],
success_url=success_url,cancel_url=cancel_url)`
where price is the ID of the Price object you created ahead of time
thanks! I did it. Another question. I'm using Angular, what I should do with my checkout url? I have just to open in another window like with window.open(CHECKOUT_URL)?
Yup, or you can redirect to it. The only thing you can't do as far as I know is render it in an i-frame
Ok I did it man, thank you for your help. Have a nice day and a good work!