You are here

protected function AvataxLib::doRequest in Drupal Commerce Connector for AvaTax 8

Performs an HTTP request to AvaTax.

Parameters

string $method: The HTTP method to use.

string $path: The remote path. The base URL will be automatically appended.

array $parameters: An array of fields to include with the request. Optional.

Return value

array The response array.

3 calls to AvataxLib::doRequest()
AvataxLib::resolveAddress in src/AvataxLib.php
Retrieve geolocation information for a specified address.
AvataxLib::transactionsCreate in src/AvataxLib.php
Creates a new transaction (/api/v2/transactions/create).
AvataxLib::transactionsVoid in src/AvataxLib.php
Voids a transaction for the given order.

File

src/AvataxLib.php, line 497

Class

AvataxLib
The AvaTax integration library.

Namespace

Drupal\commerce_avatax

Code

protected function doRequest($method, $path, array $parameters = []) {
  $response_body = [];
  try {
    $response = $this->client
      ->request($method, $path, $parameters);
    $response_body = Json::decode($response
      ->getBody()
      ->getContents());
  } catch (ClientException $e) {
    $body = $e
      ->getResponse()
      ->getBody()
      ->getContents();
    $response_body = Json::decode($body);
    $this->logger
      ->error('@method @path error: <pre>' . print_r($body, TRUE) . '</pre>', [
      '@method' => $method,
      '@path' => $path,
    ]);
  } catch (\Exception $e) {
    $this->logger
      ->error($e
      ->getMessage());
  }

  // Log the response/request if logging is enabled.
  if ($this->config
    ->get('logging')) {
    $url = $this->client
      ->getConfig('base_uri') . $path;
    $this->logger
      ->info("URL: <pre>{$method} @url</pre>Headers: <pre>@headers</pre>Request: <pre>@request</pre>Response: <pre>@response</pre>", [
      '@url' => $url,
      '@headers' => Variable::export($this->client
        ->getConfig('headers')),
      '@request' => Variable::export($parameters),
      '@response' => Variable::export($response_body),
    ]);
  }
  return $response_body;
}