You are here

function commerce_avatax_calculate_sales_tax in Drupal Commerce Connector for AvaTax 7.4

Same name and namespace in other branches
  1. 7.3 commerce_avatax.module \commerce_avatax_calculate_sales_tax()

Calculate sales tax using regular web site checkout.

1 string reference to 'commerce_avatax_calculate_sales_tax'
commerce_avatax_default_rules_configuration in ./commerce_avatax.rules_defaults.inc
Implements hook_default_rules_configuration().

File

./commerce_avatax.module, line 131
Calculate Sales Tax using AvaTax service from Avalara, Inc.

Code

function commerce_avatax_calculate_sales_tax($order) {
  $product_version = variable_get('commerce_avatax_product_version', COMMERCE_AVATAX_BASIC_VERSION);
  if (commerce_avatax_check_address($order, $product_version)) {
    $sales_tax = commerce_avatax_retrieve_sales_tax($order, $product_version);
  }
  else {
    return;
  }

  // If we have a sales tax amount.
  if ($sales_tax) {

    // Create a new AvaTax line item.
    $line_item = commerce_avatax_line_item_create($sales_tax, $order->order_id);
    commerce_avatax_add_avatax_line_item($line_item, $order);

    // Add the line item data as a property of the order.
    $order->avatax['avatax'] = $line_item;
  }
  else {
    drupal_set_message(t('AvaTax did not calculate sales tax'), 'error');
    return;
  }
}