Skip to content

Commit

Permalink
merged and added new doctype values
Browse files Browse the repository at this point in the history
  • Loading branch information
Anya Stettler committed Jul 23, 2014
2 parents 6df2f19 + 1dfd191 commit 8c277b7
Show file tree
Hide file tree
Showing 29 changed files with 718 additions and 732 deletions.
26 changes: 11 additions & 15 deletions AvaTaxClasses/AvaTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,31 @@
*/

function avataxAutoloader($class_name)
{

{
$path=dirname(__FILE__).'/classes/'.$class_name.'.class.php';

require_once $path;

}


function EnsureIsArray( $obj )
{
if( is_object($obj))
if( is_object($obj))
{
$item[0] = $obj;
}
else
$item[0] = $obj;
}
else
{
$item = (array)$obj;
}
return $item;
$item = (array)$obj;
}
return $item;
}

function getDefaultDate()
{
$dateTime=new DateTime();
$dateTime->setDate(1900,01,01);

return $dateTime->format("Y-m-d");
}
$dateTime->setDate(1900,01,01);
return $dateTime->format("Y-m-d");
}

function getCurrentDate()
{
Expand Down
125 changes: 63 additions & 62 deletions AvaTaxClasses/classes/Address.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,43 @@
*
* </pre>
* @author Avalara
* @copyright © 2004 - 2011 Avalara, Inc. All rights reserved.
* @copyright 2004 - 2011 Avalara, Inc. All rights reserved.
* @package Address
*/

class Address
{

public $AddressCode;
public $AddressCode;
public $Line1;
public $Line2;
public $Line3;
public $City;
public $Region;
public $PostalCode;
public $Country = 'US';
public $TaxRegionId;
public $Latitude;
public $Longitude;
public $Country = 'US';
public $TaxRegionId;
public $Latitude;
public $Longitude;

public function __construct($addressCode=null, $line1=null,$line2=null, $line3=null,$city=null,$region=null,$postalCode=null, $country='US', $taxRegionId=null, $latitude=null, $longitude=null)
{
$this->AddressCode = $addressCode;
public function __construct($addressCode=null, $line1=null,$line2=null, $line3=null,$city=null,$region=null,$postalCode=null, $country='US', $taxRegionId=null, $latitude=null, $longitude=null)
{
$this->AddressCode = $addressCode;
$this->Line1 = $line1;
$this->Line2 = $line2;
$this->Line3 = $line3;
$this->City = $city;
$this->Region = $region;
$this->PostalCode = $postalCode;
$this->Country = $country;
$this->TaxRegionId = $taxRegionId;
$this->Latitude = $latitude;
$this->Longitude = $longitude;
}
public static function parseAddress($jsonString)
{
$object = json_decode($jsonString);
$this->Line2 = $line2;
$this->Line3 = $line3;
$this->City = $city;
$this->Region = $region;
$this->PostalCode = $postalCode;
$this->Country = $country;
$this->TaxRegionId = $taxRegionId;
$this->Latitude = $latitude;
$this->Longitude = $longitude;
}

public static function parseAddress($jsonString)
{
$object = json_decode($jsonString);
$AddressCode = null;
$Line1 = null;
$Line2 = null;
Expand All @@ -72,7 +73,7 @@ public static function parseAddress($jsonString)
$TaxRegionId = null;
$Latitude = null;
$Longitude = null;

if (property_exists($object,"AddressCode")) $AddressCode = $object->AddressCode;
if (property_exists($object,"Line1")) $Line1 = $object->Line1;
if (property_exists($object,"Line2")) $Line2 = $object->Line2;
Expand All @@ -84,46 +85,46 @@ public static function parseAddress($jsonString)
if (property_exists($object,"TaxRegionId")) $TaxRegionId = $object->TaxRegionId;
if (property_exists($object,"Latitude")) $Latitude = $object->Latitude;
if (property_exists($object,"Longitude")) $Longitude = $object->Longitude;

return new self(
$AddressCode,
$Line1,
$Line2,
$Line3,
$City,
$Region,
$PostalCode,
$Country,
$TaxRegionId,
$Latitude,
$Longitude);


}

public function setLatitude($value) { $this->Latitude = $value; }
public function setLongitude($value) { $this->Longitude = $value; }
public function setAddressCode($value) { $this->AddressCode = $value; }
public function setLine1($value) { $this->Line1 = $value; }
public function setLine2($value) { $this->Line2 = $value; }
public function setLine3($value) { $this->Line3 = $value; }
public function setCity($value) { $this->City = $value; }
public function setRegion($value) { $this->Region = $value; }
public function setPostalCode($value) { $this->PostalCode = $value; }
public function setCountry($value) { $this->Country = $value; }
public function setTaxRegionId($value) { $this->TaxRegionId = $value; }

public function getLongitude() { return $this->Longitude; }
public function getLatitude() { return $this->Latitude; }
public function getAddressCode() { return $this->AddressCode; }
public function getLine1() { return $this->Line1; }
public function getLine2() { return $this->Line2; }
public function getLine3() { return $this->Line3; }
public function getCity() { return $this->City; }
public function getRegion() { return $this->Region; }
public function getPostalCode() { return $this->PostalCode; }
public function getCountry() { return $this->AddressCode; }
public function getTaxRegionId() { return $this->TaxRegionId; }
return new self(
$AddressCode,
$Line1,
$Line2,
$Line3,
$City,
$Region,
$PostalCode,
$Country,
$TaxRegionId,
$Latitude,
$Longitude);


}

public function setLatitude($value) { $this->Latitude = $value; }
public function setLongitude($value) { $this->Longitude = $value; }
public function setAddressCode($value) { $this->AddressCode = $value; }
public function setLine1($value) { $this->Line1 = $value; }
public function setLine2($value) { $this->Line2 = $value; }
public function setLine3($value) { $this->Line3 = $value; }
public function setCity($value) { $this->City = $value; }
public function setRegion($value) { $this->Region = $value; }
public function setPostalCode($value) { $this->PostalCode = $value; }
public function setCountry($value) { $this->Country = $value; }
public function setTaxRegionId($value) { $this->TaxRegionId = $value; }

public function getLongitude() { return $this->Longitude; }
public function getLatitude() { return $this->Latitude; }
public function getAddressCode() { return $this->AddressCode; }
public function getLine1() { return $this->Line1; }
public function getLine2() { return $this->Line2; }
public function getLine3() { return $this->Line3; }
public function getCity() { return $this->City; }
public function getRegion() { return $this->Region; }
public function getPostalCode() { return $this->PostalCode; }
public function getCountry() { return $this->AddressCode; }
public function getTaxRegionId() { return $this->TaxRegionId; }


/**
Expand Down
63 changes: 31 additions & 32 deletions AvaTaxClasses/classes/AddressServiceRest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,53 @@
* </pre>
*
* @author Avalara
* @copyright © 2004 - 2011 Avalara, Inc. All rights reserved.
* @copyright 2004 - 2011 Avalara, Inc. All rights reserved.
* @package Address
*
*/

class AddressServiceRest
{
static protected $classmap = array(
'Validate' => 'Validate',
'ValidateRequest' => 'ValidateRequest',
'Address' => 'Address',
'ValidAddress' => 'ValidAddress',
'ValidateResult' => 'ValidateResult',
'BaseResult' => 'BaseResult',
'SeverityLevel' => 'SeverityLevel',
'Message' => 'Message');

protected $config = array();
static protected $classmap = array(
'Validate' => 'Validate',
'ValidateRequest' => 'ValidateRequest',
'Address' => 'Address',
'ValidAddress' => 'ValidAddress',
'ValidateResult' => 'ValidateResult',
'BaseResult' => 'BaseResult',
'SeverityLevel' => 'SeverityLevel',
'Message' => 'Message');

public function __construct($url, $account, $license)
{
$this->config = array(
'url' => $url,
'account' => $account,
'license' => $license);

}


//Validates/normalizes a single provided address. Will either return a single, non-ambiguous validated address match or an error.
public function validate($validateRequest)
{
if(!(filter_var($this->config['url'],FILTER_VALIDATE_URL))) throw new Exception("A valid service URL is required.");
protected $config = array();

public function __construct($url, $account, $license)
{
$this->config = array(
'url' => $url,
'account' => $account,
'license' => $license);
}


//Validates/normalizes a single provided address. Will either return a single, non-ambiguous validated address match or an error.
public function validate($validateRequest)
{
if(!(filter_var($this->config['url'],FILTER_VALIDATE_URL))) throw new Exception("A valid service URL is required.");
if(empty($this->config['account'])) throw new Exception("Account number or username is required.");
if(empty($this->config['license'])) throw new Exception("License key or password is required.");
$url = $this->config['url'].'/1.0/address/validate?'. http_build_query($validateRequest->getAddress());
$curl = curl_init();

$url = $this->config['url'].'/1.0/address/validate?'. http_build_query($validateRequest->getAddress());
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //Some Windows users have had trouble with our SSL Certificates. Uncomment this line to NOT use SSL.
curl_setopt($curl, CURLOPT_USERPWD, $this->config['account'].":".$this->config['license']);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($curl);

return ValidateResult::parseResult($result);
}

}
}
?>
26 changes: 13 additions & 13 deletions AvaTaxClasses/classes/AddressType.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* The type of the address(es) returned in the validation result.
*
* @author Avalara
* @copyright © 2004 - 2011 Avalara, Inc. All rights reserved.
* @copyright 2004 - 2011 Avalara, Inc. All rights reserved.
* @package Address
*
*/
Expand All @@ -17,24 +17,24 @@ class AddressType extends Enum
public static $FirmOrCompany = 'F';
public static $GeneralDelivery = 'G';
public static $HighRise = 'H';
public static $POBox = 'P';
public static $RuralRoute = 'R';
public static $StreetOrResidential = 'S';
public static $POBox = 'P';
public static $RuralRoute = 'R';
public static $StreetOrResidential = 'S';

public static function Values()
{
return array(
'FirmOrCompany' => AddressType::$FirmOrCompany,
'GeneralDelivery' => AddressType::$GeneralDelivery,
'HighRise' => AddressType::$HighRise,
'POBox' => AddressType::$POBox,
'RuralRoute' => AddressType::$RuralRoute,
'StreetOrResidential' => AddressType::$StreetOrResidential
'FirmOrCompany' => AddressType::$FirmOrCompany,
'GeneralDelivery' => AddressType::$GeneralDelivery,
'HighRise' => AddressType::$HighRise,
'POBox' => AddressType::$POBox,
'RuralRoute' => AddressType::$RuralRoute,
'StreetOrResidential' => AddressType::$StreetOrResidential
);
}

// Unfortunate boiler plate due to polymorphism issues on static functions
public static function Validate($value) { self::__Validate($value,self::Values(),__CLASS__); }
// Unfortunate boiler plate due to polymorphism issues on static functions
public static function Validate($value) { self::__Validate($value,self::Values(),__CLASS__); }
}

?>
28 changes: 14 additions & 14 deletions AvaTaxClasses/classes/BaseResult.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@
* The base class for result objects that return a ResultCode and Messages collection -- There is no reason for clients to create these.
*
* @author Avalara
* @copyright © 2004 - 2011 Avalara, Inc. All rights reserved.
* @copyright 2004 - 2011 Avalara, Inc. All rights reserved.
* @package Base
*/


class BaseResult implements JsonSerializable
{

public function jsonSerialize(){
return [
'TransactionId' => $this->getTransactionId(),
'ResultCode' => $this->getResultCode(),
'Messages' => $this->getMessages()
];
}
class BaseResult implements JsonSerializable
{

public function jsonSerialize(){
return array(
'TransactionId' => $this->getTransactionId(),
'ResultCode' => $this->getResultCode(),
'Messages' => $this->getMessages()
);
}

/**
* A unique Transaction ID identifying a specific request/response set. Deprecated.
* @return string
*/
public function getTransactionId() { return $this->TransactionId; }
public function getTransactionId() { return $this->TransactionId; }
/**
* Indicates whether operation was successfully completed or not.
* @return string
*/
public function getResultCode() { return $this->ResultCode; }
public function getResultCode() { return $this->ResultCode; }
/**
* Accessor
* @return array
*/
public function getMessages() { return EnsureIsArray($this->Messages->Message); }
public function getMessages() { return EnsureIsArray($this->Messages->Message); }

}

Expand Down
Loading

0 comments on commit 8c277b7

Please sign in to comment.