1

This is my first time implementing the PayPal SDK and I am having some issues. I have followed the directions given on the PayPal Developer site(https://github.com/paypal/rest-api-sdk-php) exactly and I am still getting a 500 error.

Just to be clear:

  1. From the command prompt I cURL'd the required dependency manager tool Composer into the directory that contains the PHP files that will be using the PayPal API
  2. I took the JSON file located on the page here(https://developer.paypal.com/webapps/developer/docs/api/, click on the PHP tab to view the JSON), and placed it in the same directory and used the command: php compose.phar install, to download and install the PayPal SDKs
  3. I took the sdk_config.ini file from the PayPal SDK REST sample files and copied it into the base directory(same as PHP files and Composer) and edited the config file to contain my PayPal Client ID and Secret

So now I have my PHP files, the composer.json file, the sdk_config file, and the "vendor" folder which contains the Composer files and the PayPal SDK files all in one directory.

When I enter in the following code, however, which I found on the PayPal documentation site:

require 'vendor/autoload.php';
define('PP_CONFIG_PATH', __DIR__."sdk_config.ini");
use PayPal\Auth\OAuthTokenCredential;

$apiContext = new OAuthTokenCredential('my paypal client id', 'my secret');

When I run this code I get a 500 error with the error logs saying:

PHP Fatal error:  Class 'ApiContext' not found

My PHP script is not finding the PayPal SDK even though I have followed the directions exactly, and yes Composer did create the "autoload.php" file in the "vendor" folder.

Has anyone else had this issue? Is there a step I'm missing?

1
  • Can you post your complete code snippet? The ApiContext error you have posted is a local PHP error, while the 500 response is a server side error. So its not clear what exactly is happening. Also looks like you are assigning an 'OAuthTokenCredential' object to '$apiContext'. That could be causing an issue too. Commented Aug 19, 2013 at 12:37

1 Answer 1

1

You havent loaded the ApiContext class. Try this:

define('PP_CONFIG_PATH', __DIR__."sdk_config.ini");
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;

$credential = new OAuthTokenCredential($paypalClientId, $paypalSecret);
$apiContext = new ApiContext($credential, null);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.