You are here

function uc_recurring_recurring_fee in UC Recurring Payments and Subscriptions 6

Implementation of hook_recurring_fee(); default recurring fee handler.

File

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

Code

function uc_recurring_recurring_fee($order, $fee) {
  if ($order->payment_method !== 'credit') {
    watchdog('uc_recurring', 'You can only use the credit card payment method with the uc_recurring handler.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  $data = array(
    'billing_first_name' => $order->billing_first_name,
    'billing_last_name' => $order->billing_last_name,
    'billing_phone' => $order->billing_phone,
    'billing_company' => $order->billing_company,
    'billing_street1' => $order->billing_street1,
    'billing_street2' => $order->billing_street2,
    'billing_city' => $order->billing_city,
    'billing_zone' => $order->billing_zone,
    'billing_postal_code' => $order->billing_postal_code,
    'billing_country' => $order->billing_country,
    'payment_details' => $order->payment_details,
    'model' => $fee->model,
  );
  if ($key = uc_credit_encryption_key()) {
    $crypt = new uc_encryption_class();
    $data['payment_details']['cc_number'] = $crypt
      ->encrypt($key, $data['payment_details']['cc_number'], 32);
    if (variable_get('uc_credit_debug', FALSE)) {
      $data['payment_details']['cc_cvv'] = $crypt
        ->encrypt($key, $data['payment_details']['cc_cvv'], 32);
    }
    $data['payment_details']['cc_exp_month'] = $crypt
      ->encrypt($key, $data['payment_details']['cc_exp_month'], 32);
    $data['payment_details']['cc_exp_year'] = $crypt
      ->encrypt($key, $data['payment_details']['cc_exp_year'], 32);
    uc_store_encryption_errors($crypt, 'uc_recurring');
  }
  $fee = array(
    'rfid' => 0,
    'uid' => $order->uid,
    'fee_handler' => 'uc_recurring',
    'next_charge' => strtotime('+' . $fee->initial_charge),
    'fee_amount' => $fee->fee_amount,
    'regular_interval' => $fee->regular_interval,
    'remaining_intervals' => $fee->number_intervals,
    'charged_intervals' => 0,
    'order_id' => $order->order_id,
    'data' => serialize($data),
  );
  $fee['rfid'] = uc_recurring_fee_save('user', $fee);
  uc_order_comment_save($order->order_id, 0, t('Recurring fee <a href="!url">!fee</a> added to order.', array(
    '!url' => url('admin/store/orders/recurring/view/fee/' . $fee['rfid']),
    '!fee' => $fee['rfid'],
  )));
  return TRUE;
}