Index: uc_recurring_hosted.module
===================================================================
--- uc_recurring_hosted.module	(revision 8)
+++ uc_recurring_hosted.module	(working copy)
@@ -37,21 +37,6 @@
   return $items;
 }
 
-/**
- * Implementation of hook_payment_gateway_alter().
- *
- * Register own payment gateway instead of the PayPal pro.
- * @see uc_paypal_payment_gateway().
- */
-function uc_recurring_hosted_payment_gateway_alter(&$gateways) {
- foreach ($gateways as &$gateway) {
-   if ($gateway['id'] == 'paypal_wpp') {
-     // Change the callback.
-     $gateway['credit'] = 'uc_recurring_hosted_uc_paypal_wpp_charge';
-     break;
-   }
- }
-}
 
 /******************************************************************************
  * UBERCART HOOKS (including uc_recurring)
@@ -733,58 +718,11 @@
   exit();
 }
 
-/**
- * Paypal pro charge handler.
- */
-function uc_recurring_hosted_uc_paypal_wpp_charge($order_id, $amount, $data) {
-  global $user;
 
-  $success = TRUE;
+/******************************************************************************
+ * PAYPAL WPP
+ *****************************************************************************/
 
-  $order = uc_order_load($order_id);
-  if (uc_recurring_get_recurring_products_in_order($order)) {
-    if ($fees = uc_recurring_process_order($order, array('amount' => $amount, 'data' => $data))) {
-      foreach ($fees as $fee) {
-        $fee = uc_recurring_fee_user_load($fee);
-        if (!empty($fee->data['npv result']['subscription_id'])) {
-          // Add the subscription Id.
-          uc_recurring_hosted_subscription_save($fee->rfid, $fee->data['npv result']['subscription_id']);
-        }
-        else {
-          // We don't break here, as there might be some success fees that need
-          // to be registered.
-          $success = FALSE;
-        }
-      }
-    }
-    else {
-      $success = FALSE;
-    }
-
-    // Check if we have non-recurring products left.
-    if ($balance = uc_payment_balance($order)) {
-      $non_recurring = uc_paypal_wpp_charge($order_id, $balance, $data);
-      $success = $success  & $non_recurring['success'];
-    }
-
-    // There's was an error so return failure to uc_payment_process().
-    return array(
-      'success' => $success ,
-      'message' => $success ? t('PayPal pro payment successed.') : t('PayPal pro payment failed.'),
-      'uid' => $user->uid,
-    );
-
-  }
-  else {
-    // In case of some error, make sure the balance is updated.
-    $balance = uc_payment_balance($order);
-    // There are no recurring products, so use the default callback.
-    return uc_paypal_wpp_charge($order_id, $balance, $data);
-  }
-}
-
-
-
 /**
  * PayPal website payments pro process.
  */
@@ -963,34 +901,32 @@
           '@type' => $types[$data['txn_type']],
         ),
         WATCHDOG_WARNING,
-        l(t('view order'), 'admin/store/orders/'. $order_id)
+        l(t('view order'), 'admin/store/orders/'. $fee->order_id)
       );
     // Fall through.
     case 'Success':
-      $message = t('<b>@type</b><br /><b>Success: </b>@amount @currency', array('@type' => $types[$data['txn_type']], '@amount' => uc_price($nvp_request['AMT'], $context, array('sign' => FALSE)), '@currency' => $nvp_response['CURRENCYCODE']));
-      if ($data['txn_type'] != UC_CREDIT_PRIOR_AUTH_CAPTURE) {
-        $message .= '<br />'. t('<b>Address:</b> @avscode', array('@avscode' => _uc_paypal_avscode_message($nvp_response['AVSCODE'])));
-        if (variable_get('uc_credit_cvv_enabled', TRUE)) {
-          $message .= '<br />'. t('<b>CVV2:</b> @cvvmatch', array('@cvvmatch' => _uc_paypal_cvvmatch_message($nvp_response['CVV2MATCH'])));
-        }
-      }
+      $message = t('<b>Recurring Payment Setup</b><br /><b>Recurring Success: </b>@amount @currency', array('@amount' => uc_price($nvp_request['AMT'], $context, array('sign' => FALSE)), '@currency' => $nvp_response['CURRENCYCODE']));
+      
       $result = array(
         'success' => TRUE,
         'comment' => t('PayPal transaction ID: @transactionid', array('@transactionid' => $nvp_response['TRANSACTIONID'])),
         'message' => $message,
         'data' => check_plain($nvp_response['TRANSACTIONID']),
         'uid' => $user->uid,
-        // We place the subscription ID, and it will be saved in
-        // uc_recurring_hosted_uc_paypal_wpp_charge(), as we still don't have
-        // the recurring fee ID.
-        'subscription_id' => $nvp_response['PROFILEID'],
       );
 
-
+      //we need to save the rfid, we don't have it yet
+      if(!$fee->rfid){
+        $fee->rfid = uc_recurring_fee_user_save($fee);
+      }
+      
+      //save the subscription so we have the information
+      uc_recurring_hosted_subscription_save($fee->rfid, $nvp_response['PROFILEID']);
+      
       // If this was an authorization only transaction..
       if ($data['txn_type'] == UC_CREDIT_AUTH_ONLY) {
         // Log the authorization to the order.
-        uc_credit_log_authorization($order_id, $nvp_response['TRANSACTIONID'], $nvp_response['AMT']);
+        uc_credit_log_authorization($fee->order_id, $nvp_response['TRANSACTIONID'], $nvp_response['AMT']);
       }
       elseif ($data['txn_type'] == UC_CREDIT_PRIOR_AUTH_CAPTURE) {
         uc_credit_log_prior_auth_capture($order_id, $data['auth_id']);
@@ -1030,7 +966,7 @@
       break;
   }
 
-  uc_order_comment_save($order_id, $user->uid, $message, 'admin');
+  uc_order_comment_save($fee->order_id, $user->uid, $message, 'admin');
 
   // Log this only if payment money wasn't actually captured.
   if(!empty($result['success']) && !in_array($data['txn_type'], array(UC_CREDIT_AUTH_ONLY))) {
