Well,
I tried it and as soon as I changed the file on the server and tried to view an order I got an internal server error:
Here is my code that I modified per your instructions (I THINK. In the future, please post a before and after example code so people can compare and contrast old and new, otherwise you have no way to check yourself):
function order_status_update(&$d) {
global $mosConfig_offset;
$db = new ps_DB;
//$timestamp = time() + ($mosConfig_offset*60*60); //Original
$timestamp = time(); //Custom
//$mysqlDatetime = date("Y-m-d G:i:s",$timestamp); //Original
$mysqlDatetime = date("Y-m-d G:i:s", $timestamp + ($mosConfig_offset*60*60)); //Custom
if( empty($_REQUEST['include_comment'])) {
$include_comment="N";
}
// get the current order status
$curr_order_status = @$d["current_order_status"];
$notify_customer = empty($d['notify_customer']) ? "N" : $d['notify_customer'];
if( $notify_customer=="Y" ) {
$notify_customer=1;
}
else {
$notify_customer=0;
}
$d['order_comment'] = empty($d['order_comment']) ? "" : $d['order_comment'];
if( empty($d['order_item_id']) ) {
// When the order is set to "confirmed", we can capture
// the Payment with authorize.net
if( $curr_order_status=="P" && $d["order_status"]=="C") {
$q = "SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ";
$q .= "#__{vm}_order_payment.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id";
$db->query( $q );
$db->next_record();
$payment_class = $db->f("payment_class");
$d["order_number"] = $db->f("order_number");
switch( $payment_class ) {
case "ps_authorize":
require_once( CLASSPATH."payment/ps_authorize.cfg.php");
if( AN_TYPE == 'AUTH_ONLY' ) {
require_once( CLASSPATH."payment/ps_authorize.php");
$authorize = new ps_authorize();
if( !$authorize->capture_payment( $d )) {
return false;
}
}
break;
default:
// default case for payment methods that allow to "capture" the payment
if( is_file( CLASSPATH.'payment/'.basename($payment_class) ) ) {
require_once( CLASSPATH.'payment/'.basename($payment_class) );
if( !class_exists($payment_class)) break;
$paymentObj = new $payment_class();
if( !method_exists($paymentObj,'capture_payment')) break;
if( !$paymentObj->capture_payment( $d )) {
return false;
}
}
}
}
/*
* This is like the test above for delayed capture only
* we (well, I - durian) don't think the credit card
* should be captured until the item(s) are shipped.
* In fact, VeriSign says not to capture the cards until
* the item ships. Maybe this behavior should be a
* configurable item?
*
* When the order changes from Confirmed or Pending to
* Shipped, perform the delayed capture.
*
* Restricted to PayFlow Pro for now.
*/
if( ($curr_order_status=="P" || $curr_order_status=="C") && $d["order_status"]=="S") {
$q = "SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ";
$q .= "#__{vm}_order_payment.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id";
$db->query( $q );
$db->next_record();
$payment_class = $db->f("payment_class");
if( $payment_class=="payflow_pro" ) {
require_once( CLASSPATH."payment/payflow_pro.cfg.php");
if( PFP_TYPE == 'A' ) {
require_once( CLASSPATH."payment/payflow_pro.php");
$pfp = new ps_pfp();
$d["order_number"] = $db->f("order_number");
if( !$pfp->capture_payment( $d )) {
return false;
}
}
}
}
/*
* If a pending order gets cancelled, void the authorization.
*
* It might work on captured cards too, if we want to
* void shipped orders.
*
* Restricted to PayFlow Pro for now.
*/
if( $curr_order_status=="P" && $d["order_status"]=="X") {
$q = "SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ";
$q .= "#__{vm}_order_payment.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id";
$db->query( $q );
$db->next_record();
$payment_class = $db->f("payment_class");
if( $payment_class=="payflow_pro" ) {
require_once( CLASSPATH."payment/payflow_pro.cfg.php");
if( PFP_TYPE == 'A' ) {
require_once( CLASSPATH."payment/payflow_pro.php");
$pfp = new ps_pfp();
$d["order_number"] = $db->f("order_number");
if( !$pfp->void_authorization( $d )) {
return false;
}
}
}
}
$fields =array( 'order_status'=> $d["order_status"],
'mdate'=> $timestamp );
$db->buildQuery('UPDATE', '#__{vm}_orders', $fields, "WHERE order_id='" . $db->getEscaped($d["order_id"]) . "'");
$db->query();
// Update the Order History.
$fields = array( 'order_id' => $d["order_id"],
'order_status_code' => $d["order_status"],
'date_added' => $mysqlDatetime,
'customer_notified' => $notify_customer,
'comments' => $d['order_comment']
);
$db->buildQuery('INSERT', '#__{vm}_order_history', $fields );
$db->query();
// Do we need to re-update the Stock Level?
if( (strtoupper($d["order_status"]) == "X" || strtoupper($d["order_status"])=="R")
// && CHECK_STOCK == '1'
&& $curr_order_status != $d["order_status"]
) {
// 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='".$db->getEscaped($d["order_id"])."'";
$db->query( $q );
$dbu = new ps_DB;
require_once( CLASSPATH.'ps_product.php');
// Now update each ordered product
while( $db->next_record() ) {
if( ENABLE_DOWNLOADS == '1' && ps_product::is_downloadable($db->f("product_id")) && VM_DOWNLOADABLE_PRODUCTS_KEEP_STOCKLEVEL == '1') {
$q = "UPDATE #__{vm}_product
SET product_sales=product_sales-".$db->f("product_quantity")."
WHERE product_id=".$db->f("product_id");
$dbu->query( $q );
}
else {
$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 );
}
}
}
// Update the Order Items' status
$q = "SELECT order_item_id FROM #__{vm}_order_item WHERE order_id=".$db->getEscaped($d['order_id']);
$db->query($q);
$dbu = new ps_DB;
while ($db->next_record()) {
$item_id = $db->f("order_item_id");
$fields =array( 'order_status'=> $d["order_status"],
'mdate'=> $timestamp );
$dbu->buildQuery('UPDATE', '#__{vm}_order_item', $fields, "WHERE order_item_id='" .(int)$item_id . "'");
$dbu->query();
}
if (ENABLE_DOWNLOADS == '1') {
##################
## DOWNLOAD MOD
$this->mail_download_id( $d );
}
if( !empty($notify_customer) ) {
$this->notify_customer( $d );
}
} elseif( !empty($d['order_item_id'])) {
// Update the Order Items' status
$q = "SELECT order_item_id, product_id, product_quantity FROM #__{vm}_order_item
WHERE order_id=".$db->getEscaped($d['order_id'])
. ' AND order_item_id='.intval( $d['order_item_id'] );
$db->query($q);
$item_product_id = $db->f('product_id');
$item_product_quantity = $db->f('product_quantity');
if( ENABLE_DOWNLOADS == '1' && ps_product::is_downloadable($item_product_id) && VM_DOWNLOADABLE_PRODUCTS_KEEP_STOCKLEVEL == '1') {
$q = "UPDATE #__{vm}_product
SET product_sales=product_sales-".$item_product_quantity."
WHERE product_id=".$item_product_id;
$db->query( $q );
}
else {
$q = "UPDATE #__{vm}_product
SET product_in_stock=product_in_stock+".$item_product_quantity.",
product_sales=product_sales-".$item_product_quantity."
WHERE product_id=".$item_product_id;
$db->query( $q );
}
$fields =array( 'order_status'=> $d["order_status"],
'mdate'=> $timestamp );
$db->buildQuery('UPDATE', '#__{vm}_order_item', $fields, 'WHERE order_item_id='.intval( $d['order_item_id'] ));
return $db->query() !== false;
}
//echo "RUNNING PCI COMPLIANCE";
//make sure we are PCI DSS Compliant, eradicate customer credit card codes that have been processed.
$this->pcidss_compliance();
return true;
}
function pcidss_compliance(){
/* For PCI compliance we may only store the last four digits and the CVV must not be stored, setting to general 000,
convert the credit card number to ############1234 (keep last four digits for future discussions with customer,
'the card ends in.....'
*/
$q = "SELECT `#__{vm}_order_payment`.`order_id`, order_payment_code,
".VM_DECRYPT_FUNCTION."(order_payment_number,'".ENCODE_KEY."') AS creditCardNumber,
CHAR_LENGTH(".VM_DECRYPT_FUNCTION."(order_payment_number,'".ENCODE_KEY."')) AS creditCardLength
FROM
`#__{vm}_order_payment` LEFT JOIN `#__{vm}_orders` ON
`#__{vm}_order_payment`.`order_id` = `#__{vm}_orders`.`order_id`
WHERE
order_status != 'P'
AND CHAR_LENGTH(".VM_DECRYPT_FUNCTION."( order_payment_number, '".ENCODE_KEY."' )) > 8
AND LEFT( ".VM_DECRYPT_FUNCTION."( order_payment_number, '".ENCODE_KEY."' ), 8 ) != '########'";
$db = new ps_DB;
$dbUpdate = new ps_DB;
$mask = '##########################'; //24 mask characters, most cards are 16 but some are 17/18 so built in extra
$db->query( $q );
// Now update each ordered product
while( $db->next_record() ) {
//print "UPDATING ".$db->f("order_id");
$q = "UPDATE #__{vm}_order_payment SET
order_payment_code = '000', order_payment_number =
".
VM_ENCRYPT_FUNCTION."('".substr($mask, 0, $db->f("creditCardLength") - 4) . substr($db->f("creditCardNumber"), -4)."','".ENCODE_KEY."')
WHERE order_id = ".$db->f("order_id").";";
//echo $q."<br/>";
$dbUpdate->query( $q );
}
}
I don't know programming lingo, Is this code correct?