#brkbrkn

1 messages · Page 1 of 1 (latest)

short moonBOT
eternal elbow
#

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

boreal nimbus
#

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

eternal elbow
#

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

#

What the API returns will have those line items

boreal nimbus
#

where can i get checkout session id ?

#

and where should i add this code ? /buycreditwebhook or /checkoutNewProduct ?

gaunt shell
#

👋 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

boreal nimbus
#

webhook does not give me the id of the checkout session. How can I access this information?

gaunt shell
#

It does if you listen for checkout.session.completed

#

This walks you through how to use Webhooks with Checkout

boreal nimbus
#

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

gaunt shell
#

Okay so have you logged out the id there?

#

Like are you sure that you are receiving the $event to begin with?

boreal nimbus
#

$event->data->object->id returns cs_test_a1kK4QEyXxbgEgs6R9MIvxOcgpSXjDdYc5hCTuQFtBRjFQxbtjZKx6Yd98

gaunt shell
#

Okay so that looks good

#

So when you log $session there is nothing?

boreal nimbus
#

$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);
gaunt shell
#

Okay that looks good then. That is giving you the line item information which is what the code above does.

boreal nimbus
#

no

#

i want domainname but return space

gaunt shell
boreal nimbus
#

please look at my own line_items

gaunt shell
#

Ah

boreal nimbus
#

there is userDomain

gaunt shell
#

You want the $user_domain which is in your metadata

boreal nimbus
#

yes

gaunt shell
#

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.