Skip to content
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

Proxy Support Issue #276 #277

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
55 changes: 45 additions & 10 deletions lib/AvaTax/classes/DynamicSoapClient.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* DynamicSoapClient.class.php
*/

/**
* Private implementation class for all Avalara web service clients.
*
Expand All @@ -12,19 +12,24 @@
* @see AvalaraSoapClient
* @see AddressServiceSoap
* @see TaxServiceSoap
*
*
* @author Avalara
* @copyright © 2004 - 2011 Avalara, Inc. All rights reserved.
* @package Base
*/

class DynamicSoapClient extends SoapClient
{
private $config;
public function __construct($wsdl,$options,&$config)
{
parent::__construct($wsdl,$options);
$this->config = $config;
if ( ! array_key_exists('proxy_host', $config) || ! array_key_exists('proxy_port', $config)) {
$proxyConfig = $this->getProxy();
$config = array_merge($config, $proxyConfig);
}

$this->config = $config;
}

public function __call($n,$args)
Expand All @@ -34,10 +39,10 @@ public function __call($n,$args)
$result = $this->__soapCall($n,$args,NULL,array($securityHeader,$profileHeader));
return $result;
}

private function securityXML()
{
return
return
'<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">'.
'<wsse:UsernameToken>'.
'<wsse:Username>'.$this->config->account.'</wsse:Username>'.
Expand All @@ -46,16 +51,46 @@ private function securityXML()
'</wsse:UsernameToken>'.
'</wsse:Security>';
}

private function profileXML()
{
return
return
'<Profile xmlns="http://avatax.avalara.com/services" SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next" SOAP-ENV:mustUnderstand="0">'.
'<Name>'.$this->config->name.'</Name>'.
'<Client>'.$this->config->client.'</Client>'.
'<Adapter>'.$this->config->adapter.'</Adapter>'.
($this->config->isLandedCostEnabled ? '<ClientSupportMultiTax>true</ClientSupportMultiTax>' : '').
'</Profile>';
}

}

private function getProxy()
{

$proxyVars = array("https_proxy", "HTTPS_PROXY", "http_proxy", "HTTP_PROXY");
foreach ($proxyVars as $i){
if (getenv($i) !== false){
$proxyVar = $i;
break;
}
else {
return array();
}
$proxy = $_ENV[$proxyVar];
$proxy_host = parse_url($proxy, PHP_URL_HOST);
$proxy_port = parse_url($proxy, PHP_URL_PORT);
$proxyConfig = array(
"proxy_host" => $proxy_host,
"proxy_port" => $proxy_port,
"stream_context" => stream_context_create(
array(
'proxy' => "tcp://" . $proxy_host . ":" . $proxy_port,
'request_fulluri' => true,
)
)
);
return
$proxyConfig;

}
}
}