You are here

function pay_update_6004 in Pay 7

Same name and namespace in other branches
  1. 6 pay.install \pay_update_6004()

Add a "state" column to the pay_transaction table.

File

./pay.install, line 343
Pay module allows for accepting payments against a node using pluggable payment backends.

Code

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.');
}