You are here

function uc_stripe_requirements in Ubercart Stripe 8.2

Same name and namespace in other branches
  1. 8.3 uc_stripe.install \uc_stripe_requirements()
  2. 6.2 uc_stripe.install \uc_stripe_requirements()
  3. 6 uc_stripe.install \uc_stripe_requirements()
  4. 7.3 uc_stripe.install \uc_stripe_requirements()
  5. 7 uc_stripe.install \uc_stripe_requirements()
  6. 7.2 uc_stripe.install \uc_stripe_requirements()

Implements hook_requirements().

File

./uc_stripe.install, line 24
Installation file for the uc_stripe module.

Code

function uc_stripe_requirements($phase) {
  $required_minimum_version = '3.20.0';
  $php_api_version = "";
  if (class_exists('\\Stripe\\Stripe')) {
    $php_api_version = \Stripe\Stripe::VERSION;
  }
  $version_is_ok = version_compare($php_api_version, $required_minimum_version, 'ge');
  $requirements['uc_stripe_api'] = array(
    'title' => t('Stripe PHP Library for Ubercart Stripe'),
    'value' => t('Version @version', [
      '@version' => $php_api_version,
    ]),
    'description' => t('Stripe PHP Library is installed'),
  );
  $requirements['uc_stripe_api']['value'] = !empty($php_api_version) ? $php_api_version : t('Not Installed');
  $requirements['uc_stripe_api']['severity'] = $version_is_ok ? REQUIREMENT_OK : REQUIREMENT_ERROR;
  if (!$version_is_ok) {
    $requirements['uc_stripe_api']['description'] = $version_is_ok ? t('Please install Stripe PHP Library') : t("Stripe PHP API library is not recent enough. Version needs to be @version or higher", [
      '@version' => $required_minimum_version,
    ]);
  }
  $plugins = _uc_stripe_get_stripe_plugins();
  foreach ($plugins as $plugin) {
    $requirement_key = "uc_stripe_keys_{$plugin['id']}";
    $requirements[$requirement_key] = array(
      'title' => t('Stripe API Keys for uc_stripe "@plugin" payment method', [
        '@plugin' => $plugin['id'],
      ]),
      'value' => t('Configured'),
    );
    if ($phase == 'runtime' && !_uc_stripe_check_api_keys($plugin['settings'])) {
      $requirements[$requirement_key]['title'] = t('Stripe API Keys.');
      $requirements[$requirement_key]['value'] = t('Not configured');
      $requirements[$requirement_key]['severity'] = REQUIREMENT_ERROR;
      $requirements[$requirement_key]['description'] = t('The Stripe API keys are not fully configured for the @name payment method.', [
        '@name' => $plugin['id'],
      ]);
    }
  }
  return $requirements;
}