Ejemplo n.º 1
0
 /**
  * Retrieve rate
  *
  * @param   string $currencyFrom
  * @param   string $currencyTo
  * @return  float
  */
 protected function _convert($currencyFrom, $currencyTo, $retry = 0)
 {
     if ($currencyFrom != 'RUB' && $currencyTo != 'RUB') {
         return null;
     }
     $direction = null;
     if ($currencyTo == 'RUB') {
         $direction = 'to';
     }
     if ($currencyFrom == 'RUB') {
         $direction = 'from';
     }
     if (!$direction) {
         return null;
     }
     try {
         $response = $this->_httpClient->setUri($this->_url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/cbrf/timeout')))->request('GET')->getBody();
         $xml = simplexml_load_string($response, null, LIBXML_NOERROR);
         if (!$xml) {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $this->_url);
             return null;
         }
         return $this->processRates($xml->Valute, $direction, $currencyFrom, $currencyTo);
     } catch (Exception $e) {
         if ($retry == 0) {
             $this->_convert($currencyFrom, $currencyTo, 1);
         } else {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $this->_url);
         }
     }
     return null;
 }
 /**
  * Initialise our object with the full rates retrieved from Privatbankrates as the
  * free version only allows us to get the complete set of rates. But that's ok, we are
  * caching it and then processing the individual rates
  *
  * @throws Exception
  */
 public function __construct()
 {
     $this->_httpClient = new Varien_Http_Client();
     $url = $this->_url;
     $response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/pm_privatbankrates/timeout')))->request('GET')->getBody();
     // response is in json format
     if (!$response) {
         $this->_messages[] = Mage::helper('pm_privatbankrates')->__('Cannot retrieve rate from %s.', $url);
     } else {
         // check response content - returns array
         $response = Zend_Json::decode($response);
         if (array_key_exists('error', $response)) {
             $this->_messages[] = Mage::helper('pm_privatbankrates')->__('API returned error %s: %s', $response['status'], $response['description']);
         } elseif (array_key_exists('base_ccy', $response[0])) {
             $rates = array();
             $rates['UAH'] = array('buy' => 1, 'sale' => 1);
             foreach ((array) $response as $currency) {
                 $rates[$currency['ccy']] = $currency;
             }
             $this->_rates = $rates;
         } else {
             Mage::log('Privatbankrates API request: %s', $url);
             Mage::log('Privatbankrates API response: ' . print_r($response, true));
             $this->_messages[] = Mage::helper('pm_privatbankrates')->__('Unknown response from API, check system.log for details.');
         }
     }
 }
