title: Authorize.net CIM - Why The API user name is invalid or not present
body: <p>I have created an application using authorize.net CIM. When using the app in test mode everything works fine. When I switch from test mode to live mode and paste in the correct user id and transaction key, it says: The API user name is invalid or not present.</p>
  
  <p>It makes no sense. I'm 100% that the api user name and transaction key are correct.</p>
  
  <p>I'm using the CIM codeigniter library. Here's the code dealing with the setup and initialization of CIM...</p>
  
  <pre><code>&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  /*
  By: Spicer Matthews &lt;spicer@cloudmanic.com&gt;
  Company: Cloudmanic Labs, LLC
  Website: http://www.cloudmanic.com
  
  Based On Work From: 
  - John Conde &lt;johnny@johnconde.net&gt;
  - http://www.communitymx.com/content/article.cfm?page=4&amp;cid=FDB14
  */
  
  class AuthorizeCimLib
  {
      private $_CI; 
      private $_loginname;
      private $_loginkey;
      private $_response;
      private $_resultCode;
      private $_responseCode;
      private $_responseText;
      private $_success;
      private $_error;
      private $_url;
      private $_parsedresponse;
      private $_xml;
      private $_call;
      private $_responsecall;
      private $_directresponse;
      private $_items = array();
      private $_params = array();
      private $_validationmode = 'liveMode';
      private $_errormsg = '';
      private $_loginhost = 'api.authorize.net';
      private $_testhost = 'apitest.authorize.net';
      private $_loginpath = '/xml/v1/request.api';
  
      //
      // Construct..... 
      //
      function __construct()
      {
          $this-&gt;_CI =&amp; get_instance();
          $this-&gt;_set_url();
          $this-&gt;_set_default_params();
  
          // If the config is setup properly use that to initialize
          $this-&gt;_CI-&gt;config-&gt;load('authorizenet');
  
          if($this-&gt;_CI-&gt;config-&gt;item('authorizenetname') &amp;&amp; 
                  $this-&gt;_CI-&gt;config-&gt;item('authorizenetkey') &amp;&amp;
                  $this-&gt;_CI-&gt;config-&gt;item('authorizenettestmode'))
          {
              $this-&gt;initialize($this-&gt;_CI-&gt;config-&gt;item('authorizenetname'), $this-&gt;_CI-&gt;config-&gt;item('authorizenetkey'), $this-&gt;_CI-&gt;config-&gt;item('authorizenettestmode'));
          }
  
          log_message('debug', "AuthorizeCimLib Class Initialized");
      }
  
      //
      // Call this function to setup the library variables. Such as API keys.
      //
      public function initialize($name, $key, $testmode = FALSE)
      {
          // Are we in test mode??
          if($testmode)
          {
              $this-&gt;_set_testmode();
          }
  
          // Setup login names and keys.
          $this-&gt;_loginname = $name;
          $this-&gt;_loginkey = $key;
      }
  
      //
      // Set validation mode.
      //
      public function set_validationmode($mode)
      {
          $types = array('none', 'testMode', 'liveMode', 'oldLiveMode');
  
          if(in_array($mode, $types))
          {
              $this-&gt;_validationmode = $mode;
              return 1;
          } 
          else
          {
              log_message('debug', "AuthorizeCimLib Not A Valid Test Mode");
              return 0;
          }
      }
  
      //
      // Get validation mode.
      //
      public function get_validationmode()
      {
          return $this-&gt;_validationmode;
      }
  
      //
      // Set Parameters to send to Authorize.net
      //
      public function set_data($field, $value)
      {
          $this-&gt;_params[$field] = $value;
      }
  
      //
      // C;ear Parameters data
      //
      public function clear_data()
      {
          $this-&gt;_params = array();
          $this-&gt;_set_default_params();
      }
  </code></pre>