You are here

function uc_credit_default_gateway in Ubercart 6.2

Same name and namespace in other branches
  1. 5 payment/uc_credit/uc_credit.module \uc_credit_default_gateway()
  2. 7.3 payment/uc_credit/uc_credit.module \uc_credit_default_gateway()

Retrieves the ID of the default credit card gateway.

Return value

A string containing the ID of the default gateway or FALSE if none exists or none have valid credit callbacks.

2 calls to uc_credit_default_gateway()
uc_credit_order in payment/uc_credit/uc_credit.module
Implements hook_order().
uc_credit_terminal_form in payment/uc_credit/uc_credit.admin.inc
Displays the credit card terminal form for administrators.

File

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

Code

function uc_credit_default_gateway() {

  // Get an array of enabled payment gateways available for the payment method.
  $gateways = _payment_gateway_list('credit', TRUE);

  // Return FALSE if we found no gateways.
  if (empty($gateways)) {
    return FALSE;
  }

  // If we only found one gateway for this payment method...
  if (count($gateways) == 1) {

    // Get the payment gateway array and store its ID.
    $gateway = array_shift($gateways);
    $gateway_id = $gateway['id'];

    // Store the callback for this gateway.
    $callback = $gateway['credit'];
  }
  else {

    // Otherwise attempt to find the appropriate gateway function in the array.
    $callback = FALSE;

    // Loop through each gateway.
    foreach ($gateways as $gateway) {

      // Store the callback if this is the specified default.
      if ($gateway['id'] == variable_get('uc_payment_credit_gateway', '')) {
        $callback = $gateway['credit'];
        $gateway_id = $gateway['id'];
      }
    }

    // If we didn't find a default callback...
    if ($callback === FALSE) {

      // Get the key for the first payment gateway in the array.
      $gateway_id = array_shift(array_keys($gateways));

      // Store the callback for this gateway.
      $callback = $gateways[$gateway_id]['credit'];
    }
  }

  // Return FALSE if the specified callback does not exist.
  if (!function_exists($callback)) {
    return FALSE;
  }
  return $gateway_id;
}