As function stands below, the user is redirected as required, and order status changes, however no debug log
But, if part (6b) and (6c) return are not commented, then the debug log is written, but the redirect doesn't work.
How to achieve redirect AND debug log ?
function onPaymentNotification(&$statuses)
{
// (1) Create array from the received gateway response parameters
$vars = array();
$filter = JFilterInput::getInstance();
foreach($_REQUEST as $key => $value)
{
$key = $filter->clean($key);
$value = JRequest::getString($key);
$vars[$key]=$value;
}
// (2) We load the parameters of the plugin in $this->payment_params and the order data based on the order_id coming from the payment platform
$order_id = (int)@$vars['OrderID'];
$dbOrder = $this->getOrder($order_id);
$this->loadPaymentParams($dbOrder);
if(empty($this->payment_params))
return false;
$this->loadOrderData($dbOrder);
// (3) Configure the "success/fail URLs" to re-direct in (6)
$return_url = $this->pluginConfig['return_url'][2].'&order_id='.$order_id; //.$this->url_itemid ;
$cancel_url = $this->pluginConfig['cancel_url'][2].'&order_id='.$order_id; //.$this->url_itemid ;
// (4) Recalculate the hash to check for (6)
$hash = $this->jcc_signature($this->payment_params->password,$vars,false,false);
// (5) Debug mode activated or not
if($this->payment_params->debug)
{
//Display debug information in the payment log file
echo print_r($vars,true)."\n\n\n";
echo print_r($dbOrder,true)."\n\n\n";
echo print_r($hash,true)."\n\n\n";
}
// (6) Confirm (or not) the order
if (strcasecmp($hash,$vars['ResponseSignature'])!=0) //Different hash between what we calculate and the hash ent by the payment platform so we do not do anything as we consider that the notification doesn't come from the payment platform.
{
// (6a) we display debug information in the payment log file available in the configuration's Files section.
if($this->payment_params->debug)
echo 'Hash error '.$vars['ResponseSignature'].' - '.$hash."\n\n\n";
return false;
}
// (6b) If gateway response is not success
elseif($vars['ResponseCode']!='2')
{
$this->modifyOrder($order_id, $this->payment_params->invalid_status, true, true);
$JCCResponse = "Report by JCC</br>Error : " . $vars['ReasonCodeDesc'];
$JCCResponseURL = $cancel_url;
//return false;
}
// (6c) If gateway response is not success
else
{
$this->modifyOrder($order_id, $this->payment_params->verified_status, true, true);
$JCCResponse = "Report by JCC</br>Success : " . $vars['ReasonCodeDesc'];
$JCCResponseURL = $return_url;
//return true;
}
$this->app->redirect($JCCResponseURL, $JCCResponse);
}