Advertisement
Guest User

GP Webpay

a guest
Jul 27th, 2011
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.15 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Epay_gpwebpay
  4. {
  5.     var $private_key, $password, $public_key, $digest;
  6.  
  7.     public $params = array();
  8.  
  9.  
  10.     var $options    = array(
  11.         'MERCHANTNUMBER'    => GP_WEBPAY_MID,
  12.         'OPERATION'     => 'CREATE_ORDER',
  13.         'CURRENCY'      => '978',
  14.         'DEPOSITFLAG'       => 1,
  15.         'DESCRIPTION'       => 'nejaky text',
  16.         'MD'            => 'nejaky text'
  17.         );
  18.  
  19.     function __construct()
  20.     {
  21.         $this->CI =& get_instance();
  22.     }
  23.  
  24.     function sign($key, $password)
  25.     {
  26.         $fp = fopen($key, "r");
  27.         $this->private_key = fread($fp, filesize($key));
  28.         fclose($fp);
  29.         $this->password=$password;
  30.  
  31.         $digestValue = implode('|', $this->params);
  32.  
  33.         $keyid = openssl_get_privatekey($this->private_key, $this->password);
  34.         openssl_sign($digestValue, $this->digest, $keyid);
  35.         $this->digest = base64_encode($this->digest);
  36.         openssl_free_key($keyid);
  37.     }
  38.  
  39.     function verify($key)
  40.     {
  41.         $fp = fopen($key, "r");
  42.         $this->public_key = fread($fp, filesize($key));
  43.         fclose($fp);
  44.  
  45.         $pubcertid = openssl_get_publickey($this->public_key);
  46.         $digest = base64_decode($this->digest);
  47.         $data = implode('|', $this->params);
  48.         $result = openssl_verify($data, $digest, $pubcertid);
  49.         openssl_free_key($pubcertid);
  50.         return (($result == 1) ? true : false);
  51.     }
  52.  
  53.     function send_request($data)
  54.     {
  55.  
  56.         $this->params['MERCHANTNUMBER'] = $this->options['MERCHANTNUMBER'];
  57.         $this->params['OPERATION'] = $this->options['OPERATION'];
  58.         $this->params['ORDERNUMBER'] = $data['variable_symbol'];
  59.         $this->params['AMOUNT'] = $data['price'] * 100;
  60.         $this->params['CURRENCY'] = $this->options['CURRENCY'];
  61.         $this->params['DEPOSITFLAG'] = $this->options['DEPOSITFLAG'];
  62.         $this->params['MERORDERNUM'] = $data['variable_symbol'];
  63.         $this->params['URL'] = $data['redirect_url'];
  64.         $this->params['DESCRIPTION'] = $this->options['DESCRIPTION'];
  65.         $this->params['MD'] = base64_encode($this->options['MD']);
  66.  
  67.         $this->sign(GP_WEBPAY_PRIVATE_KEY, GP_WEBPAY_PASSWORD);
  68.  
  69.         if (isset($this->digest))
  70.         {
  71.             $this->params['DIGEST'] = $this->digest;
  72.             $this->params = array_map('urlencode', $this->params);
  73.             array_walk($this->params, create_function('&$val, $key', '$val = "$key=$val";'));
  74.  
  75.             return GP_WEBPAY_URL . "?" . implode('&', $this->params);
  76.         }
  77.         else
  78.         {
  79.             return false;
  80.         }
  81.     }
  82.  
  83.     function receive_response() {
  84.  
  85.     $this->params = array();
  86.     $this->params['OPERATION'] = isset($_GET['OPERATION']) ? $_GET['OPERATION'] : '';
  87.     $this->params['ORDERNUMBER'] = isset($_GET['ORDERNUMBER']) ? $_GET['ORDERNUMBER'] : '';
  88.     $this->params['MERORDERNUM'] = isset($_GET['MERORDERNUM']) ? $_GET['MERORDERNUM'] : '';
  89.     $this->params['MD'] = isset($_GET['MD']) ? $_GET['MD'] : '';
  90.     $this->params['PRCODE'] = isset($_GET['PRCODE']) ? $_GET['PRCODE'] : '';
  91.     $this->params['SRCODE'] = isset($_GET['SRCODE']) ? $_GET['SRCODE'] : '';
  92.     $this->params['RESULTTEXT'] = isset($_GET['RESULTTEXT']) ? $_GET['RESULTTEXT'] : '';
  93.  
  94.     $this->digest = isset($_GET['DIGEST']) ? $_GET['DIGEST'] : '';
  95.  
  96.     return ($this->verify(GP_WEBPAY_PUBLIC_KEY) && ($this->params['PRCODE'] == 0) && ($this->params['SRCODE'] == 0)) ? true : false;
  97.  
  98.   }
  99. }
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement