Skip to content

Commit

Permalink
Merge pull request #25 from generationtux/master
Browse files Browse the repository at this point in the history
updated sdk to work with guzzle 6.0
  • Loading branch information
nitinshirsat authored Aug 2, 2017
2 parents 4b3215e + 8de4045 commit 2e7cd57
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"type": "library",
"require": {
"php": ">=5.5.9",
"guzzlehttp/guzzle": "5.*"
"guzzlehttp/guzzle": "~6.0"
},
"require-dev": {
"phpunit/phpunit": "5.7"
Expand Down
50 changes: 33 additions & 17 deletions src/AvaTaxClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class AvaTaxClient
*/
private $auth;


private $appName;


private $appVersion;

private $machineName;

private $environment;

/**
* Construct a new AvaTaxClient
*
Expand All @@ -49,6 +59,12 @@ class AvaTaxClient
*/
public function __construct($appName, $appVersion, $machineName, $environment)
{

$this->appName = $appName;
$this->appVersion = $appVersion;
$this->machineName = $machineName;
$this->environment = $environment;

// Determine startup environment
$env = 'https://rest.avatax.com';
if ($environment == "sandbox") {
Expand All @@ -59,13 +75,8 @@ public function __construct($appName, $appVersion, $machineName, $environment)

// Configure the HTTP client
$this->client = new Client([
'base_url' => $env
'base_uri' => $env
]);

// Set client options
$this->client->setDefaultOption('headers', array(
'Accept' => 'application/json',
'X-Avalara-Client' => "{$appName}; {$appVersion}; PhpRestClient; 17.5.0-67; {$machineName}"));
}

/**
Expand Down Expand Up @@ -5644,11 +5655,14 @@ private function restCall($apiUrl, $verb, $guzzleParams)
if (!isset($guzzleParams['auth'])){
$guzzleParams['auth'] = $this->auth;
}

$guzzleParams['headers'] = [
'Accept' => 'application/json',
'X-Avalara-Client' => "{$this->appName}; {$this->appVersion}; PhpRestClient; 17.5.0-67; {$this->machineName}"
];

// Contact the server
try {
$request = $this->client->createRequest($verb, $apiUrl, $guzzleParams);
$response = $this->client->send($request);
$response = $this->client->request($verb, $apiUrl, $guzzleParams);
$body = $response->getBody();
return json_decode($body);

Expand Down Expand Up @@ -14805,7 +14819,7 @@ public function withParameter($name, $value)
*/
public function withLineParameter($name, $value)
{
$l = GetMostRecentLine("WithLineParameter");
$l = $this->getMostRecentLine("WithLineParameter");
if (empty($l['parameters'])) $l['parameters'] = [];
$l[$name] = $value;
return $this;
Expand Down Expand Up @@ -14872,7 +14886,7 @@ public function withLatLong($type, $latitude, $longitude)
*/
public function withLineAddress($type, $line1, $line2, $line3, $city, $region, $postalCode, $country)
{
$line = $this->GetMostRecentLine("WithLineAddress");
$line = $this->getMostRecentLine("WithLineAddress");
$line['addresses'][$type] = [
'line1' => $line1,
'line2' => $line2,
Expand Down Expand Up @@ -14927,7 +14941,7 @@ public function withLineTaxOverride($type, $reason, $taxAmount, $taxDate)
throw new Exception("A valid date is required for a Tax Date Tax Override.");
}

$line = $this->GetMostRecentLine("WithLineTaxOverride");
$line = $this->getMostRecentLine("WithLineTaxOverride");
$line['taxOverride'] = [
'type' => $type,
'reason' => $reason,
Expand All @@ -14947,13 +14961,14 @@ public function withLineTaxOverride($type, $reason, $taxAmount, $taxDate)
* @param string $taxCode Tax Code of the item. If left blank, the default item (P0000000) is assumed.
* @return TransactionBuilder
*/
public function withLine($amount, $quantity, $taxCode)
public function withLine($amount, $quantity, $itemCode, $taxCode)
{
$l = [
'number' => $this->_line_number,
'quantity' => $quantity,
'amount' => $amount,
'taxCode' => $taxCode
'taxCode' => $taxCode,
'itemCode' => $itemCode
];
array_push($this->_model['lines'], $l);
$this->_line_number++;
Expand Down Expand Up @@ -15010,15 +15025,16 @@ public function withSeparateAddressLine($amount, $type, $line1, $line2, $line3,
* @param string $exemptionCode The exemption code for this line item
* @return TransactionBuilder
*/
public function withExemptLine($amount, $exemptionCode)
public function withExemptLine($amount, $itemCode, $exemptionCode)
{
$l = [
'number' => $this->_line_number,
'quantity' => 1,
'amount' => $amount,
'exemptionCode' => $exemptionCode
'exemptionCode' => $exemptionCode,
'itemCode' => $itemCode
];
array_push($this->_model['lines'], $l);
array_push($this->_model['lines'], $l);
$this->_line_number++;

// Continue building
Expand Down
1 change: 0 additions & 1 deletion tests/basicWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public function testBasicWorkflow()
// Create a new client
$client = new Avalara\AvaTaxClient('phpTestApp', '1.0', 'travis-ci', 'sandbox');
$client->withSecurity(getenv('SANDBOX_USERNAME'), getenv('SANDBOX_PASSWORD'));

// Call 'Ping' to verify that we are connected
$p = $client->Ping();
$this->assertNotNull($p, "Should be able to call Ping");
Expand Down

0 comments on commit 2e7cd57

Please sign in to comment.