/**
  * The function sets EndPointUrl param of OpenPayU
  * @access public
  * @param string $ep
  */
 public static function setOpenPayuEndPoint($ep)
 {
     self::$openPayuEndPointUrl = $ep;
 }
 /**
  * Function builds OpenPayU Form
  * @access public
  * @param string $data
  * @param string $msg_name
  * @param string $version
  * @return string
  */
 public static function buildOpenPayuForm($data, $msg_name, $version = '1.0')
 {
     if (!is_array($data)) {
         return false;
     }
     $url = OpenPayUNetwork::getOpenPayuEndPoint();
     $form = "<form method='post' action='" . $url . "'>\n";
     $form .= OpenPayUBase::buildFormFragmentInput('HeaderRequest.Version', $version);
     $form .= OpenPayUBase::buildFormFragmentInput('HeaderRequest.Name', $msg_name);
     $form .= OpenPayUBase::arr2form($data, '', '');
     $form .= '</form>';
     return $form;
 }
 /**
  * @access public
  * @param string $oauth_client_name
  * @param string $oauth_client_secret
  * @return mixed
  * @throws Exception
  */
 public static function getAccessTokenOnly($oauth_client_name, $oauth_client_secret)
 {
     $params = 'client_id=' . $oauth_client_name . '&client_secret=' . $oauth_client_secret . '&grant_type=client_credentials';
     $response = OpenPayU::sendData(OpenPayUNetwork::getOpenPayuEndPoint(), $params);
     $resp_json = Tools::jsonDecode($response);
     OpenPayU::addOutputConsole('oauth response', $response);
     if (isset($resp_json->{'access_token'})) {
         $access_token = $resp_json->{'access_token'};
     }
     if (empty($access_token)) {
         throw new Exception('access_token is empty, error: ' . $response);
     }
     return $access_token;
 }
 /**
  * The function sets EndPointUrl param of OpenPayU
  * @access public
  * @param string $ep
  */
 public static function setOpenPayuEndPoint($ep)
 {
     self::$open_payu_end_point_url = $ep;
 }
 /**
  * This function sends auth data to the EndPointUrl OpenPayU
  * @access public
  * @param string $doc
  * @param integer $merchantPosId
  * @param string $signatureKey
  * @param string $algorithm
  * @return string $response
  */
 public static function sendOpenPayuDocumentAuth($doc, $merchantPosId, $signatureKey, $algorithm = 'MD5')
 {
     if (empty(OpenPayUNetwork::$openPayuEndPointUrl)) {
         throw new Exception('OpenPayUNetwork::$openPayuEndPointUrl is empty');
     }
     if (empty($signatureKey)) {
         throw new Exception('Merchant Signature Key should not be null or empty.');
     }
     if (empty($merchantPosId)) {
         throw new Exception('MerchantPosId should not be null or empty.');
     }
     $tosigndata = $doc . $signatureKey;
     $xml = urlencode($doc);
     $signature = '';
     if ($algorithm == 'MD5') {
         $signature = md5($tosigndata);
     } else {
         if ($algorithm == 'SHA') {
             $signature = sha1($tosigndata);
         } else {
             if ($algorithm == 'SHA-256' || $algorithm == 'SHA256' || $algorithm == 'SHA_256') {
                 $signature = hash('sha256', $tosigndata);
             }
         }
     }
     $authData = 'sender=' . $merchantPosId . ';signature=' . $signature . ';algorithm=' . $algorithm . ';content=DOCUMENT';
     $response = '';
     if (OpenPayUNetwork::isCurlInstalled()) {
         $response = OpenPayU::sendDataAuth(OpenPayUNetwork::$openPayuEndPointUrl, 'DOCUMENT=' . $xml, $authData);
     } else {
         throw new Exception('curl is not available');
     }
     return $response;
 }