You are here

uc_stripe.install in Ubercart Stripe 6

Installation file for the uc_stripe module.

File

uc_stripe.install
View source
<?php

/**
 * @file
 * Installation file for the uc_stripe module.
 */

/**
 * Implements hook_requirements().
 */
function uc_stripe_requirements($phase) {
  $t = get_t();
  $has_curl = function_exists('curl_init');
  $requirements['uc_stripe_curl'] = array(
    'title' => $t('cURL'),
    'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  );
  if (!$has_curl) {
    $requirements['uc_stripe_curl']['severity'] = REQUIREMENT_ERROR;
    $requirements['uc_stripe_curl']['description'] = $t("The Stripe API requires the PHP <a href='!curl_url'>cURL</a> library.", array(
      '!curl_url' => 'http://php.net/manual/en/curl.setup.php',
    ));
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function uc_stripe_install() {
  drupal_install_schema('uc_stripe');

  // This turns off the uc_recurring cron task to renew. We want this
  // off because the renewal payments are handled by Stripe and initiating
  // them separately will cause a mess.
  variable_set('uc_recurring_trigger_renewals', FALSE);
}

/**
 * Implements hook_uninstall().
 */
function uc_stripe_uninstall() {
  drupal_uninstall_schema('uc_stripe');
}

/**
 * Implements hook_schema().
 */
function uc_stripe_schema() {
  $schema = array();
  $schema['uc_recurring_stripe'] = array(
    'description' => 'Stores customer ids and plan names for Stripe subscriptions.',
    'fields' => array(
      'rfid' => array(
        'description' => 'The recurring fee id.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'active' => array(
        'description' => 'Whether or not this subscription is currently active.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'The uid of this user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'order_id' => array(
        'description' => 'The order_id of the purchase.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'The nid of this subscription product.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'customer_id' => array(
        'description' => 'The Stripe customer id.',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ),
      'plan_id' => array(
        'description' => 'The corresponding plan id.',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'rfid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_update_N().
 *
 * Added order_id to schema.
 */
function uc_stripe_update_6101() {
  $ret = array();
  db_add_field($ret, 'uc_recurring_stripe', 'order_id', array(
    'description' => 'The order_id of the purchase.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Added active to schema to indicate subscription status.
 */
function uc_stripe_update_6102() {
  $ret = array();
  db_add_field($ret, 'uc_recurring_stripe', 'active', array(
    'description' => 'Whether or not this subscription is currently active.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Added nid of subscription object.
 */
function uc_stripe_update_6103() {
  $ret = array();
  db_add_field($ret, 'uc_recurring_stripe', 'nid', array(
    'description' => 'The nid of this subscription product.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ));
  return $ret;
}