$mode = 0;
   } else {
       $mode = 1;
   }
   $return_url = fn_url("payment_notification.notify?payment=paytm&order_id={$order_id}", AREA, 'http') . '&';
   $post_variables = array("MID" => $merchant_id, "ORDER_ID" => $paytm_order_id, "CUST_ID" => $order_info['email'], "TXN_AMOUNT" => $amount, "CHANNEL_ID" => $channel_id, "INDUSTRY_TYPE_ID" => $industry_type, "WEBSITE" => $website_name);
   if ($callback == 'yes') {
       $post_variables["CALLBACK_URL"] = $return_url;
   }
   $secret_key = $processor_data['processor_params']['secret_key'];
   if ($log == "yes") {
       error_log("All Params(Parameters which are posting to paytm) : " . $all);
       error_log("paytm Secret Key : " . $secret_key);
   }
   //$checksum = $sum->calculateChecksum($secret_key,$all);
   $checksum = getChecksumFromArray($post_variables, $secret_key);
   //
   if ($callback == 'yes') {
       echo <<<EOT
t<html>
t<body onLoad="document.paytm_form.submit();">
t<form action="{$paytm_url}" method="post" name="paytm_form">
t
t<input type=hidden name="MID" value="{$merchant_id}">
t<input type=hidden name="ORDER_ID" value="{$paytm_order_id}">
t<input type=hidden name="WEBSITE" value="{$website_name}">
t<input type=hidden name="INDUSTRY_TYPE_ID" value="{$industry_type}">
t<input type=hidden name="CHANNEL_ID" value="{$channel_id}">
t<input type=hidden name="TXN_AMOUNT" value="{$amount}">
t<input type=hidden name="CUST_ID"  value="{$order_info['email']}">
   <input type=hidden name="CALLBACK_URL" value="{$return_url}"> 
function paytm_link($params)
{
    $merchant_id = $params['merchant_id'];
    $secret_key = $params['merchant_key'];
    $order_id = $params['invoiceid'];
    $website = $params['website'];
    $industry_type = $params['industry_type'];
    $channel_id = "WEB";
    $gateway_mode = $params['environment'];
    $amount = $params['amount'];
    $email = $params['clientdetails']['email'];
    $post_variables = array("MID" => $merchant_id, "ORDER_ID" => $order_id, "CUST_ID" => $email, "TXN_AMOUNT" => $amount, "CHANNEL_ID" => $channel_id, "INDUSTRY_TYPE_ID" => $industry_type, "WEBSITE" => $website);
    $checksum = getChecksumFromArray($post_variables, $secret_key);
    $companyname = 'paytm';
    $pg_url = "https://pguat.paytm.com/oltp-web/processTransaction";
    if ($gateway_mode == 'LIVE') {
        $pg_url = "https://secure.paytm.in/oltp-web/processTransaction";
    }
    $code = '
	<form method="post" action=' . $pg_url . '>
		<input type="hidden" name="MID" value="' . $merchant_id . '"/>
	    <input type="hidden" name="ORDER_ID" value="' . $order_id . '"/>
	    <input type="hidden" name="WEBSITE" value="' . $website . '"/>
	    <input type="hidden" name="INDUSTRY_TYPE_ID" value="' . $industry_type . '"/>
	    <input type="hidden" name="CHANNEL_ID" value="' . $channel_id . '"/>
	    <input type="hidden" name="TXN_AMOUNT" value="' . $amount . '"/>
	    <input type="hidden" name="CUST_ID" value="' . $email . '"/>
	    <input type="hidden" name="txnDate" value="' . date("Y-m-d H:i:s") . '"/>
	    <input type="hidden" name="CHECKSUMHASH" value="' . $checksum . '"/>
			<input type="submit" value="Pay with Paytm" />
	</form>';
    return $code;
}
 public function index()
 {
     require_once DIR_SYSTEM . 'encdec_paytm.php';
     require_once DIR_SYSTEM . 'paytm_constants.php';
     $this->load->language('payment/paytm');
     $data['button_confirm'] = $this->language->get('button_confirm');
     $this->load->model('payment/paytm');
     $this->load->model('checkout/order');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $data['merchant'] = $this->config->get('paytm_merchant');
     $data['trans_id'] = $this->session->data['order_id'];
     $data['amount'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);
     $data['channel_id'] = "WEB";
     $data['industry_type_id'] = $this->config->get('paytm_industry');
     $data['website'] = $this->config->get('paytm_website');
     if (!empty($order_info['customer_id'])) {
         $data['customer_id'] = $order_info['customer_id'];
     } else {
         $data['customer_id'] = $order_info['email'];
     }
     $data['email'] = '';
     $data['mobile_no'] = '';
     if (isset($data['email'])) {
         $data['email'] = $order_info['email'];
     }
     if (isset($data['mobile_no'])) {
         $data['mobile_no'] = preg_replace('#[^0-9]{0,13}#is', '', $order_info['telephone']);
     }
     if ($this->config->get('paytm_environment') == "P") {
         $data['action_url'] = $PAYTM_PAYMENT_URL_PROD;
     } else {
         $data['action_url'] = $PAYTM_PAYMENT_URL_TEST;
     }
     if ($_SERVER['HTTPS']) {
         $data['callback_url'] = HTTPS_SERVER . $callbackurl_tail_part;
     } else {
         $data['callback_url'] = HTTP_SERVER . $callbackurl_tail_part;
     }
     $parameters = array("MID" => $data['merchant'], "ORDER_ID" => $data['trans_id'], "CUST_ID" => $data['customer_id'], "TXN_AMOUNT" => $data['amount'], "CHANNEL_ID" => $data['channel_id'], "INDUSTRY_TYPE_ID" => $data['industry_type_id'], "WEBSITE" => $data['website'], "MOBILE_NO" => $data['mobile_no'], "EMAIL" => $data['email']);
     if ($this->config->get('paytm_callbackurl') == '1') {
         $parameters["CALLBACK_URL"] = $data['callback_url'];
     }
     $mer = htmlspecialchars_decode(decrypt_e($this->config->get('paytm_key'), $const1), ENT_NOQUOTES);
     $mer = rtrim($mer);
     $data['checkSum'] = getChecksumFromArray($parameters, $mer);
     $data['paytm_callbackurl'] = $this->config->get('paytm_callbackurl');
     $data['callback'] = $this->url->link('payment/paytm/callback', '', 'SSL');
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paytm.tpl')) {
         return $this->load->view($this->config->get('config_template') . '/template/payment/paytm.tpl', $data);
     } else {
         return $this->load->view('payment/paytm.tpl', $data);
     }
 }
