#brkbrkn-checkout-lineitems
1 messages · Page 1 of 1 (latest)
i tried this one but got error : https://codeshare.io/EBNneN
it return null
So let's see...
it should return checkout url
if i use first code it return checkout url but not add my own data
if i use second code it return nothing , just blank
Do you have an example request you can share?
https://stripe.com/docs/api/request_ids / req_123
i need to add my own metadata
cs_test_a1tLGmZZLjDe2dghZjuDbdqsXtVkS9P5sgNxsS2VaCGcNFD9yEXd9dX4TQ
Thanks
Here's the request you can look at: https://dashboard.stripe.com/test/logs/req_cE9N5NiFCIM7r3
The product_data metadata is coming through, but the price metadata is not
If you're expecting to see the line items in the result, you need to use expansion to include that:
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
This field is not included by default. To include it in the response, expand the line_items field.
i already expanded
I do not see the expand parameter in your request above
you did not expand in this request
https://stripe.com/docs/expand for examples
$session = \Stripe\Checkout\Session::retrieve([
'id' => $event->data->object->id,
'expand' => ['line_items'],
]);
i use this code
I wrote to help 3 times today. everyone says something different. I do and still get the error. please fix my code. Do not direct me anywhere.
https://codeshare.io/3A6791 my full code
While this request included expansion: https://dashboard.stripe.com/test/logs/req_o0R28pr3lGFrlD
The most recent one did not: https://dashboard.stripe.com/test/logs/req_ukTIFNJz6Q9bQo
Can you try another such GET/retrieve, share the request ID and the payload you receive back?
If you include that expansion, you should see the line items in the result
that i expect to return an error as an invalid attribute for expansion
You should look at your dashboard logs to se what Stripe received: https://dashboard.stripe.com/test/logs/
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
when webhook triggered it send this data
i dont see anything about my data userDomain
i dont understand anything. I did a million different things today and I'm so confused. Everyone says look over there and I try different things. the result does not change.
i think problem is in here :
i sent data in wrong way. i should change path. but i dont know how. so please edit my code
webhook payloads never include expansion
you need to explicitly retrieve the object to get includable/expandable fields
Are you getting the line items expanded in your create request responses? What about the retrievals with expansion.
It's expected that you do not get this in the webhook notifications
i dont know how can i do that
One of your team recommended this method to me. I didn't do it by myself
now you say that this method is wrong. I am very confused.
It's not wrong, i'm just unclear what you want
where do you want to get the line_items?
You can add expand to your create request, for example, if you want it there
If you want to get them following the session complete event, you need to retrieve the session and include expand there
When the customer successfully pays, I want to increase the customer's credit. For example, if he took 1000 credits, he should increase by 1000 credits. for this I need data like productname, productprice and userdomain. I am sending this information as meta data when creating checkout. On the other hand, I want to receive the incoming information from the webhook and send an e-mail and increase the credit over the database accordingly. I hope it was clear.
receive the incoming information from the webhook
ok, in that case, you need to grab the session id from the webhook data
do a retrieval with expansion there
then look at the line_items in the GET response
in this code, if checkout.session.completed ,
get id :
'id' => $event->data->object->id,
expand (line_items) :
'expand' => ['line_items'],
and and mail all the data sent by the webhook (for testing) :
mail("fredilihre@gmail.com","stripe success",$user_domain . " is the domainname and line items are : " . $session);
and i see that all data sent by webhook doesnt include my datas.
Can you share an example retrieve request ID you make there?
And the payload you get back?
That should include line items
'id' => $event->data->object->id,
do you want to this id ?
No, a request ID like req_123: https://stripe.com/docs/api/request_ids
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
I'm not seeing any new retrieve/get requests in your logs
i dont know why
you can review my code. i use retrieve :
$session = \Stripe\Checkout\Session::retrieve([
'id' => $event->data->object->id,
'expand' => ['line_items'],
]);
Yes, but I am telling you i do not see you making these requests, so I am asking you to show me an example request
And the payload you receive back
req_CTipoqdHUaDBln
yes of course customer.
customer will pay
not me
so customer should create checkout url according to their domain name price and product name
Sorry, I'm confused. You are creating the checkout sessions, you showed me code for that, and retrieving them.
And yu wanted to get some data from the line items there
I messed up more while trying to fix the codes. Can't even send email right now.
What does the customer create request have to do with this?
Sure, yes
he will buy 100 credits. it cost 10$ (not real price). customer will send request for checkout url. but he send their data(user domain, price and product name) then i will redirect customer to checkout url. after successfully payment, i use customer datas to add credits.
Yea thats fine
i dont know how can i explain more clear
If you examine my codes in detail, you will understand what I want to do.
you want to:
1/ create that checkout session, then redirect the customer to pay
2/ customer pays
3/ you get the checkout session completed webhook notification
4/ you retrieve that session with line items expanded to get the details you need to update your database
you have not shown me an example of making that request in step 4
not customer
Are you expecting this to be a checkout session retrieval or creation?
$app->post('/buyCreditWebhook', function (Request $request, Response $response) use ($stripe) {
this is under webbook endpoint
webhook*
I have no idea what that does, thats your own endpoint
Did you look at this in your dashboard?
You can see it is a post request to /customers. -- this is a customer create request
4/ you retrieve that session with line items expanded to get the details you need to update your database
you have not shown me an example of making that request in step 4
this request occurred on a bottom line of the database update. I pasted the code below to get the req id:
$reqid = $customer->getLastResponse()->headers["Request-Id"];
mail("fredilihre@gmail.com","stripe req","req : " . $reqid );
Ok, but can you show me this request actually happening?
$reqid = $customer->getLastResponse()
That looks like your customer create request
You probably want to change that to $session
Ok, there is that request: https://dashboard.stripe.com/test/logs/req_oj7BocApdJMexR
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
It looks like you are indeed sending the expand parameter, so what are you seeing in the response data?
If you log out $session -> line_items what do you see there?
response data
Hi there 👋 taking over, as my colleague needs to step away
Give me a few minutes to get caught up.
brkbrkn-checkout-lineitems
It looks like you're successfully getting a Checkout Session's line_items. Is there an outstanding question here that I can help with?
i am not successfully get my datas
for example
i sent userDomain data
but there is no userDomain data in webhook response.
I think you need to expand the Product, too, since you put the metadata in the product_data
expand=line_items.data.price.product
this is the code
please just fix it and send it back. dont send me any documentation link. bcs i dont understand
@odd ridge you can hire a freelancer and pay them to build your integration as you need.
We can't write the code for you just because you don't understand/don't want to.
My colleagues have explained this multiple times before. When you receive an Event on your webhook handler it happens async separately from the creation and the code you sent a picture for. It's completely orthogonal/separate.
The Event will never have line items details at all. This is just impossible.
What you need to do is change your code for the webhook handler, the part that gets checkout.session.completed and at that point you need to use our API, specifically the Retrieve Checkout Session API, to get the line items and any additional information. This would not be where you call ->create(), it'd be in your webhook handler.
Discord is busy with lots of other people to help. We might close the thread. You can always ask in #dev-help if you have a follow up question with a clear summary and exact code. Please share real code, not a picture of code.
i already retrieve
as i said multiple times before
but still i cant reveice line_items
receive
That screenshot is not helpful. That's your webhook endpoint. Your retrieve call from earlier needs to include the line below. There is no way for us to make this any clearer
expand=line_items.data.price.product
Wait. You're totally lost. So ignore webhooks for now
Just write a simple script that will retrieve the Session, expand line items, output line items on your page and prove it works
Once that works you can figure out the webhook part. But clearly you're lost and frustrated and webhook testing is a lot harder
and please stop sending pictures of code. We can't copy-paste from it to show you anything
$session = \Stripe\Checkout\Session::retrieve([
'id' => 'cs_test_123',
'expand' => ['line_items.data.price.product'],
]);
$sessionId = $session->id;
$nbLineItems = count($session->line_items->data);
$firstLineItemProductMetadata = $session->line_items->data[0]->price->product->metadata;
echo "id: $sessionId - nbLineItems: $nbLineItems - metadata: <br>";
var_dump($firstLineItemProductMetadata);
basic example
@odd ridge does ^ make sense?
i am trying now
perfect, keep me posted as you go
@odd ridge any progress? Have you been able to run my basic example?
Amazing! Do you have any follow up question?