diff --git a/includes/handlers/pay.inc b/includes/handlers/pay.inc
index 0e6bc8b..2195e82 100644
--- a/includes/handlers/pay.inc
+++ b/includes/handlers/pay.inc
@@ -87,7 +87,7 @@ class pay {
 
   function timestamp_value($val = NULL) {
     if (!$val) {
-      $val = time();
+      $val = REQUEST_TIME;
     }
     if (!is_numeric($val)) {
       $val = strtotime($val);
@@ -163,7 +163,7 @@ class pay {
   }
 
   function user() {
-    return user_load(array('uid' => $this->uid()));
+    return user_load($this->uid());
   }
 
   function total() {
@@ -179,22 +179,35 @@ class pay {
 
   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);
     }
   }
 
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_transaction() {
     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);
@@ -225,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;
@@ -236,7 +253,7 @@ class pay {
       '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;
 
@@ -294,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);
@@ -319,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',
@@ -342,19 +363,24 @@ class pay {
       $permissions[] = 'make payments on ' . $name . ' forms';
     }
     foreach ($permissions as $name) {
+      $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) {
+      $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;
   }
diff --git a/includes/handlers/pay_activity.inc b/includes/handlers/pay_activity.inc
index 6e50572..1e41839 100644
--- a/includes/handlers/pay_activity.inc
+++ b/includes/handlers/pay_activity.inc
@@ -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 a/includes/handlers/pay_form.inc b/includes/handlers/pay_form.inc
index c54b1d8..b15d63d 100644
--- a/includes/handlers/pay_form.inc
+++ b/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,6 +32,11 @@ 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);
@@ -122,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;
@@ -195,6 +204,10 @@ class pay_form extends pay {
      */
   }
 
+  /**
+   * @todo Please document this function.
+   * @see http://drupal.org/node/1354
+   */
   function pay_methods() {
     $methods = array();
     foreach ($this->pay_methods as $pmid => $status) {
@@ -208,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();
@@ -437,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() {
@@ -449,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 a/includes/handlers/pay_method.inc b/includes/handlers/pay_method.inc
index c8f68c9..e77e21a 100644
--- a/includes/handlers/pay_method.inc
+++ b/includes/handlers/pay_method.inc
@@ -95,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'];
+      }
     }
   }
 
@@ -108,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'];
+      }
     }
   }
 
@@ -156,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 a/includes/handlers/pay_method_gateway.inc b/includes/handlers/pay_method_gateway.inc
index 6d324d4..0bb1906 100644
--- a/includes/handlers/pay_method_gateway.inc
+++ b/includes/handlers/pay_method_gateway.inc
@@ -128,9 +128,10 @@ class pay_method_gateway extends pay_method {
 
   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;
       }
@@ -294,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)) {
@@ -532,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);
 
@@ -548,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 a/includes/handlers/pay_transaction.inc b/includes/handlers/pay_transaction.inc
index 2abc7ed..5192778 100644
--- a/includes/handlers/pay_transaction.inc
+++ b/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;
 
@@ -67,6 +67,11 @@ class pay_transaction extends pay {
     }
   }
 
+  function set_notes_format() {
+    $this->notes_format = filter_fallback_format();
+    return $this->notes_format;
+  }
+
   /**
    * Return the current state of this transaction.
    */
@@ -217,8 +222,8 @@ class pay_transaction extends pay {
     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);
     }
@@ -260,11 +265,11 @@ class pay_transaction extends pay {
 
   function update_status($state = NULL, $timestamp = NULL) {
     if (!$timestamp) {
-      $timestamp = time();
+      $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.
@@ -289,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;
@@ -306,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;
   }
diff --git a/includes/pay.action.inc b/includes/pay.action.inc
index 16a65f5..249e01a 100644
--- a/includes/pay.action.inc
+++ b/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 a/includes/pay.admin.inc b/includes/pay.admin.inc
index 80913ce..a27a1cd 100644
--- a/includes/pay.admin.inc
+++ b/includes/pay.admin.inc
@@ -10,11 +10,13 @@
  * 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)) {
@@ -23,15 +25,19 @@ function pay_admin_overview() {
     $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;
 }
@@ -39,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();
 
@@ -50,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(
@@ -76,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();
   }
 }
 
