You are here

function uc_credit_uc_order in Ubercart 7.3

Implements hook_uc_order().

File

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

Code

function uc_credit_uc_order($op, $order, $arg2) {

  // Set up the encryption key and object for saving and loading.
  if (isset($order->payment_method) && $order->payment_method == 'credit' && ($op == 'save' || $op == 'load')) {

    // Log an error if encryption isn't configured properly.
    if (!uc_credit_encryption_key()) {
      watchdog('uc_credit', 'Credit card encryption must be set up to process credit cards.');
    }
  }
  switch ($op) {
    case 'submit':
      if (isset($order->payment_method) && $order->payment_method == 'credit') {

        // Clear out that session variable denoting this as a CC paid order.
        unset($_SESSION['cc_pay']);

        // Process CC transactions when an order is submitted after review.
        $gateway_id = uc_credit_default_gateway();
        $data = array(
          'txn_type' => variable_get('uc_pg_' . $gateway_id . '_cc_txn_type', UC_CREDIT_AUTH_CAPTURE),
        );

        // Attempt to process the CC payment.
        $order->payment_details = uc_credit_cache('load');
        $pass = uc_payment_process_payment('credit', $order->order_id, $order->order_total, $data, TRUE, NULL, FALSE);

        // If the payment failed, store the data back in the session and
        // halt the checkout process.
        if (!$pass) {
          $message = variable_get('uc_credit_fail_message', t('We were unable to process your credit card payment. Please verify your details and try again.  If the problem persists, contact us to complete your order.'));
          return array(
            array(
              'pass' => FALSE,
              'message' => $message,
            ),
          );
        }
      }
      break;
    case 'save':
      if (isset($order->payment_method) && $order->payment_method == 'credit' && !empty($order->payment_details)) {
        _uc_credit_save_cc_data_to_order($order->payment_details, $order->order_id);
      }
      break;
    case 'load':
      if (isset($order->payment_method) && $order->payment_method == 'credit') {

        // Load the CC details from the credit cache if available.
        $order->payment_details = uc_credit_cache('load');

        // Otherwise load any details that might be stored in the data array.
        if (empty($order->payment_details) && isset($order->data['cc_data'])) {
          $order->payment_details = uc_credit_cache('save', $order->data['cc_data']);
        }
      }
      break;
  }
}