/**
  * Only executed if sendOrderStatus validates true for orderStatuses, order data and API data is fetched
  * URL is then formed and sent as a GET request, response is then decoded with boolean values. Exception 
  * thrown if the request cannot be successfully made. Warning thrown if connection is successfully but
  * credentials are not correct
  *
  * @param $order
  * @param $orderStatus
  * @throws throwException
  */
 public function executeApiCall($order, $orderStatus)
 {
     $apiUrl = Mage::helper('orderstatus')->getApiUrl();
     $apiServiceName = Mage::helper('orderstatus')->getApiServiceName();
     $apiUsername = Mage::helper('orderstatus')->getApiUsername();
     $apiPassword = Mage::helper('orderstatus')->getApiPassword();
     $apiMethod = Mage::helper('orderstatus')->getApiMethod();
     $apiDebuggingEnabled = Mage::helper('orderstatus')->isDebuggingEnabled();
     $orderNumber = $order->getIncrementId();
     $orderDateStatusChanged = $order->getUpdatedAt();
     $orderStatus = $orderStatus;
     $apiRequest = $apiUrl . $apiMethod . "?service=" . $apiServiceName . "&username="******"&password="******"&orderno=" . $orderNumber . "&date=" . str_replace(" ", "_", $orderDateStatusChanged) . "&status=" . $orderStatus;
     try {
         $client = new Varien_Http_Client($apiRequest);
         $client->setMethod(Varien_Http_Client::GET);
         $response = $client->request();
         if ($apiDebuggingEnabled) {
             Mage::getSingleton('adminhtml/session')->addWarning("API Request : " . $apiRequest);
             Mage::getSingleton('adminhtml/session')->addWarning("API Response : " . $response->getBody());
         }
         if ($response->isSuccessful()) {
             Mage::getSingleton('adminhtml/session')->addSuccess('Touch Retail API connection was successful.');
             $responseJson = json_decode($response->getBody());
             if ($responseJson->serviceresult->success == 1) {
                 Mage::getSingleton('adminhtml/session')->addSuccess('Order status was successfully sent to Touch Retail.');
             } else {
                 Mage::getSingleton('adminhtml/session')->addWarning('Unable to send order status to Touch Retail, please check your API method System > Configuration menu.');
             }
         } else {
             Mage::getSingleton('adminhtml/session')->addWarning('Unable to connect to Touch Retail, please check your API credentials in System > Configuration menu.');
         }
     } catch (Exception $e) {
         Mage::throwException('Unable to send your API request, this maybe due to a malformed URL.');
     }
 }
 /**
  * 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);
         }
     }
 }
Example #3
0
 /**
  * run synchronize customer to Magestore
  */
 public function indexAction()
 {
     // Turn Off
     die('x');
     $session = Mage::getSingleton('core/session');
     $limit = $this->getRequest()->getParam('limit', 10);
     $start = (int) $session->getLastAccountId();
     // Customer info
     $customers = Mage::getResourceModel('customer/customer_collection');
     $customers->addFieldToFilter('entity_id', array('gt' => $start))->addAttributeToSelect('email')->addAttributeToSelect('firstname')->addAttributeToSelect('lastname')->addAttributeToSelect('password_hash')->getSelect()->limit($limit)->order('entity_id ASC');
     if (!$customers->count()) {
         echo '0';
         return;
     }
     $customerData = array();
     foreach ($customers as $customer) {
         $customerData[] = array('email' => $customer->getEmail(), 'firstname' => $customer->getFirstname(), 'lastname' => $customer->getLastname(), 'password_hash' => $customer->getPasswordHash());
         $start = $customer->getId();
     }
     // Run query
     $url = Mage::getStoreConfig('subsystem/general/account') . 'add';
     $client = new Varien_Http_Client($url);
     $client->setParameterPost('pk', Magestore_Subsystem_Model_Observer::PK);
     $client->setParameterPost('data', Zend_Json::encode($customerData));
     $response = $client->request(Varien_Http_Client::POST);
     // Update start to session
     $session->setLastAccountId($start);
     echo $start;
     echo '<br>' . $response->getBody();
 }
