From d66880ec0e880da879c1eda462f81bb385e42145 Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Mon, 20 May 2019 14:28:51 -0400 Subject: [PATCH] support IPN logging on processors that send JSON data as POST --- CRM/Core/Payment.php | 9 ++++++++- CRM/Utils/JSON.php | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 1e5f646223..c4f096b668 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -261,7 +261,14 @@ abstract class CRM_Core_Payment { } $log = new CRM_Utils_SystemLogger(); - $log->alert($message, $_REQUEST); + // $_REQUEST doesn't handle JSON, to support providers that POST JSON we need the raw POST data. + $rawRequestData = file_get_contents("php://input"); + if (CRM_Utils_JSON::isValidJSON($rawRequestData)) { + $log->alert($message, json_decode($rawRequestData, TRUE)); + } + else { + $log->alert($message, $_REQUEST); + } } /** diff --git a/CRM/Utils/JSON.php b/CRM/Utils/JSON.php index d771de94e4..7ec004714f 100644 --- a/CRM/Utils/JSON.php +++ b/CRM/Utils/JSON.php @@ -46,6 +46,16 @@ class CRM_Utils_JSON { CRM_Utils_System::civiExit(); } + /** + * Test whether the input string is valid JSON. + * @param string $str + * @return boolean + */ + public static function isValidJSON($str) { + json_decode($str); + return json_last_error() == JSON_ERROR_NONE; + } + /** * Do not use this function. See CRM-16353. * @deprecated -- 2.25.1