Пример #1
0
 protected function _postRequest(Varien_Object $request)
 {
     if ($this->getConfigData('debug')) {
         foreach ($request->getData() as $key => $value) {
             $value = (string) $value;
             $requestData[] = strtoupper($key) . '[' . strlen($value) . ']=' . $value;
         }
         $requestData = join('&', $requestData);
         $debug = Mage::getModel('paygate/authorizenet_debug')->setRequestBody($requestData)->setRequestSerialized(serialize($request->getData()))->setRequestDump(print_r($request->getData(), 1))->save();
     }
     $client = new Varien_Http_Client();
     $_config = array('maxredirects' => 5, 'timeout' => 30);
     $_isProxy = $this->getConfigData('use_proxy', false);
     if ($_isProxy) {
         $_config['proxy'] = $this->getConfigData('proxy_host') . ':' . $this->getConfigData('proxy_port');
         //http://proxy.shr.secureserver.net:3128',
         $_config['httpproxytunnel'] = true;
         $_config['proxytype'] = CURLPROXY_HTTP;
     }
     $uri = $this->getConfigData('url');
     $client->setUri($uri)->setConfig($_config)->setMethod(Zend_Http_Client::POST)->setParameterPost($request->getData())->setHeaders('X-VPS-VIT-CLIENT-CERTIFICATION-ID: 33baf5893fc2123d8b191d2d011b7fdc')->setHeaders('X-VPS-Request-ID: ' . $request->getRequestId())->setHeaders('X-VPS-CLIENT-TIMEOUT: ' . $this->_clientTimeout);
     /*
      * we are sending request to payflow pro without url encoding
      * so we set up _urlEncodeBody flag to false
      */
     $response = $client->setUrlEncodeBody(false)->request();
     $result = Mage::getModel('paygate/payflow_pro_result');
     $response = strstr($response->getBody(), 'RESULT');
     $valArray = explode('&', $response);
     foreach ($valArray as $val) {
         $valArray2 = explode('=', $val);
         $result->setData(strtolower($valArray2[0]), $valArray2[1]);
     }
     $result->setResultCode($result->getResult())->setRespmsg($result->getRespmsg());
     if (!empty($debug)) {
         $debug->setResponseBody($response)->setResultSerialized(serialize($result->getData()))->setResultDump(print_r($result->getData(), 1))->save();
     }
     return $result;
 }
 /**
  * Post request to gateway and return response
  *
  * @param Varien_Object $request
  * @return Varien_Object
  */
 protected function _postRequest(Varien_Object $request)
 {
     $debugData = array('request' => $request->getData());
     $client = new Varien_Http_Client();
     $result = new Varien_Object();
     $_config = array('maxredirects' => 5, 'timeout' => 30);
     $_isProxy = $this->getConfigData('use_proxy', false);
     if ($_isProxy) {
         $_config['proxy'] = $this->getConfigData('proxy_host') . ':' . $this->getConfigData('proxy_port');
         //http://proxy.shr.secureserver.net:3128',
         $_config['httpproxytunnel'] = true;
         $_config['proxytype'] = CURLPROXY_HTTP;
     }
     $client->setUri($this->_getTransactionUrl())->setConfig($_config)->setMethod(Zend_Http_Client::POST)->setParameterPost($request->getData())->setHeaders('X-VPS-VIT-CLIENT-CERTIFICATION-ID: 33baf5893fc2123d8b191d2d011b7fdc')->setHeaders('X-VPS-Request-ID: ' . $request->getRequestId())->setHeaders('X-VPS-CLIENT-TIMEOUT: ' . $this->_clientTimeout);
     try {
         /**
          * we are sending request to payflow pro without url encoding
          * so we set up _urlEncodeBody flag to false
          */
         $response = $client->setUrlEncodeBody(false)->request();
     } catch (Exception $e) {
         $result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
         $debugData['result'] = $result->getData();
         $this->_debug($debugData);
         throw $e;
     }
     $response = strstr($response->getBody(), 'RESULT');
     $valArray = explode('&', $response);
     foreach ($valArray as $val) {
         $valArray2 = explode('=', $val);
         $result->setData(strtolower($valArray2[0]), $valArray2[1]);
     }
     $result->setResultCode($result->getResult())->setRespmsg($result->getRespmsg());
     $debugData['result'] = $result->getData();
     $this->_debug($debugData);
     return $result;
 }
Пример #3
0
 private function _tokenWorker($token, $request)
 {
     $base64ClientID = base64_encode($this->_clientId . ":" . $this->_clientSecret);
     $client = new Varien_Http_Client();
     $result = new Varien_Object();
     $_config = array('maxredirects' => 5, 'timeout' => 5);
     $client->setUri($this->getAccessTokenEndPoint())->setConfig($_config)->setMethod(Zend_Http_Client::POST)->setParameterPost($request->getData())->setHeaders('User-Agent: Varien_Http_Client')->setHeaders('Authorization: Basic ' . $base64ClientID)->setHeaders('Accept: */*');
     try {
         $response = $client->setUrlEncodeBody(false)->request();
     } catch (Exception $e) {
         $result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
         $debugData['result'] = $result->getData();
         $this->_debug($debugData);
         throw new Mage_Exception($e->getMessage());
         return false;
     }
     $body = Mage::helper('core')->jsonDecode($response->getBody());
     $result->addData($body);
     $debugData['result'] = $result->getData();
     $this->_debug($debugData);
     if (isset($debugData['result']['error'])) {
         Mage::log($debugData['result']['error_description']);
         return false;
     }
     return $result;
 }