uc_stripe.install in Ubercart Stripe 8.2
Same filename and directory in other branches
Installation file for the uc_stripe module.
File
uc_stripe.installView source
<?php
/**
* @file
* Installation file for the uc_stripe module.
*/
function _uc_stripe_get_stripe_plugins() {
$plugin_data = [];
$payment_method_names = \Drupal::configFactory()
->listAll('uc_payment.method');
foreach ($payment_method_names as $method) {
$config = \Drupal::config($method);
$data = $config
->get();
if ($data['plugin'] == 'stripe_gateway') {
$plugin_data[$data['id']] = $data;
}
}
return $plugin_data;
}
/**
* Implements hook_requirements().
*/
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;
}
/**
* Implements hook_install().
*/
function uc_stripe_install() {
// TODO: Revisit this when uc_recurring is available
// This turns ON the uc_recurring cron task to renew. We want this
// ON because the renewal payments are handled by uc_recurring and NOT the stripe gateway
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// variable_set('uc_recurring_trigger_renewals', TRUE);
}
Functions
Name | Description |
---|---|
uc_stripe_install | Implements hook_install(). |
uc_stripe_requirements | Implements hook_requirements(). |
_uc_stripe_get_stripe_plugins | @file Installation file for the uc_stripe module. |