You are here

function uc_recurring_order in UC Recurring Payments and Subscriptions 6

Same name and namespace in other branches
  1. 6.2 uc_recurring.module \uc_recurring_order()

Implementation of hook_order().

File

./uc_recurring.module, line 301
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;
          foreach ($fees as $fee) {
            if (!uc_recurring_process($arg1, $fee)) {
              uc_order_comment_save($arg1->order_id, 0, t('The recurring fee for product @model failed.', array(
                '@model' => $fee->model,
              )), 'admin', $arg1->order_status);
              $pass = FALSE;
            }
          }
          if ($pass == FALSE) {
            $process = variable_get('uc_recurring_checkout_fail', 'fail');
            if ($process == 'fail' && uc_payment_balance($arg1) < $arg1->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 set up 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);
      }
  }
}