You are here

function uc_credit_terminal_form in Ubercart 7.3

Same name and namespace in other branches
  1. 5 payment/uc_credit/uc_credit.module \uc_credit_terminal_form()
  2. 6.2 payment/uc_credit/uc_credit.admin.inc \uc_credit_terminal_form()

Displays the credit card terminal form for administrators.

See also

uc_credit_terminal_form_validate()

uc_credit_terminal_form_submit()

1 string reference to 'uc_credit_terminal_form'
uc_credit_terminal in payment/uc_credit/uc_credit.admin.inc
Displays the credit card terminal page.

File

payment/uc_credit/uc_credit.admin.inc, line 366
Credit administration menu items.

Code

function uc_credit_terminal_form($form, &$form_state, $order, $lock_amount = FALSE) {

  // Get the transaction types available to our default gateway.
  $types = uc_credit_gateway_txn_types(uc_credit_default_gateway());

  // Put the order ID in the form.
  $form['order_id'] = array(
    '#type' => 'hidden',
    '#value' => $order->order_id,
  );
  $balance = uc_payment_balance($order);

  // Let the administrator set the amount to charge.
  $form['amount'] = array(
    '#type' => 'uc_price',
    '#title' => t('Charge Amount'),
    '#default_value' => $balance > 0 ? uc_currency_format($balance, FALSE, FALSE, '.') : 0,
    '#disabled' => $lock_amount,
  );

  // Build a credit card form.
  $form['specify_card'] = array(
    '#type' => 'fieldset',
    '#title' => t('Credit card details'),
    '#description' => t('Use the available buttons in this fieldset to process with the specified card details.'),
  );
  $form['specify_card']['cc_data'] = array(
    '#tree' => TRUE,
    '#prefix' => '<div class="payment-details-credit clearfix">',
    '#suffix' => '</div>',
  );
  $form['specify_card']['cc_data'] += uc_payment_method_credit_form(array(), $form_state, $order);
  unset($form['specify_card']['cc_data']['cc_policy']);
  $form['specify_card']['actions'] = array(
    '#type' => 'actions',
  );

  // If available, let the card be charged now.
  if (in_array(UC_CREDIT_AUTH_CAPTURE, $types)) {
    $form['specify_card']['actions']['charge_card'] = array(
      '#type' => 'submit',
      '#value' => t('Charge amount'),
    );
  }

  // If available, let the amount be authorized.
  if (in_array(UC_CREDIT_AUTH_ONLY, $types)) {
    $form['specify_card']['actions']['authorize_card'] = array(
      '#type' => 'submit',
      '#value' => t('Authorize amount only'),
    );
  }

  // If available, create a reference at the gateway.
  if (in_array(UC_CREDIT_REFERENCE_SET, $types)) {
    $form['specify_card']['actions']['reference_set'] = array(
      '#type' => 'submit',
      '#value' => t('Set a reference only'),
    );
  }

  // If available, create a reference at the gateway.
  if (in_array(UC_CREDIT_CREDIT, $types)) {
    $form['specify_card']['actions']['credit_card'] = array(
      '#type' => 'submit',
      '#value' => t('Credit amount to this card'),
    );
  }

  // Find any uncaptured authorizations.
  $options = array();
  if (isset($order->data['cc_txns']['authorizations'])) {
    foreach ($order->data['cc_txns']['authorizations'] as $auth_id => $data) {
      if (empty($data['captured'])) {
        $options[$auth_id] = t('@auth_id - @date - @amount authorized', array(
          '@auth_id' => strtoupper($auth_id),
          '@date' => format_date($data['authorized'], 'short'),
          '@amount' => uc_currency_format($data['amount']),
        ));
      }
    }
  }

  // If any authorizations existed...
  if (!empty($options)) {

    // Display a fieldset with the authorizations and available action buttons.
    $form['authorizations'] = array(
      '#type' => 'fieldset',
      '#title' => t('Prior authorizations'),
      '#description' => t('Use the available buttons in this fieldset to select and act on a prior authorization. The charge amount specified above will be captured against the authorization listed below.  Only one capture is possible per authorization, and a capture for more than the amount of the authorization may result in additional fees to you.'),
    );
    $form['authorizations']['select_auth'] = array(
      '#type' => 'radios',
      '#title' => t('Select authorization'),
      '#options' => $options,
    );
    $form['authorizations']['actions'] = array(
      '#type' => 'actions',
    );

    // If available, capture a prior authorization.
    if (in_array(UC_CREDIT_PRIOR_AUTH_CAPTURE, $types)) {
      $form['authorizations']['actions']['auth_capture'] = array(
        '#type' => 'submit',
        '#value' => t('Capture amount to this authorization'),
      );
    }

    // If available, void a prior authorization.
    if (in_array(UC_CREDIT_VOID, $types)) {
      $form['authorizations']['actions']['auth_void'] = array(
        '#type' => 'submit',
        '#value' => t('Void authorization'),
      );
    }

    // Collapse this fieldset if no actions are available.
    if (!isset($form['authorizations']['actions']['auth_capture']) && !isset($form['authorizations']['actions']['auth_void'])) {
      $form['authorizations']['#collapsible'] = TRUE;
      $form['authorizations']['#collapsed'] = TRUE;
    }
  }

  // Find any uncaptured authorizations.
  $options = array();

  // Log a reference to the order for testing.
  // $order->data = uc_credit_log_reference($order->order_id, substr(md5(REQUEST_TIME), 0, 16), '4111111111111111');
  if (isset($order->data['cc_txns']['references'])) {
    foreach ($order->data['cc_txns']['references'] as $ref_id => $data) {
      $options[$ref_id] = t('@ref_id - @date - (Last 4) @card', array(
        '@ref_id' => strtoupper($ref_id),
        '@date' => format_date($data['created'], 'short'),
        '@card' => $data['card'],
      ));
    }
  }

  // If any references existed...
  if (!empty($options)) {

    // Display a fieldset with the authorizations and available action buttons.
    $form['references'] = array(
      '#type' => 'fieldset',
      '#title' => t('Customer references'),
      '#description' => t('Use the available buttons in this fieldset to select and act on a customer reference.'),
    );
    $form['references']['select_ref'] = array(
      '#type' => 'radios',
      '#title' => t('Select references'),
      '#options' => $options,
    );
    $form['references']['actions'] = array(
      '#type' => 'actions',
    );

    // If available, capture a prior references.
    if (in_array(UC_CREDIT_REFERENCE_TXN, $types)) {
      $form['references']['actions']['ref_capture'] = array(
        '#type' => 'submit',
        '#value' => t('Charge amount to this reference'),
      );
    }

    // If available, remove a previously stored reference.
    if (in_array(UC_CREDIT_REFERENCE_REMOVE, $types)) {
      $form['references']['actions']['ref_remove'] = array(
        '#type' => 'submit',
        '#value' => t('Remove reference'),
      );
    }

    // If available, remove a previously stored reference.
    if (in_array(UC_CREDIT_REFERENCE_CREDIT, $types)) {
      $form['references']['actions']['ref_credit'] = array(
        '#type' => 'submit',
        '#value' => t('Credit amount to this reference'),
      );
    }

    // Collapse this fieldset if no actions are available.
    if (!isset($form['references']['actions']['ref_capture']) && !isset($form['references']['actions']['ref_remove']) && !isset($form['references']['actions']['ref_credit'])) {
      $form['references']['#collapsible'] = TRUE;
      $form['references']['#collapsed'] = TRUE;
    }
  }
  $form['#attached']['css'][] = drupal_get_path('module', 'uc_payment') . '/uc_payment.css';
  return $form;
}