You are here

public function MolliePaymentInstaller::checkMollieAccount in Mollie Payment 7.2

Checks if a Mollie account has been configured.

Return value

array An associative array as expected by hook_requirements().

File

includes/mollie_payment.installer.inc, line 84

Class

MolliePaymentInstaller
Class MolliePaymentInstaller.

Namespace

Drupal\mollie_payment

Code

public function checkMollieAccount() {
  $value = 'no API key';
  $description = t('There is no default live API key configured.');
  $url = url('admin/config/services/mollie/account');
  $severity = REQUIREMENT_WARNING;
  $apiKey = variable_get('mollie_payment_default_api_key_live', '');
  if (!empty($apiKey)) {
    $organizationToken = variable_get('mollie_payment_default_access_token', '');
    if (empty($organizationToken)) {
      $value = 'no organization access token';
      $description = t('There is no default organization access token configured. With an organization access token your Mollie onboarding status can be checked.');
    }
    else {

      // Check the onboarding status. The Mollie API client for PHP does not
      // support this at this moment so we need to do this manually for now.
      $value = $this
        ->getOnboardingStatus();
      switch ($value) {
        case 'needs-data':
          $description = t('Mollie needs more information to enable your account.');
          $url = self::MOLLIE_ACCOUNT_URL;
          break;
        case 'in-review':
          $description = t('Mollie is reviewing your account application.');
          $url = self::MOLLIE_ACCOUNT_URL;
          break;
        case 'completed':
          $description = t('Your default Mollie account has been configured.');
          $severity = REQUIREMENT_OK;
          break;
        default:
          $description = t('The onboarding status of your Mollie account could not be determined.');
          break;
      }
    }
  }
  if ($severity === REQUIREMENT_WARNING) {

    // Add a link to the account configuration form.
    $description .= ' ' . t('Click to <a href="!url">configure your Mollie account</a>.', array(
      '!url' => $url,
    ));
  }
  return $this
    ->formatRequirements('Mollie account', $value, $description, $severity);
}