--- uc_cybersource.module.old	2009-06-16 13:22:53.000000000 +0200
+++ uc_cybersource.module.new	2009-06-16 13:25:56.000000000 +0200
@@ -545,15 +545,22 @@ function _uc_cybersource_soap_charge($or
     $purchaseTotals = new stdClass();
     $purchaseTotals->currency = $currency;
 
+    // Check if there is any discount line item because CyberSource API does not support negative amounts
+    $discount_line_items = false;
+    for ($i = 0; (i < count($order->line_items)) && !$discount_line_items; $i++) {
+      $line_item = $order->line_items[$i];
+      if ($line_item['amount'] < 0)
+        $discount_line_items = true;
+    }
     // Specify the total to charge if it's less than the order total.
-    if ($amount < $order->order_total) {
+    if (($amount < $order->order_total) || $discount_line_items) {
       $purchaseTotals->grandTotalAmount = $amount;
     }
     $request->purchaseTotals = $purchaseTotals;
 
     // Separately add products and line item into the request items object if
     // we're charging the full order total.
-    if ($amount == $order->order_total) {
+    if (($amount == $order->order_total) && !$discount_line_items) {
       $request->item = array();
       $counter = 0;
 
