You are here

function uc_usps_rate_request in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_usps/uc_usps.module \uc_usps_rate_request()
  2. 7.3 shipping/uc_usps/uc_usps.module \uc_usps_rate_request()

Construct an XML quote request.

Parameters

$packages: Array of packages received from the cart.

$origin: Delivery origin address information.

$destination: Delivery destination address information.

Return value

RateV3Request XML document to send to USPS

1 call to uc_usps_rate_request()
uc_usps_quote in shipping/uc_usps/uc_usps.module
Callback for retrieving USPS shipping quote.

File

shipping/uc_usps/uc_usps.module, line 462
Shipping quote method module that receives quotes from the United States Postal Service via XML web service.

Code

function uc_usps_rate_request($packages, $origin, $destination) {
  $request = '<RateV3Request USERID="' . variable_get('uc_usps_user_id', '') . '">';
  $services_count = 0;
  foreach ($packages as $package) {
    $qty = $package->qty;
    for ($i = 0; $i < $qty; $i++) {
      $request .= '<Package ID="' . $services_count . '">' . '<Service>ALL</Service>' . '<ZipOrigination>' . substr($origin->postal_code, 0, 5) . '</ZipOrigination>' . '<ZipDestination>' . substr($destination->postal_code, 0, 5) . '</ZipDestination>' . '<Pounds>' . intval($package->pounds) . '</Pounds>' . '<Ounces>' . number_format($package->ounces, 1, '.', '') . '</Ounces>' . '<Container>' . $package->container . '</Container>' . '<Size>' . $package->size . '</Size>' . '<Machinable>' . ($package->machinable ? 'True' : 'False') . '</Machinable>' . '</Package>';
      $services_count++;
    }
  }
  $request .= '</RateV3Request>';
  $request = 'API=RateV3&XML=' . urlencode($request);
  return $request;
}