Advertisement
sdevilcry

Prestashop module Ogone - validation.php

Jun 30th, 2011
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.89 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. include(dirname(__FILE__).'/../../config/config.inc.php');
  29. include(dirname(__FILE__).'/ogone.php');
  30.  
  31. $ogone = new Ogone();
  32.  
  33. /* First we need to check var presence */
  34. $neededVars = array('orderID', 'amount', 'currency', 'PM', 'ACCEPTANCE', 'STATUS', 'CARDNO', 'PAYID', 'NCERROR', 'BRAND', 'SHASIGN');
  35. $params = '<br /><br />'.$ogone->l('Received parameters:').'<br /><br />';
  36.  
  37. foreach ($neededVars AS $k)
  38.     if (!isset($_GET[$k]))
  39.         die($ogone->l('Missing parameter:').' '.$k);
  40.     else
  41.         $params .= $k.' : '.$_GET[$k].'<br />';
  42.  
  43. /* Then, load the customer cart and perform some checks */
  44. $cart = new Cart((int)($_GET['orderID']));
  45. if (Validate::isLoadedObject($cart))
  46. {
  47.     /* Fist, check for a valid SHA-1 signature */
  48.     $ogoneParams = array();
  49.     $ignoreKeyList = $ogone->getIgnoreKeyList();
  50.    
  51.     foreach ($_GET as $key => $value)
  52.         if (strtoupper($key) != 'SHASIGN' AND $value != '' AND !in_array($key, $ignoreKeyList))
  53.             $ogoneParams[strtoupper($key)] = $value;
  54.  
  55.     ksort($ogoneParams);
  56.     $shasign = '';
  57.     foreach ($ogoneParams as $key => $value)
  58.         $shasign .= strtoupper($key).'='.$value.Configuration::get('OGONE_SHA_OUT');
  59.     $sha1 = strtoupper(sha1($shasign));
  60.    
  61.     if ($sha1 == $_GET['SHASIGN'])
  62.     {
  63.         switch ($_GET['STATUS'])
  64.         {
  65.             case 1:
  66.                 /* Real error or payment canceled */
  67.                 $ogone->validate((int)$_GET['orderID'], _PS_OS_ERROR_, 0, $_GET['NCERROR'].$params, $_GET['secure_key']);
  68.                 break;
  69.             case 2:
  70.                 /* Real error - authorization refused */
  71.                 $ogone->validate((int)$_GET['orderID'], _PS_OS_ERROR_, 0, $ogone->l('Error (auth. refused)').'<br />'.$_GET['NCERROR'].$params, $_GET['secure_key']);
  72.                 break;
  73.             case 5:
  74.             case 9:
  75.                 /* Payment OK */
  76.                 $ogone->validate((int)$_GET['orderID'], _PS_OS_PAYMENT_, (float)($_GET['amount']), $ogone->l('Payment authorized / OK').$params, $_GET['secure_key']);
  77.                 break;
  78.             case 6:
  79.             case 7:
  80.             case 8:
  81.                 // Payment canceled later
  82.                 if ($id_order = (int)(Order::getOrderByCartId((int)($_GET['orderID']))))
  83.                 {
  84.                     // Update the amount really paid
  85.                     $order = new Order($id_order);
  86.                     $order->total_paid_real = 0;
  87.                     $order->update();
  88.                    
  89.                     // Send a new message and change the state
  90.                     $history = new OrderHistory();
  91.                     $history->id_order = $id_order;
  92.                     $history->changeIdOrderState(_PS_OS_ERROR_, $id_order);
  93.                     $history->addWithemail(true, array());
  94.                 }
  95.                 break;
  96.             default:
  97.                 $ogone->validate((int)$_GET['orderID'], _PS_OS_ERROR_, (float)($_GET['amount']), $ogone->l('Unknown status:').' '.$_GET['STATUS'].$params, $_GET['secure_key']);
  98.         }
  99.         exit;
  100.     }
  101.     else
  102.     {
  103.         $message = $ogone->l('Invalid SHA-1 signature').'<br />'.$ogone->l('SHA-1 given:').' '.$_GET['SHASIGN'].'<br />'.$ogone->l('SHA-1 calculated:').' '.$sha1.'<br />'.$ogone->l('Plain key:').' '.$shasign;
  104.         $ogone->validate((int)$_GET['orderID'], _PS_OS_ERROR_, 0, $message.'<br />'.$params, $_GET['secure_key']);
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement