Skip to content

implements config setting to allow proxy for outgoing direct link calls #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions app/code/community/Netresearch/OPS/Model/Api/Directlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class Netresearch_OPS_Model_Api_DirectLink extends Mage_Core_Model_Abstract
*
* @param array $params
* @param string $url
* @param string $proxy
*
* @return mixed
*/
public function call($params, $url)
public function call($params, $url, $proxy = '')
{
try {
$http = new Varien_Http_Adapter_Curl();
Expand All @@ -49,6 +50,9 @@ public function call($params, $url)
'verifypeer' => 1,
'verifyhost' => 2,
);
if ($proxy !== '') {
$config['proxy'] = $proxy;
}
$http->setConfig($config);
$http->write(Zend_Http_Client::POST, $url, '1.1', array(), http_build_query($params));
$response = $http->read();
Expand Down Expand Up @@ -84,7 +88,7 @@ public function performRequest($requestParams, $url, $storeId = 0)
null,
$storeId
);
$responseParams = $this->getResponseParams($params, $url);
$responseParams = $this->getResponseParams($params, $url, 0, $this->getConfig()->getDirectLinkProxy());
$helper->log(
$helper->__(
"Direct Link Request/Response in Ingenico ePayments (Ogone) \n\nRequest: %s\nResponse: %s\nMagento-URL: %s\nAPI-URL: %s",
Expand Down Expand Up @@ -116,17 +120,18 @@ public function getEncodedParametersWithHash($params, $shaCode = null, $storeId)
* @param array $params - request params
* @param string $url - the url for the request
* @param int $retryCount - current request count
* @param string $proxy - proxy for direct link calls
* @return array | null - null if requests were not successful, array containing Ingenico ePayments (Ogone) payment data otherwise
* @throws Mage_Core_Exception
*
*/
protected function getResponseParams($params, $url, $retryCount = 0)
protected function getResponseParams($params, $url, $retryCount = 0, $proxy = '')
{
$responseParams = null;
$responseXml = null;
if ($retryCount < self::MAX_RETRY_COUNT) {
try {
$responseXml = $this->call($params, $url);
$responseXml = $this->call($params, $url, $proxy);
$responseParams = $this->getParamArrFromXmlString($responseXml);
} catch (Exception $e) {
try {
Expand All @@ -150,7 +155,7 @@ protected function getResponseParams($params, $url, $retryCount = 0)
$responseXml
)
);
$responseParams = $this->getResponseParams($params, $url, ++$retryCount);
$responseParams = $this->getResponseParams($params, $url, ++$retryCount, $proxy);
}
}
} else {
Expand Down Expand Up @@ -237,4 +242,12 @@ public function checkResponse($responseParams)
);
}
}

/**
* @return Netresearch_OPS_Model_Config
*/
protected function getConfig()
{
return Mage::getModel('ops/config');
}
}
11 changes: 11 additions & 0 deletions app/code/community/Netresearch/OPS/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,17 @@ public function getDirectLinkMaintenanceApiPath($storeId = null)
return $this->determineOpsUrl('directlink_maintenance_api', $storeId);
}

/**
* returns the proxy (if set in config) for the maintenance api calls
*
* @param null $storeId
*
* @return string - the proxy for the maintenance api calls
*/
public function getDirectLinkProxy($storeId = null)
{
return $this->getConfigData('directlink_proxy', $storeId);
}
/**
* getter for the iDeal issuers
*
Expand Down
1 change: 1 addition & 0 deletions app/code/community/Netresearch/OPS/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
<directlink_gateway>https://secure.ogone.com/ncol/test/maintenancedirect.asp</directlink_gateway>
<directlink_gateway_order>https://secure.ogone.com/ncol/test/orderdirect.asp</directlink_gateway_order>
<directlink_maintenance_api>https://secure.ogone.com/ncol/test/querydirect.asp</directlink_maintenance_api>
<directlink_proxy></directlink_proxy>
<ops_alias_gateway_test>https://ogone.test.v-psp.com/Tokenization/HostedPage</ops_alias_gateway_test>
<showcatalogbutton>1</showcatalogbutton>
<showhomebutton>1</showhomebutton>
Expand Down
9 changes: 9 additions & 0 deletions app/code/community/Netresearch/OPS/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@
<show_in_store>1</show_in_store>
<depends><mode>custom</mode></depends>
</directlink_maintenance_api>
<directlink_proxy translate="label comment">
<label>DirectLink Proxy URL</label>
<frontend_type>text</frontend_type>
<comment><![CDATA[If your server is behind a proxy, then enter the URL here: e.g. http://x.y.z.x:8080/]]></comment>
<sort_order>75</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</directlink_proxy>
<api_userid translate="label tooltip">
<label>API User</label>
<tooltip><![CDATA[Special user for API must be created in the Ingenico ePayments (Ogone) backend in section <em>Users</em>.]]></tooltip>
Expand Down