You are here

function commerce_avatax_check_address in Drupal Commerce Connector for AvaTax 7.5

Same name and namespace in other branches
  1. 7.4 commerce_avatax.module \commerce_avatax_check_address()

Checks if the Avatax service needs to be called for this address.

1 call to commerce_avatax_check_address()
commerce_avatax_calculate_tax in ./commerce_avatax.module
Performs Tax calculation for a given order.

File

./commerce_avatax.module, line 605
AvaTax service integration from Avalara, Inc.

Code

function commerce_avatax_check_address(EntityDrupalWrapper $order_wrapper, $field_name) {

  // Skip the check if the customer profile field is empty.
  if (!isset($order_wrapper->{$field_name}) || is_null($order_wrapper->{$field_name}
    ->value())) {
    return FALSE;
  }
  if (!isset($order_wrapper->{$field_name}->commerce_customer_address)) {
    return FALSE;
  }
  $customer_address = $order_wrapper->{$field_name}->commerce_customer_address
    ->value();

  // Don't calculate Sales Tax if the provided address is in the US but the
  // State is not in Avax states list.
  if ($customer_address['country'] == 'US') {
    $avatax_states = variable_get(COMMERCE_AVATAX_VAR_PREFIX . 'select_states', array());

    // Exit if not a valid AvaTax state.
    if (!empty($avatax_states) && !in_array($customer_address['administrative_area'], $avatax_states)) {
      return FALSE;
    }
  }
  return TRUE;
}