function pw_edd_process_payment($purchase_data)
{
    global $edd_options;
    /**********************************
     * set transaction mode
     **********************************/
    if (edd_is_test_mode()) {
        $paytm_redirect = 'https://pguat.paytm.com/oltp-web/processTransaction?';
    } else {
        if ($edd_options['paytm_select_mode'] == '1') {
            $paytm_redirect = 'https://secure.paytm.in/oltp-web/processTransaction?';
        } else {
            $paytm_redirect = 'https://pguat.paytm.com/oltp-web/processTransaction?';
        }
    }
    // check for any stored errors
    $errors = edd_get_errors();
    if (!$errors) {
        $purchase_summary = edd_get_purchase_summary($purchase_data);
        /****************************************
         * setup the payment details to be stored
         ****************************************/
        $payment = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'gateway' => 'paytm', 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
        // record the pending payment
        $payment = edd_insert_payment($payment);
        $merchant_payment_confirmed = false;
        $secret_key = $edd_options['paytm_mer_access_key'];
        $params = array('REQUEST_TYPE' => 'DEFAULT', 'MID' => $edd_options['paytm_merchant_id'], 'TXN_AMOUNT' => $purchase_data['price'], 'CHANNEL_ID' => "WEB", 'INDUSTRY_TYPE_ID' => $edd_options['paytm_industry_type'], 'WEBSITE' => $edd_options['paytm_website_name'], 'CUST_ID' => $purchase_data['user_email'], 'ORDER_ID' => $purchase_data['purchase_key'], 'EMAIL' => $purchase_data['user_email']);
        if ($edd_options['paytm_callback'] == '1') {
            $params['CALLBACK_URL'] = get_site_url() . '/?edd-listener=PAYTM_IPN&payment_id=' . $payment;
        }
        $checksum = getChecksumFromArray($params, $secret_key);
        $params['CHECKSUMHASH'] = $checksum;
        foreach ($params as $key => $val) {
            $submit_Params .= trim($key) . '=' . trim(urlencode($val)) . '&';
        }
        $submit_Params = substr($submit_Params, 0, -1);
        $request = $paytm_redirect . $submit_Params;
        wp_redirect($request);
        exit;
    } else {
        $fail = true;
        // errors were detected
    }
    if ($fail !== false) {
        // if errors are present, send the user back to the purchase page so they can be corrected
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    }
}
function initiateTxnRefund($requestParamList)
{
    $CHECKSUM = getChecksumFromArray($requestParamList, PAYTM_MERCHANT_KEY, 0);
    $requestParamList["CHECKSUM"] = $CHECKSUM;
    return callAPI(PAYTM_REFUND_URL, $requestParamList);
}
        /**
         * Generate paytm button link
         **/
        public function generate_paytm_form($order_id)
        {
            global $woocommerce;
            $txnDate = date('Y-m-d');
            $milliseconds = (int) (1000 * strtotime(date('Y-m-d')));
            if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) {
                $order = new WC_Order($order_id);
            } else {
                $order = new woocommerce_order($order_id);
            }
            $redirect_url = $this->redirect_page_id == "" || $this->redirect_page_id == 0 ? get_site_url() . "/" : get_permalink($this->redirect_page_id);
            // pretty url check //
            $a = strstr($redirect_url, "?");
            if ($a) {
                $redirect_url .= "&wc-api=WC_paytm";
            } else {
                $redirect_url .= "?wc-api=WC_paytm";
            }
            error_log("redirect url = this {$redirect_url}");
            //////////////
            $order_id = $order_id;
            $amt = $order->order_total;
            $txntype = '1';
            $ptmoption = '1';
            $currency = "INR";
            $purpose = "1";
            $productDescription = 'paytm';
            $ip = $_SERVER['REMOTE_ADDR'];
            /*$post_variables = Array(
            			"merchantIdentifier" => $this -> merchantIdentifier,
            			"orderId" => $order_id,
            			"returnUrl" => $redirect_url,
            			"buyerEmail" => $order -> billing_email,
            			"buyerFirstName" => $order -> billing_first_name,
            			"buyerLastName" => $order -> billing_last_name,
            			"buyerAddress" => $order -> billing_address_1,
            			"buyerCity" => $order -> billing_city,
            			"buyerState" => $order -> billing_state,
            			"buyerCountry" => $order -> billing_country,
            			"buyerPincode" => $order -> billing_postcode,
            			"buyerPhoneNumber" => $order -> billing_phone,
            			"txnType" => $txntype,
            			"ptmoption" => $ptmoption,
            			"mode" => $this -> mode,
            			"currency" => $currency,
            			"amount" => $amt, //Amount should be in paisa
            			"merchantIpAddress" => $ip,
            			"purpose" => $purpose,
            			"productDescription" => $productDescription,
            			"txnDate" => $txnDate
            
            			);*/
            $email = '';
            $mobile_no = '';
            try {
                $email = $order->billing_email;
            } catch (Exception $e) {
            }
            try {
                $mobile_no = preg_replace('#[^0-9]{0,13}#is', '', $order->billing_phone);
            } catch (Exception $e) {
            }
            $post_variables = array("MID" => $this->merchantIdentifier, "ORDER_ID" => $order_id, "CUST_ID" => $order->billing_first_name, "TXN_AMOUNT" => $amt, "CHANNEL_ID" => $this->channel_id, "INDUSTRY_TYPE_ID" => $this->industry_type, "WEBSITE" => $this->website, "EMAIL" => $email, "MOBILE_NO" => $mobile_no);
            if ($this->callbackurl == 'yes') {
                $post_variables["CALLBACK_URL"] = get_site_url() . '/?page_id=7&wc-api=WC_paytm';
            }
            $all = '';
            foreach ($post_variables as $name => $value) {
                if ($name != 'checksum') {
                    $all .= "'";
                    if ($name == 'returnUrl') {
                        $all .= $value;
                    } else {
                        $all .= $value;
                    }
                    $all .= "'";
                }
            }
            if ($this->log == "yes") {
                error_log("AllParams : " . $all);
                error_log("Secret Key : " . $this->secret_key);
            }
            //$checksum = Checksum::calculateChecksum($this->secret_key, $all);
            $checksum = getChecksumFromArray($post_variables, $this->secret_key);
            $paytm_args = array('merchantIdentifier' => $this->merchantIdentifier, 'orderId' => $order_id, 'returnUrl' => $redirect_url, 'buyerEmail' => $order->billing_email, 'buyerFirstName' => $order->billing_first_name, 'buyerLastName' => $order->billing_last_name, 'buyerAddress' => $order->billing_address_1, 'buyerCity' => $order->billing_city, 'buyerState' => $order->billing_state, 'buyerCountry' => $order->billing_country, 'buyerPincode' => $order->billing_postcode, 'buyerPhoneNumber' => $order->billing_phone, 'txnType' => $txntype, 'ptmoption' => $ptmoption, 'mode' => $this->mode, 'currency' => $currency, 'amount' => $amt, 'merchantIpAddress' => $ip, 'purpose' => $purpose, 'productDescription' => $productDescription, 'txnDate' => $txnDate, 'checksum' => $checksum);
            foreach ($paytm_args as $name => $value) {
                if ($name != 'checksum') {
                    if ($name == 'returnUrl') {
                        $value = $value;
                    } else {
                        $value = $value;
                    }
                }
            }
            $paytm_args_array = array();
            /* foreach($paytm_args as $key => $value){
            						if($key != 'checksum') {
            			if ($key == 'returnUrl') {
                            $paytm_args_array[] = "<input type='hidden' name='$key' value='". $value ."'/>";
            				} else {
            				$paytm_args_array[] = "<input type='hidden' name='$key' value='". $value ."'/>";
            				}
            				} else {
            				$paytm_args_array[] = "<input type='hidden' name='$key' value='$value'/>";
            				}
                        }*/
            $paytm_args_array[] = "<input type='hidden' name='MID' value='" . $this->merchantIdentifier . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='ORDER_ID' value='" . $order_id . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='WEBSITE' value='" . $this->website . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='INDUSTRY_TYPE_ID' value='" . $this->industry_type . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='CHANNEL_ID' value='" . $this->channel_id . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='TXN_AMOUNT' value='" . $amt . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='CUST_ID' value='" . $order->billing_first_name . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='EMAIL' value='" . $email . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='MOBILE_NO' value='" . $mobile_no . "'/>";
            if ($this->callbackurl == 'yes') {
                $call = get_site_url() . '/?page_id=7&wc-api=WC_paytm';
                $paytm_args_array[] = "<input type='hidden' name='CALLBACK_URL' value='" . $call . "'/>";
            }
            $paytm_args_array[] = "<input type='hidden' name='txnDate' value='" . date('Y-m-d H:i:s') . "'/>";
            $paytm_args_array[] = "<input type='hidden' name='CHECKSUMHASH' value='" . $checksum . "'/>";
            return '<form action="' . $this->gateway_url . '" method="post" id="paytm_payment_form">
                ' . implode('', $paytm_args_array) . '
                <input type="submit" class="button-alt" id="submit_paytm_payment_form" value="' . __('Pay via paytm') . '" /> <a class="button cancel" href="' . $order->get_cancel_order_url() . '">' . __('Cancel order &amp; restore cart') . '</a>
                <script type="text/javascript">