Ejemplo n.º 3
0
 protected function _convert($currencyFrom, $currencyTo, $retry = 0)
 {
     $url = sprintf($this->_url, $currencyFrom, $currencyTo);
     try {
         $response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/fixerio/timeout')))->request('GET')->getBody();
         $converted = json_decode($response);
         $rate = $converted->rates->{$currencyTo};
         if (!$rate) {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
             return null;
         }
         //test for bcmath to retain precision
         if (function_exists('bcadd')) {
             return bcadd($rate, '0', 12);
         }
         return (double) $rate;
     } catch (Exception $e) {
         if ($retry == 0) {
             return $this->_convert($currencyFrom, $currencyTo, 1);
         } else {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
             return null;
         }
     }
 }
 /**
  * Retrieve rate
  *
  * @param   string $currencyFrom
  * @param   string $currencyTo
  * @param   int $retry
  * @return  float
  */
 protected function _convert($currencyFrom, $currencyTo, $retry = 0)
 {
     $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
     $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
     try {
         sleep(Mage::getStoreConfig('currency/google_finance/delay'));
         $response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/google_finance/timeout')))->request('GET')->getBody();
         $data = explode('bld>', $response);
         if (empty($data[1])) {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
             return null;
         }
         $data = explode($currencyTo, $data[1]);
         $exchangeRate = 1;
         if (empty($data[0])) {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
             return null;
         } else {
             $exchangeRate = $data[0];
         }
         return (double) $exchangeRate * 1.0;
     } catch (Exception $e) {
         if ($retry == 0) {
             $this->_convert($currencyFrom, $currencyTo, 1);
         } else {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Get the Http Client to use for the request to reCAPTCHA
  *
  * @return Varien_Http_Client
  */
 public function getHttpClient()
 {
     if (is_null($this->_client)) {
         $this->_client = new Varien_Http_Client();
     }
     $this->_client->setUri(self::REQUEST_URL);
     return $this->_client;
 }
Ejemplo n.º 6
0
 public function restRequest($method, $params)
 {
     $result = null;
     $url = $this->_getRestUrl($method);
     $data = $this->_restDataFormat($method, $params);
     $httpClient = new Varien_Http_Client();
     $result = $httpClient->setUri($url)->setHeaders('Content-Type: text/xml; charset=UTF-8')->setRawData($data)->request(Varien_Http_Client::POST)->getBody();
     return $result;
 }
Ejemplo n.º 7
0
 protected function _convert($currencyFrom, $currencyTo, $retry = 0)
 {
     $supported = $this->getSupportedCurrencies();
     if (!(in_array($currencyFrom, $supported) && $currencyTo == 'BTC' || $currencyFrom == 'BTC' && in_array($currencyTo, $supported))) {
         $this->_messages[] = Mage::helper('directory')->__('Conversion from %s to %s is not supported by BitPay Bitcoin Exchange Rates will fallback to use Webservicex.', $currencyFrom, $currencyTo);
         try {
             $default = Mage::getModel('directory/currency_import_webservicex');
             return $default->convert($currencyFrom, $currencyTo);
         } catch (Exception $e) {
             $this->_messages[] = $e->getMessage();
         }
     }
     try {
         $response = $this->_httpClient->setUri($this->_url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/bitpay/timeout')))->request('GET')->getBody();
         $prices = (array) json_decode($response);
         if (!$prices) {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $this->_url);
             return null;
         }
         $altCurrency = $currencyFrom == "BTC" ? $currencyTo : $currencyFrom;
         foreach ($prices as $price) {
             if ($price->code == $altCurrency) {
                 $rate = $price->rate;
             }
         }
         if (!$rate) {
             return null;
         }
         if ($currencyFrom == "BTC") {
             $result = (double) $rate;
         } else {
             $result = 1 / (double) $rate;
         }
         $this->_messages[] = Mage::helper('directory')->__('Retrieved rate from %s to %s.', $currencyFrom, $currencyTo);
         return $result;
     } catch (Exception $e) {
         if ($retry == 0) {
             $this->_convert($currencyFrom, $currencyTo, 1);
         } else {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $_url);
         }
     }
 }
 public function tunnelAction()
 {
     $httpClient = new Varien_Http_Client();
     if ($ga = $this->getRequest()->getParam('ga')) {
         if ($params = unserialize(base64_decode(urldecode($ga)))) {
             $response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 15))->request('GET');
             $headers = $response->getHeaders();
             $this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
         }
     }
 }
Ejemplo n.º 9
0
 protected function _convert($currencyFrom, $currencyTo, $retry = 0)
 {
     $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
     $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
     try {
         $response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/webservicex/timeout')))->request('GET')->getBody();
         $xml = simplexml_load_string($response, null, LIBXML_NOERROR);
         if (!$xml) {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
             return null;
         }
         return (double) $xml;
     } catch (Exception $e) {
         if ($retry == 0) {
             $this->_convert($currencyFrom, $currencyTo, 1);
         } else {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
         }
     }
 }
