You are here

function uc_fedex_address_is_residential in FedEx Shipping 7.2

Same name and namespace in other branches
  1. 6.2 uc_fedex.aval.inc \uc_fedex_address_is_residential()

Convenience function to determine if an address is Residential or Commercial.

This determination is made using the FedEx Address Validation API if address validation is enabled in the module admin settings. Otherwise, the $default input parameter is used.

Parameters

$address: An object holding address data.

$default: TRUE if $address is Residential, FALSE otherwise.

$verbose: If TRUE, display result of address determination in a Drupal message.

Return value

bool TRUE if $address is Residential, FALSE otherwise.

2 calls to uc_fedex_address_is_residential()
uc_fedex_fulfill_order_validate in ./uc_fedex.ship.inc
Passes final information into shipment object.
uc_fedex_quote in ./uc_fedex.module
Callback for retrieving a FedEx shipping quote.

File

./uc_fedex.aval.inc, line 155
FedEx Web Services Rate / Available Services Quote.

Code

function uc_fedex_address_is_residential($address, $default = TRUE, $verbose = FALSE) {

  // If desired, use Address API to determine whether FedEx considers
  // the address to be Residential or Commercial.
  if (variable_get('uc_fedex_address_validation', FALSE)) {

    // Ensure we have the information needed to validate the address.
    if (empty($address->street1) || empty($address->city) || empty($address->zone) || empty($address->postal_code) || empty($address->country)) {
      return $default;
    }

    // Make request to FedEx web service.
    $response = uc_fedex_address_request($address);
    $residential_status = $response->AddressResults->ProposedAddressDetails->ResidentialStatus;
    switch ($residential_status) {
      case 'RESIDENTIAL':
        if ($verbose) {
          drupal_set_message(t('FedEx classifies this address as RESIDENTIAL'));
        }
        return TRUE;
        break;
      case 'BUSINESS':
        if ($verbose) {
          drupal_set_message(t('FedEx classifies this address as COMMERCIAL'));
        }
        return FALSE;
        break;
      default:

        // Any other result, fall through to use the store default.
        if ($verbose) {
          drupal_set_message(t("FedEx can't determine the address type"));
        }
        break;
    }
  }

  // Address API validation not wanted, or failed, so return default choice.
  return $default;
}