#Vish-Checkout

1 messages · Page 1 of 1 (latest)

peak rose
#

Hi, have you look at the webhook event checkout.session.completed? It should have all the information of the paid Checkout Session

wraith pendant
#

That is not the issue. I am using that in the second step.

#

The problem is how to correspond line items between first and second step.

#

Let me explain with an example.

#

There are 3 line items and I have to create 3 records for these 3 line items in my database. Lets say the information I need to save for these 3 line items are a,b,c

#

Here is what the database looks like

peak rose
#

In first step you have the Checkout Session Id, correct?

#

the cs_test_xxx or cs_live_xxx value

wraith pendant
#

After creating I get it yes

#

But that does not really help

#

How do I correspond the line items in the session to the records in my database

#

?

peak rose
#

Can you continue with your database structure?

#

the part from a,b,c

wraith pendant
#

so in the database it looks something like this

#

id1 - a
id2 - b
id3- c

#

The ids above are not stripe ids

#

These are ids I have created

#

Now There are 3 line items in the session

#

lets call them A, B, C

#

I need some infor from Line item A and save it in the first record

#

so after successful session the database should look something like this

#

id1 - a - A.1
id2 - b - B.1
id3- c - C.1

#

How do I do that?

#

A.1 is lets say the quantity in that line item

#

does it make sense?

#

This could have been solved if I was allowed to save metadata on the line item. The I could save id1 as metadata on first line item but it seems that is not possible

peak rose
#

I am trying to grasp the issue. In step 1 after you created the Session, you have the session id (cs_test_xxx), and you have 3 line_items id (Stripe id). How about saving those into your database right after step 1 finished?

wraith pendant
#

ok but how do I know which line item in Step 1 corresponds to which record in my database?

#

Will they be in the same order as I added them in the session object?

#

I know this is a difficult scenario to understand(or maybe I am not doing a very good job explaining it) so let me know if something does not make sense

peak rose
#

When you create the line items in step 1, did you create it directly?

wraith pendant
#

I use await stripe.checkout.sessions.create

#

and the line_items are in the session object as follows

#

line_items: [{price: priceId1, quantity: 1}, {priceId2, quantity: 2}]

peak rose
#

If you delay creating record in your database until this time, then you should have this line_item.id to insert to your database in the first place

wraith pendant
#

I get that part, and I can do this, but how do I know which line item corresponds to which line item I inserted?

#

Are they in the same order?

#

In the above example:
line_items: [{price: priceId1, quantity: 1}, {priceId2, quantity: 2}]

#

Lets say for first line item, I need to save 'a' in the database, and for second line item, I need to save 'b' in the database

#

And when I get the line items after creating it will the order remain the same?

#

If the order remains the then I can say that first line item corresponds to the record that contains 'a' in database

#

Makes sense?

peak rose
#

In this particular example you have different priceID and quantity, so it's distinguishable isn't it? Otherwise if you have 1 line item with exactly same priceId and quantity, it doesn't make sense to distinguish them at all, since they are just 2 objects created using same information

wraith pendant
#

They can be the same price id and quantity also

peak rose
#

Sorry if I am missing smth, but my understanding is that - creating the Checkout Session with Stripe first - then based on Stripe response, start to save everything you need to your database

wraith pendant
#

It can be this as well
line_items: [{price: priceId1, quantity: 1}, {priceId1, quantity: 1}]

#

what would you do in this case?

peak rose
#

Then why would you need to save 'a' for one item and 'b' for another? Aren't they the same?

wraith pendant
#

No they will not be. To give you an example, lets say they both are shirts and cost the same so only one product exists on Stripe. But users can choose which color they want it in

#

So the first color is blue and second color is yellow

#

I need to save blue and yellow in the database

peak rose
#

Then you need 2 separated Product (different id) to represent blue and yellow

wraith pendant
#

But I dont want to do that. I will have to create 100s of products

#

Can I assume that order of the line items will remain the same?

peak rose
#

I think it's the same, but we don't (officially) guarantee it, so I can't recommend that approach

#

My understanding is you can have as many products as possible. If you don't want to pre-create Product, you can create them on-the-fly with Checkout Session by using this parameter: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data-metadata

#

That each time creating Checkout you will have a new Product, with metadata, or description, corresponding to the order

wraith pendant
#

Unfortunately creating multiple products is not an option for me. So there is no othwe way?

peak rose
#

Unfortunately that's all I can offer. I would take this as feedback to Checkout team, but sorry, nothing else jump up

wraith pendant
#

Another issue I found is that only 10 line items are returned when line_items is expanded in session. Is there a way to get all line items?

peak rose
wraith pendant
#

Can you please check from someone in your team(maybe the checkout team) if the order is maintained? If it is them my problem is solved.

peak rose
#

It would takes time since they are in US timezone. And ultimately I discourage that approach. What if we changed the order in the future? Or it bugged somewhere. It's not a guaranteed thing in the Doc so when it change it could break your business and cost you a lot of effort to clean up later on

#

If it's on the Doc then we would be responsible to make sure it follow the Spec

wraith pendant
#

Alright thanks

peak rose
#

I will feedback to the team! Essentially having description or metadata on creation for each line_item would solve your problem, correct?

wraith pendant
#

Yes

#

There is no way to get line item id before creating session right? or assign custom line item id?

peak rose
#

No

wraith pendant
#

Agghhh....its so frustrating. The reason we cannot use multiple products is because we are creating a shop for jerseys.

peak rose
wraith pendant
#

In jerseys they can have their name at the back as well....so its not only a blue yellow problem