VirtueMart Forum

VirtueMart Dev/Coding Central: VM1 (old version) => Development Projects, Modifications, Hacks & Tweaks. VM1.1 => Payment Modules => Topic started by: drpop on August 28, 2007, 12:38:00 PM

Title: My updated worldpay_notify.php
Post by: drpop on August 28, 2007, 12:38:00 PM
Worldpay and download_id mails just weren't playing nice on my VM. I couldn't find anyone else with the same problems, in fact, I couldn't find anyone using worldpay and downloads. Payment would process, order would update to confirmed via callback, but no download_id mail would be sent. Manually switching the order back to pending, then to confirmed again would get the mal out ok, but it just wouldnt work automatically via the worldpay_notify.

To this end I tweaked the stock worldpay_notify.php with chunks from notify.php and now all is fine.

Theres probably a pile of stuff in here I dont need and I am sure someone could tidy it up but for what its worth, and in the hope of helping someone else in this situation here is my updated worldpay_notify.php,

<?php
/*
* @version $Id: worldpay_notify.php 617 2007-01-04 19:43:08Z soeren_nb $
* @package VirtueMart
* @subpackage Payment
*
* @copyright (C) 2004 Soeren Eberhardt
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* VirtueMart is Free Software.
* VirtueMart comes with absolute no warranty.
*
* www.virtuemart.net
*/

$messages = Array();
function 
debug_msg$msg ) {
    global 
$messages;
    if( 
PAYPAL_DEBUG == "1" ) {
        if( !
defined"_DEBUG_HEADER")  ) {
            echo 
"<h2>PayPal Notify.php Debug OUTPUT</h2>";
            
define"_DEBUG_HEADER""1" );
        }
        
$messages[] = "<pre>$msg</pre>";
        echo 
end$messages );
    }
}

if (
$_POST) {
    
header("Status: 200 OK");
    
define('_VALID_MOS''1');
    global 
$mosConfig_absolute_path$mosConfig_live_site$mosConfig_lang$database,
    
$mosConfig_mailfrom$mosConfig_fromname;
    
    
/*** access Joomla's configuration file ***/
        
$my_path dirname(__FILE__);
        
        if( 
file_exists($my_path."/../../../configuration.php")) {
            require_once(
$my_path."/../../../configuration.php");
        }
        elseif( 
file_exists($my_path."/../../configuration.php")){
            require_once(
$my_path."/../../configuration.php");
        }
        elseif( 
file_exists($my_path."/configuration.php")){
            require_once( 
$my_path."/configuration.php" );
        }
        else
            die( 
"Joomla Configuration File not found!" );
        
        include_once( 
$my_path.'/compat.joomla1.5.php' );
        
        if( 
class_exists'jconfig')) {
define'_JEXEC');
define('JPATH_BASE'$mosConfig_absolute_path );

require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/application.php' );
require_once ( JPATH_BASE'/includes/database.php');
// create the mainframe object
$mainframe = new JSite();

// set the configuration
$mainframe->setConfiguration(JPATH_CONFIGURATION DS 'configuration.php');

// load system plugin group
JPluginHelper::importPlugin'system' );

// trigger the onStart events
$mainframe->triggerEvent'onBeforeStart' );

// create the session
$mainframe->setSession$mainframe->getCfg('live_site').$mainframe->getClientId() );
$database =& JFactory::getDBO();
        }
        else {
        

        
require_once($mosConfig_absolute_path'/includes/database.php');
        
$database = new database$mosConfig_host$mosConfig_user$mosConfig_password$mosConfig_db$mosConfig_dbprefix );
        }
        
        
// load Joomla Language File
        
if (file_exists$mosConfig_absolute_path'/language/'.$mosConfig_lang.'.php' )) {
            require_once( 
$mosConfig_absolute_path'/language/'.$mosConfig_lang.'.php' );
        }
        elseif (
file_exists$mosConfig_absolute_path'/language/english.php' )) {
            require_once( 
$mosConfig_absolute_path'/language/english.php' );
        }
    
/*** END of Joomla config ***/
    
    
    /*** VirtueMart part ***/        
        
require_once($mosConfig_absolute_path.'/administrator/components/com_virtuemart/virtuemart.cfg.php');
        require_once( 
CLASSPATH'ps_main.php');
        
require_once( CLASSPATH"language.class.php" );
require_once(CLASSPATH."Log/Log.php");
$vmLoggerConf = array(
'buffering' => true
);
/**
 * This Log Object will help us log messages and errors
 * See http://pear.php.net/package/Log
 * @global Log vmLogger
 */
