You are here

function theme_card_data_overview in Commerce Card on File 7

Themes a display of stored card data.

Parameters

$variables: An array of theme variables including:

  • card_data: a data array for the stored card on file
2 theme calls to theme_card_data_overview()
commerce_cardonfile_delete_form in includes/commerce_cardonfile.pages.inc
Builds the form for deleting cardonfile data.
commerce_cardonfile_overview in includes/commerce_cardonfile.pages.inc
Displays the card data overview for the "Stored payment methods" account tab.

File

./commerce_cardonfile.module, line 167
Supports card on file functionality for credit card payment methods by associating card data reference IDs from payment gateways with user accounts.

Code

function theme_card_data_overview($variables) {
  drupal_add_css(drupal_get_path('module', 'commerce_cardonfile') . '/theme/commerce_cardonfile.css');
  $card_data = $variables['card_data'];

  // Load the credit card helper functions from the Payment module.
  module_load_include('inc', 'commerce_payment', 'includes/commerce_payment.credit_card');
  $card_types = commerce_payment_credit_card_types();

  // Extract the name of the card type if possible.
  $card_type = t('Credit card');
  if (!empty($card_types[$card_data['card_type']])) {
    $card_type = $card_types[$card_data['card_type']];
  }

  // Build an array of data lines to include in the overview.
  $lines = array(
    t('Type:') => $card_type,
    t('Cardholder name:') => check_plain($card_data['card_name']),
    t('Number (last 4):') => '******' . check_plain($card_data['card_number']),
    t('Expiration date:') => check_plain($card_data['card_exp_month'] . '/' . $card_data['card_exp_year']),
  );
  $output = '';
  foreach ($lines as $label => $value) {

    // Only add a line if it has a value.
    if (!empty($value)) {
      $output .= '<div class="commerce-card-data-line"><span class="label">' . $label . '</span> ' . $value . '</div>';
    }
  }
  return '<div class="commerce-card-data">' . $output . '</div>';
}