<?php

/**
 * @file
 * Install, update and uninstall functions for the uc_payment module.
 */

/**
 * Implements hook_schema().
 */
function uc_payment_schema() {
  $schema = array();

  $schema['uc_payment_receipts'] = array(
    'description' => 'Stores completed payments.',
    'fields' => array(
      'receipt_id' => array(
        'description' => 'Primary key: the payment receipt ID.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'order_id' => array(
        'description' => 'The {uc_orders}.order_id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'method' => array(
        'description' => 'The payment method.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'amount' => array(
        'description' => 'The payment amount in the store default currency.',
        'type' => 'numeric',
        'precision' => 16,
        'scale' => 5,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'The {users}.uid who collected the payment.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'data' => array(
        'description' => 'A serialized array of extra payment data.',
        'type' => 'text',
        'serialize' => TRUE,
      ),
      'comment' => array(
        'description' => 'A comment made on the payment.',
        'type' => 'text',
      ),
      'received' => array(
        'description' => 'The Unix timestamp indicating when the payment was received.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'order_id' => array('order_id'),
    ),
    'primary key' => array('receipt_id'),
    'foreign keys' => array(
      'uc_orders' => array(
        'table' => 'uc_orders',
        'columns' => array('order_id' => 'order_id'),
      ),
    ),
  );

  return $schema;
}
