2017-01-25 17:13 阅读 66

使用配置文件和Paypal SDK会抛出PayPalInvalidCredentialException

This was originally a support ticket that ended up being my rubber duck. I'm posting it to stack overflow to help anyone that comes behind me. Hopefully, it'll save you some time.

Required Information

  • PHP Version: 5.3
  • PayPal-PHP-SDK Version: 1.11
  • Debug ID(s): ?

Issue Description

Using the instructions at: does not seem to work. I'm getting the following error:

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

The above article links to sample code that doesn't match the code in the article. Furthermore, it seems to reference a nonexistent $apiContext.

The official samples contain an sdk_config.ini, but it doesn't seem to be used anywhere.

Other (older) sources 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.


(Please ignore the bad practices. This is an experiment.)


require_once  '../../vendor/autoload.php';
require_once './class/PaymentManager.php';



$payment = new PaymentManager();




if(!defined("PP_CONFIG_PATH")) {
    define("PP_CONFIG_PATH", 'config/paypal.ini');

class PaymentManager {

    public function test(){
        echo $this->saveCC("visa", "4417119669820331", "012", "11", "2019", "Joe", "Shopper");

    private function saveCC($type, $number, $ccv, $month, $year, $firstName, $lastName){
        $creditCard = new \PayPal\Api\CreditCard();

        try {
        catch (\PayPal\Exception\PayPalConnectionException $ex) {
            error_log("Exception while saving CC: ".$ex->getData());

        return $creditCard;



; Modified from:

;## 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).
acct1.ClientId = [REDACTED]
acct1.ClientSecret = [REDACTED]

;Connection Information
; Add Curl Constants to be configured
; The settings provided in configurations would override defaults
; if provided in configurations

; Adding HTTP Headers to each request sent to PayPal APIs
;http.headers.PayPal-Partner-Attribution-Id = 123123123


;Service Configuration
; can be set to sandbox / live
mode = sandbox

;Logging Information
; 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.

; Settings for PayPalDefaultLogFactory

; 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

; 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

;Caching Configuration
; 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
; 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
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douchun9719 douchun9719 2017-01-25 17:13


    • PP_CONFIG_PATH should be the path to the .ini file, without the filename.

      if(!defined("PP_CONFIG_PATH")) {
          define("PP_CONFIG_PATH", 'config/');
    • The .ini file itself should be named sdk_config.ini. There may be a way to change the filename, but this is what the sdk looks for by default. I'm certainly interested if someone knows how to change it, but this is not a show stopper.

    点赞 评论 复制链接分享