You are here

function uc_credit_terminal_form_submit in Ubercart 7.3

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

Submit handler for credit terminal form.

See also

uc_credit_terminal_form()

uc_credit_terminal_form_validate()

File

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

Code

function uc_credit_terminal_form_submit($form, &$form_state) {

  // Load the order.
  $order = uc_order_load($form_state['values']['order_id']);

  // Get the data from the form and replace masked data from the order.
  $cc_data = $form_state['values']['cc_data'];
  if (strpos($cc_data['cc_number'], t('(Last 4) ')) === 0) {
    $cc_data['cc_number'] = $order->payment_details['cc_number'];
  }
  if (isset($cc_data['cc_cvv']) && isset($order->payment_details['cc_cvv'])) {
    if ($cc_data['cc_cvv'] == str_repeat('-', strlen($cc_data['cc_cvv']))) {
      $cc_data['cc_cvv'] = $order->payment_details['cc_cvv'];
    }
  }

  // Cache the values for use during processing.
  uc_credit_cache('save', $cc_data, FALSE);

  // Build the data array passed on to the payment gateway.
  $data = array();
  switch ($form_state['values']['op']) {
    case t('Charge amount'):
      $data['txn_type'] = UC_CREDIT_AUTH_CAPTURE;
      break;
    case t('Authorize amount only'):
      $data['txn_type'] = UC_CREDIT_AUTH_ONLY;
      break;
    case t('Set a reference only'):
      $data['txn_type'] = UC_CREDIT_REFERENCE_SET;
      break;
    case t('Credit amount to this card'):
      $data['txn_type'] = UC_CREDIT_CREDIT;
      break;
    case t('Capture amount to this authorization'):
      $data['txn_type'] = UC_CREDIT_PRIOR_AUTH_CAPTURE;
      $data['auth_id'] = $form_state['values']['select_auth'];
      break;
    case t('Void authorization'):
      $data['txn_type'] = UC_CREDIT_VOID;
      $data['auth_id'] = $form_state['values']['select_auth'];
      break;
    case t('Charge amount to this reference'):
      $data['txn_type'] = UC_CREDIT_REFERENCE_TXN;
      $data['ref_id'] = $form_state['values']['select_ref'];
      break;
    case t('Remove reference'):
      $data['txn_type'] = UC_CREDIT_REFERENCE_REMOVE;
      $data['ref_id'] = $form_state['values']['select_ref'];
      break;
    case t('Credit amount to this reference'):
      $data['txn_type'] = UC_CREDIT_REFERENCE_CREDIT;
      $data['ref_id'] = $form_state['values']['select_ref'];
  }
  $result = uc_payment_process_payment('credit', $form_state['values']['order_id'], $form_state['values']['amount'], $data, TRUE, NULL, FALSE);
  _uc_credit_save_cc_data_to_order(uc_credit_cache('load'), $form_state['values']['order_id']);
  if ($result) {
    drupal_set_message(t('The credit card was processed successfully. See the admin comments for more details.'));
  }
  else {
    drupal_set_message(t('There was an error processing the credit card.  See the admin comments for details.'), 'error');
  }
  $form_state['redirect'] = 'admin/store/orders/' . $form_state['values']['order_id'];
}