'eCommerce Receipts',
'fields' => array(
'erid' => array(
'description' => 'Receipt Id',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'ecid' => array(
'description' => 'Customer Id',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'Payment Method',
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
),
'extern_id' => array(
'description' => 'External Payment Method Id',
'type' => 'varchar',
'length' => '64',
'not null' => TRUE,
'default' => '',
),
'currency' => array(
'description' => '3 letter currency code',
'type' => 'varchar',
'length' => '3',
'not null' => TRUE,
),
'amount' => array(
'description' => 'Receipt Amount',
'type' => 'numeric',
'not null' => TRUE,
'precision' => '10',
'scale' => '2',
),
'allocated' => array(
'description' => 'Allocation Amount',
'type' => 'numeric',
'not null' => TRUE,
'precision' => '10',
'scale' => '2',
),
'balance' => array(
'description' => 'Receipt Balance',
'type' => 'numeric',
'not null' => TRUE,
'precision' => '10',
'scale' => '2',
),
'allocation' => array(
'description' => 'Allocation Details',
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
),
'status' => array(
'description' => 'eCommerce Recieipt Status Code',
'type' => 'int',
'not null' => TRUE,
),
'response_text' => array(
'description' => 'Payment Method Response Text',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'Description of Payment Method',
'type' => 'varchar',
'length' => '128',
'not null' => FALSE,
'default' => '',
),
'created' => array(
'description' => 'Date Created',
'type' => 'int',
'not null' => TRUE,
),
'changed' => array(
'description' => 'Date Updated',
'type' => 'int',
'not null' => TRUE,
),
),
'primary key' => array('erid'),
'indexes' => array(
'ecid' => array('ecid'),
'extern_id' => array('type', 'extern_id'),
),
);
$schema['ec_receipt_types'] = array(
'description' => 'eCommerce Receipt Types',
'fields' => array(
'type' => array(
'description' => 'Type',
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
),
'name' => array(
'description' => 'Name',
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
),
'description' => array(
'description' => 'Description',
'type' => 'text',
'not null' => TRUE,
),
'allow_payments' => array(
'description' => 'Allow Payments',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'allow_admin_payments' => array(
'description' => 'Allow Admin Payments',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'allow_refunds' => array(
'description' => 'Allow Refunds',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'allow_payto' => array(
'description' => 'Allow 3rd Party Payments',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'allow_recurring' => array(
'description' => 'Allow Recurring Payments',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'weight' => array(
'description' => 'Priority on Checkout',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('type'),
);
$schema['ec_receipt_allocation'] = array(
'description' => 'eCommerce Receipt Allocations',
'fields' => array(
'eaid' => array(
'description' => 'Allocation Id',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'erid' => array(
'description' => 'Receipt Id',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'Type of Allocation',
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
),
'etid' => array(
'description' => 'Transaction Id',
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
),
'created' => array(
'description' => 'Date Created',
'type' => 'int',
'not null' => TRUE,
),
'amount' => array(
'description' => 'Allocation Amount',
'type' => 'numeric',
'not null' => TRUE,
'precision' => '10',
'scale' => '2',
),
'reversed' => array(
'description' => 'Allocation Reversed',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('eaid'),
'indexes' => array(
'erid' => array('erid'),
'type' => array('type', 'etid'),
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function ec_receipt_requirements($phase = 'install') {
$t = get_t();
$requirements = array();
switch ($phase) {
case 'runtime':
// Check for Payment gateways installed.
$requirements['ec_payment_gateway']['title'] = $t('Payment gateways enabled');
$filter = array(
'allow_payments' => TRUE,
);
$gateways = array_map('_ec_requirements_map_gateways', ec_receipt_type_filter($filter));
if (empty($gateways)) {
$requirements['ec_payment_gateway']['value'] = $t('No payment gateways have been enabled.');
$requirements['ec_payment_gateway']['severity'] = REQUIREMENT_ERROR;
$requirements['ec_payment_gateway']['description'] = $t('Payment gateways are used to determine the lists of available currencies and charge customers for purchases. Enable a payment gateway on the Modules page', array('!link' => url('admin/modules')));
}
else {
$requirements['ec_payment_gateway']['value'] = implode(', ', $gateways);
$requirements['ec_payment_gateway']['severity'] = REQUIREMENT_OK;
}
// Check currency is set correctly.
$dc = variable_get('ec_default_currency', NULL);
$currencies = ec_receipt_currency_list();
$requirements['ec_currency']['title'] = st('Default system currency');
if (isset($dc) && isset($currencies[$dc])) {
$requirements['ec_currency']['value'] = $currencies[$dc];
$requirements['ec_currency']['severity'] = REQUIREMENT_OK;
}
elseif (isset($dc)) {
$requirements['ec_currency']['value'] = $t('Default system currency is not an available currency %currency', array('%currency' => $dc));
$requirements['ec_currency']['severity'] = REQUIREMENT_ERROR;
$requirements['ec_currency']['description'] = $t('The current default currency is not valid. Set this on the Receipt type settings', array('!link' => url('admin/config/store/rtypes/settings')));
}
elseif (empty($gateways)) {
$requirements['ec_currency']['value'] = $t('No currency set or payment gateways to determine the currency to use.');
$requirements['ec_currency']['severity'] = REQUIREMENT_ERROR;
$requirements['ec_currency']['description'] = $t('There are currently no payment gateways enabled to determine which curreny can be used as the default. Enable a payment gateway and then set the default currency on the Receipt type settings', array('!enable' => url('admin/modules'), '!link' => url('admin/config/store/rtypes/settings')));
}
else {
$requirements['ec_currency']['value'] = $t('No currency set');
$requirements['ec_currency']['severity'] = REQUIREMENT_ERROR;
$requirements['ec_currency']['description'] = $t('The default system currency has not been set. Set this on the Receipt type settings', array('!link' => url('admin/config/store/rtypes/settings')));
}
// Check that allocation is balanced.
$requirements['ec_allocated']['title'] = t('Receipt allocation');
$requirements['ec_allocated']['description'] = t('Checking all allocations and make sure that they total the same as what is recorded in the receipts table. ie. "SUM(ec_receipt_allocation.amount) == SUM(ec_receipt.allocated)"');
$receipt_allocation = 0 + db_query('SELECT SUM(amount) FROM {ec_receipt_allocation}')->fetchField();
$receipt = 0 + db_query('SELECT SUM(allocated) FROM {ec_receipt}')->fetchField();
$requirements['ec_allocated']['value'] = $receipt_allocation == $receipt ? t('Allocation is in balance') : t('Allocation is not in balance (%allocation != %allocate)', array('%allocation' => format_currency($receipt_allocation), '%allocate' => format_currency($receipt)));
$requirements['ec_allocated']['severity'] = $receipt_allocation == $receipt ? REQUIREMENT_OK : REQUIREMENT_ERROR;
// Check the balance of all the receipts.
$requirements['ec_receipt']['title'] = t('Receipt balance');
$requirements['ec_receipt']['description'] = t('Checking all of the receipts and making sure they balance internally ie. "(amount - (balance + allocated)) == 0"');
$balance = (float) db_query('SELECT SUM(amount - (balance + allocated)) FROM {ec_receipt}')->fetchField();
$requirements['ec_receipt']['value'] = $balance ? t('Receipts are out of balance') : t('Receipts are in balance');
$requirements['ec_receipt']['severity'] = $balance ? REQUIREMENT_ERROR : REQUIREMENT_OK;
break;
}
return $requirements;
}
function _ec_requirements_map_gateways($a) {
return $a->name;
}
/**
* Implements hook_update_last_removed().
*/
function ec_receipt_update_last_removed() {
return 6407;
}