$vmLogger = &vmLog::singleton('display'''''$vmLoggerConfPEAR_LOG_TIP);
$GLOBALS['vmLogger'] =& $vmLogger;

        require_once( 
CLASSPATH 'phpmailer/class.phpmailer.php');
        
$mail = new vmPHPMailer();
        
$mail->PluginDir CLASSPATH 'phpmailer/';
        
$mail->SetLanguage("en"CLASSPATH 'phpmailer/language/');
              
        
/* load the VirtueMart Language File */
        
if (file_existsADMINPATH'languages/'.$mosConfig_lang.'.php' ))
          require_once( 
ADMINPATH'languages/'.$mosConfig_lang.'.php' );
        else
          require_once( 
ADMINPATH'languages/english.php' );
        
        
/* Load the Worldpay Configuration File */ 
        
require_once( CLASSPATH'payment/ps_worldpay.cfg.php' );
        
        
/* Load the VirtueMart database class */
        
require_once( CLASSPATH'ps_database.php' );
        
    // restart session
    require_once(CLASSPATH."ps_session.php");

    // Constructor initializes the session!
    $sess = new ps_session();                        
    
    // Include globals; for this, $db is needed, as is htmlTools.class.php
    $db = new ps_DB;
    require_once( CLASSPATH'htmlTools.class.php' );
    require_once( ADMINPATH'global.php' );
    
/*** END VirtueMart part ***/


    
/**
    Read in the post from worldpay.
    Email was used in PayPal version

    **/
    
$workstring 'cmd=_notify-validate'// Notify validate
    
$i 1;
    foreach (
$_POST as $ipnkey => $ipnval) {
        if (
get_magic_quotes_gpc())
            
// Fix issue with magic quotes
            
$ipnval stripslashes ($ipnval);
            
       if (!
eregi("^[_0-9a-z-]{1,30}$",$ipnkey)  || !strcasecmp ($ipnkey'cmd'))  { 
            
// ^ Antidote to potential variable injection and poisoning
            
unset ($ipnkey); 
            unset (
$ipnval); 
        } 
       
// Eliminate the above
        // Remove empty keys (not values)
        
if (@$ipnkey != '') { 
          
//unset ($_POST); // Destroy the original ipn post array, sniff...
          
$workstring.='&'.@$ipnkey.'='.urlencode(@$ipnval); 
        }
       echo 
"key ".$i++.": $ipnkey, value: $ipnval<br />";
    } 
// Notify string

    
$payment_status  trim(stripslashes($_POST['transStatus'])); //if $payment_status == 'Y'?
    
$order_id =  trim(stripslashes($_POST['cartId']));
    
    
$d['order_id'] = $order_id;    //this identifies the order record

    
if( $payment_status == 'Y' ){
        
$d['order_status'] = 'C';  //this is the new value for the database field I think X for cancelled, C for confirmed
    
}
    else if( 
$payment_status == 'C' ){
        
$d['order_status'] = 'X';  //this is the new value for the database field I think X for cancelled, C for confirmed
    
}

    require_once ( 
CLASSPATH 'ps_order.php' );

    
$ps_order= new ps_order;

    
$ps_order->order_status_update($d);
}

?>
Title: Re: My updated worldpay_notify.php
Post by: richrock on December 13, 2007, 17:07:05 PM
Doesn't work for me.  All I get is a Restricted Access error.  I've double checked the callback url, uploaded the worldpay_notify.php again, tested again.  Just a blank page with 'Restricted Access'.

Any ideas?  This is the last part of the setup for me and I just want it over with...
Title: Re: My updated worldpay_notify.php
Post by: Kurosaki on December 19, 2007, 18:33:24 PM
Now I will use worldpay because Paypal sucks, but still I use it.

Since I don't need to send downloads id, only the change of the status the original notify worked fine for me.
Title: Re: My updated worldpay_notify.php
Post by: richrock on December 20, 2007, 10:58:09 AM
Which version are you using?  I still havent got this to work....  :'( :'( :'(
Title: Re: My updated worldpay_notify.php
Post by: Kurosaki on December 20, 2007, 15:56:31 PM
I replyied your PM.

Have you configured your installation ID in the virtuemart payment module editor. If you have enabled and configured your WP admin panel with your callback url now that should work.
Title: Re: My updated worldpay_notify.php
Post by: richrock on December 20, 2007, 16:30:46 PM
Yes to both - this is still not working
Title: Re: My updated worldpay_notify.php
Post by: richrock on January 02, 2008, 11:58:55 AM
I have updated the callback url to

www.sitenamehere.com/administrator/components/com_virtuemart/worldpay_notify.php and set it to full read/write access (to be on the safe side).  Even waited a few hours because I know some changes on Worldpay's servers can take some time to update. 

I tried a sale, and no luck.  I'm beginning to wonder if the worldpay_notify is using deprecated functions in Joomla?

FWIW - Joomla 1.5 RC3, Virtuemart 1.1 Beta2.
Title: Re: My updated worldpay_notify.php
Post by: ReJigged on November 21, 2012, 12:42:30 PM
I'm getting the same. Was this ever solved?

J! 1.5.22
VM 1.1.8

Sales are processed but customer just sees a blank page with 'Restricted access' after payment.