class ClientFactory in Drupal Commerce Connector for AvaTax 8
API Client factory.
Hierarchy
- class \Drupal\commerce_avatax\ClientFactory
Expanded class hierarchy of ClientFactory
1 file declares its use of ClientFactory
- AddressValidationTest.php in tests/
src/ Kernel/ AddressValidationTest.php
1 string reference to 'ClientFactory'
1 service uses ClientFactory
File
- src/
ClientFactory.php, line 11
Namespace
Drupal\commerce_avataxView source
class ClientFactory {
/**
* The client factory.
*
* @var \Drupal\Core\Http\ClientFactory
*/
protected $clientFactory;
/**
* The extensions list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $extensionList;
/**
* Constructs a new AvaTax ClientFactory object.
*
* @param \Drupal\Core\Http\ClientFactory $client_factory
* The client factory.
* @param \Drupal\Core\Extension\ExtensionList $extension_list
* The extension list.
*/
public function __construct(CoreClientFactory $client_factory, ExtensionList $extension_list) {
$this->clientFactory = $client_factory;
$this->extensionList = $extension_list;
}
/**
* Gets an API client instance.
*
* @param array $config
* The config for the client.
*
* @return \GuzzleHttp\Client
* The API client.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientFactory:: |
protected | property | The client factory. | |
ClientFactory:: |
protected | property | The extensions list. | |
ClientFactory:: |
public | function | Gets an API client instance. | |
ClientFactory:: |
public | function | Constructs a new AvaTax ClientFactory object. |