#nikoschns_best-practices
1 messages · Page 1 of 1 (latest)
👋 Welcome to your new thread!
⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1458458495811588218
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- nikoschns_docs, 20 hours ago, 7 messages
- nikoschns_error, 1 day ago, 13 messages
👋 Just so I'm clear, you want to get the relevant Payment Intent object from the invoice.finalized webhook payload, so that you can add metadata to it?
@mossy rampart Webhook payloads never include expanded properties, so you will need to retrieve the invoice object when you get invoice.finalized (or whatever invoice events you need) and in that retrieval you can expand the payments to get the list of invoice payments. Once you extract payment intent IDs from there you can update the payment intent metadata as you see fit.
So what you are saying is that the invoice I get from the webhook invoice.finalized event does not contain the expand properties and hence I have to retrieve it like: const invoice = await stripe.invoices.retrieve(<invoice id>);
yes exactly, with the expansion added in the retrieve() options
const invoice = await stripe.invoices.retrieve(<invoice id>, { expand: ['payments'] });
https://docs.stripe.com/expand?lang=node#multiple-properties
That's very interesting. I will give it a try
You can’t receive webhook events with properties auto-expanded. Objects sent in events are always in their minimal form. To access nested values in expandable properties, you must retrieve the object in a separate call within your webhook handler.
from the same expansion doc: https://docs.stripe.com/expand#with-webhooks
Let me know if you need any more help after trying that!
I guess the connected account for which the invoice was created cannot be retrieved somehow from the webhook invoice?
What do you mean? Can you share an example of what you're trying to find?
I want to use what you are suggested:
const invoice = await stripe.invoices.retrieve(<invoice id>, { expand: ['payments'] });
but for a connected account
const invoice = await stripe.invoices.retrieve(<invoice id>, { expand: ['payments'] }, {stripeAccount: <account id>});
So I was wondering if the stripe account id can be found somewhere in the invoice i got from the webhook. According to the documentation, it seems that there is no such a field but I thought asking in case there was a trick or something