#pdot-price-lineitems

1 messages · Page 1 of 1 (latest)

gusty walrus
#

Can you clarify what you mean exactly? Like what is the context/which API are we talking about?

terse trail
#

Sorry, when creating a payment stripe.checkout all our payments use the following format -

#

But now wer're creating subscriptions and would like to follow the same format. Is it possible to keep the same format using a priceID

#

The main thing is to keep the metadata in the same object to avoid any complications with the frontend

gusty walrus
#

you're creating subscriptions via Checkout?

#

If so what is blocking you? Do you get an error?

terse trail
#

Yes, we're trying to do installmentsm, and the way that I was told was to first create the subscription via checkout, then call subscription schedule create to update the interations to end the subscription in 3 months.

#

just asking if its possible to use 'price': 'priceid' inside the price data > product_data?

gusty walrus
terse trail
#

I keep getting an error, but gimme a sec let me try something else

gusty walrus
#

if you can share both the exact code (not a picture) and the error, I can help!

terse trail
#

here is the error: server response: Request req_amCismPN8kBppK: Received unknown parameter: line_items[0][price_data][product_data][price]

#

and the code is: try: checkout_session = stripe.checkout.Session.create( line_items=[{ 'quantity': 1, 'price_data': { 'currency': 'usd', 'product_data': { 'price': BCMAS_SUBSCRIPTION_PRICE_ID, 'metadata': { 'productType': 'certification', } }, } }], mode='subscription', success_url=FRONT_END_DOMAIN + '/success?session_id={CHECKOUT_SESSION_ID}', cancel_url=FRONT_END_DOMAIN + '/cancel', customer_email=email ) print(checkout_session) return checkout_session except Exception as e: return str(e)

#

I don't think I can pass price: "priceID" inside the price_data obj

#

I believe stripe makes it so I can only use either price, or price_data and not combine them. I ask this question btw because of the metadata placement. I need it to be in price_data

gusty walrus
#

why do you have price inside product_data it doesn't make sense

#

either you already have a Price id and you pass price: 'price_123' or you don't and you pass price_data to create a new one inline

#

I don't understand the logic of what you are trying to do I'm sorry.

terse trail
#

that's okay I think I figured it out, I must use either price or price_data. I wanted to keep the consistency of using price_data but since we're using fixed products for the subscriptions I have to use price

gusty walrus
#

but why would you want price_data since you already have existing Prices?

#

is it just for metadata? If so you can set the metadata on the Price itself

terse trail
#

the prices are only for subscriptions, for all other products we use price_data to dynamically build products

#

wanted to use price_data for consistency, since the frontend is looking for the metadata in the price_data object in line_items

#

that's okay I think I'll have to change how the frontend reads the metadata

gusty walrus
#

oh boy

#

why would your frontend care about metadata? The front-end shouldn't even know about line items in theory

terse trail
#

The frontend only uses metadata to determine what type of product was pruchased to show specific thank you pages

gusty walrus
#

why would the front end show a thank you page?

#

the back-end is what gets the redirect or the Event checkout.session.completed. The back-end should be what decides what to display/show

terse trail
#

assume a scenario where there are two types of products, certifications, and event tickets. Upon a successful payment, how would you recommend the /success page to give next details about the user;s purchase. For example, for certification - it would say things regarding where thery can sign in, how to start the certification ext. While the event ticket purchase will show things related to when the event is, directions, ext. How woould you recommend building dynamic /success pages without knowing the productType coming from metaData?

gusty walrus
#

the success page is server-side.Your server-side code looks at the Session and its line items and decides what to do. Not the client-side

#

ultimately, you can still put metadata on the Price really it works the exact same way

#

when you pass price_data[metadata] what it does is create a Price with that metadata. When you pass price: 'price_123' it uses that specific Price and its metadata

terse trail
#

okay that sounds good, I'll approach with price and not price_data

#

sorry about the confusion, its our first week with stripe

gusty walrus
#

Totally fine, there are just a lot of APIs and ways to build your integration

#

usually metadata is a server-side concept, something only your server-side code looks up and does something with

#

As long as you make sure the client can trust the info coming from the server you should be fine overall though

terse trail
#

yeah I think I was calling the session after successful checkout and sending the whole payload to frontend and doing the manuplications there. I'll do the manipulation on backend and only send the productType to the frontend.

#

Thank you for helping avoid such a silly mistake

gusty walrus
#

No silly mistake, the whole price_data concept is quite tricky to grasp

#

I wish we documented our API patterns somewhere

terse trail
#

thanks again, have a good rest of your day

gusty walrus
#

we use the xxx_data concept in many places like payment_intent_data and subscription_data on Checkout. The idea is that what goes in that hash is the same parameters as what goes on the Create API for that other API. So in payment_intent_data you put information that would go in the https://stripe.com/docs/api/payment_intents/create API