Commit 414e3596 authored by eileenmcnaughton's avatar eileenmcnaughton Committed by Eileen McNaughton

CRM-14494 add system logger to handle payment notification & test

CRM-14449 log legacy style ipns to system_log

CRM-14449 logging request seems more consistent with others

CRM-14449 stding message value in payment notification logs

CRM-14449 log ipaddress on ipn calls

CRM-14449 add fn exists as legacy non-boostrapped methods get to this point
parent e2bef985
...@@ -130,15 +130,16 @@ abstract class CRM_Core_Payment { ...@@ -130,15 +130,16 @@ abstract class CRM_Core_Payment {
* @return mixed * @return mixed
*/ */
public static function logPaymentNotification($params) { public static function logPaymentNotification($params) {
$message = ''; $message = 'payment_notification ';
if (!empty($params['processor_name'])) { if (!empty($params['processor_name'])) {
$message = 'processor_name=' . $params['processor_name']; $message .= 'processor_name=' . $params['processor_name'];
} }
if (!empty($params['processor_id'])) { if (!empty($params['processor_id'])) {
$message .= 'processor_id=' . $params['processor_id']; $message .= 'processor_id=' . $params['processor_id'];
} }
$log = CRM_Utils_SystemLogger();
$log->log('alert', $message, $_REQUEST); $log = new CRM_Utils_SystemLogger();
$log->alert($message, $_REQUEST);
} }
/** /**
...@@ -182,7 +183,7 @@ abstract class CRM_Core_Payment { ...@@ -182,7 +183,7 @@ abstract class CRM_Core_Payment {
/** /**
* This function checks to see if we have the right config values * This function checks to see if we have the right config values
* *
* @param string $mode the mode we are operating in (live or test) * @internal param string $mode the mode we are operating in (live or test)
* *
* @return string the error message if any * @return string the error message if any
* @public * @public
......
...@@ -58,9 +58,9 @@ class CRM_Utils_System { ...@@ -58,9 +58,9 @@ class CRM_Utils_System {
* (optional) Whether to include the reset GET string (if present). * (optional) Whether to include the reset GET string (if present).
* @param bool $includeForce * @param bool $includeForce
* (optional) Whether to include the force GET string (if present). * (optional) Whether to include the force GET string (if present).
* @param string $path * @param string $path
* (optional) The path to use for the new url. * (optional) The path to use for the new url.
* @param string $absolute * @param string $absolute
* (optional) Whether to return an absolute URL. * (optional) Whether to return an absolute URL.
* *
* @return string * @return string
...@@ -178,7 +178,7 @@ class CRM_Utils_System { ...@@ -178,7 +178,7 @@ class CRM_Utils_System {
* *
* @param string $content * @param string $content
* The content that will be themed. * The content that will be themed.
* @param bool $print * @param bool $print
* (optional) Are we displaying to the screen or bypassing theming? * (optional) Are we displaying to the screen or bypassing theming?
* @param bool $maintenance * @param bool $maintenance
* (optional) For maintenance mode. * (optional) For maintenance mode.
...@@ -720,7 +720,7 @@ class CRM_Utils_System { ...@@ -720,7 +720,7 @@ class CRM_Utils_System {
return substr_replace($number, $replace, 0, -$keep); return substr_replace($number, $replace, 0, -$keep);
} }
/** /**
* Determine which PHP modules are loaded. * Determine which PHP modules are loaded.
* *
* @return array * @return array
...@@ -956,7 +956,7 @@ class CRM_Utils_System { ...@@ -956,7 +956,7 @@ class CRM_Utils_System {
* @param int $ver * @param int $ver
* The major version of PHP that is required. * The major version of PHP that is required.
* @param bool $abort * @param bool $abort
* (optional) Whether to fatally abort if the version requirement is not * (optional) Whether to fatally abort if the version requirement is not
* met. Defaults to TRUE. * met. Defaults to TRUE.
* @return bool * @return bool
* Returns TRUE if the requirement is met, FALSE if the requirement is not * Returns TRUE if the requirement is met, FALSE if the requirement is not
...@@ -1173,9 +1173,10 @@ class CRM_Utils_System { ...@@ -1173,9 +1173,10 @@ class CRM_Utils_System {
$address = CRM_Utils_Array::value('REMOTE_ADDR', $_SERVER); $address = CRM_Utils_Array::value('REMOTE_ADDR', $_SERVER);
$config = CRM_Core_Config::singleton(); $config = CRM_Core_Config::singleton();
if ($config->userSystem->is_drupal) { if ($config->userSystem->is_drupal && function_exists('ip_address')) {
//drupal function handles the server being behind a proxy securely //drupal function handles the server being behind a proxy securely. We still have legacy ipn methods
$address = ip_address(); // that reach this point without bootstrapping hence the check that the fn exists
$address = ip_address();
} }
// hack for safari // hack for safari
...@@ -1731,7 +1732,7 @@ class CRM_Utils_System { ...@@ -1731,7 +1732,7 @@ class CRM_Utils_System {
// getPluginList() // getPluginList()
/** /**
* *
*/ */
static function executeScheduledJobs() { static function executeScheduledJobs() {
$facility = new CRM_Core_JobManager(); $facility = new CRM_Core_JobManager();
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
*/ */
class CRM_Utils_SystemLogger extends Psr\Log\AbstractLogger implements \Psr\Log\LoggerInterface { class CRM_Utils_SystemLogger extends Psr\Log\AbstractLogger implements \Psr\Log\LoggerInterface {
public function log($level, $message, array $context = array()) { public function log($level, $message, array $context = array()) {
if(!isset($context['hostname'])) {
$context['hostname'] = CRM_Utils_System::ipAddress();
}
$rec = new CRM_Core_DAO_SystemLog(); $rec = new CRM_Core_DAO_SystemLog();
$separateFields = array('contact_id', 'hostname'); $separateFields = array('contact_id', 'hostname');
foreach ($separateFields as $separateField) { foreach ($separateFields as $separateField) {
......
...@@ -35,6 +35,8 @@ session_start(); ...@@ -35,6 +35,8 @@ session_start();
require_once '../civicrm.config.php'; require_once '../civicrm.config.php';
$config = CRM_Core_Config::singleton(); $config = CRM_Core_Config::singleton();
$log = new CRM_Utils_SystemLogger();
$log->log('alert', 'payment_notification processor_name=AuthNet', $_REQUEST);
$authorizeNetIPN = new CRM_Core_Payment_AuthorizeNetIPN(); $authorizeNetIPN = new CRM_Core_Payment_AuthorizeNetIPN();
$authorizeNetIPN->main(); $authorizeNetIPN->main();
...@@ -36,6 +36,8 @@ session_start(); ...@@ -36,6 +36,8 @@ session_start();
require_once '../civicrm.config.php'; require_once '../civicrm.config.php';
$config = CRM_Core_Config::singleton(); $config = CRM_Core_Config::singleton();
$log = new CRM_Utils_SystemLogger();
$log->log('alert', 'payment_notification processor_name=Google_Checkout', $_REQUEST);
$rawPostData = file_get_contents('php://input'); $rawPostData = file_get_contents('php://input');
CRM_Core_Payment_GoogleIPN::main($rawPostData); CRM_Core_Payment_GoogleIPN::main($rawPostData);
...@@ -38,11 +38,13 @@ require_once '../civicrm.config.php'; ...@@ -38,11 +38,13 @@ require_once '../civicrm.config.php';
/* Cache the real UF, override it with the SOAP environment */ /* Cache the real UF, override it with the SOAP environment */
$config = CRM_Core_Config::singleton(); $config = CRM_Core_Config::singleton();
$log = new CRM_Utils_SystemLogger();
if (empty($_GET)) { if (empty($_GET)) {
$log->log('alert', 'payment_notification processor_name=PayPal', $_REQUEST);
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($_REQUEST); $paypalIPN = new CRM_Core_Payment_PayPalProIPN($_REQUEST);
} }
else { else {
$log->log('alert', 'payment_notification PayPal_Standard', $_REQUEST);
$paypalIPN = new CRM_Core_Payment_PayPalIPN(); $paypalIPN = new CRM_Core_Payment_PayPalIPN();
// @todo upgrade standard per Pro // @todo upgrade standard per Pro
} }
......
...@@ -17,7 +17,8 @@ require_once '../civicrm.config.php'; ...@@ -17,7 +17,8 @@ require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php'; require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton(); $config = CRM_Core_Config::singleton();
$log = new CRM_Utils_SystemLogger();
$log->log('alert', 'payment_notification processor_name=Payment_Express', $_REQUEST);
/* /*
* Get the password from the Payment Processor's table based on the DPS user id * Get the password from the Payment Processor's table based on the DPS user id
* being passed back from the server * being passed back from the server
......
...@@ -25,28 +25,30 @@ ...@@ -25,28 +25,30 @@
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
*/ */
/**
* require_once 'CiviTest/CiviUnitTestCase.php';
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2014 class CRM_Core_PaymentTest extends CiviUnitTestCase {
* $Id$ function get_info() {
* return array(
*/ 'name' => 'Payment Test',
class CRM_Utils_SystemLogger implements \Psr\Log\LoggerInterface { 'description' => 'Test Payment methods.',
static public function log($level, $message, array $context = array()) { 'group' => 'Payment Processor Tests',
echo 'k'; );
$rec = new CRM_Core_DAO_SystemLog(); }
$separateFields = array('contact_id', 'hostname');
foreach ($separateFields as $separateField) { /**
if (isset($context[$separateField])) { * test the payment method is adequately logged - we don't expect the processing to succeed
$rec->{$separateField} = $context[$separateField]; */
unset($context[$separateField]); function testHandlePaymentMethodLogging() {
} $params = array('processor_name' => 'Paypal', 'data' => 'blah');
try {
CRM_Core_Payment::handlePaymentMethod('method', $params);
}
catch (Exception $e) {
} }
print_r($rec); $log = $this->callAPISuccess('SystemLog', 'get', array());
$rec->level = $level; $this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log->id]['message']);
$rec->message = $message;
$rec->context = json_encode($context);
$rec->save();
} }
} }
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
<civicrm_preferences_date /> <civicrm_preferences_date />
<civicrm_system_log />
<civicrm_worldregion /> <civicrm_worldregion />
<civicrm_component /> <civicrm_component />
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<comment>error level per PSR3</comment> <comment>error level per PSR3</comment>
<type>varchar</type> <type>varchar</type>
<length>9</length> <length>9</length>
<default>info</default> <default>'info'</default>
<add>4.5</add> <add>4.5</add>
</field> </field>
<field> <field>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment