gogua

payge

Mar 6th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.00 KB | None | 0 0
  1. <?php
  2.  
  3. class payge extends PaymentModule
  4. {
  5.     private $_html = '';
  6.     private $_postErrors = array();
  7.  
  8.     public function __construct()
  9.     {
  10.    
  11.      $config = Configuration::getMultiple(array('GEOPAY_PAYGE_MERCHANT_NAME', 'GEOPAY_PAYGE_MERCHANT_KEY','GEOPAY_PAYGE_CALLBACK_URL','GEOPAY_PAYGE_SUCCESS_URL','GEOPAY_PAYGE_ERROR_URL','GEOPAY_PAYGE_CANCEL_URL'));
  12.  
  13.         $this->name = 'payge';        
  14.         $this->tab = 'payments_gateways';
  15.         $this->version = 1.0;
  16.         $this->author = 'PAYGE';
  17.         $this->currencies = true;
  18.         if(isset($config['GEOPAY_PAYGE_MERCHANT_NAME'])) $this->merchant_name = $config['GEOPAY_PAYGE_MERCHANT_NAME']; else   $this->merchant_name = '';
  19.         if(isset($config['GEOPAY_PAYGE_MERCHANT_KEY']))  $this->merchant_key = $config['GEOPAY_PAYGE_MERCHANT_KEY'];   else   $this->merchant_key  = '';
  20.         if(isset($config['GEOPAY_PAYGE_CALLBACK_URL']))  $this->callback_url = $config['GEOPAY_PAYGE_CALLBACK_URL'];   else   $this->callback_url  =    payge::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/payge/paycallback.php?';
  21.         if(isset($config['GEOPAY_PAYGE_SUCCESS_URL']))   $this->success_url = $config['GEOPAY_PAYGE_SUCCESS_URL'];     else   $this->success_url   =    payge::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/payge/redirect.php?paygestatus=SUCCESS&';
  22.         if(isset($config['GEOPAY_PAYGE_ERROR_URL']))     $this->error_url = $config['GEOPAY_PAYGE_ERROR_URL'];         else   $this->error_url     =    payge::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/payge/redirect.php?paygestatus=ERROR&';
  23.         if(isset($config['GEOPAY_PAYGE_CANCEL_URL']))    $this->cancel_url = $config['GEOPAY_PAYGE_CANCEL_URL'];       else   $this->cancel_url    =    payge::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/payge/redirect.php?paygestatus=CANCEL&';
  24.         if(isset($config['GEOPAY_PAYGE_TESTMODE']))      $this->testmode = $config['GEOPAY_PAYGE_TESTMODE'];           else   $this->testmode      = 1;        
  25.        
  26.         $this->success_text = 'Thank you! Your purchase was successful';
  27.         $this->error_text = 'Sorry, Your purchase cannot be completed. Please try again.';
  28.         $this->cancel_text = 'Sorry, your purchase was canceled. Please try again or contact your bank';
  29.        
  30.  
  31.  
  32.  
  33.         parent::__construct();
  34.        
  35.         /* The parent construct is required for translations */
  36.         $this->page = basename(__FILE__, '.php');
  37.         $this->displayName = 'payge';
  38.         $this->description = $this->l('Payments by LibertyBank.');
  39.         $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
  40.        
  41.     }        
  42.  
  43.     function install()
  44.     {        
  45.         if (!parent::install() OR !$this->registerHook('payment')  OR !$this->registerHook('updateOrderStatus'))       return false;
  46.  
  47.     $table1="CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."payge_payments` (
  48.        `id` int(20) NOT NULL auto_increment,
  49.        `status` varchar(50) NOT NULL,
  50.        `transactioncode` int(20) NOT NULL,
  51.        `amount` int(20) NOT NULL,
  52.        `currency` varchar(3) NOT NULL,
  53.        `ordercode` int(20) NOT NULL,
  54.        `paymethod` varchar(20) NOT NULL,
  55.        `testmode` varchar(1) NOT NULL,
  56.        `check` varchar(64) NOT NULL,
  57.        `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
  58.        PRIMARY KEY (`id`),
  59.        KEY `ordercode` (`ordercode`),
  60.        KEY `transactioncode` (`transactioncode`)
  61.        ) ENGINE=MyISAM";
  62.        
  63.        
  64.     $table2="CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."payge_payments_return` (
  65.        `id` int(20) NOT NULL auto_increment,
  66.        `transactioncode` int(20) NOT NULL,
  67.        `resultcode` enum('','0','1','-1','-2','-3') NOT NULL,
  68.        `data` varchar(255) NOT NULL,
  69.        `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
  70.        PRIMARY KEY (`id`),
  71.        KEY `transactioncode` (`transactioncode`)
  72.        ) ENGINE=MyISAM
  73.        ";
  74.          Db::getInstance()->Execute($table1);        
  75.          Db::getInstance()->Execute($table2);        
  76.         return true;
  77.     }
  78.    
  79.     function uninstall()
  80.     {
  81.          Configuration::deleteByName('GEOPAY_PAYGE_MERCHANT_NAME');
  82.          Configuration::deleteByName('GEOPAY_PAYGE_MERCHANT_KEY');
  83.          Configuration::deleteByName('GEOPAY_PAYGE_CALLBACK_URL');
  84.          Configuration::deleteByName('GEOPAY_PAYGE_SUCCESS_URL');
  85.          Configuration::deleteByName('GEOPAY_PAYGE_ERROR_URL');
  86.          Configuration::deleteByName('GEOPAY_PAYGE_CANCEL_URL');
  87.          Configuration::deleteByName('GEOPAY_PAYGE_TESTMODE');        
  88.          Db::getInstance()->Execute('DROP TABLE IF  EXISTS `'._DB_PREFIX_.'payge_payments`');
  89.      Db::getInstance()->Execute('DROP TABLE IF  EXISTS `'._DB_PREFIX_.'payge_payments_return`');
  90.  
  91.     return  parent::uninstall();
  92.     }
  93.    
  94.  
  95.    
  96.    
  97.     private function _displayForm()
  98.     {   $testmode =htmlentities(Tools::getValue('testmode', $this->testmode), ENT_COMPAT, 'UTF-8');
  99.         $this->_html .=
  100.         '<table  border="0"  cellpadding="0" cellspacing="0" id="tabs">
  101.           <tr>
  102.             <td><legend>'.$this->l('Settings').'</legend>  </td>
  103.           </tr>
  104.         </table>
  105.        <form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post">
  106.            <fieldset>
  107.                <table border="0" width="500" cellpadding="0" cellspacing="0" id="form">
  108.                    <tr><td ><b>'.$this->description.'</b><br /><br /></td></tr>
  109.                    <tr><td >'.$this->l('MERCHANT NAME:').'<br /></td><td><input type="text" name="merchant_name" value="'.htmlentities(Tools::getValue('merchant_name', $this->merchant_name), ENT_COMPAT, 'UTF-8').'" style="width: 300px;" /></td></tr>                    
  110.                    <tr><td >'.$this->l('MERCHANT KEY:').'<br /></td><td><input type="text" name="merchant_key" value="'.htmlentities(Tools::getValue('merchant_key', $this->merchant_key), ENT_COMPAT, 'UTF-8').'" style="width: 300px;" /></td></tr>
  111.                    <tr><td >'.$this->l('CALLBACK URL:').'<br /></td><td><input type="text" name="callback_url" value="'.htmlentities(Tools::getValue('callback_url', $this->callback_url), ENT_COMPAT, 'UTF-8').'" style="width: 300px;" /></td></tr>                                        
  112.                    <tr><td >'.$this->l('SUCCESS URL:').'<br /></td><td><input type="text" name="success_url" value="'.htmlentities(Tools::getValue('success_url', $this->success_url), ENT_COMPAT, 'UTF-8').'" style="width: 300px;" /></td></tr>
  113.                    <tr><td >'.$this->l('ERROR URL:').'<br /></td><td><input type="text" name="error_url" value="'.htmlentities(Tools::getValue('error_url', $this->error_url), ENT_COMPAT, 'UTF-8').'" style="width: 300px;" /></td></tr>                    
  114.                    <tr><td >'.$this->l('CANCEL URL:').'<br /></td><td><input type="text" name="cancel_url" value="'.htmlentities(Tools::getValue('cancel_url', $this->cancel_url), ENT_COMPAT, 'UTF-8').'" style="width: 300px;" /></td></tr>                    
  115.                    <tr><td >'.$this->l('Test Mode:').'<br /></td><td><select name="testmode"><option value="1" '.(( $testmode==1)?"SELECTED":"").'>Enabled</option><option value="0"'.(( $testmode==0)?"SELECTED":"").'>Disabled</option></select></td></tr>                                        
  116.                    <tr><td colspan="2" align="center"><br><input class="button" name="btnSubmit" value="'.$this->l('Update settings').'" type="submit" /></td></tr>
  117.                </table>
  118.            </fieldset>
  119.         </form>
  120.        ';
  121.     }
  122.    
  123.         private function _postProcess()
  124.     {
  125.         if (Tools::isSubmit('btnSubmit'))
  126.         {
  127.             Configuration::updateValue('GEOPAY_PAYGE_MERCHANT_NAME', Tools::getValue('merchant_name'));
  128.             Configuration::updateValue('GEOPAY_PAYGE_MERCHANT_KEY', Tools::getValue('merchant_key'));          
  129.             Configuration::updateValue('GEOPAY_PAYGE_CALLBACK_URL', Tools::getValue('callback_url'));
  130.             Configuration::updateValue('GEOPAY_PAYGE_SUCCESS_URL', Tools::getValue('success_url'));
  131.             Configuration::updateValue('GEOPAY_PAYGE_ERROR_URL', Tools::getValue('error_url'));
  132.             Configuration::updateValue('GEOPAY_PAYGE_CANCEL_URL', Tools::getValue('cancel_url'));
  133.             Configuration::updateValue('GEOPAY_PAYGE_TESTMODE', Tools::getValue('testmode'));          
  134.         }
  135.         $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('ok').'" /> '.$this->l('Settings updated').'</div>';
  136.     }
  137.  
  138.  
  139.     function getContent()
  140.     {
  141.         $this->_html = '<h2>'.$this->displayName.'</h2>';
  142.  
  143.         if (!empty($_POST))
  144.                             $this->_postProcess();
  145.                       else
  146.                             $this->_html .= '<br />';
  147.  
  148.         $this->_displayForm();
  149.         return $this->_html;
  150.     }
  151.  
  152.     /**
  153.      * getShopDomainSsl returns domain name according to configuration and depending on ssl activation
  154.      *
  155.      * @param boolean $http if true, return domain name with protocol
  156.      * @param boolean $entities if true,
  157.      * @return string domain
  158.      */
  159.     public static function getShopDomainSsl($http = false, $entities = false)
  160.     {
  161.         if (!($domain = Configuration::get('PS_SHOP_DOMAIN_SSL')))
  162.             $domain = Tools::getHttpHost();
  163.         if ($entities)
  164.             $domain = htmlspecialchars($domain, ENT_COMPAT, 'UTF-8');
  165.         if ($http)
  166.             $domain = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$domain;
  167.         return $domain;
  168.     }
  169.  
  170.  
  171. function hookPayment($params)
  172.     {
  173.    
  174.        global $smarty;
  175.        
  176.  
  177.              $smarty->assign(array(
  178.                         'this_module' => $this->name,
  179.                         'this_description' => $this->description,
  180.             'this_path' => $this->_path,
  181.             'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
  182.         ));
  183.  
  184.         return $this->display(__FILE__, 'payge.tpl');
  185.  
  186.    }
  187.  
  188.  
  189. function ProductData($products){
  190.     $return = "";
  191.     $a_product = "";
  192.     $b_product = "";
  193.     $SUM = 0;
  194.  
  195.  
  196.     for($i=0;$i< sizeof($products);$i++){
  197.     $product = $products[$i];
  198.     $Name = $product[name]." - ".$product[attributes];
  199.     $Quantity = $product[cart_quantity];
  200.     $Price = $product[price_wt];
  201.         $SUMPrice = $product[total_wt];
  202.         $SUM += $SUMPrice;
  203.         $NewName = $Quantity." x ".$Name;
  204.         $a_product .= $NewName.$SUMPrice;
  205.         $b_product .= '    <input type="hidden" name="item'.($i+1).'_name"  value="'.$NewName.'" />
  206.    <input type="hidden" name="item'.($i+1).'_price"  value="'.$SUMPrice.'" />
  207. ';
  208.     }
  209.         $arr = array();
  210.         $arr[0] = $a_product;
  211.         $arr[1] = $b_product;
  212.         $arr[2] = $SUM;
  213.         return $arr;
  214. }
  215.  
  216. function execPayment($cart){
  217.         $c = new Currency(intval($cart->id_currency));
  218.         $currency=$c->iso_code;
  219.         $amount        =  $cart->getOrderTotal(true, Cart::BOTH) * 100;
  220.         $cart_id       =  $cart->id;
  221.         $this->validateOrder($cart_id, _PS_OS_BANKWIRE_ , $amount / 100 , $this ->displayName, '');        
  222.  
  223.     $order_id      =  Order::getOrderByCartId($cart_id);
  224.         $description   =  'Payment of goods on the site '.$_SERVER['SERVER_NAME'];              
  225.                                          
  226.     $secretkey   =  $this->merchant_key;
  227.         $merchant    =  $this->merchant_name;
  228.         $ordercode   =  $order_id ;
  229.         $description =  $description ;
  230.         $clientname  =  $cart->id_customer;
  231.  
  232.         $customdata  =  "customdata";
  233.         $lng = Language::getIsoById(intval($cart->id_lang));
  234.         $successurl  =  $this->success_url;
  235.         $errorurl    =  $this->error_url ;
  236.         $cancelurl   =  $this->cancel_url;
  237.         $callbackurl =  $this->callback_url;
  238.         $testmode    =  $this->testmode;
  239.                          
  240.         $clientname  = htmlentities($clientname,ENT_QUOTES,"UTF-8");
  241.         $customdata  = htmlentities($customdata,ENT_QUOTES,"UTF-8");
  242.         $description = htmlentities($description,ENT_QUOTES,"UTF-8");
  243.         $products = $cart->getProducts();
  244.         $order_products = $this->ProductData($products);
  245.        
  246.  
  247.      $str = $secretkey
  248.            . $merchant
  249.            . $ordercode
  250.            . $amount
  251.            . $currency
  252.            . $description
  253.            . $clientname
  254.            . $customdata
  255.            . $lng
  256.            . $testmode
  257.            . $order_products[0];
  258.  
  259. $check = strtoupper(hash('sha256', $str));
  260.  
  261. $FORM="
  262.    <body onload = \"document.getElementById('frm').submit();\"><center><b>".$this->description."</b></center>
  263.    <form method='post' action='https://www.pay.ge/pay/' name='frm' id ='frm'>
  264.    <input type='hidden' name='merchant'    value='$merchant' />
  265.    <input type='hidden' name='ordercode'   value='$ordercode' />
  266.    <input type='hidden' name='amount'      value='$amount' />
  267.    <input type='hidden' name='currency'    value='$currency' />
  268.    <input type='hidden' name='description' value='$description' />
  269.    <input type='hidden' name='clientname'  value='$clientname' />
  270.    <input type='hidden' name='customdata'  value='$customdata' />
  271.    <input type='hidden' name='lng'         value='$lng' />
  272.    <input type='hidden' name='successurl'  value='$successurl' />
  273.    <input type='hidden' name='errorurl'    value='$errorurl' />
  274.    <input type='hidden' name='cancelurl'   value='$cancelurl' />
  275.    <input type='hidden' name='callbackurl' value='$callbackurl' />
  276.    <input type='hidden' name='testmode'    value='$testmode' />
  277.    <input type='hidden' name='check'       value='$check' />
  278. ".$order_products[1]."    
  279.    </form>
  280.    </body>
  281. ";
  282.  
  283.  
  284.  
  285. return $FORM;
  286.  
  287. }
  288.  
  289.  
  290.     function return_message($status)
  291.     {
  292.      switch($status)
  293.         {
  294.             case "SUCCESS"  : return  $this->success_text;
  295.                 case "ERROR"    : return  $this->error_text;
  296.                 case "CANCEL"   : return  $this->cancel_text;
  297.             default     : return  $this->error_text;
  298.         }
  299.     }    
  300.  
  301.     function redirect($status)
  302.     {
  303.      switch($status)
  304.         {
  305.             case "SUCCESS"  : Tools::redirectLink($this->success_url);
  306.                 case "ERROR"    : Tools::redirectLink($this->error_url);
  307.                 case "CANCEL"   : Tools::redirectLink($this->cancel_url);
  308.             default     : Tools::redirectLink($this->error_url);
  309.         }
  310.     }    
  311.    
  312.    
  313. }
  314.  
  315. ?>
Advertisement
Add Comment
Please, Sign In to add comment