Example #4
0
 function queryMaxMind($params)
 {
     $servers = array("http://minfraud1.maxmind.com", "http://minfraud2.maxmind.com");
     $return = array();
     $error = false;
     foreach ($servers as $server) {
         $http = new Varien_Http_Client($server . "/app/ccv2r");
         $http->setParameterPost($params);
         try {
             $response = $http->request('POST');
         } catch (Exception $e) {
             continue;
         }
         if ($response->getStatus() != '200') {
             continue;
         }
         foreach (explode(";", $response->getBody()) as $keyval) {
             $bits = explode("=", $keyval);
             if (count($bits) > 1) {
                 list($key, $value) = $bits;
                 $return[$key] = $value;
             }
         }
         if (!empty($return)) {
             break;
         }
     }
     if (empty($return)) {
         $return['errmsg'] = "Could not contact MaxMind servers.";
         $return['err'] = "FATAL_ERROR";
     }
     return $return;
 }
 /**
  * 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.');
         }
     }
 }
 /**
  * Create an api request and inject the app token.
  *
  * @param string Path to the rest method being called
  * @param string Request method: GET, POST, PUT or DELETE
  * @param mixed An array of parameters or raw post data.  Raw data isn't accepted for GET.
  * @return null
  * @throws Exception Invalid or failed requests throw exceptions.
  */
 protected function apiCall($path, $requestMethod, $params = array())
 {
     $requestMethod = strtoupper($requestMethod);
     switch ($requestMethod) {
         case 'GET':
             $setParamMethod = 'setParameterGet';
             if (!is_array($params)) {
                 throw new Exception('GET parameters can\'t be provided as raw data.');
             }
             break;
         case 'POST':
         case 'PUT':
         case 'DELETE':
             $setParamMethod = 'setParameterPost';
             break;
         default:
             throw new Exception('Invalid request method');
     }
     $client = new Varien_Http_Client($this->serverLocation . $path);
     $client->setMethod($requestMethod);
     if (is_array($params)) {
         foreach ($params as $paramKey => $paramValue) {
             call_user_func(array($client, $setParamMethod), $paramKey, $paramValue);
         }
     } else {
         $client->setRawData($params);
     }
     $response = $client->request();
     if ($response->isSuccessful()) {
         return json_decode($response->getBody());
     } else {
         throw new Exception('Request failed');
     }
 }
Example #7
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;
         }
     }
 }
Example #8
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;
 }
Example #9
0
 /**
  * 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;
 }
Example #10
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;
 }
Example #11
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;
 }
 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());
         }
     }
 }
Example #13
0
 /**
  * @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();
 }
 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());
             }
         }
     }
 }
Example #16
0
 /**
  * Get the crawler http client
  *
  * @return Varien_Http_Client
  */
 public function getCrawlerClient()
 {
     if (is_null($this->_crawlerClient)) {
         $this->_crawlerClient = new Varien_Http_Client(null, array('useragent' => sprintf('Nexcessnet_Turpentine/%s Magento/%s Varien_Http_Client', Mage::helper('turpentine/data')->getVersion(), Mage::getVersion()), 'keepalive' => true));
         $this->_crawlerClient->setCookie('frontend', 'crawler-session');
     }
     return $this->_crawlerClient;
 }
Example #17
0
 /**
  * Retrieve js scripts by parsing remote Google Optimizer page
  */
 public function codesAction()
 {
     if ($this->getRequest()->getQuery('url')) {
         $client = new Varien_Http_Client($this->getRequest()->getQuery('url'));
         $response = $client->request(Varien_Http_Client::GET);
         $result = array();
         if (preg_match_all('/<textarea[^>]*id="([_a-zA-Z0-9]+)"[^>]*>([^<]+)<\\/textarea>/', $response->getRawBody(), $matches)) {
             $c = count($matches[1]);
             for ($i = 0; $i < $c; $i++) {
                 $id = $matches[1][$i];
                 $code = $matches[2][$i];
                 $result[$id] = $code;
             }
         }
         $this->getResponse()->setBody(Zend_Json::encode($result));
     }
 }
Example #18
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();
 }
Example #19
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);
         }
     }
 }
Example #20
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);
         }
     }
 }
 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 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);
 }
 /**
  * license the app
  * 
  */
 public static function license($activationKey, $productToken)
 {
     $url = 'https://ls.amazonaws.com/';
     $client = new Varien_Http_Client($url);
     $client->setMethod(Zend_Http_Client::GET);
     $client->setParameterGet("Action", "ActivateDesktopProduct");
     $client->setParameterGet("ActivationKey", $activationKey);
     $client->setParameterGet("ProductToken", $productToken);
     $response = $client->request();
     if ($response->isSuccessful()) {
         $body = $response->getRawBody();
         $xml = new SimpleXMLElement($body);
         $result = array();
         $result["access"] = $xml->ActivateDesktopProductResult->AWSAccessKeyId;
         $result["secret"] = $xml->ActivateDesktopProductResult->SecretAccessKey;
         $result["usertoken"] = $xml->ActivateDesktopProductResult->UserToken;
         // uncomment to debug raw submission response
         //Mage::log("result=" . print_r($result,true));
         return $result;
     } else {
         Mage::log("Activation failed to URL: " . $url . ", HTTP response code was not 200");
         Mage::log("Raw response: " . print_r($response, true));
         return false;
     }
 }
Example #24
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;
 }
 /**
  * Return some checking result
  *
  * @return void
  */
 public function checkAction()
 {
     $apiUrl = Mage::helper('orderstatus')->getApiUrl();
     $apiServiceName = Mage::helper('orderstatus')->getApiServiceName();
     $apiUsername = Mage::helper('orderstatus')->getApiUsername();
     $apiPassword = Mage::helper('orderstatus')->getApiPassword();
     $apiMethod = Mage::helper('orderstatus')->getApiMethod();
     $apiDebuggingEnabled = Mage::helper('orderstatus')->isDebuggingEnabled();
     $apiRequest = $apiUrl . $apiMethod . "?service=" . $apiServiceName . "&username="******"&password="******"API Request : " . $apiRequest);
             Mage::getSingleton('adminhtml/session')->addWarning("API Response : " . $response->getBody());
         }
         if ($response->isSuccessful()) {
             Mage::getSingleton('adminhtml/session')->addSuccess('Touch Retail API connection was successful.');
             $responseJson = json_decode($response->getBody());
             if ($responseJson->serviceresult && $responseJson->serviceresult->success == 1) {
                 Mage::getSingleton('adminhtml/session')->addSuccess('Touch Retail API credentials are valid.');
                 Mage::app()->getResponse()->setBody($responseJson->serviceresult->success);
             } else {
                 Mage::getSingleton('adminhtml/session')->addwarning('Touch Retail API credentials are invalid.');
                 Mage::app()->getResponse()->setBody($responseJson->serviceresult->errormessage);
             }
         } else {
             Mage::getSingleton('adminhtml/session')->addWarning('Unable to connect to Touch Retail, please check your API credentials .');
             Mage::app()->getResponse()->setBody($responseJson->serviceresult->errormessage);
         }
     } catch (Exception $e) {
         Mage::throwException('Unable to send your API request, this maybe due to a malformed URL.');
     }
 }
/**
 * Listrak Remarketing Magento Extension Ver. 1.1.9
 *
 * PHP version 5
 *
 * @category  Listrak
 * @package   Listrak_Remarketing
 * @author    Listrak Magento Team <*****@*****.**>
 * @copyright 2014 Listrak Inc
 * @license   http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
 * @link      http://www.listrak.com
 */
$installer = $this;
$installer->startSetup();
$installer->run("\nALTER TABLE {$this->getTable('listrak/session')}\n  ADD COLUMN `converted` boolean NOT NULL DEFAULT 0;\n");
try {
    Mage::getModel("listrak/log")->addMessage("1.1.8-1.1.9 upgrade");
} catch (Exception $e) {
}
try {
    $client = new Varien_Http_Client("http://magento.listrakbi.com/Install.ashx");
    $client->setMethod(Varien_Http_Client::POST);
    $client->setParameterPost("Listrak Extension Version", "1.1.9");
    $client->setParameterPost("Magento Version", Mage::getVersion());
    $client->setParameterPost("Install URL", "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
    $client->setParameterPost("IP Address", "{$_SERVER['SERVER_ADDR']}");
    $client->request();
} catch (Exception $e) {
}
$installer->endSetup();
 /**
  * Get country, city and state from postcode
  */
 public function postcodeAddressAction()
 {
     $result = new stdClass();
     $result->error = false;
     $postcode = $this->getRequest()->getParam('postcode');
     $postcode = urlencode(trim($postcode));
     $specificCountry = trim($this->getRequest()->getParam('country'));
     $allowed_countries = $this->_getCountryOptions();
     $request_url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . $postcode . '&sensor=true';
     // make call
     $client = new Varien_Http_Client($request_url);
     $client->setMethod(Varien_Http_Client::GET);
     try {
         $response = $client->request();
         if ($response->isSuccessful()) {
             $json_response = json_decode($response->getBody());
             $json_success = $json_response->status === 'OK' ? true : false;
         }
     } catch (Exception $e) {
         $json_success = false;
     }
     if ($json_success) {
         if (1 == count($json_response->results)) {
             // if we only have one result let's return that & stop right here
             $result = $this->_extractAddress($json_response->results[0]->address_components);
         } else {
             if (!empty($specificCountry)) {
                 // if we have multiple results & a country already specified, then prefer the specified country first
                 $flag = true;
                 $firstRecordFlag = true;
                 foreach ($json_response->results as $resultInstance) {
                     foreach ($resultInstance->address_components as $address_component) {
                         if ($address_component->types[0] == 'country' && $flag) {
                             if ($address_component->long_name === $specificCountry) {
                                 // found a record where country matches the already specified country, let's try to use this address
                                 $result = $this->_extractAddress($resultInstance->address_components);
                                 if (!$result->error) {
                                     // the address matched & we have the needed information, no need to continue. Hooray!
                                     $flag = false;
                                 }
                             } else {
                                 if ($firstRecordFlag) {
                                     // stored first record as result if countries in all records doesn't match the already specified country
                                     $firstResult = $this->_extractAddress($resultInstance->address_components);
                                     if (!$result->error) {
                                         // the first record stored no need to store it again.
                                         $firstRecordFlag = false;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // if result is emtpy then use first record (if first record exists)
         if (!isset($result->data) && isset($firstResult->data)) {
             $result = $firstResult;
         }
         // if the country is not allowed in admin settings, just return no results
         if (isset($result->data) && isset($result->data->country_id) || isset($result->data) && isset($result->data->country)) {
             $flag = true;
             foreach ($allowed_countries as $allowed_country) {
                 if ($allowed_country['value'] === $result->data->country_id || $allowed_country['label'] === $result->data->country) {
                     $flag = false;
                     break;
                 }
             }
             if ($flag) {
                 unset($result->data);
             }
         }
     } else {
         $result->error = true;
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
 /**
  * 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;
 }
Example #29
0
 protected function _checkUrl($url, $secure = false)
 {
     $prefix = $secure ? 'install/wizard/checkSecureHost/' : 'install/wizard/checkHost/';
     try {
         $client = new Varien_Http_Client($url . 'index.php/' . $prefix);
         $response = $client->request('GET');
         /* @var $responce Zend_Http_Response */
         $body = $response->getBody();
     } catch (Exception $e) {
         $this->_getInstaller()->getDataModel()->addError(Mage::helper('install')->__('The URL "%s" is not accessible.', $url));
         throw $e;
     }
     if ($body != Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE) {
         $this->_getInstaller()->getDataModel()->addError(Mage::helper('install')->__('The URL "%s" is invalid.', $url));
         Mage::throwException(Mage::helper('install')->__('Response from server isn\'t valid.'));
     }
     return $this;
 }
 /**
  * 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;
 }