public function USPSInternationalRate::intlRateRequest in Ubercart 8.4
Constructs a quote request for international shipments.
Parameters
array $packages: Array of packages received from the cart.
$origin: Delivery origin address information.
$destination: Delivery destination address information.
Return value
string IntlRateRequest XML document to send to USPS.
1 call to USPSInternationalRate::intlRateRequest()
- USPSInternationalRate::quote in shipping/
uc_usps/ src/ Plugin/ Ubercart/ ShippingQuote/ USPSInternationalRate.php - Callback for retrieving USPS shipping quote.
File
- shipping/
uc_usps/ src/ Plugin/ Ubercart/ ShippingQuote/ USPSInternationalRate.php, line 302
Class
- USPSInternationalRate
- Provides a percentage rate shipping quote plugin.
Namespace
Drupal\uc_usps\Plugin\Ubercart\ShippingQuoteCode
public function intlRateRequest(array $packages, $origin, $destination) {
$usps_config = \Drupal::config('uc_usps.settings');
\Drupal::moduleHandler()
->loadInclude('uc_usps', 'inc', 'uc_usps.countries');
$request = '<IntlRateV2Request USERID="' . $usps_config
->get('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 ($usps_config
->get('insurance')) {
$request .= '<ExtraServices><ExtraService>1</ExtraService></ExtraServices>';
}
// Close off Package tag.
$request .= '</Package>';
$package_id++;
}
}
$request .= '</IntlRateV2Request>';
$request = 'API=IntlRateV2&XML=' . UrlHelper::encodePath($request);
return $request;
}