You are here

function uc_payment_method_credit_form in Ubercart 5

Same name and namespace in other branches
  1. 6.2 payment/uc_credit/uc_credit.module \uc_payment_method_credit_form()
  2. 7.3 payment/uc_credit/uc_credit.module \uc_payment_method_credit_form()
3 calls to uc_payment_method_credit_form()
uc_authorizenet_arb_admin_update_form in payment/uc_authorizenet/uc_authorizenet.module
uc_authorizenet_arb_user_update_form in payment/uc_authorizenet/uc_authorizenet.module
uc_credit_terminal_form in payment/uc_credit/uc_credit.module
1 string reference to 'uc_payment_method_credit_form'
uc_payment_method_credit in payment/uc_credit/uc_credit.module

File

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

Code

function uc_payment_method_credit_form($order) {

  // Normally the CC data is posted in via AJAX.
  if (!empty($_POST['payment-details-data']) && arg(0) == 'cart') {
    $order->payment_details = uc_credit_cache('save', $_POST['payment-details-data']);
  }

  // But we have to accommodate failed checkout form validation here.
  if (isset($_SESSION['sescrd'])) {
    $order->payment_details = uc_credit_cache('save', $_SESSION['sescrd']);
    unset($_SESSION['sescrd']);
  }
  $form['cc_policy'] = array(
    '#value' => variable_get('uc_credit_policy', t('Your billing information must match the billing address for the credit card entered below or we will be unable to process your payment.')),
  );
  if (variable_get('uc_credit_type_enabled', FALSE)) {
    $types = variable_get('uc_credit_accepted_types', implode("\r\n", array(
      t('Visa'),
      t('Mastercard'),
      t('Discover'),
      t('American Express'),
    )));
    if (empty($types)) {
      $types = array(
        t('N/A'),
      );
    }
    else {
      $types = explode("\r\n", $types);
    }
    foreach ($types as $type) {
      $options[check_plain($type)] = $type;
    }
    $form['cc_type'] = array(
      '#type' => 'select',
      '#title' => t('Card type'),
      '#options' => $options,
      '#default_value' => $order->payment_details['cc_type'],
    );
  }
  if (variable_get('uc_credit_owner_enabled', FALSE)) {
    $form['cc_owner'] = array(
      '#type' => 'textfield',
      '#title' => t('Card owner'),
      '#default_value' => $order->payment_details['cc_owner'],
      '#attributes' => array(
        'autocomplete' => 'off',
      ),
      '#size' => 32,
      '#maxlength' => 64,
    );
  }

  // Setup the default CC number on the credit card form.
  if (variable_get('uc_credit_validate_numbers', TRUE) && (strlen($order->payment_details['cc_number']) > 4 && !_valid_card_number($order->payment_details['cc_number']))) {

    // Display the number as is if it does not validate so it can be corrected.
    $default_num = $order->payment_details['cc_number'];
  }
  elseif (!empty($order->payment_details['cc_number'])) {
    if (user_access('view cc numbers') && strlen($order->payment_details['cc_number']) > 4) {

      // Display the full number to those with access.
      $default_num = $order->payment_details['cc_number'];
    }
    else {

      // Otherwise default to the last 4 digits.
      $default_num = t('(Last 4) ') . substr($order->payment_details['cc_number'], -4);
    }
  }
  $form['cc_number'] = array(
    '#type' => 'textfield',
    '#title' => t('Card number'),
    '#default_value' => $_SESSION['clear_cc'] ? '' : $default_num,
    '#attributes' => array(
      'autocomplete' => 'off',
    ),
    '#size' => 20,
    '#maxlength' => 19,
  );
  if (variable_get('uc_credit_start_enabled', FALSE)) {
    $form['cc_start_month'] = uc_select_month(t('Start Month'), $order->payment_details['cc_start_month'], TRUE);
    $form['cc_start_year'] = uc_select_year(t('Start Year'), $order->payment_details['cc_start_year'], date('Y') - 10, date('Y'), TRUE);
  }
  $form['cc_exp_month'] = uc_select_month(t('Expiration Month'), $order->payment_details['cc_exp_month']);
  $form['cc_exp_year'] = uc_select_year(t('Expiration Year'), $order->payment_details['cc_exp_year']);
  if (variable_get('uc_credit_issue_enabled', FALSE)) {

    // Setup the default Issue Number on the credit card form.
    if (!_valid_card_issue($order->payment_details['cc_issue'])) {

      // Display the Issue Number as is if it does not validate so it can be corrected.
      $default_card_issue = $order->payment_details['cc_issue'];
    }
    elseif (!empty($order->payment_details['cc_issue'])) {
      if (user_access('view cc numbers')) {

        // Display the full number to those with access.
        $default_card_issue = $order->payment_details['cc_issue'];
      }
      else {

        // Otherwise mask it with dashes.
        $default_card_issue = str_repeat('-', strlen($order->payment_details['cc_issue']));
      }
    }
    $form['cc_issue'] = array(
      '#type' => 'textfield',
      '#title' => t('Issue Number'),
      '#default_value' => $default_card_issue,
      '#attributes' => array(
        'autocomplete' => 'off',
      ),
      '#size' => 2,
      '#maxlength' => 2,
    );
  }
  if (variable_get('uc_credit_cvv_enabled', TRUE)) {

    // Setup the default CVV  on the credit card form.
    if (!_valid_cvv($order->payment_details['cc_cvv'])) {

      // Display the CVV as is if it does not validate so it can be corrected.
      $default_cvv = $order->payment_details['cc_cvv'];
    }
    elseif (!empty($order->payment_details['cc_cvv'])) {
      if (user_access('view cc numbers')) {

        // Display the full number to those with access.
        $default_cvv = $order->payment_details['cc_cvv'];
      }
      else {

        // Otherwise mask it with dashes.
        $default_cvv = str_repeat('-', strlen($order->payment_details['cc_cvv']));
      }
    }
    $form['cc_cvv'] = array(
      '#type' => 'textfield',
      '#title' => t('CVV'),
      '#default_value' => $_SESSION['clear_cc'] ? '' : $default_cvv,
      '#attributes' => array(
        'autocomplete' => 'off',
      ),
      '#size' => variable_get('uc_credit_amex', TRUE) ? 4 : 3,
      '#maxlength' => variable_get('uc_credit_amex', TRUE) ? 4 : 3,
    );
  }
  if (variable_get('uc_credit_bank_enabled', FALSE)) {
    $form['cc_bank'] = array(
      '#type' => 'textfield',
      '#title' => t('Issuing bank'),
      '#default_value' => $order->payment_details['cc_bank'],
      '#attributes' => array(
        'autocomplete' => 'off',
      ),
      '#size' => 32,
      '#maxlength' => 64,
    );
  }
  unset($_SESSION['clear_cc']);
  return $form;
}