Ejemplo n.º 10
0
 protected function _convert($currencyFrom, $currencyTo, $retry = 0)
 {
     $supported = $this->getSupportedCurrencies();
     if (!(in_array($currencyFrom, $supported) && $currencyTo == 'BTC' || $currencyFrom == 'BTC' && in_array($currencyTo, $supported))) {
         //$this->_messages[] = Mage::helper('bitcoin')->__('Conversion from %s to %s is not supported in Bitcoincharts.', $currencyFrom, $currencyTo);
         //return null;
         try {
             $default = Mage::getModel('directory/currency_import_webservicex');
             return $default->convert($currencyFrom, $currencyTo);
         } catch (Exception $e) {
             $this->_messages[] = $e->getMessage();
         }
     }
     try {
         $response = $this->_httpClient->setUri($this->_url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/bitcoincharts/timeout')))->request('GET')->getBody();
         $prices = (array) json_decode($response);
         if (!$prices) {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $this->_url);
             return null;
         }
         $altCurrency = $currencyFrom == "BTC" ? $currencyTo : $currencyFrom;
         // 24h, 7d, 30d
         // assume 24h
         $rate = (array) $prices[$altCurrency];
         if (!$rate) {
             return null;
         }
         if ($currencyFrom == "BTC") {
             $result = (double) $rate["24h"];
         } else {
             $result = 1 / (double) $rate["24h"];
         }
         return $result;
     } catch (Exception $e) {
         if ($retry == 0) {
             $this->_convert($currencyFrom, $currencyTo, 1);
         } else {
             $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
         }
     }
 }
 public function tunnelAction()
 {
     $httpClient = new Varien_Http_Client();
     $gaData = $this->getRequest()->getParam('ga');
     $gaHash = $this->getRequest()->getParam('h');
     if ($gaData && $gaHash) {
         $newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
         if ($newHash == $gaHash) {
             $params = json_decode(base64_decode(urldecode($gaData)), true);
             if ($params) {
                 $response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 5))->request('GET');
                 $headers = $response->getHeaders();
                 $this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
             }
         }
     }
 }
 public function tunnelAction()
 {
     //if(!Mage::helper('magenotification')->checkLicenseKeyAdminController($this)){ return; }
     $httpClient = new Varien_Http_Client();
     $gaData = $this->getRequest()->getParam('ga');
     $gaHash = $this->getRequest()->getParam('h');
     if ($gaData && $gaHash) {
         $newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
         if ($newHash == $gaHash) {
             if ($params = unserialize(base64_decode(urldecode($gaData)))) {
                 $response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 5))->request('GET');
                 $headers = $response->getHeaders();
                 $this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
             }
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Verify installation id in Worldpay registration system to reduce configuration failures (experimental)
  *
  * @return Phoenix_Worldpay_Model_Config_Backend_Instid
  */
 protected function _beforeSave()
 {
     try {
         if ($this->getValue()) {
             $client = new Varien_Http_Client();
             $client->setUri((string) Mage::getConfig()->getNode('phoenix/worldpay/verify_url'))->setConfig(array('timeout' => 10))->setHeaders('accept-encoding', '')->setParameterPost('inst_id', $this->getValue())->setMethod(Zend_Http_Client::POST);
             $response = $client->request();
             //                $responseBody = $response->getBody();
             //                if (empty($responseBody) || $responseBody != 'VERIFIED') {
             // verification failed. throw error message (not implemented yet).
             //                }
             // okay, inst_id verified. continue saving.
         }
     } catch (Exception $e) {
         // verification system unavailable. no further action.
     }
     return parent::_beforeSave();
 }
Ejemplo n.º 14
0
 public function localeTestAction()
 {
     var_dump(Mage::getModel('inchoo_facebook/locale')->getOptionLocales());
     //var_dump(Mage::app()->getLocale()->getOptionLocales());
     return;
     $client = new Varien_Http_Client();
     $response = $client->setUri('http://www.facebook.com/translations/FacebookLocale.xml')->request('GET')->getBody();
     $xml = simplexml_load_string($response, null, LIBXML_NOERROR);
     if (!$xml) {
         return null;
     }
     $locales = array();
     foreach ($xml->locale as $item) {
         $locales[(string) $item->codes->code->standard->representation] = (string) $item->englishName;
     }
     //var_dump($locales);
     //Mage::app()->saveCache(serialize($locales), 'inchoo_facebook_locale', array(), 7*24*60*60);
     //array(Mage_Core_Model_Config::CACHE_TAG)
     //$locales = unserialize(Mage::app()->loadCache('inchoo_facebook_locale')); //false
     var_dump($locales);
 }
Ejemplo n.º 15
0
 public function SendRequest($topic, $orderId, $customerId, $productId = 0, $categoryId = 0, $quoteId = 0)
 {
     $affiliate = 0;
     $client = new Varien_Http_Client();
     $company_app_name = $this->getStoreConfig('revenueconduit_app_name');
     $store_name = $this->getStoreConfig('revenueconduit_store_name');
     $storeId = Mage::app()->getStore()->getStoreId();
     $url = Mage::getStoreConfig('web/unsecure/base_link_url', $storeId);
     $host = "https://app.revenueconduit.com/magento_incoming_requests/receive";
     $parameter = array("company_app_name" => $company_app_name, "store_name" => $store_name, 'domain' => $url);
     if (!empty($_COOKIE) && array_key_exists('affiliate', $_COOKIE)) {
         $affiliate = $_COOKIE['affiliate'];
     }
     $postParameters = array("topic" => $topic, "order_id" => $orderId, "customer_id" => $customerId, "product_id" => $productId, 'category_id' => $categoryId, 'referral_code_id' => $affiliate ? $affiliate : 0, 'quote_id' => $quoteId);
     $client->setUri($host)->setConfig(array('timeout' => 30))->setParameterGet($parameter)->setParameterPost($postParameters)->setUrlEncodeBody(false)->setMethod(Zend_Http_Client::POST);
     try {
         $response = $client->request();
         return $response->getBody();
     } catch (Exception $e) {
         Mage::log("Could not send the {$topic} request to RevenueConduit. Error Message: " . $e->getMessage(), null);
     }
     return null;
 }
Ejemplo n.º 16
0
 protected function _postRequest(Varien_Object $request)
 {
     $debugData = array('request' => $request->getData());
     $result = Mage::getModel('paygate/authorizenet_result');
     $client = new Varien_Http_Client();
     $uri = $this->getConfigData('cgi_url');
     $client->setUri($uri ? $uri : self::CGI_URL);
     $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
     $client->setParameterPost($request->getData());
     $client->setMethod(Zend_Http_Client::POST);
     try {
         $response = $client->request();
     } catch (Exception $e) {
         $result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
         $debugData['result'] = $result->getData();
         $this->_debug($debugData);
         Mage::throwException($this->_wrapGatewayError($e->getMessage()));
     }
     $responseBody = $response->getBody();
     $r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
     if ($r) {
         $result->setResponseCode((int) str_replace('"', '', $r[0]))->setResponseSubcode((int) str_replace('"', '', $r[1]))->setResponseReasonCode((int) str_replace('"', '', $r[2]))->setResponseReasonText($r[3])->setApprovalCode($r[4])->setAvsResultCode($r[5])->setTransactionId($r[6])->setInvoiceNumber($r[7])->setDescription($r[8])->setAmount($r[9])->setMethod($r[10])->setTransactionType($r[11])->setCustomerId($r[12])->setMd5Hash($r[37])->setCardCodeResponseCode($r[38])->setCAVVResponseCode(isset($r[39]) ? $r[39] : null);
     } else {
         Mage::throwException(Mage::helper('paygate')->__('Error in payment gateway.'));
     }
     $debugData['result'] = $result->getData();
     $this->_debug($debugData);
     return $result;
 }
Ejemplo n.º 17
0
 /**
  *  Send request to gateway
  *
  *  @param    Mage_Chronopay_Model_Gateway_Request
  *  @return	  mixed
  */
 protected function _postRequest(Mage_Chronopay_Model_Gateway_Request $request)
 {
     $result = Mage::getModel('chronopay/gateway_result');
     $client = new Varien_Http_Client();
     $url = $this->getConfigData('cgi_url');
     $client->setUri($url ? $url : self::CGI_URL);
     $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
     $client->setParameterPost($request->getData());
     $client->setMethod(Zend_Http_Client::POST);
     $debugData = array('request' => $request->getData());
     try {
         $response = $client->request();
         $body = $response->getRawBody();
         if (preg_match('/(T\\|(.+)\\|[\\r\\n]{0,}){0,1}(Y\\|(.+)?|\\|)|(N\\|(.+[\\r\\n]{0,}.+){0,})/', $body, $matches)) {
             $transactionId = $matches[2];
             $message = isset($matches[4]) ? trim($matches[4], '|') : '';
             if (isset($matches[5], $matches[6])) {
                 $result->setError($matches[6]);
                 Mage::throwException($matches[6]);
             }
             if ($message == 'Completed') {
                 $result->setTransaction($request->getTransaction());
             }
             if (strlen($transactionId)) {
                 $result->setTransaction($transactionId);
             }
             if (!$result->getTransaction()) {
                 Mage::throwException(Mage::helper('chronopay')->__('The transaction ID is invalid.'));
             }
         } else {
             Mage::throwException(Mage::helper('chronopay')->__('Invalid response format.'));
         }
     } catch (Exception $e) {
         $result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
         $exceptionMsg = Mage::helper('chronopay')->__('Gateway request error: %s', $e->getMessage());
         $debugData['result'] = $result->getData();
         $this->_debug($debugData);
         Mage::throwException($exceptionMsg);
     }
     $debugData['result'] = $result->getData();
     $this->_debug($debugData);
     return $result;
 }
Ejemplo n.º 18
0
 protected function _postRequest(Varien_Object $request)
 {
     $result = AO::getModel('paygate/authorizenet_result');
     $client = new Varien_Http_Client();
     $uri = $this->getConfigData('cgi_url');
     $client->setUri($uri ? $uri : self::CGI_URL);
     $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
     $client->setParameterPost($request->getData());
     $client->setMethod(Zend_Http_Client::POST);
     if ($this->getConfigData('debug')) {
         foreach ($request->getData() as $key => $value) {
             $requestData[] = strtoupper($key) . '=' . $value;
         }
         $requestData = join('&', $requestData);
         $debug = AO::getModel('paygate/authorizenet_debug')->setRequestBody($requestData)->setRequestSerialized(serialize($request->getData()))->setRequestDump(print_r($request->getData(), 1))->save();
     }
     try {
         $response = $client->request();
     } catch (Exception $e) {
         $result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
         if (!empty($debug)) {
             $debug->setResultSerialized(serialize($result->getData()))->setResultDump(print_r($result->getData(), 1))->save();
         }
         AO::throwException(AO::helper('paygate')->__('Gateway request error: %s', $e->getMessage()));
     }
     $responseBody = $response->getBody();
     $r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
     if ($r) {
         $result->setResponseCode((int) str_replace('"', '', $r[0]))->setResponseSubcode((int) str_replace('"', '', $r[1]))->setResponseReasonCode((int) str_replace('"', '', $r[2]))->setResponseReasonText($r[3])->setApprovalCode($r[4])->setAvsResultCode($r[5])->setTransactionId($r[6])->setInvoiceNumber($r[7])->setDescription($r[8])->setAmount($r[9])->setMethod($r[10])->setTransactionType($r[11])->setCustomerId($r[12])->setMd5Hash($r[37])->setCardCodeResponseCode($r[39]);
     } else {
         AO::throwException(AO::helper('paygate')->__('Error in payment gateway'));
     }
     if (!empty($debug)) {
         $debug->setResponseBody($responseBody)->setResultSerialized(serialize($result->getData()))->setResultDump(print_r($result->getData(), 1))->save();
     }
     return $result;
 }
Ejemplo n.º 19
0
 protected function processAdminRequest($params, $requestTimeout = 60)
 {
     try {
         $client = new Varien_Http_Client();
         $client->setUri($this->getAdminUrl())->setConfig(array('timeout' => $requestTimeout))->setParameterPost($params)->setMethod(Zend_Http_Client::POST);
         $response = $client->request();
         $responseBody = $response->getBody();
         if (empty($responseBody)) {
             Mage::throwException($this->_getHelper()->__('vacc API failure. The request has not been processed.'));
         }
         // create array out of response
     } catch (Exception $e) {
         Mage::log($e->getMessage());
         Mage::throwException($this->_getHelper()->__('vacc API connection error. The request has not been processed.'));
     }
     return $responseBody;
 }
Ejemplo n.º 20
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;
 }
