You are here

function uc_usps_intl_rate_request in Ubercart 5

Same name and namespace in other branches
  1. 6.2 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()
1 call to uc_usps_intl_rate_request()
uc_usps_intl_quote in shipping/uc_usps/uc_usps.module
Callback for retrieving USPS shipping quote to other countries.

File

shipping/uc_usps/uc_usps.module, line 494
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) {
  $request = '<IntlRateRequest USERID="' . variable_get('uc_usps_user_id', '') . '">';
  $services_count = 0;

  // This needs to be international name per USPS website. See http://pe.usps.com/text/Imm/immctry.htm
  $shipto_country = uc_get_country_data(array(
    'country_id' => $destination->country,
  ));
  foreach ($packages as $package) {
    $qty = $package->qty;
    for ($i = 0; $i < $qty; $i++) {
      $request .= '<Package ID="' . $services_count . '">' . '<Pounds>' . intval($package->pounds) . '</Pounds>' . '<Ounces>' . ceil($package->ounces) . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $shipto_country[0]['country_name'] . '</Country>' . '</Package>';
      $services_count++;
    }
  }
  $request .= '</IntlRateRequest>';
  $request = 'API=IntlRate&XML=' . urlencode($request);
  return $request;
}