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 {
* @return mixed
*/
public static function logPaymentNotification($params) {
$message = '';
$message = 'payment_notification ';
if (!empty($params['processor_name'])) {
$message = 'processor_name=' . $params['processor_name'];
$message .= 'processor_name=' . $params['processor_name'];
}
if (!empty($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 {
/**
* 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
* @public
......
......@@ -1173,8 +1173,9 @@ class CRM_Utils_System {
$address = CRM_Utils_Array::value('REMOTE_ADDR', $_SERVER);
$config = CRM_Core_Config::singleton();
if ($config->userSystem->is_drupal) {
//drupal function handles the server being behind a proxy securely
if ($config->userSystem->is_drupal && function_exists('ip_address')) {
//drupal function handles the server being behind a proxy securely. We still have legacy ipn methods
// that reach this point without bootstrapping hence the check that the fn exists
$address = ip_address();
}
......
......@@ -34,6 +34,9 @@
*/
class CRM_Utils_SystemLogger extends Psr\Log\AbstractLogger implements \Psr\Log\LoggerInterface {
public function log($level, $message, array $context = array()) {
if(!isset($context['hostname'])) {
$context['hostname'] = CRM_Utils_System::ipAddress();
}
$rec = new CRM_Core_DAO_SystemLog();
$separateFields = array('contact_id', 'hostname');
foreach ($separateFields as $separateField) {
......
......@@ -35,6 +35,8 @@ session_start();
require_once '../civicrm.config.php';
$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->main();
......@@ -36,6 +36,8 @@ session_start();
require_once '../civicrm.config.php';
$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');
CRM_Core_Payment_GoogleIPN::main($rawPostData);
......@@ -38,11 +38,13 @@ require_once '../civicrm.config.php';
/* Cache the real UF, override it with the SOAP environment */
$config = CRM_Core_Config::singleton();
$log = new CRM_Utils_SystemLogger();
if (empty($_GET)) {
$log->log('alert', 'payment_notification processor_name=PayPal', $_REQUEST);
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($_REQUEST);
}
else {
$log->log('alert', 'payment_notification PayPal_Standard', $_REQUEST);
$paypalIPN = new CRM_Core_Payment_PayPalIPN();
// @todo upgrade standard per Pro
}
......
......@@ -17,7 +17,8 @@ require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';
$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
* being passed back from the server
......
......@@ -25,28 +25,30 @@
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
require_once 'CiviTest/CiviUnitTestCase.php';
class CRM_Core_PaymentTest extends CiviUnitTestCase {
function get_info() {
return array(
'name' => 'Payment Test',
'description' => 'Test Payment methods.',
'group' => 'Payment Processor Tests',
);
}
/**
* test the payment method is adequately logged - we don't expect the processing to succeed
*/
class CRM_Utils_SystemLogger implements \Psr\Log\LoggerInterface {
static public function log($level, $message, array $context = array()) {
echo 'k';
$rec = new CRM_Core_DAO_SystemLog();
$separateFields = array('contact_id', 'hostname');
foreach ($separateFields as $separateField) {
if (isset($context[$separateField])) {
$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);
$rec->level = $level;
$rec->message = $message;
$rec->context = json_encode($context);
$rec->save();
$log = $this->callAPISuccess('SystemLog', 'get', array());
$this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log->id]['message']);
}
}
......@@ -19,6 +19,8 @@
<civicrm_preferences_date />
<civicrm_system_log />
<civicrm_worldregion />
<civicrm_component />
......
......@@ -39,7 +39,7 @@
<comment>error level per PSR3</comment>
<type>varchar</type>
<length>9</length>
<default>info</default>
<default>'info'</default>
<add>4.5</add>
</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