You are here

function uc_recurring_byref_save in Ubercart 5

Saves a reference transaction fee to the database.

Recurring handlers for payment gateways processing recurring fees through a reference transaction should use the uc_recurring_byref system. By calling this function from a recurring fee handler and passing on the order and fee objects as received, the system will add the fee to the single table that will be processed on cron.

Parameters

$order: The order object for the recurring fee.

$fee: The fee data object.

$handler: The name of the recurring fee handler using the uc_recurring_byref system.

$callback: The name of the charge function for the gateway that will be used to charge the reference transactions.

$ref_id: The reference ID that will be used to process the reference transaction at the payment gateway.

File

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

Code

function uc_recurring_byref_save($order, $fee, $handler, $callback, $ref_id) {

  // Build the data array stored for the fee.
  $data = array(
    'charge_callback' => $callback,
    'ref_id' => $ref_id,
    'model' => $fee->model,
  );
  $fee = array(
    'rfid' => db_next_id('{uc_product_users}_rfid'),
    'uid' => $order->uid,
    'fee_handler' => 'uc_recurring_byref:' . $handler,
    '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),
  );
  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;
}