Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function _gen_hash($query = '')
- {
- // Check if we have a salt value set in our config file
- if ( $this->config->item('hash_salt') === FALSE )
- {
- show_error('A hashing salt value must be set.');
- }
- // If we passed in an array, we need to build it into a string
- if( is_array($query) )
- {
- $query = $this->_build_query($query);
- }
- // If our query has the &hashValue in it still (from beanstream's response), get rid of it
- if( strpos($query, '&hashValue=') !== FALSE )
- {
- $query = substr($query, 0, strpos($query, '&hashValue='));
- }
- // Add the salt onto our query
- $string = $query.$this->config->item('hash_salt');
- return sha1($string);
- }
- private function _build_query($data = array())
- {
- $query = '';
- foreach ( $data as $k => $v )
- {
- $v = ( $k == 'trnAmount' ) ? $v : $this->_bs_encode($v);
- $query .= '&' . $k . '=' . $v;
- }
- // substr used to get rid of the leading "&"
- return substr($query, 1);
- }
- // Encodes spaces into a "+" and all other non-alphanumerics into their hex values
- private function _bs_encode($str = '')
- {
- return preg_replace_callback(
- '([^A-Za-z0-9])',
- create_function(
- '$non_alphanum',
- '
- $c = $non_alphanum[0];
- return ( $c == " " ) ? "+" : "%".strtoupper(bin2hex($c));
- '
- ),
- $str
- );
- }
Add Comment
Please, Sign In to add comment