This is my full code of file mytemplate.php
<?php
ini_set("display_errors", 0);
/**
* Template Name: My Order Result
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
//this code use both GET and POST method
$mTransactionID = $_REQUEST['mTransactionID'];
$bankCode = $_REQUEST['bankCode'];
$transactionStatus = $_REQUEST['transactionStatus'];
$description = $_REQUEST['description'];
$ts = $_REQUEST['ts'];
$checksum = $_REQUEST['checksum'];
global $woo_options;
global $woocommerce;
require_once(WP_PLUGIN_DIR . '/classes/common.class.php');
require_once(WP_PLUGIN_DIR . '/classes/rest.client.class.php');
include_once(WP_PLUGIN_DIR . '/class-wc-gateway-pay.php');
$gatemay_pay=new WC_Gateway_Paycc();
$sMySecretkey = trim($gatemay_pay->settings['working_key']);//key use to hash checksum that will be provided by Pay
$sRawMyCheckSum = $mTransactionID.$bankCode.$transactionStatus.$ts.$sMySecretkey;
$sMyCheckSum = sha1($sRawMyCheckSum);
if($sMyCheckSum != $checksum)
{
response($mTransactionID, '-1', $sMySecretkey);
}
$iCurrentTS = time();
$iTotalSecond = $iCurrentTS - $ts;
$iLimitSecond = 300;//5 min = 5*60 = 300
$status_num=-1;
$oder_code=0;
$order_id = $wpdb->get_col($wpdb->prepare("SELECT order_id FROM <code>".$wpdb->prefix."order_pay</code> WHERE merchant_transactionID = %s ", $mTransactionID));
$old_status = $wpdb->get_col($wpdb->prepare("SELECT status FROM <code>".$wpdb->prefix."order_pay</code> WHERE merchant_transactionID = %s ", $mTransactionID));
if(is_array($order_id) && isset($order_id[0]) && $order_id[0]>0)
$oder_code=$order_id[0];
if(is_array($old_status) && isset($old_status[0]) && $old_status[0]>0)
$status_num=$old_status[0];
$processResult = process($mTransactionID, $bankCode, $transactionStatus,$status_num,$oder_code,$wpdb);
response($mTransactionID, $processResult, $sMySecretkey);
/*===============================Function region=======================================*/
function process($mTransactionID, $bankCode, $transactionStatus,$status_num,$oder_code,$wpdb)
{
try
{
if($oder_code>0){
$order = new WC_Order($oder_code);
//do you update order status process
if($status_num==1){
return 2;
}
if($transactionStatus==1){
$order->payment_complete();
$order -> add_order_note('Success !');
$order->update_status('Completed','');
}
else{
if($transactionStatus!=$status_num){
$order -> add_order_note('Failed !');
}
}
if($transactionStatus!=$status_num){
$wpdb->query("update <code>".$wpdb->prefix."order_pay</code> set <code>status</code>=".$transactionStatus." where <code>order_id</code>= ".(int)$oder_code);
}
return 1;//if process successfully
}
return -3;
}
catch(Exception $_e)
{
return -3;
}
}
function response($mTransactionID, $returnCode, $key)
{
$ts = time();
$sRawMyCheckSum = $mTransactionID.$returnCode.$ts.$key;
$checksum = sha1($sRawMyCheckSum);
$aData = array(
'mTransactionID' => $mTransactionID,
'returnCode' => $returnCode,
'ts' => time(),
'checksum' => $checksum
);
echo json_encode($aData);
exit;
}
/*===============================End Function region=======================================*/
?>