<?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 [URL unfurl="true"]http://www.gnu.org/copyleft/gpl.html[/URL] GNU/GPL
* VirtueMart is Free Software.
* VirtueMart comes with absolute no warranty.
*
* [URL unfurl="true"]www.virtuemart.net[/URL]
*/
if ($_POST) {
WriteFile("Start of file");
define('_VALID_MOS', '1');
global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_lang;
WriteFile("Mambo config");
/*** access Mambo's configuration file ***/
$my_path = dirname($_SERVER['SCRIPT_FILENAME']);
WriteFile("Script_Filename=" . $my_path);
WriteFile("Mambo config 1");
$mambo_path = str_replace("administrator/components/com_virtuemart", "", $my_path);
WriteFile("Mambo_path=" . $mambo_path);
WriteFile("Mambo config 2");
require_once($mambo_path.'configuration.php');
WriteFile("Mambo config 3");
// ######### ERROR HAPPENS ON LINE BELOW ############
require_once($mambo_path.'includes/database.php');
WriteFile("Mambo config 4");
global $database;
WriteFile("Mambo config 5");
$database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
WriteFile("Mambo language");
// load Mambo Language File
if (file_exists( $mosConfig_absolute_path. '/language/'.$mosConfig_lang.'.php' )){
require_once( $mosConfig_absolute_path. '/language/'.$mosConfig_lang.'.php' );
}
else{
require_once( $mosConfig_absolute_path. '/language/english.php' );
}
/*** END of Mambo config ***/
/*** VirtueMart part ***/
WriteFile("Virtuemart part");
define('PHPSHOPPATH', $mosConfig_absolute_path.'/administrator/components/com_virtuemart/');
require_once(PHPSHOPPATH."virtuemart.cfg.php");
require_once( CLASSPATH. "language.class.php" );
//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/');
WriteFile("Virtuemart language");
/* load the VirtueMart Language File */
if (file_exists( ADMINPATH. 'languages/'.$mosConfig_lang.'.php' ))
require_once( ADMINPATH. 'languages/'.$mosConfig_lang.'.php' );
else
require_once( ADMINPATH. 'languages/english.php' );
/*
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' );
/*** END VirtueMart part ***/
/**
Read in the post from worldpay.
Email was used in PayPal version
**/
WriteFile("Start of foreach");
$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
WriteFile("Payment Status");
$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
}
//Write $_POST to file
WriteFile("ps_order.php");
require_once ( CLASSPATH . 'ps_order.php' );
$ps_order= new ps_order;
$ps_order->order_status_update($d);
WriteFile("EOF");
}
function WriteFile($msg)
{
$d = date('d.m.y H.i.s');
$fh = fopen("mylog.txt", 'a');
fwrite($fh, $d . $msg . "\n");
fclose($fh);
}
?>