#Reitrac
1 messages · Page 1 of 1 (latest)
You can retrieve the checkout session
That info is within price: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i have my checkout session ID and i need to get product name and price to sync information to my wordpress
Yeah you can use the above api request
how ? i dont understand this doc :/
Are you a developer?
Oh ok. You can use our stripe php library: https://github.com/stripe/stripe-php. Then make an api call to retrieve the checkout session by id: https://stripe.com/docs/api/checkout/sessions/retrieve?lang=php. Then, on the object that's returned, you can look at price data: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i already have this, i created webhook, etc.. everything works. Now, i need to get informations after payments to sync with my database
What webhook event are you listening to?
What events specifically?
i dont know, as i said, i just need to get product name and amount to sync with my database
I showed you how. But you told me you wanted to do it from webhooks, so I need to know what events you are listening for to help you. From the checkout session object, it's in the price data: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price. Only thing to note is you'll have to retrieve the product based on the product id to get more data on the product: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product. You can retrieve with this api call: https://stripe.com/docs/api/products/retrieve
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i'm lost :/
yes
i have a webhook.php file and it works cause i wrote in my database after payment
Ok. What events are you listening to in that code?
Here is my file
On my dashboard, when i created my wbehook, i add "checkout" and checked all
These are the events you are handling in your code:
switch ($event->type) {
case 'checkout.session.async_payment_failed':
$session = $event->data->object;
$sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', 'Echoué')";
$conn->exec($sql);
break;
case 'checkout.session.async_payment_succeeded':
$session = $event->data->object;
$sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', 'Réussi')";
$conn->exec($sql);
break;
case 'checkout.session.completed':
$session = $event->data->object;
$sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', '".$session."')";
$conn->exec($sql);
break;
case 'checkout.session.expired':
$session = $event->data->object;
$sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', 'Expiré')";
$conn->exec($sql);
break;
// ... handle other event types
default:
echo 'Received unknown event type ' . $event->type;
}```
Within checkout.session.completed, you can get the checkout session object (that's the $session variable you created)
That object has price data: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Right, so you do this step I outlined above:
Only thing to note is you'll have to retrieve the product based on the product id to get more data on the product: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product. You can retrieve with this api call: https://stripe.com/docs/api/products/retrieve
So you grab the product id on that object
Then you have to make an api call to get the product name
i have no product ID
StripeCheckoutSession JSON: { "id": "cs_test_a1YG63LWYc4ocr5ooJkq8LWF0WoC5NNYDmeDspQaq4rwAyCJBVcejQXzzM", "object": "checkout.session", "after_expiration": null, "allow_promotion_codes": null, "amount_subtotal": 3500, "amount_total
This is wat $session return
That's only a small part
What does the whole object look like
Product is here: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
but i have no product ID, so how can i get it ?
the only thing i have is price and session ID
What's the checkout session id?
Oh I see
One sec
I see product on the object
What does the rest of $session look like?
You only shared part
No you only shared:
"id": "cs_test_a1YG63LWYc4ocr5ooJkq8LWF0WoC5NNYDmeDspQaq4rwAyCJBVcejQXzzM",
"object": "checkout.session",
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 3500,
"amount_total```
There's more to the object
You can tell it's an incomplete json object because there's no close }
You stored the incomplete object then
Do you have a character count restriction in that database column?
I also don't recommend storing the whole object
Just store the values that you need
But anyway, we're getting away from the issue here
Don't look at what you stored in the database here. Within your code in that case 'checkout.session.completed': $session = $event->data->object; $sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', '".$session."')"; $conn->exec($sql); break; block, you can get the product id from the $session variable