Update for invalid input stream from IPN post #74
* Performs check to ensure the file_get_contents() function is not disabled and attempts to enable. * Prior to PHP 5.6, php://input couldn't be reliably re-read. This patch reads it once and works with that data via the raw_post_data variable. * https://github.com/bitpay/magento-plugin/issues/74
This commit is contained in:
parent
482027cde1
commit
cc63905509
|
@ -19,17 +19,27 @@ class Bitpay_Core_IpnController extends Mage_Core_Controller_Front_Action
|
|||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
if (!ini_get('allow_url_fopen')) {
|
||||
ini_set('allow_url_fopen', true);
|
||||
}
|
||||
|
||||
$raw_post_data = file_get_contents('php://input');
|
||||
|
||||
if ($raw_post_data === false) {
|
||||
throw new Exception('Could not read from the php://input stream or invalid Bitpay IPN received.');
|
||||
}
|
||||
|
||||
Mage::helper('bitpay')->registerAutoloader();
|
||||
Mage::helper('bitpay')->debugData(
|
||||
array(
|
||||
sprintf('Incoming IPN from bitpay'),
|
||||
getallheaders(),
|
||||
file_get_contents('php://input'),
|
||||
$raw_post_data,
|
||||
)
|
||||
);
|
||||
|
||||
// Magento doesn't seem to have a way to get the Request body
|
||||
$ipn = json_decode(file_get_contents('php://input'));
|
||||
$ipn = json_decode($raw_post_data);
|
||||
$ipn->posData = is_string($ipn->posData) ? json_decode($ipn->posData) : $ipn->posData;
|
||||
$ipn->buyerFields = isset($ipn->buyerFields) ? $ipn->buyerFields : new stdClass();
|
||||
Mage::helper('bitpay')->debugData($ipn);
|
||||
|
|
Loading…
Reference in New Issue