You are here

function uc_recurring_order in Ubercart 5

Implementation of hook_order().

File

payment/uc_recurring/uc_recurring.module, line 272
Allows you to add a recurring fee to a product/SKU to handle subscription type services.

Code

function uc_recurring_order($op, &$arg1, $arg2) {
  switch ($op) {
    case 'submit':
      if (variable_get('uc_recurring_checkout_process', TRUE)) {
        $fees = uc_recurring_find_fees($arg1);
        if (count($fees)) {
          $pass = TRUE;
          $order = uc_order_load($arg1->order_id);
          foreach ($fees as $fee) {
            if (!uc_recurring_process($order, $fee)) {
              uc_order_comment_save($order->order_id, 0, t('The recurring fee for product @model failed.', array(
                '@model' => $fee->model,
              )), 'admin', $order->order_status);
              $pass = FALSE;
            }
          }
          if ($pass == FALSE) {
            $process = variable_get('uc_recurring_checkout_fail', 'fail');
            if ($process == 'fail' && uc_payment_balance($order) < $order->order_total) {
              $process = 'proceed';
            }
            switch ($process) {
              case 'fail':
                return array(
                  array(
                    'pass' => FALSE,
                    'message' => t('Your order cannot be completed, because we could not process your recurring payment. Please review your payment details and contact us to complete your order if the problem persists.'),
                  ),
                );
              case 'proceed':
                return array(
                  array(
                    'pass' => TRUE,
                    'message' => t('Your order has been submitted, but we may need to contact you to ensure your recurring fee is setup properly. Thank you for your understanding.'),
                  ),
                );
            }
          }
        }
      }
      break;
    case 'update':
      if (uc_order_status_data($arg1->order_status, 'state') == 'in_checkout') {
        db_query("UPDATE {uc_recurring_users} SET uid = %d WHERE uid = 0 AND order_id = %d", $arg1->uid, $arg1->order_id);
      }
  }
}