Advertisement
sdevilcry

Prestashop module Ogone - ogone.php

Jun 30th, 2011
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.60 KB | None | 0 0
  1. <?php
  2. /*
  3. * 2007-2011 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Academic Free License (AFL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/afl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. *  @author PrestaShop SA <contact@prestashop.com>
  22. *  @copyright  2007-2011 PrestaShop SA
  23. *  @version  Release: $Revision: 1.4 $
  24. *  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  25. *  International Registered Trademark & Property of PrestaShop SA
  26. */
  27.  
  28. class Ogone extends PaymentModule
  29. {
  30.     private $_ignoreKeyList = array('secure_key');
  31.  
  32.     public function __construct()
  33.     {
  34.         $this->name = 'ogone';
  35.         $this->tab = 'payments_gateways';
  36.         $this->version = '2.1';
  37.        
  38.         parent::__construct();
  39.        
  40.         $this->displayName = 'Ogone';
  41.         $this->description = '';
  42.     }
  43.    
  44.     public function install()
  45.     {
  46.         return (parent::install() AND
  47.             $this->registerHook('payment') AND
  48.             $this->registerHook('orderConfirmation'));
  49.     }
  50.    
  51.     public function getContent()
  52.     {
  53.         if (Tools::isSubmit('submitOgone'))
  54.         {
  55.             Configuration::updateValue('OGONE_PSPID', Tools::getValue('OGONE_PSPID'));
  56.             Configuration::updateValue('OGONE_SHA_IN', Tools::getValue('OGONE_SHA_IN'));
  57.             Configuration::updateValue('OGONE_SHA_OUT', Tools::getValue('OGONE_SHA_OUT'));
  58.             Configuration::updateValue('OGONE_MODE', (int)Tools::getValue('OGONE_MODE'));
  59.             $dataSync = (($pspid = Configuration::get('OGONE_PSPID'))
  60.                 ? '<img src="http://www.prestashop.com/modules/ogone.png?pspid='.urlencode($pspid).'&mode='.(int)Tools::getValue('OGONE_MODE').'" style="float:right" />'
  61.                 : ''
  62.             );
  63.             echo $this->displayConfirmation($this->l('Configuration updated').$dataSync);
  64.         }
  65.        
  66.         return '
  67.         <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Help').'</legend>
  68.             <p>'.$this->l('Please follow these steps:').'</p>
  69.             <ol>
  70.                 <li>
  71.                     <h3>'.$this->l('PrestaShop side').'</h3>
  72.                     <ol>
  73.                         <li>'.$this->l('Fill in your Ogone ID (PSPID)').'</li>
  74.                         <li>'.$this->l('Fill in the signatures of your choice (you will have to copy them to Ogone back office).').'</li>
  75.                         <li>'.$this->l('Select test mode if you just created your test account on Ogone (it does not work with the demo account).').'</li>
  76.                     </ol>
  77.                 </li>
  78.                 <li>
  79.                     <h3>
  80.                         '.$this->l('Ogone Side').' /
  81.                         <a href="https://secure.ogone.com/ncol/test/admin_ogone.asp"><span style="text-decoration:underline;color:#383838">'.$this->l('test mode').'</span></a> /
  82.                         <a href="https://secure.ogone.com/ncol/prod/admin_ogone.asp"><span style="text-decoration:underline;color:#383838">'.$this->l('production mode').'</span></a>
  83.                     </h3>
  84.                     <ol>
  85.                         <li><a href="../modules/'.$this->name.'/docs/en1.png">'.$this->l('See the screenshot for step').' 1</a></li>
  86.                         <li><a href="../modules/'.$this->name.'/docs/en2.png">'.$this->l('See the screenshot for step').' 2</a></li>
  87.                         <li><a href="../modules/'.$this->name.'/docs/en3.png">'.$this->l('See the screenshot for step').' 3</a></li>
  88.                         <li><a href="../modules/'.$this->name.'/docs/en4.png">'.$this->l('See the screenshot for step').' 4</a></li>
  89.                     </ol>
  90.                 </li>
  91.             </ol>
  92.             <h3>'.$this->l('Test cards').'</h3>
  93.             <ul>
  94.                 <li>Visa : 4111 1111 1111 1111</li>
  95.                 <li>Visa 3D : 4000 0000 0000 0002</li>
  96.                 <li>American Express : 3741 1111 1111 111</li>
  97.                 <li>MasterCard : 5399 9999 9999 9999</li>
  98.                 <li>Diners : 3625 5695 5800 17</li>
  99.                 <li>Bancontact/Mister : 67030000000000003</li>
  100.                 <li>Visa Purchasing : 4484 1200 0000 0029</li>
  101.                 <li>American Express : 3742 9101 9071 995</li>
  102.             </ul>
  103.             <div class="clear">&nbsp;</div>
  104.         </fieldset>
  105.         <div class="clear">&nbsp;</div>
  106.         <form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post">
  107.             <fieldset><legend><img src="../img/admin/contact.gif" /> '.$this->l('Settings').'</legend>
  108.                 <label for="pspid">'.$this->l('PSPID').'</label>
  109.                 <div class="margin-form">
  110.                     <input type="text" id="pspid" size="20" name="OGONE_PSPID" value="'.Tools::getValue('OGONE_PSPID', Configuration::get('OGONE_PSPID')).'" />
  111.                 </div>
  112.                 <div class="clear">&nbsp;</div>
  113.                 <label for="sha-in">'.$this->l('SHA-in signature').'</label>
  114.                 <div class="margin-form">
  115.                     <input type="text" id="sha-in" size="20" name="OGONE_SHA_IN" value="'.Tools::getValue('OGONE_SHA_IN', Configuration::get('OGONE_SHA_IN')).'" />
  116.                 </div>
  117.                 <div class="clear">&nbsp;</div>
  118.                 <label for="sha-out">'.$this->l('SHA-out signature').'</label>
  119.                 <div class="margin-form">
  120.                     <input type="text" id="sha-out" size="20" name="OGONE_SHA_OUT" value="'.Tools::getValue('OGONE_SHA_OUT', Configuration::get('OGONE_SHA_OUT')).'" />
  121.                 </div>
  122.                 <div class="clear">&nbsp;</div>
  123.                 <label>'.$this->l('Mode').'</label>
  124.                 <div class="margin-form">
  125.                     <span style="display:block;float:left;margin-top:3px;"><input type="radio" id="test" name="OGONE_MODE" value="0" style="vertical-align:middle;display:block;float:left;margin-top:2px;margin-right:3px;"
  126.                         '.(!Tools::getValue('OGONE_MODE', Configuration::get('OGONE_MODE')) ? 'checked="checked"' : '').'
  127.                     />
  128.                     <label for="test" style="color:#900;display:block;float:left;text-align:left;width:60px;">'.$this->l('Test').'</label>&nbsp;</span>
  129.                     <span style="display:block;float:left;margin-top:3px;">
  130.                     <input type="radio" id="production" name="OGONE_MODE" value="1" style="vertical-align:middle;display:block;float:left; margin-top:2px;margin-right:3px;"
  131.                         '.(Tools::getValue('OGONE_MODE', Configuration::get('OGONE_MODE')) ? 'checked="checked"' : '').'
  132.                     />
  133.                     <label for="production" style="color:#080;display:block;float:left;text-align:left;width:85px;">'.$this->l('Production').'</label></span>
  134.                 </div>
  135.                 <div class="clear">&nbsp;</div>
  136.                 <input type="submit" name="submitOgone" value="'.$this->l('Update settings').'" class="button" />
  137.             </fieldset>
  138.         </form>
  139.         <div class="clear">&nbsp;</div>';
  140.     }
  141.    
  142.     public function getIgnoreKeyList()
  143.     {
  144.         return $this->_ignoreKeyList;
  145.     }
  146.    
  147.     public function hookPayment($params)
  148.     {
  149.         global $smarty;
  150.        
  151.         $currency = new Currency((int)($params['cart']->id_currency));
  152.         $lang = new Language((int)($params['cart']->id_lang));
  153.         $customer = new Customer((int)($params['cart']->id_customer));
  154.         $address = new Address((int)($params['cart']->id_address_invoice));
  155.         $country = new Country((int)($address->id_country), (int)($params['cart']->id_lang));
  156.        
  157.         $ogoneParams = array();
  158.         $ogoneParams['PSPID'] = Configuration::get('OGONE_PSPID');
  159.         $ogoneParams['OPERATION'] = 'SAL';
  160.         $ogoneParams['ORDERID'] = pSQL($params['cart']->id);
  161.         $ogoneParams['AMOUNT'] = number_format(Tools::convertPrice((float)(number_format($params['cart']->getOrderTotal(true, Cart::BOTH), 2, '.', '')), $currency), 2, '.', '') * 100;
  162.         $ogoneParams['CURRENCY'] = $currency->iso_code;
  163.         $ogoneParams['LANGUAGE'] = $lang->iso_code.'_'.strtoupper($lang->iso_code);
  164.         $ogoneParams['CN'] = $customer->lastname;
  165.         $ogoneParams['EMAIL'] = $customer->email;
  166.         $ogoneParams['OWNERZIP'] = $address->postcode;
  167.         $ogoneParams['OWNERADDRESS'] = ($address->address1);
  168.         $ogoneParams['OWNERCTY'] = $country->iso_code;
  169.         $ogoneParams['OWNERTOWN'] = $address->city;
  170.         $ogoneParams['PARAMPLUS'] = 'secure_key='.$params['cart']->secure_key;
  171.         if (!empty($address->phone))
  172.             $ogoneParams['OWNERTELNO'] = $address->phone;
  173.  
  174.         ksort($ogoneParams);
  175.         $shasign = '';
  176.         foreach ($ogoneParams as $key => $value)
  177.             $shasign .= strtoupper($key).'='.$value.Configuration::get('OGONE_SHA_IN');
  178.         $ogoneParams['SHASign'] = strtoupper(sha1($shasign));
  179.        
  180.         $smarty->assign('ogone_params', $ogoneParams);
  181.         $smarty->assign('OGONE_MODE', Configuration::get('OGONE_MODE'));
  182.        
  183.         return $this->display(__FILE__, 'ogone.tpl');
  184.     }
  185.    
  186.     public function hookOrderConfirmation($params)
  187.     {
  188.         global $smarty, $cookie;
  189.        
  190.         if ($params['objOrder']->module != $this->name)
  191.             return;
  192.        
  193.         if ($params['objOrder']->valid)
  194.             $smarty->assign(array('status' => 'ok', 'id_order' => $params['objOrder']->id));
  195.         else
  196.             $smarty->assign('status', 'failed');
  197.         $link = new Link();
  198.         $smarty->assign('ogone_link', (method_exists($link, 'getPageLink') ? $link->getPageLink('contact-form.php', true) : Tools::getHttpHost(true).'contact-form.php'));
  199.         return $this->display(__FILE__, 'hookorderconfirmation.tpl');
  200.     }
  201.    
  202.     public function validate($id_cart, $id_order_state, $amount, $message = '', $secure_key)
  203.     {
  204.         $this->validateOrder((int)$id_cart, $id_order_state, $amount, $this->displayName, $message, NULL, NULL, true, pSQL($secure_key));
  205.         if ($amount > 0 AND class_exists('PaymentCC'))
  206.         {
  207.             $pcc = new PaymentCC();
  208.             $order = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'orders WHERE id_cart = '.(int)$secure_cart[0]);
  209.             $pcc->id_order = (int)$order['id_order'];
  210.             $pcc->id_currency = (int)$order['id_currency'];
  211.             $pcc->amount = $amount;
  212.             $pcc->transaction_id = Tools::getValue('PAYID');
  213.             $pcc->card_number = Tools::getValue('CARDNO');
  214.             $pcc->card_brand = Tools::getValue('BRAND');
  215.             $pcc->card_expiration = Tools::getValue('ED');
  216.             $pcc->card_holder = Tools::getValue('CN');
  217.             $pcc->add();
  218.         }
  219.     }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement