本文整理汇总了PHP中Varien_Http_Client::setMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Http_Client::setMethod方法的具体用法?PHP Varien_Http_Client::setMethod怎么用?PHP Varien_Http_Client::setMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Http_Client
的用法示例。
在下文中一共展示了Varien_Http_Client::setMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apiCall
/**
* 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');
}
}
示例2: getClient
/**
* 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;
}
示例3: executeApiCall
/**
* 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=" . $apiUsername . "&password=" . $apiPassword . "&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.');
}
}
示例4: license
/**
* 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;
}
}
示例5: checkAction
/**
* 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=" . $apiUsername . "&password=" . $apiPassword;
Mage::log($apiRequest);
try {
$client = new Varien_Http_Client($apiRequest);
$client->setMethod(Varien_Http_Client::GET);
$response = $client->request();
Mage::log($response);
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 && $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.');
}
}
示例6: _verifyResponse
/**
* Veritfy the gateway response
*
* @param string $apiKey
* @param string $token
* @param string $timestamp
* @param string $signature
* @return boolean
*/
public function _verifyResponse($purchase_id)
{
$client_id = Mage::helper('sign2pay')->getSign2payClientId();
$client_secret = Mage::helper('sign2pay')->getSign2payClientSecret();
$client = new Varien_Http_Client('https://app.sign2pay.com/api/v2/payment/status/' . $purchase_id);
$client->setMethod(Varien_Http_Client::GET);
$client->setAuth($client_id, $client_secret);
try {
$response = $client->request();
$body = json_decode($response->getBody());
if (array_key_exists('status', $body) || $body['status'] == 'processing') {
return true;
} else {
return false;
}
} catch (Zend_Http_Client_Exception $e) {
Mage::logException($e);
return false;
}
}
示例7: _postRequest
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;
}
示例8: _postRequest
/**
* 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;
}
示例9: _postRequest
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;
}
示例10: _postRequest
/**
* 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;
}
示例11: _postRequest
/**
* 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());
}
示例12: catch
/**
* Listrak Remarketing Magento Extension Ver. 1.1.9
*
* PHP version 5
*
* @category Listrak
* @package Listrak_Remarketing
* @author Listrak Magento Team <magento@listrak.com>
* @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();
示例13: ping
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);
}
}
示例14: _postRequest
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;
}
示例15: checkAwesomeCheckoutVersion
public function checkAwesomeCheckoutVersion()
{
$request_url = 'http://api.anattadesign.com/awesomecheckout/1alpha/status/latestVersion';
// 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 === 'success' ? true : false;
}
} catch (Exception $e) {
$json_success = false;
}
if ($json_success) {
// Don't do anything if we are on latest, this prevents duplicate notifications
if (version_compare($json_response->latestVersion, Mage::getStoreConfig('anattadesign_awesomecheckout_latest_checked_version'), 'eq')) {
return;
}
$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'];
if (version_compare($json_response->latestVersion, $version, '>')) {
Mage::getModel('adminnotification/inbox')->setSeverity(Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE)->setTitle(Mage::helper('anattadesign_awesomecheckout')->__("Awesome Checkout %s is now available", $json_response->latestVersion))->setDateAdded(gmdate('Y-m-d H:i:s'))->setUrl('http://www.awesomecheckout.com/update')->setDescription(Mage::helper('anattadesign_awesomecheckout')->__('Your version of Awesome Checkout is currently not up-to-date. Please <a href="http://www.awesomecheckout.com/update">click here</a> to get the latest version.'))->save();
Mage::getModel('core/config')->saveConfig('anattadesign_awesomecheckout_latest_checked_version', $json_response->latestVersion);
}
}
}