You are here

function uc_recurring_fee_cancel in UC Recurring Payments and Subscriptions 7.2

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

Wrapper function to cancel a user's recurring fee.

Cancellation is done by setting remaining intervals to 0.

Parameters

$rfid: The recurring fee's ID.

$fee: Optional; The loaded fee object.

4 calls to uc_recurring_fee_cancel()
uc_recurring_admin_edit_form_submit in ./uc_recurring.admin.inc
@todo Please document this function.
uc_recurring_hosted_paypal_ipn in modules/uc_recurring_hosted/uc_recurring_hosted.paypal_ipn.inc
Handle IPN callbacks for PayPal recurring payments
uc_recurring_uc_order in ./uc_recurring.module
Implements hook_uc_order().
uc_recurring_user_cancel_form_submit in ./uc_recurring.pages.inc
Implements hook_submit() for the cancel recurring fee form().

File

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

Code

function uc_recurring_fee_cancel($rfid, $fee = NULL) {
  global $user;
  if (empty($fee)) {
    $fee = uc_recurring_fee_user_load($rfid);
  }
  $remaining = $fee->remaining_intervals;
  $fee->remaining_intervals = 0;
  $fee->status = UC_RECURRING_FEE_STATUS_CANCELLED;

  // Add a timestamp to the user cancellation.
  $fee->data['cancel'] = REQUEST_TIME;
  uc_recurring_fee_user_save($fee);
  uc_recurring_invoke($fee->fee_handler, 'cancel callback', array(
    $fee,
  ));

  // Add comment about cancellation in the product.
  uc_order_comment_save($fee->order_id, $user->uid, t('<a href="@user-link">@user</a> cancelled recurring fee <a href="@fee-link">@fee</a>. There were @remaining fee(s) still pending.', array(
    '@user-link' => url('user/' . $user->uid),
    '@user' => $user->name,
    '@fee-link' => url('admin/store/orders/recurring/view/fee/' . $rfid),
    '@fee' => $rfid,
    '@remaining' => $remaining < 0 ? 'unlimited' : $remaining,
  )));

  // Let other modules act on the canceled fee.
  module_invoke_all('uc_recurring_cancel', $fee);
  $order = uc_order_load($fee->order_id);

  // @todo - replace with rules

  //ca_pull_trigger('uc_recurring_cancel', $order, $fee);
  rules_invoke_event('uc_recurring_cancel', $order, $fee);
}