diff -up ./uc_paypal.module ../uc_paypal_patched/uc_paypal.module
--- ./uc_paypal.module	2010-04-10 00:12:46.037001400 +0200
+++ ../uc_paypal_patched/uc_paypal.module	2010-05-02 15:36:04.734375000 +0200
@@ -83,6 +83,69 @@ function uc_paypal_ipn_access() {
 }
 
 /**
+ * Implementation of hook_menu_alter().
+ */
+function uc_paypal_menu_alter(&$items) {
+  $callback = $items['cart/checkout/complete']['page callback'];
+  if ($callback != 'uc_paypal_checkout_complete') {
+    variable_set('uc_paypal_checkout_complete_bak', $callback);
+    $items['cart/checkout/complete']['page callback'] = 'uc_paypal_checkout_complete';
+  }
+}
+
+// Override uc_cart_checkout_complete() when payment method is paypal.
+function uc_paypal_checkout_complete() {
+  if (!$_SESSION['do_complete']
+   || !($order = uc_order_load(intval($_SESSION['cart_order'])))
+   || ($order->payment_method != 'paypal_wps') && ($order->payment_method != 'paypal_ec')
+   || ($order->uid == 0)) {
+    return call_user_func(variable_get('uc_paypal_checkout_complete_bak', 'uc_cart_checkout_complete'));
+  }
+
+  // Get checkout_complete output.
+  global $user;
+  if ($order->uid == $user->uid) {
+
+    // Build output for the already logged in user.
+    $messages['uc_msg_order_submit_format'] = variable_get('uc_msg_order_submit', uc_get_message('completion_message'));
+    $messages['uc_msg_order_logged_in_format'] = variable_get('uc_msg_order_logged_in', uc_get_message('completion_logged_in'));
+    $messages['uc_msg_continue_shopping_format'] = variable_get('uc_msg_continue_shopping', uc_get_message('continue_shopping'));
+
+    $output_message = '';
+    foreach ($messages as $format => $message) {
+      $message = token_replace_multiple($message, array('global' => NULL, 'order' => $order));
+      $message = check_markup($message, variable_get($format, FILTER_FORMAT_DEFAULT), FALSE);
+      $output_message .= $message;
+    }
+    $output = theme('uc_cart_complete_sale', $output_message);
+  }
+  else {
+
+    // Use the output built during autoresponse.
+    $output = $order->data['uc_paypal_complete_sale_output'];
+    unset($order->data['uc_paypal_complete_sale_output']);
+    db_query("UPDATE {uc_orders} SET data = '%s' WHERE order_id = %d", serialize($order->data), $order->order_id);
+
+    // Login the user if specified.
+    if (($user->uid == 0) && variable_get('uc_new_customer_login', FALSE)) {
+      user_external_login(user_load($order->uid));
+    }
+  }
+
+  // Clear cart data.
+  uc_cart_empty(uc_cart_get_id());
+  unset($_SESSION['cart_order'], $_SESSION['do_complete']);
+
+  // Redirect to a custom page if defined.
+  $page = variable_get('uc_cart_checkout_complete_page', '');
+  if (!empty($page)) {
+    drupal_goto($page);
+  }
+
+  return $output;
+}
+
+/**
  * Implementation of hook_perm().
  */
 function uc_paypal_perm() {
diff -up ./uc_paypal.pages.inc ../uc_paypal_patched/uc_paypal.pages.inc
--- ./uc_paypal.pages.inc	2010-04-10 00:12:45.818254200 +0200
+++ ../uc_paypal_patched/uc_paypal.pages.inc	2010-05-02 15:35:52.625000000 +0200
@@ -94,7 +94,9 @@ function uc_paypal_ipn($order_id = 0) {
       case 'Completed':
         $comment = t('PayPal transaction ID: @txn_id', array('@txn_id' => $txn_id));
         uc_payment_enter($order_id, 'paypal_wps', $payment_amount, $order->uid, NULL, $comment);
-        uc_cart_complete_sale($order);
+        $order->data['uc_paypal_complete_sale_output'] = uc_cart_complete_sale($order);
+        db_query("UPDATE {uc_orders} SET data = '%s' WHERE order_id = %d", serialize($order->data), $order->order_id);
+
         uc_order_comment_save($order_id, 0, t('Payment of @amount @currency submitted through PayPal.', array('@amount' => uc_price($payment_amount, $context, $options), '@currency' => $payment_currency)), 'order', 'payment_received');
         uc_order_comment_save($order_id, 0, t('PayPal IPN reported a payment of @amount @currency.', array('@amount' => uc_price($payment_amount, $context, $options), '@currency' => $payment_currency)));
         break;
