title: Using config file with Paypal SDK throws PayPalInvalidCredentialException
body: <p><sup>This was originally a support ticket that ended up being my <a href="https://en.wikipedia.org/wiki/Rubber_duck_debugging" rel="nofollow noreferrer">rubber duck</a>. I'm posting it to stack overflow to help anyone that comes behind me. Hopefully, it'll save you some time.</sup></p>
  
  <h3>Required Information</h3>
  
  <ul>
  <li>PHP Version: 5.3</li>
  <li>PayPal-PHP-SDK Version: 1.11</li>
  <li>Debug ID(s): ?</li>
  </ul>
  
  <h3>Issue Description</h3>
  
  <p>Using the instructions at: <a href="https://github.com/paypal/PayPal-PHP-SDK/wiki/File-based-Configurations" rel="nofollow noreferrer">https://github.com/paypal/PayPal-PHP-SDK/wiki/File-based-Configurations</a> does not seem to work. I'm getting the following error:</p>
  
  <pre><code>PHP Fatal error:  Uncaught exception 'PayPal\Exception\PayPalInvalidCredentialException' with message 'Credential not found for  default user. Please make sure your configuration/APIContext has credential information
  </code></pre>
  
  <p>The above article links to <a href="https://gist.github.com/jaypatel512/94e626b684f6fefa5078" rel="nofollow noreferrer">sample code</a> that doesn't match the code in the article. Furthermore, it seems to reference a nonexistent <code>$apiContext</code>.</p>
  
  <p>The official <a href="https://github.com/paypal/PayPal-PHP-SDK/tree/master/sample" rel="nofollow noreferrer">samples</a> contain an <a href="https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/sdk_config.ini" rel="nofollow noreferrer">sdk_config.ini</a>, but it doesn't seem to be used anywhere. </p>
  
  <p>Other (older) <a href="https://github.com/paypal/sdk-core-php/wiki/Configuring-the-SDK#api-credentials" rel="nofollow noreferrer">sources</a> prefer to use the "Classic TEST API Credentials." I'd prefer to use the id and secret as this seems to be a better solution if only it would work.</p>
  
  <h3>Files</h3>
  
  <p><em>(Please ignore the bad practices. This is an experiment.)</em></p>
  
  <p>test.php
      
  
  <pre><code>require_once  '../../vendor/autoload.php';
  require_once './class/PaymentManager.php';
  date_default_timezone_set('America/Chicago');
  
  print_r("\n\n");
  
  $payment = new PaymentManager();
  $payment-&gt;test();
  
  print_r("\n\n");
  </code></pre>
  
  <p>PaymentManager.php
      
  
  <pre><code>if(!defined("PP_CONFIG_PATH")) {
      define("PP_CONFIG_PATH", 'config/paypal.ini');
  }
  
  class PaymentManager {
  
  
      public function test(){
          echo $this-&gt;saveCC("visa", "4417119669820331", "012", "11", "2019", "Joe", "Shopper");
      }
  
  
      private function saveCC($type, $number, $ccv, $month, $year, $firstName, $lastName){
          error_log(file_get_contents('config/paypal.ini'));
          $creditCard = new \PayPal\Api\CreditCard();
          $creditCard-&gt;setType($type)
              -&gt;setNumber($number)
              -&gt;setExpireMonth($month)
              -&gt;setExpireYear($year)
              -&gt;setCvv2($ccv)
              -&gt;setFirstName($firstName)
              -&gt;setLastName($lastName);
  
          try {
              $creditCard-&gt;create();
          }
          catch (\PayPal\Exception\PayPalConnectionException $ex) {
              error_log("Exception while saving CC: ".$ex-&gt;getData());
          }
  
          return $creditCard;
      }
  
  
  }
  </code></pre>
  
  <p>paypal.ini</p>
  
  <pre><code>; Modified from: https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/sdk_config.ini
  
  ;## This is an example configuration file for the SDK.
  ;## This is an example configuration file for the SDK.
  ;## The sample scripts configure the SDK dynamically
  ;## but you can choose to go for file based configuration
  ;## in simpler apps (See bootstrap.php for more).
  [Account]
  acct1.ClientId = [REDACTED]
  acct1.ClientSecret = [REDACTED]
  
  ;Connection Information
  [Http]
  ; Add Curl Constants to be configured
  ; The settings provided in configurations would override defaults
  ; if provided in configurations
  http.CURLOPT_CONNECTTIMEOUT = 30
  
  ; Adding HTTP Headers to each request sent to PayPal APIs
  ;http.headers.PayPal-Partner-Attribution-Id = 123123123
  
  ;http.Proxy=http://[username:password]@hostname[:port]
  
  ;Service Configuration
  [Service]
  ; can be set to sandbox / live
  mode = sandbox
  
  ;Logging Information
  [Log]
  ; For custom logging implementation, you can set the
  ; logging factory provider class here.
  ; The class should be implementing \PayPal\Log\PayPalLogFactory.
  ; If this is not set, it will default to \PayPal\Log\PayPalDefaultLogFactory.
  ;log.AdapterFactory=\PayPal\Log\PayPalDefaultLogFactory
  
  ; Settings for PayPalDefaultLogFactory
  log.LogEnabled=true
  
  ; When using a relative path, the log file is created
  ; relative to the .php file that is the entry point
  ; for this request. You can also provide an absolute
  ; path here
  ; Settings for PayPalDefaultLogFactory
  log.FileName=config/PayPal.log
  
  ; Logging level can be one of any provided at \Psr\Log\LogLevel
  ; Logging is most verbose in the 'DEBUG' level and
  ; decreases as you proceed towards ERROR
  ; DEBUG level is disabled for live, to not log sensitive information.
  ; If the level is set to DEBUG, it will be reduced to INFO automatically
  log.LogLevel=INFO
  
  ;Caching Configuration
  [cache]
  ; If Cache is enabled, it stores the access token retrieved from ClientId and Secret from the
  ; server into a file provided by the cache.FileName option or by using
  ; the constant $CACHE_PATH value in PayPal/Cache/AuthorizationCache if the option is omitted/empty.
  ; If the value is set to 'true', it would try to create a file and store the information.
  ; For any other value, it would disable it
  ; Please note, this is a very good performance improvement, and we would encourage you to
  ; set this up properly to reduce the number of calls, to almost 50% on normal use cases
  ; PLEASE NOTE: You may need to provide proper write permissions to /var directory under PayPal-PHP-SDK on
  ; your hosting server or whichever custom directory you choose
  cache.enabled=true
  ; When using a relative path, the cache file is created
  ; relative to the .php file that is the entry point
  ; for this request. You can also provide an absolute
  ; path here
  cache.FileName=config/auth.cache
  </code></pre>