public function ClientFactory::createInstance in Drupal Commerce Connector for AvaTax 8
Gets an API client instance.
Parameters
array $config: The config for the client.
Return value
\GuzzleHttp\Client The API client.
File
- src/
ClientFactory.php, line 49
Class
- ClientFactory
- API Client factory.
Namespace
Drupal\commerce_avataxCode
public function createInstance(array $config) {
switch ($config['api_mode']) {
case 'production':
$base_uri = 'https://rest.avatax.com/';
break;
case 'development':
default:
$base_uri = 'https://sandbox-rest.avatax.com/';
break;
}
// Specify the x-Avalara-Client header.
$server_machine_name = gethostname();
$module_info = $this->extensionList
->getExtensionInfo('commerce_avatax');
$version = !empty($module_info['version']) ? $module_info['version'] : '8.x-1.x';
$x_avalara_client = "Drupal Commerce; Version [{$version}]; REST; V2; [{$server_machine_name}]";
$options = [
'base_uri' => $base_uri,
'headers' => [
'Authorization' => 'Basic ' . base64_encode($config['account_id'] . ':' . $config['license_key']),
'Content-Type' => 'application/json',
'x-Avalara-UID' => 'a0o33000003waOC',
'x-Avalara-Client' => $x_avalara_client,
],
];
return $this->clientFactory
->fromOptions($options);
}