Patreon / patreon-php

Interact with the Patreon API via OAuth
Apache License 2.0
145 stars 41 forks source link

Webhooks. #52

Closed ariesclark closed 4 years ago

ariesclark commented 5 years ago

the event data is being sent in the POST request body. In PHP we can access this information like so:

$input = @file_get_contents("php://input"); $event_json = json_decode($input);

once you have run that snippet of code, your event can be found in $event_json.

As the browser never navigates to these PHP files, it is a good idea to write all your output to files

For example, My "create.php" file looks like this:

$input = @file_get_contents("php://input");
$event_json = json_decode($input);

ob_flush();
ob_start();

  var_dump($event_json);

file_put_contents("post.txt", ob_get_flush());

hat you get in the signature is just there to let you verify the POST response body hasn't been tampered with/intercepted. I don't know anything about HMAC-MD5 so I'm not going to try and explain it here :P

I hope this has helped you guys :)

lastly... Patreon!! can we please see this^^^ in the Documentation!? haha (this is 4 hours of my life I'm not getting back)

I believe you now have the basic information you need to understand how this works :)

Regarding this, I've tried doing this myself and in my file, all it says is NULL. I'm still confused on how I'm supposed to obtain the webhook information.

Originally posted by @RubyTheRose in https://github.com/Patreon/patreon-php/issues/20#issuecomment-440346991

Linkupdated commented 5 years ago
$patreonEvent = $_SERVER['HTTP_X_PATREON_EVENT'];
$patreonSignature = $_SERVER['HTTP_X_PATREON_SIGNATURE'];

$input = @file_get_contents("php://input");
$event_json = json_decode($input);

file_put_contents("post.txt", json_encode($event_json, JSON_PRETTY_PRINT));

Here's my code for testing if it helps anyone. Still looking into how to validate with the HMAC-MD5