jQuery(function(){
    jQuery("body").block(
            {
                message: "<img src=\\"' . $woocommerce->plugin_url() . '/assets/images/ajax-loader.gif\\" alt=\\"Redirecting…\\" style=\\"float:left; margin-right: 10px;\\" />' . __('Thank you for your order. We are now redirecting you to paytm to make payment.') . '",
                    overlayCSS:
            {
                background: "#fff",
                    opacity: 0.6
        },
        css: {
            padding:        20,
                textAlign:      "center",
                color:          "#555",
                border:         "3px solid #aaa",
                backgroundColor:"#fff",
                cursor:         "wait",
                lineHeight:"32px"
        }
        });
        jQuery("#submit_paytm_payment_form").click();

        });
                    </script>
                </form>';
        }
 function process_button()
 {
     global $order, $customer_id, $cart, $cart_DirecPay_ID;
     $merchant_mid = MODULE_PAYMENT_PAYTM_MERCHANT_ID;
     $merchant_key = html_entity_decode(MODULE_PAYMENT_PAYTM_MERCHANT_KEY);
     $website = MODULE_PAYMENT_PAYTM_WEBSITE;
     $industry_type_id = MODULE_PAYMENT_PAYTM_INDUSTRY_TYPE_ID;
     $callback_enabled = MODULE_PAYMENT_PAYTM_CALLBACK;
     $amount = $order->info['total'];
     //$orderId = $cart->cartID;
     $order_id = substr($cart_DirecPay_ID, strpos($cart_DirecPay_ID, '-') + 1);
     $_SESSION['sorderid'] = $order_id;
     $post_variables = array("MID" => $merchant_mid, "ORDER_ID" => $order_id, "CUST_ID" => !empty($customer_id) ? $customer_id : $order->customer['email_address'], "WEBSITE" => $website, "INDUSTRY_TYPE_ID" => $industry_type_id, "EMAIL" => $order->customer['email_address'], "MOBILE_NO" => $order->customer['telephone'], "CHANNEL_ID" => "WEB", "TXN_AMOUNT" => $amount);
     if (stripos($callback_enabled, "yes") !== false) {
         $post_variables['CALLBACK_URL'] = tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');
     }
     $checksum = getChecksumFromArray($post_variables, $merchant_key);
     $post_variables['CHECKSUMHASH'] = $checksum;
     $process_button_string = '';
     foreach ($post_variables as $key => $value) {
         $process_button_string .= tep_draw_hidden_field($key, $value);
     }
     return $process_button_string;
 }
 public function execPayment($cart)
 {
     global $smarty, $cart;
     $bill_address = new Address(intval($cart->id_address_invoice));
     $ship_address = new Address(intval($cart->id_address_delivery));
     $bc = new Country($bill_address->id_country);
     $sc = new Country($ship_address->id_country);
     $customer = new Customer(intval($cart->id_customer));
     $account_id = Configuration::get('ACCOUNT_ID');
     $secret_key = Configuration::get('SECRET_KEY');
     $mode = Configuration::get('MODE');
     $id_currency = intval(Configuration::get('PS_CURRENCY_DEFAULT'));
     $currency = new Currency(intval($id_currency));
     $first_name = $bill_address->firstname;
     $last_name = $bill_address->lastname;
     $name = $first_name . " " . $last_name;
     $address1 = $bill_address->address1;
     $address2 = $bill_address->address2;
     $address = $address1 . " " . $address2;
     $city = $bill_address->city;
     //echo $country = $bc->iso_code; die;
     $Code = array("AF" => "AFG", "AL" => "ALB", "DZ" => "DZA", "AS" => "ASM", "AD" => "AND", "AO" => "AGO", "AI" => "AIA", "AQ" => "ATA", "AG" => "ATG", "AR" => "ARG", "AM" => "ARM", "AW" => "ABW", "AU" => "AUS", "AT" => "AUT", "AZ" => "AZE", "BS" => "BHS", "BH" => "BHR", "BD" => "BGD", "BB" => "BRB", "BY" => "BLR", "BE" => "BEL", "BZ" => "BLZ", "BJ" => "BEN", "BM" => "BMU", "BT" => "BTN", "BO" => "BOL", "BA" => "BIH", "BW" => "BWA", "BV" => "BVT", "BR" => "BRA", "IO" => "IOT", "VG" => "VGB", "BN" => "BRN", "BG" => "BGR", "BF" => "BFA", "BI" => "BDI", "KH" => "KHM", "CM" => "CMR", "CA" => "CAN", "CV" => "CPV", "KY" => "CYM", "CF" => "CAF", "TD" => "TCD", "CL" => "CHL", "CN" => "CHN", "CX" => "CXR", "CC" => "CCK", "CO" => "COL", "KM" => "COM", "CG" => "COG", "CK" => "C*K", "CR" => "CRI", "CI" => "CIV", "HR" => "HRV", "CU" => "CUB", "CY" => "CYP", "CZ" => "CZE", "DK" => "DNK", "DM" => "DMA", "DO" => "DOM", "TL" => "TLS", "EC" => "ECU", "EG" => "EGY", "SV" => "SLV", "GQ" => "GNQ", "ER" => "ERI", "EE" => "EST", "ET" => "ETH", "FK" => "FLK", "FO" => "FRO", "FJ" => "FJI", "FI" => "FIN", "FR => FRA", "FX" => "FXX", "GF" => "GUF", "PF" => "PYF", "TF" => "ATF", "GA" => "GAB", "GE" => "GEO", "GM" => "GMB", "PS" => "PSE", "DE" => "DEU", "GH" => "GHA", "GI" => "GIB", "GR" => "GRC", "GL" => "GRL", "GD" => "GRD", "GP" => "GLP", "GU" => "GUM", "GT" => "GTM", "GN" => "GIN", "GW" => "GNB", "GY" => "GUY", "HT" => "HTI", "HM" => "HMD", "HN" => "HND", "HK" => "HKG", "HU" => "HUN", "IS" => "ISL", "IN" => "IND", "ID" => "IDN", "IQ" => "IRQ", "IE" => "IRL", "IR" => "IRN", "IL" => "ISR", "IT" => "ITA", "JM" => "JAM", "JP" => "JPN", "JO" => "JOR", "KZ" => "KAZ", "KE" => "KEN", "KI" => "KIR", "KP" => "PRK", "KR" => "KOR", "KW" => "KWT", "KG" => "KGZ", "LA" => "LAO", "LV" => "LVA", "LB" => "LBN", "LS" => "LSO", "LR" => "LBR", "LY" => "LBY", "LI" => "LIE", "LT" => "LTU", "LU" => "LUX", "MO" => "MAC", "MK" => "MKD", "MG" => "MDG", "MW" => "MWI", "MY" => "MYS", "MV" => "MDV", "ML" => "MLI", "MT" => "MLT", "MH" => "MHL", "MQ" => "MTQ", "MR" => "MRT", "MU" => "MUS", "YT" => "MYT", "MX" => "MEX", "FM" => "FSM", "MD" => "MDA", "MC" => "MCO", "MN" => "MNG", "MS" => "MSR", "MA" => "MAR", "MZ" => "MOZ", "MM" => "MMR", "NA" => "NAM", "NR" => "NRU", "NP" => "NPL", "NL" => "NLD", "NC" => "NCL", "NZ" => "NZL", "NI" => "NIC", "NE" => "NER", "NG" => "NGA", "NU" => "NIU", "NF" => "NFK", "MP" => "MNP", "NO" => "NOR", "OM" => "OMN", "PK" => "PAK", "PW" => "PLW", "PA" => "PAN", "PG" => "PNG", "PY" => "PRY", "PE" => "PER", "PH" => "PHL", "PN" => "PCN", "PL" => "POL", "PT" => "PRT", "PR" => "PRI", "QA" => "QAT", "RE" => "REU", "RO" => "ROU", "RU" => "RUS", "RW" => "RWA", "LC" => "LCA", "WS" => "WSM", "SM" => "SMR", "ST" => "STP", "SA" => "SAU", "SN" => "SEN", "SC" => "SYC", "SL" => "SLE", "SG" => "SGP", "SK" => "SVK", "SI" => "SVN", "SB" => "SLB", "SO" => "SOM", "ZA" => "ZAF", "ES" => "ESP", "LK" => "LKA", "SH" => "SHN", "KN" => "KNA", "PM" => "SPM", "VC" => "VCT", "SD" => "SDN", "SR" => "SUR", "SJ" => "SJM", "SZ" => "SWZ", "SE" => "SWE", "CH" => "CHE", "SY" => "SYR", "TW" => "TWN", "TJ" => "TJK", "TZ" => "TZA", "TH" => "THA", "TG" => "TGO", "TK" => "TKL", "TO" => "TON", "TT" => "TTO", "TN" => "TUN", "TR" => "TUR", "TM" => "TKM", "TC" => "TCA", "TV" => "TUV", "UG" => "UGA", "UA" => "UKR", "AE" => "ARE", "GB" => "GBR", "US" => "USA", "VI" => "VIR", "UY" => "URY", "UZ" => "UZB", "VU" => "VUT", "VA" => "VAT", "VE" => "VEN", "VN" => "VNM", "WF" => "WLF", "EH" => "ESH", "YE" => "YEM", "CS" => "SCG", "ZR" => "ZAR", "ZM" => "ZMB", "ZW" => "ZWE", "AP" => "   ", "RS" => "SRB", "AX" => "ALA", "EU" => "", "ME" => "MNE", "GG" => "GGY", "JE" => "JEY", "IM" => "IMN", "CW" => "CUW", "SX" => "SXM");
     $country = $Code[$bc->iso_code];
     $state_obj = new State($bill_address->id_state);
     $state = $state_obj->name;
     $phone = $bill_address->phone_mobile;
     $postal_code = $bill_address->postcode;
     $email = $customer->email;
     $qStrings = array("DR" => "{DR}");
     $return_url = urldecode(Context::getContext()->link->getModuleLink('ebs', 'response', $qStrings, true));
     $ship_first_name = $ship_address->firstname;
     $ship_last_name = $ship_address->lastname;
     $ship_name = $ship_first_name . " " . $ship_last_name;
     $ship_address1 = $ship_address->address1;
     $ship_address2 = $ship_address->address2;
     $ship_addr = $ship_address1 . " " . $ship_address2;
     $ship_city = $ship_address->city;
     $ship_country = $country;
     $ship_state_obj = new State($ship_address->id_state);
     $ship_state = $state_obj->name;
     $ship_phone = $ship_address->phone_mobile;
     $ship_postal_code = $ship_address->postcode;
     if (!Validate::isLoadedObject($bill_address) or !Validate::isLoadedObject($customer)) {
         return $this->l('Paytm error: (invalid address or customer)');
     }
     $amount = $cart->getOrderTotal(true, Cart::BOTH);
     $ref_no = intval($cart->id);
     //$return_url = 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/ebs/response.php?DR={DR}&cart_id='.intval($cart->id);
     $hash = $secret_key . "|" . $account_id . "|" . $amount . "|" . $ref_no . "|" . html_entity_decode($return_url) . "|" . $mode;
     $securehash = md5($hash);
     $reference_no = intval($cart->id);
     $description = "Order ID is " . $reference_no;
     $order_id = $ref_no;
     $date = date('Y-m-d');
     $industry_type = Configuration::get('PayTM_MERCHANT_INDUSTRY_TYPE');
     $channel_id = Configuration::get('PayTM_MERCHANT_CHANNEL_ID');
     $website = Configuration::get('PayTM_MERCHANT_WEBSITE');
     $paytmurl = Configuration::get('PayTM_GATEWAY_URL');
     $merchant_id = Configuration::get('PayTM_MERCHANT_ID');
     $secret_key = Configuration::get('PayTM_SECRET_KEY');
     $cust_id = intval($cart->id_customer);
     $callback = Configuration::get('PayTM_ENABLE_CALLBACK');
     $mode = Configuration::get('PayTM_MODE');
     $mod = $mode;
     if ($mod == "TEST") {
         $mode = 0;
     } else {
         $mode = 1;
     }
     $mobile_no = '';
     $email = '';
     try {
         $mobile_no = preg_replace('#[^0-9]{0,13}#is', '', $bill_address->phone_mobile);
     } catch (Exception $e) {
     }
     try {
         $email = $customer->email;
     } catch (Exception $e) {
     }
     $post_variables = array("MID" => $merchant_id, "ORDER_ID" => $order_id, "CUST_ID" => $cust_id, "TXN_AMOUNT" => $amount, "CHANNEL_ID" => $channel_id, "INDUSTRY_TYPE_ID" => $industry_type, "WEBSITE" => $website, "MOBILE_NO" => $mobile_no, "EMAIL" => $email);
     $callback_html = '';
     if (!empty($callback) && stripos($callback, 'on') !== false) {
         $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"];
         }
         $callback_html = "<input type='hidden' name='CALLBACK_URL' value='" . $protocol . $host . __PS_BASE_URI__ . 'index.php?fc=module&module=paytm&controller=response' . "'/>";
         $post_variables['CALLBACK_URL'] = $protocol . $host . __PS_BASE_URI__ . 'index.php?fc=module&module=paytm&controller=response';
     }
     $checksum = getChecksumFromArray($post_variables, $secret_key);
     $smarty->assign(array('merchant_id' => $merchant_id, 'paytmurl' => $paytmurl, 'date' => $date, 'order_id' => $order_id, 'amount' => $amount, 'website' => $website, 'industry_type' => $industry_type, 'channel_id' => $channel_id, 'cust_id' => $cust_id, 'mobile_no' => $mobile_no, 'email' => $email, 'callback_html' => $callback_html, 'checksum' => $checksum));
     return $this->display(__FILE__, 'payment_execution.tpl');
 }
