#lynexis-webhooks
1 messages · Page 1 of 1 (latest)
So I have the checkout.session.completed type webhook, and what I need to send to the API call is two parameters, which are product data and user...
And I have noticed with a console.log(request.body) that gives me a Buffer, so I cannot read the custom params
have you tried referring to https://stripe.com/docs/webhooks/quickstart to setup your your server to listen for webhook events? After you use the construct event method, you should be able to refer to the data in the event
The thing is that I do not need the data in the event, but other data that I send in my client side
alright, so lets take this step by step. Are you passing in those custom data as metadata when creating a Checkout Session? https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata
I don't, what happens if I do?
I only send the line_items param inside the session creation
that metadata will be included on the Checkout Session object, and hence be included in all checkout.session.* events
So in the metadata object I send my custom object, whenever the event checkout.session.completed triggers, I can read that specific object?
yep, that's right
Alright, let me give it a shot
Excuse me, can I send a screenshot of how am I sending the metadata and if it's correct?
Because there is an error that says Invalid value type {} must be a string, and everything is a string
sure feel free to share your code snippet here!
This is how I am trying atm
metadata: {
"package": {
"first": first,
"price": price,
"count": count,
"expire": expire
},
"user": usuario
}
Where the values are object values turned into strings with .toString()
what programming language are you using?
node.js
gimme a second to see if i can give you an example
Sure
the metadata field expects an object with basic key-value pairs. The value must be a string.
so what this means is that you can't have a key with an object as a value e.g.
"first": "something",
"price": 1234,
"count": 5678,
"expire": 123432454,
"user": {
"test" : 1234
}
So basically I cannot send an object inside the metadata object
Send them separatelly
one option is to extract out all the values like
"first": "something",
"price": 1234,
"count": 5678,
"expire": 123432454,
"user.test": 1234
}
yep!
Alright let me try it
Another question, the metadata is only saved when the checkout session is done?
no, the metadata is saved to the Checkout Session object during creation. It doesn't matter if the customer completes the Checkout Session or not
Oh, that is weird because I just tried gathering the metadata object and it comes empty when the webhook event occurs
can you share the event id?
Hold on I think im doing it wrong, I'm printing in console the session object when the checkout.session.completed event occurs, which gives me past transactions that have been made without the "metadata" modification to the server... It doesn't show the checkout session that i just tried because I didn't completed it
Am i right?
sounds about right!
try completing that specific new Checkout Session and see if it shows
Yeah, I just have to switch to test again cause this thing is live haha
wanted to add on in case this helps, you can send an object but would need to change it into a string example :
var metadataString = JSON.stringify({
"first": "something",
"price": 1234,
"count": 5678,
"expire": 123432454,
"user.test": {
"test" : 1234
}
...
metadata: {
package : metadataString
}
...
you're welcome 😄