PAVv3 PHP w/cURL

From CDYNE Wiki
Jump to navigation Jump to search

Verify Address Advanced (With cURL)

Calling Verify Address Advanced using cURL and json.

 1 <?php
 2 //Request paramters in json format
 3 
 4 $json = '{
 5 		"CityName":"Chesapeake"
 6 		,"FirmOrRecipient":""
 7 		,"LicenseKey":"(Your Key)"
 8 		,"PrimaryAddressLine":"2125 Smith Ave"
 9 		,"SecondaryAddressLine":""
10 		,"State":"VA"
11 		,"Urbanization":""
12 		,"ZipCode":"23320"
13 	}';
14 
15 //Method
16 $url = 'http://pav3.cdyne.com/PavService.svc/VerifyAddressAdvanced';
17 
18 $cURL = curl_init();
19 
20 curl_setopt($cURL,CURLOPT_URL,$url);
21 curl_setopt($cURL,CURLOPT_POST,true);
22 curl_setopt($cURL,CURLOPT_POSTFIELDS,$json);
23 curl_setopt($cURL,CURLOPT_RETURNTRANSFER, true);  
24 curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
25 //If you desire your results in xml format, use the following line for your httpheaders and comment out the httpheaders code line above.
26 //curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
27 
28 $result = curl_exec($cURL);
29 
30 curl_close($cURL);
31 
32 print_r($result);
33 ?>


Verify Address

 1 <pre>
 2 <?php
 3  
 4 $param = array(
 5 	'FirmOrRecipient' => 'CDYNE'
 6 	,'PrimaryAddressLine' => '505 Independence Parkway'
 7 	,'SecondaryAddressLine' => 'Suite 300'
 8 	,'Urbanization' => ''
 9 	,'CityName' => 'Chesapeake'
10 	,'State' => 'VA'
11 	,'ZipCode' => '23320'
12 	,'LicenseKey' => f01d89fd-5155-5455-5585-e84ab8de8591' 
13 );	
14 
15 $queryString = http_build_query($param);
16 
17 $url = 'http://pav3.cdyne.com/PavService.svc/VerifyAddress' . '?' . $queryString;
18 
19 $ch = curl_init(); 
20 
21 curl_setopt($ch,CURLOPT_URL,$url);
22 curl_setopt($ch,CURLOPT_HTTPGET,true);
23 curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);  
24 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
25 
26 $response = curl_exec($ch); 
27 
28 curl_close($ch); 
29 
30 $array = json_decode($response);
31 
32 print_r($array);
33 
34 ?>
35 </pre>