#jay492
1 messages ยท Page 1 of 1 (latest)
Hi ๐ what help are you looking for?
hi so this is the code that i have in the webhook in the server.js
i want to store the customer information in database so that user can open their unique create-portal-session page
when i try the code and added the payment method, it looked like this
Sorry, I'm not sure I'm grasping what the question is. I'm a little surprised the retrieve request isn't erroring since you seem to be passing it an entire object rather than an ID as it's expecting.
so
i want user to open their unique create-portal-session page. To do that i think i need to store customer Id when an user do a create-checkout-session. In the webhook, how can i extract the user's id? (i don't need any help to pass it to database, just need with how to get the customer id in Stripe)
It's in the customer field on the Checkout Session:
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-customer
so it should already be in the Event body that you received at event.data.object.customer. Are you seeing something different when you log out the contents of the Event you're receiving?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
no
Are you seeing something different when you log out the contents of the Event you're receiving? what do you mean by this?
You shared a snippet of a code that belongs to an Event handler on your webhook endpoint. Have you tried logging out the full contents of the Event object that your code is receiving? Something like console.log(event)
yep
that is this
Okay, and do you see a customer field there? The screenshot is too cropped to see the full contents.
There is more to that object than that, I'm not sure why you aren't seeing it all in your console.
Oh, the top lines say you're only seeing the last 15 lines of your log, so you're not seeing the whole object.
oh that might be
There should be a customer field in that object that contains the ID of the related Customer object, as long as there is a Customer associated with the Checkout Session.
apparently,
when i added the payment method, it will not show anything even i'm trying to print some stuff with this code case event.type == 'checkout.session.completed':
console.log("iminthecompleted")
// Retrieve the session. If you require line items in the response, you may include them by expanding line_items.
const sessionWithLineItems = await stripe.checkout.sessions.retrieve(
event.data.object
);
customerId = sessionWithLineItems.customer;
console.log("this is a custmerId ", customerId);
Sorry, I'm having a hard time parsing what you're trying to convey. Are you saying console.log lines don't seem to be triggering at all? If so, I would recommend adding additional logging to your endpoint so you can debug why it isn't hitting those lines.
i will try that. coz the code below should get executed once user create checkout-session right?
also const sessionWithLineItems = await stripe.checkout.sessions.retrieve(
event.data.object
);
customerId = sessionWithLineItems.customer; storing customer will be the best option to make a unique create-portal session page for every user?
That Event does not get generated when a checkout session is created, it's triggered when the customer completes the checkout process.
If you want to create new payments or Checkout Sessions for a specific Customer, then yes you will likely want to log the Customer's ID. You don't need to retrieve the Checkout Session though, it's already provided in the body of the Event that your endpoint receives.