public function execPayment($cart)
 {
     if (!$this->active) {
         return;
     }
     global $cookie, $smarty;
     // $this->display_column_left = false;
     // $this->display_column_right = false;
     // Check if cart_id has already been stored in tbl cart_sent
     $cart_id_count = @Db::getInstance()->getValue("SELECT COUNT( cart_id ) FROM  `" . _DB_PREFIX_ . "hipay_cart_sent` WHERE cart_id = '" . (int) $cart->id . "'");
     if ($cart_id_count == 0) {
         $sql_add_cart_id = "INSERT INTO `" . _DB_PREFIX_ . "hipay_cart_sent` (`cart_id`, `timestamp`)\r\n            VALUES('" . (int) $cart->id . "', NOW() )";
         @Db::getInstance()->execute($sql_add_cart_id);
     } else {
         // Found. Duplicate cart
         $duplicate_status_msg = HipayClass::duplicateCart();
         if ($duplicate_status_msg) {
             $override_payment_mode = true;
         }
     }
     $smarty->assign(array('nbProducts' => $cart->nbProducts(), 'cust_currency' => $cart->id_currency, 'currencies' => $this->getCurrency((int) $cart->id_currency), 'total' => $cart->getOrderTotal(true, Cart::BOTH), 'this_path' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/'));
     Tools::addCSS(_MODULE_DIR_ . $this->name . '/css/hipay.css');
     Tools::addJS(_MODULE_DIR_ . $this->name . '/js/14hipay.js');
     $hipay_payment_mode = Configuration::get('HIPAY_PAYMENT_MODE');
     if (Tools::getValue('cartMemorizeToken')) {
         $sql_insert = "INSERT INTO `" . _DB_PREFIX_ . "hipay_tokens_tmp` (`cart_id`) VALUES('" . (int) $cart->id . "')";
         @Db::getInstance()->execute($sql_insert);
     }
     // Initializing the payment mode to the default configuration mode
     $payment_mode = Configuration::get('HIPAY_PAYMENT_MODE');
     // Check card used - if card used is a local card, force mode 'dedicated page'
     if (Tools::isSubmit('localcardToken') && tools::getValue('localcardToken')) {
         // Override to mode page dedicated
         $payment_mode = 3;
     }
     // Last check, if $override_payment_mode = true then override all payement modes and force error message display
     if ($override_payment_mode) {
         // Override to mode page cart duplicated
         $payment_mode = 4;
         // Use $duplicate_status_msg to display msg err
     }
     // Different calls depending on Payment mode
     switch ($payment_mode) {
         case 1:
             // Mode Iframe
             $data = HipayApi::getApiData($cart, 'iframe');
             $response = HipayApi::restApi('hpayment', $data);
             // Update to display montant
             $currency_array = $this->getCurrency((int) $cart->id_currency);
             $currency = $currency_array[0]['iso_code'];
             foreach ($currency_array as $key => $value) {
                 if ($value['id_currency'] == $cart->id_currency) {
                     $actual_currency = $value['iso_code'];
                 }
             }
             if ($currency != $actual_currency) {
                 $currency = $actual_currency;
             }
             if (Tools::strlen(Configuration::get('HIPAY_IFRAME_WIDTH')) > 0) {
                 $iframe_width = Configuration::get('HIPAY_IFRAME_WIDTH');
             } else {
                 $iframe_width = '100%';
             }
             if (Tools::strlen(Configuration::get('HIPAY_IFRAME_HEIGHT')) > 0) {
                 $iframe_height = Configuration::get('HIPAY_IFRAME_HEIGHT');
             } else {
                 $iframe_height = '670';
             }
             $this->context->smarty->assign(array('iframe_url' => $response->forwardUrl, 'cart_id' => $cart->id, 'currency' => $currency, 'amount' => $cart->getOrderTotal(true, Cart::BOTH), 'iframe_width' => $iframe_width, 'iframe_height' => $iframe_height));
             // $payment_tpl = 'payment_execution_iframe.tpl';
             return $this->display(__FILE__, '1.4/views/templates/front/payment_execution_iframe.tpl');
             break;
         case 2:
             // Mode API
             // Mode API
             // Constructs data array and sends it as a parameter to the tpl
             $currency_array = $this->getCurrency((int) $cart->id_currency);
             $currency = $currency_array[0]['iso_code'];
             foreach ($currency_array as $key => $value) {
                 if ($value['id_currency'] == $cart->id_currency) {
                     $actual_currency = $value['iso_code'];
                 }
             }
             if ($currency != $actual_currency) {
                 $currency = $actual_currency;
             }
             $this->context->smarty->assign(array('status_error' => '200', 'cart_id' => $cart->id, 'currency' => $currency, 'amount' => $cart->getOrderTotal(true, Cart::BOTH)));
             // Tpl will load a form that will store those infomations.
             $card_str = Configuration::get('HIPAY_ALLOWED_CARDS');
             $selection_cards = array('american-express' => $this->l('American Express'), 'bcmc' => $this->l('Bancontact / Mister Cash'), 'cb' => $this->l('Carte Bancaire'), 'maestro' => $this->l('Maestro'), 'mastercard' => $this->l('MasterCard'), 'visa' => $this->l('Visa'));
             $cart_arr = explode(',', $card_str);
             $carte = array();
             foreach ($cart_arr as $key => $value) {
                 foreach ($selection_cards as $key1 => $value1) {
                     if ($key1 && $value == $key1) {
                         $carte[$key1] = $value1;
                     }
                 }
             }
             $this->context->smarty->assign(array('cartes' => $carte));
             $tokens = HipayToken::getTokens($cart->id_customer);
             //
             if (isset($tokens['0'])) {
                 $token_display = 'true';
             } else {
                 $token_display = 'false';
             }
             $allow_memorize = HipayClass::getShowMemorization();
             $this->context->smarty->assign(array('token_display' => $token_display, 'allow_memorize' => $allow_memorize, 'tokens' => $tokens));
             // Assign paths
             $smarty->assign(array('this_path' => $this->_path, 'this_path_bw' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/'));
             // $payment_tpl = 'payment_execution_api.tpl';
             return $this->display(__FILE__, '1.4/views/templates/front/payment_execution_api.tpl');
             break;
         case 3:
             $local_card = tools::getValue('localcardToken');
             $data = HipayApi::getApiData($cart, null, null, $local_card);
             if ($local_card == 'sofort-uberweisung' || $local_card == 'sisal' || $local_card == 'przelewy24' || $local_card == 'webmoney' || $local_card == 'yandex' || $local_card == 'paypal') {
                 $data['payment_product'] = $local_card;
                 unset($data['payment_product_list']);
                 unset($data['merchant_display_name']);
                 unset($data['css']);
                 $response = HipayApi::restApi('order', $data);
             } else {
                 $response = HipayApi::restApi('hpayment', $data);
             }
             if ($response == false) {
                 // Wrong response, redirect to page order first step
                 Tools::redirect('index.php?controller=order&xer=2');
             }
             Tools::redirect($response->forwardUrl, '');
             break;
         case 4:
             // Use $duplicate_status_msg array to display msg err
             $this->context->smarty->assign(array('duplicate_status_msg' => $duplicate_status_msg));
             return $this->display(__FILE__, '1.4/views/templates/front/payment_cart_duplicate.tpl');
             break;
         case 0:
         default:
             // Dedicated page
             // NO TPL NEEDED, will redirect to response forwardURL
             if (Tools::isSubmit('localcardToken') && tools::getValue('localcardToken')) {
                 $local_card = tools::getValue('localcardToken');
             } else {
                 $local_card = null;
             }
             // p($local_card);
             $data = HipayApi::getApiData($cart, null, null, $local_card);
             // p($data);
             // die(0);
             $response = HipayApi::restApi('hpayment', $data);
             // p($response);
             // die('here');
             if ($response == false) {
                 // Wrong response, redirect to page order first step
                 Tools::redirect('index.php?controller=order&xer=2');
             }
             Tools::redirect($response->forwardUrl, '');
             break;
     }
     return $this->display(__FILE__, '1.4/views/templates/front/payment_execution.tpl');
 }