#TomConnolly - ruby metadata
1 messages · Page 1 of 1 (latest)
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?
I do see it, but I don't have the syntax for retrieving it. I get confused about JSON.
Ah, i think you can access event.metadata["key"] no? Or otherwise use JSON.parse(event.metadata)?
I know the question sounds a little like "I know my abcs, but what comes after c?"
I'm not a ruby pro so have to look this up to 😄
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
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
wh.data.object.metadata.. returns undefined method 'object'.
Have you tried following the steps/samples code here?
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.
Are you using our SDK to construct the event object from the request you receive?
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.
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
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?
- Not an issue, i dont think, we just needed to figure out what each other meant. You were ahead asking about metadata when the issue was (hopefully) initial request parsing.
- This sample code shows doing so for each server language:
https://stripe.com/docs/webhooks#webhook-endpoint-code
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
Once you're comfortable with that, we recommend verifying signatures for authenticity using construct_event and a webhook signing secret:
https://stripe.com/docs/webhooks/signatures#verify-official-libraries
But i don't recommend going to this until the first version works, it has more ways to get complicated
Good luck!