Separating Paypal Standard Log File

Written by in Tutorials on November 21, 2012  |  4 Comments

separating-paypal-log-file

OpenCart Paypal payment have usefull feature to log the Paypal IPN (Instant Payment Notification) when a transaction is affected. Whenever order is created and customer decide to pay through Paypal, either it is complete, pending or may be refunded, OpenCart create a log in the error log file.

In most case, we cleared error log after we fix the errors, but of course the Paypal log is also cleared. So to keep the paypal log for future refference we need to save it to different file. In this tutorial we will separating the Paypal Standard log and develope log viewer interface to access Paypal log on admin.

Modificate OpenCart

To separating Paypal standard log from error log, we need to make our own function in system/library/log.php then replace all default write log function inside the catalog/controller/payment/pp_standard.php with our new function. We will do it with vQmod.

Create new log write function for Paypal standard payment:

<file name="system/library/log.php">
   <operation>
      <search position="before"><![CDATA[write($message)]]></search>
      <add><![CDATA[
         public function writePaypalStandard($message) {
            $file = DIR_LOGS . 'paypal_standard.log';
            
            $handle = fopen($file, 'a+'); 
            fwrite($handle, date('Y-m-d G:i:s') . ' - ' . $message . "\n");
            fclose($handle); 
         }
      ]]></add>
   </operation>
</file>

Replace default log write in Paypal standard payment with the new one:

<file name="catalog/controller/payment/pp_standard.php">
   <operation>
      <search position="replace"><![CDATA[$this->log->write]]></search>
      <add><![CDATA[$this->log->writePaypalStandard]]></add>
   </operation>
</file>

Actualy with modification above you already get paypal_standard.log file at system/logs/ folder when someone pay through Paypal Standard payment module. But of course this tutorial isn’t complete without the log viewer at admin. In the next step we will create two new file to make an admin interface for the Paypal Standard Log, just like the error log.

Log Viewer

Controller
  1. Open folder admin/controller/tool/
  2. Copy error_log.php file and renamed to: paypal_standard_log.php
  3. Open the paypal_standard_log.php file to make some adjustment.
    1. Change ControllerToolErrorLog to ControllerToolPaypalStandardLog
    2. Find and replace all tool/error_log with tool/paypal_standard_log
    3. Find and replace all $this->config->get(‘config_error_filename’) with “paypal_standard.log”
    4. Since there is no need to use another template, make sure you call the error_log.tpl (around line 48)
      $this->template = 'tool/error_log.tpl';
Language
  1. Open folder admin/language/english/tool/
  2. Copy error_log.php file and renamed to: paypal_standard_log.php
  3. Open the paypal_standard_log.php file to make some adjustment.
    <?php
    // Heading
    $_['heading_title'] = 'Paypal Standard Log';
    
    // Text
    $_['text_success']  = 'Success: You have successfully cleared your Paypal Standard log!';
    ?>
          
Create Menu Link

Now we will create admin link to view the Paypal Standard log at url: example.com/admin/index.php?route=tool/paypal_standard_log&token=xxx. As modification above, we will use vQmod to achieve it.

<file name="admin/view/template/common/header.tpl">
	<operation>
		<search position="after"><![CDATA[$text_error_log;]]></search>
		<add><![CDATA[<li><a href="<?php echo $this->url->link('tool/paypal_standard_log', 'token=' . $this->session->data['token'], 'SSL'); ?>">Paypal Standard Logs</a></a></li>
		]]></add>
	</operation>
</file>

You can download file bellow to try this tutorial.

Download720 downloads
Tags: , , ,

About the Author

The man behind OpencartNews and EchoThemes.

View all posts by

4 Comments on "Separating Paypal Standard Log File"

  1. Kemal May 8, 2013 at 6:39 am · Reply

    Thanks for the tutorial!

    Just for some newbees: don’t forget to add permissions to your “Top Administrator” group :)

  2. Gabby February 18, 2013 at 2:32 pm · Reply

    I did try creating order then go back to my site but i did not get anything in the log file

  3. Lourence January 31, 2013 at 4:04 am · Reply

    Really great, thank you very much but do you know if still working with latest v1.5.5.x ?

    I ‘ll try and ;-) report trouble, even if not tested, is not ?

  4. Jessica January 30, 2013 at 1:59 am · Reply

    it’s very very interresting ;-) many many thanks to share it

Leave a Comment

comm comm comm