Last active
August 29, 2015 14:26
-
-
Save hypeJunction/913f07c5fc4f2542a0aa to your computer and use it in GitHub Desktop.
Working with PayPal IPN's malformatted multidimensional arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PayPal\IPN\PPIPNMessage; | |
$postData = file_get_contents('php://input'); | |
$ipn = new PPIPNMessage($postData); | |
if (!$ipn->validate()) { | |
exit; | |
} | |
$data = array(); | |
$fixArr = preg_replace("/\b(\w+)\\%5B(\w+)\\%5D\.([^=]*)[=]([^\&]*)([\&$])\b/", "$1%5B$2%5D%5B$3%5D=$4$5", $postData); | |
parse_str($fixArr, $data); | |
if (isset($data['payment_status'])) { | |
$payment_status = $data['payment_status']; | |
$txn_id = $data['txn_id']; | |
} else if ($data['transaction']) { | |
foreach ($data['transaction'] as $transaction) { | |
if ($transaction['is_primary_receiver'] === 'true') { | |
$payment_status = $transaction['status']; | |
$txn_id = $transaction['id']; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment