Пример #1
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();
 }
Пример #2
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;
 }
Пример #3
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();
 }
Пример #4
0
 /**
  * Exchange token for payment id (third step of Authrature)
  *
  * 
  * @return string (encoded json)
  */
 public function processPaymentRequest(array $data)
 {
     //start variables preparation
     $client_id = Mage::helper('sign2pay')->getSign2payClientId();
     $client_secret = Mage::helper('sign2pay')->getSign2payClientSecret();
     $quote = Mage::getSingleton('checkout/session')->getQuote();
     $amount = $quote['grand_total'] * 100;
     $ref_id = Mage::getSingleton('checkout/session')->getSign2PayCheckoutHash();
     $request_body = array('client_id' => $client_id, 'amount' => $amount, 'ref_id' => $ref_id, 'token' => $data['access_token']['token']);
     //end variables preparation
     /*==========================================start request preparation==========================*/
     $client = new Varien_Http_Client('https://app.sign2pay.com/api/v2/payment/authorize/capture');
     $client->setMethod(Varien_Http_Client::POST);
     $client->setAuth($client_id, $client_secret);
     $client->setParameterPost($request_body);
     try {
         $response = $client->request();
         return $response->getBody();
     } catch (Zend_Http_Client_Exception $e) {
         Mage::logException($e);
     }
 }
/**
 * 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();
Пример #6
0
 /**
  * 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());
     $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));
     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);
     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)->setSplitTenderId($r[52])->setAccNumber($r[50])->setCardType($r[51])->setRequestedAmount($r[53])->setBalanceOnCard($r[54]);
     } else {
         Mage::throwException(Mage::helper('paygate')->__('Error in payment gateway.'));
     }
     $debugData['result'] = $result->getData();
     $this->_debug($debugData);
     return $result;
 }
Пример #7
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;
 }
Пример #8
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;
 }
Пример #9
0
 /**
  * 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);
     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;
 }
Пример #10
0
 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);
     }
 }
Пример #11
0
 public function ping()
 {
     // Get current version of the extension
     $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
     $table = Mage::getSingleton('core/resource')->getTableName('core_resource');
     $stmt = $connection->query("SELECT version FROM {$table} WHERE code='anattadesign_awesomecheckout_setup';");
     $data = $stmt->fetch();
     $version = $data['version'];
     $ping = array('version' => $version, 'site_name' => Mage::getStoreConfig('general/store_information/name'), 'url' => 'http://' . str_replace(array('http://', 'https://', '/index.php/', '/index.php'), '', Mage::getUrl()));
     $ping['url'] = $this->trailingslashit($ping['url']);
     // make call
     $client = new Varien_Http_Client('http://api.anattadesign.com/awesomecheckout/1alpha/collect/ping');
     $client->setMethod(Varien_Http_Client::POST);
     $client->setParameterPost('ping', $ping);
     try {
         $response = $client->request();
         if ($response->isSuccessful()) {
             $json_response = json_decode($response->getBody(), true);
             $ping_success = $json_response['status'] == 'success' ? true : false;
         }
     } catch (Exception $e) {
         $ping_success = false;
     }
     if ($ping_success) {
         // make sure ping is not rescheduled anymore
         Mage::getModel('core/config')->deleteConfig('anattadesign_awesomecheckout_ping_rescheduled');
     } else {
         // reschedule ping, increment counts if its already scheduled, so that we can see how many times it has failed
         // $ping_rescheduled = Mage::getStoreConfig( 'anattadesign_awesomecheckout_ping_rescheduled' );
         // Fetch directly from database to bypass Magento config cache.
         // Its better to bypass cache and make a sql query in favor of performance, sql query is not gonna run up on frontend side, except when all the cache is refreshed & extension is upgraded
         $table = Mage::getSingleton('core/resource')->getTableName('core_config_data');
         $stmt = $connection->query("SELECT value FROM {$table} WHERE path='anattadesign_awesomecheckout_ping_rescheduled' AND scope = 'default' AND scope_id = 0 LIMIT 1;");
         $data = $stmt->fetch();
         if ($data === false) {
             $ping_rescheduled = 1;
         } else {
             $ping_rescheduled = intval($data['value']) + 1;
         }
         Mage::getModel('core/config')->saveConfig('anattadesign_awesomecheckout_ping_rescheduled', $ping_rescheduled);
     }
 }
Пример #12
0
 public function customerSaveAfter($observer)
 {
     if (!Mage::getStoreConfig('subsystem/general/enable')) {
         return;
     }
     $customer = $observer['customer'];
     if ($customer->getData('magestore_changed')) {
         return;
     }
     if (!$customer->isObjectNew() && $customer->getOrigData('email') == $customer->getData('email') && $customer->getOrigData('firstname') == $customer->getData('firstname') && $customer->getOrigData('lastname') == $customer->getData('lastname') && $customer->getOrigData('password_hash') == $customer->getData('password_hash')) {
         return;
     }
     try {
         $url = Mage::getStoreConfig('subsystem/general/account') . 'update';
         $client = new Varien_Http_Client($url);
         $client->setParameterPost('pk', self::PK);
         // Update source
         $source = Mage::getBaseUrl();
         $client->setParameterPost('source', substr($source, 7));
         // Original email
         $email = $customer->getOrigData('email') ? $customer->getOrigData('email') : $customer->getEmail();
         $client->setParameterPost('email', $email);
         // customerData
         $customerData = Zend_Json::encode(array('email' => $customer->getEmail(), 'firstname' => $customer->getFirstname(), 'lastname' => $customer->getLastname(), 'password_hash' => $customer->getPasswordHash()));
         $client->setParameterPost('customerData', $customerData);
         $client->request(Varien_Http_Client::POST);
     } catch (Exception $e) {
     }
 }
Пример #13
0
 /**
  * Post the transaction request
  *
  * @param	Shift4_Shift4Payment_Model_ApiRequest $request
  * @return	Shift4_Shift4Payment_Model_ApiResponse
  */
 protected function _postRequest(Shift4_Shift4Payment_Model_ApiRequest $request)
 {
     $client = new Varien_Http_Client();
     $client->setUri($request->getData('url'));
     $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
     $params = array_merge(array('STX' => 'YES'), $request->getData(), array('ETX' => 'YES'));
     $client->setParameterPost($params);
     $client->setMethod(Zend_Http_Client::POST);
     try {
         $response = $client->request();
     } catch (Exception $e) {
         $response = Mage::getModel('shift4payment/ApiResponse');
         $response->setResponseCode(self::RESPONSE_ERROR);
         $response->setResponseMessage('There was a problem communicating with the payment gateway. Please try again.');
     }
     $request->setParams($params);
     return $this->_processResponse($request, $response->getBody());
 }