#Ajith Selvakumar-webhook-metadata
1 messages · Page 1 of 1 (latest)
Hey, what parameter did you pass to set the metadata?
What events are you subscribed to?
Yes, so that metadata parameter will on be set on the Checkout Session object, not the underlying subscription object
You should instead use the subscription_data.metadata parameter: https://stripe.com/docs/api/checkout/sessions/create#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.
is this correct? And i need the meta data on all the invoice events
Will this work for that use case?
That looks right, yep!
For the invoice.* events, the Subscription object won't be included by default. You'll need to expand that field: https://stripe.com/docs/api/invoices/object#invoice_object-subscription
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.
You'll need to make an API call to retrieve the Invoice object, passing the expand: ['subscription'] parameter
Okay do you have any code examples for this
I am not a great developer just 1 year of experience, i am finding it too difficult
With stripe-node?
const invoice = await stripe.invoices.retrieve(
'in_xxx', {
expand: ['subscription']
}
);
Okay in order to get metadata, i need to retrieve the session. Won't i get them in the response body of the webhook where we can get the event.
No, as explained the subscription field on the Invoice object is just the sub_xxx ID. If you need the metadata field from the Subscription object you'll need to expand (using that API call ☝️ ) and it'll be in the response
is this fine?
Why are you retrieving the Checkout Session?
You should retrieve the Invoice in your webhook that is receiving the invoice.* events
There won't be any Checkout Session context in those event payloads
event.type isn't the parameter you need to pass there. It'll be event.data.object.id
Fine?
.id
Oops
Are you testing this webhook code locally via the Stripe CLI?
Yes i am trying to do so, but it says "No signatures found matching the expected signature for payload"
You need to use the webhook secret whsec_xxx that the CLI prints out
Not the one from the Dashboard
Yes I gave the secret key from the cli only, still it says that error
My guess is whatever framework/library you're using is manipulating _req.body
The constructEvent function expects the raw request object
Ohh okay
Can you assist on checking this webhook with a trigger to setup subscription?
I'm not sure what you mean
I have the webhook running locally and it will be called while any trigger.
I need to set a trigger to test it. So that i can confirm that we are getting the metadata in the webhook
stripe trigger invoice.paid
I think first we need to give metadata in some format right?
If you have a pre-existing subscription with the metadata, you can just re-send a related event to the webhook