? uc_recurring_renew_pending.patch
Index: uc_recurring.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/uc_recurring/uc_recurring.module,v
retrieving revision 1.1.4.17
diff -u -p -r1.1.4.17 uc_recurring.module
--- uc_recurring.module	22 Jun 2009 01:35:35 -0000	1.1.4.17
+++ uc_recurring.module	2 Jul 2009 07:07:00 -0000
@@ -264,7 +264,7 @@ function uc_recurring_order_view_update_
 function uc_recurring_cron() {
   $successes = 0;
   $fails = 0;
-
+  
   $result = db_query("SELECT * FROM {uc_recurring_users} WHERE (remaining_intervals > 0 OR remaining_intervals IS NULL) AND next_charge <= %d", time());
   while ($fee = db_fetch_array($result)) {
     $fee['data'] = unserialize($fee['data']);
@@ -311,6 +311,17 @@ function uc_recurring_find_fee($fee_hand
  *   (int)order_id of the new order or FALSE if unable to renew fee
  */
 function uc_recurring_renew($fee, $check_handler = TRUE) {
+  // give the fee handler module a chance to say the payment is still pending
+  $pending_test_func = 'uc_recurring_'. $fee['fee_handler'] .'_renew_pending';
+  if (function_exists($pending_test_func)) {
+    $pending_result = $pending_test_func($fee);
+    if ($pending_result) {
+      uc_order_comment_save($fee['order_id'], 0, t('Info: Recurring fee <a href="!url">!fee</a> for product @model is currently pending. Will retry.', array('!url' => url('admin/store/orders/recurring/view/fee/'. $fee['rfid']), '!fee' => $fee['rfid'], '@model' => $fee['data']['model'])));
+      watchdog('uc_recurring', 'Recurring fee of !amount for product @model on order !order_id is still pending. Will retry.', array('!amount' => $fee['fee_amount'], '@model' => $fee['data']['model'], '!order_id' => $fee['order_id']), WATCHDOG_INFO, l(t('order !order_id', array('!order_id' => $fee['order_id'])), 'admin/store/orders/'. $fee['order_id']));
+      return FALSE;
+    }
+  }
+  
   // attempt to a call uc_recurring_[fee_handler]_renew() function if it exits
   $renew_func = 'uc_recurring_'. $fee['fee_handler'] .'_renew'; 
   if ($check_handler == FALSE || function_exists($renew_func)) {
@@ -348,6 +359,7 @@ function uc_recurring_renew($fee, $check
     $fee['fee_amount'] = uc_order_get_total($new_order);
     uc_order_update_status($new_id, 'processing');
 
+
     if ($check_handler == FALSE || ($check_handler && $renew_func($new_order, $fee))) {
       uc_order_update_status($new_id, 'payment_received');
       // payment was successful save the new order
@@ -1024,7 +1036,7 @@ function uc_recurring_fee_delete($featur
       db_query("DELETE FROM {uc_recurring_products} WHERE pfid = %d", $feature['pfid']);
       break;
     case 'user':
-      module_invoke_all('recurring_api', 'delete', $feature['fid']);
+      module_invoke_all('recurring_api', 'delete', $feature['pfid']);
       db_query("DELETE FROM {uc_recurring_users} WHERE rfid = %d", $feature['pfid']);
       break;
   }
