#brkbrkn-checkout-lineitems

1 messages · Page 1 of 1 (latest)

toxic fjordBOT
odd ridge
real sun
#

Was just about to ask if you were hitting errors

#

At first glance, the code looks fine

odd ridge
#

it return null

real sun
#

So let's see...

odd ridge
#

it should return checkout url

#

if i use first code it return checkout url but not add my own data

real sun
#

What do you mean it returns null?

#

What is null?

odd ridge
#

if i use second code it return nothing , just blank

real sun
#

Do you have an example request you can share?

odd ridge
#

first code return this

#

second code return ""

real sun
#

I note you're setting metadata two different ways

#

Can you share the request id?

odd ridge
#

i need to add my own metadata

real sun
#

Or that session ID from the image above

#

cs_test_123

odd ridge
#

cs_test_a1tLGmZZLjDe2dghZjuDbdqsXtVkS9P5sgNxsS2VaCGcNFD9yEXd9dX4TQ

real sun
#

Thanks

#

The product_data metadata is coming through, but the price metadata is not

#

This field is not included by default. To include it in the response, expand the line_items field.

odd ridge
#

i already expanded

real sun
#

I do not see the expand parameter in your request above

odd ridge
#

$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.

real sun
#

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

odd ridge
#

ok

#

i just changed line_items to different thing and i will look at what it return

real sun
#

that i expect to return an error as an invalid attribute for expansion

odd ridge
#

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

real sun
#

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

odd ridge
#

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.

real sun
#

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

odd ridge
#

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.

real sun
#

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

odd ridge
#

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.

real sun
#

Can you share an example retrieve request ID you make there?

#

And the payload you get back?

#

That should include line items

odd ridge
#

'id' => $event->data->object->id,
do you want to this id ?

real sun
#

I'm not seeing any new retrieve/get requests in your logs

odd ridge
#

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'],
]);

real sun
#

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

odd ridge
#

req_CTipoqdHUaDBln

real sun
#

Thanks

#

Ok, thats a customer creation request

#

Not a Checkout session retrieval

odd ridge
#

yes of course customer.

#

customer will pay

#

not me

#

so customer should create checkout url according to their domain name price and product name

real sun
#

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

odd ridge
#

I messed up more while trying to fix the codes. Can't even send email right now.

real sun
#

What does the customer create request have to do with this?

odd ridge
#

customer

#

will pay

#

for exampğle

real sun
#

Sure, yes

odd ridge
#

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.

real sun
#

Yea thats fine

odd ridge
#

i dont know how can i explain more clear

#

If you examine my codes in detail, you will understand what I want to do.

real sun
#

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

odd ridge
#

req_T7af6DLmAGciym

#

code side

real sun
#

Again, this is a customer create request

#

YOu can inspect it there

odd ridge
#

not customer

real sun
#

Are you expecting this to be a checkout session retrieval or creation?

odd ridge
#

$app->post('/buyCreditWebhook', function (Request $request, Response $response) use ($stripe) {

#

this is under webbook endpoint

#

webhook*

real sun
#

I have no idea what that does, thats your own endpoint

real sun
#

You can see it is a post request to /customers. -- this is a customer create request

odd ridge
#

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

real sun
#

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

#

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?

covert orchid
#

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?

odd ridge
#

i am not successfully get my datas

#

for example

#

i sent userDomain data

#

but there is no userDomain data in webhook response.

covert orchid
#

I think you need to expand the Product, too, since you put the metadata in the product_data

expand=line_items.data.price.product

odd ridge
#

this is the code

#

please just fix it and send it back. dont send me any documentation link. bcs i dont understand

surreal cave
#

@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.

odd ridge
#

OK...

#

wait

#

i will try

#

dont close

surreal cave
#

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.

odd ridge
#

i already retrieve

#

as i said multiple times before

#

but still i cant reveice line_items

#

receive

covert orchid
#

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

odd ridge
#

ok

#

i will change my code to expand=line_items.data.price.product

surreal cave
#

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?

odd ridge
#

i am trying now

surreal cave
#

perfect, keep me posted as you go

#

@odd ridge any progress? Have you been able to run my basic example?

odd ridge
#

it works

#

finally

#

thank you!

surreal cave
#

Amazing! Do you have any follow up question?