You are here

function uc_usps_rate_request in Ubercart 6.2

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

Constructs a quote request for domestic shipments.

Parameters

$packages: Array of packages received from the cart.

$origin: Delivery origin address information.

$destination: Delivery destination address information.

Return value

RateV4Request 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 550
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 = '<RateV4Request USERID="' . variable_get('uc_usps_user_id', '') . '">';
  $request .= '<Revision>2</Revision>';
  $rate_type = variable_get('uc_usps_online_rates', FALSE);
  $package_id = 0;
  foreach ($packages as $package) {
    $qty = $package->qty;
    for ($i = 0; $i < $qty; $i++) {
      $request .= '<Package ID="' . $package_id . '">' . '<Service>' . ($rate_type ? 'ONLINE' : 'ALL') . '</Service>' . '<ZipOrigination>' . substr(trim($origin->postal_code), 0, 5) . '</ZipOrigination>' . '<ZipDestination>' . substr(trim($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>' . '<Width>' . $package->width . '</Width>' . '<Length>' . $package->length . '</Length>' . '<Height>' . $package->height . '</Height>' . '<Girth>' . $package->girth . '</Girth>' . '<Machinable>' . ($package->machinable ? 'True' : 'False') . '</Machinable>' . '</Package>';
      $package_id++;
    }
  }
  $request .= '</RateV4Request>';
  return 'API=RateV4&XML=' . drupal_urlencode($request);
}