function verifychecksum_e($arrayList, $key, $checksumvalue)
{
    $arrayList = removeCheckSumParam($arrayList);
    ksort($arrayList);
    $str = getArray2Str($arrayList);
    $paytm_hash = decrypt_e($checksumvalue, $key);
    $salt = substr($paytm_hash, -4);
    $finalString = $str . "|" . $salt;
    $website_hash = hash("sha256", $finalString);
    $website_hash .= $salt;
    $validFlag = "FALSE";
    if ($website_hash == $paytm_hash) {
        return true;
    } else {
        return false;
    }
}
 public function index()
 {
     require_once DIR_SYSTEM . 'encdec_paytm.php';
     require_once DIR_SYSTEM . 'paytm_constants.php';
     $this->language->load('payment/paytm');
     $this->document->setTitle($this->language->get('heading_title'));
     $arr = array();
     foreach ($this->request->post as $key => $value) {
         if ($key == 'paytm_key') {
             $arr[$key] = encrypt_e($value, $const1);
             continue;
         }
         $arr[$key] = $value;
     }
     $this->load->model('setting/setting');
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
         $this->model_setting_setting->editSetting('paytmexample', $arr);
         $this->session->data['success'] = $this->language->get('text_success');
         $this->redirect($this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'));
     }
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->data['text_enabled'] = $this->language->get('text_enabled');
     $this->data['text_disabled'] = $this->language->get('text_disabled');
     $this->data['text_all_zones'] = $this->language->get('text_all_zones');
     $this->data['text_yes'] = $this->language->get('text_yes');
     $this->data['text_no'] = $this->language->get('text_no');
     $this->data['text_live'] = $this->language->get('text_live');
     $this->data['text_successful'] = $this->language->get('text_successful');
     $this->data['text_fail'] = $this->language->get('text_fail');
     $this->data['text_env_production'] = $this->language->get('text_env_production');
     $this->data['text_env_test'] = $this->language->get('text_env_test');
     $this->data['entry_merchant'] = $this->language->get('entry_merchant');
     $this->data['entry_merchantkey'] = $this->language->get('entry_merchantkey');
     $this->data['entry_website'] = $this->language->get('entry_website');
     $this->data['entry_industry'] = $this->language->get('entry_industry');
     $this->data['entry_order_status'] = $this->language->get('entry_order_status');
     $this->data['entry_status'] = $this->language->get('entry_status');
     $this->data['callbackurl_status'] = $this->language->get('callbackurl_status');
     $this->data['entry_checkstatus'] = $this->language->get('entry_checkstatus');
     $this->data['entry_environment'] = $this->language->get('entry_environment');
     $this->data['button_save'] = $this->language->get('button_save');
     $this->data['button_cancel'] = $this->language->get('button_cancel');
     if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
     } else {
         $this->data['error_warning'] = '';
     }
     if (isset($this->error['merchant'])) {
         $this->data['error_merchant'] = $this->error['merchant'];
     } else {
         $this->data['error_merchant'] = '';
     }
     if (isset($this->error['key'])) {
         $this->data['error_key'] = $this->error['key'];
     } else {
         $this->data['error_key'] = '';
     }
     if (isset($this->error['website'])) {
         $this->data['error_website'] = $this->error['website'];
     } else {
         $this->data['error_website'] = '';
     }
     if (isset($this->error['industry'])) {
         $this->data['error_industry'] = $this->error['industry'];
     } else {
         $this->data['error_industry'] = '';
     }
     if (isset($this->request->post['paytm_order_status_id'])) {
         $this->data['paytm_order_status_id'] = $this->request->post['paytm_order_status_id'];
     } else {
         $this->data['paytm_order_status_id'] = $this->config->get('paytm_order_status_id');
     }
     $this->load->model('localisation/order_status');
     $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => false);
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_payment'), 'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => ' :: ');
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('payment/paytm', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => ' :: ');
     $this->data['action'] = $this->url->link('payment/paytm', 'token=' . $this->session->data['token'], 'SSL');
     $this->data['cancel'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL');
     if (isset($this->request->post['paytm_merchant'])) {
         $this->data['paytm_merchant'] = $this->request->post['paytm_merchant'];
     } else {
         $this->data['paytm_merchant'] = $this->config->get('paytm_merchant');
     }
     if (isset($this->request->post['paytm_website'])) {
         $this->data['paytm_website'] = $this->request->post['paytm_website'];
     } else {
         $this->data['paytm_website'] = $this->config->get('paytm_website');
     }
     if (isset($this->request->post['paytm_industry'])) {
         $this->data['paytm_industry'] = $this->request->post['paytm_industry'];
     } else {
         $this->data['paytm_industry'] = $this->config->get('paytm_industry');
     }
     if (isset($this->request->post['paytm_key'])) {
         $this->data['paytm_key'] = $this->request->post['paytm_key'];
     } else {
         $this->data['paytm_key'] = "";
         if ($this->config->get('paytm_key') != "") {
             $this->data['paytm_key'] = htmlspecialchars_decode(decrypt_e($this->config->get('paytm_key'), $const1), ENT_NOQUOTES);
         }
     }
     if (isset($this->request->post['paytm_status'])) {
         $this->data['paytm_status'] = $this->request->post['paytm_status'];
     } else {
         $this->data['paytm_status'] = $this->config->get('paytm_status');
     }
     if (isset($this->request->post['paytm_callbackurl'])) {
         $this->data['paytm_callbackurl'] = $this->request->post['paytm_callbackurl'];
     } else {
         $this->data['paytm_callbackurl'] = $this->config->get('paytm_callbackurl');
     }
     if (isset($this->request->post['paytm_checkstatus'])) {
         $this->data['paytm_checkstatus'] = $this->request->post['paytm_checkstatus'];
     } else {
         $this->data['paytm_checkstatus'] = $this->config->get('paytm_checkstatus');
     }
     if (isset($this->request->post['paytm_environment'])) {
         $this->data['paytm_environment'] = $this->request->post['paytm_environment'];
     } else {
         $this->data['paytm_environment'] = $this->config->get('paytm_environment');
     }
     $this->template = 'payment/paytm.tpl';
     $this->children = array('common/header', 'common/footer');
     $this->response->setOutput($this->render());
 }
function verifychecksum_eFromStr($str, $key, $checksumvalue)
{
    $paytm_hash = decrypt_e($checksumvalue, $key);
    $salt = substr($paytm_hash, -4);
    $finalString = $str . "|" . $salt;
    $website_hash = hash("sha256", $finalString);
    $website_hash .= $salt;
    $validFlag = "FALSE";
    if ($website_hash == $paytm_hash) {
        $validFlag = "TRUE";
    } else {
        $validFlag = "FALSE";
    }
    return $validFlag;
}
 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());
         }
     }
 }