@@ -152,7 +165,7 @@ 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),
@@ -168,13 +181,13 @@ function pay_admin_pay_form_list($handler = NULL, $uid = NULL) {
     $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'];
   }
@@ -192,10 +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']) {
+      if (empty($info['title'])) {
         continue; // Exclude unnamed base classes.
       }
+      $options[$name] = $name;
       $form['pay_method'][$name] = array(
         '#type' => 'radio',
         '#name' => 'pay_method',
@@ -204,6 +219,7 @@ function pay_admin_method_form(&$form_state, $pay_method = NULL) {
         '#return_value' => $name,
       );
     }
+    $form['pay_method']['#options'] = $options;
   }
 
   $form['submit'] = array(
@@ -211,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;
@@ -220,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;
@@ -230,7 +247,7 @@ 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']);
   }
 }
diff --git a/includes/pay.menu.inc b/includes/pay.menu.inc
index a93653f..4d2cd44 100644
--- a/includes/pay.menu.inc
+++ b/includes/pay.menu.inc
@@ -11,7 +11,17 @@
  */
 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'),
@@ -19,12 +29,12 @@ function pay_menu_menu() {
       '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'),
@@ -33,18 +43,18 @@ function pay_menu_menu() {
       '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',
     ),
-    '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 a/includes/pay.trigger.inc b/includes/pay.trigger.inc
index 7effdb6..6eb3402 100644
--- a/includes/pay.trigger.inc
+++ b/includes/pay.trigger.inc
@@ -7,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 +63,7 @@ function pay_pay_transaction_complete(&$transaction) {
 function pay_actions_do($hook, &$object) {
   if (module_exists('trigger')) {
     $context = array();
-    foreach (_trigger_get_hook_aids('pay', $hook) as $aid => $action_info) {
+    foreach (trigger_get_assigned_actions('pay') as $aid => $action_info) {
       if ($aid) {
         actions_do($aid, $object, $context);
       }
diff --git a/includes/views/pay_handler_field_handler.inc b/includes/views/pay_handler_field_handler.inc
index 15a448f..93514e9 100644
--- a/includes/views/pay_handler_field_handler.inc
+++ b/includes/views/pay_handler_field_handler.inc
@@ -12,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 a/includes/views/pay_handler_field_pay_form.inc b/includes/views/pay_handler_field_pay_form.inc
index ce17533..c67bbb0 100644
--- a/includes/views/pay_handler_field_pay_form.inc
+++ b/includes/views/pay_handler_field_pay_form.inc
@@ -29,7 +29,7 @@ class pay_handler_field_pay_form extends views_handler_field {
     if ($this->table != $this->query->base_table) {
       $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
@@ -39,6 +39,7 @@ class pay_handler_field_pay_form extends views_handler_field {
         $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 a/includes/views/pay_handler_filter_amount.inc b/includes/views/pay_handler_filter_amount.inc
index 7b1e2d3..086a3f2 100644
--- a/includes/views/pay_handler_filter_amount.inc
+++ b/includes/views/pay_handler_filter_amount.inc
@@ -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']);
       }
     }
 
diff --git a/modules/pay_node/includes/pay_node.admin.inc b/modules/pay_node/includes/pay_node.admin.inc
index 15d62a1..4144abc 100644
--- a/modules/pay_node/includes/pay_node.admin.inc
+++ b/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,6 +50,10 @@ function pay_node_admin_settings(&$form_state) {
   return system_settings_form($form);
 }
 
+/**
+ * @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())));
@@ -66,7 +70,7 @@ function pay_node_admin_node_type_form_alter(&$form, &$form_state) {
   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;
   }
@@ -126,7 +130,7 @@ function pay_node_admin_node_type_form_alter(&$form, &$form_state) {
     );
 
     $embeddable = array('' => ' - None -');
-    foreach (pay_forms(NULL, TRUE) as $pay_form) {
+    foreach (pay_forms_list(NULL, TRUE) as $pay_form) {
       $embeddable[$pay_form->pfid] = $pay_form->title();
     }
 
@@ -302,7 +306,7 @@ function pay_node_admin_node_form_alter(&$form, &$form_state) {
 
           // List of available forms.
           $options = array('' => ' - None -');
-          foreach (pay_forms(NULL, TRUE) as $pay_form) {
+          foreach (pay_forms_list(NULL, TRUE) as $pay_form) {
             $options[$pay_form->pfid] = $pay_form->title();
           }
 
diff --git a/modules/pay_node/includes/views/pay_node.views.inc b/modules/pay_node/includes/views/pay_node.views.inc
index a4b5818..8f09d72 100644
--- a/modules/pay_node/includes/views/pay_node.views.inc
+++ b/modules/pay_node/includes/views/pay_node.views.inc
@@ -7,7 +7,7 @@
  */
 
 /**
- * Implementation of hook_views_data().
+ * Implements hook_views_data().
  */
 function pay_node_views_data() {
 
@@ -132,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 a/modules/pay_node/pay_node.info b/modules/pay_node/pay_node.info
index c8128cc..0cdcd49 100644
--- a/modules/pay_node/pay_node.info
+++ b/modules/pay_node/pay_node.info
@@ -1,5 +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
diff --git a/modules/pay_node/pay_node.install b/modules/pay_node/pay_node.install
index b7dcb04..7e05d06 100644
--- a/modules/pay_node/pay_node.install
+++ b/modules/pay_node/pay_node.install
@@ -7,7 +7,7 @@
  */
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function pay_node_schema() {
   return array(
@@ -30,20 +30,6 @@ 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() {
@@ -51,9 +37,13 @@ function pay_node_update_6001() {
     '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;
+  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.');
 }
 
 /**
@@ -73,8 +63,8 @@ function pay_node_update_6002() {
     ),
     '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.');
 }
 
 /**
@@ -83,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 a/modules/pay_node/pay_node.module b/modules/pay_node/pay_node.module
index 7f33baa..d96cd93 100644
--- a/modules/pay_node/pay_node.module
+++ b/modules/pay_node/pay_node.module
@@ -2,11 +2,11 @@
 // $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'),
@@ -39,18 +39,18 @@ function pay_node_pay_form_access($node) {
 }
 
 /**
- * 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 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 dirname(__FILE__) . '/includes/pay_node.admin.inc';
     pay_node_admin_node_type_form_alter($form, $form_state);
   }
 
@@ -68,98 +68,142 @@ function pay_node_form_alter(&$form, &$form_state, $form_id) {
 }
 
 /**
- * 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,
-      );
+  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);
-      }
+    // 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);
-          }
+    // 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(
@@ -169,7 +213,7 @@ function pay_node_views_api() {
 }
 
 /**
- * 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)) {
@@ -184,7 +228,7 @@ 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']) {
@@ -207,17 +251,18 @@ function pay_node_pay_transaction_create(&$transaction, $values = array()) {
 }
 
 /**
- * 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;
@@ -253,11 +298,11 @@ function pay_node_form_load($node) {
 
   // 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.
diff --git a/modules/pay_progress/pay_progress.info b/modules/pay_progress/pay_progress.info
index 5c72e65..ede3b67 100644
--- a/modules/pay_progress/pay_progress.info
+++ b/modules/pay_progress/pay_progress.info
@@ -2,4 +2,4 @@ name = Pay progress
 description = Progress bar for Pay forms
 package = Payment API
 dependencies[] = pay
-core = 6.x
+core = 7.x
diff --git a/modules/pay_progress/pay_progress.module b/modules/pay_progress/pay_progress.module
index 834b3a0..abfbb34 100644
--- a/modules/pay_progress/pay_progress.module
+++ b/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 a/modules/pay_progress/theme/pay_progress.theme.inc b/modules/pay_progress/theme/pay_progress.theme.inc
index ac5d8fd..80e0a3f 100644
--- a/modules/pay_progress/theme/pay_progress.theme.inc
+++ b/modules/pay_progress/theme/pay_progress.theme.inc
@@ -7,28 +7,33 @@
  */
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function pay_progress_theme_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'));
 }
 
 /**
diff --git a/pay.info b/pay.info
index 8e64d8c..b775e0c 100644
--- a/pay.info
+++ b/pay.info
@@ -1,4 +1,4 @@
 name = Pay
 description = Pay for donations, orders or other nodes
 package = Payment API
-core = 6.x
+core = 7.x
diff --git a/pay.install b/pay.install
index a046c2f..3773269 100644
--- a/pay.install
+++ b/pay.install
@@ -7,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(
@@ -317,107 +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;
+  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 a/pay.module b/pay.module
index 3f7c32d..70509d4 100644
--- a/pay.module
+++ b/pay.module
@@ -6,37 +6,50 @@
  */
 
 /**
- * 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) {
@@ -49,32 +62,52 @@ function pay_perm() {
 }
 
 /**
- * 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();
 }
 
 /**
@@ -100,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.
@@ -125,7 +158,7 @@ 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(
@@ -140,7 +173,7 @@ function pay_views_api() {
 function pay_handlers($type, $handler_name = NULL, $refresh = FALSE) {
   static $handlers = array();
   if ($refresh || !isset($handlers[$type])) {
-    module_load_include('handlers.inc', 'pay', 'includes/pay');
+    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'])) {
@@ -193,7 +226,7 @@ function pay_load_handler($type, $name) {
 
     // 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];
   }
@@ -201,8 +234,10 @@ 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') {
@@ -220,9 +255,11 @@ function pay_load($type, $values = NULL) {
       if ($type == 'pay_activity') {
         $key = 'paid';
       }
-      if ($values = db_fetch_object(db_query("SELECT * from {%s}
-        WHERE $key = %d", $type, $values))) {
-
+      $result = db_select($type, 't')
+        ->fields('t')
+        ->condition($key, $values)
+        ->execute();
+      if ($values = $result->fetchObject()) {
         $handler = isset($values->handler) ? $values->handler : $type;
       }
       else {
@@ -241,7 +278,7 @@ 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);
     }
@@ -259,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);
 }
 
 /**
@@ -298,10 +335,12 @@ 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);
+    $pay = pay_load_object($type, $pay);
   }
 
   // Add a "build mode" to $form_state so that the form handlers can render
@@ -333,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) {
@@ -361,7 +400,7 @@ 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;
         if (method_exists($pay, $func)) {
@@ -420,35 +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;
-  }
-  $sql = "SELECT * FROM {pay_form}";
-  if ($where) {
-    $sql .= ' WHERE ' . join(' AND ', $where);
+    $query->condition('embeddable', $embeddable);
   }
-  $sql .= " ORDER BY title";
+  $query->orderBy('title');
 
-  $forms = array();
-  $res = db_query($sql, $args);
+  $result = $query->execute();
 
-  while ($row = db_fetch_object($res)) {
+  $forms = array();
+  while ($row = $result->fetchObject()) {
     if ($pay_form = pay_form_load($row)) {
       $forms[$row->pfid] = $pay_form;
     }
   }
+
   return $forms;
 }
 
diff --git a/theme/pay.theme.inc b/theme/pay.theme.inc
index dd61235..7d25116 100644
--- a/theme/pay.theme.inc
+++ b/theme/pay.theme.inc
@@ -15,49 +15,49 @@ function pay_theme_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()),
     ),
   );
 }
@@ -65,14 +65,17 @@ function pay_theme_theme() {
 /**
  * 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,
@@ -92,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;
@@ -110,7 +113,7 @@ function template_preprocess_pay_transaction(&$variables) {
   }
 
   if ($activity = $pay_transaction->activity()) {
-    $variables['activity'] = theme('pay_activity_list', $activity);
+    $variables['activity'] = theme('pay_activity_list', array('activity' => $activity));
   }
 }
 
@@ -128,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',
@@ -146,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]);
@@ -167,13 +176,14 @@ function template_preprocess_pay_cc_form(&$variables) {
     $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'),
@@ -197,23 +207,25 @@ function theme_pay_activity_list($activity_list) {
     }
 
     $row = array(
-      format_date($activity->timestamp, 'small'),
+      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 a/theme/pay_cc_form.tpl.php b/theme/pay_cc_form.tpl.php
index 7560a6a..b815f5e 100644
--- a/theme/pay_cc_form.tpl.php
+++ b/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>