<?php

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";
$checkSum = "";
//Here checksum string will return by getChecksumFromArray() function.
$checkSum = getChecksumFromArray($_POST, PAYTM_MERCHANT_KEY);
//print_r($_POST);
echo json_encode(array("CHECKSUMHASH" => $checkSum, "ORDER_ID" => $_POST["ORDER_ID"], "payt_STATUS" => "1"));
//Sample response return to SDK
//  {"CHECKSUMHASH":"GhAJV057opOCD3KJuVWesQ9pUxMtyUGLPAiIRtkEQXBeSws2hYvxaj7jRn33rTYGRLx2TosFkgReyCslu4OUj\/A85AvNC6E4wUP+CZnrBGM=","ORDER_ID":"asgasfgasfsdfhl7","payt_STATUS":"1"}
 public function hookPayment($params)
 {
     global $smarty, $cart, $cookie;
     $bill_address = new Address(intval($params['cart']->id_address_invoice));
     $ship_address = new Address(intval($params['cart']->id_address_delivery));
     $customer = new Customer(intval($params['cart']->id_customer));
     if (!Validate::isLoadedObject($bill_address) or !Validate::isLoadedObject($customer)) {
         return $this->l('Paytm error: (invalid address or customer)');
     }
     $mobile_no = '';
     $email = '';
     try {
         $mobile_no = preg_replace('#[^0-9]{0,13}#is', '', $bill_address->phone_mobile);
     } catch (Exception $e) {
     }
     try {
         $email = $customer->email;
     } catch (Exception $e) {
     }
     $merchant_id = Configuration::get('Paytm_MERCHANT_ID');
     $secret_key = Configuration::get('Paytm_SECRET_KEY');
     $industry_type = Configuration::get('Paytm_MERCHANT_INDUSTRY_TYPE');
     $channel_id = Configuration::get('Paytm_MERCHANT_CHANNEL_ID');
     $website = Configuration::get('Paytm_MERCHANT_WEBSITE');
     $callback = (int) Configuration::get('Paytm_ENABLE_CALLBACK');
     $amount = $cart->getOrderTotal(true, Cart::BOTH);
     $order_id = (int) $cookie->id_cart;
     $post_variables = array("MID" => $merchant_id, "ORDER_ID" => $order_id, "CUST_ID" => $params['cart']->id_customer, "TXN_AMOUNT" => $amount, "CHANNEL_ID" => $channel_id, "INDUSTRY_TYPE_ID" => $industry_type, "WEBSITE" => $website, "MOBILE_NO" => $mobile_no, "EMAIL" => $email);
     $callback_html = '';
     if ($callback == 1) {
         $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"];
         }
         $callback_html = "<input type='hidden' name='CALLBACK_URL' value='" . $protocol . $host . __PS_BASE_URI__ . 'modules/paytm/response.php' . "'/>";
         $post_variables['CALLBACK_URL'] = $callback_html;
     }
     $checksum = getChecksumFromArray($post_variables, $secret_key);
     $date = date('Y-m-d H:i:s');
     $smarty->assign(array('merchant_id' => $merchant_id, 'PaytmUrl' => $this->getPaytmUrl(), 'date' => $date, 'amount' => $amount, 'id_cart' => $order_id, 'WEBSITE' => $website, 'INDUSTRY_TYPE_ID' => $industry_type, 'CHANNEL_ID' => $channel_id, 'MOBILE_NO' => $mobile_no, 'EMAIL' => $email, 'CUST_ID' => $params['cart']->id_customer, 'checksum' => $checksum, 'callback_html' => $callback_html, 'this_path' => $this->_path));
     return $this->display(__FILE__, 'paytm.tpl');
 }
    public static function send_to_paytm_form($confirmation, $form, $entry, $ajax)
    {
        // ignore requests that are not the current form's submissions
        if (RGForms::post("gform_submit") != $form["id"]) {
            return $confirmation;
        }
        $settings = get_option("gf_paytm_form_settings");
        $paytm_mid = rgar($settings, "paytm_mid");
        $paytm_mode = rgar($settings, "paytm_mode");
        $paytm_callback = rgar($settings, "paytm_callback");
        $paytm_channel_id = rgar($settings, "paytm_channel_id");
        $paytm_industry_type_id = rgar($settings, "paytm_industry_type_id");
        $paytm_key = rgar($settings, "paytm_key");
        $paytm_website = rgar($settings, "paytm_website");
        $config = GFPaytmFormData::get_feed_by_form($form["id"]);
        if (!$config) {
            self::log_debug("NOT sending to Paytm Form: No Paytm Form setup was located for form_id = {$form['id']}.");
            return $confirmation;
        } else {
            $config = $config[0];
            //using first sagepayform feed (only one sagepayform feed per form is supported)
        }
        // updating entry meta with current feed id
        gform_update_meta($entry["id"], "paytm_form_feed_id", $config["id"]);
        // updating entry meta with current payment gateway
        gform_update_meta($entry["id"], "payment_gateway", "paytmform");
        //updating lead's payment_status to Processing
        RGFormsModel::update_lead_property($entry["id"], "payment_status", 'Processing');
        //Getting Url (Production or Sandbox)
        if ($paytm_mode == 'test') {
            $redirect_url = 'https://pguat.paytm.com/oltp-web/processTransaction';
        } else {
            if ($paytm_mode == 'production') {
                $redirect_url = 'https://secure.paytm.in/oltp-web/processTransaction';
            }
        }
        $invoice_id = apply_filters("gform_paytm_form_invoice", "", $form, $entry);
        $red = $entry['id'];
        $invoice = empty($invoice_id) ? $red : $invoice_id;
        //Current Currency
        $currency = GFCommon::get_currency();
        //Customer fields
        $fields = "";
        $first_name = "";
        $last_name = "";
        $phone = "";
        $email = "";
        foreach (self::get_customer_fields() as $field) {
            $field_id = $config["meta"]["customer_fields"][$field["name"]];
            $value = rgar($entry, $field_id);
            if ($field["name"] == "first_name") {
                $first_name = $value;
                $value = '';
            } else {
                if ($field["name"] == "last_name") {
                    $last_name = $value;
                    $value = '';
                } else {
                    if ($field["name"] == "phone") {
                        $phone = $value;
                        $value = '';
                    } else {
                        if ($field["name"] == "email") {
                            $email = $value;
                            $value = '';
                        } else {
                            if ($field["name"] == "amount") {
                                $amount = $value;
                                $value = '';
                            }
                        }
                    }
                }
            }
        }
        $time_stamp = date("ymdHis");
        $orderid = $time_stamp . "-" . $invoice;
        /*
        		    $paytm_arg['CustomerName']		= substr($first_name.' '.$last_name, 0, 100);
                $paytm_arg['CustomerEMail'] 		= substr($email, 0, 255);
                
            
                $paytm_arg['BillingPostCode'] 	= substr($postcode, 0, 10);
                $paytm_arg['BillingCountry'] 		= $country;
                $paytm_arg['BillingPhone'] 		= substr($phone, 0, 20);
                
            
                $paytm_arg['DeliveryPostCode'] 	= substr($postcode, 0, 10);
                $paytm_arg['DeliveryCountry'] 	= $country;
                $paytm_arg['DeliveryPhone'] 		= substr($phone, 0, 20); 
                
                $paytm_arg['FailureURL'] 			= get_bloginfo("url") . "/?page=gf_paytm_form_ipn";
                $paytm_arg['SuccessURL'] 			= get_bloginfo("url") . "/?page=gf_paytm_form_ipn";*/
        $paytm_arg['REQUEST_TYPE'] = 'DEFAULT';
        $paytm_arg['MID'] = $paytm_mid;
        $paytm_arg['WEBSITE'] = $paytm_website;
        $paytm_arg['INDUSTRY_TYPE_ID'] = $paytm_industry_type_id;
        $paytm_arg['CHANNEL_ID'] = $paytm_channel_id;
        $paytm_arg['ORDER_ID'] = $orderid;
        $paytm_arg['CUST_ID'] = $email;
        $paytm_arg['TXN_AMOUNT'] = (double) filter_var($amount, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
        $paytm_arg['EMAIL'] = $email;
        $paytm_arg['MOBILE_NO'] = $phone;
        if ($paytm_callback == 'yes') {
            $paytm_arg['CALLBACK_URL'] = get_site_url() . '?gf_paytm_form_return';
        }
        $paytm_arg['CHECKSUMHASH'] = getChecksumFromArray($paytm_arg, $paytm_key);
        //$customer_fields = self::customer_query_string($config, $entry);
        //If page is HTTPS, set return mode to 2 (meaning Paytm Form will post info back to page)
        //If page is not HTTPS, set return mode to 1 (meaning Paytm Form will redirect back to page) to avoid security warning
        $return_url = self::return_url($form["id"], $entry["id"]);
        //Cancel URL
        $cancel_url = !empty($config["meta"]["cancel_url"]) ? $config["meta"]["cancel_url"] : "";
        //URL that will listen to notifications from Paytm Form
        $ipn_url = get_bloginfo("url") . "/?page=gf_paytm_form_ipn";
        $url = apply_filters("gform_paytm_form_request_{$form['id']}", apply_filters("gform_paytm_form_request", $url, $form, $entry), $form, $entry);
        self::log_debug("Sending to Paytm Form: {$url}");
        //wp_die("<pre>".print_r($test123,TRUE)."</pre><pre>".print_r($paytm_arg,TRUE)."</pre>"); exit;
        $ajax = TRUE;
        if (headers_sent() || $ajax) {
            $paytm_arg_array = array();
            foreach ($paytm_arg as $key => $value) {
                $paytm_arg_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
            }
            $confirmation = '<form action="' . $redirect_url . '" method="post" id="paytm_payment_form" name="paytm_payment_form">
					' . implode('', $paytm_arg_array) . '
					<input type="submit" class="button" id="submit_paytm_payment_form" value="Pay via Paytm" /> <a class="button cancel" href="http://google.com">Cancel order &amp; restore cart</a>
				</form>
				<script>	
			    window.onload=function(){
         //   		document.paytm_payment_form.submit();
            	}
            </script>';
        }
        return $confirmation;
    }
 function plgVmConfirmedOrder($cart, $order)
 {
     if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) {
         return null;
         // Another method was selected, do nothing
     }
     if (!$this->selectedThisElement($method->payment_element)) {
         return false;
     }
     $session = JFactory::getSession();
     $return_context = $session->getId();
     $this->logInfo('plgVmConfirmedOrder order number: ' . $order['details']['BT']->order_number, 'message');
     if (!class_exists('VirtueMartModelOrders')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php';
     }
     if (!class_exists('VirtueMartModelCurrency')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php';
     }
     //$usr = JFactory::getUser();
     $new_status = '';
     $usrBT = $order['details']['BT'];
     $address = isset($order['details']['ST']) ? $order['details']['ST'] : $order['details']['BT'];
     if (!class_exists('TableVendors')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'table' . DS . 'vendors.php';
     }
     /*$vendorModel = VmModel::getModel('Vendor');
     		$vendorModel->setId(1);
     		$vendor = $vendorModel->getVendor();
     		$vendorModel->addImages($vendor, 1);*/
     $this->getPaymentCurrency($method);
     $q = 'SELECT `currency_code_3` FROM `#__virtuemart_currencies` WHERE `virtuemart_currency_id`="' . $method->payment_currency . '" ';
     $db = JFactory::getDBO();
     $db->setQuery($q);
     $currency_code_3 = $db->loadResult();
     $paymentCurrency = CurrencyDisplay::getInstance($method->payment_currency);
     $totalInPaymentCurrency = $paymentCurrency->convertCurrencyTo($method->payment_currency, $order['details']['BT']->order_total, false);
     $cd = CurrencyDisplay::getInstance($cart->pricesCurrency);
     if ($totalInPaymentCurrency <= 0) {
         vmInfo(JText::_('VMPAYMENT_PAYTM_PAYMENT_AMOUNT_INCORRECT'));
         return false;
     }
     $merchant_id = $method->merchant_id;
     if (empty($merchant_id)) {
         vmInfo(JText::_('VMPAYMENT_PAYTM_MERCHANT_ID_NOT_SET'));
         return false;
     }
     $secret_key = $method->secret_key;
     if (empty($secret_key)) {
         vmInfo(JText::_('VMPAYMENT_PAYTM_SECRET_KEY_NOT_SET'));
         return false;
     }
     $channel_id = $method->channel_id;
     if (empty($channel_id)) {
         vmInfo(JText::_('VMPAYMENT_PAYTM_CHANNEL_ID_NOT_SET'));
         return false;
     }
     $industry_type = $method->industry_type;
     if (empty($industry_type)) {
         vmInfo(JText::_('VMPAYMENT_PAYTM_INDUSTRY_TYPE_NOT_SET'));
         return false;
     }
     $website_name = $method->website_name;
     if (empty($website_name)) {
         vmInfo(JText::_('VMPAYMENT_PAYTM_WEBSITE_NAME_NOT_SET'));
         return false;
     }
     $mode = $method->mode;
     $callbackflag = $method->callbackflag;
     $log = $method->log;
     $return_url = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&on=' . $order['details']['BT']->order_number . '&pm=' . $order['details']['BT']->virtuemart_paymentmethod_id . '&orderId=' . JRequest::getVar('orderId') . '&responseCode=' . JRequest::getVar('responseCode') . '&responseDescription=' . JRequest::getVar('responseDescription') . '&checksum=' . JRequest::getVar('checksum'));
     $product = $cart->products;
     //echo "<pre>";print_r($method);echo "</pre>";
     $description = $method->description;
     $order_id = $order['details']['BT']->order_number;
     $email = $order['details']['BT']->email;
     $firstname = $order['details']['BT']->first_name;
     $lastname = $order['details']['BT']->last_name;
     $address = $order['details']['BT']->address_1 . " " . $order['details']['BT']->address_2;
     $city = $order['details']['BT']->city;
     $state = isset($order['details']['BT']->virtuemart_state_id) ? ShopFunctions::getStateByID($order['details']['BT']->virtuemart_state_id) : '';
     $country = ShopFunctions::getCountryByID($order['details']['BT']->virtuemart_country_id, 'country_2_code');
     $zip = $order['details']['BT']->zip;
     $phone = $order['details']['BT']->phone_1;
     $amount = intval($totalInPaymentCurrency);
     //should be in paisa
     $ship_address = $address->address_1;
     if (isset($address->address_2)) {
         $ship_address .= " " . $address->address_2;
     }
     /*	$post_variables = Array(
     		    "merchantIdentifier" => $merchant_id, 
     		    "orderId" => $order_id,
     			"returnUrl" => $return_url,
     			"buyerEmail" => $email,
     			"buyerFirstName" => $firstname,
     			"buyerLastName" => $lastname,
     			"buyerAddress" => $address,
     			"buyerCity" => $city,
     			"buyerState" => $state,
     			"buyerCountry" => $country,
     			"buyerPincode" =>  $zip,
     			"buyerPhoneNumber" => $phone,
     			"txnType" => 1,
     			"zpPayOption" => 1,
     			"mode" => $mode,
     			"currency" => $currency_code_3,
     			"amount" => $amount,	
     			"merchantIpAddress" => "127.0.0.1",  	//Merchant Ip Address
     			"purpose" => 1,
     			"productDescription" => "Order Id ".$order_id,		//$product->virtuemart_product_name,//$description,
     			"shipToAddress" => $ship_address,	
     			"shipToCity" => $address->city,			
     			"shipToState" => isset($address->virtuemart_state_id) ? ShopFunctions::getStateByID($address->virtuemart_state_id) : '',
     			"shipToCountry" => ShopFunctions::getCountryByID($address->virtuemart_country_id, 'country_2_code'),
     		    "shipToPincode" => $address->zip,
     		    "shipToPhoneNumber" => $address->phone_1,
     			"shipToFirstName" => $address->first_name,
     			"shipToLastName" => $address->last_name,
     			"txnDate" => date('Y-m-d'),
     						
     		); */
     $post_variables = array("MID" => $merchant_id, "ORDER_ID" => $order_id, "CUST_ID" => $firstname, "TXN_AMOUNT" => $amount, "CHANNEL_ID" => $channel_id, "INDUSTRY_TYPE_ID" => $industry_type, "WEBSITE" => $website_name);
     if ($callbackflag == '1') {
         $post_variables["CALLBACK_URL"] = JURI::base() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&pm=paytm';
     }
     function sanitizedURL($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] = "%\\*%";
         $sanitizedParam = preg_replace($pattern, "", $param);
         return $sanitizedParam;
     }
     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;
     }
     $all = '';
     foreach ($post_variables as $name => $value) {
         if ($name != 'checksum') {
             $all .= "'";
             if ($name == 'returnUrl') {
                 $all .= sanitizedURL($value);
             } else {
                 $all .= sanitizedParam($value);
             }
             $all .= "'";
         }
     }
     function calculateChecksum($secret_key, $all)
     {
         $hash = hash_hmac('sha256', $all, $secret_key);
         $checksum = $hash;
         return $checksum;
     }
     if ($log == "on") {
         error_log("All Params : " . $all);
         error_log("Paytm Secret Key : " . $secret_key);
     }
     //$checksum = calculateChecksum($secret_key,$all);
     $checksum = getChecksumFromArray($post_variables, $secret_key);
     /*$post_variables = Array(
     		    "merchantIdentifier" => $merchant_id, 
     		    "orderId" => $order_id,
     			"returnUrl" => $return_url,
     			"buyerEmail" => sanitizedParam($email),
     			"buyerFirstName" => sanitizedParam($firstname),
     			"buyerLastName" => sanitizedParam($lastname),
     			"buyerAddress" => sanitizedParam($address),
     			"buyerCity" => $city,
     			"buyerState" => $state, 
     			"buyerCountry" => $country,
     			"buyerPincode" =>  $zip,
     			"buyerPhoneNumber" => $phone,
     			"txnType" => 1,
     			'zpPayOption' => 1,
     			"mode" => $mode,
     			"currency" => $currency_code_3,
     			"amount" => $amount,
     			"merchantIpAddress" => "127.0.0.1", 
     			"purpose" => 1,
     			"productDescription" => "Order Id ".$order_id, //$product->virtuemart_product_name,	//$description,
     		    "shipToAddress" => sanitizedParam($ship_address),	
     			"shipToCity" => $address->city,			
     			"shipToState" => isset($address->virtuemart_state_id) ? ShopFunctions::getStateByID($address->virtuemart_state_id) : '',
     			"shipToCountry" => ShopFunctions::getCountryByID($address->virtuemart_country_id, 'country_2_code'),
     			"shipToPincode" => $address->zip,
     		    "shipToPhoneNumber" => $address->phone_1,
     			"shipToFirstName" => $address->first_name,
     			"shipToLastName" => $address->last_name,
     			"txnDate" => date('Y-m-d'),
     			"checksum" => $checksum,			
     		); */
     $post_variables = array("MID" => $merchant_id, "ORDER_ID" => $order_id, "WEBSITE" => $website_name, "INDUSTRY_TYPE_ID" => $industry_type, "CHANNEL_ID" => $channel_id, "TXN_AMOUNT" => $amount, "CUST_ID" => $firstname, "txnDate" => date('Y-m-d H:i:s'), "CHECKSUMHASH" => $checksum);
     if ($callbackflag == '1') {
         $post_variables["CALLBACK_URL"] = JURI::base() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&pm=paytm';
     }
     $dbValues['order_number'] = $order['details']['BT']->order_number;
     $dbValues['payment_name'] = $this->renderPluginName($method, $order);
     $dbValues['virtuemart_paymentmethod_id'] = $cart->virtuemart_paymentmethod_id;
     $dbValues['description'] = $description;
     $dbValues['paytm_custom'] = $return_context;
     $dbValues['billing_currency'] = $method->payment_currency;
     $dbValues['amount'] = $amount;
     $this->storePSPluginInternalData($dbValues);
     if ($mode == 0) {
         $url = "pguat.paytm.com/oltp-web/processTransaction";
     } else {
         $url = "secure.paytm.in/oltp-web/processTransaction";
     }
     // add spin image
     $html = '<html><head><title>Redirection</title></head><body><div style="margin: auto; text-align: center;">';
     $html .= '<form action="' . "https://" . $url . '" method="post" name="vm_paytm_form" >';
     $html .= '<input type="submit"  value="' . JText::_('VMPAYMENT_PAYTM_REDIRECT_MESSAGE') . '" />';
     foreach ($post_variables as $name => $value) {
         $html .= '<input type="hidden" style="" name="' . $name . '" value="' . $value . '" />';
     }
     $html .= '</form></div>';
     $html .= ' <script type="text/javascript">';
     $html .= ' document.vm_paytm_form.submit();';
     $html .= ' </script></body></html>';
     // 	2 = don't delete the cart, don't send email and don't redirect
     $cart->_confirmDone = false;
     $cart->_dataValidated = false;
     $cart->setCartIntoSession();
     JRequest::setVar('html', $html);
 }
