From 439fba24d6be253b895bb1d0863e9465d2aaac64 Mon Sep 17 00:00:00 2001 From: thomas Bell Date: Tue, 6 Jun 2017 11:00:06 -0400 Subject: [PATCH 1/2] updated sdk to work with guzzle 6.0 --- composer.json | 2 +- src/AvaTaxClient.php | 32 +++++++++++++++++++++++--------- tests/basicWorkflowTest.php | 1 - 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 5e0b90f..46257c9 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "type": "library", "require": { "php": ">=5.5.9", - "guzzlehttp/guzzle": "5.*" + "guzzlehttp/guzzle": "~6.0" }, "require-dev": { "phpunit/phpunit": "5.7" diff --git a/src/AvaTaxClient.php b/src/AvaTaxClient.php index cea3012..0bc149c 100644 --- a/src/AvaTaxClient.php +++ b/src/AvaTaxClient.php @@ -39,6 +39,16 @@ class AvaTaxClient */ private $auth; + + private $appName; + + + private $appVersion; + + private $machineName; + + private $environment; + /** * Construct a new AvaTaxClient * @@ -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") { @@ -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}")); } /** @@ -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); diff --git a/tests/basicWorkflowTest.php b/tests/basicWorkflowTest.php index 463d6a3..2e312a7 100644 --- a/tests/basicWorkflowTest.php +++ b/tests/basicWorkflowTest.php @@ -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"); From 8de4045382f2a403a8b3c6e7fc18a36ee867aef3 Mon Sep 17 00:00:00 2001 From: Thomas Bell Date: Wed, 7 Jun 2017 14:59:57 -0400 Subject: [PATCH 2/2] updated with line to work with extra variables --- src/AvaTaxClient.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/AvaTaxClient.php b/src/AvaTaxClient.php index 0bc149c..f96a8af 100644 --- a/src/AvaTaxClient.php +++ b/src/AvaTaxClient.php @@ -14819,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; @@ -14886,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, @@ -14941,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, @@ -14961,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++; @@ -15024,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