#matrix - Notifications
1 messages · Page 1 of 1 (latest)
Hello
Hello! Can you provide more details? How are you using Stripe? How do you want to be notified?
I have a checkout session for a single product and the product is associated to a price. I would like to use webhook and I see that there is a checkout.session.completed object but it does not include the reference to the product or the price
is there an event i can listen that tell me a certain product was purchased?
You're listening for the right event, but once you receive the event you need to fetch the Checkout Session from the API with the line_items expanded: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
Yep, we have a snippet here: https://stripe.com/docs/api/checkout/sessions/retrieve?lang=node
You would do that and add the expansion info.
It would look something like this:
const session = await stripe.checkout.sessions.retrieve('cs_test_123', {
expand: [
'line_items'
],
});
great thanks
@mental turtle is it correct to say that if i want to print the product in my console i just need to write console.log(‘product ID = ', session.line_items.data[0].price.product); ?
I only have one product in my checkout
Yeah, I think that will work. Have you tried it?
will do
thanks
i get an error
Invalid checkout.session id: cs_test_xxx
do i need to autenticate in some way? i am using connect direct charge
Sounds like the Checkout Session ID you provided isn't correct. Are you using the correct API key?
Oh, so this is for a Checkout Session that exists on a connected account?
yes
You need to make the API call for the connected account: https://stripe.com/docs/connect/authentication
I managed to get it work with this
const session = await stripe.checkout.sessions.retrieve(dataObject.id, { expand: [ 'line_items' ], stripeAccount: event.account, });
however i see this warning in my console
(node:1) Stripe: Options found in arguments (stripeAccount). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.
(Use node --trace-warnings ... to show where the warning was created)
(node:1) Stripe: Invalid options found (expand); ignoring.
Yeah, the stripeAccount value should be in a separate object supplied as the third argument.
Like this:
const session = await stripe.checkout.sessions.retrieve(dataObject.id, {
expand: [
'line_items'
],
}, {
stripeAccount: event.account,
});