Index: modules/ecommerce/contrib/authorize_net/authorize_net.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/contrib/authorize_net/authorize_net.module,v
retrieving revision 1.27.2.4
diff -u -r1.27.2.4 authorize_net.module
--- modules/ecommerce/contrib/authorize_net/authorize_net.module	11 Aug 2006 00:27:50 -0000	1.27.2.4
+++ modules/ecommerce/contrib/authorize_net/authorize_net.module	16 Aug 2006 17:58:01 -0000
@@ -428,14 +428,17 @@
   curl_close($ch);
 
   $return = preg_split("/[,]+/", "$buffer");
+  // Add an element to the beginning of the array so that the response codes
+  // are numbered as in the authorize.net documentation, which begins with 1.
+  array_unshift($return, '');
 
-  switch ($return[0]) {
+  switch ($return[1]) {
 
     case 1: // Credit card successfully charged
       $txn = array(
         'txnid'           => $edit['txnid'],
-        'anid'            => $return[6],
-        'amount'          => $return[8],
+        'anid'            => $return[7],
+        'amount'          => $return[9],
         'payment_status'  => payment_get_status_id('completed'),
         'payment_method'  => 'authorize_net',
       );
@@ -454,7 +457,9 @@
       break;
 
     default: // Credit card error: card was not charged.
-      drupal_set_message($return[3], 'error');
+      drupal_set_message($return[4], 'error');
+      // Log the error.
+      watchdog('ecommerce', t('Authorize.net payment error for transaction %txnid for user %user_link. Response code: %return_1. Response subcode: %return_2. Response reason code: %return_3. Response reason text: %return_4.', array('%txnid' => $edit['txnid'], '%user_link' => l($t->uid, 'user/'. $t->uid), '%return_1' => $return[1], '%return_2' => $return[2], '%return_3' => $return[3], '%return_4' => $return[4]), WATCHDOG_ERROR, l(t('view'), 'admin/store/transaction')));
       drupal_goto($payment_url);
       break;
   }
