Does anyone out there have any functions they could share to use the UPS online Tools system to rate packages based on weight?
I need to send the zip code and weight info to ups and get a response that I can take to the next checkout page to add the shipping price to the order total.
I have generated this code so far to send the variables to ups:
$ShiptoAddress = $address1;
$ShiptoAddress2 = $address2;
// $ShipToCity = $20_destCity;
$ShipToState = $state;
// $ShipToZipCode = $19_destPostal;
$ShipperZipCode = "37076";
$Service= "4";
// $Residential = $49_residential;
$CountryCode = "US";
$PickupType = "01";
// $PackagingType = $48_container;
$Weight = $itemweight;
$XMLRequest = "<\?xml version=\'1.0\'?><AccessRequest>
<UserId>**</UserId>
<Password></Password>
<AccessLicenseNumber>*********</AccessLicenseNumber>
</AccessRequest>
<\?xml version=\'1.0\'\?><RatingServiceSelectionRequest xml:lang=\'en-US\'>
<Request>
<TransactionReference>
<CustomerContext>Rating and Service</CustomerContext><XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<RequestAction>Rate</RequestAction><RequestOption>shop</RequestOption>
</Request>
<PickupType><Code>$PickupType</Code></PickupType>
<Shipment><Shipper><Address><PostalCode>$ShipperZipCode</PostalCode></Address></Shipper>
<ShipTo><Address><PostalCode>$19_destPostal</PostalCode></Address></ShipTo>
<Service><Code>$Service</Code></Service>
<Package><PackagingType><Code>$$48_Container</Code></PackagingType>
<PackageWeight><Weight>$Weight</Weight></PackageWeight></Package>
</Shipment></RatingServiceSelectionRequest>";
$XMLRequestDisp = $XMLRequest . "<" . "<br><";
$XMLRequestDisp = $XMLRequestDisp . "<br></" . "</";
$XMLRequestDisp = addslashes($XMLRequestDisp);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, stripslashes($string));
curl_setopt($ch, CURLOPT_URL, "https://www.ups.com/ups.app/xml/Rate");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec ($ch);
curl_close ($ch);
$ch = StripSlashes($ch);
I have no idea how to parse the return, so that I can use the variables.
Thanks
DW