You are here

function uc_usps_intl_rate_request in Ubercart 6.2

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

Constructs a quote request for international shipments.

Parameters

$packages: Array of packages received from the cart.

$origin: Delivery origin address information.

$destination: Delivery destination address information.

Return value

IntlRateRequest XML document to send to USPS

1 call to uc_usps_intl_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 596
Shipping quote method module that receives quotes from the United States Postal Service via XML web service.

Code

function uc_usps_intl_rate_request($packages, $origin, $destination) {
  module_load_include('inc', 'uc_usps', 'uc_usps.countries');
  $request = '<IntlRateV2Request USERID="' . variable_get('uc_usps_user_id', '') . '">';
  $request .= '<Revision>2</Revision>';

  // USPS does not use ISO 3166 country name in some cases so we
  // need to transform ISO country name into one USPS understands.
  $shipto_country = uc_usps_country_map($destination->country);
  $package_id = 0;
  foreach ($packages as $package) {
    $qty = $package->qty;
    for ($i = 0; $i < $qty; $i++) {
      $request .= '<Package ID="' . $package_id . '">' . '<Pounds>' . intval($package->pounds) . '</Pounds>' . '<Ounces>' . ceil($package->ounces) . '</Ounces>' . '<MailType>All</MailType>' . '<ValueOfContents>' . $package->price . '</ValueOfContents>' . '<Country>' . $shipto_country . '</Country>' . '<Container>' . 'RECTANGULAR' . '</Container>' . '<Size>' . 'REGULAR' . '</Size>' . '<Width>' . '</Width>' . '<Length>' . '</Length>' . '<Height>' . '</Height>' . '<Girth>' . '</Girth>' . '<OriginZip>' . substr(trim($origin->postal_code), 0, 5) . '</OriginZip>';

      // Check if we need to add any special services to this package
      if (variable_get('uc_usps_insurance', FALSE)) {
        $request .= '<ExtraServices><ExtraService>1</ExtraService></ExtraServices>';
      }

      // Close off Package tag
      $request .= '</Package>';
      $package_id++;
    }
  }
  $request .= '</IntlRateV2Request>';
  $request = 'API=IntlRateV2&XML=' . drupal_urlencode($request);
  return $request;
}