You are here

function uc_payment_method_check in Ubercart 6.2

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

Payment method callback for the "Check" payment method.

1 string reference to 'uc_payment_method_check'
uc_payment_pack_payment_method in payment/uc_payment_pack/uc_payment_pack.module
Implements hook_payment_method().

File

payment/uc_payment_pack/uc_payment_pack.module, line 314
Provides the Check/Money Order, COD, and "Other" payment methods.

Code

function uc_payment_method_check($op, &$order) {
  switch ($op) {
    case 'cart-details':
      if (!variable_get('uc_check_mailing_street1', FALSE)) {
        $details = t('Checks should be made out to:') . '<p>' . uc_address_format(variable_get('uc_store_name', ''), NULL, variable_get('uc_store_company', ''), variable_get('uc_store_street1', ''), variable_get('uc_store_street2', ''), variable_get('uc_store_city', ''), variable_get('uc_store_zone', ''), variable_get('uc_store_postal_code', ''), variable_get('uc_store_country', 840)) . '</p><p>' . variable_get('uc_check_policy', '') . '</p>';
      }
      else {
        $details = t('Checks should be made out to:') . '<p>' . uc_address_format(variable_get('uc_check_mailing_name', ''), NULL, variable_get('uc_check_mailing_company', ''), variable_get('uc_check_mailing_street1', ''), variable_get('uc_check_mailing_street2', ''), variable_get('uc_check_mailing_city', ''), variable_get('uc_check_mailing_zone', ''), variable_get('uc_check_mailing_postal_code', ''), variable_get('uc_check_mailing_country', 840)) . '</p><p>' . variable_get('uc_check_policy', '') . '</p>';
      }
      return $details;
    case 'cart-review':
      if (!variable_get('uc_check_mailing_street1', FALSE)) {
        $review[] = array(
          'title' => t('Mail to'),
          'data' => uc_address_format(variable_get('uc_store_name', ''), NULL, variable_get('uc_store_company', ''), variable_get('uc_store_street1', ''), variable_get('uc_store_street2', ''), variable_get('uc_store_city', ''), variable_get('uc_store_zone', ''), variable_get('uc_store_postal_code', ''), variable_get('uc_store_country', 840)),
        );
      }
      else {
        $review[] = array(
          'title' => t('Mail to'),
          'data' => uc_address_format(variable_get('uc_check_mailing_name', ''), NULL, variable_get('uc_check_mailing_company', ''), variable_get('uc_check_mailing_street1', ''), variable_get('uc_check_mailing_street2', ''), variable_get('uc_check_mailing_city', ''), variable_get('uc_check_mailing_zone', ''), variable_get('uc_check_mailing_postal_code', ''), variable_get('uc_check_mailing_country', 840)),
        );
      }
      return $review;
    case 'order-view':
      if (!variable_get('uc_payment_tracking', TRUE)) {
        return '';
      }
      $result = db_query("SELECT clear_date FROM {uc_payment_check} WHERE " . "order_id = %d ", $order->order_id);
      if ($check = db_fetch_object($result)) {
        $output = t('Clear Date:') . ' ' . format_date($check->clear_date, 'custom', variable_get('uc_date_format_default', 'm/d/Y'));
      }
      else {
        $output = l(t('Receive Check'), 'admin/store/orders/' . $order->order_id . '/receive_check');
      }
      $output .= '<br />';
      return $output;
    case 'customer-view':
      if (!variable_get('uc_payment_tracking', TRUE)) {
        return '';
      }
      $output = '';
      $result = db_query("SELECT clear_date FROM {uc_payment_check} WHERE order_id = %d ", $order->order_id);
      if ($check = db_fetch_object($result)) {
        $output = t('Check received') . '<br />' . t('Expected clear date:') . '<br />' . format_date($check->clear_date, 'custom', variable_get('uc_date_format_default', 'm/d/Y'));
      }
      return $output;
    case 'settings':
      $form['check_address_info'] = array(
        '#value' => '<div>' . t('Set the mailing address to display to customers who choose this payment method during checkout.') . '</div>',
      );
      $form['uc_check_mailing_company'] = uc_textfield(uc_get_field_name('company'), variable_get('uc_check_mailing_company', ''), FALSE, NULL, 128);
      $form['uc_check_mailing_name'] = uc_textfield(t('Contact'), variable_get('uc_check_mailing_name', ''), FALSE, t('Direct checks to a person or department.'), 128);
      $form['uc_check_mailing_street1'] = uc_textfield(uc_get_field_name('street1'), variable_get('uc_check_mailing_street1', ''), FALSE, NULL, 128);
      $form['uc_check_mailing_street2'] = uc_textfield(uc_get_field_name('street2'), variable_get('uc_check_mailing_street2', ''), FALSE, NULL, 128);
      $form['uc_check_mailing_city'] = uc_textfield(uc_get_field_name('city'), variable_get('uc_check_mailing_city', ''), FALSE);
      $form['uc_check_mailing_country'] = uc_country_select(uc_get_field_name('country'), variable_get('uc_check_mailing_country', uc_store_default_country()));
      if (isset($_POST['uc_check_mailing_country'])) {
        $country_id = intval($_POST['uc_check_mailing_country']);
      }
      else {
        $country_id = variable_get('uc_check_mailing_country', uc_store_default_country());
      }
      $form['uc_check_mailing_zone'] = uc_zone_select(uc_get_field_name('zone'), variable_get('uc_check_mailing_zone', ''), FALSE, $country_id);
      $form['uc_check_mailing_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), variable_get('uc_check_mailing_postal_code', ''), FALSE, NULL, 10, 10);
      $form['uc_check_policy'] = array(
        '#type' => 'textarea',
        '#title' => t('Check payment policy'),
        '#description' => t('Instructions for customers on the checkout page.'),
        '#default_value' => variable_get('uc_check_policy', t('Personal and business checks will be held for up to 10 business days to ensure payment clears before an order is shipped.')),
        '#rows' => 3,
      );
      return $form;
  }
}