Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
PayPal's REST APIs are a very easy way to add e-Commerce functionality to your web project. There is a PHP SDK available for it, and there is a very good API Samples site that covers just about anything you would want to do with the SDK. However something that I thought was missing from this documentation was how to create your PayPal App and Sandbox accounts as well as the autoload.php file that's references but never actually included in the package.

This post is in response to this missing bit of documentation. I won't attempt to cover anything more than the official documentation covers since it does a really good job in that respect already.

To get started you need to head over to the Sandbox Accounts page and create two accounts that you will use during development and testing. These are for the Sandbox PayPal site. When creating these accounts you can assign the amount of money they will contain, whether they are verified, etc. You need at least the business account, but it's best to create a business and a personal account straight away. Remember these are just for the sandbox and will not affect the live PayPal servers.

Once the accounts are created, you can go over to the My Apps page and start creating an App by clicking the Create App button.

Fill in the App name and select the Sandbox developer account for the app, then click Create App.

The next screen will display your App's credentials, for now you can scroll past those all the way to the bottom and select the features that your app will use. It's best to select a minimal set of features rather than have everything available. Not all apps will have all features unlocked, this depends on your country. The Return URL is not necessary because you specify this when making a call to PayPal anyway. Click Save when done.

You should take note of the Client ID and Secret from your App's information page, this is used in your bootstrap.php file later.

Now you are almost ready to use the SDK. I opted for the 'direct download' approach without using Composer. This meant that I needed to use an auto-loader. The API examples keep referencing the autoload.php script in the PayPal directory from the SDK, but this is nowhere to be found, so I've created the following as a quick fix.
function PayPal_PHP_SDK_autoload($className)
$classPath = explode('\\', $className);
if ($classPath[0] != 'PayPal') {
$classPath = array_slice($classPath, 1, 2);
$filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php';
if (file_exists($filePath)) {

To make use of that in your code, simply use the following snippet:
 Your Code
require __DIR__ . '/PayPal/autoload.php';

Now you are ready for the rest of the SDK. Good luck!


Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...