/** * Client GET call * * @param $string, $string * @return Varien_Http_Client $response */ private function getClient($apiKey, $url) { $client = new Varien_Http_Client($url); $client->setMethod(Varien_Http_Client::GET); $client->setHeaders('Authorization', 'Token token="' . $apiKey . '"'); return $client; }
/** * @param array $data Array of each installed Fontis extensions version * @return string * @throws Exception */ public function request($data) { $client = new Varien_Http_Client(Mage::helper('fontis_info')->getInfoUrl(), array('keepalive' => true)); $client->setParameterPost('data', $data); // If we accept gzip encoding and the response isn't actually chunked, Zend_Http_Response will throw // an exception. Unfortunately, this means we can't use gzip encoded responses at this time. $client->setHeaders('Accept-encoding', 'identity'); $response = $client->request(Varien_Http_Client::POST); if ($response->isError()) { // if the request fails, throw an exception throw new Exception('Error getting info data: ' . $response->getStatus() . ' ' . $response->getMessage()); } return $response->getBody(); }
/** * This function returns full transaction details for a specified transaction ID. * * @link http://www.authorize.net/support/ReportingGuide_XML.pdf * @link http://developer.authorize.net/api/transaction_details/ * @param string $transactionId * @return Varien_Object */ protected function _getTransactionDetails($transactionId) { $requestBody = sprintf('<?xml version="1.0" encoding="utf-8"?>' . '<getTransactionDetailsRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">' . '<merchantAuthentication><name>%s</name><transactionKey>%s</transactionKey></merchantAuthentication>' . '<transId>%s</transId>' . '</getTransactionDetailsRequest>', $this->getConfigData('login'), $this->getConfigData('trans_key'), $transactionId); $client = new Varien_Http_Client(); $uri = $this->getConfigData('cgi_url_td'); $client->setUri($uri ? $uri : self::CGI_URL_TD); $client->setConfig(array('timeout' => 45)); $client->setHeaders(array('Content-Type: text/xml')); $client->setMethod(Zend_Http_Client::POST); $client->setRawData($requestBody); $debugData = array('request' => $requestBody); try { $responseBody = $client->request()->getBody(); $debugData['result'] = $responseBody; $this->_debug($debugData); libxml_use_internal_errors(true); $responseXmlDocument = new Varien_Simplexml_Element($responseBody); libxml_use_internal_errors(false); } catch (Exception $e) { Mage::throwException(Mage::helper('paygate')->__('Payment updating error.')); } $response = new Varien_Object(); $response->setResponseCode((string) $responseXmlDocument->transaction->responseCode)->setResponseReasonCode((string) $responseXmlDocument->transaction->responseReasonCode); return $response; }
public function postData($json, $endpoint) { $apiURL = Mage::getStoreConfig('settings/endpoint_url') . '/' . $endpoint; $appID = Mage::getStoreConfig('reachly_handleevent_options/section_one/field_app_id'); $secretKey = Mage::getStoreConfig('reachly_handleevent_options/section_one/field_secret_key'); $auth = $appID . ":" . base64_encode(hash_hmac('sha256', $json, $secretKey)); $client = new Varien_Http_Client(); $client->setUri($apiURL)->setMethod('POST')->setConfig(array('maxredirects' => 0, 'timeout' => 15)); $client->setHeaders(array('Content-Length: ' . strlen($json), 'Authorization: ' . $auth)); $client->setRawData($json, "application/json;charset=UTF-8"); $reqCounter = 0; do { $success = true; try { $response = $client->request(); } catch (Zend_Http_Client_Exception $e) { $success = false; $reqCounter++; } } while (!$success && $reqCounter < 3); }
private function rpxCall($url, $method = 'GET', $postParams = null) { $result = "rpxCallUrl: no result yet"; try { $http = new Varien_Http_Client($url); $http->setHeaders(array("Accept-encoding" => "identity")); if ($method == 'POST') { $http->setParameterPost($postParams); } $response = $http->request($method); $body = $response->getBody(); try { $result = json_decode($body); } catch (Exception $e) { throw Mage::exception('Mage_Core', $e); } if ($result) { return $result; } else { throw Mage::exception('Mage_Core', "something went wrong"); } } catch (Exception $e) { throw Mage::exception('Mage_Core', $e); } }
/** * Send the HTTP request and return an HTTP response object * * @param string $url * @param Varien_Object $data * @param string $method * @return Varien_Object */ public function request($url, Varien_Object $data, $method = 'GET') { $client = new Varien_Http_Client($url, array('timeout' => 30)); $client->setMethod($method); $client->setHeaders('Accept-Encoding: identity'); if ($method == Zend_Http_Client::POST) { $client->setParameterPost($this->_parseArray($data)); } else { $client->setParameterGet($this->_parseArray($data)); } $response = $client->request(); $body = json_decode($response->getBody(), true); $result = $this->_parseObject($body); return $result; }