You are here

function uc_order_pane_payment in Ubercart 7.3

Same name and namespace in other branches
  1. 5 payment/uc_payment/uc_payment_order_pane.inc \uc_order_pane_payment()
  2. 6.2 payment/uc_payment/uc_payment_order_pane.inc \uc_order_pane_payment()

Handles the Payment order pane.

1 string reference to 'uc_order_pane_payment'
uc_payment_uc_order_pane in payment/uc_payment/uc_payment.module
Implements hook_uc_order_pane().

File

payment/uc_payment/uc_payment_order_pane.inc, line 17
Contains the callbacks for the payment order pane supplied with Ubercart and their corresponding helper functions.

Code

function uc_order_pane_payment($op, $order, &$form = NULL, &$form_state = NULL) {
  switch ($op) {
    case 'view':
      $build['balance'] = array(
        '#markup' => t('Balance: @balance', array(
          '@balance' => uc_currency_format(uc_payment_balance($order)),
        )),
      );
      if (user_access('view payments')) {
        $build['view_payments'] = array(
          '#markup' => ' (' . l(t('View'), 'admin/store/orders/' . $order->order_id . '/payments') . ')',
        );
      }
      $method_name = _uc_payment_method_data($order->payment_method, 'review');
      if (empty($method_name)) {
        $method_name = _uc_payment_method_data($order->payment_method, 'name');
      }
      $build['method'] = array(
        '#markup' => t('Method: @payment_method', array(
          '@payment_method' => $method_name,
        )),
        '#prefix' => '<br />',
      );
      $func = _uc_payment_method_data($order->payment_method, 'callback');
      if (function_exists($func)) {
        $method_output = $func('order-view', $order);
        if (!empty($method_output)) {
          $build['output'] = $method_output + array(
            '#prefix' => '<br />',
          );
        }
      }
      return $build;
    case 'customer':
      $method_name = _uc_payment_method_data($order->payment_method, 'review');
      if (empty($method_name)) {
        $method_name = _uc_payment_method_data($order->payment_method, 'name');
      }
      $build['method'] = array(
        '#markup' => t('Method: @payment_method', array(
          '@payment_method' => $method_name,
        )),
      );
      $func = _uc_payment_method_data($order->payment_method, 'callback');
      if (function_exists($func)) {
        $method_output = $func('customer-view', $order);
        if (!empty($method_output)) {
          $build['output'] = $method_output + array(
            '#prefix' => '<br />',
          );
        }
      }
      return $build;
    case 'edit-form':
      $methods = _uc_payment_method_list();
      $options = array();
      foreach ($methods as $id => $method) {
        $options[$id] = $method['name'];
      }
      $form['payment']['payment_method'] = array(
        '#type' => 'select',
        '#title' => t('Payment method'),
        '#default_value' => $order->payment_method,
        '#options' => !empty($options) ? $options : array(
          t('None available'),
        ),
        '#disabled' => empty($options),
        '#ajax' => array(
          'callback' => 'uc_payment_order_pane_ajax_callback',
          'progress' => array(
            'type' => 'throbber',
          ),
          'wrapper' => 'payment-details',
        ),
      );
      $form['payment']['payment_details'] = array(
        '#tree' => TRUE,
        '#prefix' => '<div id="payment-details">',
        '#suffix' => '</div>',
      );
      $method = isset($form_state['values']['payment_method']) ? $form_state['values']['payment_method'] : $order->payment_method;
      $func = _uc_payment_method_data($method, 'callback');
      if (function_exists($func) && ($details = $func('order-details', $order))) {
        if (is_array($details)) {
          $form['payment']['payment_details'] += $details;
        }
        else {
          $form['payment']['payment_details']['#markup'] = $details;
        }
      }
      return $form;
    case 'edit-theme':
      return drupal_render($form['payment']);
    case 'edit-process':
      $changes = array();
      $changes['payment_method'] = $form_state['values']['payment_method'];
      $changes['payment_details'] = isset($form_state['values']['payment_details']) ? $form_state['values']['payment_details'] : array();
      $func = _uc_payment_method_data($form_state['values']['payment_method'], 'callback');
      if (function_exists($func) && ($return = $func('edit-process', $order, $form, $form_state)) != NULL && is_array($return)) {
        $changes['payment_details'] = array_merge($changes['payment_details'], $return);
      }
      if (!isset($order->payment_details)) {
        $order->payment_details = array();
      }
      return $changes;
  }
}