pay.install in Pay 7
Same filename and directory in other branches
Pay module allows for accepting payments against a node using pluggable payment backends.
File
pay.installView source
<?php
/**
* @file
* Pay module allows for accepting payments against a node using pluggable
* payment backends.
*/
/**
* Implements hook_schema().
*/
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() {
$table = drupal_get_schema('pay_item', TRUE);
db_create_table('pay_item', $table);
return t('Created "pay_item" table.');
}
/**
* Add a "mail" column to the pay_transaction table.
*/
function pay_update_6002() {
db_add_field('pay_transaction', 'mail', array(
'type' => 'varchar',
'length' => 200,
));
return t('Added a "mail" column to the pay_transaction table.');
}
/**
* Add an "embeddable" column to the pay_form table.
*/
function pay_update_6003() {
$spec = array(
'type' => 'int',
'size' => 'tiny',
'default' => 0,
);
db_add_field('pay_form', 'embeddable', $spec);
return t('Add an "embeddable" column to the pay_form table.');
}
/**
* Add a "state" column to the pay_transaction table.
*/
function pay_update_6004() {
$spec = array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'default' => 'pending',
);
db_add_field('pay_transaction', 'state', $spec);
// Set some default values for existing transactions.
// Complete if total == total_paid.
db_update('pay_transaction')
->fields(array(
'state' => "complete",
))
->where('total = total_paid')
->execute();
// Making a hefty assumption that it's canceled if total_paid = 0.
db_update('pay_transaction')
->fields(array(
'state' => "canceled",
))
->condition('total', 0, '>')
->condition('total_paid', 0)
->execute();
// Setting everything else, AKA partial-payments, to 'active' / in progress.
db_update('pay_transaction')
->fields(array(
'state' => "active",
))
->where('total != total_paid')
->condition('total', 0, '>')
->condition('total_paid', 0, '>')
->execute();
// Special case - successful transactions (e.g. from CIM) on $0 transactions.
$query = db_update('pay_transaction', 't')
->fields(array(
'state' => "pending",
));
$query
->join('pay_activity', 'a', 't.pxid = a.pxid');
$query
->condition('t.state', "canceled")
->condition('a.result', '1')
->execute();
return t('Add a "state" column to the pay_transaction table.');
}
/**
* Rename 'activity' to 'action' in pay_activity table.
*/
function pay_update_6005() {
$spec = array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
);
db_change_field('pay_activity', 'activity', 'action', $spec);
return t('Renamed "activity" column to "action" in pay_activity table.');
}
/**
* Rename 'activity' to 'action' in pay_method.
*/
function pay_update_6006() {
$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_update('pay_method')
->fields(array(
'settings' => serialize($settings),
))
->condition('pmid', $row->pmid)
->execute();
}
}
return t('Renamed "activity" column to "action" in pay_method table.');
}
/**
* Remove my actions from the actions table so that they get re-read.
*/
function pay_update_6007() {
db_delete('actions')
->condition('type', "pay_transaction")
->execute();
return t('Removed my actions from the actions table so that they get re-read.');
}
Functions
Name | Description |
---|---|
pay_schema | Implements hook_schema(). |
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. |