diff --git includes/handlers/pay.inc includes/handlers/pay.inc
index 8571dc6..2195e82 100644
--- includes/handlers/pay.inc
+++ includes/handlers/pay.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -18,12 +19,12 @@ class pay {
   function __construct($values = NULL) {
     $current = (array) $this;
     if ($values) {
-      foreach ((array)$values as $name => $val) {
+      foreach ((array) $values as $name => $val) {
         if ($name == 'settings' && !empty($val) && is_scalar($val)) {
           $this->__construct(unserialize($val));
         }
         elseif (array_key_exists($name, $current) && !is_null($val)) {
-          $func = 'set_'. $name;
+          $func = 'set_' . $name;
           if (method_exists($this, $func)) {
             $this->$func($val);
           }
@@ -36,7 +37,7 @@ class pay {
     }
     // Set defaults if possible.
     foreach ($current as $name => $val) {
-      $func = 'set_'. $name;
+      $func = 'set_' . $name;
       if (method_exists($this, $func)) {
         $this->$func($this->$name);
       }
@@ -58,7 +59,9 @@ class pay {
   }
 
   function set_hostname($val = NULL) {
-    if (!$val) $val = ip_address();
+    if (!$val) {
+      $val = ip_address();
+    }
     $this->hostname = check_plain($val);
   }
 
@@ -83,9 +86,13 @@ class pay {
   }
 
   function timestamp_value($val = NULL) {
-    if (!$val) $val = time();
-    if (!is_numeric($val)) $val = strtotime($val);
-    return (int)$val;
+    if (!$val) {
+      $val = REQUEST_TIME;
+    }
+    if (!is_numeric($val)) {
+      $val = strtotime($val);
+    }
+    return (int) $val;
   }
 
   function set_created($val = NULL) {
@@ -107,11 +114,13 @@ class pay {
       global $user;
       $val = $user->uid;
     }
-    $this->uid = (int)$val;
+    $this->uid = (int) $val;
   }
 
   function set_mail($val = NULL) {
-    if (valid_email_address($val)) $this->mail = $val;
+    if (valid_email_address($val)) {
+      $this->mail = $val;
+    }
   }
 
   function set_handler() {
@@ -140,7 +149,9 @@ class pay {
   }
 
   function menu_path() {
-    if ($this->menu_path) return check_plain($this->menu_path);
+    if ($this->menu_path) {
+      return check_plain($this->menu_path);
+    }
   }
 
   function title() {
@@ -152,7 +163,7 @@ class pay {
   }
 
   function user() {
-    return user_load(array('uid' => $this->uid()));
+    return user_load($this->uid());
   }
 
   function total() {
@@ -161,27 +172,46 @@ class pay {
       $total .= '.00';
     }
     if (strpos($total, '.') === 0) {
-      $total = '0.'. $total;
+      $total = '0.' . $total;
     }
     return $total;
   }
 
   function notes() {
     if (isset($this->notes)) {
-      return check_markup($this->notes, $this->notes_format);
+      $notes_format = $this->set_notes_format();
+      return check_markup($this->notes, $notes_format);
     }
   }
 
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_form() {
-    if ($this->pfid) return pay_form_load($this->pfid);
+    if ($this->pfid) {
+      return pay_form_load($this->pfid);
+    }
   }
 
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_transaction() {
-    if ($this->pxid) return pay_transaction_load($this->pxid);
+    if ($this->pxid) {
+      return pay_transaction_load($this->pxid);
+    }
   }
 
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_activity() {
-    if ($this->paid) return pay_activity_load($this->paid);
+    if ($this->paid) {
+      return pay_activity_load($this->paid);
+    }
   }
 
   function form_setup(&$form, &$form_state, $form_type = 'form') {
@@ -194,7 +224,7 @@ class pay {
     // form). Set the POSTed values.
     if (!$form_state['submitted'] && isset($_REQUEST[$handler])) {
       foreach ($_REQUEST[$handler] as $posted_name => $posted_val) {
-        $func = 'set_'. $posted_name;
+        $func = 'set_' . $posted_name;
 
         // It is up to the handler to sanitize the value in its set_* functions.
         if (method_exists($this, $func)) {
@@ -208,6 +238,10 @@ class pay {
       $form['#after_build'][] = 'pay_after_build';
     }
 
+    // TODO: check this, variable not set on 2nd step of
+    // admin/config/pay/pay/add so we're adding in a default setting.
+    if (empty($form_state['pay_form_type'])) $form_state['pay_form_type'] = $form_type;
+
     $values = (array) $this;
     $values['type'] = $this->table;
     $values['form'] = $form_type;
@@ -215,11 +249,11 @@ class pay {
 
     $class = array(
       'pay',
-      'pay-'. $form_type,
-      'pay-'. $handler,
-      'pay-'. $form_type .'-'. $form_state['pay_form_type'],
+      'pay-' . $form_type,
+      'pay-' . $handler,
+      'pay-' . $form_type . '-' . $form_state['pay_form_type'],
     );
-    $form['#attributes']['class'] = empty($form['#attributes']['class']) ? join(' ', $class) : $form['#attributes']['class'] . ' ' . join(' ', $class);
+    $form['#attributes']['class'] = empty($form['#attributes']['class']) ? $class : $form['#attributes']['class'] + $class;
 
     $form['#pay'][] = $values;
 
@@ -245,8 +279,7 @@ class pay {
     }
   }
 
-  function settings_form_validate($form, &$form_state) {
-  }
+  function settings_form_validate($form, &$form_state) { }
 
   function settings_form_submit($form, &$form_state) {
     $this->form_values($form_state);
@@ -258,11 +291,9 @@ class pay {
     $this->form_setup($form, $form_state);
   }
 
-  function form_validate($form, &$form_state) {
-  }
+  function form_validate($form, &$form_state) { }
 
-  function form_submit($form, &$form_state) {
-  }
+  function form_submit($form, &$form_state) { }
 
   function save($values = array()) {
     $this->__construct($values);
@@ -280,7 +311,7 @@ class pay {
       $this->handler = get_class($this);
 
       $this->new = isset($this->{$this->key}) ? FALSE : TRUE;
-      $update = $this->new ? NULL : $this->key;
+      $update = $this->new ? array() : $this->key;
 
       // Save this item.
       drupal_write_record($this->table, $this, $update);
@@ -293,7 +324,9 @@ class pay {
 
   function permissions_settings($activity = 'view', $title = NULL) {
     $perm = $this->permissions[$activity];
-    if (!$title) $title = t('Permissions');
+    if (!$title) {
+      $title = t('Permissions');
+    }
 
     $element = array(
       '#type' => 'checkboxes',
@@ -303,18 +336,22 @@ class pay {
       '#tree' => TRUE,
     );
 
+    $all = (!empty($perm['all']) ? $perm['all'] : 0);
     $element['all'] = array(
       '#type' => 'checkbox',
       '#title' => t('Everyone'),
-      '#default_value' => $perm['all'],
+      '#default_value' => $all,
     );
+    $options['all'] = 'all';
 
     // The owner of this pay item.
+    $owner = (!empty($perm['owner']) ? $perm['owner'] : 0);
     $element['owner'] = array(
       '#type' => 'checkbox',
       '#title' => t('Owner'),
-      '#default_value' => $perm['owner'],
+      '#default_value' => $owner,
     );
+    $options['owner'] = 'owner';
 
     $permissions = array(
       'administer pay',
@@ -322,23 +359,28 @@ class pay {
       'make payments on any form',
     );
     foreach (pay_handlers('pay_form') as $name => $info) {
-      $permissions[] = 'administer payments for '. $name .' forms';
-      $permissions[] = 'make payments on '. $name .' forms';
+      $permissions[] = 'administer payments for ' . $name . ' forms';
+      $permissions[] = 'make payments on ' . $name . ' forms';
     }
     foreach ($permissions as $name) {
-      $element['permission:'. $name] = array(
+      $default = (!empty($perm['permission:' . $name]) ? $perm['permission:' . $name] : 0);
+      $element['permission:' . $name] = array(
         '#type' => 'checkbox',
         '#title' => t('Users of any role with the %perm permission', array('%perm' => $name)),
-        '#default_value' => $perm['permission:'. $name],
+        '#default_value' => $default,
       );
+      $options['permission:' . $name] = 'permission:' . $name;
     }
     foreach (user_roles() as $rid => $role) {
-      $element['role:'. $rid] = array(
+      $default = (!empty($perm['role:' . $rid]) ? $perm['role:' . $rid] : 0);
+      $element['role:' . $rid] = array(
         '#type' => 'checkbox',
         '#title' => t('Members of the %role role', array('%role' => $role)),
-        '#default_value' => $perm['role:'. $rid],
+        '#default_value' => $default,
       );
+      $options['role:' . $rid] = 'role:' . $rid;
     }
+    $element['#options'] = $options;
 
     return $element;
   }
@@ -350,28 +392,40 @@ class pay {
     }
 
     // In the absence of any permissions, default access to TRUE.
-    if (!is_array($this->permissions)) return TRUE;
+    if (!is_array($this->permissions)) {
+      return TRUE;
+    }
 
     if (is_array($this->permissions) && $perm = $this->permissions[$activity]) {
       foreach ($perm as $key => $status) {
-        if (!$status) continue;
+        if (!$status) {
+          continue;
+        }
 
         // The owner of this item.
         if ($key == 'owner' && $this->uid) {
-          if ($account->uid == $this->uid) return TRUE;
+          if ($account->uid == $this->uid) {
+            return TRUE;
+          }
         }
 
         // The 'Everyone' permission.
-        if ($key == 'all') return TRUE;
+        if ($key == 'all') {
+          return TRUE;
+        }
 
         // Any user with a named permission.
         if (substr($key, 0, 11) == 'permission:') {
-          if (user_access(substr($key, 11), $account)) return TRUE;
+          if (user_access(substr($key, 11), $account)) {
+            return TRUE;
+          }
         }
 
         // Any user with the defined role.
         if (substr($key, 0, 5) == 'role:') {
-          if (isset($account->roles[substr($key, 5)])) return TRUE;
+          if (isset($account->roles[substr($key, 5)])) {
+            return TRUE;
+          }
         }
       }
     }
@@ -386,7 +440,7 @@ class pay {
    */
   function drupal_invoke($hook, $values = array()) {
     foreach (module_implements($hook) as $name) {
-      $func = $name .'_'. $hook;
+      $func = $name . '_' . $hook;
       $func($this, $values);
     }
   }
diff --git includes/handlers/pay_activity.inc includes/handlers/pay_activity.inc
index 142cc77..1e41839 100644
--- includes/handlers/pay_activity.inc
+++ includes/handlers/pay_activity.inc
@@ -46,7 +46,7 @@ class pay_activity extends pay {
    * Set the $data value, which is stored as a serialized value in the database.
    */
   function set_data($value = NULL) {
-    if(!empty($value) && is_scalar($value)) {
+    if (!empty($value) && is_scalar($value)) {
       $this->data = unserialize($value);
     }
     else {
@@ -97,10 +97,10 @@ class pay_activity extends pay {
    * The transaction balance as of this payment's completion.
    */
   function balance() {
-    return (float) db_result(db_query("SELECT t.total - SUM(a.transaction_total)
+    return (float) db_query("SELECT t.total - SUM(a.transaction_total)
       FROM {pay_activity} a
       INNER JOIN {pay_transaction} t USING (pxid)
-      WHERE t.pxid = %d AND a.paid <= %d", $this->pxid, $this->paid));
+      WHERE t.pxid = :t.pxid AND a.paid <= :a.paid", array(':t.pxid' => $this->pxid, ':a.paid' => $this->paid))->fetchField();
   }
 
   /**
diff --git includes/handlers/pay_form.inc includes/handlers/pay_form.inc
index 324e2c2..b15d63d 100644
--- includes/handlers/pay_form.inc
+++ includes/handlers/pay_form.inc
@@ -20,7 +20,7 @@ class pay_form extends pay {
   var $currency;
   var $pay_methods = array();
   var $notes_title = 'Comments';
-  var $notes_format = FILTER_FORMAT_DEFAULT;
+  var $notes_format = NULL;
   var $notes_description = '';
 
   var $user_register = FALSE;
@@ -32,10 +32,17 @@ class pay_form extends pay {
     return check_plain($this->title);
   }
 
+  function set_notes_format() {
+    $this->notes_format = filter_fallback_format();
+    return $this->notes_format;
+  }
+
   function set_transaction($values) {
     module_load_include('inc', 'pay', 'includes/handlers/pay_transaction');
     $this->transaction = New pay_transaction($values);
-    if (!$this->transaction->pfid) $this->transaction->pfid = $this->pfid;
+    if (!$this->transaction->pfid) {
+      $this->transaction->pfid = $this->pfid;
+    }
     $this->transaction->save($values);
     return $this->transaction;
   }
@@ -50,7 +57,7 @@ class pay_form extends pay {
    *  as needed.
    */
   function set_valid_actions($pay_transaction, &$actions) {
-    foreach($this->pay_methods() as $pay_method) {
+    foreach ($this->pay_methods() as $pay_method) {
       $pay_method->set_valid_actions($this, $actions);
     }
   }
@@ -71,9 +78,10 @@ class pay_form extends pay {
       // set this variable and deal with the conversion fallout responsibly.
       if (variable_get('pay_currency_multiple', FALSE)) {
         foreach ($this->pay_methods() as $method) {
-          foreach ($method->available_currencies() as $currency)
-          if (!isset($this->currency_list[$currency])) {
-            $this->currency_list[$currency] = $currency;
+          foreach ($method->available_currencies() as $currency) {
+            if (!isset($this->currency_list[$currency])) {
+              $this->currency_list[$currency] = $currency;
+            }
           }
         }
       }
@@ -93,14 +101,20 @@ class pay_form extends pay {
   }
 
   function currency() {
-    if (!isset($this->currency)) $this->set_currency();
+    if (!isset($this->currency)) {
+      $this->set_currency();
+    }
     return $this->currency;
   }
 
   function user_register() {
     global $user;
-    if ($user->uid) return FALSE;
-    if ($this->user_register == 'none') return FALSE;
+    if ($user->uid) {
+      return FALSE;
+    }
+    if ($this->user_register == 'none') {
+      return FALSE;
+    }
     return $this->user_register;
   }
 
@@ -113,10 +127,14 @@ class pay_form extends pay {
     }
   }
 
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_method_list() {
     $list = array();
-    $res = db_query("SELECT * FROM {pay_method} WHERE STATUS = 1 ORDER BY title");
-    while ($row = db_fetch_object($res)) {
+    $result = db_query("SELECT * FROM {pay_method} WHERE STATUS = 1 ORDER BY title");
+    while ($row = $result->fetchObject()) {
       $list[$row->pmid] = $row->title;
     }
     return $list;
@@ -141,7 +159,7 @@ class pay_form extends pay {
         '#title' => t('Title'),
         '#default_value' => $this->title,
         '#required' => TRUE,
-        '#description' => t('This title will appear as the title of the form page and in listings.')
+        '#description' => t('This title will appear as the title of the form page and in listings.'),
       );
     }
 
@@ -172,20 +190,24 @@ class pay_form extends pay {
     /**
      * @todo Disable this until it's ready for prime time.
      *
-    $form[$group]['user_register'] = array(
-      '#type' => 'radios',
-      '#title' => t('Provide a user registration form'),
-      '#description' => t('Allow users to register or login while making a payment.'),
-      '#options' => array(
-        'none' => t('No: Transactions will be recorded anonymously.'),
-        'optional' => t('Optional: If users do not register or login, their transaction will be recorded anonymously.'),
-        'required' => t('Required: Users must register or login and payments will be associated with their account.'),
-      ),
-      '#default_value' => $this->user_register,
-    );
-    */
+     $form[$group]['user_register'] = array(
+     '#type' => 'radios',
+     '#title' => t('Provide a user registration form'),
+     '#description' => t('Allow users to register or login while making a payment.'),
+     '#options' => array(
+     'none' => t('No: Transactions will be recorded anonymously.'),
+     'optional' => t('Optional: If users do not register or login, their transaction will be recorded anonymously.'),
+     'required' => t('Required: Users must register or login and payments will be associated with their account.'),
+     ),
+     '#default_value' => $this->user_register,
+     );
+     */
   }
 
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_methods() {
     $methods = array();
     foreach ($this->pay_methods as $pmid => $status) {
@@ -199,6 +221,10 @@ class pay_form extends pay {
     return $methods;
   }
 
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_method_form(&$form, &$form_state) {
     $group = $this->handler();
     $methods = $this->pay_methods();
@@ -212,7 +238,7 @@ class pay_form extends pay {
       // Make sure each payment method has a total.
       if (!isset($form[$group]['pay_method'][$pmid]['total'])) {
         $form[$group]['pay_method'][$pmid]['total'] = array(
-          '#type'  => 'value',
+          '#type' => 'value',
           '#value' => 0.00,
         );
       }
@@ -293,7 +319,9 @@ class pay_form extends pay {
         }
 
         // Keep track of any visible elements.
-        if ($form[$group][$key]['#access'] !== FALSE) $visible[] = $key;
+        if ($form[$group][$key]['#access'] !== FALSE) {
+          $visible[] = $key;
+        }
 
         // Change the 'action' to the ultimate destination for the form.
         $form['#action'] = url($this->menu_path());
@@ -338,12 +366,14 @@ class pay_form extends pay {
 
     // If there is no total value per payment method, set the global total.
     foreach ($values['pay_method']['selected'] as $pmid => $status) {
-      if (!$status) continue;
+      if (!$status) {
+        continue;
+      }
       $method_values = $values['pay_method'][$pmid];
       $method_values['pmid'] = $pmid;
       $method_element = $form[$group]['pay_method'][$pmid];
       if (!$method_values['total']) {
-        form_set_value($method_element['total'], (float)$total, $form_state);
+        form_set_value($method_element['total'], (float) $total, $form_state);
         $method_values['total'] = $total;
       }
       $pay_method = pay_method_load($method_values);
@@ -382,10 +412,14 @@ class pay_form extends pay {
 
     // Run payment activities for the 1 or more selected payment methods.
     $selected = $values['pay_method']['selected'];
-    if (!is_array($selected)) $selected = array($selected => 1);
+    if (!is_array($selected)) {
+      $selected = array($selected => 1);
+    }
 
     foreach ($selected as $pmid => $status) {
-      if (!$status) continue;
+      if (!$status) {
+        continue;
+      }
       $method_values = $values['pay_method'][$pmid];
       $method_values['pmid'] = $pmid;
       $pay_method = pay_method_load($method_values);
@@ -420,11 +454,11 @@ class pay_form extends pay {
   }
 
   function total() {
-    return (float) db_result(db_query("SELECT SUM(total) as total FROM {pay_transaction} WHERE pfid = %d", $this->pfid));
+    return (float) db_query("SELECT SUM(total) as total FROM {pay_transaction} WHERE pfid = :pfid", array(':pfid' => $this->pfid))->fetchField();
   }
 
   function total_paid() {
-    return (float) db_result(db_query("SELECT SUM(total_paid) as total FROM {pay_transaction} WHERE pfid = %d", $this->pfid));
+    return (float) db_query("SELECT SUM(total_paid) as total FROM {pay_transaction} WHERE pfid = :pfid", array(':pfid' => $this->pfid))->fetchField();
   }
 
   function total_goal() {
@@ -432,6 +466,6 @@ class pay_form extends pay {
   }
 
   function transaction_count() {
-    return (int) db_result(db_query("SELECT COUNT(*) FROM {pay_transaction} WHERE pfid = %d", $this->pfid));
+    return (int) db_query("SELECT COUNT(*) FROM {pay_transaction} WHERE pfid = :pfid", array(':pfid' => $this->pfid))->fetchField();
   }
 }
diff --git includes/handlers/pay_item.inc includes/handlers/pay_item.inc
index 574f65c..8a0ad32 100644
--- includes/handlers/pay_item.inc
+++ includes/handlers/pay_item.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
diff --git includes/handlers/pay_method.inc includes/handlers/pay_method.inc
index 662b51f..e77e21a 100644
--- includes/handlers/pay_method.inc
+++ includes/handlers/pay_method.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -42,7 +43,7 @@ class pay_method extends pay {
    *  An array of default actions, passed by reference. Modify or augment this
    *  as needed.
    */
-  function set_valid_actions($pay_form, &$actions) {}
+  function set_valid_actions($pay_form, &$actions) { }
 
   /**
    * Determine whether an action is valid and appropraite for a transaction.
@@ -94,7 +95,9 @@ class pay_method extends pay {
     }
     else {
       $info = pay_handlers('pay_method', $this->handler());
-      $this->title = $info['title'];
+      if (!empty($info['title'])) {
+        $this->title = $info['title'];
+      }
     }
   }
 
@@ -107,7 +110,9 @@ class pay_method extends pay {
     }
     else {
       $info = pay_handlers('pay_method', $this->handler());
-      $this->description = $info['description'];
+      if (!empty($info['description'])) {
+        $this->description = $info['description'];
+      }
     }
   }
 
@@ -155,6 +160,10 @@ class pay_method extends pay {
   }
 
   // This is called from the form_validate function in a pay_form class.
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_method_validate($form, &$form_state, $element) {
 
     // Confirm that the amount falls within our min/max settings.
diff --git includes/handlers/pay_method_direct.inc includes/handlers/pay_method_direct.inc
index 74c3e3d..1879358 100644
--- includes/handlers/pay_method_direct.inc
+++ includes/handlers/pay_method_direct.inc
@@ -12,16 +12,14 @@ class pay_method_direct extends pay_method {
    * This method will be called when the user needs to be sent to the gateway
    * provider for processing.  Override it to include valid request values.
    */
-  function direct_request() {
-  }
+  function direct_request() { }
 
   /**
    * This method will be called on a return response (e.g. PayPal IPN)
    * including an unfiltered version of the $_REQUEST array.  This method must
    * be extended in order for your direct method to work!
    */
-  function direct_response($response = array()) {
-  }
+  function direct_response($response = array()) { }
 
   /**
    * Augment the available payment actions for transactions that include
@@ -117,33 +115,33 @@ class pay_method_direct extends pay_method {
     }
     $method_form = array();
     $method_form['first_name'] = array(
-      '#type'       => 'textfield',
-      '#title'      => t('First name'),
-      '#required'   => TRUE,
+      '#type' => 'textfield',
+      '#title' => t('First name'),
+      '#required' => TRUE,
     );
     $method_form['last_name'] = array(
-      '#type'       => 'textfield',
-      '#title'      => t('Last name'),
-      '#required'   => TRUE,
+      '#type' => 'textfield',
+      '#title' => t('Last name'),
+      '#required' => TRUE,
     );
     if ($user->uid) {
       $method_form['mail'] = array(
-        '#type'       => 'value',
-        '#value'      => $user->mail,
+        '#type' => 'value',
+        '#value' => $user->mail,
       );
     }
     else {
       $method_form['mail'] = array(
-        '#type'       => 'textfield',
-        '#title'      => t('E-mail'),
-        '#required'   => TRUE,
+        '#type' => 'textfield',
+        '#title' => t('E-mail'),
+        '#required' => TRUE,
       );
     }
     $method_form['billto'] = array(
-      '#type'       => 'postal',
+      '#type' => 'postal',
       '#postal_user' => $user,
-      '#title'      => t('Billing address'),
-      '#required'   => TRUE,
+      '#title' => t('Billing address'),
+      '#required' => TRUE,
     );
 
     // Add this method_form to the expected place on the parent form.
diff --git includes/handlers/pay_method_gateway.inc includes/handlers/pay_method_gateway.inc
index 5d036c2..0bb1906 100644
--- includes/handlers/pay_method_gateway.inc
+++ includes/handlers/pay_method_gateway.inc
@@ -65,7 +65,9 @@ class pay_method_gateway extends pay_method {
     $result = $this->execute($this->activity);
 
     // If successful, increase the 'captured' balance.
-    if ($result) $this->activity->set_transaction_total($this->activity->total);
+    if ($result) {
+      $this->activity->set_transaction_total($this->activity->total);
+    }
 
     // If the transaction's state is 'pending', this is an auth_capture
     // action. We don't have enough to complete it, so return a failed state.
@@ -83,8 +85,7 @@ class pay_method_gateway extends pay_method {
   /**
    * Refund a transaction.
    */
-  function refund_action() {
-  }
+  function refund_action() { }
 
   /**
    * Cancel a transaction.
@@ -100,7 +101,7 @@ class pay_method_gateway extends pay_method {
    * Returning NULL prevents anything from executing. Subclasses are responsible
    * for returning a responsible url.
    */
-  function gateway_url() {}
+  function gateway_url() { }
 
   /**
    * The request data that will be sent to your gatway provider.
@@ -108,7 +109,7 @@ class pay_method_gateway extends pay_method {
    * Returning NULL prevents anything from executing. Subclasses are responsible
    * for returning responsible request data.
    */
-  function gateway_request() {}
+  function gateway_request() { }
 
   /**
    * HTTP headers that should be sent to the gateway provider.
@@ -123,13 +124,14 @@ class pay_method_gateway extends pay_method {
     return array();
   }
 
-  function gateway_response() {}
+  function gateway_response() { }
 
   function execute($activity) {
     if ($request = $this->gateway_request()) {
-      $ret = drupal_http_request($this->gateway_url(), $this->gateway_headers(), 'POST', $request);
-      if ($ret->error) {
+      $ret = drupal_http_request($this->gateway_url(), array('headers' => $this->gateway_headers(), 'method' => 'POST', 'data' => $request));
+      if (isset($ret->error)) {
         watchdog('payment', "Gateway Error: @err Payment NOT processed.", array('@err' => $ret->error));
+        drupal_set_message(t('We were unable to process your credit card payment. Please verify your card details and try again. If the problem persists, contact us to complete your order.'), 'error');
         $this->activity->data = (array) $ret;
         $this->activity->result = FALSE;
       }
@@ -186,65 +188,99 @@ class pay_method_gateway extends pay_method {
     $prefix5 = substr($this->cc_number, 0, 5);
     $prefix6 = substr($this->cc_number, 0, 6);
 
-   /**
-    * References: http://www.beachnet.com/~hstiles/cardtype.html
-    */
+    /**
+     * References: http://www.beachnet.com/~hstiles/cardtype.html
+     */
     switch ($prefix1) {
       case 1:
         // JCB: prefix 1800, length 15
-        if ($prefix4 == 1800) $this->cc_type = 'jcb';
+        if ($prefix4 == 1800) {
+          $this->cc_type = 'jcb';
+        }
         break;
 
       case 2:
         // JCB: prefix 2131, length 15
-        if ($prefix4 == 2131) $this->cc_type = 'jcb';
+        if ($prefix4 == 2131) {
+          $this->cc_type = 'jcb';
+        }
 
         // enRoute: prefix 2014, 2149 length 15
-        elseif ($prefix4 == 2014) $this->cc_type = 'enroute';
-        elseif ($prefix4 == 2149) $this->cc_type = 'enroute';
+        elseif ($prefix4 == 2014) {
+          $this->cc_type = 'enroute';
+        }
+        elseif ($prefix4 == 2149) {
+          $this->cc_type = 'enroute';
+        }
         break;
 
       case 3:
         // Diners Club: prefix 300-305, length 14
-        if (in_array($prefix3, array(300, 301, 302, 303, 304, 305))) $this->cc_type = 'diners';
+        if (in_array($prefix3, array(300, 301, 302, 303, 304, 305))) {
+          $this->cc_type = 'diners';
+        }
 
         // AmEX: prefix 34, 37, length 15
-        elseif (in_array($prefix2, array(34, 37))) $this->cc_type = 'amex';
+        elseif (in_array($prefix2, array(34, 37))) {
+          $this->cc_type = 'amex';
+        }
 
         // Diners Club: prefix 36, 38, length 14
-        elseif (in_array($prefix2, array(36, 38))) $this->cc_type = 'diners';
+        elseif (in_array($prefix2, array(36, 38))) {
+          $this->cc_type = 'diners';
+        }
 
         // JCB: prefix 3, length 16
-        else $this->cc_type = 'jcb';
+        else {
+          $this->cc_type = 'jcb';
+        }
         break;
 
       case 4:
         // Visa: prefix 4, length 13, 16
         $this->cc_type = 'visa';
         // Switch: prefix 4903, 4905, 4911, 4936
-        if (in_array($prefix4, array(4903, 4905, 4911, 4936))) $this->cc_type = 'switch';
+        if (in_array($prefix4, array(4903, 4905, 4911, 4936))) {
+          $this->cc_type = 'switch';
+        }
         break;
 
       case 5:
         // Mastercard: prefix 51-55, length 16
-        if (in_array($prefix2, array(51, 52, 53, 54, 55))) $this->cc_type = 'mc';
+        if (in_array($prefix2, array(51, 52, 53, 54, 55))) {
+          $this->cc_type = 'mc';
+        }
         // Switch: prefix 564182
-        if ($prefix6 == 564182) $this->cc_type = 'switch';
+        if ($prefix6 == 564182) {
+          $this->cc_type = 'switch';
+        }
         // Maestro: prefix 5018, 5020, 5038
-        if (in_array($prefix4, array(5018, 5020, 5038))) $this->cc_type = 'maestro';
+        if (in_array($prefix4, array(5018, 5020, 5038))) {
+          $this->cc_type = 'maestro';
+        }
         break;
 
       case 6:
         // Discover: prefix 6011, length 16
-        if ($prefix4 == 6011) $this->cc_type = 'discover';
+        if ($prefix4 == 6011) {
+          $this->cc_type = 'discover';
+        }
         // Laser: prefix 6304 or 6706 or 6709 or 6771, length 19
-        if ($prefix4 == 6304 || $prefix4 == 6706 || $prefix4 == 6709 || $prefix4 == 6771) $this->cc_type = 'laser';
+        if ($prefix4 == 6304 || $prefix4 == 6706 || $prefix4 == 6709 || $prefix4 == 6771) {
+          $this->cc_type = 'laser';
+        }
         // Switch: prefix 633110, 6333, 6759,
-        if ($prefix6 == 633110 || $prefix4 == 6333) $this->cc_type = 'switch';
+        if ($prefix6 == 633110 || $prefix4 == 6333) {
+          $this->cc_type = 'switch';
+        }
         // Maestro: prefix 6759, 6761, 6763
-        if (in_array($prefix4, array(6759, 6761, 6763))) $this->cc_type = 'maestro';
+        if (in_array($prefix4, array(6759, 6761, 6763))) {
+          $this->cc_type = 'maestro';
+        }
         // Solo: prefix 6334 or 6767
-        if ($prefix4 == 6334 || $prefix4 == 6767) $this->cc_type = 'solo';
+        if ($prefix4 == 6334 || $prefix4 == 6767) {
+          $this->cc_type = 'solo';
+        }
         break;
     }
     // Only if we still fail to determine card type, reset it to user supplied
@@ -259,6 +295,7 @@ class pay_method_gateway extends pay_method {
   }
 
   function cc_number_validate() {
+    $total = 0;
     $number = $this->cc_number;
 
     if ((strlen($number) < 13) || (strlen($number) > 19)) {
@@ -297,7 +334,7 @@ class pay_method_gateway extends pay_method {
   }
 
   function cc_issue_number_validate() {
-    if ($this->cc_issue_number_required($this->cc_type) && (strlen($this->cc_issue_number) != 2|| !is_numeric($this->cc_issue_number))) {
+    if ($this->cc_issue_number_required($this->cc_type) && (strlen($this->cc_issue_number) != 2 || !is_numeric($this->cc_issue_number))) {
       $this->error_message = t('Invalid issue number.');
       return FALSE;
     }
@@ -326,7 +363,7 @@ class pay_method_gateway extends pay_method {
     if ($this->gateway_supports_cc) {
       $payment_types = array(
         'visa' => t('Visa'),
-        'mc'   => t('Mastercard'),
+        'mc' => t('Mastercard'),
         'amex' => t('American Express'),
         'discover' => t('Discover'),
         'diners' => t("Diner's Club"),
@@ -345,7 +382,9 @@ class pay_method_gateway extends pay_method {
 
     if ($filter) {
       foreach ($payment_types as $key => $label) {
-        if (!$filter[$key]) unset($payment_types[$key]);
+        if (!$filter[$key]) {
+          unset($payment_types[$key]);
+        }
       }
     }
     return $payment_types;
@@ -391,73 +430,75 @@ class pay_method_gateway extends pay_method {
     $method_form['#theme'] = 'pay_cc_form';
 
     $options = array();
-    if ($this->gateway_supports_cc) $options['cc'] = t('Credit or debit card');
+    if ($this->gateway_supports_cc) {
+      $options['cc'] = t('Credit or debit card');
+    }
     // TODO should reflect 'bank account' input here, but it's unsupported.
 
     $method_form['payment_type'] = array(
-      '#type'       => 'select',
-      '#title'      => t('Payment type'),
-      '#options'    => $options,
-      '#required'   => TRUE,
+      '#type' => 'select',
+      '#title' => t('Payment type'),
+      '#options' => $options,
+      '#required' => TRUE,
       '#default_value' => 'cc',
-      '#access'     => count($options) > 1,
+      '#access' => count($options) > 1,
     );
 
     $method_form['first_name'] = array(
-      '#type'       => 'textfield',
-      '#title'      => t('First name'),
+      '#type' => 'textfield',
+      '#title' => t('First name'),
       '#pre_render' => array('pay_element_set_required'),
     );
     $method_form['last_name'] = array(
-      '#type'       => 'textfield',
-      '#title'      => t('Last name'),
+      '#type' => 'textfield',
+      '#title' => t('Last name'),
       '#pre_render' => array('pay_element_set_required'),
     );
     if ($user->uid) {
       $method_form['mail'] = array(
-        '#type'       => 'value',
-        '#value'      => $user->mail,
+        '#type' => 'value',
+        '#value' => $user->mail,
       );
     }
     else {
       $method_form['mail'] = array(
-        '#type'       => 'textfield',
-        '#title'      => t('E-mail'),
+        '#type' => 'textfield',
+        '#title' => t('E-mail'),
         '#pre_render' => array('pay_element_set_required'),
       );
     }
     $method_form['billto'] = array(
-      '#type'       => 'postal',
+      '#type' => 'postal',
       '#postal_user' => $user,
-      '#title'      => t('Billing address'),
+      '#title' => t('Billing address'),
       '#pre_render' => array('pay_element_set_required'),
     );
     $method_form['cc_type'] = array(
-      '#type'       => 'radios',
-      '#title'      => t('Card type'),
-      '#options'    => $this->payment_types($this->payment_types),
+      '#type' => 'radios',
+      '#title' => t('Card type'),
+      '#options' => $this->payment_types($this->payment_types),
     );
     $method_form['cc_number'] = array(
-      '#type'        => 'textfield',
-      '#title'      => t('Card number'),
-      '#size'        => 19,
-      '#maxlength'  => 19,
+      '#type' => 'textfield',
+      '#title' => t('Card number'),
+      '#size' => 19,
+      '#maxlength' => 19,
       '#pre_render' => array('pay_element_set_required'),
       '#attributes' => array('autocomplete' => 'off'),
     );
     $method_form['cc_ccv2'] = array(
-      '#type'        => 'textfield',
-      '#title'      => t('Security code'),
-      '#size'        => 4,
-      '#maxlength'  => 4,
+      '#type' => 'textfield',
+      '#title' => t('Security code'),
+      '#size' => 4,
+      '#maxlength' => 4,
       '#attributes' => array('autocomplete' => 'off'),
     );
     if ($this->cc_issue_number_required()) {
       $method_form['cc_issue_number'] = array(
-        '#type'       => 'textfield',
-        '#title'      => t('Issue number'),
-        '#size'       => 2,
-        '#maxlength'  => 2,
+        '#type' => 'textfield',
+        '#title' => t('Issue number'),
+        '#size' => 2,
+        '#maxlength' => 2,
         '#attributes' => array('autocomplete' => 'off'),
       );
     }
@@ -465,11 +506,11 @@ class pay_method_gateway extends pay_method {
     $months = array();
     foreach (range(1, 12) as $i) {
       $key = str_pad($i, 2, '0', STR_PAD_LEFT);
-      $months[$key] = $key .'- '. date('F', strtotime('1-'. $i .'-2000'));
+      $months[$key] = $key . '- ' . date('F', strtotime('1-' . $i . '-2000'));
     }
     $method_form['cc_exp_month'] = array(
-      '#type'       => 'select',
-      '#options'    => $months,
+      '#type' => 'select',
+      '#options' => $months,
       '#pre_render' => array('pay_element_set_required'),
       '#attributes' => array('title' => t('Expiration month')),
     );
@@ -480,8 +521,8 @@ class pay_method_gateway extends pay_method {
       $years[substr($year, 2)] = $year;
     }
     $method_form['cc_exp_year'] = array(
-      '#type'       => 'select',
-      '#options'    => $years,
+      '#type' => 'select',
+      '#options' => $years,
       '#pre_render' => array('pay_element_set_required'),
       '#attributes' => array('title' => t('Expiration year')),
     );
@@ -493,6 +534,10 @@ class pay_method_gateway extends pay_method {
   }
 
   // This is called from the form_validate function in a pay_form class.
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_method_validate($form, &$form_state, $element) {
     parent::pay_method_validate($form, $form_state, $element);
 
@@ -509,7 +554,7 @@ class pay_method_gateway extends pay_method {
       );
 
       foreach ($required as $key) {
-        if (!count($this->$key) || (is_string($this->$key) && strlen(trim($this->$key)) == 0)) {
+        if ((!count($this->$key) || (is_string($this->$key) && strlen(trim($this->$key)) == 0)) && isset($element[$key])) {
           form_error($element[$key], t('!name field is required.', array('!name' => $element[$key]['#title'])));
         }
       }
diff --git includes/handlers/pay_transaction.inc includes/handlers/pay_transaction.inc
index d5015f5..5192778 100644
--- includes/handlers/pay_transaction.inc
+++ includes/handlers/pay_transaction.inc
@@ -16,7 +16,7 @@ class pay_transaction extends pay {
   var $total_paid;
   var $currency;
   var $notes;
-  var $notes_format = FILTER_FORMAT_DEFAULT;
+  var $notes_format = NULL;
   var $mail;
   var $title;
 
@@ -52,7 +52,9 @@ class pay_transaction extends pay {
         'description' => t('The transaction has been refunded.'),
       ),
     );
-    if ($state) return $states[$state];
+    if ($state) {
+      return $states[$state];
+    }
     return $states;
   }
 
@@ -60,20 +62,31 @@ class pay_transaction extends pay {
    * Set the state of this transaction.
    */
   function set_state($state = 'pending') {
-    if (array_key_exists($state, $this->states())) $this->state = $state;
+    if (array_key_exists($state, $this->states())) {
+      $this->state = $state;
+    }
+  }
+
+  function set_notes_format() {
+    $this->notes_format = filter_fallback_format();
+    return $this->notes_format;
   }
 
   /**
    * Return the current state of this transaction.
    */
   function state($title = FALSE) {
-    if (!$this->state) $this->set_state();
+    if (!$this->state) {
+      $this->set_state();
+    }
 
     if ($title) {
       $info = $this->states($this->state);
       return $info['title'];
     }
-    else return $this->state;
+    else {
+      return $this->state;
+    }
   }
 
   /**
@@ -88,30 +101,30 @@ class pay_transaction extends pay {
   function valid_actions($name = NULL) {
     // Create a default list of potential payment actions.
     $actions = array(
-     'authorize' => array(
-       'title' => t('Authorize'),
-       'callback' => 'authorize_action',
-       'valid states' => array('pending'),
+      'authorize' => array(
+        'title' => t('Authorize'),
+        'callback' => 'authorize_action',
+        'valid states' => array('pending'),
       ),
-      'complete'  => array(
+      'complete' => array(
         'title' => t('Complete'),
         'message' => t('Transaction completed'),
         'callback' => 'complete_action',
         'valid states' => array('pending', 'active'),
       ),
-      'cancel'      => array(
+      'cancel' => array(
         'title' => t('Cancel'),
         'message' => t('Transaction cancelled'),
         'callback' => 'cancel_action',
         'valid states' => array('pending', 'active'),
       ),
-      'refund'      => array(
+      'refund' => array(
         'title' => t('Refund'),
         'message' => t('Transaction has been refunded'),
         'callback' => 'refund_action',
         'valid states' => array('complete'),
       ),
-      'delete'      => array(
+      'delete' => array(
         'title' => t('Delete'),
         'message' => t('Transaction has been deleted'),
       ),
@@ -121,7 +134,9 @@ class pay_transaction extends pay {
     // The pay_form handler also calls set_valid_actions for each pay_method.
     $this->pay_form()->set_valid_actions($this, $actions);
 
-    if ($name) return $actions[$name];
+    if ($name) {
+      return $actions[$name];
+    }
     return $actions;
   }
 
@@ -134,7 +149,9 @@ class pay_transaction extends pay {
   function available_actions() {
     $actions = $this->valid_actions();
     foreach ($actions as $action => $info) {
-      if (!$this->valid_action($action)) unset($actions[$action]);
+      if (!$this->valid_action($action)) {
+        unset($actions[$action]);
+      }
     }
     return $actions;
   }
@@ -146,18 +163,26 @@ class pay_transaction extends pay {
     $valid = TRUE;
 
     // Special-case 'delete' pseudo-action.
-    if ($action == 'delete') return user_access('administer pay');
+    if ($action == 'delete') {
+      return user_access('administer pay');
+    }
 
     // Is it defined in our list of valid_actions?
-    if (!$info = $this->valid_actions($action)) return FALSE;
+    if (!$info = $this->valid_actions($action)) {
+      return FALSE;
+    }
 
     // Is the current workflow state compatible with this action?
-    if (!in_array($this->state(), $info['valid states'])) return FALSE;
+    if (!in_array($this->state(), $info['valid states'])) {
+      return FALSE;
+    }
 
     // Query each payment method in this transaction's history for validity.
     foreach ($this->pay_method_activities() as $pmid => $history) {
       $pay_method = pay_method_load($pmid);
-      if (!method_exists($pay_method, $info['callback'])) $valid = FALSE;
+      if (!method_exists($pay_method, $info['callback'])) {
+        $valid = FALSE;
+      }
       $valid = $valid && $pay_method->valid_action($action, $this, $history);
     }
 
@@ -190,13 +215,15 @@ class pay_transaction extends pay {
 
   function set_title($value = NULL) {
     // This is likely a dummy transaction.
-    if (!$this->pay_form()) return;
+    if (!$this->pay_form()) {
+      return;
+    }
 
     if (!$value) {
       $values = array(
         '@form' => $this->pay_form()->title(),
-        '!name' => theme('username', $this->user()->name),
-        '!date' => format_date($this->created, 'small'),
+        '!name' => theme('username', array('account' => $this->user()->name)),
+        '!date' => format_date($this->created, 'short'),
       );
       $value = t('Payment for "@form" by !name on !date', $values);
     }
@@ -220,7 +247,9 @@ class pay_transaction extends pay {
   }
 
   function currency() {
-    if (!($this->currency)) $this->set_currency();
+    if (!($this->currency)) {
+      $this->set_currency();
+    }
     return $this->currency;
   }
 
@@ -235,10 +264,12 @@ class pay_transaction extends pay {
   }
 
   function update_status($state = NULL, $timestamp = NULL) {
-    if (!$timestamp) $timestamp = time();
+    if (!$timestamp) {
+      $timestamp = REQUEST_TIME;
+    }
 
-    $this->total_paid = db_result(db_query("SELECT SUM(transaction_total)
-      FROM {pay_activity} WHERE pxid = %d", $this->pxid));
+    $this->total_paid = db_query("SELECT SUM(transaction_total)
+      FROM {pay_activity} WHERE pxid = :pxid", array(':pxid' => $this->pxid))->fetchField();
 
     if ($state == 'complete') {
       // Payment has in fact been completed.
@@ -263,10 +294,10 @@ class pay_transaction extends pay {
   function activity() {
     if (!isset($this->activity)) {
       $this->activity = array();
-      $res = db_query("SELECT paid FROM {pay_activity} WHERE pxid = %d
-        ORDER BY paid", $this->pxid);
-      while ($paid = db_result($res)) {
-        $this->activity[$paid] = pay_load('pay_activity', $paid);
+      $res = db_query("SELECT paid FROM {pay_activity} WHERE pxid = :pxid
+        ORDER BY paid", array(':pxid' => $this->pxid));
+      while ($paid = $res->fetchField()) {
+        $this->activity[$paid] = pay_load_object('pay_activity', $paid);
       }
     }
     return $this->activity;
@@ -280,10 +311,18 @@ class pay_transaction extends pay {
     $this->drupal_invoke('pay_transaction_delete');
 
     // Delete any activities associated with this transaction.
-    db_query("DELETE FROM {pay_activity} WHERE pxid = %d", $this->pxid);
+    // TODO Please review the conversion of this statement to the D7 database API syntax.
+    /* db_query("DELETE FROM {pay_activity} WHERE pxid = %d", $this->pxid) */
+    db_delete('pay_activity')
+  ->condition('pxid', $this->pxid)
+  ->execute();
 
     // Delete this transaction from the database.
-    db_query("DELETE FROM {pay_transaction} WHERE pxid = %d", $this->pxid);
+    // TODO Please review the conversion of this statement to the D7 database API syntax.
+    /* db_query("DELETE FROM {pay_transaction} WHERE pxid = %d", $this->pxid) */
+    db_delete('pay_transaction')
+  ->condition('pxid', $this->pxid)
+  ->execute();
 
     return TRUE;
   }
@@ -297,7 +336,9 @@ class pay_transaction extends pay {
     foreach ($this->activity() as $activity) {
       $activities[$activity->pmid][$activity->paid] = $activity;
     }
-    if ($pmid) return $activities[$pmid];
+    if ($pmid) {
+      return $activities[$pmid];
+    }
     return $activities;
   }
 }
diff --git includes/pay.action.inc includes/pay.action.inc
index 16a65f5..249e01a 100644
--- includes/pay.action.inc
+++ includes/pay.action.inc
@@ -11,28 +11,28 @@
  */
 function pay_action_info() {
   $hooks = array();
-  if (function_exists('pay_hook_info')) {
-    $hooks = pay_hook_info();
+  if (function_exists('pay_trigger_info')) {
+    $hooks = pay_trigger_info();
     $hooks = $hooks['pay'];
   }
   $return = array(
     'pay_transaction_complete_action' => array(
       'type' => 'pay_transaction',
-      'description' => t('Complete transaction'),
+      'label' => t('Complete transaction'),
       'configurable' => FALSE,
-      'hooks' => $hooks,
+      'triggers' => $hooks,
     ),
     'pay_transaction_cancel_action' => array(
       'type' => 'pay_transaction',
-      'description' => t('Cancel transaction'),
+      'label' => t('Cancel transaction'),
       'configurable' => FALSE,
-      'hooks' => $hooks,
+      'triggers' => $hooks,
     ),
     'pay_transaction_delete_action' => array(
       'type' => 'pay_transaction',
-      'description' => t('Delete transaction'),
+      'label' => t('Delete transaction'),
       'configurable' => FALSE,
-      'hooks' => $hooks,
+      'triggers' => $hooks,
     ),
   );
   return $return;
diff --git includes/pay.admin.inc includes/pay.admin.inc
index ecf8250..648b109 100644
--- includes/pay.admin.inc
+++ includes/pay.admin.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -9,26 +10,34 @@
  * Payment settings overview.
  */
 function pay_admin_overview() {
-  $output = '';
+  $output = array();
 
-  $output .= drupal_get_form('pay_admin_settings');
+  $settings = drupal_get_form('pay_admin_settings');
+  $output['settings'] = $settings;
 
   $hdrs = array(t('Label'), t('Handler'), t('Operations'));
+  $row = array();
   $info = pay_handlers('pay_method');
   foreach (pay_form_load()->pay_method_list() as $pmid => $pay_method) {
-    if (!$pay_method = pay_method_load($pmid)) continue;
+    if (!$pay_method = pay_method_load($pmid)) {
+      continue;
+    }
     $rows[] = array(
       $pay_method->title(),
       $info[$pay_method->handler()]['title'],
-      l(t('edit'), 'admin/settings/pay/'. $pmid .'/edit'),
+      l(t('edit'), 'admin/config/pay/pay/' . $pmid . '/edit'),
     );
   }
-  if ($rows) {
-    $output .= '<h3>' . t('Payment methods') . '</h3>';
-    $output .= theme('table', $hdrs, $rows);
+  if (!empty($rows)) {
+    $header = '<h3>' . t('Payment methods') . '</h3>';
+    $table = theme('table', array('header' => $hdrs, 'rows' => $rows));
+    $output['header']['#markup'] = $header;
+    $output['table']['#markup'] = $table;
+    $output['settings'] = $settings;
+    $output['output'] = $settings . $header . $table;
   }
   else {
-    drupal_set_message(t('You need at least one payment method before you can accept payments on your site. You can add a payment method !add_url.', array('!add_url' => l(t('here'), 'admin/settings/pay/add'))), 'warning');
+    drupal_set_message(t('You need at least one payment method before you can accept payments on your site. You can add a payment method !add_url.', array('!add_url' => l(t('here'), 'admin/config/pay/add'))), 'warning');
   }
   return $output;
 }
@@ -36,7 +45,7 @@ function pay_admin_overview() {
 /**
  * Overall settings form for global payment options.
  */
-function pay_admin_settings(&$form_state) {
+function pay_admin_settings($form, &$form_state) {
   $list = array('' => t('Please select'));
   $list += pay_currency_list();
 
@@ -47,8 +56,8 @@ function pay_admin_settings(&$form_state) {
   // to have a different currency than others without support for conversion.
   $disabled = FALSE;
   if (!variable_get('pay_currency_multiple', FALSE)) {
-    $disabled = $disabled || db_result(db_query("SELECT count(1)
-      FROM {pay_transaction} WHERE currency IS NOT NULL AND currency != ''"));
+    $disabled = $disabled || db_query("SELECT count(1)
+      FROM {pay_transaction} WHERE currency IS NOT NULL AND currency != ''")->fetchField();
   }
 
   $form['pay_currency'] = array(
@@ -73,12 +82,19 @@ function pay_admin_settings_submit($form, &$form_state) {
   // No variable has been set yet, so this is the first time setting this value.
   // Set this default value on all pay_forms and pay_transactions.
   $currency = $form_state['values']['pay_currency'];
-  if (!$count = db_result(db_query("SELECT count(1)
-    FROM {pay_transaction}
-    WHERE currency IS NOT NULL AND currency NOT IN ('', '%s')", $currency))) {
+  if (!$count = db_query("SELECT count(1)
+    FROM {pay_transaction} WHERE currency IS NOT NULL AND currency NOT IN ('', :currency)", array(':currency' => $currency))->fetchField()) {
 
-    db_query("UPDATE {pay_form} SET currency = '%s'", $currency);
-    db_query("UPDATE {pay_transaction} SET currency = '%s'", $currency);
+    db_update('pay_form')
+      ->fields(array(
+          'currency' => $currency,
+        ))
+      ->execute();
+    db_update('pay_transaction')
+      ->fields(array(
+          'currency' => $currency,
+        ))
+      ->execute();
   }
 }
 
@@ -88,12 +104,30 @@ function pay_admin_settings_submit($form, &$form_state) {
 function pay_admin_pay_form_list($handler = NULL, $uid = NULL) {
 
   $hdrs = array(
-    array('data' => t('Title'), 'field' => 'Title'),
-    array('data' => t('Owner'), 'field' => 'uid'),
-    array('data' => t('Handler'), 'field' => 'handler'),
-    array('data' => t('Status'), 'field' => 'status'),
-    array('data' => t('Total'), 'field' => 'total'),
-    array('data' => t('Total paid'), 'field' => 'total_paid'),
+    array(
+      'data' => t('Title'),
+      'field' => 'Title',
+    ),
+    array(
+      'data' => t('Owner'),
+      'field' => 'uid',
+    ),
+    array(
+      'data' => t('Handler'),
+      'field' => 'handler',
+    ),
+    array(
+      'data' => t('Status'),
+      'field' => 'status',
+    ),
+    array(
+      'data' => t('Total'),
+      'field' => 'total',
+    ),
+    array(
+      'data' => t('Total paid'),
+      'field' => 'total_paid',
+    ),
     array(),
   );
 
@@ -112,11 +146,11 @@ function pay_admin_pay_form_list($handler = NULL, $uid = NULL) {
     }
     if ($subclasses) {
       $subclasses[] = $handler;
-      $subclasses = "'" . join("', '", $subclasses) ."'";
-      $sql .= " WHERE f.handler IN (". $subclasses .")";
+      $subclasses = "'" . join("', '", $subclasses) . "'";
+      $sql .= " WHERE f.handler IN (" . $subclasses . ")";
     }
     else {
-      $sql .= " WHERE f.handler = '". check_plain($handler) ."'";
+      $sql .= " WHERE f.handler = '" . check_plain($handler) . "'";
     }
     unset($hdrs[2]);
   }
@@ -131,31 +165,37 @@ function pay_admin_pay_form_list($handler = NULL, $uid = NULL) {
     $pay_form = pay_form_load($data);
     $row = array(
       $pay_form->menu_path() ? l($pay_form->title(), $pay_form->menu_path()) : $pay_form->title(),
-      theme('username', $pay_form->user()),
+      theme('username', array('account' => $pay_form->user())),
       $pay_form->handler_title(),
       $pay_form->status ? t('active') : t('disabled'),
       round($data->total),
       round($data->total_paid),
-      l(t('edit'), $path .'/'. $pay_form->pfid .'/edit', array('query' => 'destination='. $path)),
+      l(t('edit'), $path . '/' . $pay_form->pfid . '/edit', array('query' => 'destination=' . $path)),
     );
-    if ($handler) unset($row[2]);
+    if ($handler) {
+      unset($row[2]);
+    }
     $rows[] = $row;
   }
-  if (empty($rows)) $rows[] = array();
+  if (empty($rows)) {
+    $rows[] = array();
+  }
 
-  return theme('table', $hdrs, $rows);
+  return theme('table', array('header' => $hdrs, 'rows' => $rows));
 }
 
 /**
  * Admin form to create or update payment methods.
  */
-function pay_admin_method_form(&$form_state, $pay_method = NULL) {
+function pay_admin_method_form(&$form, $form_state, $pay_method = NULL) {
   if (isset($form_state['storage']['pay_method'])) {
     $pay_method = $form_state['storage']['pay_method'];
   }
   if ($pay_method) {
     $form = array();
-    if (!is_object($pay_method)) $pay_method = pay_method_load($pay_method);
+    if (!is_object($pay_method)) {
+      $pay_method = pay_method_load($pay_method);
+    }
     $pay_method->settings_form($form, $form_state);
     $pmid = isset($pay_method->pmid) ? $pay_method->pmid : get_class($pay_method);
     $form['#pay_method'] = $pmid;
@@ -165,8 +205,12 @@ function pay_admin_method_form(&$form_state, $pay_method = NULL) {
       '#type' => 'radios',
       '#title' => t('Payment handler'),
     );
+    $options = array();
     foreach (pay_handlers('pay_method') as $name => $info) {
-      if (!$info['title']) continue; // Exclude unnamed base classes.
+      if (empty($info['title'])) {
+        continue; // Exclude unnamed base classes.
+      }
+      $options[$name] = $name;
       $form['pay_method'][$name] = array(
         '#type' => 'radio',
         '#name' => 'pay_method',
@@ -175,6 +219,7 @@ function pay_admin_method_form(&$form_state, $pay_method = NULL) {
         '#return_value' => $name,
       );
     }
+    $form['pay_method']['#options'] = $options;
   }
 
   $form['submit'] = array(
@@ -182,6 +227,7 @@ function pay_admin_method_form(&$form_state, $pay_method = NULL) {
     '#value' => t('Save values'),
   );
 
+  // @TODO: check this still works.
   // Vertical tab-ify this form if vertical_tabs module is installed.
   $form['#pre_render'][] = 'vertical_tabs_form_pre_render';
   return $form;
@@ -191,9 +237,9 @@ function pay_admin_method_form(&$form_state, $pay_method = NULL) {
  * Submit handler for pay_method_settings.
  */
 function pay_admin_method_form_submit($form, &$form_state) {
-  if (!$form['#pay_method']) {
+  if (empty($form['#pay_method'])) {
     if ($form_state['values']['pay_method']) {
-      if (!count($form_state['storage'])) {
+      if (empty($form_state['storage'])) {
         $form_state['storage'] = $form_state['values'];
         $form_state['rebuild'] = TRUE;
         return;
@@ -201,13 +247,15 @@ function pay_admin_method_form_submit($form, &$form_state) {
     }
   }
   else {
-    $form_state['redirect'] = 'admin/settings/pay';
+    $form_state['redirect'] = 'admin/config/pay/pay';
     unset($form_state['rebuild'], $form_state['storage']);
   }
 }
 
 function pay_form_settings(&$form_state, $pay_form, $destination = NULL) {
-  if (!is_object($pay_form)) $pay_form = pay_form_load($pay_form);
+  if (!is_object($pay_form)) {
+    $pay_form = pay_form_load($pay_form);
+  }
 
   $pay_form->settings_form($form, $form_state);
 
diff --git includes/pay.handlers.inc includes/pay.handlers.inc
index 71f46b9..5106a1c 100644
--- includes/pay.handlers.inc
+++ includes/pay.handlers.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -9,7 +10,7 @@
  * Implementation of hook_pay_method_handler_info().
  */
 function pay_pay_method_handler_info() {
-  $path = drupal_get_path('module', 'pay') .'/includes/handlers';
+  $path = drupal_get_path('module', 'pay') . '/includes/handlers';
   return array(
     'pay_method_custom' => array(
       'title' => t('Custom payment'),
diff --git includes/pay.menu.inc includes/pay.menu.inc
index 22cb47e..4d2cd44 100644
--- includes/pay.menu.inc
+++ includes/pay.menu.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -10,40 +11,50 @@
  */
 function pay_menu_menu() {
   return array(
-    'admin/settings/pay' => array(
+    'admin/config/pay' => array(
+      'title' => 'Payment',
+      'description' => 'Payment module settings',
+      'position' => 'right',
+      'weight' => 10,
+      'page callback' => 'system_admin_menu_block_page',
+      'access arguments' => array('access administration pages'),
+      'file' => 'system.admin.inc',
+      'file path' => drupal_get_path('module', 'system'),
+    ),
+    'admin/config/pay/pay' => array(
       'title' => 'Payment settings',
       'page callback' => 'pay_admin_overview',
       'access arguments' => array('administer pay'),
       'file' => 'pay.admin.inc',
-      'file path' => drupal_get_path('module', 'pay') .'/includes',
+      'file path' => drupal_get_path('module', 'pay') . '/includes',
       'description' => 'Configure payment methods and administer payment settings.',
     ),
-    'admin/settings/pay/overview' => array(
+    'admin/config/pay/pay/overview' => array(
       'title' => 'Overview',
       'type' => MENU_DEFAULT_LOCAL_TASK,
       'weight' => -10,
     ),
-    'admin/settings/pay/add' => array(
+    'admin/config/pay/pay/add' => array(
       'title' => 'Add a payment method',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('pay_admin_method_form'),
       'access arguments' => array('administer pay'),
       'file' => 'pay.admin.inc',
-      'file path' => drupal_get_path('module', 'pay') .'/includes',
+      'file path' => drupal_get_path('module', 'pay') . '/includes',
       'type' => MENU_LOCAL_TASK,
     ),
-    'admin/settings/pay/%pay_method/edit' => array(
+    'admin/config/pay/pay/%pay_method/edit' => array(
       'title' => 'Edit payment method',
       'page callback' => 'drupal_get_form',
-      'page arguments' => array('pay_admin_method_form', 3),
+      'page arguments' => array('pay_admin_method_form', 4),
       'access arguments' => array('administer pay'),
       'file' => 'pay.admin.inc',
-      'file path' => drupal_get_path('module', 'pay') .'/includes',
+      'file path' => drupal_get_path('module', 'pay') . '/includes',
     ),
-    'pay/transaction/%pay_transaction' => array(
+    'pay/transaction/pay/%pay_transaction' => array(
       'title' => 'Transaction details',
       'page callback' => 'theme',
-      'page arguments' => array('pay_transaction', 2),
+      'page arguments' => array('pay_transaction', 3),
       'access arguments' => array('administer payments for any form'),
     ),
     'pay/transaction/%pay_transaction/%' => array(
diff --git includes/pay.token.inc includes/pay.token.inc
index 0a50f7d..b974bc7 100644
--- includes/pay.token.inc
+++ includes/pay.token.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -41,5 +42,4 @@ function pay_token_list($type = 'all') {
 /**
  * Implementation of hook_token_values().
  */
-function pay_token_values($type = 'all', $object = NULL) {
-}
+function pay_token_values($type = 'all', $object = NULL) { }
diff --git includes/pay.trigger.inc includes/pay.trigger.inc
index 8e4997d..02a31a6 100644
--- includes/pay.trigger.inc
+++ includes/pay.trigger.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -6,25 +7,25 @@
  */
 
 /**
- * Implementation of hook_hook_info().
+ * Implementation of hook_trigger_info().
  */
-function pay_hook_info() {
-  $hooks = array('pay' => array('pay' => array()));
+function pay_trigger_info() {
+  $hooks = array('pay' => array());
 
   foreach (pay_handlers('pay_form') as $name => $info) {
     $replace = array('@type' => $info['title']);
 
-    $hooks['pay']['pay'][$name .'_transaction_create'] = array(
-      'runs when' => t('@type: A new payment transaction is created but no payment activites have been attempted', $replace),
+    $hooks['pay'][$name . '_transaction_create'] = array(
+      'label' => t('@type: A new payment transaction is created but no payment activites have been attempted', $replace),
     );
-    $hooks['pay']['pay'][$name .'_activity_create'] = array(
-      'runs when' => t('@type: A payment activity has occurred, but the transaction is not yet complete', $replace),
+    $hooks['pay'][$name . '_activity_create'] = array(
+      'label' => t('@type: A payment activity has occurred, but the transaction is not yet complete', $replace),
     );
-    $hooks['pay']['pay'][$name .'_transaction_complete'] = array(
-      'runs when' => t('@type: A payment transaction has been completed', $replace),
+    $hooks['pay'][$name . '_transaction_complete'] = array(
+      'label' => t('@type: A payment transaction has been completed', $replace),
     );
-    $hooks['pay']['pay'][$name .'_goal'] = array(
-      'runs when' => t('@type: The form has a goal amount and that goal has been reached', $replace),
+    $hooks['pay'][$name . '_goal'] = array(
+      'label' => t('@type: The form has a goal amount and that goal has been reached', $replace),
     );
   }
   return $hooks;
@@ -63,7 +64,9 @@ function pay_actions_do($hook, &$object) {
   if (module_exists('trigger')) {
     $context = array();
     foreach (_trigger_get_hook_aids('pay', $hook) as $aid => $action_info) {
-      if ($aid) actions_do($aid, $object, $context);
+      if ($aid) {
+        actions_do($aid, $object, $context);
+      }
     }
   }
 }
diff --git includes/views/pay.views.inc includes/views/pay.views.inc
index f8b6295..0e39fad 100644
--- includes/views/pay.views.inc
+++ includes/views/pay.views.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -161,7 +162,7 @@ function pay_views_data() {
     'field' => array(
       'handler' => 'pay_handler_field_amount',
       'click sortable' => TRUE,
-     ),
+    ),
     'filter' => array(
       'handler' => 'pay_handler_filter_amount',
     ),
diff --git includes/views/pay.views_default.inc includes/views/pay.views_default.inc
index d2a3e35..703e026 100644
--- includes/views/pay.views_default.inc
+++ includes/views/pay.views_default.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
diff --git includes/views/pay_handler_argument_default_form.inc includes/views/pay_handler_argument_default_form.inc
index 072afdb..bed1864 100644
--- includes/views/pay_handler_argument_default_form.inc
+++ includes/views/pay_handler_argument_default_form.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 /**
  * @file
  * Contains the payment form from URL argument default plugin.
diff --git includes/views/pay_handler_field_amount.inc includes/views/pay_handler_field_amount.inc
index daf3a15..1b5fe3c 100644
--- includes/views/pay_handler_field_amount.inc
+++ includes/views/pay_handler_field_amount.inc
@@ -9,7 +9,7 @@ class pay_handler_field_amount extends views_handler_field_numeric {
     $join->construct('pay_transaction', 'pay_form', 'pfid', 'pfid');
     $pay_transaction_table = $this->query->ensure_table('pay_transaction', $this->table_alias, $join);
     $sum = 'SUM(' . $pay_transaction_table . '.' . $this->real_field . ')';
-    $field_alias = $this->query->add_field('', $sum, $this->real_field .'_amount');
+    $field_alias = $this->query->add_field('', $sum, $this->real_field . '_amount');
     $this->field_alias = $field = $field_alias;
 
     $this->add_additional_fields();
diff --git includes/views/pay_handler_field_count.inc includes/views/pay_handler_field_count.inc
index fa9b121..40b5f36 100644
--- includes/views/pay_handler_field_count.inc
+++ includes/views/pay_handler_field_count.inc
@@ -9,9 +9,9 @@ class pay_handler_field_count extends views_handler_field_numeric {
     $join->construct('pay_transaction', 'pay_form', 'pfid', 'pfid');
     $pay_transaction_table = $this->query->ensure_table('pay_transaction', $this->table_alias, $join);
     $count = 'COUNT(' . $pay_transaction_table . '.' . $this->real_field . ')';
-    $count = 'COUNT(' . $pay_transaction_table .'.uid)';
+    $count = 'COUNT(' . $pay_transaction_table . '.uid)';
 //    $this->query->add_groupby($pay_transaction_table .'.uid');
-    $field_alias = $this->query->add_field('', $count, $this->real_field .'_count');
+    $field_alias = $this->query->add_field('', $count, $this->real_field . '_count');
     $this->field_alias = $field = $field_alias;
 
     $this->add_additional_fields();
diff --git includes/views/pay_handler_field_handler.inc includes/views/pay_handler_field_handler.inc
index e1797bb..93514e9 100644
--- includes/views/pay_handler_field_handler.inc
+++ includes/views/pay_handler_field_handler.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -11,7 +12,7 @@ class pay_handler_field_handler extends views_handler_field {
 
     // Load the payment form and use the 'nice' label from hook_pay_handlers.
     $key = $values->{$this->definition['pay_key']};
-    if ($pay = pay_load($this->definition['pay_type'], $key)) {
+    if ($pay = pay_load_object($this->definition['pay_type'], $key)) {
       return $info[$pay->handler()]['title'];
     }
   }
diff --git includes/views/pay_handler_field_pay_form.inc includes/views/pay_handler_field_pay_form.inc
index c17beda..c67bbb0 100644
--- includes/views/pay_handler_field_pay_form.inc
+++ includes/views/pay_handler_field_pay_form.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -26,18 +27,19 @@ class pay_handler_field_pay_form extends views_handler_field {
   function render(&$values) {
     $key = $this->definition['pay_key'];
     if ($this->table != $this->query->base_table) {
-      $key = $this->field_alias ? $this->field_alias : $this->table .'_'. $key;
+      $key = $this->field_alias ? $this->field_alias : $this->table . '_' . $key;
     }
-    if ($pay = pay_load($this->definition['pay_type'], $values->$key)) {
+    if ($pay = pay_load_object($this->definition['pay_type'], $values->$key)) {
 
       /* TODO this is an inappropriate hack that presumes that a missing
-         menu_path() should be node/XX/pay on node-based views. This case is
-         only true on pay_node forms. This should move to that module somehow.
+       menu_path() should be node/XX/pay on node-based views. This case is
+       only true on pay_node forms. This should move to that module somehow.
        */
       if (!$pay->menu_path() && ($nid = $values->nid)) {
         $pay->set_menu_path('node/' . $nid . '/pay');
       }
 
+      // TODO Please change this theme call to use an associative array for the $variables parameter.
       return theme($this->options['display'], $pay);
     }
   }
diff --git includes/views/pay_handler_field_pay_form_link.inc includes/views/pay_handler_field_pay_form_link.inc
index cb80ff7..1cb85a8 100644
--- includes/views/pay_handler_field_pay_form_link.inc
+++ includes/views/pay_handler_field_pay_form_link.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -9,7 +10,10 @@ class pay_handler_field_pay_form_link extends views_handler_field {
   function option_definition() {
     $options = parent::option_definition();
 
-    $options['text'] = array('default' => '', 'translatable' => TRUE);
+    $options['text'] = array(
+      'default' => '',
+      'translatable' => TRUE,
+    );
 
     return $options;
   }
@@ -27,7 +31,7 @@ class pay_handler_field_pay_form_link extends views_handler_field {
     // Id field is either 'pfid' or 'pay_form_pfid', depending on view's base.
     $key = $this->definition['pay_key'];
     if ($this->table != $this->query->base_table) {
-      $key = $this->field_alias ? $this->field_alias : $this->table .'_'. $key;
+      $key = $this->field_alias ? $this->field_alias : $this->table . '_' . $key;
     }
 
     if ($pay_form = pay_form_load($values->$key)) {
diff --git includes/views/pay_handler_field_pay_transaction_link.inc includes/views/pay_handler_field_pay_transaction_link.inc
index 0abdc96..a0ac82a 100644
--- includes/views/pay_handler_field_pay_transaction_link.inc
+++ includes/views/pay_handler_field_pay_transaction_link.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -10,7 +11,10 @@ class pay_handler_field_pay_transaction_link extends views_handler_field {
   function option_definition() {
     $options = parent::option_definition();
 
-    $options['text'] = array('default' => '', 'translatable' => TRUE);
+    $options['text'] = array(
+      'default' => '',
+      'translatable' => TRUE,
+    );
 
     return $options;
   }
@@ -28,11 +32,11 @@ class pay_handler_field_pay_transaction_link extends views_handler_field {
     // Id field is either 'pfid' or 'pay_form_pfid', depending on view's base.
     $key = $this->definition['pay_key'];
     if ($this->table != $this->query->base_table) {
-      $key = $this->field_alias ? $this->field_alias : $this->table .'_'. $key;
+      $key = $this->field_alias ? $this->field_alias : $this->table . '_' . $key;
     }
 
     if (isset($values->$key)) {
-      $path = 'pay/transaction/'. $values->$key;
+      $path = 'pay/transaction/' . $values->$key;
       $text = !empty($this->options['text']) ? $this->options['text'] : t('Details');
       return l($text, $path);
     }
diff --git includes/views/pay_handler_filter_amount.inc includes/views/pay_handler_filter_amount.inc
index e4ee6b9..086a3f2 100644
--- includes/views/pay_handler_filter_amount.inc
+++ includes/views/pay_handler_filter_amount.inc
@@ -18,7 +18,7 @@ class pay_handler_filter_amount extends views_handler_filter_numeric {
 
     return $options;
   }
-  
+
   function value_form(&$form, &$form_state) {
     $form['value']['#tree'] = TRUE;
 
@@ -39,7 +39,7 @@ class pay_handler_filter_amount extends views_handler_filter_numeric {
         $which = in_array($this->operator, $this->operator_values(2)) ? 'minmax' : 'value';
       }
       else {
-        $source = 'edit-' . form_clean_id($this->options['expose']['operator']);
+        $source = 'edit-' . drupal_clean_css_identifier($this->options['expose']['operator']);
       }
     }
 
@@ -102,14 +102,17 @@ class pay_handler_filter_amount extends views_handler_filter_numeric {
         // Ensure there is something in the 'value'.
         $form['value'] = array(
           '#type' => 'value',
-          '#value' => NULL
+          '#value' => NULL,
         );
       }
 
       $form['value']['value_or_goal'] = array(
         '#type' => 'select',
         '#title' => 'Value',
-        '#options' => array('value' => t('Enter a value'), 'goal' => t('Payment form goal amount')),
+        '#options' => array(
+          'value' => t('Enter a value'),
+          'goal' => t('Payment form goal amount'),
+        ),
         '#weight' => -1,
         '#default_value' => $this->value['value_or_goal'],
         '#process' => array('views_process_dependency'),
@@ -120,14 +123,14 @@ class pay_handler_filter_amount extends views_handler_filter_numeric {
       $form['value']['value']['#dependency_count'] = 2;
     }
   }
-  
+
   function query() {
     $this->ensure_my_table();
     $field = "$this->table_alias.$this->real_field";
     $sql = "SELECT SUM($this->real_field) FROM {pay_transaction} px WHERE px.pfid = $this->table_alias.pfid";
-    $field_alias = $this->query->add_field('', "($sql)", $this->real_field .'_total_paid');
+    $field_alias = $this->query->add_field('', "($sql)", $this->real_field . '_total_paid');
     $this->field_alias = $field = $field_alias;
- 
+
     $info = $this->operators();
     if (!empty($info[$this->operator]['method'])) {
       $this->{$info[$this->operator]['method']}($field);
diff --git includes/views/pay_handler_filter_handler.inc includes/views/pay_handler_filter_handler.inc
index 21f579a..a8f37d4 100644
--- includes/views/pay_handler_filter_handler.inc
+++ includes/views/pay_handler_filter_handler.inc
@@ -10,7 +10,7 @@ class pay_handler_filter_handler extends views_handler_filter_in_operator {
     if (!isset($this->value_options)) {
       $this->value_options = array();
       // Provide a list of available handlers to select from.
-      foreach(pay_handlers($this->pay_type) as $name => $info) {
+      foreach (pay_handlers($this->pay_type) as $name => $info) {
         $this->value_options[$name] = $info['title'];
       }
     }
diff --git modules/pay_node/includes/pay_node.admin.inc modules/pay_node/includes/pay_node.admin.inc
index 3b25de2..4144abc 100644
--- modules/pay_node/includes/pay_node.admin.inc
+++ modules/pay_node/includes/pay_node.admin.inc
@@ -8,7 +8,7 @@
 /**
  * Menu callback for pay_node admin screen.
  */
-function pay_node_admin_settings(&$form_state) {
+function pay_node_admin_settings($form, &$form_state) {
   $form = array();
 
   // Available node payment models.
@@ -50,23 +50,27 @@ function pay_node_admin_settings(&$form_state) {
   return system_settings_form($form);
 }
 
-function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function pay_node_admin_node_type_form_alter(&$form, &$form_state) {
   $models = array_keys(array_filter(variable_get('pay_node_models', array())));
   $forms  = array_keys(array_filter(variable_get('pay_node_forms', array())));
   $suffix = '_' . $form['#node_type']->type;
 
   $form['pay_node'] = array(
-    '#type' =>  'fieldset',
-    '#title' =>  t('Payment settings'),
-    '#collapsible' =>  TRUE,
-    '#collapsed' =>  !variable_get('pay_node_enabled'. $suffix, FALSE),
+    '#type' => 'fieldset',
+    '#title' => t('Payment settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => !variable_get('pay_node_enabled' . $suffix, FALSE),
   );
 
   // Don't do anything further if there are no payment forms or modes available.
   if (!count($models) || !count($forms)) {
     $form['pay_node']['error'] = array(
       '#type' => 'markup',
-      '#value' => t('<p>In order to accept payments on this node type, you will need to enable at least one payment model and at least one form type. You can configure these on the !pay_settings.</p>', array('!pay_settings' => l(t('payment settings page'), 'admin/settings/pay/node'))),
+      '#value' => t('<p>In order to accept payments on this node type, you will need to enable at least one payment model and at least one form type. You can configure these on the !pay_settings.</p>', array('!pay_settings' => l(t('payment settings page'), 'admin/config/pay/node'))),
     );
     return;
   }
@@ -75,7 +79,7 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
   $form['pay_node']['pay_node_enabled'] = array(
     '#type' => 'checkbox',
     '#title' => t('Enable payments on this content type'),
-    '#default_value' => variable_get('pay_node_enabled'. $suffix, FALSE),
+    '#default_value' => variable_get('pay_node_enabled' . $suffix, FALSE),
     '#disabled' => (!count($models) || !count($forms)),
   );
 
@@ -95,7 +99,7 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
         'form' => 'Node creation',
         'view' => 'Node display',
       ),
-      '#default_value' => variable_get('pay_node_model'. $suffix, NULL),
+      '#default_value' => variable_get('pay_node_model' . $suffix, NULL),
     );
   }
 
@@ -112,7 +116,7 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
       '#type' => 'checkbox',
       '#title' => t('Require payment forms on @type nodes', array('@type' => $form['#node_type']->name)),
       '#description' => t('Require linked or new payment forms when creating or editing content.'),
-      '#default_value' => variable_get('pay_node_view_required'. $suffix, 0),
+      '#default_value' => variable_get('pay_node_view_required' . $suffix, 0),
     );
 
     $form['pay_node']['view_form']['pay_node_method'] = array(
@@ -122,11 +126,11 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
         'create' => t('Create a new form for every node'),
         'select' => t('Link to an existing form'),
       ),
-      '#default_value' => variable_get('pay_node_method'. $suffix, 'create'),
+      '#default_value' => variable_get('pay_node_method' . $suffix, 'create'),
     );
 
-    $embeddable = array( '' => ' - None -');
-    foreach (pay_forms(NULL, TRUE) as $pay_form) {
+    $embeddable = array('' => ' - None -');
+    foreach (pay_forms_list(NULL, TRUE) as $pay_form) {
       $embeddable[$pay_form->pfid] = $pay_form->title();
     }
 
@@ -136,47 +140,47 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
     );
 
     /*
-    $handler = 'pay_donate'; // TODO
-    $settings = variable_get($handler . $suffix, array());
-    $settings['handler'] = $handler;
-    $settings_form = array();
-    $pay_form = pay_form_load($settings);
-    $pay_form->settings_form($form, $form_state);
-    if (isset($form[$handler])) {
-      $form[$handler]['#type'] = 'fieldset';
-      $form[$handler]['#collapsible'] = TRUE;
-      $form[$handler]['#title'] = $pay_form->title();
-
-      $form['pay_node']['view_form'][$handler] = $form[$handler];
-      $form[$handler]['#access'] = FALSE;
-    }
-
-    $form['#submit'][] = 'pay_test_submit';
-    */
+     $handler = 'pay_donate'; // TODO
+     $settings = variable_get($handler . $suffix, array());
+     $settings['handler'] = $handler;
+     $settings_form = array();
+     $pay_form = pay_form_load($settings);
+     $pay_form->settings_form($form, $form_state);
+     if (isset($form[$handler])) {
+     $form[$handler]['#type'] = 'fieldset';
+     $form[$handler]['#collapsible'] = TRUE;
+     $form[$handler]['#title'] = $pay_form->title();
+
+     $form['pay_node']['view_form'][$handler] = $form[$handler];
+     $form[$handler]['#access'] = FALSE;
+     }
+
+     $form['#submit'][] = 'pay_test_submit';
+     */
     /*
-    $pay_form->settings_form($settings_form, $form_state);
-    unset($settings_form['submit']);
+     $pay_form->settings_form($settings_form, $form_state);
+     unset($settings_form['submit']);
 
-    $settings_form['#type'] = 'fieldset';
-    $settings_form['#collapsible'] = TRUE;
-    $settings_form['#title'] = t('Default form options');
-    $settings_form['#tree'] = TRUE;
+     $settings_form['#type'] = 'fieldset';
+     $settings_form['#collapsible'] = TRUE;
+     $settings_form['#title'] = t('Default form options');
+     $settings_form['#tree'] = TRUE;
 
-    $form['pay_node']['view_form']['pay_node_view_default_create'] = $settings_form;
-    */
+     $form['pay_node']['view_form']['pay_node_view_default_create'] = $settings_form;
+     */
 
     $form['pay_node']['view_form']['pay_node_view_default_select'] = array(
       '#type' => 'select',
       '#title' => t('Default form selection'),
       '#options' => $embeddable,
-      '#default_value' => variable_get('pay_node_view_default_select'. $suffix, ''),
+      '#default_value' => variable_get('pay_node_view_default_select' . $suffix, ''),
     );
 
     $form['pay_node']['view_form']['pay_node_view_override'] = array(
       '#type' => 'checkbox',
       '#title' => t('Allow administrators to override the default form selection'),
       '#description' => t('Use the selected value by default, but present the selection to administrators so that they can link different @type nodes to different payment forms.', array('@type' => $form['#node_type']->name)),
-      '#default_value' => variable_get('pay_node_view_override'. $suffix, ''),
+      '#default_value' => variable_get('pay_node_view_override' . $suffix, ''),
     );
 
     $form['pay_node']['view_display'] = array(
@@ -192,7 +196,7 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
       '#type' => 'select',
       '#title' => t('Teaser display'),
       '#options' => $display_options,
-      '#default_value' => variable_get('pay_node_display_teaser'. $suffix, ''),
+      '#default_value' => variable_get('pay_node_display_teaser' . $suffix, ''),
     );
 
     $display_options += array('tab' => t('As a menu tab'));
@@ -201,7 +205,7 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
       '#type' => 'select',
       '#title' => t('Full node display'),
       '#options' => $display_options,
-      '#default_value' => variable_get('pay_node_display'. $suffix, 'pay_form_default'),
+      '#default_value' => variable_get('pay_node_display' . $suffix, 'pay_form_default'),
     );
   }
 
@@ -217,34 +221,34 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
     $form['pay_node']['pay_node_form'] = array(
       '#type' => 'select',
       '#options' => $forms,
-      '#default_value' => variable_get('pay_node_form'. $suffix, NULL),
+      '#default_value' => variable_get('pay_node_form' . $suffix, NULL),
     );
   }
 
   // Handler-specific settings
-    /*
-  foreach ($forms as $handler) {
-    $settings = variable_get('pay_node_'. $handler . $suffix, array());
-
-    $pay_form = pay_form_load($handler);
-    $pay_form->settings_form($form, $form_state);
-
-    if (isset($form[$handler])) {
-      $form[$handler]['#type'] = 'fieldset';
-      $form[$handler]['#collapsible'] = TRUE;
-      $form[$handler]['#title'] = $pay_form->title();
-
-      $form['pay_node']['pay_node_'. $handler] = $form[$handler];
-      $form[$handler]['#access'] = FALSE;
-    }
-    if (isset($form['pay_node']['pay_form_settings'][$handler])) {
-      $form['pay_node']['pay_form_settings'][$handler]['#type'] = 'fieldset';
-      $form['pay_node']['pay_form_settings'][$handler]['#collapsible'] = TRUE;
-      $form['pay_node']['pay_form_settings'][$handler]['#title'] = $handler;
-      $form['pay_node']['pay_form_settings'][$handler]['#tree'] = TRUE;
-    }
-  }
-    */
+  /*
+   foreach ($forms as $handler) {
+   $settings = variable_get('pay_node_'. $handler . $suffix, array());
+
+   $pay_form = pay_form_load($handler);
+   $pay_form->settings_form($form, $form_state);
+
+   if (isset($form[$handler])) {
+   $form[$handler]['#type'] = 'fieldset';
+   $form[$handler]['#collapsible'] = TRUE;
+   $form[$handler]['#title'] = $pay_form->title();
+
+   $form['pay_node']['pay_node_'. $handler] = $form[$handler];
+   $form[$handler]['#access'] = FALSE;
+   }
+   if (isset($form['pay_node']['pay_form_settings'][$handler])) {
+   $form['pay_node']['pay_form_settings'][$handler]['#type'] = 'fieldset';
+   $form['pay_node']['pay_form_settings'][$handler]['#collapsible'] = TRUE;
+   $form['pay_node']['pay_form_settings'][$handler]['#title'] = $handler;
+   $form['pay_node']['pay_form_settings'][$handler]['#tree'] = TRUE;
+   }
+   }
+   */
 }
 
 /**
@@ -253,28 +257,32 @@ function  pay_node_admin_node_type_form_alter(&$form, &$form_state) {
 function pay_node_admin_node_form_alter(&$form, &$form_state) {
   // Settings variable suffix.
   $node = $form['#node'];
-  $suffix = '_'. $form['#node']->type;
+  $suffix = '_' . $form['#node']->type;
 
   // Don't continue if pay_node settings aren't enabled for this node type.
-  if (!variable_get('pay_node_enabled'. $suffix, FALSE)) return;
+  if (!variable_get('pay_node_enabled' . $suffix, FALSE)) {
+    return;
+  }
 
   // Determine the payment model and verify that it's currently valid.
-  $model = variable_get('pay_node_model'. $suffix, NULL);
-  if (!in_array($model, variable_get('pay_node_models', array()))) return;
+  $model = variable_get('pay_node_model' . $suffix, NULL);
+  if (!in_array($model, variable_get('pay_node_models', array()))) {
+    return;
+  }
 
   // Add payment form settings on the node form to control how it's displayed.
   if ($model == 'view') {
-    $visible  = variable_get('pay_node_view_override'. $suffix, FALSE);
-    $required = variable_get('pay_node_view_required'. $suffix, FALSE);
+    $visible  = variable_get('pay_node_view_override' . $suffix, FALSE);
+    $required = variable_get('pay_node_view_required' . $suffix, FALSE);
 
     // The default settings are overrideable, so present some settings.
     if ($visible) {
-      switch (variable_get('pay_node_method'. $suffix, '')) {
+      switch (variable_get('pay_node_method' . $suffix, '')) {
 
         // Create a new payment form for each node using default values.
         case 'create':
           if (!$pay_form = pay_node_form_load($node)) {
-            $pay_form = pay_form_load(variable_get('pay_node_form'. $suffix, ''));
+            $pay_form = pay_form_load(variable_get('pay_node_form' . $suffix, ''));
           }
 
           if ($pay_form) {
@@ -283,20 +291,22 @@ function pay_node_admin_node_form_alter(&$form, &$form_state) {
 
             // Do not allow menu_path to be specified.
             $form[$group][$group]['menu_path'] = array(
-              '#type' => 'value', '#value' => '');
+              '#type' => 'value',
+              '#value' => '',
+            );
 
             // Add an after_build handler to map the pay_form to its node.
             $form['#after_build'][] = 'pay_node_admin_node_form_after_build';
           }
           break;
 
-        // Link to an existing form.
+          // Link to an existing form.
         case 'select':
           $group = 'pay_node';
 
           // List of available forms.
-          $options = array( '' =>  ' - None -');
-          foreach (pay_forms(NULL, TRUE) as $pay_form) {
+          $options = array('' => ' - None -');
+          foreach (pay_forms_list(NULL, TRUE) as $pay_form) {
             $options[$pay_form->pfid] = $pay_form->title();
           }
 
@@ -324,11 +334,11 @@ function pay_node_admin_node_form_alter(&$form, &$form_state) {
 
     // The settings are NOT visible, so silently set the defaults.
     else {
-      switch (variable_get('pay_node_method'. $suffix, '')) {
+      switch (variable_get('pay_node_method' . $suffix, '')) {
         case 'create':
           break;
 
-        // Store the default selected form for this node type.
+          // Store the default selected form for this node type.
         case 'select':
           $pay_form_default = pay_node_form_load($node);
           $form['pay_node'] = array(
@@ -341,32 +351,32 @@ function pay_node_admin_node_form_alter(&$form, &$form_state) {
   }
 
   /*
-  if ($pay_form = pay_node_form_load($form['#node'])) {
-    $model = variable_get('pay_node_model_'. $form['#node']->type, NULL);
-    $active_models = variable_get('pay_node_models', array());
-    if ($active_models[$model]) {
-      if ($model == 'form') {
-        $pay_form->form($form, $form_state);
-      }
-
-      // Embed payment form settings into the node editing form.
-      if ($model == 'view') {
-        $pay_form->settings_form($form, $form_state);
-
-        // Add an after_build handler to map the pay_form to its node.
-        $form['#after_build'][] = 'pay_node_admin_node_form_after_build';
-
-        // Add a fieldset to differentiate the settings form.
-        $group = $pay_form->handler();
-        if (isset($form[$group])) {
-          $form[$group]['#type'] = 'fieldset';
-          $form[$group]['#collapsible'] = TRUE;
-          $form[$group]['#title'] = t('Payment settings');
-        }
-      }
-    }
-  }
-  */
+   if ($pay_form = pay_node_form_load($form['#node'])) {
+   $model = variable_get('pay_node_model_'. $form['#node']->type, NULL);
+   $active_models = variable_get('pay_node_models', array());
+   if ($active_models[$model]) {
+   if ($model == 'form') {
+   $pay_form->form($form, $form_state);
+   }
+
+   // Embed payment form settings into the node editing form.
+   if ($model == 'view') {
+   $pay_form->settings_form($form, $form_state);
+
+   // Add an after_build handler to map the pay_form to its node.
+   $form['#after_build'][] = 'pay_node_admin_node_form_after_build';
+
+   // Add a fieldset to differentiate the settings form.
+   $group = $pay_form->handler();
+   if (isset($form[$group])) {
+   $form[$group]['#type'] = 'fieldset';
+   $form[$group]['#collapsible'] = TRUE;
+   $form[$group]['#title'] = t('Payment settings');
+   }
+   }
+   }
+   }
+   */
 }
 
 function pay_test_submit($form, $form_state) {
diff --git modules/pay_node/includes/views/pay_node.views.inc modules/pay_node/includes/views/pay_node.views.inc
index 9b3a3bf..8f09d72 100644
--- modules/pay_node/includes/views/pay_node.views.inc
+++ modules/pay_node/includes/views/pay_node.views.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -6,7 +7,7 @@
  */
 
 /**
- * Implementation of hook_views_data().
+ * Implements hook_views_data().
  */
 function pay_node_views_data() {
 
@@ -131,7 +132,7 @@ function pay_node_views_data() {
 }
 
 /**
- * Implementation of hook_views_handlers().
+ * Implements hook_views_handlers().
  */
 function pay_node_views_handlers() {
   return array(
diff --git modules/pay_node/includes/views/pay_node_handler_field_pay_form_link.inc modules/pay_node/includes/views/pay_node_handler_field_pay_form_link.inc
index 435b248..1d4e984 100644
--- modules/pay_node/includes/views/pay_node_handler_field_pay_form_link.inc
+++ modules/pay_node/includes/views/pay_node_handler_field_pay_form_link.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
diff --git modules/pay_node/pay_node.info modules/pay_node/pay_node.info
index 15d07df..0cdcd49 100644
--- modules/pay_node/pay_node.info
+++ modules/pay_node/pay_node.info
@@ -1,12 +1,5 @@
 name = Node payments
 description = Attach payment forms to node creation or display pages.
 package = Payment API
-core = 6.x
+core = 7.x
 dependencies[] = pay
-
-; Information added by drupal.org packaging script on 2011-05-09
-version = "6.x-1.1"
-core = "6.x"
-project = "pay"
-datestamp = "1304964416"
-
diff --git modules/pay_node/pay_node.install modules/pay_node/pay_node.install
index c593cc0..7e05d06 100644
--- modules/pay_node/pay_node.install
+++ modules/pay_node/pay_node.install
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -6,7 +7,7 @@
  */
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function pay_node_schema() {
   return array(
@@ -29,27 +30,20 @@ function pay_node_schema() {
 }
 
 /**
- * Implementation of hook_install().
- */
-function pay_node_install() {
-  drupal_install_schema('pay_node');
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function pay_node_uninstall() {
-  drupal_uninstall_schema('pay_node');
-}
-
-/**
  * Add a "method" column to the pay_form_node table.
  */
 function pay_node_update_6001() {
-  $spec = array('type' => 'varchar', 'length' => 20);
-  db_add_field($ret, 'pay_form_node', 'method', $spec);
-  $ret[] = update_sql("UPDATE {pay_form_node} SET method = 'create'");
-  return $ret;
+  $spec = array(
+    'type' => 'varchar',
+    'length' => 20,
+  );
+  db_add_field('pay_form_node', 'method', $spec);
+  db_update('pay_form_node')
+    ->fields(array(
+      'method' => "create",
+    ))
+    ->execute();
+  return t('Added a "method" column to the pay_form_node table.');
 }
 
 /**
@@ -58,13 +52,19 @@ function pay_node_update_6001() {
 function pay_node_update_6002() {
   $table = array(
     'fields' => array(
-      'pxid' => array('type' => 'int', 'unsigned' => TRUE),
-      'nid' => array('type' => 'int', 'unsigned' => TRUE),
+      'pxid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+      ),
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+      ),
     ),
     'primary key' => array('pxid', 'nid'),
   );
-  db_create_table($ret, 'pay_transaction_node', $table);
-  return $ret;
+  db_create_table('pay_transaction_node', $table);
+  return t('Added the pay_transaction_node table.');
 }
 
 /**
@@ -73,7 +73,13 @@ function pay_node_update_6002() {
  * associated with nodes correctly.
  */
 function pay_node_update_6003() {
-  $ret[] = update_sql("UPDATE {pay_form} SET menu_path = NULL
-    WHERE menu_path LIKE 'node/%/pay'");
-  return $ret;
+  // TODO: review this, check NULL bit.
+  db_update('pay_form')
+    ->fields(array(
+      'menu_path' => NULL,
+    ))
+    ->condition('menu_path', 'node/%/pay', 'LIKE')
+    ->execute();
+  return t('Removed menu_path entries from pay_node forms.');
 }
+
diff --git modules/pay_node/pay_node.module modules/pay_node/pay_node.module
index aaa3eab..af28779 100644
--- modules/pay_node/pay_node.module
+++ modules/pay_node/pay_node.module
@@ -1,17 +1,18 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function pay_node_menu() {
   return array(
-    'admin/settings/pay/node' => array(
+    'admin/config/pay/pay/node' => array(
       'title' => 'Node settings',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('pay_node_admin_settings'),
       'access arguments' => array('administer pay'),
       'file' => 'pay_node.admin.inc',
-      'file path' => drupal_get_path('module', 'pay_node') .'/includes',
+      'file path' => drupal_get_path('module', 'pay_node') . '/includes',
       'type' => MENU_LOCAL_TASK,
     ),
     'node/%node/pay' => array(
@@ -28,24 +29,28 @@ function pay_node_menu() {
  * An access callback for payment forms.
  */
 function pay_node_pay_form_access($node) {
-  if (!$pay_form = pay_node_form_load($node)) return FALSE;
-  if (!$pay_form->pay_methods()) return FALSE;
+  if (!$pay_form = pay_node_form_load($node)) {
+    return FALSE;
+  }
+  if (!$pay_form->pay_methods()) {
+    return FALSE;
+  }
   return TRUE;
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
  */
 function pay_node_form_alter(&$form, &$form_state, $form_id) {
   // Include the payment settings form on an individual node.
   if ($form['#id'] == 'node-form') {
-    require_once(dirname(__FILE__) . '/includes/pay_node.admin.inc');
+    require_once DRUPAL_ROOT . '/' . dirname(__FILE__) . '/includes/pay_node.admin.inc';
     pay_node_admin_node_form_alter($form, $form_state);
   }
 
   // Provide general settings for any node type.
   if ($form['#id'] == 'node-type-form') {
-    require_once(dirname(__FILE__) . '/includes/pay_node.admin.inc');
+    require_once DRUPAL_ROOT . '/' . dirname(__FILE__) . '/includes/pay_node.admin.inc';
     pay_node_admin_node_type_form_alter($form, $form_state);
   }
 
@@ -53,111 +58,165 @@ function pay_node_form_alter(&$form, &$form_state, $form_id) {
   if (isset($form_state['pay_node'])) {
     $node = $form_state['pay_node'];
     if (isset($form['#pay'])) {
-      $form['pay_node_nid'] = array('#type' => 'value', '#value' => $node->nid);
+      $form['pay_node_nid'] = array(
+        '#type' => 'value',
+        '#value' => $node->nid,
+      );
       return;
     }
   }
 }
 
 /**
- * Implementation of hook_nodeapi().
+ * Implements hook_node_load().
  */
-function pay_node_nodeapi(&$node, $op, $teaser = NULL, $a4 = NULL) {
+function pay_node_node_load($node, $types) {
   // Add the payment acceptance form to the node.
-  if ($op == 'load') {
-    if ($pay_form = pay_node_form_load($node)) {
-      $node->pay_form = $pay_form;
-    }
+  if ($pay_form = pay_node_form_load($node)) {
+    $node->pay_form = $pay_form;
   }
+}
 
+/**
+ * Implements hook_node_view().
+ */
+function pay_node_node_view($node, $view_mode = 'full') {
   // Add the payment acceptance form to the node display.
-  if ($op == 'view') {
+  // Determine the selected theme function for this node type.
+  if ($teaser) {
+    $theme = variable_get('pay_node_display_teaser_' . $node->type, '');
+  }
+  else {
+    $theme = variable_get('pay_node_display_' . $node->type, 'pay_form_default');
+  }
+
+  // Do not include anything for 'tab' or empty functions (hidden).
+  if (in_array($theme, array('', 'tab'))) {
+    return;
+  }
+
+  // Add the pay_form's content to the node display.
+  if (isset($node->pay_form->pfid)) {
 
-    // Determine the selected theme function for this node type.
-    if ($teaser) {
-      $theme = variable_get('pay_node_display_teaser_'. $node->type, '');
+    if (function_exists('content_extra_field_weight')) {
+      $weight = content_extra_field_weight($node->type, 'pay_node');
     }
     else {
-      $theme = variable_get('pay_node_display_'. $node->type, 'pay_form_default');
+      $weight = 25;
     }
 
-    // Do not include anything for 'tab' or empty functions (hidden).
-    if (in_array($theme, array('', 'tab'))) return;
+    // TODO Please change this theme call to use an associative array for the $variables parameter.
+    $node->content['pay_node'] = array(
+      '#type' => 'markup',
+      '#value' => theme($theme, $node->pay_form),
+      '#weight' => $weight,
+    );
+  }
+}
 
-    // Add the pay_form's content to the node display.
-    if (isset($node->pay_form->pfid)) {
+/**
+ * Implements hook_node_insert().
+ */
+function pay_node_node_insert($node) {
+  // Create a record that links this payment form to this node.
+  if ($node->nid && isset($node->pay_node)) {
+    $method = variable_get('pay_node_method_' . $node->type, '');
+    $record = array(
+      'nid' => $node->nid,
+      'method' => $method,
+    );
 
-      if (function_exists('content_extra_field_weight')) {
-        $weight = content_extra_field_weight($node->type, 'pay_node');
-      }
-      else $weight = 25;
+    // Link to an existing pay_form using its id.
+    if (is_scalar($node->pay_node) && $node->pay_node) {
+      $record['pfid'] = $node->pay_node;
+      db_delete('pay_form_node')
+        ->condition('nid', $node->nid)
+        ->condition('method', $method)
+        ->execute();
+      drupal_write_record('pay_form_node', $record);
+    }
 
-      $node->content['pay_node'] = array(
-        '#type' => 'markup',
-        '#value' => theme($theme, $node->pay_form),
-        '#weight' => $weight,
-      );
+    // Creating a new form as we go.
+    else {
+      foreach ($node->pay_node as $pay_form) {
+        if ($pay_form->new) {
+          $record['pfid'] = $pay_form->pfid;
+          drupal_write_record('pay_form_node', $record);
+        }
+      }
     }
   }
+}
 
+/**
+ * Implements hook_node_update().
+ */
+function pay_node_node_update($node) {
   // Create a record that links this payment form to this node.
-  if ($op == 'insert' || $op == 'update') {
-    if ($node->nid && isset($node->pay_node)) {
-      $method = variable_get('pay_node_method_'. $node->type, '');
-      $record = array('nid' => $node->nid, 'method' => $method);
-
-      // Link to an existing pay_form using its id.
-      if (is_scalar($node->pay_node) && $node->pay_node) {
-        $record['pfid'] = $node->pay_node;
-        db_query("DELETE FROM {pay_form_node}
-          WHERE nid = %d AND method = '%s'", $node->nid, $method);
-        drupal_write_record('pay_form_node', $record);
-      }
+  if ($node->nid && isset($node->pay_node)) {
+    $method = variable_get('pay_node_method_' . $node->type, '');
+    $record = array(
+      'nid' => $node->nid,
+      'method' => $method,
+    );
 
-      // Creating a new form as we go.
-      else {
-        foreach ($node->pay_node as $pay_form) {
-          if ($pay_form->new) {
-            $record['pfid'] = $pay_form->pfid;
-            drupal_write_record('pay_form_node', $record);
-          }
+    // Link to an existing pay_form using its id.
+    if (is_scalar($node->pay_node) && $node->pay_node) {
+      $record['pfid'] = $node->pay_node;
+      db_delete('pay_form_node')
+        ->condition('nid', $node->nid)
+        ->condition('method', $method)
+        ->execute();
+      drupal_write_record('pay_form_node', $record);
+    }
+
+    // Creating a new form as we go.
+    else {
+      foreach ($node->pay_node as $pay_form) {
+        if ($pay_form->new) {
+          $record['pfid'] = $pay_form->pfid;
+          drupal_write_record('pay_form_node', $record);
         }
       }
     }
   }
+}
 
+/**
+ * Implements hook_node_delete().
+ */
+function pay_node_node_delete($node) {
   // Remove the pay_form <-> node relationship from the database.
-  if ($op == 'delete') {
-
-    // Disable (but don't delete) any pay_forms attached to this node.
-    $res = db_query("SELECT pfid FROM {pay_form_node}
-      WHERE nid = %d", $node->nid);
+  // Disable (but don't delete) any pay_forms attached to this node.
+  $res = db_query("SELECT pfid FROM {pay_form_node}
+    WHERE nid = :nid", array(':nid' => $node->nid));
 
-    while ($pfid = db_result($res)) {
-      $pay_form = pay_form_load($pfid);
-      $pay_form->disable();
-    }
-
-    // Delete the relationship in the database.
-    db_query("DELETE FROM {pay_form_node} WHERE nid = %d", $node->nid);
+  while ($pfid = $res->fetchField()) {
+    $pay_form = pay_form_load($pfid);
+    $pay_form->disable();
   }
+
+  // Delete the relationship in the database.
+  db_delete('pay_form_node')
+    ->condition('nid', $node->nid)
+    ->execute();
 }
 
 /**
- * Implementation of hook_views_api().
+ * Implements hook_views_api().
  */
 function pay_node_views_api() {
   return array(
     'api' => 2,
-    'path' => drupal_get_path('module', 'pay_node') .'/includes/views',
+    'path' => drupal_get_path('module', 'pay_node') . '/includes/views',
   );
 }
 
 /**
- * Implementation of hook_content_extra_fields().
+ * Implements hook_content_extra_fields().
  */
 function pay_node_content_extra_fields($type_name) {
-  if (variable_get('pay_node_enabled_'. $type_name, FALSE)) {
+  if (variable_get('pay_node_enabled_' . $type_name, FALSE)) {
     return array(
       'pay_node' => array(
         'label' => t('Payment information'),
@@ -169,33 +228,41 @@ function pay_node_content_extra_fields($type_name) {
 }
 
 /**
- * Implementation of hook_pay_transaction_create().
+ * Implements hook_pay_transaction_create().
  */
 function pay_node_pay_transaction_create(&$transaction, $values = array()) {
   if (isset($values['pay_node_nid']) && $nid = $values['pay_node_nid']) {
 
     // Verify that this node actually has a pay form and is the correct one.
-    if (!$pay_form = pay_node_form_load($nid)) return;
-    if ($pay_form->pfid != $transaction->pfid) return;
+    if (!$pay_form = pay_node_form_load($nid)) {
+      return;
+    }
+    if ($pay_form->pfid != $transaction->pfid) {
+      return;
+    }
 
     // Store a relationship between the transaction and the node it came from.
-    $record = array('nid' => $nid, 'pxid' => $transaction->pxid);
+    $record = array(
+      'nid' => $nid,
+      'pxid' => $transaction->pxid,
+    );
     drupal_write_record('pay_transaction_node', $record);
   }
 }
 
 /**
- * Implementation of hook_pay_transaction_delete().
+ * Implements hook_pay_transaction_delete().
  */
 function pay_node_pay_transaction_delete(&$transaction) {
-  db_query("DELETE FROM {pay_transaction_node}
-    WHERE pxid = %d", $transaction->pxid);
+  db_delete('pay_transaction_node')
+    ->condition('pxid', $transaction->pxid)
+    ->execute();
 }
 
 /**
  * A callback for node/x/pay which presents a payment form.
  */
-function pay_node_pay_form(&$form_state, $node) {
+function pay_node_pay_form($form, &$form_state, $node) {
   // Load the pay_form for this node, if it exists, and return a default form.
   if ($pay_form = pay_node_form_load($node)) {
     $form_state['pay_node'] = $node;
@@ -209,29 +276,37 @@ function pay_node_pay_form(&$form_state, $node) {
  */
 function pay_node_form_load($node) {
   // Allow this to work if we only get a nid.
-  if (is_scalar($node)) $node = node_load($node);
+  if (is_scalar($node)) {
+    $node = node_load($node);
+  }
 
   // Don't continue if pay_node settings aren't enabled for this node type.
-  if (!variable_get('pay_node_enabled_'. $node->type, FALSE)) return;
+  if (!variable_get('pay_node_enabled_' . $node->type, FALSE)) {
+    return;
+  }
 
   // Determine the pay_form handler for this type, and verify that it's enabled.
-  if (!$handler = variable_get('pay_node_form_'. $node->type, NULL)) return;
-  if (!array_key_exists($handler, array_filter(variable_get('pay_node_forms', array())))) return;
+  if (!$handler = variable_get('pay_node_form_' . $node->type, NULL)) {
+    return;
+  }
+  if (!array_key_exists($handler, array_filter(variable_get('pay_node_forms', array())))) {
+    return;
+  }
 
   // The linking method (create, select, etc.)
-  $method = variable_get('pay_node_method_'. $node->type, '');
+  $method = variable_get('pay_node_method_' . $node->type, '');
 
   // Load the pay_form that is associated with this node, if one exists.
   if ($node->nid) {
-    if ($pfid = db_result(db_query("SELECT pfid FROM {pay_form_node} n
+    if ($pfid = db_query("SELECT pfid FROM {pay_form_node} n
       INNER JOIN {pay_form} f USING ( pfid )
-      WHERE f.handler = '%s'
-      AND n.nid = %d
-      AND method = '%s'", $handler, $node->nid, $method))) {
+      WHERE f.handler = :f.handler
+      AND n.nid = :n.nid
+      AND method = :method", array(':f.handler' => $handler, ':n.nid' => $node->nid, ':method' => $method))->fetchField()) {
 
       if ($pay_form = pay_form_load($pfid)) {
         // Hard-code the payment form's URL.
-        $pay_form->set_menu_path('node/'. $node->nid .'/pay');
+        $pay_form->set_menu_path('node/' . $node->nid . '/pay');
       }
     }
 
@@ -246,7 +321,7 @@ function pay_node_form_load($node) {
 
     // The node is linked to a form. Use the default value.
     if ($method = 'select') {
-      if ($pfid = variable_get('pay_node_view_default_select_'. $node->type, '')) {
+      if ($pfid = variable_get('pay_node_view_default_select_' . $node->type, '')) {
         $pay_form = pay_form_load($pfid);
       }
     }
diff --git modules/pay_progress/pay_progress.info modules/pay_progress/pay_progress.info
index 19fa40c..ede3b67 100644
--- modules/pay_progress/pay_progress.info
+++ modules/pay_progress/pay_progress.info
@@ -2,11 +2,4 @@ name = Pay progress
 description = Progress bar for Pay forms
 package = Payment API
 dependencies[] = pay
-core = 6.x
-
-; Information added by drupal.org packaging script on 2011-05-09
-version = "6.x-1.1"
-core = "6.x"
-project = "pay"
-datestamp = "1304964416"
-
+core = 7.x
diff --git modules/pay_progress/pay_progress.module modules/pay_progress/pay_progress.module
index 834b3a0..abfbb34 100644
--- modules/pay_progress/pay_progress.module
+++ modules/pay_progress/pay_progress.module
@@ -6,7 +6,7 @@
  */
 
 /**
- * Implementation of hook_pay_form_displays_alter().
+ * Implements hook_pay_form_displays_alter().
  */
 function pay_progress_pay_form_displays_alter(&$displays) {
   $displays['pay_progress'] = array(
@@ -18,7 +18,7 @@ function pay_progress_pay_form_displays_alter(&$displays) {
 }
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function pay_progress_theme() {
   module_load_include('theme.inc', 'pay_progress', 'theme/pay_progress');
diff --git modules/pay_progress/theme/pay_progress.theme.inc modules/pay_progress/theme/pay_progress.theme.inc
index b7c6552..80e0a3f 100644
--- modules/pay_progress/theme/pay_progress.theme.inc
+++ modules/pay_progress/theme/pay_progress.theme.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -6,28 +7,33 @@
  */
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function pay_progress_theme_theme() {
-  $path = drupal_get_path('module', 'pay_progress') .'/theme';
+  $path = drupal_get_path('module', 'pay_progress') . '/theme';
   return array(
     'pay_progress' => array(
-      'arguments' => array('pay_form' => NULL, 'progress_type' => 'total'),
+      'variables' => array('pay_form' => NULL, 'progress_type' => 'total'),
       'template' => 'pay_progress',
       'pattern' => 'pay_progress__',
       'file' => 'pay_progress.theme.inc',
       'path' => $path,
     ),
     'pay_progress_total_paid' => array(
-      'arguments' => array('pay_form' => NULL),
+      'variables' => array('pay_form' => NULL),
       'file' => 'pay_progress.theme.inc',
       'path' => $path,
     ),
   );
 }
 
-function theme_pay_progress_total_paid($pay_form) {
-  return theme('pay_progress', $pay_form, 'total_pledged');
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function theme_pay_progress_total_paid($variables) {
+  $pay_form = $variables['pay_form'];
+  return theme('pay_progress', array('pay_form' => $pay_form, 'progress_type' => 'total_pledged'));
 }
 
 /**
@@ -41,7 +47,7 @@ function theme_pay_progress_total_paid($pay_form) {
  */
 function template_preprocess_pay_progress(&$variables, $hook) {
   // Add base CSS for progress bar theming
-  drupal_add_css(drupal_get_path('module', 'pay_progress') .'/theme/pay_progress.css');
+  drupal_add_css(drupal_get_path('module', 'pay_progress') . '/theme/pay_progress.css');
 
   $pay_form = $variables['pay_form'];
 
diff --git pay.info pay.info
index 5301e96..b775e0c 100644
--- pay.info
+++ pay.info
@@ -1,11 +1,4 @@
 name = Pay
 description = Pay for donations, orders or other nodes
 package = Payment API
-core = 6.x
-
-; Information added by drupal.org packaging script on 2011-05-09
-version = "6.x-1.1"
-core = "6.x"
-project = "pay"
-datestamp = "1304964416"
-
+core = 7.x
diff --git pay.install pay.install
index 0b97ab9..3773269 100644
--- pay.install
+++ pay.install
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -6,14 +7,9 @@
  * payment backends.
  */
 
-function pay_install() {
-  drupal_install_schema('pay');
-}
-
-function pay_uninstall() {
-  drupal_uninstall_schema('pay');
-}
-
+/**
+ * Implements hook_schema().
+ */
 function pay_schema() {
   $schema['pay_form'] = array(
     'fields' => array(
@@ -316,103 +312,127 @@ function pay_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;
+  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() {
-  $ret = array();
-  db_add_column($ret, 'pay_transaction', 'mail', 'varchar(200)');
-  return $ret;
+  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() {
-  $ret = array();
-  $spec = array('type' => 'int', 'size' => 'tiny', 'default' => 0);
-  db_add_field($ret, 'pay_form', 'embeddable', $spec);
-  return $ret;
+  $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() {
-  $ret = array();
   $spec = array(
     'type' => 'varchar',
     'length' => 20,
     'not null' => TRUE,
     'default' => 'pending',
   );
-  db_add_field($ret, 'pay_transaction', 'state', $spec);
+  db_add_field('pay_transaction', 'state', $spec);
 
   // Set some default values for existing transactions.
 
   // Complete if total == total_paid.
-  $ret[] = update_sql("UPDATE {pay_transaction}
-    SET state = 'complete' WHERE 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.
-  $ret[] = update_sql("UPDATE {pay_transaction}
-    SET state = 'canceled' WHERE total > 0 AND 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.
-  $ret[] = update_sql("UPDATE {pay_transaction}
-    SET state = 'active' WHERE total > 0 AND total_paid > 0 AND total != total_paid");
+  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.
-  $ret[] = update_sql("UPDATE {pay_transaction} t, {pay_activity} a
-    SET state = 'pending'
-    WHERE t.pxid = a.pxid AND t.state = 'canceled' AND a.result = '1'");
+  $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 $ret;
+  return t('Add a "state" column to the pay_transaction table.');
 }
 
 /**
  * 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;
+  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() {
-  $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}
-        SET settings = '%s' WHERE pmid = %d", serialize($settings), $row->pmid);
+      db_update('pay_method')
+        ->fields(array(
+          'settings' => serialize($settings),
+        ))
+        ->condition('pmid', $row->pmid)
+        ->execute();
     }
   }
-  return $ret;
+  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() {
-  $ret = array();
-  update_sql("DELETE FROM {actions} WHERE TYPE = 'pay_transaction'");
-  return $ret;
+  db_delete('actions')
+    ->condition('type', "pay_transaction")
+    ->execute();
+  return t('Removed my actions from the actions table so that they get re-read.');
 }
+
diff --git pay.module pay.module
index 365f670..70509d4 100644
--- pay.module
+++ pay.module
@@ -6,75 +6,108 @@
  */
 
 /**
- * Implementation of hook_init().
+ * Implements hook_init().
  */
 function pay_init() {
+  $path = drupal_get_path('module', 'pay');
   if (module_exists('trigger')) {
-    include_once dirname(__FILE__) .'/includes/pay.trigger.inc';
+    module_load_include('inc', 'pay', 'includes/pay.trigger');
   }
   if (module_exists('token')) {
-    include_once dirname(__FILE__) .'/includes/pay.token.inc';
+    module_load_include('inc', 'pay', 'includes/pay.token');
   }
 
-  include_once dirname(__FILE__) .'/includes/pay.action.inc';
+  module_load_include('inc', 'pay', 'includes/pay.action');
 }
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function pay_menu() {
-  module_load_include('menu.inc', 'pay', 'includes/pay');
+  module_load_include('inc', 'pay', 'includes/pay.menu');
   return pay_menu_menu();
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
-function pay_perm() {
+function pay_permission() {
   // Permissions based on form types and global settings.
   $permissions = array(
-    'view reports for any payment form',
-    'administer pay',
-    'administer payments for any form',
-    'make payments on any form',
+    'view reports for any payment form' => array(
+      'title' => t('view reports for any payment form'),
+      'description' => t('View reports for any payment form'),
+    ),
+    'administer pay' => array(
+      'title' => t('administer pay'),
+      'description' => t('Administer pay module'),
+    ),
+    'administer payments for any form' => array(
+      'title' => t('administer payments for any form'),
+      'description' => t('Administer payments for any pay module form'),
+    ),
+    'make payments on any form' => array(
+      'title' => t('make payments on any form'),
+      'description' => t('Make payments on any pay module form'),
+    ),
   );
 
   foreach (pay_handlers('pay_form') as $name => $info) {
-    $permissions[] = 'administer payments for '. $name .' forms';
-    $permissions[] = 'make payments on '. $name .' forms';
-    $permissions[] = 'view reports for '. $name .' forms';
+    $permissions[] = 'administer payments for ' . $name . ' forms';
+    $permissions[] = 'make payments on ' . $name . ' forms';
+    $permissions[] = 'view reports for ' . $name . ' forms';
   }
 
   return $permissions;
 }
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function pay_theme() {
-  module_load_include('theme.inc', 'pay', 'theme/pay');
+  module_load_include('inc', 'pay', 'theme/pay.theme');
   return pay_theme_theme();
 }
 
 /**
- * Implementation of hook_user().
+ * Implements hook_user_categories().
  */
-function pay_user($op, &$edit, &$account, $category = NULL) {
-  switch ($op) {
-    case 'categories':
-      // Return only a modes 'category' entry - the real work happens in the
-      // page callback for payment settings.  See also hook_menu.
-      return array(array( 'name' => 'pay' ));
+function pay_user_categories() {
+  // Return only a modes 'category' entry - the real work happens in the
+  // page callback for payment settings.  See also hook_menu.
+  return array(array(
+    'name' => 'pay',
+    'title' => 'Payments',
+    'weight' => 10,
+  ));
+}
 
-    case 'delete':
-      // Deactivate any payment forms this user may have created.
-      db_query("UPDATE {pay_form} SET status = 0, uid = 0 WHERE uid = %d", $account->uid);
+/**
+ * Implements hook_user_cancel().
+ */
+function pay_user_cancel($edit, $account, $method) {
+  // Deactivate any payment forms this user may have created.
+  db_update('pay_form')
+    ->fields(array(
+      'status' => 0,
+      'uid' => 0,
+    ))
+    ->condition('uid', $account->uid)
+    ->execute();
 
-      // Remove reference to this user's uid in transaction history.
-      db_query("UPDATE {pay_transaction} SET uid = 0 WHERE uid = %d", $account->uid);
-      db_query("UPDATE {pay_activity} SET uid = 0 WHERE uid = %d", $account->uid);
-      break;
-  }
+  // Remove reference to this user's uid in transaction history.
+  db_update('pay_transaction')
+    ->fields(array(
+      'uid' => 0,
+    ))
+    ->condition('uid', $account->uid)
+    ->execute();
+  db_update('pay_activity')
+    ->fields(array(
+      'uid' => 0,
+    ))
+    ->condition('uid', $account->uid)
+    ->execute();
 }
 
 /**
@@ -85,7 +118,9 @@ function pay_user_settings_access($account) {
   // Permit access if any module returns TRUE in hook_pay_user_settings_access()
   foreach (module_implements('pay_user_settings_access') as $module) {
     $func = $module . '_pay_user_settings_access';
-    if ($func($account)) return TRUE;
+    if ($func($account)) {
+      return TRUE;
+    }
   }
 
   // Return FALSE by default, thus hiding the 'Payment settings' form.
@@ -98,14 +133,14 @@ function pay_user_settings_access($account) {
  * @ingroup forms
  */
 function pay_user_settings_page($account, $category = 'default') {
-  drupal_set_title(check_plain($account->name));
+  drupal_set_title($account->name);
   return drupal_get_form('pay_user_settings_form', $account, $category);
 }
 
 /**
  * A form callback for a user's 'Payment settings' page.
  */
-function pay_user_settings_form(&$form_state, $account, $category = 'default') {
+function pay_user_settings_form($form, &$form_state, $account, $category = 'default') {
   $form = array();
 
   // Rely on whatever the underlying hooks might return.
@@ -123,12 +158,12 @@ function pay_user_settings_form(&$form_state, $account, $category = 'default') {
 }
 
 /**
- * Implementation of hook_views_api().
+ * Implements hook_views_api().
  */
 function pay_views_api() {
   return array(
     'api' => 2,
-    'path' => drupal_get_path('module', 'pay') .'/includes/views',
+    'path' => drupal_get_path('module', 'pay') . '/includes/views',
   );
 }
 
@@ -136,16 +171,22 @@ function pay_views_api() {
  * API Function: All available payment handlers.
  */
 function pay_handlers($type, $handler_name = NULL, $refresh = FALSE) {
-  static $handlers = array();;
+  static $handlers = array();
   if ($refresh || !isset($handlers[$type])) {
-    module_load_include('handlers.inc', 'pay', 'includes/pay');
-    $handlers[$type] = module_invoke_all($type .'_handler_info');
+    module_load_include('inc', 'pay', 'includes/pay.handlers');
+    $handlers[$type] = module_invoke_all($type . '_handler_info');
     foreach ($handlers[$type] as $name => $info) {
-      if (!isset($info['module'])) $handlers[$type][$name]['module'] = $name;
-      if (!isset($info['handler'])) $handlers[$type][$name]['handler'] = $name;
+      if (!isset($info['module'])) {
+        $handlers[$type][$name]['module'] = $name;
+      }
+      if (!isset($info['handler'])) {
+        $handlers[$type][$name]['handler'] = $name;
+      }
     }
   }
-  if ($handler_name) return $handlers[$type][$handler_name];
+  if ($handler_name) {
+    return $handlers[$type][$handler_name];
+  }
 
   return $handlers[$type];
 }
@@ -159,27 +200,33 @@ function pay_load_handler($type, $name) {
   if (!isset($cache[$type])) {
     // Base classes for handlers.
     module_load_include('inc', 'pay', 'includes/handlers/pay');
-    module_load_include('inc', 'pay', 'includes/handlers/'. $type);
+    module_load_include('inc', 'pay', 'includes/handlers/' . $type);
     $cache[$type] = array();
   }
 
   // This is a pay primitive class, so we're done.
-  if ($type == $name) return TRUE;
+  if ($type == $name) {
+    return TRUE;
+  }
 
   // Already loaded.
-  if (isset($cache[$type][$name])) return $cache[$type][$name];
+  if (isset($cache[$type][$name])) {
+    return $cache[$type][$name];
+  }
 
   if ($name && $handler = pay_handlers($type, $name)) {
     // Ensure the parent is loaded.
-    if (isset($handler['parent'])) pay_load_handler($type, $handler['parent']);
+    if (isset($handler['parent'])) {
+      pay_load_handler($type, $handler['parent']);
+    }
 
     // Respect the 'path' element that may have been specified.
-    $file = isset($handler['path']) ? $handler['path'] .'/' : '';
-    $file .= $name .'.inc';
+    $file = isset($handler['path']) ? $handler['path'] . '/' : '';
+    $file .= $name . '.inc';
 
     // Require the file, if it exists.
     if ($cache[$type][$name] = is_file($file)) {
-      require_once($file);
+      require_once DRUPAL_ROOT . '/' . $file;
     }
     return $cache[$type][$name];
   }
@@ -187,18 +234,32 @@ function pay_load_handler($type, $name) {
 
 /**
  * API Function: Load a payment class.
+ *
+ * This function was renamed in D7 as to not collide with hook_load().
  */
-function pay_load($type, $values = NULL) {
+function pay_load_object($type, $values = NULL) {
   if (is_scalar($values)) {
     if (is_numeric($values)) {
-      if ($type == 'pay_form') $key = 'pfid';
-      if ($type == 'pay_method') $key = 'pmid';
-      if ($type == 'pay_item') $key = 'piid';
-      if ($type == 'pay_transaction') $key = 'pxid';
-      if ($type == 'pay_activity') $key = 'paid';
-      if ($values = db_fetch_object(db_query("SELECT * from {%s}
-        WHERE $key = %d", $type, $values))) {
-
+      if ($type == 'pay_form') {
+        $key = 'pfid';
+      }
+      if ($type == 'pay_method') {
+        $key = 'pmid';
+      }
+      if ($type == 'pay_item') {
+        $key = 'piid';
+      }
+      if ($type == 'pay_transaction') {
+        $key = 'pxid';
+      }
+      if ($type == 'pay_activity') {
+        $key = 'paid';
+      }
+      $result = db_select($type, 't')
+        ->fields('t')
+        ->condition($key, $values)
+        ->execute();
+      if ($values = $result->fetchObject()) {
         $handler = isset($values->handler) ? $values->handler : $type;
       }
       else {
@@ -217,9 +278,9 @@ function pay_load($type, $values = NULL) {
       $handler = $values->handler;
     }
     elseif (isset($values->pmid)) {
-      $handler_values = pay_load($type, $values->pmid);
+      $handler_values = pay_load_object($type, $values->pmid);
       $handler = get_class($handler_values);
-      $values = array_merge((array)$handler_values, (array)$values);
+      $values = array_merge((array) $handler_values, (array) $values);
     }
     else {
       // Allow return of a generic object of the type requested.
@@ -235,35 +296,35 @@ function pay_load($type, $values = NULL) {
  * API Function: Load a payment form object.
  */
 function pay_form_load($values = NULL) {
-  return pay_load('pay_form', $values);
+  return pay_load_object('pay_form', $values);
 }
 
 /**
  * API Function: Load a payment method object.
  */
 function pay_method_load($values = NULL) {
-  return pay_load('pay_method', $values);
+  return pay_load_object('pay_method', $values);
 }
 
 /**
  * API Function: Load a payment transaction object.
  */
 function pay_transaction_load($values = NULL) {
-  return pay_load('pay_transaction', $values);
+  return pay_load_object('pay_transaction', $values);
 }
 
 /**
  * API Function: Load a payment item object.
  */
 function pay_item_load($values = NULL) {
-  return pay_load('pay_item', $values);
+  return pay_load_object('pay_item', $values);
 }
 
 /**
  * API Function: Load a payment activity object.
  */
 function pay_activity_load($values = NULL) {
-  return pay_load('pay_activity', $values);
+  return pay_load_object('pay_activity', $values);
 }
 
 /**
@@ -274,9 +335,13 @@ function pay_activity_load($values = NULL) {
  *
  * Alternatively, you can manually add payment form capabilities by including
  * the code from this function in your form builder or form_alter code.
+ *
+ * TODO Rename this function as to not collide with hook_form().
  */
 function pay_form(&$form_state, $pay, $type = NULL, $form_type = 'default') {
-  if ($type) $pay = pay_load($type, $pay);
+  if ($type) {
+    $pay = pay_load_object($type, $pay);
+  }
 
   // Add a "build mode" to $form_state so that the form handlers can render
   // forms differently based on user-defined context.
@@ -307,7 +372,7 @@ function pay_after_build($form, &$form_state) {
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
  * Pass the form to any applicable pay handlers in case they have some input.
  */
 function pay_form_alter(&$form, &$form_state, $form_id) {
@@ -335,9 +400,9 @@ function pay_submit($form, &$form_state) {
 function pay_form_callback($callback, &$form, &$form_state) {
   if (isset($form['#pay'])) {
     foreach ($form['#pay'] as $key => $item) {
-      if ($pay = pay_load($item['type'], $item)) {
+      if ($pay = pay_load_object($item['type'], $item)) {
         $func = isset($item['form']) ? $item['form'] : 'form';
-        $func .= '_'. $callback;
+        $func .= '_' . $callback;
         if (method_exists($pay, $func)) {
           $pay->$func($form, $form_state);
         }
@@ -394,31 +459,32 @@ function pay_form_displays_list() {
 
 /**
  * List available payment forms.
+ *
+ * Renamed in D7 to avoid conflict with hook_forms().
  */
-function pay_forms($handler = NULL, $embeddable = NULL, $status = 1) {
-  $where = $args = array();
+function pay_forms_list($handler = NULL, $embeddable = NULL, $status = 1) {
+  $query = db_select('pay_form', 'pf')
+           ->fields('pf');
   if (!is_null($handler)) {
-    $where[] = "handler = '%s'";
-    $args[]  = $handler;
+    $query->condition('handler', $handler);
   }
   if (!is_null($status)) {
-    $where[] = "status = %d";
-    $args[]  = $status;
+    $query->condition('status', $status);
   }
   if (!is_null($embeddable)) {
-    $where[] = "embeddable = %d";
-    $args[]  = $embeddable;
+    $query->condition('embeddable', $embeddable);
   }
-  $sql = "SELECT * FROM {pay_form}";
-  if ($where) $sql .= ' WHERE '. join(' AND ', $where);
-  $sql .= " ORDER BY title";
+  $query->orderBy('title');
 
-  $forms = array();
-  $res = db_query($sql, $args);
+  $result = $query->execute();
 
-  while ($row = db_fetch_object($res)) {
-    if ($pay_form = pay_form_load($row)) $forms[$row->pfid] = $pay_form;
+  $forms = array();
+  while ($row = $result->fetchObject()) {
+    if ($pay_form = pay_form_load($row)) {
+      $forms[$row->pfid] = $pay_form;
+    }
   }
+
   return $forms;
 }
 
@@ -452,7 +518,9 @@ function pay_currency_list() {
     }
 
     // Create a sorted key => value array.
-    foreach ($currencies as $item) $list[$item] = $item;
+    foreach ($currencies as $item) {
+      $list[$item] = $item;
+    }
     ksort($list);
     drupal_alter('pay_currency_list', $list);
   }
@@ -480,7 +548,9 @@ function pay_transaction_states($state = NULL) {
     }
   }
 
-  if (isset($state)) return $states[$state];
+  if (isset($state)) {
+    return $states[$state];
+  }
   return $states;
 }
 
@@ -489,7 +559,9 @@ function pay_transaction_states($state = NULL) {
  */
 function pay_transaction_state_name($state) {
   // It's a transaction object?  Function as a wrapper for its state() method.
-  if (is_object($state)) return $state->state(TRUE);
+  if (is_object($state)) {
+    return $state->state(TRUE);
+  }
 
   // Or else just return the label based on this name.
   return pay_transaction_states($state);
@@ -500,12 +572,18 @@ function pay_transaction_state_name($state) {
  */
 function pay_transaction_valid_action($pay_transaction, $action) {
   // Not a valid action for this transaction.  Skip it and return FALSE.
-  if (!$pay_transaction->valid_action($action)) return FALSE;
+  if (!$pay_transaction->valid_action($action)) {
+    return FALSE;
+  }
 
   // Return TRUE for payment administrators for this/all forms.
-  if (user_access('administer payments for any form')) return TRUE;
+  if (user_access('administer payments for any form')) {
+    return TRUE;
+  }
   $handler = $pay_transaction->pay_form()->handler();
-  if (user_access('administer payments for ' . $handler .' forms')) return TRUE;
+  if (user_access('administer payments for ' . $handler . ' forms')) {
+    return TRUE;
+  }
 
   // Give up and return false.
   return FALSE;
@@ -517,14 +595,18 @@ function pay_transaction_valid_action($pay_transaction, $action) {
 function pay_transaction_do_action($transaction, $action, $path = FALSE) {
   if ($transaction->do_action($action)) {
     $info = $transaction->valid_actions[$action];
-    if ($info['message']) drupal_set_message($info['message']);
+    if ($info['message']) {
+      drupal_set_message($info['message']);
+    }
   }
 
   // Redirect to the transaction page or the front page if it has been deleted.
   if ($path) {
     if ($path === TRUE) {
       $path = 'pay/transaction/' . $transaction->pxid;
-      if ($action == 'delete') $path = '<front>';
+      if ($action == 'delete') {
+        $path = '<front>';
+      }
     }
     drupal_goto($path);
   }
diff --git theme/pay.theme.inc theme/pay.theme.inc
index 1566ae8..7d25116 100644
--- theme/pay.theme.inc
+++ theme/pay.theme.inc
@@ -1,4 +1,5 @@
-<?php // $Id$
+<?php
+// $Id$
 
 /**
  * @file
@@ -9,69 +10,72 @@
  * Implementation of hook_theme().
  */
 function pay_theme_theme() {
-  $path = drupal_get_path('module', 'pay') .'/theme';
+  $path = drupal_get_path('module', 'pay') . '/theme';
 
   return array(
     // The all-purpose form renderer for payment forms.
     'pay_form' => array(
-      'arguments' => array('form' => array()),
+      'variables' => array('form' => array()),
       'template' => 'pay_form',
       'pattern' => 'pay_form__',
       'path' => $path,
     ),
     'pay_form_default' => array(
-      'arguments' => array('pay_form' => array()),
+      'variables' => array('pay_form' => array()),
       'file' => 'pay.theme.inc',
       'path' => $path,
     ),
     'pay_form_amount' => array(
-      'arguments' => array('pay_form' => array()),
+      'variables' => array('pay_form' => array()),
       'template' => 'pay_form_amount',
       'pattern' => 'pay_form_amount__',
       'file' => 'pay.theme.inc',
       'path' => $path,
     ),
     'pay_form_link' => array(
-      'arguments' => array('pay_form' => array()),
+      'variables' => array('pay_form' => array(), 'text' => 'Make a payment'),
       'file' => 'pay.theme.inc',
       'path' => $path,
     ),
     'pay_transaction' => array(
-      'arguments' => array('pay_transaction' => array()),
+      'variables' => array('pay_transaction' => array()),
       'template' => 'pay_transaction',
       'pattern' => 'pay_transaction__',
       'file' => 'pay.theme.inc',
       'path' => $path,
     ),
     'pay_cc_form' => array(
-      'arguments' => array('element' => array()),
+      'render element' => 'element',
       'template' => 'pay_cc_form',
       'pattern' => 'pay_cc_form__',
       'file' => 'pay.theme.inc',
       'path' => $path,
     ),
     'pay_money' => array(
-      'arguments' => array('value' => 0, 'currency' => 'USD'),
+      'variables' => array('value' => 0, 'currency' => 'USD'),
       'file' => 'pay.theme.inc',
       'path' => $path,
     ),
     'pay_activity_list' => array(
-      'arguments' => array('activity' => array()),
-    )
+      'variables' => array('activity' => array()),
+    ),
   );
 }
 
 /**
  * Theme function for default form displays.
  */
-function theme_pay_form_default($pay_form) {
+function theme_pay_form_default($variables) {
+  $pay_form = $variables['pay_form'];
   return drupal_get_form('pay_form', $pay_form);
 }
 
 /**
  * Theme function for links to payment forms.
  */
-function theme_pay_form_link($pay_form, $text = 'Make a payment') {
+function theme_pay_form_link($variables) {
+  $pay_form = $variables['pay_form'];
+  $text = $variables['text'];
   if ($path = $pay_form->menu_path()) {
     $link = array(
       'title' => $text,
@@ -91,7 +95,7 @@ function template_preprocess_pay_transaction(&$variables) {
   $pay_transaction = $variables['pay_transaction'];
   $variables['pay_form'] = pay_form_load($pay_transaction->pfid);
 
-  $variables['date'] = format_date($pay_transaction->created, 'small');
+  $variables['date'] = format_date($pay_transaction->created, 'short');
   $variables['user'] = user_load($pay_transaction->uid);
   $variables['notes'] = $pay_transaction->notes();
   $variables['id'] = $pay_transaction->pxid;
@@ -100,13 +104,16 @@ function template_preprocess_pay_transaction(&$variables) {
     $links = array();
     foreach ($actions as $name => $info) {
       $href = 'pay/transaction/' . $pay_transaction->pxid . '/' . $name;
-      $links[$name] = array('href' => $href, 'title' => t($info['title']));
+      $links[$name] = array(
+        'href' => $href,
+        'title' => t($info['title']),
+      );
     }
     $variables['actions'] = theme_links($links, array('class' => 'pay-transaction-links'));
   }
 
   if ($activity = $pay_transaction->activity()) {
-    $variables['activity'] = theme('pay_activity_list', $activity);
+    $variables['activity'] = theme('pay_activity_list', array('activity' => $activity));
   }
 }
 
@@ -124,12 +131,17 @@ function template_preprocess_pay_cc_form(&$variables) {
   if ($variables['element']['cc_type']) {
     $path = drupal_get_path('module', 'pay') . '/theme/images/';
     foreach ($variables['element']['cc_type']['#options'] as $card => $label) {
-      $variables['element']['cc_type'][$card]['#title'] = theme('image', $path. $card .'.png', $label);
+      if (empty($card)) continue;
+      $variables['element']['cc_type_image'][$card] = array(
+        '#type' => 'markup',
+        '#markup' => theme('image', array('path' => $path . $card . '.png', 'width' => $label)),
+      );
     }
   }
 
   // Elements that will be specifically included by the theme template.
   $expected = array(
+    'cc_type_image',
     'cc_type',
     'first_name',
     'last_name',
@@ -142,6 +154,7 @@ function template_preprocess_pay_cc_form(&$variables) {
   );
 
   $variables['pay']['prefix'] = $variables['pay']['suffix'] = array();
+  $printed = FALSE;
   foreach (element_children($variables['element']) as $item) {
     if (in_array($item, $expected)) {
       $variables['pay'][$item] = drupal_render($variables['element'][$item]);
@@ -157,18 +170,20 @@ function template_preprocess_pay_cc_form(&$variables) {
 
   if ($first_time) {
     $variables['setup'] = $first_time;
-    $first_time = FALSE;  }
+    $first_time = FALSE;
+  }
   else {
     $variables['setup'] = FALSE;
   }
 
-  $variables['pay_form'] = join('', $variables['pay']);
+  $variables['pay_form'] = $variables['pay'];
 }
 
 /**
  * Theme function for default money format.
  */
-function theme_pay_activity_list($activity_list) {
+function theme_pay_activity_list($variables) {
+  $activity_list = $variables['activity'];
 
   $hdrs = array(
     t('Date'),
@@ -192,23 +207,25 @@ function theme_pay_activity_list($activity_list) {
     }
 
     $row = array(
-      format_date($activity->timestamp, 'small'),
-      $account->uid ? l($account->name, 'user/'. $account->uid) : '-',
+      format_date($activity->timestamp, 'short'),
+      $account->uid ? l($account->name, 'user/' . $account->uid) : '-',
       $activity->pay_method()->title(),
-      theme('pay_money', $activity->total, $currency),
-      theme('pay_money', $activity->balance(), $currency),
+      theme('pay_money', array('value' => $activity->total, 'currency' => $currency)),
+      theme('pay_money', array('value' => $activity->balance(), 'currency' => $currency)),
       $comment,
     );
 
     $rows[] = $row;
   }
-  return theme('table', $hdrs, $rows);
+  return theme('table', array('header' => $hdrs, 'rows' => $rows));
 }
 
 /**
  * Theme function for default money format.
  */
-function theme_pay_money($value, $currency) {
+function theme_pay_money($variables) {
+  $value = $variables['value'];
+  $currency = $variables['currency'];
   //@todo: Add some logic for handling currencies?
   if ($currency == 'USD' || (!$currency)) {
     $symbol = '$';
diff --git theme/pay_cc_form.tpl.php theme/pay_cc_form.tpl.php
index 7560a6a..b815f5e 100644
--- theme/pay_cc_form.tpl.php
+++ theme/pay_cc_form.tpl.php
@@ -7,6 +7,7 @@
  *
  *  - $element: The full form array.
  *  - $pay_form: The entire rendered form.
+ *  - $pay['cc_type_image']: The credit card type images..
  *  - $pay['cc_type']: The credit card type selection.
  *  - $pay['first_name']: The first name of the card holder.
  *  - $pay['last_name']: The last name of the card holder.
@@ -25,31 +26,40 @@ if ($setup) {
 }
 ?>
 
-<?php if ($pay['prefix']) :?>
+<?php if (!empty($pay['prefix'])) :?>
   <div class="pay-cc-form-prefix">
-    <?php foreach($pay['prefix'] as $item):?>
+    <?php foreach ($pay['prefix'] as $item):?>
         <?php print $item; ?>
     <?php endforeach?>
   </div>
 <?php endif?>
 <div class="pay-cc-form">
+  <?php if (!empty($pay['first_name']) || !empty($pay['last_name'])) :?>
   <div class="pay-cc-name">
-    <div class="pay-cc-first-name cc-name">
-      <?php print $pay['first_name']; ?>
-    </div>
-    <div class="pay-cc-last-name cc-name">
-      <?php print $pay['last_name']; ?>
-    </div>
-  </div>
-  <div class="pay-cc-mail cc-mail">
-    <?php print $pay['mail']; ?>
+    <?php if (!empty($pay['first_name'])) :?>
+      <div class="pay-cc-first-name cc-name">
+        <?php print $pay['first_name']; ?>
+      </div>
+    <?php endif; ?>
+    <?php if (!empty($pay['last_name'])) :?>
+      <div class="pay-cc-last-name cc-name">
+        <?php print $pay['last_name']; ?>
+      </div>
+    <?php endif; ?>
   </div>
-  <?php if ($pay['billto']) :?>
+  <?php endif; ?>
+  <?php if (!empty($pay['mail'])) :?>
+    <div class="pay-cc-mail cc-mail">
+      <?php print $pay['mail']; ?>
+    </div>
+  <?php endif; ?>
+  <?php if (!empty($pay['billto'])) :?>
     <div class="pay-cc-billto cc-billto">
       <?php print $pay['billto']; ?>
     </div>
   <?php endif ?>
   <div class="pay-cc-type">
+    <?php print $pay['cc_type_image']; ?>
     <?php print $pay['cc_type']; ?>
   </div>
   <div class="pay-cc-info">
@@ -59,7 +69,7 @@ if ($setup) {
     <div class="pay-cc-ccv2 cc-info">
       <?php print $pay['cc_ccv2']; ?>
     </div>
-    <?php if ($pay['cc_issue_number']) :?>
+    <?php if (!empty($pay['cc_issue_number'])) :?>
       <div class="pay-cc-issue-number cc-issue-number cc-info">
         <?php print $pay['cc_issue_number']; ?>
       </div>
@@ -75,9 +85,9 @@ if ($setup) {
   </div>
 </div>
 <div class="clear"></div>
-<?php if ($pay['suffix']) :?>
+<?php if (!empty($pay['suffix'])) :?>
   <div class="pay-cc-form-suffix">
-    <?php foreach($pay['suffix'] as $item):?>
+    <?php foreach ($pay['suffix'] as $item):?>
         <?php print $item; ?>
     <?php endforeach?>
   </div>
