#TomConnolly - ruby metadata

1 messages · Page 1 of 1 (latest)

modest patio
#

If an object has metadata it should be included in the webhook payload. Do you have a particular example event ID where you're not seeing it?

wet dawn
#

I do see it, but I don't have the syntax for retrieving it. I get confused about JSON.

modest patio
#

Ah, i think you can access event.metadata["key"] no? Or otherwise use JSON.parse(event.metadata)?

wet dawn
#

I know the question sounds a little like "I know my abcs, but what comes after c?"

modest patio
#

I'm not a ruby pro so have to look this up to 😄

wet dawn
#

My excuse is I'll be starting my 81st year in June.. I have the webhook stored in the db. Here's what I've been trying:

#

wh = Webhook.find(the number)

#

wh.status returns "processed", wh.id returns the correct id, wh.data gives me the entire JSON payload.

#

wh.metadata gives full dump

#

wh.data.metadata same

modest patio
#

ah, i think you might want to access the metadata on the object
wh.data.object.metadata

#

The actual Stripe object the event is about lives on that object path, and it is what carries the metadata

wet dawn
#

wh.data.object.metadata.. returns undefined method 'object'.

modest patio
wet dawn
#

I guess I have to study the StripeHandler in Rails to see how "status" and "data" got their own columns in the database. Metadata does not have its own column, but is embedded in the whole JASON dump called "data." I need to learn how to break it out so I can access it. I have read these steps many times, thank you.

modest patio
#

Are you using our SDK to construct the event object from the request you receive?

wet dawn
#

I am sure that is where I didn't do the right thing. (constructing the event)

#

I take it that's a Ruby thing, and not a Stripe thing.

modest patio
#

It's available in all our libraries -- helper method to parse the webhook request into a stripe object

#

I'd suggest taking a look at the sample code to see how that's used

wet dawn
#

Could I bother you with two more requests? 1. How could I have posed my original question to make the situation clearer to the reader? 2. Can you point me to a specific page in the docs where I cal learn to parse the wh correctly?

modest patio
#

The key line we're discussing is this one:

#
 event = Stripe::Event.construct_from(
      JSON.parse(payload, symbolize_names: true)
    )
#

construct_from builds the object without any signature verification

#

Good luck!