#redbluesock_code
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/1403297335202811965
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
{
"id": "evt_1RiZqXINxfzIe4TvCmIxQUvP",
"object": "event",
"api_version": "2025-06-30.basil",
"created": 1751974680,
"data": {
"object": {
"metadata": {}, <--- here we want the data to show up
},
}
That's an invoice.payment_succeeded invoice, yes?
Yes, correct.
Any metadata you set on the Subscription should be available on the Invoice on this prop: https://docs.stripe.com/api/invoices/object#invoice_object-parent-subscription_details-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Looking at your code:
.putMetadata(METADATA_INVOICE_ITEM_TYPE, METADATA_INVOICE_ITEM_TYPE_VALUE_SUBSCRIPTION)
You're setting the top-level metadata parameter. Those key/values aren't passed through to underlying objects: https://docs.stripe.com/metadata#set-indirectly
You should use subscription_data[metadata]: https://docs.stripe.com/api/checkout/sessions/create?api-version=2025-07-30.basil#create_checkout_session-subscription_data-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yes, we call putMetadata(...) on the SessionCreateParams.SubscriptionData.Builder and successfully add out values to the /data/object/parent/subscription_details/metadata element.
But we're processing different types of of invoices (like one time payments) where we need to differentiate in further processing. Unfortunately it's not possible to do this based on the line items.
So we looked for a field that is always available in all invoice webhooks whether it's an subscription or something else and found the top-level metadata field.
Ah okay, they're not passed. Thanks thats helpful. Then we'll no longer focus on this element but work on another solution for our case.
Can you share an invoice (in_xxx) where the metadata isn't copied? Using that evt_xxx above I can see the metadata in the hash I shared
Well the invoice you shared is associated to a sub that was created via a Checkout Session. You did set subscription_data[metadata] there so overall confused as to what the ask is
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Are you using Checkout for the one-time payments/invoices? Maybe this is the param you need: https://docs.stripe.com/api/checkout/sessions/create?api-version=2025-07-30.basil#create_checkout_session-invoice_creation-invoice_data-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yes I can share an invoice (in_1RtQf2INxfzIe4Tv0pKZm9k3) and event (evt_1RtQf5INxfzIe4TvUHlw07OD):
Reading through the docs I see https://docs.stripe.com/metadata?lang=java#events and that's exactly what we want.
OK in that example you can just set top-level metadata: https://docs.stripe.com/api/invoices/create?api-version=2025-07-30.basil#create_invoice-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
Hi, maybe we can shorten this: So according to https://docs.stripe.com/metadata?lang=java#events you can set the top level metadata field of an invoice. Right?
And this data is also passed via webhook?
yes correct
But we expect this metadata to show up in the invoice.payment_succeded event but this can't be the case since SessionCreateParams.builder().putMetadata(...) doesn't add metadata to the invoice, right?
this is a different question than the 2 above ones
yes you can add metadata to the invoice object
when you're creating an invoice
but if you're creating a Checkout Session, the top level metadata is on the checkout session object
not the invoice object
Okay sorry to be unclear but I think I see the problem. We'll try to SessionCreateParams.builder().setInvoiceCreation(SessionCreateParams.builder().putMetadata(...)... and check wheterh we get our metadata in the invoice.payment_succeded event.
no
you need to do what my colleague suggested here
Yes okay, I'll get back to our developers since I see I am not sufficiently familiar with the subject to elaborate. They've told me they can't set the specific metadata field on the invoice but I think they can work with the suggested solution.
Thanks for your help!
setting the metadata to the subscription will copy them to the invoice https://docs.stripe.com/metadata#exceptions