You are here

function uc_payment_method_cod in Ubercart 5

Same name and namespace in other branches
  1. 6.2 payment/uc_payment_pack/uc_payment_pack.module \uc_payment_method_cod()
  2. 7.3 payment/uc_payment_pack/uc_payment_pack.module \uc_payment_method_cod()

Handle the Cash on Delivery payment method.

1 string reference to 'uc_payment_method_cod'
uc_payment_pack_payment_method in payment/uc_payment_pack/uc_payment_pack.module
Implementation of hook_payment_method().

File

payment/uc_payment_pack/uc_payment_pack.module, line 130
Provides the check/money order, COD, and "other" payment methods.

Code

function uc_payment_method_cod($op, &$arg1) {
  switch ($op) {
    case 'cart-details':
      $details = variable_get('uc_cod_policy', t('Full payment is expected upon delivery or prior to pick-up.'));
      if (($max = variable_get('uc_cod_max_order', 0)) > 0 && is_numeric($max)) {
        $details .= '<p>' . t('Orders totalling more than !number are <b>not eligible</b> for COD.', array(
          '!number' => uc_currency_format($max),
        )) . '</p>';
      }
      if (variable_get('uc_cod_delivery_date', FALSE)) {
        $details .= uc_strip_form(drupal_get_form('uc_payment_method_cod_form', $arg1));
      }
      return $details;
    case 'cart-process':
      if (variable_get('uc_cod_delivery_date', FALSE)) {
        $arg1->payment_details['delivery_month'] = intval($_POST['cod_delivery_month']);
        $arg1->payment_details['delivery_day'] = intval($_POST['cod_delivery_day']);
        $arg1->payment_details['delivery_year'] = intval($_POST['cod_delivery_year']);
      }
      return TRUE;
    case 'cart-review':
      if (variable_get('uc_cod_delivery_date', FALSE)) {
        $date = uc_date_format($arg1->payment_details['delivery_month'], $arg1->payment_details['delivery_day'], $arg1->payment_details['delivery_year']);
        $review[] = array(
          'title' => t('Delivery Date'),
          'data' => $date,
        );
      }
      return $review;
    case 'order-view':
    case 'customer-view':
      if (variable_get('uc_cod_delivery_date', FALSE)) {
        $output = t('Desired delivery date:') . '<br />' . uc_date_format($arg1->payment_details['delivery_month'], $arg1->payment_details['delivery_day'], $arg1->payment_details['delivery_year']);
      }
      return $output;
    case 'order-details':
      if (variable_get('uc_cod_delivery_date', FALSE)) {
        $details .= uc_strip_form(drupal_get_form('uc_payment_method_cod_form', $arg1));
      }
      return $details;
    case 'edit-process':
      if (variable_get('uc_cod_delivery_date', FALSE)) {
        return array(
          'payment_details' => array(
            'delivery_month' => intval($_POST['cod_delivery_month']),
            'delivery_day' => intval($_POST['cod_delivery_day']),
            'delivery_year' => intval($_POST['cod_delivery_year']),
          ),
        );
      }
      return;
    case 'order-load':
      $result = db_query("SELECT * FROM {uc_payment_cod} WHERE order_id = %d", $arg1->order_id);
      if ($row = db_fetch_object($result)) {
        $arg1->payment_details['delivery_month'] = $row->delivery_month;
        $arg1->payment_details['delivery_day'] = $row->delivery_day;
        $arg1->payment_details['delivery_year'] = $row->delivery_year;
      }
      break;
    case 'order-submit':
      if ($arg1->payment_method == 'cod' && ($max = variable_get('uc_cod_max_order', 0)) > 0 && is_numeric($max) && $arg1->order_total > $max) {
        $result[] = array(
          'pass' => FALSE,
          'message' => t('Your final order total exceeds the maximum for COD payment.  Please go back and select a different method of payment.'),
        );
        $_SESSION['expanded_panes'][] = 'payment';
        return $result;
      }
    case 'order-save':
      db_query("DELETE FROM {uc_payment_cod} WHERE order_id = %d", $arg1->order_id);
      db_query("INSERT INTO {uc_payment_cod} VALUES (%d, %d, %d, %d)", $arg1->order_id, $arg1->payment_details['delivery_month'], $arg1->payment_details['delivery_day'], $arg1->payment_details['delivery_year']);
      break;
    case 'order-delete':
      db_query("DELETE FROM {uc_payment_cod} WHERE order_id = %d", $arg1->order_id);
      break;
    case 'settings':
      $form['uc_cod_max_order'] = array(
        '#type' => 'textfield',
        '#title' => t('Maximum order total eligible for COD'),
        '#default_value' => variable_get('uc_cod_max_order', 0),
        '#description' => t('Set to 0 for no maximum order limit.'),
      );
      $form['uc_cod_delivery_date'] = array(
        '#type' => 'checkbox',
        '#title' => t('Let customers enter a desired delivery date.'),
        '#default_value' => variable_get('uc_cod_delivery_date', FALSE),
      );
      return $form;
  }
}