PayPal Webhook sends no POST data

Viewed 354

Configured my PayPal webhook successfully to be notified of all events.

PayPal calls my webhook (a simple script) when events occur... but does not send any POST data with it....

All PHP arrays are empty ($_POST, $_GET, $_REQUEST) except for $_SERVER of course.

What is going on? The webhook simulator says that the events are sent/queued succesfully...

The $_SERVER array contains the suggested HTTP_PAYPAL_... headers and everything.... but the $_POST array is empty.

My webhook is written as follows...

<?php

require ('./ace-includes/ace_log.php');

ace_log(print_r($_POST, true));
ace_log(print_r($_REQUEST, true));
ace_log(print_r($_GET, true));
ace_log(print_r($_SERVER, true));

ace_sendlog("NOTIFY SCRIPT CALLED");

?>
1 Answers

I figured it out....

You cannot use $_POST to get the data....

The data is contained in the HTTP file sent to the script.

In this case you MUST use

file_get_contents('php://input');

to get the data.

So for PayPal PHP webhooks you would do this....

$json = file_get_contents('php://input');
$data = json_decode($json);

This works and now I am getting all the data.

This really should be documented somewhere.... anywhere... but its not... and not obvious to an beginning PHP programmer.

Related