// Create an array having all required parameters for creating checksum.
$paramList["MID"] = PAYTM_MERCHANT_MID;
$paramList["ORDER_ID"] = $ORDER_ID;
$paramList["CUST_ID"] = $CUST_ID;
$paramList["INDUSTRY_TYPE_ID"] = $INDUSTRY_TYPE_ID;
$paramList["CHANNEL_ID"] = $CHANNEL_ID;
$paramList["TXN_AMOUNT"] = $TXN_AMOUNT;
$paramList["WEBSITE"] = PAYTM_MERCHANT_WEBSITE;
/*
$paramList["MSISDN"] = $MSISDN; //Mobile number of customer
$paramList["EMAIL"] = $EMAIL; //Email ID of customer
$paramList["VERIFIED_BY"] = "EMAIL"; //
$paramList["IS_USER_VERIFIED"] = "YES"; //
*/
//Here checksum string will return by getChecksumFromArray() function.
$checkSum = getChecksumFromArray($paramList, PAYTM_MERCHANT_KEY);
?>
<html>
<head>
<title>Merchant Check Out Page</title>
</head>
<body>
	<center><h1>Please do not refresh this page...</h1></center>
		<form method="post" action="<?php 
echo PAYTM_TXN_URL;
?>
" name="f1">
		<table border="1">
			<tbody>
			<?php 
foreach ($paramList as $name => $value) {