You are here

protected function AuthorizeNet::uc_authorizenet_xml_api in Ubercart 8.4

Sends an XML API Request to Authorize.Net.

Parameters

string $server: The name of the server to send request to - 'production' or 'developer'.

string $xml: The XML to send to Authorize.Net.

Return value

bool TRUE or FALSE indicating the success of the API request.

File

payment/uc_authorizenet/src/Plugin/Ubercart/PaymentMethod/AuthorizeNet.php, line 476

Class

AuthorizeNet
Defines the Authorize.net payment method.

Namespace

Drupal\uc_authorizenet\Plugin\Ubercart\PaymentMethod

Code

protected function uc_authorizenet_xml_api($server, $xml) {
  if ($server == 'production') {
    $post_url = 'https://api.authorize.net/xml/v1/request.api';
  }
  elseif ($server == 'developer') {
    $post_url = 'https://apitest.authorize.net/xml/v1/request.api';
  }
  else {
    return FALSE;
  }
  $response = \Drupal::httpClient()
    ->setSslVerification(TRUE, TRUE, 2)
    ->setConfig([
    'curl.options' => [
      CURLOPT_FOLLOWLOCATION => FALSE,
    ],
  ])
    ->post($post_url, [
    "Content-Type: text/xml",
  ], $xml)
    ->send();

  // Log any errors to the watchdog.
  if ($response
    ->isError()) {
    \Drupal::logger('uc_authorizenet')
      ->error('@error', [
      '@error' => $response
        ->getReasonPhrase(),
    ]);
    return FALSE;
  }
  return $response
    ->getBody(TRUE);
}