patreon-php
patreon-php copied to clipboard
Pulling out from webhook patron data (email , name, pledge amount, etc)
Is there an easy way to pull out data from a webhook?
Maybe it's me, but I've not found any kind of documentation, example, anything. Not here, not on patreon's api...
I need to create a """"simple"""" script which will do
retrieved data > to variables
if pledge:create do stuff if pledge:delete do stuff if pledge:update do stuff
Is that so hard to achieve?
Actually there's is a document here: https://docs.patreon.com/#webhooks
You can take from here the idea on how to validate the signature: https://github.com/Patreon/patreon-wordpress/blob/e5c0656b5e0631abbfa93b18ca110c7abd1aafab/classes/patreon_routing.php#L651-L665
And then you can just use this to fetch the json data:
json_decode($raw_post_data, true);
$raw_post_data
is the content of the post request as string.
I'm posting this now cuz I was having the same issue, but found this solution. Haven't tried it yet, but let me know if it helps :)
Oh, and to check by event you can get the header X-Patreon-Event
and check with that, like:
$type = $headers['X-Patreon-Event'];
if($type === 'pledge:create'){
// TODO
}