#brkbrkn
1 messages · Page 1 of 1 (latest)
It is expected for the webhook event itself to not have the items. If you retrieve the Checkout Session with the API they should show up again
sorry i dont understand. i am new to stripe. i create checkout session with /checkoutNewProduct endpoint and my webhook send data to /buyCreditWebhook endpoint. can you please review my full code and say what i should change ? my full code : https://codeshare.io/ZJV6PV
Basically this line is expected not to work
$line_items = $session->line_items->data;
You can't get the line items from the version of the session object that is in the webhook event
So you need to make this retreive call with the Id of the checkout session from that event https://stripe.com/docs/api/checkout/sessions/retrieve
What the API returns will have those line items
where can i get checkout session id ?
and where should i add this code ? /buycreditwebhook or /checkoutNewProduct ?
👋 stepping in
We can't review full code for you
Have you tried to test your code?
Are you hitting an error?
Or we can help unblock you if you have a specific question.
But there are many folks we help on this server so we can't go through your code line by line
webhook does not give me the id of the checkout session. How can I access this information?
It does if you listen for checkout.session.completed
Have you taken a look at https://stripe.com/docs/payments/checkout/fulfill-orders ?
This walks you through how to use Webhooks with Checkout
$session = \Stripe\Checkout\Session::retrieve([
'id' => $event->data->object->id,
'expand' => ['line_items'],
]);
i already used retrieve and fulfill orders.
still same. i tried million of different variations but still same. still i cant see my data.
Okay so have you logged out the id there?
Like are you sure that you are receiving the $event to begin with?
$event->data->object->id returns cs_test_a1kK4QEyXxbgEgs6R9MIvxOcgpSXjDdYc5hCTuQFtBRjFQxbtjZKx6Yd98
$line_items = $session->line_items->data;
$session_id = $event->data->object->id;
// Fulfill the purchase...
foreach($line_items as $line_item){
// Get the product name and price from the line item
$product_name = $line_item->price_data->product_data->name;
$product_price = $line_item->price_data->unit_amount;
$user_domain = $line_item->price_data->product_data->metadata->userDomain;
mail("fredilihre@gmail.com","stripe success",$user_domain . " is the domainname and line items are : " . $line_item);
here is email i got : https://prnt.sc/ZGbJGPUS6Dop
Okay that looks good then. That is giving you the line item information which is what the code above does.
no
i want domainname but return space
here is my own line_items: https://prnt.sc/crzfdKnH3Ek-
Sorry I don't understand what you mean by this? Can you clarify?
please look at my own line_items
Ah
there is userDomain
You want the $user_domain which is in your metadata
yes
Gotcha okay yeah that won't be returned here. The reason is because you are setting it as metadata within your product_data. This creates a new product and the price is associated with the product but we only return the price within the Checkout Sessions line items.