1

So I have my PHP IPN script working, now I am just not sure how to get the post values? Paypal returns the post as an array like this.

transaction[0].is_primary_receiver=false
&transaction[0].id_for_sender_txn=50E02759CC687801U
&log_default_shipping_address_in_transaction=false
&transaction[0].receiver=xxxxxxxxxx@gmail.com
&action_type=PAY
&transaction[1].status=Completed

There is obviously more but you get the idea, I tried accessing the post for status like this.

$payment_status = $_POST['transaction'][1]['status']

but this doesn't work, it returns the first letter which is C. So how do I access the values for all of them.

Wes
  • 163
  • 1
  • 12

1 Answers1

4

With a little search I've found this link to be helpfull: https://developer.paypal.com/webapps/developer/docs/classic/ipn/ht_ipn/

The most relevant part of the page:

// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream. 
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
    $keyval = explode ('=', $keyval);
    if (count($keyval) == 2)
        $myPost[$keyval[0]] = urldecode($keyval[1]);
}
Ricardo Souza
  • 16,030
  • 6
  • 37
  • 69
  • 1
    I had to add one extra thing to the the script above. Where it urldecodes $keyval[1], I had to also urldecode $keyval[0], the index. The reason is because for something like transaction[1].status, without urldecoding it sets it as transaction%5B1%5D.status . Other than that it works great, I just use for statements to iterate through each transaction to add up the price and check it and get the txn_id and stuff. – Wes Sep 26 '13 at 00:37
  • Great! You got it. ;) – Ricardo Souza Sep 26 '13 at 18:16