<?php
// the function returns an MD5 of parameters passed
function ref_sign() {
$params = func_get_args();
$prehash = implode("::", $params);
return md5($prehash);
}
// filtering junk off acquired parameters
foreach($_REQUEST as $request_key => $request_value) {
$_REQUEST[$request_key] = substr(strip_tags(trim($request_value)), 0, 250);
}
// service secret code
$secret_code = trim(SMS_SICRET_CODE);
// collecting required data
$purse = $_REQUEST["s_purse"]; // sms:bank id
$order_id = $_REQUEST["s_order_id"]; // operation id
$amount = $_REQUEST["s_amount"]; // transaction sum
$clear_amount = $_REQUEST["s_clear_amount"]; // billing algorithm
$inv = $_REQUEST["s_inv"]; // operation number
$phone = $_REQUEST["s_phone"]; // phone number
$sign = $_REQUEST["s_sign_v2"]; // signature
// making the reference signature
$reference = ref_sign($secret_code, $purse, $order_id, $amount, $clear_amount, $inv, $phone);
// validating the signature
if($sign == $reference) {
define('_VALID_MOS', '1');
global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_lang, $database,
$mosConfig_mailfrom, $mosConfig_fromname;
/*** access Mambo'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( "Mambo Configuration File not found!" );
if( file_exists ($mosConfig_absolute_path. '/includes/database.php'))
require_once($mosConfig_absolute_path. '/includes/database.php');
else
require_once($mosConfig_absolute_path. '/classes/database.php');
$database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
// 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 ***/
require_once($mosConfig_absolute_path.'/administrator/components/com_virtuemart/virtuemart.cfg.php');
require_once( CLASSPATH. "language.class.php" );
/* 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' );
/* Load the WebMoney Configuration File */
require_once( CLASSPATH. 'payment/ps_webmoney.cfg.php' );
/* Load the VirtueMart database class */
require_once( CLASSPATH. 'ps_database.php' );
$invoice = trim(stripslashes($_POST['sms_invoice']));
$qv = "SELECT order_id, order_number, user_id, order_total FROM #__vm_orders ";
$qv .= "WHERE order_number='".$invoice."'";
$dbbt = new ps_DB;
$dbbt->query($qv);
$dbbt->next_record();
$order_id = $dbbt->f("order_id");
$order_total = $dbbt->f("order_total");
$d['order_id'] = $order_id;
$d['order_total'] = $order_total;
$d['order_status'] = SMSCOIN_VERIFIED_STATUS;
$db = new ps_DB;
$timestamp = time();
$notify_customer = 1;
$q = "UPDATE #__{vm}_orders SET";
$q .= " order_status='" . $d["order_status"] . "' ";
$q .= ", mdate='" . $timestamp . "' ";
$q .= "WHERE order_id='" . $d["order_id"] . "'";
$db->query($q);
// Update the Order History.
$q = "INSERT INTO #__{vm}_order_history ";
$q .= "(order_id,order_status_code,date_added,customer_notified,comments) VALUES (";
$q .= "'".$d["order_id"] . "', '" . $d["order_status"] . "', NOW(), '$notify_customer', '".$d['order_comment']."')";
$db->query($q);
if (ENABLE_DOWNLOADS == '1') {
##################
## DOWNLOAD MOD
$url = $mosConfig_live_site."/index.php?option=com_virtuemart&page=shop.downloads";
if ($d["order_status"]==ENABLE_DOWNLOAD_STATUS) {
$dbw = new ps_DB;
$dbw_2 = new ps_DB;
$q = "SELECT * FROM #__{vm}_product_download WHERE";
$q .= " order_id = '" . $d["order_id"] . "'";
$dbw->query($q);
$dbw->next_record();
$userid = $dbw->f("user_id");
$download_id = $dbw->f("download_id");
$datei=$dbw->f("file_name");
$dbw_2->query($q);
if ($download_id) {
$dbv = new ps_DB;
$q = "SELECT * FROM #__{vm}_vendor ";
$q .= "WHERE vendor_id='1'";
$dbv->query($q);
$dbv->next_record();
$db = new ps_DB;
$q="SELECT first_name,last_name, user_email FROM #__{vm}_user_info WHERE user_id = '$userid' AND address_type='BT'";
$db->query($q);
$db->next_record();
$message = _HI . $db->f("first_name") . " " . $db->f("last_name") . "\n\n";
$message .= $VM_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_1.".\n";
$message .= $VM_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_2."\n\n";
while($dbw_2->next_record()) {
$message .= $dbw_2->f("file_name").": ".$dbw_2->f("download_id")
. "\n$url&download_id=".$dbw_2->f("download_id")."\n\n";
}
$message .= $VM_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_3 . DOWNLOAD_MAX."\n";
$expire = ((DOWNLOAD_EXPIRE / 60) / 60) / 24;
$message .= str_replace("{expire}", $expire, $VM_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_4);
$message .= "\n\n____________________________________________________________\n";
$message .= $VM_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_5."\n";
$message .= $dbv->f("vendor_name") . " \n" . $mosConfig_live_site."\n\n".$dbv->f("contact_email") . "\n";
$message .= "____________________________________________________________\n";
$message .= $VM_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_6 . $dbv->f("vendor_name");
$mail_Body = $message;
$mail_Subject = $VM_LANG->_PHPSHOP_DOWNLOADS_SEND_SUBJ;
require_once( CLASSPATH. 'ps_main.php' );
$result = vmMail( $dbv->f("contact_email"), $dbv->f("vendor_name"),
$db->f("user_email"), $mail_Subject, $mail_Body, '' );
}
}
}
elseif ($d["order_status"] == DISABLE_DOWNLOAD_STATUS) {
$q = "DELETE FROM #__{vm}_product_download WHERE order_id=" . $d["order_id"];
$db->query($q);
$db->next_record();
}
$d['order_status'] = $VM_LANG->_PHPSHOP_SMSCOIN_ORDER_STATUS;
} else {
// failure, reporting error
$order_status = SMSCOIN_INVALID_STATUS;
$timestamp = time();
$notify_customer = 0;
if( ($order_status == "X" || $order_status =="R" ||
$order_status == "x" || $order_status =="r") &&
CHECK_STOCK == '1'
) {
// Get the order items and update the stock level
// to the number before the order was placed
$q = "SELECT product_id, product_quantity FROM #__{vm}_order_item WHERE order_id='".$d['order_id']."'";
$db = new ps_DB;
$db->query( $q );
$dbu = new ps_DB;
// Now update each ordered product
while( $db->next_record() ) {
$q = "UPDATE #__{vm}_product SET product_in_stock=product_in_stock+".$db->f("product_quantity")
.",product_sales=product_sales-".$db->f("product_quantity")." WHERE product_id='".$db->f("product_id")."'";
$dbu->query( $q );
}
$q = "UPDATE #__{vm}_orders SET";
$q .= " order_status='" . $order_status . "' ";
$q .= ", mdate='" . $timestamp . "' ";
$q .= "WHERE order_id='" . $d["order_id"] . "'";
$db->query($q);
// Update the Order History.
$q = "INSERT INTO #__{vm}_order_history ";
$q .= "(order_id,order_status_code,date_added,customer_notified,comments) VALUES (";
$q .= "'".$d["order_id"] . "', '" . $d["order_status"] . "', NOW(), '$notify_customer', '".$d['order_comment']."')";
$db->query($q);
}
}
?>