|
This is how to get worldpay_notify.php call back working for virtuemart 1.1.4 and joomla 1.5. I will be modifying it soon to email the customer with the new confirmed/cancelled status of their order. The worldpay_notify.php does not work that is included with the virtue mart extension for joomla. Download worldpay_notifiy.zip which contains the code below.
//error_reporting(E_ALL); //ini_set("display_errors", 1);
/* * @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 */ define ('PAYPAL_DEBUG', '0');
$messages = Array(); function debug_msg( $msg ) { global $messages; if( PAYPAL_DEBUG == "1" ) { if( !defined( "_DEBUG_HEADER") ) { echo "PayPal Notify.php Debug OUTPUT"; define( "_DEBUG_HEADER", "1" ); } $messages[] = "$msg "; echo end( $messages ); } } if ($_POST) { header("HTTP/1.0 200 OK");
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")) { $absolute_path = dirname( $my_path."/../../../configuration.php" ); require_once($my_path."/../../../configuration.php"); } elseif( file_exists($my_path."/../../configuration.php")){ $absolute_path = dirname( $my_path."/../../configuration.php" ); require_once($my_path."/../../configuration.php"); } elseif( file_exists($my_path."/configuration.php")){ $absolute_path = dirname( $my_path."/configuration.php" ); require_once( $my_path."/configuration.php" ); } else { die( "Joomla Configuration File not found!" ); } $absolute_path = realpath( $absolute_path ); // Set up the appropriate CMS framework if( class_exists( 'jconfig' ) ) { define( '_JEXEC', 1 ); define( 'JPATH_BASE', $absolute_path ); define( 'DS', DIRECTORY_SEPARATOR ); // Load the framework require_once ( JPATH_BASE . DS . 'includes' . DS . 'defines.php' ); require_once ( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
// create the mainframe object $mainframe = & JFactory::getApplication( 'site' ); // Initialize the framework $mainframe->initialise(); // load system plugin group JPluginHelper::importPlugin( 'system' ); // trigger the onBeforeStart events $mainframe->triggerEvent( 'onBeforeStart' ); $lang =& JFactory::getLanguage(); $mosConfig_lang = $GLOBALS['mosConfig_lang'] = strtolower( $lang->getBackwardLang() ); // Adjust the live site path $mosConfig_live_site = str_replace('/administrator/components/com_virtuemart', '', JURI::base()); $mosConfig_absolute_path = JPATH_BASE; } else { define('_VALID_MOS', '1'); require_once($mosConfig_absolute_path. '/includes/joomla.php'); require_once($mosConfig_absolute_path. '/includes/database.php'); $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix ); $mainframe = new mosMainFrame($database, 'com_virtuemart', $mosConfig_absolute_path ); }
// 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 ***/ debug_msg( "1. Finished Initialization of the worldpay_notify.php script" );
/*** VirtueMart part ***/
define('PHPSHOPPATH', $mosConfig_absolute_path.'/administrator/components/com_virtuemart/');
require_once( PHPSHOPPATH."virtuemart.cfg.php");
require_once( CLASSPATH. "language.class.php" ); debug_msg( "1a. Included language class" );
//Set up the mailer to infor Warehouse of validated order //require_once( $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php'); //$mail = new mosPHPMailer(); //$mail->PluginDir = $mosConfig_absolute_path . '/includes/phpmailer/'; //$mail->SetLanguage("en", $mosConfig_absolute_path . '/includes/phpmailer/language/');
/* load the VirtueMart Language File */ /* if (file_exists( ADMINPATH. 'languages/admin/'.$mosConfig_lang.'.php' )) { require_once( ADMINPATH. 'languages/admin/'.$mosConfig_lang.'.php' ); } else { require_once( ADMINPATH. 'languages/admin/english.php' ); } */ debug_msg( "2. Included admin language files" );
/* Moded Gotta replace this...perhaps Load the PayPal Configuration File */ require_once( CLASSPATH. 'payment/ps_worldpay.cfg.php' );
/* Load the VirtueMart database class */ require_once( CLASSPATH. 'ps_database.php' ); debug_msg( "3. PS_database loaded" );
/*** 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 "; } // Notify string debug_msg( "4. Got post values" );
$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); debug_msg( "5. Updated Table" );
}
|