USPS Real time rates
Posted by Anonymous on May Tue 29th 5:54 PM - Never Expires| View : 442Syntax: PHP
2349 characters | 63 lines | 2.29 KB
- <?
- // ========== 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.
- // 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>";
- 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\'];';
- }
- }
- $price = $params['RATEV3RESPONSE']['1ST']['1']['RATE'];
- if($add_rate != ""){
- $price = $price+$add_rate;
- }
- ?>
