#rdhp

1 messages · Page 1 of 1 (latest)

jolly badgerBOT
soft heart
#

Hi, do you have a question?

steady junco
#

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)
soft heart
#

Is there a question there? I'm not sure what to do with this information

steady junco
#

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?

soft heart
steady junco
#

so instead of use the key "price" I can use "price_data"?

soft heart
#

Yup, you define the Price attributes in-line during the Checkout Session creation

steady junco
#

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

soft heart
#

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

steady junco
#

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)?

soft heart
#

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

steady junco
#

Ok I did it man, thank you for your help. Have a nice day and a good work!