#lynexis-webhooks

1 messages · Page 1 of 1 (latest)

glossy tiger
#

hi there! can you elaborate more on your use case?

weak stump
#

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

glossy tiger
#

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

weak stump
#

The thing is that I do not need the data in the event, but other data that I send in my client side

glossy tiger
weak stump
#

I don't, what happens if I do?

#

I only send the line_items param inside the session creation

glossy tiger
#

that metadata will be included on the Checkout Session object, and hence be included in all checkout.session.* events

weak stump
#

So in the metadata object I send my custom object, whenever the event checkout.session.completed triggers, I can read that specific object?

glossy tiger
#

yep, that's right

weak stump
#

Alright, let me give it a shot

weak stump
#

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

glossy tiger
#

sure feel free to share your code snippet here!

weak stump
#

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()

glossy tiger
#

what programming language are you using?

weak stump
#

node.js

glossy tiger
#

gimme a second to see if i can give you an example

weak stump
#

Sure

glossy tiger
#

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
      }
weak stump
#

So basically I cannot send an object inside the metadata object

#

Send them separatelly

glossy tiger
#

one option is to extract out all the values like

      "first": "something",
      "price": 1234,
      "count": 5678,
      "expire": 123432454,
      "user.test":  1234
    }
weak stump
#

Alright let me try it

#

Another question, the metadata is only saved when the checkout session is done?

glossy tiger
#

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

weak stump
#

Oh, that is weird because I just tried gathering the metadata object and it comes empty when the webhook event occurs

glossy tiger
#

can you share the event id?

weak stump
#

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?

glossy tiger
#

sounds about right!

#

try completing that specific new Checkout Session and see if it shows

weak stump
#

Yeah, I just have to switch to test again cause this thing is live haha

glossy tiger
#

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
  }
...

weak stump
#

I managed it out!

#

Thank you very much for your time

glossy tiger
#

you're welcome 😄