function edd_process_paytm_gateway_ipn()
{
    global $edd_options;
    if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
        return;
    }
    $payment_id = $_GET['payment_id'];
    if (empty($payment_id)) {
        edd_send_back_to_checkout('?payment-mode=paytm_gateway');
    }
    // Fallback just in case post_max_size is lower than needed
    if (isset($_POST['ORDERID']) && isset($_POST['RESPCODE'])) {
        $order_sent = $_POST['ORDERID'];
        $responseDescription = $_POST['RESPMSG'];
        if ($_POST['RESPCODE'] == '01') {
            // success
            $order_sent = $_POST['ORDERID'];
            $res_code = $_POST['RESPCODE'];
            $responseDescription = $_POST['RESPMSG'];
            $checksum_recv = $_POST['CHECKSUMHASH'];
            $paramList = $_POST;
            $order_amount = $_POST['TXNAMOUNT'];
            //  code by paytm team
            $bool = "FALSE";
            $secret_key = $edd_options['paytm_mer_access_key'];
            $bool = verifychecksum_e($paramList, $secret_key, $checksum_recv);
            if ($bool == "TRUE") {
                $payment_meta = edd_get_payment_meta($payment_id);
                edd_insert_payment_note($payment_id, sprintf(__('Thank you for your order . Your transaction has been successful. Paytm Transaction ID: %s', 'edd'), $_REQUEST['TXNID']));
                edd_set_payment_transaction_id($payment_id, $_REQUEST['TXNID']);
                edd_update_payment_status($payment_id, 'complete');
                edd_empty_cart();
                edd_send_to_success_page();
            } else {
                edd_record_gateway_error(__('Paytm Error', 'edd'), sprintf(__('Transaction Failed Invalid Checksum', 'edd'), ''), $payment_id);
                edd_update_payment_status($payment_id, 'failed');
                edd_insert_payment_note($payment_id, sprintf(__('Transaction Failed Invalid Checksum', 'edd'), ''));
                wp_redirect('?page_id=6&payment-mode=paytm_gateway');
                //edd_send_back_to_checkout( '?payment-mode=paytm_gateway' );
            }
        } else {
            edd_record_gateway_error(__('Paytm Error', 'edd'), sprintf(__('Transaction Failed. %s', 'edd'), $responseDescription), $payment_id);
            edd_update_payment_status($payment_id, 'failed');
            edd_insert_payment_note($payment_id, sprintf(__('Transaction Failed. %s', 'edd'), $responseDescription));
            wp_redirect('?page_id=6&payment-mode=paytm_gateway');
        }
    } else {
        edd_record_gateway_error(__('Paytm Error', 'edd'), sprintf(__('Transaction Failed, No Response ', 'edd'), ''), $payment_id);
        edd_update_payment_status($payment_id, 'failed');
        edd_insert_payment_note($payment_id, sprintf(__('Transaction Failed, No Response ', 'edd'), ''));
        wp_redirect('?page_id=6&payment-mode=paytm_gateway');
    }
    exit;
}
 public function postProcess()
 {
     $order_id = $_POST['ORDERID'];
     $res_code = $_POST['RESPCODE'];
     $res_desc = $_POST['RESPMSG'];
     $checksum_recv = $_POST['CHECKSUMHASH'];
     $paramList = $_POST;
     //var_dump($paramList);
     $secret_key = Configuration::get('PayTM_SECRET_KEY');
     $order_amount = $_POST['TXNAMOUNT'];
     $bool = "FALSE";
     $bool = verifychecksum_e($paramList, $secret_key, $checksum_recv);
     /*if(isset($DR)){
     			$DR = preg_replace("/\s/","+",$DR);
     			$rc4 = new Crypt_RC4($secret_key);
     			$QueryString = base64_decode($DR);
     			$rc4->decrypt($QueryString);
     			$QueryString = explode('&',$QueryString);
     			$response = array();
     			foreach($QueryString as $param){
     				$param = explode('=',$param);
     				$response[$param[0]] = urldecode($param[1]);
     				array(8) { ["RESPCODE"]=> string(3) "141" ["RESPMSG"]=> string(26) "Cancel Request by Customer" ["STATUS"]=> string(11) "TXN_FAILURE" ["MID"]=> string(20) "pebble49164290093828" ["TXNAMOUNT"]=> string(3) "199" ["ORDERID"]=> string(4) "1105" ["TXNID"]=> string(4) "9051" ["CHECKSUMHASH"]=> string(108) "8JTqSis+Uqe2iVMo/vWLgjFQkay2pZQkoN/uUVaBbkZrwkYEZMXIKfKy9NfYd2Fk9JaHiemzwNVpfRJrqiWzyeDWxZSJBhCi5NBEaTdbcZA=" } 
     			}
     		}*/
     $cartID = $order_id;
     $extras = array();
     $extras['transaction_id'] = $_POST['TXNID'];
     $cart = new Cart(intval($cartID));
     $amount = $cart->getOrderTotal(true, Cart::BOTH);
     $responseMsg = $_POST['RESPMSG'];
     if ($bool == "TRUE") {
         if ($res_code == "01") {
             $status_code = "Ok";
             $message = "Transaction Successful";
             // $status = "15" ;
             $status = Configuration::get('Paytm_ID_ORDER_SUCCESS');
         } else {
             if ($res_code == "141") {
                 $responseMsg = "Transaction Cancelled. ";
                 $message = "Transaction Cancelled";
                 $status = "6";
             } else {
                 $responseMsg = "Transaction Failed. ";
                 $message = "Transaction Failed";
                 $status = Configuration::get('Paytm_ID_ORDER_FAILED');
             }
         }
     } else {
         $status_code = "Failed";
         $responseMsg = "Security Error ..!";
         $status = Configuration::get('Paytm_ID_ORDER_FAILED');
     }
     $history_message = $responseMsg . '. Paytm Payment ID: ' . $_POST['TXNID'];
     $obj = new Paytm();
     $obj->validateOrder(intval($cart->id), $status, $order_amount, $obj->displayName, $history_message, $extras, '', false, $cart->secure_key);
     $this->context->smarty->assign(array('status' => $status_code, 'responseMsg' => $message, 'this_path' => $this->module->getPathUri(), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->module->name . '/'));
     $cart_qties == 0;
     $cart->delete();
     $this->setTemplate('payment_response.tpl');
 }
}
// Handling response from paytm
if (defined('PAYMENT_NOTIFICATION')) {
    $joint_order_id = explode("-", $_POST['ORDERID']);
    $order_id = $joint_order_id[0];
    $res_code = $_POST['RESPCODE'];
    $res_desc = $_POST['RESPMSG'];
    $checksum_recv = $_POST['CHECKSUMHASH'];
    $paramList = $_POST;
    if (fn_check_payment_script('paytm.php', $order_id, $processor_data)) {
        if (empty($processor_data)) {
            $processor_data = fn_get_processor_data($order_info['email']);
        }
        $secret_key = $processor_data["processor_params"]['secret_key'];
        $bool = "FALSE";
        $bool = verifychecksum_e($paramList, $secret_key, $checksum_recv);
        $paytmTxnIdText = "";
        if (isset($_POST['TXNID']) && !empty($_POST['TXNID'])) {
            $paytmTxnIdText = " Paytm Transaction Id : " . $_POST['TXNID'];
        }
        if (!empty($order_id)) {
            if (fn_check_payment_script('paytm.php', $order_id, $processor_data)) {
                $pp_response = array();
                $order_info = fn_get_order_info($order_id);
                if ($bool == "TRUE") {
                    if ($_REQUEST['RESPCODE'] == 01) {
                        $pp_response['order_status'] = 'P';
                        $pp_response['reason_text'] = "Thank you. Your order has been processed successfully." . $paytmTxnIdText;
                    } else {
                        $pp_response['order_status'] = 'F';
                        $pp_response['reason_text'] = "Thank you. Your order has been unsuccessfull" . $paytmTxnIdText;
 public function callback()
 {
     require_once DIR_SYSTEM . 'encdec_paytm.php';
     require_once DIR_SYSTEM . 'paytm_constants.php';
     $param = array();
     foreach ($_POST as $key => $value) {
         if ($key != "route") {
             $param[$key] = $_REQUEST[$key];
         }
     }
     $isValidChecksum = false;
     $txnstatus = false;
     $authStatus = false;
     $mer = htmlspecialchars_decode(decrypt_e($this->config->get('paytm_key'), $const1), ENT_NOQUOTES);
     $mer = rtrim($mer);
     if (isset($_REQUEST['CHECKSUMHASH'])) {
         $checksum = htmlspecialchars_decode($_REQUEST['CHECKSUMHASH']);
         $return = verifychecksum_e($param, $mer, $_REQUEST['CHECKSUMHASH']);
         if ($return == "TRUE") {
             $isValidChecksum = true;
         }
     }
     $order_id = $_REQUEST['ORDERID'];
     $this->load->model('checkout/order');
     $order_info = $this->model_checkout_order->getOrder($order_id);
     if ($param['STATUS'] == "TXN_SUCCESS") {
         $txnstatus = true;
     }
     if ($order_info) {
         $this->language->load('payment/paytm');
         $this->data['title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_name'));
         $this->data['language'] = $this->language->get('code');
         $this->data['direction'] = $this->language->get('direction');
         $this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_name'));
         $this->data['text_response'] = $this->language->get('text_response');
         $this->data['text_success'] = $this->language->get('text_success');
         $this->data['text_success_wait'] = sprintf($this->language->get('text_success_wait'), $this->url->link('checkout/success'));
         $this->data['text_failure'] = $this->language->get('text_failure');
         $this->data['text_failure_wait'] = sprintf($this->language->get('text_failure_wait'), $this->url->link('checkout/cart'));
         if ($txnstatus && $isValidChecksum) {
             $authStatus = true;
             $this->load->model('checkout/order');
             if ($authStatus == false) {
                 // 					$this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'),$this->language->get('auth_query_mismatch'));
                 // 					$this->model_checkout_order->update($order_id, 10,$this->language->get('auth_query_mismatch'),false);
                 $this->data['continue'] = $this->url->link('checkout/cart');
                 if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paytm_failure.tpl')) {
                     $this->template = $this->config->get('config_template') . '/template/payment/paytm_failure.tpl';
                 } else {
                     $this->template = 'default/template/payment/paytm_failure.tpl';
                 }
             } else {
                 $this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'));
                 $this->model_checkout_order->update($order_id, $this->config->get('paytm_order_status_id'), '', false);
                 $this->data['continue'] = $this->url->link('checkout/success');
                 if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paytm_success.tpl')) {
                     $this->template = $this->config->get('config_template') . '/template/payment/paytm_success.tpl';
                 } else {
                     $this->template = 'default/template/payment/paytm_success.tpl';
                 }
             }
             $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
             $this->response->setOutput($this->render());
         } else {
             $this->load->model('checkout/order');
             // 				if ($isValidChecksum == false) {
             // 					$this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'), $this->language->get('checksum_mismatch'));
             // 					$this->model_checkout_order->update($order_id, 1,$this->language->get('checksum_mismatch'),false);
             // 				}
             // 				else if ($param['STATUS'] == "TXN_FAILURE") {
             // 					$message = 'Txn Failed';
             // 					$this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'),$messge);
             // 					$this->model_checkout_order->update($order_id, 10,$message,false);
             // 				}
             $this->data['continue'] = $this->url->link('checkout/cart');
             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paytm_failure.tpl')) {
                 $this->template = $this->config->get('config_template') . '/template/payment/paytm_failure.tpl';
             } else {
                 $this->template = 'default/template/payment/paytm_failure.tpl';
             }
             $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
             $this->response->setOutput($this->render());
         }
     }
 }
 /**
  * Check for valid paytm server callback // response processing //
  **/
 function check_paytm_response()
 {
     global $woocommerce;
     if (isset($_POST['ORDERID']) && isset($_POST['RESPCODE'])) {
         $order_sent = $_POST['ORDERID'];
         $responseDescription = $_POST['RESPMSG'];
         if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) {
             $order = new WC_Order($_POST['ORDERID']);
         } else {
             $order = new woocommerce_order($_POST['ORDERID']);
         }
         if ($this->log == "yes") {
             error_log("Response Code = " . $_POST['RESPCODE']);
         }
         $redirect_url = $this->redirect_page_id == "" || $this->redirect_page_id == 0 ? get_site_url() . "/" : get_permalink($this->redirect_page_id);
         $this->msg['class'] = 'error';
         $this->msg['message'] = "Thank you for shopping with us. However, the transaction has been Failed For Reason  : " . $responseDescription;
         if ($_POST['RESPCODE'] == 01) {
             // success
             $order_amount = $order->order_total;
             if ($_POST['TXNAMOUNT'] == $order_amount) {
                 if ($this->log == "yes") {
                     error_log("amount matched");
                 }
                 // code by paytm team
                 $order_sent = $_POST['ORDERID'];
                 $res_code = $_POST['RESPCODE'];
                 $responseDescription = $_POST['RESPMSG'];
                 $checksum_recv = $_POST['CHECKSUMHASH'];
                 $paramList = $_POST;
                 $order_amount = $_POST['TXNAMOUNT'];
                 //  code by paytm team
                 $all = $paramList;
                 if ($this->log == "yes") {
                     error_log("received parameters = " . $all);
                 }
                 $bool = "FALSE";
                 $bool = verifychecksum_e($paramList, $this->secret_key, $checksum_recv);
                 //$newcheck = Checksum::calculateChecksum($this->secret_key, $all);
                 if ($this->log == "yes") {
                     error_log("calculated checksum = " . $newch . " and checksum received = " . $_POST['CHECKSUMHASH']);
                 }
                 if ($bool == "TRUE") {
                     if ($order->status !== 'completed') {
                         error_log("SUCCESS");
                         $this->msg['message'] = "Thank you for your order . Your transaction has been successful.";
                         $this->msg['class'] = 'success';
                         if ($order->status == 'processing') {
                         } else {
                             $order->payment_complete();
                             $order->add_order_note('Mobile Wallet payment successful');
                             $order->add_order_note($this->msg['message']);
                             $woocommerce->cart->empty_cart();
                         }
                     }
                 } else {
                     // server to server failed while call//
                     //error_log("api process failed");
                     $this->msg['class'] = 'error';
                     $this->msg['message'] = "Severe Error Occur.";
                     $order->update_status('failed');
                     $order->add_order_note('Failed');
                     $order->add_order_note($this->msg['message']);
                 }
             } else {
                 // Order mismatch occur //
                 //error_log("order mismatch");
                 $this->msg['class'] = 'error';
                 $this->msg['message'] = "Order Mismatch Occur";
                 $order->update_status('failed');
                 $order->add_order_note('Failed');
                 $order->add_order_note($this->msg['message']);
             }
         } else {
             $order->update_status('failed');
             $order->add_order_note('Failed');
             $order->add_order_note($responseDescription);
             $order->add_order_note($this->msg['message']);
         }
         add_action('the_content', array(&$this, 'paytmShowMessage'));
         $redirect_url = $this->redirect_page_id == "" || $this->redirect_page_id == 0 ? get_site_url() . "/" : get_permalink($this->redirect_page_id);
         //For wooCoomerce 2.0
         $redirect_url = add_query_arg(array('msg' => urlencode($this->msg['message']), 'type' => $this->msg['class']), $redirect_url);
         wp_redirect($redirect_url);
         exit;
     }
 }
$gatewaymodule = "paytm";
$GATEWAY = getGatewayVariables($gatewaymodule);
$response = array();
$response = $_POST;
if (isset($response['ORDERID']) && isset($response['STATUS']) && isset($response['RESPCODE']) && $response['RESPCODE'] != 325) {
    $txnid = $response['ORDERID'];
    $txnid = checkCbInvoiceID($txnid, 'paytm');
    $status = $response['STATUS'];
    $paytm_trans_id = $response['TXNID'];
    $checksum_recv = '';
    $amount = $response['TXNAMOUNT'];
    if (isset($response['CHECKSUMHASH'])) {
        $checksum_recv = $response['CHECKSUMHASH'];
    }
    checkCbTransID($paytm_trans_id);
    $checksum_status = verifychecksum_e($response, html_entity_decode($GATEWAY['merchant_key']), $checksum_recv);
    if ($status == 'TXN_SUCCESS' && $checksum_status == "TRUE") {
        $gatewayresult = "success";
        addInvoicePayment($txnid, $paytm_trans_id, $amount, $gatewaymodule);
        logTransaction($GATEWAY["name"], $response, $response['RESPMSG']);
    } elseif ($status == "TXN_SUCCESS" && $checksum_status != "TRUE") {
        logTransaction($GATEWAY["name"], $response, "Checksum Mismatch");
    } else {
        logTransaction($GATEWAY["name"], $response, $response['RESPMSG']);
    }
    $protocol = 'http://';
    $host = '';
    if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == '1')) {
        $protocol = 'https://';
    }
    if (isset($_SERVER["HTTP_HOST"]) && !empty($_SERVER["HTTP_HOST"])) {
 function before_process()
 {
     global $cart;
     $contents = $cart->contents;
     $cart->remove_all();
     $cart->contents = $contents;
     $merchant_key = html_entity_decode(MODULE_PAYMENT_PAYTM_MERCHANT_KEY);
     $paramList = $_POST;
     $paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : "";
     $isValidChecksum = verifychecksum_e($paramList, $merchant_key, $paytmChecksum);
     $resp_code = isset($_POST["RESPCODE"]) ? $_POST["RESPCODE"] : "";
     if ($isValidChecksum) {
         if ($resp_code != "01") {
             tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode("Your payment was not processed. Please try again...!"), 'SSL', true, false));
         }
     } else {
         tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode("Security error...!"), 'SSL', true, false));
     }
 }
 public function processPayment()
 {
     if (!$this->active) {
         return;
     }
     $order_id = $_POST['ORDERID'];
     global $smarty, $cart, $cookie;
     $responseMsg = '';
     if (isset($_POST['RESPCODE']) && $_POST['RESPCODE'] == "01") {
         $secret_key = Configuration::get('Paytm_SECRET_KEY');
         $bool = "FALSE";
         $paramList = $_POST;
         $checksum_recv = $_POST['CHECKSUMHASH'];
         $bool = verifychecksum_e($paramList, $secret_key, $checksum_recv);
         $extra_vars['transaction_id'] = $_POST['TXNID'];
         if ($bool == "TRUE") {
             $customer = new Customer((int) $cart->id_customer);
             parent::validateOrder((int) $order_id, Configuration::get('Paytm_ID_ORDER_SUCCESS'), $_POST['TXNAMOUNT'], $this->displayName, null, $extra_vars, null, true, $cart->secure_key, null);
             $result = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart=' . $order_id);
             $order = new Order($result['id_order']);
             $order->addOrderPayment($_POST['TXNAMOUNT'], null, $_POST['TXNID']);
         } else {
             parent::validateOrder((int) $order_id, Configuration::get('Paytm_ID_ORDER_FAILED'), $_POST['TXNAMOUNT'], $this->displayName, NULL, $extra_vars, '', false, $cart->secure_key);
             $result = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart=' . $order_id);
             $order = new Order($result['id_order']);
             $order->addOrderPayment($_POST['TXNAMOUNT'], null, $_POST['TXNID']);
         }
     } else {
         parent::validateOrder((int) $order_id, Configuration::get('Paytm_ID_ORDER_FAILED'), $_POST['TXNAMOUNT'], $this->displayName, NULL, $extra_vars, '', false, $cart->secure_key);
         $result = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart=' . $order_id);
         $order = new Order($result['id_order']);
         $order->addOrderPayment($_POST['TXNAMOUNT'], null, $_POST['TXNID']);
     }
     $result = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart=' . $order_id);
     Tools::redirectLink(__PS_BASE_URI__ . 'order-detail.php?id_order=' . $result['id_order']);
 }
 public static function maybe_thankyou_page()
 {
     if (!self::is_gravityforms_supported()) {
         return;
     }
     if (!empty($_POST)) {
         $str = RGForms::get("gf_paytm_form_return");
         $str = base64_decode($str);
         $settings = get_option("gf_paytm_form_settings");
         $paytm_key = rgar($settings, "paytm_key");
         $paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : "";
         //Sent by Paytm pg
         $isValidChecksum = verifychecksum_e($_POST, $paytm_key, $paytmChecksum);
         //parse_str($str, $query);
         if ($isValidChecksum == true) {
             $custom = $_POST['ORDERID'];
             list($vv, $entry_id) = explode("-", $custom);
             $entry = RGFormsModel::get_lead($entry_id);
             if (!$entry) {
                 self::log_error("Entry could not be found. Entry ID: {$entry_id}. Aborting.");
                 return;
             }
             self::log_debug("Entry has been found." . print_r($entry, true));
             $config = self::get_config_by_entry($entry);
             if (!$config) {
                 self::log_error("Form no longer is configured with Paytm Form Addon. Form ID: {$entry["form_id"]}. Aborting.");
                 return;
             }
             $settings = get_option("gf_paytm_form_settings");
             self::log_debug("Form {$entry["form_id"]} is properly configured.");
             if ($_POST['RESPCODE'] == "01") {
                 $payment_status = "SUCCESS";
             } else {
                 $payment_status = "FAILED";
             }
             $cancel = apply_filters("gform_paytm_form_pre_ipn", false, $_POST, $entry, $config);
             if (!$cancel) {
                 self::log_debug("Setting payment status...");
                 self::set_payment_status($config, $entry, $payment_status, $_POST['ORDERID'], null, $_POST['TXNAMOUNT']);
             } else {
                 self::log_debug("IPN processing cancelled by the gform_paytm_form_pre_ipn filter. Aborting.");
             }
             //  list($form_id, $lead_id) = explode("|", $query["ids"]);
             //	add_action('the_content', array('GFSagePayForm', 'paytmShowMessage'));
             $redirect_url = get_bloginfo("url") . '/?resp_msg=' . urlencode($_POST['RESPMSG']);
             wp_redirect($redirect_url);
             exit;
         } else {
             if (isset($_POST['RESPCODE'])) {
                 $redirect_url = get_bloginfo("url") . '/?resp_msg=' . urlencode("Security error!");
                 wp_redirect($redirect_url);
                 exit;
             }
         }
     } else {
     }
 }
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
// following files need to be included
require_once "./lib/config_paytm.php";
require_once "./lib/encdec_paytm.php";
$paytmChecksum = "";
$paramList = array();
$isValidChecksum = FALSE;
$paramList = $_POST;
$return_array = $_POST;
$paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : "";
//Sent by Paytm pg
//Verify all parameters received from Paytm pg to your application. Like MID received from paytm pg is same as your application’s MID, TXN_AMOUNT and ORDER_ID are same as what was sent by you to Paytm PG for initiating transaction etc.
$isValidChecksum = verifychecksum_e($paramList, PAYTM_MERCHANT_KEY, $paytmChecksum);
//will return TRUE or FALSE string.
// if ($isValidChecksum===TRUE)
// 	$return_array["IS_CHECKSUM_VALID"] = "Y";
// else
// 	$return_array["IS_CHECKSUM_VALID"] = "N";
$return_array["IS_CHECKSUM_VALID"] = $isValidChecksum ? "Y" : "N";
//$return_array["TXNTYPE"] = "";
//$return_array["REFUNDAMT"] = "";
unset($return_array["CHECKSUMHASH"]);
$encoded_json = htmlentities(json_encode($return_array));
?>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-I">
 function plgVmOnPaymentResponseReceived(&$html)
 {
     if (!class_exists('VirtueMartCart')) {
         require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php';
     }
     if (!class_exists('shopFunctionsF')) {
         require JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
     }
     if (!class_exists('VirtueMartModelOrders')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php';
     }
     $paytm_data = JRequest::get('post');
     // the payment itself should send the parameter needed.
     $virtuemart_paymentmethod_id = JRequest::getInt('pm', 0);
     $order_number = JRequest::getString('on', 0);
     $vendorId = 0;
     if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
         return null;
         // Another method was selected, do nothing
     }
     if (!$this->selectedThisElement($method->payment_element)) {
         return null;
     }
     if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) {
         return null;
     }
     if (!($paymentTable = $this->getDataByOrderId($virtuemart_order_id))) {
         return '';
     }
     $payment_name = $this->renderPluginName($method);
     function sanitizedParam($param)
     {
         $pattern[0] = "%,%";
         $pattern[1] = "%#%";
         $pattern[2] = "%\\(%";
         $pattern[3] = "%\\)%";
         $pattern[4] = "%\\{%";
         $pattern[5] = "%\\}%";
         $pattern[6] = "%<%";
         $pattern[7] = "%>%";
         $pattern[8] = "%`%";
         $pattern[9] = "%!%";
         $pattern[10] = "%\\\$%";
         $pattern[11] = "%\\%%";
         $pattern[12] = "%\\^%";
         $pattern[13] = "%=%";
         $pattern[14] = "%\\+%";
         $pattern[15] = "%\\|%";
         $pattern[16] = "%\\\\%";
         $pattern[17] = "%:%";
         $pattern[18] = "%'%";
         $pattern[19] = "%\"%";
         $pattern[20] = "%;%";
         $pattern[21] = "%~%";
         $pattern[22] = "%\\[%";
         $pattern[23] = "%\\]%";
         $pattern[24] = "%\\*%";
         $pattern[25] = "%&%";
         $sanitizedParam = preg_replace($pattern, "", $param);
         return $sanitizedParam;
     }
     function verifyChecksum($checksum, $all, $secret)
     {
         $hash = hash_hmac('sha256', $all, $secret);
         $cal_checksum = $hash;
         $bool = 0;
         if ($checksum == $cal_checksum) {
             $bool = 1;
         }
         return $bool;
     }
     $order_id = JRequest::getString('ORDERID', 0);
     $res_code = JRequest::getString('RESPCODE', 0);
     $res_desc = JRequest::getString('RESPMSG', 0);
     $checksum_recv = JRequest::getString('CHECKSUMHASH', 0);
     //$input = JFactory::getApplication->input;
     $paramList = JRequest::get('post');
     $amount = JRequest::getString('TXNAMOUNT', 0);
     $all = "'" . $order_id . "''" . $res_code . "''" . $res_desc . " " . "'";
     $bool = 0;
     //$bool = verifyChecksum($checksum_recv, $all, $method->secret_key);
     $bool = verifychecksum_e($paramList, $method->secret_key, $checksum_recv);
     if ($bool == 1) {
         if ($res_code == "01") {
             echo '<br><tr><td width="50%" align="center" valign="middle">Thank you for shopping with us. Your account has been charged and your transaction is successful. We will be shipping your order to you soon.</td></tr><br>';
             $new_status = $method->status_success;
         } else {
             echo '<tr><td width="50%" align="center" valign="middle">Thank you for shopping with us. The response is compromised</td></tr><br>';
             $new_status = $method->status_pending;
         }
     } else {
         echo '<tr><td width="50%" align="center" valign="middle">Security Error. Response compromised.</td> </tr>';
         $new_status = $method->status_canceled;
     }
     function vmModel($model = null)
     {
         if (!class_exists('VmModel')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'vmmodel.php';
         }
         return vmModel::getModel($model);
     }
     $modelOrder = vmModel('orders');
     $order['order_status'] = $new_status;
     $order['customer_notified'] = 0;
     $order['comments'] = '';
     $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, true);
     $this->_storePaytmInternalData($method, $order_id, $res_code, $res_desc, $virtuemart_order_id, $paymentTable->paytm_custom);
     if ($res_code == 100) {
         $html = $this->_getPaymentResponseHtml($paymentTable, $payment_name, $res_code, $res_desc);
     } else {
         $cancel_return = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel&on=' . $order_number . '&pm=' . $virtuemart_paymentmethod_id);
         $html = ' <script type="text/javascript">';
         $html .= 'window.location = "' . $cancel_return . '"';
         $html .= ' </script>';
         JRequest::setVar('html', $html);
     }
     //We delete the old stuff
     // get the correct cart / session
     $cart = VirtueMartCart::getCart();
     $cart->emptyCart();
     return true;
 }
 function plgVmOnPaymentResponseReceived(&$html)
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (!class_exists('VirtueMartCart')) {
             require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
         }
         if (!class_exists('shopFunctionsF')) {
             require VMPATH_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
         }
         if (!class_exists('VirtueMartModelOrders')) {
             require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php';
         }
         if (!isset($_POST)) {
         }
         $paytm_data = JRequest::get('post');
         // the payment itself should send the parameter needed.
         $virtuemart_paymentmethod_id = $this->_getPaytmPluginCode()->virtuemart_paymentmethod_id;
         $order_number = $_POST['ORDERID'];
         $vendorId = 0;
         if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
             return null;
             // Another method was selected, do nothing
         }
         if (!$this->selectedThisElement($method->payment_element)) {
             return false;
         }
         if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) {
             return null;
         }
         if (!($paymentTable = $this->getDataByOrderId($virtuemart_order_id))) {
             return '';
         }
         $payment_name = $this->renderPluginName($method);
         function sanitizedParam($param)
         {
             $pattern[0] = "%,%";
             $pattern[1] = "%#%";
             $pattern[2] = "%\\(%";
             $pattern[3] = "%\\)%";
             $pattern[4] = "%\\{%";
             $pattern[5] = "%\\}%";
             $pattern[6] = "%<%";
             $pattern[7] = "%>%";
             $pattern[8] = "%`%";
             $pattern[9] = "%!%";
             $pattern[10] = "%\\\$%";
             $pattern[11] = "%\\%%";
             $pattern[12] = "%\\^%";
             $pattern[13] = "%=%";
             $pattern[14] = "%\\+%";
             $pattern[15] = "%\\|%";
             $pattern[16] = "%\\\\%";
             $pattern[17] = "%:%";
             $pattern[18] = "%'%";
             $pattern[19] = "%\"%";
             $pattern[20] = "%;%";
             $pattern[21] = "%~%";
             $pattern[22] = "%\\[%";
             $pattern[23] = "%\\]%";
             $pattern[24] = "%\\*%";
             $pattern[25] = "%&%";
             $sanitizedParam = preg_replace($pattern, "", $param);
             return $sanitizedParam;
         }
         $order_id = JRequest::getString('ORDERID', 0);
         $res_code = JRequest::getString('RESPCODE', 0);
         $res_desc = JRequest::getString('RESPMSG', 0);
         $checksum_recv = JRequest::getString('CHECKSUMHASH', 0);
         $paramList = JRequest::get('post');
         $amount = JRequest::getString('TXNAMOUNT', 0);
         $mode = JRequest::getString('PAYMENTMODE', 0);
         $payment_id = JRequest::getString('TXNID', 0);
         $all = "'" . $order_id . "''" . $res_code . "''" . $res_desc . " " . "'";
         if (verifychecksum_e($paramList, $method->secret_key, $checksum_recv)) {
             if ($res_code == "01") {
                 echo '<br><tr><td width="50%" align="center" valign="middle">Thank you for shopping with us. Your account has been charged and your transaction is successful. We will be shipping your order to you soon.</td></tr><br>';
                 $new_status = $method->status_success;
             } else {
                 echo '<br><tr><td width="50%" align="center" valign="middle"><b>Transaction Failed. </b>' . $res_desc . '</td></tr><br>';
                 $cancel_return = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel&on=' . $order_number . '&pm=' . $virtuemart_paymentmethod_id);
                 echo "</br><a href='" . $cancel_return . "'><b>Go Back To Cart</a>";
                 $new_status = $method->status_pending;
             }
         } else {
             echo '<tr><td width="50%" align="center" valign="middle">Security Error. Response compromised.</td></tr>';
             $cancel_return = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel&on=' . $order_number . '&pm=' . $virtuemart_paymentmethod_id);
             echo "</br><a href='" . $cancel_return . "'><b>Go Back To Cart</a>";
             $new_status = $method->status_canceled;
         }
         function vmModel($model = null)
         {
             if (!class_exists('VmModel')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'vmmodel.php';
             }
             return vmModel::getModel($model);
         }
         $modelOrder = vmModel('orders');
         $order['order_status'] = $new_status;
         $order['customer_notified'] = 0;
         $order['comments'] = '';
         $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, true);
         $cart = VirtueMartCart::getCart();
         $this->_storePaytmInternalData($method, $order_id, $res_code, $res_desc, $virtuemart_order_id, $paymentTable->paytm_custom, $amount, $mode, $payment_id);
         if ($res_code == "01") {
             $cart->emptyCart();
             $html = $this->_getPaymentResponseHtml($paymentTable, $payment_name, $res_code, $res_desc);
         }
         return true;
     } else {
         $protocol = 'http://';
         $host = '';
         if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == '1')) {
             $protocol = 'https://';
         }
         if (isset($_SERVER["HTTP_HOST"]) && !empty($_SERVER["HTTP_HOST"])) {
             $host = $_SERVER["HTTP_HOST"];
         }
         header("Location: {$protocol}{$host}");
         return false;
     }
 }