You are here

function commerce_avatax_object in Drupal Commerce Connector for AvaTax 7.5

Returns a statically cached instance of an Avatax object.

Parameters

string $api_key: The API key to use to submit requests to the Avatax API.

string $api_mode: The passed API module will determine the base url of the API.

Return value

Avatax|bool. The constructed Avatax object or FALSE if the library could not be loaded..

6 calls to commerce_avatax_object()
commerce_avatax_calculate_tax in ./commerce_avatax.module
Performs Tax calculation for a given order.
commerce_avatax_commerce_payment_order_paid_in_full in ./commerce_avatax.module
Implements hook_commerce_payment_order_paid_in_full().
commerce_avatax_commit_transaction in ./commerce_avatax.module
COMMIT an existing transaction for a given $order.
commerce_avatax_credentials_settings_validate in includes/commerce_avatax.admin.inc
Validate handler for the "Validate credentials" button.
commerce_avatax_validate_address in includes/commerce_avatax.address.inc
Validate the address entered on checkout form.

... See full list

File

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

Code

function commerce_avatax_object($api_key = '', $api_mode = '') {
  $avatax =& drupal_static(__FUNCTION__, array());

  // If the Api key wasn't provided.
  if (empty($api_key)) {
    $account_number = commerce_avatax_account_number();
    $license_key = commerce_avatax_license_key();
    if (!empty($account_number) && !empty($license_key)) {
      $api_key = base64_encode("{$account_number}:{$license_key}");
    }
    else {
      return FALSE;
    }
  }
  if (!isset($avatax[$api_key])) {
    $logger = NULL;
    $api_mode = empty($api_mode) ? commerce_avatax_api_mode() : $api_mode;

    // Specify the logger if the logging was enabled.
    if (variable_get(COMMERCE_AVATAX_VAR_PREFIX . 'enable_logging', FALSE)) {
      $logger = 'watchdog';
    }

    // Specify the x-Avalara-Client header.
    $server_machine_name = gethostname();
    $module_info = system_get_info('module', 'commerce_avatax');
    $version = !empty($module_info['version']) ? $module_info['version'] : '5.x';
    $headers = array(
      "x-Avalara-Client" => "Drupal Commerce; Version [{$version}]; REST; V2; [{$server_machine_name}]",
    );
    $avatax[$api_key] = new Avatax($api_key, $api_mode, $logger, $headers);
  }
  return $avatax[$api_key];
}