You are here

function uc_credit_references in Ubercart 5

Return any transaction references on a given user's orders.

Parameters

$account (optional): The user account whose orders are to be searched for CC references. Default: The current user account context.

Return value

A structured array. Each element's key is the transaction reference, and the value is an array containing the billing information and the truncated credit card number.

File

payment/uc_credit/uc_credit.module, line 1981
Defines the credit card payment method and hooks in payment gateways.

Code

function uc_credit_references($account = NULL) {
  static $references = array();

  // If account is NULL, we'll use the current user context.
  if (is_null($account)) {
    global $user;
    $account = drupal_clone($user);
  }
  if (!isset($references[$account->uid])) {
    $result = db_query("SELECT billing_first_name, billing_last_name, billing_phone, billing_company, billing_street1, billing_street2, billing_city, billing_zone, billing_postal_code, billing_country, data FROM {uc_orders} WHERE uid = %d", $account->uid);
    while ($order = db_fetch_array($result)) {

      // Extract data and remove it from the result; we won't need it later and
      // that'll help keep our code clean.
      $data = unserialize($order['data']);
      unset($order['data']);

      // For each reference, store the reference ID as the key and the billing info
      // and truncated CC data as the value.
      if (is_array($data['cc_txns']) && is_array($data['cc_txns']['references'])) {
        foreach ($data['cc_txns']['references'] as $id => $reference) {
          $references[$account->uid][$id] = $order + array(
            'cc_number' => $reference['card'],
          );
        }
      }
    }
  }
  return $references[$account->uid];
}