Ejemplo n.º 21
0
 /**
  * Reading a page via HTTPS and returning its content.
  */
 protected function _getHttpsPage($host, $parameter)
 {
     $client = new Varien_Http_Client();
     $client->setUri($host)->setConfig(array('timeout' => 30))->setHeaders('accept-encoding', '')->setParameterGet($parameter)->setMethod(Zend_Http_Client::GET);
     $request = $client->request();
     // Workaround for pseudo chunked messages which are yet too short, so
     // only an exception is is thrown instead of returning raw body
     if (!preg_match("/^([\\da-fA-F]+)[^\r\n]*\r\n/sm", $request->getRawBody(), $m)) {
         return $request->getRawBody();
     }
     return $request->getBody();
 }
Ejemplo n.º 22
0
 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);
 }
Ejemplo n.º 23
0
 /**
  * Send request for tracking
  *
  * @param array $trackings
  * @return void
  */
 protected function _getXMLTracking($trackings)
 {
     $xmlStr = '<?xml version="1.0" encoding="UTF-8"?>' . '<req:KnownTrackingRequest' . ' xmlns:req="http://www.dhl.com"' . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . ' xsi:schemaLocation="http://www.dhl.com TrackingRequestKnown.xsd" />';
     $xml = new SimpleXMLElement($xmlStr);
     $requestNode = $xml->addChild('Request', '', '');
     $serviceHeaderNode = $requestNode->addChild('ServiceHeader', '', '');
     $serviceHeaderNode->addChild('SiteID', (string) $this->getConfigData('id'));
     $serviceHeaderNode->addChild('Password', (string) $this->getConfigData('password'));
     $xml->addChild('LanguageCode', 'EN', '');
     foreach ($trackings as $tracking) {
         $xml->addChild('AWBNumber', $tracking, '');
     }
     /*
      * Checkpoint details selection flag
      * LAST_CHECK_POINT_ONLY
      * ALL_CHECK_POINTS
      */
     $xml->addChild('LevelOfDetails', 'ALL_CHECK_POINTS', '');
     /*
      * Value that indicates for getting the tracking details with the additional
      * piece details and its respective Piece Details, Piece checkpoints along with
      * Shipment Details if queried.
      *
      * S-Only Shipment Details
      * B-Both Shipment & Piece Details
      * P-Only Piece Details
      * Default is ‘S’
      */
     //$xml->addChild('PiecesEnabled', 'ALL_CHECK_POINTS');
     $request = $xml->asXML();
     $request = utf8_encode($request);
     $responseBody = $this->_getCachedQuotes($request);
     if ($responseBody === null) {
         $debugData = array('request' => $request);
         try {
             $client = new Varien_Http_Client();
             $client->setUri((string) $this->getConfigData('gateway_url'));
             $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
             $client->setRawData($request);
             $responseBody = $client->request(Varien_Http_Client::POST)->getBody();
             $debugData['result'] = $responseBody;
             $this->_setCachedQuotes($request, $responseBody);
         } catch (Exception $e) {
             $this->_errors[$e->getCode()] = $e->getMessage();
             $responseBody = '';
         }
         $this->_debug($debugData);
     }
     $this->_parseXmlTrackingResponse($trackings, $responseBody);
 }
