You are here

function uc_recurring_cron in UC Recurring Payments and Subscriptions 6.2

Same name and namespace in other branches
  1. 6 uc_recurring.module \uc_recurring_cron()
  2. 7.2 uc_recurring.module \uc_recurring_cron()

Implementation of hook_cron().

On the renewal time of a recurring fee see if the payment method would like to perform any addition actions.

LOCK AGAINST DUPLICATE CALLS OF THIS FUNCTION: ---------------------------------------------- A lock is set for a default 30sec - this can be overridden by altering the uc_recurring_cron_timeout variable

1 call to uc_recurring_cron()
ucRecurringTestCase::processRecurringFee in ./uc_recurring.test
Process a recurring fee.

File

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

Code

function uc_recurring_cron() {
  if (!lock_acquire('uc_recurring_cron', variable_get('uc_recurring_cron_timeout', 30))) {

    // Don't run the recurring payments while another process has this lock.
    return FALSE;
  }
  if (variable_get('uc_recurring_trigger_renewals', TRUE)) {
    $fees = uc_recurring_get_fees_for_renew();
    if (!empty($fees)) {
      $fail = $success = 0;
      foreach ($fees as $fee) {
        if ($order_id = uc_recurring_renew($fee)) {
          $success++;
        }
        else {

          // payment attempted but failed
          $fail++;
        }
        if (lock_may_be_available('uc_recurring_cron')) {

          // exit if the lock has expired
          break;
        }
      }
      watchdog('uc_recurring', '@success recurring fees processed successfully; @fail failed.', array(
        '@success' => $success,
        '@fail' => $fail,
      ));
    }
  }
  lock_release('uc_recurring_cron');
  $fees = uc_recurring_get_fees_for_expiration();
  if (!empty($fees)) {
    foreach ($fees as $fee) {
      uc_recurring_expire($fee);
    }
    watchdog('uc_recurring', '@count recurring fees expired successfully.', array(
      '@count' => count($fees),
    ));
  }
}