function uc_recurring_order_process_order in UC Recurring Payments and Subscriptions 7.2
Same name and namespace in other branches
- 6.2 modules/uc_recurring_order/uc_recurring_order.module \uc_recurring_order_process_order()
Process a recurring order.
1 call to uc_recurring_order_process_order()
- uc_recurring_order_uc_order in modules/
uc_recurring_order/ uc_recurring_order.module - Implements hook_uc_order().
File
- modules/
uc_recurring_order/ uc_recurring_order.module, line 279 - Provides a way to duplicate entire orders.
Code
function uc_recurring_order_process_order($order, $recurring) {
global $user;
if (variable_get('uc_recurring_order_enabled', TRUE)) {
$payment_method = !empty($order->payment_method) ? $order->payment_method : 'default';
if (!($fee_handler = uc_recurring_get_recurring_info($payment_method))) {
drupal_set_message(t('A handler for processing and renewing recurring fees cannot be found for the @payment-method payment method.', array(
'@payment-method' => $order->payment_method,
)), 'error');
return FALSE;
}
// Create a new fee object.
$fee = new stdClass();
$fee->uid = $order->uid;
$fee->fee_handler = $fee_handler['fee handler'];
$fee->created = REQUEST_TIME;
$fee->order_id = $order->order_id;
// If the product fee amount is 0, it means we need to use the product
// price. This allows recurring fees to be adjusted by attributes.
$fee->fee_amount = $order->order_total;
// Add the order's ID as the order title.
$fee->fee_title = t('Renewal of order @order_id', array(
'@order_id' => $order->order_id,
));
$fee->next_charge = strtotime('+' . $recurring);
$fee->regular_interval = $recurring;
$fee->remaining_intervals = -1;
// hard coded to unlimited
$fee->charged_intervals = 0;
// Clone the products so we don't mess with the actual order products.
$products = array();
foreach ($order->products as $index => $product) {
$products[$index] = clone $product;
unset($products[$index]->order_product_id);
unset($products[$index]->order_id);
}
$fee->data = array(
'uc_recurring_order' => array(
'products' => $products,
),
);
$fee->attempts = 0;
$fee->pfid = NULL;
$fee->order_product_id = NULL;
$fee->own_handler = !empty($fee_handler['own handler']);
drupal_alter('recurring_fee_user_create', $fee);
$rfid = FALSE;
if (uc_recurring_invoke($fee->fee_handler, 'process callback', array(
$order,
&$fee,
))) {
$rfid = uc_recurring_fee_user_save($fee);
uc_order_comment_save($order->order_id, $user->uid, t('Recurring fee <a href="@recurring-view-fee">@rfid</a> added to order.', array(
'@recurring-view-fee' => url('admin/store/orders/recurring/view/fee/' . $rfid),
'@rfid' => $rfid,
)));
}
else {
return FALSE;
}
}
return $rfid;
}