Question

I have set up the following script to test notifications of orders paid via Google Checkout:

<?php
    mail('max@edison.com', 'google checkout order alert', json_encode($_POST));
?>

I'm getting the email, but the value of the $_POST array is blank (in other words, the body of the email is simply []).

Am I wrong to think that the values should be getting sent immediately via POST? Or is the notification request really just an opportunity for me to then request from Google the most recent order details? I.e., my above script would need to make a request to Google for the order details.

Was it helpful?

Solution

The Google Checkout postback request is a raw JSON post, not a typical HTTP post (which is what would be needed in order to populate the $_POST array). In order to read the contents of the postback request, you must get the raw post body, and json_decode it.

This should do the trick: json_decode(file_get_contents('php://input'))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top