You are here

function uc_cybersource_requirements in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 payment/uc_cybersource/uc_cybersource.install \uc_cybersource_requirements()

Implements hook_requirements().

File

payment/uc_cybersource/uc_cybersource.install, line 11
Install, update and uninstall functions for the uc_cybersource module.

Code

function uc_cybersource_requirements($phase) {
  $t = get_t();
  $has_curl = function_exists('curl_init');
  $has_dom = class_exists('DOMDocument');
  $has_soap = class_exists('SoapClient');

  // Valid methods are 'soap' and 'post'.  Defaults here to 'post' on install.
  $method = variable_get('uc_cybersource_method', 'post');

  // Using SOAP.
  if ($method == 'soap') {
    $requirements['uc_cybersource_soap_and_dom'] = array(
      'title' => $t('SOAP and DOM'),
      'value' => $has_soap && $has_dom ? $t('Enabled') : $t('Not found'),
    );
    if (!$has_soap || !$has_dom) {
      $requirements['uc_cybersource_soap_and_dom']['severity'] = REQUIREMENT_ERROR;
      $requirements['uc_cybersource_soap_and_dom']['description'] = $t("CyberSource's SOAP Toolkit API requires the PHP <a href='!soap_url'>SOAP</a> and <a href='!dom_url'>DOM</a> libraries.", array(
        '!soap_url' => 'http://php.net/manual/en/soap.setup.php',
        '!dom_url' => 'http://php.net/manual/en/dom.setup.php',
      ));
    }
  }
  elseif ($method == 'post') {
    $requirements['uc_cybersource_curl'] = array(
      'title' => $t('cURL'),
      'value' => $has_curl ? $t('Enabled') : $t('Not found'),
    );
    if (!$has_curl) {
      $requirements['uc_cybersource_curl']['severity'] = REQUIREMENT_ERROR;
      $requirements['uc_cybersource_curl']['description'] = $t("CyberSource's Silent Order POST requires the PHP <a href='!curl_url'>cURL</a> library.", array(
        '!curl_url' => 'http://php.net/manual/en/curl.setup.php',
      ));
    }
  }

  // We need HOP.php if we're using the post method and also the Hosted Order
  // page, which is a payment method rather than a gateway.
  if ($method != 'soap') {
    require_once 'uc_cybersource.module';
    $has_cybersource_hop = uc_cybersource_hop_include();
    $requirements['uc_cybersource'] = array(
      'title' => t('CyberSource HOP.php'),
      'value' => $has_cybersource_hop ? $t('Enabled') : $t('Not found'),
    );
    if (!$has_cybersource_hop) {
      $requirements['uc_cybersource']['description'] = t('For instructions on how to generate this file, please refer to <a href="http://www.cybersource.com/support_center/implementation/downloads/hosted_order_page/">CyberSource\'s Hosted Order Pages Documentation</a>, specifically the "Downloading Security Scripts" in Chapter 2 of the <a href="http://apps.cybersource.com/library/documentation/sbc/HOP_UG/html/">HOP User\'s Guide</a>.');
      $severity = $phase == 'install' ? REQUIREMENT_INFO : REQUIREMENT_ERROR;
      $requirements['uc_cybersource']['severity'] = $severity;
    }
    else {
      $requirements['uc_cybersource']['severity'] = REQUIREMENT_OK;
      $requirements['uc_cybersource']['description'] = t('The HOP.php library is readable.');
    }
  }
  return $requirements;
}