Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class payge extends PaymentModule
- {
- private $_html = '';
- private $_postErrors = array();
- public function __construct()
- {
- $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'));
- $this->name = 'payge';
- $this->tab = 'payments_gateways';
- $this->version = 1.0;
- $this->author = 'PAYGE';
- $this->currencies = true;
- if(isset($config['GEOPAY_PAYGE_MERCHANT_NAME'])) $this->merchant_name = $config['GEOPAY_PAYGE_MERCHANT_NAME']; else $this->merchant_name = '';
- if(isset($config['GEOPAY_PAYGE_MERCHANT_KEY'])) $this->merchant_key = $config['GEOPAY_PAYGE_MERCHANT_KEY']; else $this->merchant_key = '';
- 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?';
- 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&';
- 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&';
- 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&';
- if(isset($config['GEOPAY_PAYGE_TESTMODE'])) $this->testmode = $config['GEOPAY_PAYGE_TESTMODE']; else $this->testmode = 1;
- $this->success_text = 'Thank you! Your purchase was successful';
- $this->error_text = 'Sorry, Your purchase cannot be completed. Please try again.';
- $this->cancel_text = 'Sorry, your purchase was canceled. Please try again or contact your bank';
- parent::__construct();
- /* The parent construct is required for translations */
- $this->page = basename(__FILE__, '.php');
- $this->displayName = 'payge';
- $this->description = $this->l('Payments by LibertyBank.');
- $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
- }
- function install()
- {
- if (!parent::install() OR !$this->registerHook('payment') OR !$this->registerHook('updateOrderStatus')) return false;
- $table1="CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."payge_payments` (
- `id` int(20) NOT NULL auto_increment,
- `status` varchar(50) NOT NULL,
- `transactioncode` int(20) NOT NULL,
- `amount` int(20) NOT NULL,
- `currency` varchar(3) NOT NULL,
- `ordercode` int(20) NOT NULL,
- `paymethod` varchar(20) NOT NULL,
- `testmode` varchar(1) NOT NULL,
- `check` varchar(64) NOT NULL,
- `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- KEY `ordercode` (`ordercode`),
- KEY `transactioncode` (`transactioncode`)
- ) ENGINE=MyISAM";
- $table2="CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."payge_payments_return` (
- `id` int(20) NOT NULL auto_increment,
- `transactioncode` int(20) NOT NULL,
- `resultcode` enum('','0','1','-1','-2','-3') NOT NULL,
- `data` varchar(255) NOT NULL,
- `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- KEY `transactioncode` (`transactioncode`)
- ) ENGINE=MyISAM
- ";
- Db::getInstance()->Execute($table1);
- Db::getInstance()->Execute($table2);
- return true;
- }
- function uninstall()
- {
- Configuration::deleteByName('GEOPAY_PAYGE_MERCHANT_NAME');
- Configuration::deleteByName('GEOPAY_PAYGE_MERCHANT_KEY');
- Configuration::deleteByName('GEOPAY_PAYGE_CALLBACK_URL');
- Configuration::deleteByName('GEOPAY_PAYGE_SUCCESS_URL');
- Configuration::deleteByName('GEOPAY_PAYGE_ERROR_URL');
- Configuration::deleteByName('GEOPAY_PAYGE_CANCEL_URL');
- Configuration::deleteByName('GEOPAY_PAYGE_TESTMODE');
- Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'payge_payments`');
- Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'payge_payments_return`');
- return parent::uninstall();
- }
- private function _displayForm()
- { $testmode =htmlentities(Tools::getValue('testmode', $this->testmode), ENT_COMPAT, 'UTF-8');
- $this->_html .=
- '<table border="0" cellpadding="0" cellspacing="0" id="tabs">
- <tr>
- <td><legend>'.$this->l('Settings').'</legend> </td>
- </tr>
- </table>
- <form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post">
- <fieldset>
- <table border="0" width="500" cellpadding="0" cellspacing="0" id="form">
- <tr><td ><b>'.$this->description.'</b><br /><br /></td></tr>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <tr><td colspan="2" align="center"><br><input class="button" name="btnSubmit" value="'.$this->l('Update settings').'" type="submit" /></td></tr>
- </table>
- </fieldset>
- </form>
- ';
- }
- private function _postProcess()
- {
- if (Tools::isSubmit('btnSubmit'))
- {
- Configuration::updateValue('GEOPAY_PAYGE_MERCHANT_NAME', Tools::getValue('merchant_name'));
- Configuration::updateValue('GEOPAY_PAYGE_MERCHANT_KEY', Tools::getValue('merchant_key'));
- Configuration::updateValue('GEOPAY_PAYGE_CALLBACK_URL', Tools::getValue('callback_url'));
- Configuration::updateValue('GEOPAY_PAYGE_SUCCESS_URL', Tools::getValue('success_url'));
- Configuration::updateValue('GEOPAY_PAYGE_ERROR_URL', Tools::getValue('error_url'));
- Configuration::updateValue('GEOPAY_PAYGE_CANCEL_URL', Tools::getValue('cancel_url'));
- Configuration::updateValue('GEOPAY_PAYGE_TESTMODE', Tools::getValue('testmode'));
- }
- $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('ok').'" /> '.$this->l('Settings updated').'</div>';
- }
- function getContent()
- {
- $this->_html = '<h2>'.$this->displayName.'</h2>';
- if (!empty($_POST))
- $this->_postProcess();
- else
- $this->_html .= '<br />';
- $this->_displayForm();
- return $this->_html;
- }
- /**
- * getShopDomainSsl returns domain name according to configuration and depending on ssl activation
- *
- * @param boolean $http if true, return domain name with protocol
- * @param boolean $entities if true,
- * @return string domain
- */
- public static function getShopDomainSsl($http = false, $entities = false)
- {
- if (!($domain = Configuration::get('PS_SHOP_DOMAIN_SSL')))
- $domain = Tools::getHttpHost();
- if ($entities)
- $domain = htmlspecialchars($domain, ENT_COMPAT, 'UTF-8');
- if ($http)
- $domain = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$domain;
- return $domain;
- }
- function hookPayment($params)
- {
- global $smarty;
- $smarty->assign(array(
- 'this_module' => $this->name,
- 'this_description' => $this->description,
- 'this_path' => $this->_path,
- 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
- ));
- return $this->display(__FILE__, 'payge.tpl');
- }
- function ProductData($products){
- $return = "";
- $a_product = "";
- $b_product = "";
- $SUM = 0;
- for($i=0;$i< sizeof($products);$i++){
- $product = $products[$i];
- $Name = $product[name]." - ".$product[attributes];
- $Quantity = $product[cart_quantity];
- $Price = $product[price_wt];
- $SUMPrice = $product[total_wt];
- $SUM += $SUMPrice;
- $NewName = $Quantity." x ".$Name;
- $a_product .= $NewName.$SUMPrice;
- $b_product .= ' <input type="hidden" name="item'.($i+1).'_name" value="'.$NewName.'" />
- <input type="hidden" name="item'.($i+1).'_price" value="'.$SUMPrice.'" />
- ';
- }
- $arr = array();
- $arr[0] = $a_product;
- $arr[1] = $b_product;
- $arr[2] = $SUM;
- return $arr;
- }
- function execPayment($cart){
- $c = new Currency(intval($cart->id_currency));
- $currency=$c->iso_code;
- $amount = $cart->getOrderTotal(true, Cart::BOTH) * 100;
- $cart_id = $cart->id;
- $this->validateOrder($cart_id, _PS_OS_BANKWIRE_ , $amount / 100 , $this ->displayName, '');
- $order_id = Order::getOrderByCartId($cart_id);
- $description = 'Payment of goods on the site '.$_SERVER['SERVER_NAME'];
- $secretkey = $this->merchant_key;
- $merchant = $this->merchant_name;
- $ordercode = $order_id ;
- $description = $description ;
- $clientname = $cart->id_customer;
- $customdata = "customdata";
- $lng = Language::getIsoById(intval($cart->id_lang));
- $successurl = $this->success_url;
- $errorurl = $this->error_url ;
- $cancelurl = $this->cancel_url;
- $callbackurl = $this->callback_url;
- $testmode = $this->testmode;
- $clientname = htmlentities($clientname,ENT_QUOTES,"UTF-8");
- $customdata = htmlentities($customdata,ENT_QUOTES,"UTF-8");
- $description = htmlentities($description,ENT_QUOTES,"UTF-8");
- $products = $cart->getProducts();
- $order_products = $this->ProductData($products);
- $str = $secretkey
- . $merchant
- . $ordercode
- . $amount
- . $currency
- . $description
- . $clientname
- . $customdata
- . $lng
- . $testmode
- . $order_products[0];
- $check = strtoupper(hash('sha256', $str));
- $FORM="
- <body onload = \"document.getElementById('frm').submit();\"><center><b>".$this->description."</b></center>
- <form method='post' action='https://www.pay.ge/pay/' name='frm' id ='frm'>
- <input type='hidden' name='merchant' value='$merchant' />
- <input type='hidden' name='ordercode' value='$ordercode' />
- <input type='hidden' name='amount' value='$amount' />
- <input type='hidden' name='currency' value='$currency' />
- <input type='hidden' name='description' value='$description' />
- <input type='hidden' name='clientname' value='$clientname' />
- <input type='hidden' name='customdata' value='$customdata' />
- <input type='hidden' name='lng' value='$lng' />
- <input type='hidden' name='successurl' value='$successurl' />
- <input type='hidden' name='errorurl' value='$errorurl' />
- <input type='hidden' name='cancelurl' value='$cancelurl' />
- <input type='hidden' name='callbackurl' value='$callbackurl' />
- <input type='hidden' name='testmode' value='$testmode' />
- <input type='hidden' name='check' value='$check' />
- ".$order_products[1]."
- </form>
- </body>
- ";
- return $FORM;
- }
- function return_message($status)
- {
- switch($status)
- {
- case "SUCCESS" : return $this->success_text;
- case "ERROR" : return $this->error_text;
- case "CANCEL" : return $this->cancel_text;
- default : return $this->error_text;
- }
- }
- function redirect($status)
- {
- switch($status)
- {
- case "SUCCESS" : Tools::redirectLink($this->success_url);
- case "ERROR" : Tools::redirectLink($this->error_url);
- case "CANCEL" : Tools::redirectLink($this->cancel_url);
- default : Tools::redirectLink($this->error_url);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment