For Drupal 6.x version
For Ups address validation dynamically at time of checkout.Dynamically checking whether its Residential or Commercial .

I have not developed any module to add address validation.

Just a simple way I have did it.

Added function in my custom module.

function check_shipping_address($address)
{

require_once('Address_validation.php');
$av = new Address_validation();
$av->setReturnType('Array'); // Array or json (Default)

// $address['address1'],$address['city'],$address['state'],$address['zipcode'],$address['country'] is required
// $address['country'] = 'US' Only

$av->setAddress($address);
$data = $av->getResponse();

/*echo "

data==";
	print_r($data);
	echo "

"; */

return $data[0][description];

}

In ubercart/shipping/uc_ups/uc_ups.module file
i have added the code in function
function uc_ups_shipping_quote($packages, $origin, $destination, $ups_service) { .. }
After line 327 .
$shipto_city = $destination->city;
$shipto_address = $destination->street1;
For getting the address and city of ShipTo.

Then format a array .
Add it after line 346.
$addresscheck = array("address1" =>$shipto_address ,
"city" => $shipto_city,
"state" => $shipto_zone,
"zipcode" => $shipto_zip,
"country" => $shipto_country);

Now in schema I have added and check whether its commercial or Residential address.
on Line 445.

if(check_shipping_address($addresscheck)=='Residential') // Call a function and pass the address
{
$schema .= "
";
}

Thanks. if you need my help let me know.

Comments

dharabhatia’s picture

Forgot to show code of Address_validation.php
Put this file in your custom module where you have enter the function of addresscheck

/*
* Author  : Mark Song (ilovekanon@gmail.com)
* Blog : Uniapple.net
*/

define("ACCESS_LICENSE_NUMBER","");
define("USER_ID","");
define("USER_PASSWORD","");
define("MODE","Dev");

class Address_validation {
	protected $_url;
	protected $_returnType = 'json';
	protected $_consignee;
	protected $_address1;
	protected $_address2;
	protected $_city;
	protected $_state;
	protected $_zipCode;
	protected $_country;
	
	public function __construct(){
		if(strtolower(MODE) == 'dev'){
			$this->_url = "https://wwwcie.ups.com/ups.app/xml/XAV"; 
		}else{
			$this->_url = "https://onlinetools.ups.com/ups.app/xml/XAV"	;
		}
	}

	public function setAddress($addressArray){
		if(!is_array($addressArray)){
			throw new Exception("Address Info should be an array!");
		}
		
		if(!isset($addressArray['address1']) && $addressArray['address1'] == ''){
			throw new Exception("Address1 is required, array key is address1");
		}
		if(!isset($addressArray['city']) && $addressArray['city'] == ''){
			throw new Exception("City is required, array key is city");
		}
		if(!isset($addressArray['state']) && $addressArray['state'] == ''){
			throw new Exception("State is required, array key is state");
		}
		if(!isset($addressArray['zipcode']) && $addressArray['zipcode'] == ''){
			throw new Exception("Zip Code is required, array key is zipcode");
		}
		if(!isset($addressArray['country']) && $addressArray['country'] != 'US'){
			throw new Exception("Country is required and county should be US only, array key is country");
		}
		
		if(isset($addressArray['consignee'])) $this->_consignee = $addressArray['consignee'];
		$this->_address1 = $addressArray['address1'];
		if(isset($addressArray['address2'])) $this->_address2 = $addressArray['address2'];
		$this->_city = $addressArray['city'];
		$this->_state = $addressArray['state'];
		$this->_zipcode = $addressArray['zipcode'];
		$this->_country = $addressArray['country'];
	}

	public function setReturnType($type){
		$this->_returnType = $type;
	}

	public function getResponse(){
		$response = $this->request();

		$responseArray = new SimpleXMLElement($response);
		$data = array(); //return data container

		//print_r($responseArray);

		if($responseArray->Response->ResponseStatusDescription == 'Failure'){
			// error
			$data['error']['errorSeverity'] = $responseArray->Response->Error->ErrorSeverity;
			$data['error']['errorCode'] = $responseArray->Response->Error->ErrorCode;
			$data['error']['errorDescription'] = $responseArray->Response->Error->ErrorDescription;

			return $this->getReturnByType($data);
		}
	
		$addressSize = sizeof($responseArray->AddressKeyFormat);
		if($addressSize <1){
			$data['error']['errorCode'] = "0000";
			$data['error']['errorDescription'] = "Can not find the address";
		}elseif($addressSize > 1){
			$arrSize = sizeof($responseArray->AddressKeyFormat);

			for($i=0; $i<$arrSize; $i++){
				$temp = $responseArray->AddressKeyFormat[$i];
				
				$data[$i]['code'] = $temp->AddressClassification->Code;
				$data[$i]['description'] = $temp->AddressClassification->Description;
				
				if(is_array($temp->AddressLine)){
					$data[$i]['address'] = implode(",",$temp->AddressLine);
				}else{
					$data[$i]['address'] = $temp->AddressLine;
				}
				$data[$i]['region'] = $temp->Region;
				$data[$i]['city'] = $temp->PoliticalDivision2;
				$data[$i]['state'] = $temp->PoliticalDivision1;
				$data[$i]['zipcode'] = $temp->PostcodePrimaryLow;
				$data[$i]['country'] = $temp->CountryCode;
			}
		}else{
			$temp = $responseArray->AddressKeyFormat;

			$data[0]['code'] = $temp->AddressClassification->Code;
			$data[0]['description'] = $temp->AddressClassification->Description;

			if(is_array($temp->AddressLine)){
				$data[0]['address'] = implode(",",$temp->AddressLine);
			}else{
				$data[0]['address'] = $temp->AddressLine;
			}
			$data[0]['region'] = $temp->Region;
			$data[0]['city'] = $temp->PoliticalDivision2;
			$data[0]['state'] = $temp->PoliticalDivision1;
			$data[0]['zipcode'] = $temp->PostcodePrimaryLow;
			$data[0]['country'] = $temp->CountryCode;
		}

		return $this->getReturnByType($data);
	}
	
	protected function getReturnByType($data){
		if(strtolower($this->_returnType) == 'json'){
			return json_encode($data);	
		}else{
			return $data;
		}
	}

	protected function request(){
		$xml = $this->generateXML();

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $this->_url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
		curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$response = curl_exec($ch); print_r();
		$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

		if($status != '200'){
			throw new Exception("CURL Faild, status code is : ".$status);
		}

		curl_close($ch);

		return $response;
	}

	protected function generateXML(){
		$xml  = "<?xml version='1.0' 


".ACCESS_LICENSE_NUMBER."
".USER_ID."
".USER_PASSWORD."

<?xml version='1.0' ?>



1.0001

XAV
3

3
";
if($this->_consignee) $xml .= " UPS Capital";
$xml .= "".$this->_address1."";
if($this->_address2) $xml .= "#2L";
$xml .= "
".$this->_city."
".$this->_state."
".$this->_zipcode."
".$this->_country."


";
return $xml;
}
}//class
?>