Ejemplo n.º 24
0
 /**
  * Send request to Totango
  *
  * @param array $params
  * @return bool
  */
 private function _sendRequest($params)
 {
     $result = false;
     if (empty($params)) {
         $this->log('Could not send a request with empty parameters');
         return $result;
     }
     $url = self::SERVICE_URL;
     $httpClient = new Varien_Http_Client();
     try {
         $response = $httpClient->setUri($url)->setHeaders('Content-Type: image/gif')->setParameterPost($params)->request(Varien_Http_Client::POST);
         if ($response->isSuccessful()) {
             $result = true;
         } else {
             $this->log('"Send Request" response was unsuccessful');
         }
     } catch (Exception $e) {
         $this->log(sprintf('[Send Request Exception]: %s', $e->getMessage()));
         $this->log($e, 'exception');
     }
     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;
 }
Ejemplo n.º 26
0
 public function request($url, $params, $object = null, $timeout = null)
 {
     if (!$timeout) {
         $timeout = 0;
     }
     try {
         $client = new Varien_Http_Client();
         $client->setUri($url)->setConfig(array('timeout' => $timeout))->setHeaders('accept-encoding', '')->setParameterPost($params)->setMethod(Zend_Http_Client::POST);
         if ($object instanceof Mageplace_Backup_Model_Backup && $object->getProfileData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_ENABLE) && $object->getProfileData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_USER)) {
             $client->setAuth($object->getProfileData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_USER), $object->getProfileData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_PASSWORD));
         } elseif ($object instanceof Mageplace_Backup_Model_Profile && $object->getData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_ENABLE) && $object->getData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_USER)) {
             $client->setAuth($object->getData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_USER), $object->getData(Mageplace_Backup_Model_Profile::COLUMN_AUTH_PASSWORD));
         }
         $response = $client->request();
         return $response->getRawBody();
     } catch (Zend_Http_Client_Exception $zhce) {
         if ($zhce->getMessage() != 'Unable to read response, or response is empty') {
             Mage::logException($zhce);
             throw $zhce;
         }
     } catch (Exception $e) {
         Mage::logException($e);
         throw $e;
     }
     return '';
 }
 /**
  * Post request to gateway and return responce
  *
  * @param Mage_Paygate_Model_Authorizenet_Request $request)
  * @return Mage_Paygate_Model_Authorizenet_Result
  */
 protected function _postRequest(Varien_Object $request)
 {
     $debugData = array('request' => $request->getData());
     $debugData['class'] = get_class($request);
     $result = Mage::getModel('paygate/authorizenet_result');
     $client = new Varien_Http_Client();
     $uri = $this->getConfigData('cgi_url');
     $client->setUri($uri ? $uri : self::CGI_URL);
     //Mage::log(' ---------- new post request ', null, 'capture.log');
     //Mage::log(' uri '.$client->getUri(), null, 'capture.log');
     $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
     foreach ($request->getData() as $key => $value) {
         $request->setData($key, str_replace(self::RESPONSE_DELIM_CHAR, '', $value));
     }
     $request->setXDelimChar(self::RESPONSE_DELIM_CHAR);
     $client->setParameterPost($request->getData());
     $client->setMethod(Zend_Http_Client::POST);
     //Mage::log($request->getData(), null, 'capture.log');
     try {
         $response = $client->request();
     } catch (Exception $e) {
         $result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
         $debugData['result'] = $result->getData();
         $this->_debug($debugData);
         Mage::throwException($this->_wrapGatewayError($e->getMessage()));
     }
     $responseBody = $response->getBody();
     $debugData['responseBody'] = $responseBody;
     $r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
     $debugData['deliminator'] = self::RESPONSE_DELIM_CHAR;
     $debugData['results_exploded'] = $r;
     if ($r) {
         $result->setResponseCode((int) str_replace('"', '', $r[0]))->setResponseSubcode((int) str_replace('"', '', $r[1]))->setResponseReasonCode((int) str_replace('"', '', $r[2]))->setResponseReasonText($r[3])->setApprovalCode($r[4])->setAvsResultCode($r[5])->setTransactionId($r[6])->setInvoiceNumber($r[7])->setDescription($r[8])->setAmount($r[9])->setMethod($r[10])->setTransactionType($r[11])->setCustomerId($r[12])->setMd5Hash($r[37])->setCardCodeResponseCode($r[38])->setCAVVResponseCode(isset($r[39]) ? $r[39] : null)->setSplitTenderId($r[52])->setAccNumber($r[50])->setCardType($r[51])->setRequestedAmount($r[53])->setBalanceOnCard($r[54]);
     } else {
         Mage::throwException(Mage::helper('revolution')->__('Error in payment gateway.'));
     }
     $debugData['result'] = $result->getData();
     $this->_debug($debugData);
     return $result;
 }
Ejemplo n.º 28
0
 protected function _postRequest($request)
 {
     $client = new Varien_Http_Client();
     $client->setUri($this->getUrl());
     $client->setConfig(array('maxredirects' => 2, 'timeout' => 60));
     $client->setParameterGet($request);
     $client->setMethod(Zend_Http_Client::GET);
     try {
         $response = $client->request();
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('pnsofortueberweisung')->__('Gateway request error: %s', $e->getMessage()));
     }
     $responseBody = $response->getBody();
     return $responseBody;
 }
Ejemplo n.º 29
0
 /**
  * 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;
 }
Ejemplo n.º 30
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;
 }