Skip to content

Instantly share code, notes, and snippets.

@EdwardIII
Created January 17, 2013 11:24
Show Gist options
  • Save EdwardIII/4555306 to your computer and use it in GitHub Desktop.
Save EdwardIII/4555306 to your computer and use it in GitHub Desktop.
<?php
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 ***/
/*** VirtueMart part ***/
require_once($mosConfig_absolute_path.'/administrator/components/com_virtuemart/virtuemart.cfg.php');
include_once( ADMINPATH.'/compat.joomla1.5.php' );
require_once( ADMINPATH. 'global.php' );
require_once( CLASSPATH. 'ps_main.php' );
/* @MWM1: Logging enhancements (file logging & composite logger). */
$vmLogIdentifier = "notify.php";
require_once(CLASSPATH."Log/LogInit.php");
// restart session
// Constructor initializes the session!
$sess = new ps_session();
/*** END VirtueMart part ***/
}
global $vendor_mail, $vendor_currency, $VM_LANG, $vmLogger;
$database = new ps_DB;
$ps_vendor_id = $_SESSION["ps_vendor_id"];
$auth = $_SESSION['auth'];
//$ps_checkout = new ps_checkout;
require_once(CLASSPATH ."payment/ps_realex.cfg.php");
$html = '<html><head></head><body>';
$timestamp = $_POST['TIMESTAMP'];
$result = $_POST['RESULT'];
$orderid = $_POST['ORDER_ID'];
$message = $_POST['MESSAGE'];
$authcode = $_POST['AUTHCODE'];
$pasref = $_POST['PASREF'];
$realexmd5 = $_POST['MD5HASH'];
//get the information from the module configuration
$merchantid = REALEX_MERCHANTID;
$secret = REALEX_SHARED_SECRET;
$tmp = "$timestamp.$merchantid.$orderid.$result.$message.$pasref.$authcode";
$md5hash = md5($tmp);
$tmp = "$md5hash.$secret";
$md5hash = md5($tmp);
$d['order_id'] = $orderid; //this identifies the order record
//Check to see if hashes match or not
if ($md5hash != $realexmd5) {
$html .= "The hashes do not match - response not authenticated!";
$d['order_status'] = REALEX_INVALID_STATUS; // set order status to cancelled
}else{
if ($result == "00") {
$html .= REALEX_SUCCESS_MESSAGE . '<br/><br/>';
$html .= 'To continue browsing please <a href=' . URL . '><b><u>click here</u></b></a><br/><br/>';
$d['order_status'] = REALEX_VERIFIED_STATUS; // set order status to confirmed
$d["order_payment_trans_id"] = $authcode;
$d["order_payment_log"] = 'AuthCode: ' . $authcode . ' ';
$d["order_payment_log"] = 'PasRef: ' . $pasref . ' ';
$d["order_payment_log"] .= 'CVN Result: ' . $_POST['CVNRESULT'] . ' ';
$d["order_payment_log"] .= 'AVS Postcode Response: ' . $_POST['AVSPOSTCODERESPONSE'] . ' ';
$d["order_payment_log"] .= 'AVS Address Response: ' . $_POST['AVSADDRESSRESPONSE'] . ' ';
}else{
$html .= REALEX_ERROR_MESSAGE . '<br/><br/>';
$html .= 'To try again please <a href=' . URL . '><b><u>click here</u></b></a><br /><br />';
$d['order_status'] = REALEX_INVALID_STATUS; // set order status to cancelled
}
}
$d['notify_customer'] = true;
$d['order_comment'] = $d["order_payment_log"];
$html .= '<script type="text/javascript">setTimeout("window.location = \"' . URL . '\"", 5000);</script></body></html>';
require_once ( CLASSPATH . 'ps_order.php' );
$ps_order= new ps_order;
$ps_order->order_status_update($d);
echo $html;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment