You are here

pay.install in Pay 6

Same filename and directory in other branches
  1. 7 pay.install

Pay module allows for accepting payments against a node using pluggable payment backends.

File

pay.install
View source
<?php

// $Id$

/**
 * @file
 * Pay module allows for accepting payments against a node using pluggable
 * payment backends.
 */
function pay_install() {
  drupal_install_schema('pay');
}
function pay_uninstall() {
  drupal_uninstall_schema('pay');
}
function pay_schema() {
  $schema['pay_form'] = array(
    'fields' => array(
      'pfid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'status' => array(
        'type' => 'int',
        'size' => 'tiny',
      ),
      'handler' => array(
        'type' => 'varchar',
        'length' => '100',
      ),
      'embeddable' => array(
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => '100',
      ),
      'menu_path' => array(
        'type' => 'varchar',
        'length' => '100',
      ),
      'total_goal' => array(
        'type' => 'float',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'min_amount' => array(
        'type' => 'float',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'max_amount' => array(
        'type' => 'float',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'currency' => array(
        'type' => 'varchar',
        'length' => '3',
      ),
      'settings' => array(
        'type' => 'text',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'pfid',
    ),
  );
  $schema['pay_transaction'] = array(
    'fields' => array(
      'pxid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'pfid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'state' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
        'default' => 'pending',
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'completed' => array(
        'type' => 'int',
        'not null' => FALSE,
      ),
      'total' => array(
        'type' => 'float',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'total_paid' => array(
        'type' => 'float',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'currency' => array(
        'type' => 'varchar',
        'length' => '3',
      ),
      'notes' => array(
        'type' => 'text',
      ),
      'notes_format' => array(
        'type' => 'int',
        'size' => 'small',
      ),
      'mail' => array(
        'type' => 'varchar',
        'length' => 200,
      ),
    ),
    'primary key' => array(
      'pxid',
    ),
  );
  $schema['pay_activity'] = array(
    'fields' => array(
      'paid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'pxid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'pmid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '10',
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '10',
      ),
      'payment_type' => array(
        'type' => 'varchar',
        'length' => '100',
        'not null' => FALSE,
      ),
      'action' => array(
        'type' => 'varchar',
        'length' => '100',
        'not null' => TRUE,
      ),
      'result' => array(
        'type' => 'int',
        'not null' => FALSE,
        'disp-width' => '11',
      ),
      'identifier' => array(
        'type' => 'varchar',
        'length' => '100',
        'not null' => FALSE,
      ),
      'total' => array(
        'type' => 'float',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'transaction_total' => array(
        'type' => 'float',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => FALSE,
        'disp-width' => '11',
      ),
      'hostname' => array(
        'type' => 'varchar',
        'length' => '100',
        'not null' => FALSE,
      ),
      'data' => array(
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'paid',
    ),
  );
  $schema['pay_method'] = array(
    'fields' => array(
      'pmid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'handler' => array(
        'type' => 'varchar',
        'length' => '100',
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => '100',
        'not null' => FALSE,
      ),
      'description' => array(
        'type' => 'varchar',
        'length' => '255',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => FALSE,
        'disp-width' => '11',
      ),
      'min_amount' => array(
        'type' => 'numeric',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'max_amount' => array(
        'type' => 'numeric',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'settings' => array(
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'pmid',
    ),
  );
  $schema['pay_item'] = array(
    'fields' => array(
      'piid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'handler' => array(
        'type' => 'varchar',
        'length' => '100',
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => '100',
        'not null' => FALSE,
      ),
      'status' => array(
        'type' => 'int',
        'not null' => FALSE,
        'disp-width' => '11',
      ),
      'description' => array(
        'type' => 'varchar',
        'length' => '255',
      ),
      'cost' => array(
        'type' => 'numeric',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '2',
      ),
      'settings' => array(
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'piid',
    ),
  );
  return $schema;
}

/**
 * Add our payment item table.
 */
function pay_update_6001() {
  $ret = array();
  $table = drupal_get_schema('pay_item', TRUE);
  db_create_table($ret, 'pay_item', $table);
  return $ret;
}

/**
 * Add a "mail" column to the pay_transaction table.
 */
function pay_update_6002() {
  $ret = array();
  db_add_column($ret, 'pay_transaction', 'mail', 'varchar(200)');
  return $ret;
}

/**
 * Add an "embeddable" column to the pay_form table.
 */
function pay_update_6003() {
  $ret = array();
  $spec = array(
    'type' => 'int',
    'size' => 'tiny',
    'default' => 0,
  );
  db_add_field($ret, 'pay_form', 'embeddable', $spec);
  return $ret;
}

/**
 * Add a "state" column to the pay_transaction table.
 */
function pay_update_6004() {
  $ret = array();
  $spec = array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => 'pending',
  );
  db_add_field($ret, 'pay_transaction', 'state', $spec);

  // Set some default values for existing transactions.
  // Complete if total == total_paid.
  $ret[] = update_sql("UPDATE {pay_transaction}\n    SET state = 'complete' WHERE total = total_paid");

  // Making a hefty assumption that it's canceled if total_paid = 0.
  $ret[] = update_sql("UPDATE {pay_transaction}\n    SET state = 'canceled' WHERE total > 0 AND total_paid = 0");

  // Setting everything else, AKA partial-payments, to 'active' / in progress.
  $ret[] = update_sql("UPDATE {pay_transaction}\n    SET state = 'active' WHERE total > 0 AND total_paid > 0 AND total != total_paid");

  // Special case - successful transactions (e.g. from CIM) on $0 transactions.
  $ret[] = update_sql("UPDATE {pay_transaction} t, {pay_activity} a\n    SET state = 'pending'\n    WHERE t.pxid = a.pxid AND t.state = 'canceled' AND a.result = '1'");
  return $ret;
}

/**
 * Rename 'activity' to 'action' in pay_activity table.
 */
function pay_update_6005() {
  $ret = array();
  $spec = array(
    'type' => 'varchar',
    'length' => 100,
    'not null' => TRUE,
  );
  db_change_field($ret, 'pay_activity', 'activity', 'action', $spec);
  return $ret;
}

/**
 * Rename 'activity' to 'action' in pay_method.
 */
function pay_update_6006() {
  $ret = array();
  $res = db_query("SELECT * FROM {pay_method}");
  while ($row = db_fetch_object($res)) {
    $settings = unserialize($row->settings);
    if (array_key_exists('pay_form_activity', $settings)) {
      $settings['pay_form_action'] = $settings['pay_form_activity'];
      unset($settings['pay_form_activity']);
      db_query("UPDATE {pay_method}\n        SET settings = '%s' WHERE pmid = %d", serialize($settings), $row->pmid);
    }
  }
  return $ret;
}

/**
 * Remove my actions from the actions table so that they get re-read.
 */
function pay_update_6007() {
  $ret = array();
  update_sql("DELETE FROM {actions} WHERE TYPE = 'pay_transaction'");
  return $ret;
}

Functions

Namesort descending Description
pay_install @file Pay module allows for accepting payments against a node using pluggable payment backends.
pay_schema
pay_uninstall
pay_update_6001 Add our payment item table.
pay_update_6002 Add a "mail" column to the pay_transaction table.
pay_update_6003 Add an "embeddable" column to the pay_form table.
pay_update_6004 Add a "state" column to the pay_transaction table.
pay_update_6005 Rename 'activity' to 'action' in pay_activity table.
pay_update_6006 Rename 'activity' to 'action' in pay_method.
pay_update_6007 Remove my actions from the actions table so that they get re-read.