简体   繁体   中英

How to go live from sandbox with Paypal php SDK

I am getting 401 errors after switching to using my live key. I am getting a 401 error invalid_client Client Authentication failed.

What steps do I need to follow in order to switch from Sandbox to Live when using the PayPal PHP SDK?

The information provided on the official github page for the PHP SDK are partially correct.

The two steps required are:

  • Update your key and secret
  • Ensure your configuration is set to "live"

However, as everything works in the sandbox out of the box without any configuration and just the keys, there are no instructions on creating a configuration file or setting the configuration via code.

You have two options to set the live site configuration:

  1. Set the configuration via code when creating the $apiContext. See code sample below:

     $apiContext = new \\PayPal\\Rest\\ApiContext( new \\PayPal\\Auth\\OAuthTokenCredential( $this->client_id, // ClientID $this->client_secret // ClientSecret ) ); $apiContext->setConfig( array( 'mode' => 'LIVE', 'log.LogEnabled' => true, 'log.FileName' => '../PayPal.log', 'log.LogLevel' => 'INFO', // PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS ) ); 
  2. Set the configuration via an sdk_config.ini file. Note, the SDK specifically looks for the filename "sdk_config.ini". There is a sample config file that you can reuse at \\PayPal-PHP-SDK\\paypal\\rest-api-sdk-php\\tests\\

To ensure that the sdk_config.ini file is found and load correctly you have two options. If you are using a bootstrap.ini file you can define a constant PP_CONFIG_PATH which the SDK will use to find the location of you sdk_config.ini file.

An example bootstrap file with an example of defining the PP_CONFIG_PATH is also included in the \\tests\\ location mentioned above.

The second option is to place your config file in this location "\\vendor\\PayPal-PHP-SDK\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Core..\\config\\sdk_config.ini", again this location is hard coded into the SDK.

NOTE THAT: The instructions provided on the github page suggest setting the mode variable to "live", but the switch statement in the code looks for "SANDBOX" or "LIVE" and by default it is set to "PayPalConstants::REST_SANDBOX_ENDPOINT" which is defined in "\\lib\\PayPal\\Core\\PayPalConstants.php"

To help with debugging and ensuring your endpoint is being set correctly check out the function _getEndpoint($config) :77 in the file OauthHandler.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM