Guest User

Untitled

a guest
Oct 17th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. private function _gen_hash($query = '')
  2. {
  3.     // Check if we have a salt value set in our config file
  4.     if ( $this->config->item('hash_salt') === FALSE )
  5.     {
  6.         show_error('A hashing salt value must be set.');
  7.     }
  8.  
  9.     // If we passed in an array, we need to build it into a string
  10.     if( is_array($query) )
  11.     {
  12.         $query = $this->_build_query($query);
  13.     }
  14.  
  15.     // If our query has the &hashValue in it still (from beanstream's response), get rid of it
  16.     if( strpos($query, '&hashValue=') !== FALSE )
  17.     {
  18.         $query = substr($query, 0, strpos($query, '&hashValue='));
  19.     }
  20.  
  21.     // Add the salt onto our query
  22.     $string = $query.$this->config->item('hash_salt');
  23.  
  24.     return sha1($string);
  25. }
  26.  
  27.  
  28. private function _build_query($data = array())
  29. {
  30.     $query = '';
  31.  
  32.     foreach ( $data as $k => $v )
  33.     {
  34.         $v = ( $k == 'trnAmount' ) ? $v : $this->_bs_encode($v);
  35.  
  36.         $query .= '&' . $k . '=' . $v;
  37.     }
  38.  
  39.     // substr used to get rid of the leading "&"
  40.     return substr($query, 1);
  41. }
  42.  
  43.  
  44. // Encodes spaces into a "+" and all other non-alphanumerics into their hex values
  45. private function _bs_encode($str = '')
  46. {
  47.     return preg_replace_callback(
  48.         '([^A-Za-z0-9])',
  49.         create_function(
  50.             '$non_alphanum',
  51.             '
  52.             $c = $non_alphanum[0];
  53.             return ( $c == " " ) ? "+" : "%".strtoupper(bin2hex($c));
  54.             '
  55.         ),
  56.         $str
  57.     );
  58. }
Add Comment
Please, Sign In to add comment