/ Published in: PHP
URL: http://e-commsolution.com/usps-real-time-shipping/
Expand |
Embed | Plain Text
<? // ========== CHANGE THESE VALUES TO MATCH YOUR OWN =========== $userName = "USERNAME"; // Your USPS Username $orgin_zip = "90210"; // location that you are shipping from. $add_rate = ""; // amount that you would like to add on top of usps rate, can be left blank // =============== DON'T CHANGE BELOW THIS LINE =============== // ====== Yahoo Post Script Values ======== $dest_zip = $_POST['Ship-Zip']; $weight = $_POST['Total-Weight']; $type = $_POST['Shipping']; $url = "http://Production.ShippingAPIs.com/ShippingAPI.dll"; // production server and not test server. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); // This section of code is from http://www.marksanborn.net/php/calculating-usps-shipping-rates-with-php/ and is the master mind for the creation. // You can donate at http://www.marksanborn.net/donate... Please do if this helps your store. $data = "API=RateV3&XML=<RateV3Request USERID=\"$userName\"><Package ID=\"1ST\"><Service>$type</Service><ZipOrigination>$orgin_zip</ZipOrigination><ZipDestination>$dest_zip</ZipDestination><Pounds>".ceil($weight)."</Pounds><Ounces>0</Ounces><Size>REGULAR</Size><Machinable>TRUE</Machinable></Package></RateV3Request>"; curl_setopt($ch, CURLOPT_POSTFIELDS,$data); $result=curl_exec ($ch); foreach ($vals as $xml_elem) { if ($xml_elem['type'] == 'open') { } else { $level[$xml_elem['level']] = $xml_elem['tag']; } } if ($xml_elem['type'] == 'complete') { $start_level = 1; $php_stmt = '$params'; while($start_level < $xml_elem['level']) { $php_stmt .= '[$level['.$start_level.']]'; $start_level++; } $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];'; } } curl_close($ch); $price = $params['RATEV3RESPONSE']['1ST']['1']['RATE']; if($add_rate != ""){ $price = $price+$add_rate; } ?>
You need to login to post a comment.
